* chore: updated project settings state * chore: updated sorting on project state * chore: updated grab handler in state item * chore: Updated UI and added garb handler icon * chore: handled top and bottom sequence in middle element swap * chore: handled input state element char limit to 100 * chore: typos and code cleanup in create state * chore: handled typos and comments wherever is required * chore: handled sorting logic
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
// types
|
|
import { IState, IStateResponse } from "@plane/types";
|
|
import { STATE_GROUPS, TDraggableData } from "@/constants/state";
|
|
|
|
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;
|
|
|
|
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);
|
|
});
|
|
};
|
|
|
|
export const getCurrentStateSequence = (
|
|
groupSates: IState[],
|
|
destinationData: TDraggableData,
|
|
edge: string | undefined
|
|
) => {
|
|
const defaultSequence = 65535;
|
|
if (!edge) return defaultSequence;
|
|
|
|
const currentStateIndex = groupSates.findIndex((state) => state.id === destinationData.id);
|
|
const currentStateSequence = groupSates[currentStateIndex]?.sequence || undefined;
|
|
|
|
if (!currentStateSequence) return defaultSequence;
|
|
|
|
if (edge === "top") {
|
|
const prevStateSequence = groupSates[currentStateIndex - 1]?.sequence || undefined;
|
|
|
|
if (prevStateSequence === undefined) {
|
|
return currentStateSequence - defaultSequence;
|
|
}
|
|
return (currentStateSequence + prevStateSequence) / 2;
|
|
} else if (edge === "bottom") {
|
|
const nextStateSequence = groupSates[currentStateIndex + 1]?.sequence || undefined;
|
|
|
|
if (nextStateSequence === undefined) {
|
|
return currentStateSequence + defaultSequence;
|
|
}
|
|
return (currentStateSequence + nextStateSequence) / 2;
|
|
}
|
|
};
|