Skip to content
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

chore: state ordering sequence in kanban and list layout #3130

Merged
merged 1 commit into from
Dec 14, 2023
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
3 changes: 3 additions & 0 deletions web/constants/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 13 additions & 1 deletion web/helpers/state.helper.ts
Original file line number Diff line number Diff line change
@@ -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);
});
};
4 changes: 3 additions & 1 deletion web/store/project/project-state.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = () => {
Expand Down
Loading