-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[WEB-2943] chore: issue reaction and code refactor #6350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,16 +11,15 @@ import { ProjectService, ProjectStateService, ProjectArchiveService } from "@/se | |||||||||||||||||||||||||||||
| // store | ||||||||||||||||||||||||||||||
| import { CoreRootStore } from "../root.store"; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| type ProjectOverviewCollapsible = "links" | "attachments"; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export interface IProjectStore { | ||||||||||||||||||||||||||||||
| // observables | ||||||||||||||||||||||||||||||
| isUpdatingProject: boolean; | ||||||||||||||||||||||||||||||
| loader: boolean; | ||||||||||||||||||||||||||||||
| projectMap: { | ||||||||||||||||||||||||||||||
| [projectId: string]: TProject; // projectId: project Info | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
| projectEpicPropertiesMap: { | ||||||||||||||||||||||||||||||
| [projectId: string]: any; | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
| // computed | ||||||||||||||||||||||||||||||
| filteredProjectIds: string[] | undefined; | ||||||||||||||||||||||||||||||
| workspaceProjectIds: string[] | undefined; | ||||||||||||||||||||||||||||||
|
|
@@ -32,9 +31,15 @@ export interface IProjectStore { | |||||||||||||||||||||||||||||
| // actions | ||||||||||||||||||||||||||||||
| getProjectById: (projectId: string | undefined | null) => TProject | undefined; | ||||||||||||||||||||||||||||||
| getProjectIdentifierById: (projectId: string | undefined | null) => string; | ||||||||||||||||||||||||||||||
| getProjectEpicPropertiesById: (projectId: string | undefined | null) => any; | ||||||||||||||||||||||||||||||
| // collapsible | ||||||||||||||||||||||||||||||
| openCollapsibleSection: ProjectOverviewCollapsible[]; | ||||||||||||||||||||||||||||||
| lastCollapsibleAction: ProjectOverviewCollapsible | null; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| setOpenCollapsibleSection: (section: ProjectOverviewCollapsible[]) => void; | ||||||||||||||||||||||||||||||
| setLastCollapsibleAction: (section: ProjectOverviewCollapsible) => void; | ||||||||||||||||||||||||||||||
| toggleOpenCollapsibleSection: (section: ProjectOverviewCollapsible) => void; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // fetch actions | ||||||||||||||||||||||||||||||
| fetchProjectEpicProperties: (workspaceSlug: string, projectId: string) => Promise<any>; | ||||||||||||||||||||||||||||||
| fetchProjects: (workspaceSlug: string) => Promise<TProject[]>; | ||||||||||||||||||||||||||||||
| fetchProjectDetails: (workspaceSlug: string, projectId: string) => Promise<TProject>; | ||||||||||||||||||||||||||||||
| // favorites actions | ||||||||||||||||||||||||||||||
|
|
@@ -58,9 +63,9 @@ export class ProjectStore implements IProjectStore { | |||||||||||||||||||||||||||||
| projectMap: { | ||||||||||||||||||||||||||||||
| [projectId: string]: TProject; // projectId: project Info | ||||||||||||||||||||||||||||||
| } = {}; | ||||||||||||||||||||||||||||||
| projectEpicPropertiesMap: { | ||||||||||||||||||||||||||||||
| [projectId: string]: any; | ||||||||||||||||||||||||||||||
| } = {}; | ||||||||||||||||||||||||||||||
| openCollapsibleSection: ProjectOverviewCollapsible[] = []; | ||||||||||||||||||||||||||||||
| lastCollapsibleAction: ProjectOverviewCollapsible | null = null; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // root store | ||||||||||||||||||||||||||||||
| rootStore: CoreRootStore; | ||||||||||||||||||||||||||||||
| // service | ||||||||||||||||||||||||||||||
|
|
@@ -76,6 +81,8 @@ export class ProjectStore implements IProjectStore { | |||||||||||||||||||||||||||||
| isUpdatingProject: observable, | ||||||||||||||||||||||||||||||
| loader: observable.ref, | ||||||||||||||||||||||||||||||
| projectMap: observable, | ||||||||||||||||||||||||||||||
| openCollapsibleSection: observable.ref, | ||||||||||||||||||||||||||||||
| lastCollapsibleAction: observable.ref, | ||||||||||||||||||||||||||||||
| // computed | ||||||||||||||||||||||||||||||
| filteredProjectIds: computed, | ||||||||||||||||||||||||||||||
| workspaceProjectIds: computed, | ||||||||||||||||||||||||||||||
|
|
@@ -85,7 +92,6 @@ export class ProjectStore implements IProjectStore { | |||||||||||||||||||||||||||||
| joinedProjectIds: computed, | ||||||||||||||||||||||||||||||
| favoriteProjectIds: computed, | ||||||||||||||||||||||||||||||
| // fetch actions | ||||||||||||||||||||||||||||||
| fetchProjectEpicProperties: action, | ||||||||||||||||||||||||||||||
| fetchProjects: action, | ||||||||||||||||||||||||||||||
| fetchProjectDetails: action, | ||||||||||||||||||||||||||||||
| // favorites actions | ||||||||||||||||||||||||||||||
|
|
@@ -96,6 +102,10 @@ export class ProjectStore implements IProjectStore { | |||||||||||||||||||||||||||||
| // CRUD actions | ||||||||||||||||||||||||||||||
| createProject: action, | ||||||||||||||||||||||||||||||
| updateProject: action, | ||||||||||||||||||||||||||||||
| // collapsible actions | ||||||||||||||||||||||||||||||
| setOpenCollapsibleSection: action, | ||||||||||||||||||||||||||||||
| setLastCollapsibleAction: action, | ||||||||||||||||||||||||||||||
| toggleOpenCollapsibleSection: action, | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| // root store | ||||||||||||||||||||||||||||||
| this.rootStore = _rootStore; | ||||||||||||||||||||||||||||||
|
|
@@ -214,23 +224,22 @@ export class ProjectStore implements IProjectStore { | |||||||||||||||||||||||||||||
| return projectIds; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| fetchProjectEpicProperties = async (workspaceSlug: string, projectId: string) => { | ||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||
| const response = await this.projectService.fetchProjectEpicProperties(workspaceSlug, projectId); | ||||||||||||||||||||||||||||||
| runInAction(() => { | ||||||||||||||||||||||||||||||
| set(this.projectEpicPropertiesMap, [projectId], response); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| return response; | ||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||
| console.log("Failed to fetch epic properties from project store"); | ||||||||||||||||||||||||||||||
| throw error; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| setOpenCollapsibleSection = (section: ProjectOverviewCollapsible[]) => { | ||||||||||||||||||||||||||||||
| this.openCollapsibleSection = section; | ||||||||||||||||||||||||||||||
| if (this.lastCollapsibleAction) this.lastCollapsibleAction = null; | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| getProjectEpicPropertiesById = computedFn((projectId: string | undefined | null) => { | ||||||||||||||||||||||||||||||
| const projectEpicProperties = this.projectEpicPropertiesMap[projectId ?? ""]; | ||||||||||||||||||||||||||||||
| return projectEpicProperties; | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| setLastCollapsibleAction = (section: ProjectOverviewCollapsible) => { | ||||||||||||||||||||||||||||||
| this.openCollapsibleSection = [section]; | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| toggleOpenCollapsibleSection = (section: ProjectOverviewCollapsible) => { | ||||||||||||||||||||||||||||||
| if (this.openCollapsibleSection && this.openCollapsibleSection.includes(section)) { | ||||||||||||||||||||||||||||||
| this.openCollapsibleSection = this.openCollapsibleSection.filter((s) => s !== section); | ||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||
| this.openCollapsibleSection = [...this.openCollapsibleSection, section]; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
Comment on lines
+236
to
+242
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add null check and use optional chaining. The Apply this diff to improve the implementation: toggleOpenCollapsibleSection = (section: ProjectOverviewCollapsible) => {
- if (this.openCollapsibleSection && this.openCollapsibleSection.includes(section)) {
+ if (this.openCollapsibleSection?.includes(section)) {
this.openCollapsibleSection = this.openCollapsibleSection.filter((s) => s !== section);
} else {
- this.openCollapsibleSection = [...this.openCollapsibleSection, section];
+ this.openCollapsibleSection = [...(this.openCollapsibleSection ?? []), section];
}
};📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (1.9.4)[error] 237-237: Change to an optional chain. Unsafe fix: Change to an optional chain. (lint/complexity/useOptionalChain) |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * get Workspace projects using workspace slug | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Method implementation doesn't match its name.
The
setLastCollapsibleActionmethod not only sets the last action but also modifies theopenCollapsibleSection. This violates the Single Responsibility Principle and is inconsistent with the method name.Consider separating the concerns:
setLastCollapsibleAction = (section: ProjectOverviewCollapsible) => { - this.openCollapsibleSection = [section]; + this.lastCollapsibleAction = section; };