[WIKI-458] refactor: base page instance for additional properties (#7228)

* refactor: create a super class for base page

* fix: path

---------

Co-authored-by: Palanikannan M <akashmalinimurugu@gmail.com>
This commit is contained in:
Aaryan Khandelwal
2025-06-19 16:00:18 +05:30
committed by GitHub
parent 414010688d
commit eb5ffebcc6
7 changed files with 30 additions and 15 deletions

View File

@@ -10,7 +10,7 @@ export * from "./issues";
export * from "./module";
export * from "./views";
export * from "./integration";
export * from "./pages";
export * from "./page";
export * from "./ai";
export * from "./estimate";
export * from "./importer";

View File

@@ -1,9 +1,9 @@
import { TLogoProps } from "./common";
import { EPageAccess } from "./enums";
import { TLogoProps } from "../common";
import { EPageAccess } from "../enums";
import { TPageExtended } from "./extended";
export type TPage = {
export type TPage = TPageExtended & {
access: EPageAccess | undefined;
anchor?: string | null | undefined;
archived_at: string | null | undefined;
color: string | undefined;
created_at: Date | undefined;
@@ -16,7 +16,6 @@ export type TPage = {
name: string | undefined;
owned_by: string | undefined;
project_ids?: string[] | undefined;
team: string | null | undefined;
updated_at: Date | undefined;
updated_by: string | undefined;
workspace: string | undefined;

1
packages/types/src/page/extended.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
export type TPageExtended = {};

2
packages/types/src/page/index.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
export * from "./core";
export * from "./extended";

View File

@@ -1,7 +1,7 @@
import { ICycle } from "./cycle";
import { TIssue } from "./issues/issue";
import { IModule } from "./module";
import { TPage } from "./pages";
import { TPage } from "./page";
import { IProject } from "./project";
import { IUser } from "./users";
import { IWorkspace } from "./workspace";

View File

@@ -0,0 +1,16 @@
import { TPage, TPageExtended } from "@plane/types";
import { RootStore } from "@/plane-web/store/root.store";
import { TBasePageServices } from "@/store/pages/base-page";
export type TExtendedPageInstance = TPageExtended & {
asJSONExtended: TPageExtended;
};
export class ExtendedBasePage implements TExtendedPageInstance {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
constructor(store: RootStore, page: TPage, services: TBasePageServices) {}
get asJSONExtended(): TExtendedPageInstance["asJSONExtended"] {
return {};
}
}

View File

@@ -7,6 +7,7 @@ import { TDocumentPayload, TLogoProps, TNameDescriptionLoader, TPage } from "@pl
import { TChangeHandlerProps } from "@plane/ui";
import { convertHexEmojiToDecimal } from "@plane/utils";
// plane web store
import { ExtendedBasePage } from "@/plane-web/store/pages/extended-base-page";
import { RootStore } from "@/plane-web/store/root.store";
export type TBasePage = TPage & {
@@ -69,7 +70,7 @@ export type TPageInstance = TBasePage &
getRedirectionLink: () => string;
};
export class BasePage implements TBasePage {
export class BasePage extends ExtendedBasePage implements TBasePage {
// loaders
isSubmitting: TNameDescriptionLoader = "saved";
editorRef: EditorRefApi | null = null;
@@ -82,13 +83,11 @@ export class BasePage implements TBasePage {
label_ids: string[] | undefined;
owned_by: string | undefined;
access: EPageAccess | undefined;
anchor?: string | null | undefined;
is_favorite: boolean;
is_locked: boolean;
archived_at: string | null | undefined;
workspace: string | undefined;
project_ids?: string[] | undefined;
team: string | null | undefined;
created_by: string | undefined;
updated_by: string | undefined;
created_at: Date | undefined;
@@ -106,6 +105,8 @@ export class BasePage implements TBasePage {
page: TPage,
services: TBasePageServices
) {
super(store, page, services);
this.id = page?.id || undefined;
this.name = page?.name;
this.logo_props = page?.logo_props || undefined;
@@ -114,13 +115,11 @@ export class BasePage implements TBasePage {
this.label_ids = page?.label_ids || undefined;
this.owned_by = page?.owned_by || undefined;
this.access = page?.access || EPageAccess.PUBLIC;
this.anchor = page?.anchor || undefined;
this.is_favorite = page?.is_favorite || false;
this.is_locked = page?.is_locked || false;
this.archived_at = page?.archived_at || undefined;
this.workspace = page?.workspace || undefined;
this.project_ids = page?.project_ids || undefined;
this.team = page?.team || undefined;
this.created_by = page?.created_by || undefined;
this.updated_by = page?.updated_by || undefined;
this.created_at = page?.created_at || undefined;
@@ -140,7 +139,6 @@ export class BasePage implements TBasePage {
label_ids: observable,
owned_by: observable.ref,
access: observable.ref,
anchor: observable.ref,
is_favorite: observable.ref,
is_locked: observable.ref,
archived_at: observable.ref,
@@ -212,18 +210,17 @@ export class BasePage implements TBasePage {
label_ids: this.label_ids,
owned_by: this.owned_by,
access: this.access,
anchor: this.anchor,
logo_props: this.logo_props,
is_favorite: this.is_favorite,
is_locked: this.is_locked,
archived_at: this.archived_at,
workspace: this.workspace,
project_ids: this.project_ids,
team: this.team,
created_by: this.created_by,
updated_by: this.updated_by,
created_at: this.created_at,
updated_at: this.updated_at,
...this.asJSONExtended,
};
}