forked from github/plane
fix: project states fixes (#2731)
* fix: project states fixes * fix: states fixes * fix: formating all files
This commit is contained in:
committed by
GitHub
parent
bd1a850f35
commit
20fb79567f
@@ -7,11 +7,7 @@ export const groupBy = (array: any[], key: string) => {
|
||||
}, {});
|
||||
};
|
||||
|
||||
export const orderArrayBy = (
|
||||
orgArray: any[],
|
||||
key: string,
|
||||
ordering: "ascending" | "descending" = "ascending"
|
||||
) => {
|
||||
export const orderArrayBy = (orgArray: any[], key: string, ordering: "ascending" | "descending" = "ascending") => {
|
||||
if (!orgArray || !Array.isArray(orgArray) || orgArray.length === 0) return [];
|
||||
|
||||
const array = [...orgArray];
|
||||
@@ -53,3 +49,28 @@ export const checkIfArraysHaveSameElements = (arr1: any[] | null, arr2: any[] |
|
||||
|
||||
return arr1.length === arr2.length && arr1.every((e) => arr2.includes(e));
|
||||
};
|
||||
|
||||
type GroupedItems<T> = { [key: string]: T[] };
|
||||
|
||||
export const groupByField = <T>(array: T[], field: keyof T): GroupedItems<T> =>
|
||||
array.reduce((grouped: GroupedItems<T>, item: T) => {
|
||||
const key = String(item[field]);
|
||||
grouped[key] = (grouped[key] || []).concat(item);
|
||||
return grouped;
|
||||
}, {});
|
||||
|
||||
export const sortByField = (array: any[], field: string): any[] =>
|
||||
array.sort((a, b) => (a[field] < b[field] ? -1 : a[field] > b[field] ? 1 : 0));
|
||||
|
||||
export const orderGroupedDataByField = <T>(groupedData: GroupedItems<T>, orderBy: keyof T): GroupedItems<T> => {
|
||||
for (const key in groupedData) {
|
||||
if (groupedData.hasOwnProperty(key)) {
|
||||
groupedData[key] = groupedData[key].sort((a, b) => {
|
||||
if (a[orderBy] < b[orderBy]) return -1;
|
||||
if (a[orderBy] > b[orderBy]) return 1;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
return groupedData;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export const getFileExtension = (filename: string) =>
|
||||
filename.slice(((filename.lastIndexOf(".") - 1) >>> 0) + 2);
|
||||
export const getFileExtension = (filename: string) => filename.slice(((filename.lastIndexOf(".") - 1) >>> 0) + 2);
|
||||
|
||||
export const getFileName = (fileName: string) => {
|
||||
const dotIndex = fileName.lastIndexOf(".");
|
||||
|
||||
@@ -17,6 +17,4 @@ export const debounce = (func: any, wait: number, immediate: boolean = false) =>
|
||||
};
|
||||
};
|
||||
|
||||
export const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL
|
||||
? process.env.NEXT_PUBLIC_API_BASE_URL
|
||||
: "";
|
||||
export const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL ? process.env.NEXT_PUBLIC_API_BASE_URL : "";
|
||||
|
||||
@@ -41,13 +41,16 @@ export const groupReactions: (reactions: any[], key: string) => { [key: string]:
|
||||
reactions: any,
|
||||
key: string
|
||||
) => {
|
||||
const groupedReactions = reactions.reduce((acc: any, reaction: any) => {
|
||||
if (!acc[reaction[key]]) {
|
||||
acc[reaction[key]] = [];
|
||||
}
|
||||
acc[reaction[key]].push(reaction);
|
||||
return acc;
|
||||
}, {} as { [key: string]: any[] });
|
||||
const groupedReactions = reactions.reduce(
|
||||
(acc: any, reaction: any) => {
|
||||
if (!acc[reaction[key]]) {
|
||||
acc[reaction[key]] = [];
|
||||
}
|
||||
acc[reaction[key]].push(reaction);
|
||||
return acc;
|
||||
},
|
||||
{} as { [key: string]: any[] }
|
||||
);
|
||||
|
||||
return groupedReactions;
|
||||
};
|
||||
|
||||
@@ -1,27 +1,7 @@
|
||||
// types
|
||||
import { IState, IStateResponse } from "types";
|
||||
import { IStateResponse } from "types";
|
||||
|
||||
export const orderStateGroups = (
|
||||
unorderedStateGroups: IStateResponse | undefined
|
||||
): IStateResponse | undefined => {
|
||||
export const orderStateGroups = (unorderedStateGroups: IStateResponse | undefined): IStateResponse | undefined => {
|
||||
if (!unorderedStateGroups) return undefined;
|
||||
|
||||
return Object.assign(
|
||||
{ backlog: [], unstarted: [], started: [], completed: [], cancelled: [] },
|
||||
unorderedStateGroups
|
||||
);
|
||||
};
|
||||
|
||||
export const getStatesList = (stateGroups: IStateResponse | undefined): IState[] | undefined => {
|
||||
if (!stateGroups) return undefined;
|
||||
|
||||
// order the unordered state groups first
|
||||
const orderedStateGroups = orderStateGroups(stateGroups);
|
||||
|
||||
if (!orderedStateGroups) return undefined;
|
||||
|
||||
// extract states from the groups and return them
|
||||
return Object.keys(orderedStateGroups)
|
||||
.map((group) => [...orderedStateGroups[group].map((state: IState) => state)])
|
||||
.flat();
|
||||
return Object.assign({ backlog: [], unstarted: [], started: [], completed: [], cancelled: [] }, unorderedStateGroups);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user