[PE-182] refactor: pages' components and store for scalability (#6283)

* refactor: created a generic base page instance

* refactor: project store hooks

* chore: add missing prop declaration

* refactor: editor page root and body

* refactor: issue embed hook

* chore: update search entity types

* fix: version editor component

* fix: add page to favorites action

---------

Co-authored-by: Prateek Shourya <prateekshourya29@gmail.com>
This commit is contained in:
Aaryan Khandelwal 2024-12-27 20:41:38 +05:30 committed by GitHub
parent 211d5e1cd0
commit 8d7425a3b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 553 additions and 521 deletions

View file

@ -1,103 +0,0 @@
import { MAX_FILE_SIZE } from "@plane/constants";
import { getFileURL } from "./file";
// Define image-related types locally
type DeleteImage = (assetUrlWithWorkspaceId: string) => Promise<void>;
type RestoreImage = (assetUrlWithWorkspaceId: string) => Promise<void>;
type UploadImage = (file: File) => Promise<string>;
// Define the FileService interface based on usage
interface IFileService {
deleteOldEditorAsset: (workspaceId: string, src: string) => Promise<void>;
deleteNewAsset: (url: string) => Promise<void>;
restoreOldEditorAsset: (workspaceId: string, src: string) => Promise<void>;
restoreNewAsset: (anchor: string, src: string) => Promise<void>;
cancelUpload: () => void;
}
// Define TFileHandler locally since we can't import from @plane/editor
interface TFileHandler {
getAssetSrc: (path: string) => Promise<string>;
cancel: () => void;
delete: DeleteImage;
upload: UploadImage;
restore: RestoreImage;
validation: {
maxFileSize: number;
};
}
/**
* @description generate the file source using assetId
* @param {string} anchor
* @param {string} assetId
*/
export const getEditorAssetSrc = (anchor: string, assetId: string): string | undefined => {
const url = getFileURL(`/api/public/assets/v2/anchor/${anchor}/${assetId}/`);
return url;
};
type TArgs = {
anchor: string;
uploadFile: (file: File) => Promise<string>;
workspaceId: string;
fileService: IFileService;
};
/**
* @description this function returns the file handler required by the editors
* @param {TArgs} args
*/
export const getEditorFileHandlers = (args: TArgs): TFileHandler => {
const { anchor, uploadFile, workspaceId, fileService } = args;
return {
getAssetSrc: async (path: string) => {
if (!path) return "";
if (path?.startsWith("http")) {
return path;
} else {
return getEditorAssetSrc(anchor, path) ?? "";
}
},
upload: uploadFile,
delete: async (src: string) => {
if (src?.startsWith("http")) {
await fileService.deleteOldEditorAsset(workspaceId, src);
} else {
await fileService.deleteNewAsset(getEditorAssetSrc(anchor, src) ?? "");
}
},
restore: async (src: string) => {
if (src?.startsWith("http")) {
await fileService.restoreOldEditorAsset(workspaceId, src);
} else {
await fileService.restoreNewAsset(anchor, src);
}
},
cancel: fileService.cancelUpload,
validation: {
maxFileSize: MAX_FILE_SIZE,
},
};
};
/**
* @description this function returns the file handler required by the read-only editors
*/
export const getReadOnlyEditorFileHandlers = (
args: Pick<TArgs, "anchor">
): { getAssetSrc: TFileHandler["getAssetSrc"] } => {
const { anchor } = args;
return {
getAssetSrc: async (path: string) => {
if (!path) return "";
if (path?.startsWith("http")) {
return path;
} else {
return getEditorAssetSrc(anchor, path) ?? "";
}
},
};
};

View file

@ -4,7 +4,6 @@ export * from "./datetime";
export * from "./color";
export * from "./common";
export * from "./datetime";
export * from "./editor";
export * from "./emoji";
export * from "./file";
export * from "./issue";