init
This commit is contained in:
34
worklenz-frontend/src/utils/sort-team-members.ts
Normal file
34
worklenz-frontend/src/utils/sort-team-members.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
export const sortByBooleanField = <T extends Record<string, any>>(
|
||||
data: T[],
|
||||
field: keyof T,
|
||||
prioritizeTrue: boolean = true
|
||||
) => {
|
||||
return [...data].sort((a, b) => {
|
||||
const aValue = !!a[field];
|
||||
const bValue = !!b[field];
|
||||
|
||||
if (aValue === bValue) return 0;
|
||||
if (prioritizeTrue) {
|
||||
return aValue ? -1 : 1;
|
||||
} else {
|
||||
return !aValue ? -1 : 1;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const sortBySelection = (data: Array<{ selected?: boolean }>) =>
|
||||
sortByBooleanField(data, 'selected');
|
||||
|
||||
export const sortByPending = (data: Array<{ pending_invitation?: boolean }>) =>
|
||||
sortByBooleanField(data, 'pending_invitation', false);
|
||||
|
||||
export const sortTeamMembers = (data: Array<{ selected?: boolean; pending_invitation?: boolean; is_pending?: boolean }>) => {
|
||||
return sortByBooleanField(
|
||||
sortByBooleanField(
|
||||
sortByBooleanField(data, 'is_pending', false),
|
||||
'pending_invitation',
|
||||
false
|
||||
),
|
||||
'selected'
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user