2023-02-08 13:21:03 +00:00
|
|
|
// types
|
2023-04-22 12:49:35 +00:00
|
|
|
import { IState, IStateResponse } from "types";
|
2023-02-08 13:21:03 +00:00
|
|
|
|
2023-07-26 17:50:44 +00:00
|
|
|
export const orderStateGroups = (
|
|
|
|
unorderedStateGroups: IStateResponse | undefined
|
|
|
|
): IStateResponse | undefined => {
|
|
|
|
if (!unorderedStateGroups) return undefined;
|
|
|
|
|
|
|
|
return Object.assign(
|
2023-02-08 13:21:03 +00:00
|
|
|
{ backlog: [], unstarted: [], started: [], completed: [], cancelled: [] },
|
|
|
|
unorderedStateGroups
|
|
|
|
);
|
2023-07-26 17:50:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const getStatesList = (stateGroups: IStateResponse | undefined): IState[] | undefined => {
|
|
|
|
if (!stateGroups) return undefined;
|
2023-02-08 13:21:03 +00:00
|
|
|
|
|
|
|
// order the unordered state groups first
|
2023-02-08 18:28:17 +00:00
|
|
|
const orderedStateGroups = orderStateGroups(stateGroups);
|
2023-02-08 13:21:03 +00:00
|
|
|
|
2023-07-26 17:50:44 +00:00
|
|
|
if (!orderedStateGroups) return undefined;
|
|
|
|
|
2023-02-08 13:21:03 +00:00
|
|
|
// extract states from the groups and return them
|
|
|
|
return Object.keys(orderedStateGroups)
|
|
|
|
.map((group) => [...orderedStateGroups[group].map((state: IState) => state)])
|
|
|
|
.flat();
|
|
|
|
};
|