mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
minor changes in workspavcestore logic
This commit is contained in:
parent
86e952eb1f
commit
852f662612
@ -7,7 +7,7 @@ import { set } from "lodash";
|
|||||||
export interface IWorkspaceData {
|
export interface IWorkspaceData {
|
||||||
workspaceMap: Record<string, WorkspaceModel>;
|
workspaceMap: Record<string, WorkspaceModel>;
|
||||||
|
|
||||||
addWorkspaces: (workspaces: IWorkspace[]) => void;
|
addWorkspace: (workspaces: IWorkspace) => void;
|
||||||
deleteWorkspace: (workspaceId: string) => void;
|
deleteWorkspace: (workspaceId: string) => void;
|
||||||
getWorkspacebyId: (workspaceId: string) => WorkspaceModel | undefined;
|
getWorkspacebyId: (workspaceId: string) => WorkspaceModel | undefined;
|
||||||
}
|
}
|
||||||
@ -25,10 +25,8 @@ export class WorkspaceData implements IWorkspaceData {
|
|||||||
this.dataStore = _dataStore;
|
this.dataStore = _dataStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
addWorkspaces = (workspaces: IWorkspace[]) => {
|
addWorkspace = (workspace: IWorkspace) => {
|
||||||
workspaces.forEach((workspace) => {
|
set(this.workspaceMap, [workspace.id], new WorkspaceModel(workspace, this.dataStore));
|
||||||
set(this.workspaceMap, [workspace.id], new WorkspaceModel(workspace, this.dataStore));
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
deleteWorkspace = (workspaceId: string) => {
|
deleteWorkspace = (workspaceId: string) => {
|
||||||
|
@ -38,9 +38,9 @@ export class UserModel implements IUserModel {
|
|||||||
fetchWorkspaces = async () => {
|
fetchWorkspaces = async () => {
|
||||||
const workspaceResponse = await this.workspaceService.userWorkspaces();
|
const workspaceResponse = await this.workspaceService.userWorkspaces();
|
||||||
|
|
||||||
this.data.workspace.addWorkspaces(workspaceResponse);
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
workspaceResponse.forEach((workspace) => {
|
workspaceResponse.forEach((workspace) => {
|
||||||
|
this.data.workspace.addWorkspace(workspace);
|
||||||
set(this.workspaces, [workspace.id], this.data.workspace.workspaceMap[workspace.id]);
|
set(this.workspaces, [workspace.id], this.data.workspace.workspaceMap[workspace.id]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -53,8 +53,8 @@ export class UserModel implements IUserModel {
|
|||||||
*/
|
*/
|
||||||
createWorkspace = async (data: Partial<IWorkspace>) =>
|
createWorkspace = async (data: Partial<IWorkspace>) =>
|
||||||
await this.workspaceService.createWorkspace(data).then((response) => {
|
await this.workspaceService.createWorkspace(data).then((response) => {
|
||||||
this.data.workspace.addWorkspaces([response]);
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
|
this.data.workspace.addWorkspace(response);
|
||||||
set(this.workspaces, [response.id], this.data.workspace.workspaceMap[response.id]);
|
set(this.workspaces, [response.id], this.data.workspace.workspaceMap[response.id]);
|
||||||
});
|
});
|
||||||
return response;
|
return response;
|
||||||
|
@ -58,4 +58,22 @@ export class WorkspaceModel implements IWorkspaceModel {
|
|||||||
this.organization_size = workspace.organization_size;
|
this.organization_size = workspace.organization_size;
|
||||||
this.total_issues = workspace.total_issues;
|
this.total_issues = workspace.total_issues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get toJSON() {
|
||||||
|
return {
|
||||||
|
id: this.id,
|
||||||
|
owner: this.owner,
|
||||||
|
created_at: this.created_at,
|
||||||
|
updated_at: this.updated_at,
|
||||||
|
name: this.name,
|
||||||
|
url: this.url,
|
||||||
|
logo: this.logo,
|
||||||
|
total_members: this.total_members,
|
||||||
|
slug: this.slug,
|
||||||
|
created_by: this.created_by,
|
||||||
|
updated_by: this.updated_by,
|
||||||
|
organization_size: this.organization_size,
|
||||||
|
total_issues: this.total_issues,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user