[WEB-2192] fix: order of state groups in space app (#5317)
* chore: added sequence in the states endpoint * fix state grouping order in space app --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
This commit is contained in:
parent
806eae0139
commit
91142659ca
4 changed files with 33 additions and 12 deletions
|
|
@ -27,14 +27,11 @@ class ProjectStatesEndpoint(BaseAPIView):
|
||||||
status=status.HTTP_404_NOT_FOUND,
|
status=status.HTTP_404_NOT_FOUND,
|
||||||
)
|
)
|
||||||
|
|
||||||
states = (
|
states = State.objects.filter(
|
||||||
State.objects.filter(
|
~Q(name="Triage"),
|
||||||
~Q(name="Triage"),
|
workspace__slug=deploy_board.workspace.slug,
|
||||||
workspace__slug=deploy_board.workspace.slug,
|
project_id=deploy_board.project_id,
|
||||||
project_id=deploy_board.project_id,
|
).values("name", "group", "color", "id", "sequence")
|
||||||
)
|
|
||||||
.values("name", "group", "color", "id")
|
|
||||||
)
|
|
||||||
|
|
||||||
return Response(
|
return Response(
|
||||||
states,
|
states,
|
||||||
|
|
|
||||||
|
|
@ -109,10 +109,10 @@ const getModuleColumns = (moduleStore: IIssueModuleStore): IGroupByColumn[] | un
|
||||||
};
|
};
|
||||||
|
|
||||||
const getStateColumns = (projectState: IStateStore): IGroupByColumn[] | undefined => {
|
const getStateColumns = (projectState: IStateStore): IGroupByColumn[] | undefined => {
|
||||||
const { states } = projectState;
|
const { sortedStates } = projectState;
|
||||||
if (!states) return;
|
if (!sortedStates) return;
|
||||||
|
|
||||||
return states.map((state) => ({
|
return sortedStates.map((state) => ({
|
||||||
id: state.id,
|
id: state.id,
|
||||||
name: state.name,
|
name: state.name,
|
||||||
icon: (
|
icon: (
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
import { action, makeObservable, observable, runInAction } from "mobx";
|
import clone from "lodash/clone";
|
||||||
|
import { action, computed, makeObservable, observable, runInAction } from "mobx";
|
||||||
import { IState } from "@plane/types";
|
import { IState } from "@plane/types";
|
||||||
|
import { sortStates } from "@/helpers/state.helper";
|
||||||
import { StateService } from "@/services/state.service";
|
import { StateService } from "@/services/state.service";
|
||||||
import { CoreRootStore } from "./root.store";
|
import { CoreRootStore } from "./root.store";
|
||||||
|
|
||||||
export interface IStateStore {
|
export interface IStateStore {
|
||||||
// observables
|
// observables
|
||||||
states: IState[] | undefined;
|
states: IState[] | undefined;
|
||||||
|
//computed
|
||||||
|
sortedStates: IState[] | undefined;
|
||||||
// computed actions
|
// computed actions
|
||||||
getStateById: (stateId: string | undefined) => IState | undefined;
|
getStateById: (stateId: string | undefined) => IState | undefined;
|
||||||
// fetch actions
|
// fetch actions
|
||||||
|
|
@ -21,6 +25,8 @@ export class StateStore implements IStateStore {
|
||||||
makeObservable(this, {
|
makeObservable(this, {
|
||||||
// observables
|
// observables
|
||||||
states: observable,
|
states: observable,
|
||||||
|
// computed
|
||||||
|
sortedStates: computed,
|
||||||
// fetch action
|
// fetch action
|
||||||
fetchStates: action,
|
fetchStates: action,
|
||||||
});
|
});
|
||||||
|
|
@ -28,6 +34,11 @@ export class StateStore implements IStateStore {
|
||||||
this.rootStore = _rootStore;
|
this.rootStore = _rootStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get sortedStates() {
|
||||||
|
if (!this.states) return;
|
||||||
|
return sortStates(clone(this.states));
|
||||||
|
}
|
||||||
|
|
||||||
getStateById = (stateId: string | undefined) => this.states?.find((state) => state.id === stateId);
|
getStateById = (stateId: string | undefined) => this.states?.find((state) => state.id === stateId);
|
||||||
|
|
||||||
fetchStates = async (anchor: string) => {
|
fetchStates = async (anchor: string) => {
|
||||||
|
|
|
||||||
13
space/helpers/state.helper.ts
Normal file
13
space/helpers/state.helper.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { IState } from "@plane/types";
|
||||||
|
import { STATE_GROUPS } from "@/constants/state";
|
||||||
|
|
||||||
|
export const sortStates = (states: IState[]) => {
|
||||||
|
if (!states || states.length === 0) return;
|
||||||
|
|
||||||
|
return states.sort((stateA, stateB) => {
|
||||||
|
if (stateA.group === stateB.group) {
|
||||||
|
return stateA.sequence - stateB.sequence;
|
||||||
|
}
|
||||||
|
return Object.keys(STATE_GROUPS).indexOf(stateA.group) - Object.keys(STATE_GROUPS).indexOf(stateB.group);
|
||||||
|
});
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue