mirror of
https://github.com/makeplane/plane
synced 2025-08-07 19:59:33 +00:00
Compare commits
1 Commits
workspace-
...
fix/store-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e53fb61d54 |
@@ -33,6 +33,7 @@ export interface IPage extends TPage {
|
||||
update: (pageData: Partial<TPage>) => Promise<TPage | undefined>;
|
||||
updateTitle: (title: string) => void;
|
||||
updateDescription: (binaryString: string, descriptionHTML: string) => Promise<void>;
|
||||
updatePageProperties: (page: TPage) => void;
|
||||
makePublic: () => Promise<void>;
|
||||
makePrivate: () => Promise<void>;
|
||||
lock: () => Promise<void>;
|
||||
@@ -137,6 +138,7 @@ export class Page implements IPage {
|
||||
update: action,
|
||||
updateTitle: action,
|
||||
updateDescription: action,
|
||||
updatePageProperties: action,
|
||||
makePublic: action,
|
||||
makePrivate: action,
|
||||
lock: action,
|
||||
@@ -287,6 +289,22 @@ export class Page implements IPage {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @description update the page property observables
|
||||
* @param {TPage} page
|
||||
*/
|
||||
updatePageProperties = (page: TPage) => {
|
||||
const properties = this.asJSON;
|
||||
Object.keys(properties).forEach((key) => {
|
||||
const currentPropertyKey = key as keyof TPage;
|
||||
set(
|
||||
this,
|
||||
[currentPropertyKey],
|
||||
page?.[currentPropertyKey] === undefined ? this?.[currentPropertyKey] : page?.[currentPropertyKey]
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @description update the page
|
||||
* @param {Partial<TPage>} pageData
|
||||
|
||||
@@ -61,6 +61,7 @@ export class ProjectPageStore implements IProjectPageStore {
|
||||
updateFilters: action,
|
||||
clearAllFilters: action,
|
||||
// actions
|
||||
handlePageInstanceCreation: action,
|
||||
getAllPages: action,
|
||||
getPageById: action,
|
||||
createPage: action,
|
||||
@@ -145,6 +146,21 @@ export class ProjectPageStore implements IProjectPageStore {
|
||||
set(this.filters, ["filters"], {});
|
||||
});
|
||||
|
||||
/**
|
||||
* @description if the page instance is present, update the page properties
|
||||
* @description if the page instance is not present, create a new instance of the page
|
||||
* @param {TPage} page
|
||||
*/
|
||||
handlePageInstanceCreation = (page: TPage) => {
|
||||
if (!page.id) return;
|
||||
const pageInstance = this.data?.[page?.id];
|
||||
if (pageInstance) {
|
||||
pageInstance.updatePageProperties(page ?? {});
|
||||
} else {
|
||||
set(this.data, [page.id], new Page(this.store, page));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @description fetch all the pages
|
||||
*/
|
||||
@@ -161,7 +177,7 @@ export class ProjectPageStore implements IProjectPageStore {
|
||||
|
||||
const pages = await this.service.fetchAll(workspaceSlug, projectId);
|
||||
runInAction(() => {
|
||||
for (const page of pages) if (page?.id) set(this.data, [page.id], new Page(this.store, page));
|
||||
for (const page of pages) if (page?.id) this.handlePageInstanceCreation(page);
|
||||
this.loader = undefined;
|
||||
});
|
||||
|
||||
@@ -195,7 +211,7 @@ export class ProjectPageStore implements IProjectPageStore {
|
||||
|
||||
const page = await this.service.fetchById(workspaceSlug, projectId, pageId);
|
||||
runInAction(() => {
|
||||
if (page?.id) set(this.data, [page.id], new Page(this.store, page));
|
||||
if (page?.id) this.handlePageInstanceCreation(page);
|
||||
this.loader = undefined;
|
||||
});
|
||||
|
||||
@@ -228,7 +244,7 @@ export class ProjectPageStore implements IProjectPageStore {
|
||||
|
||||
const page = await this.service.create(workspaceSlug, projectId, pageData);
|
||||
runInAction(() => {
|
||||
if (page?.id) set(this.data, [page.id], new Page(this.store, page));
|
||||
if (page?.id) this.handlePageInstanceCreation(page);
|
||||
this.loader = undefined;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user