Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion space/core/store/issue-detail.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class IssueDetailStore implements IIssueDetailStore {
anchor,
{
entity_identifier: commentID ?? "",
entity_type: EFileAssetType.ISSUE_ATTACHMENT,
entity_type: EFileAssetType.ISSUE_DESCRIPTION,
},
file
);
Expand Down
2 changes: 1 addition & 1 deletion web/core/services/inbox/inbox-issue.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class InboxIssueService extends APIService {
});
}

async regeneratePublishForm(workspaceSlug: string, projectId: string): Promise<TInboxIssue> {
async regeneratePublishForm(workspaceSlug: string, projectId: string): Promise<TInboxForm> {
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/publish-intake-regenerate/`)
.then((response) => response?.data)
.catch((error) => {
Expand Down
5 changes: 4 additions & 1 deletion web/core/store/inbox/project-inbox.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@ export class ProjectInboxStore implements IProjectInboxStore {
const form = await this.inboxIssueService.regeneratePublishForm(workspaceSlug, projectId);
if (form) {
runInAction(() => {
set(this.intakeForms, projectId, form);
set(this.intakeForms, projectId, {
...this.intakeForms[projectId],
anchor: form?.anchor,
});
});
}
} catch {
Expand Down
10 changes: 10 additions & 0 deletions web/core/store/project/project.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { CoreRootStore } from "../root.store";

export interface IProjectStore {
// observables
isUpdatingProject: boolean;
loader: boolean;
projectMap: {
[projectId: string]: TProject; // projectId: project Info
Expand Down Expand Up @@ -47,6 +48,7 @@ export interface IProjectStore {

export class ProjectStore implements IProjectStore {
// observables
isUpdatingProject: boolean = false;
loader: boolean = false;
projectMap: {
[projectId: string]: TProject; // projectId: project Info
Expand All @@ -63,6 +65,7 @@ export class ProjectStore implements IProjectStore {
constructor(_rootStore: CoreRootStore) {
makeObservable(this, {
// observables
isUpdatingProject: observable,
loader: observable.ref,
projectMap: observable,
// computed
Expand Down Expand Up @@ -380,13 +383,20 @@ export class ProjectStore implements IProjectStore {
const projectDetails = this.getProjectById(projectId);
runInAction(() => {
set(this.projectMap, [projectId], { ...projectDetails, ...data });
this.isUpdatingProject = true;
});
const response = await this.projectService.updateProject(workspaceSlug, projectId, data);
runInAction(() => {
this.isUpdatingProject = false;
});
return response;
} catch (error) {
console.log("Failed to create project from project store");
this.fetchProjects(workspaceSlug);
this.fetchProjectDetails(workspaceSlug, projectId);
runInAction(() => {
this.isUpdatingProject = false;
});
Comment on lines +386 to +399
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve loading state management and error handling.

The current implementation has several areas for improvement:

  1. The loading state should be set before the optimistic update to accurately reflect the operation's start.
  2. The error handling code duplicates the loading state reset logic.
  3. The error logging message is too generic.

Consider this refactoring:

  updateProject = async (workspaceSlug: string, projectId: string, data: Partial<TProject>) => {
+   runInAction(() => {
+     this.isUpdatingProject = true;
+   });
    try {
      const projectDetails = this.getProjectById(projectId);
      runInAction(() => {
        set(this.projectMap, [projectId], { ...projectDetails, ...data });
-       this.isUpdatingProject = true;
      });
      const response = await this.projectService.updateProject(workspaceSlug, projectId, data);
-     runInAction(() => {
-       this.isUpdatingProject = false;
-     });
      return response;
    } catch (error) {
-     console.log("Failed to create project from project store");
+     console.error("Failed to update project:", { workspaceSlug, projectId, error });
      this.fetchProjects(workspaceSlug);
      this.fetchProjectDetails(workspaceSlug, projectId);
-     runInAction(() => {
-       this.isUpdatingProject = false;
-     });
      throw error;
+   } finally {
+     runInAction(() => {
+       this.isUpdatingProject = false;
+     });
    }
  };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this.isUpdatingProject = true;
});
const response = await this.projectService.updateProject(workspaceSlug, projectId, data);
runInAction(() => {
this.isUpdatingProject = false;
});
return response;
} catch (error) {
console.log("Failed to create project from project store");
this.fetchProjects(workspaceSlug);
this.fetchProjectDetails(workspaceSlug, projectId);
runInAction(() => {
this.isUpdatingProject = false;
});
runInAction(() => {
this.isUpdatingProject = true;
});
try {
const projectDetails = this.getProjectById(projectId);
runInAction(() => {
set(this.projectMap, [projectId], { ...projectDetails, ...data });
});
const response = await this.projectService.updateProject(workspaceSlug, projectId, data);
return response;
} catch (error) {
console.error("Failed to update project:", { workspaceSlug, projectId, error });
this.fetchProjects(workspaceSlug);
this.fetchProjectDetails(workspaceSlug, projectId);
throw error;
} finally {
runInAction(() => {
this.isUpdatingProject = false;
});
}

throw error;
}
};
Expand Down