From aafac9ed1dd10469c4c30b7f862cd9407135fdf2 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Thu, 14 Dec 2023 16:45:39 +0530 Subject: [PATCH] chore: state sequence ordering (#3130) --- web/constants/project.ts | 3 +++ web/helpers/state.helper.ts | 14 +++++++++++++- web/store/project/project-state.store.ts | 4 +++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/web/constants/project.ts b/web/constants/project.ts index f8508ad45..1e9a0213e 100644 --- a/web/constants/project.ts +++ b/web/constants/project.ts @@ -51,6 +51,9 @@ export const PROJECT_AUTOMATION_MONTHS = [ { label: "12 Months", value: 12 }, ]; +export const STATE_GROUP_KEYS = ["backlog", "unstarted", "started", "completed", "cancelled"]; + + export const PROJECT_UNSPLASH_COVERS = [ "https://images.unsplash.com/photo-1531045535792-b515d59c3d1f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=870&q=80", "https://images.unsplash.com/photo-1693027407934-e3aa8a54c7ae?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=870&q=80", diff --git a/web/helpers/state.helper.ts b/web/helpers/state.helper.ts index ef6c3ba77..4c443113a 100644 --- a/web/helpers/state.helper.ts +++ b/web/helpers/state.helper.ts @@ -1,7 +1,19 @@ // types -import { IStateResponse } from "types"; +import { STATE_GROUP_KEYS } from "constants/project"; +import { IState, IStateResponse } from "types"; export const orderStateGroups = (unorderedStateGroups: IStateResponse | undefined): IStateResponse | undefined => { if (!unorderedStateGroups) return undefined; return Object.assign({ backlog: [], unstarted: [], started: [], completed: [], cancelled: [] }, unorderedStateGroups); }; + +export const sortStates = (states: IState[]) => { + if (!states || states.length === 0) return null; + + return states.sort((stateA, stateB) => { + if (stateA.group === stateB.group) { + return stateA.sequence - stateB.sequence; + } + return STATE_GROUP_KEYS.indexOf(stateA.group) - STATE_GROUP_KEYS.indexOf(stateB.group); + }); +}; diff --git a/web/store/project/project-state.store.ts b/web/store/project/project-state.store.ts index 2ac6be8ff..1cb1aeb42 100644 --- a/web/store/project/project-state.store.ts +++ b/web/store/project/project-state.store.ts @@ -4,6 +4,8 @@ import { RootStore } from "../root"; import { IState } from "types"; // services import { ProjectService, ProjectStateService } from "services/project"; +// helpers +import { sortStates } from "helpers/state.helper"; import { groupByField } from "helpers/array.helper"; export interface IProjectStateStore { @@ -77,7 +79,7 @@ export class ProjectStateStore implements IProjectStateStore { if (!this.rootStore.project.projectId) return null; const states = this.states[this.rootStore.project.projectId]; if (!states) return null; - return states; + return sortStates(states); } projectStateIds = () => {