|
|
@ -5,7 +5,9 @@ import { useGlobal } from '#imports' |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Hook for managing user sorts and sort configurations. |
|
|
|
* Hook for managing user sorts and sort configurations. |
|
|
|
* @returns An object containing reactive values and functions related to user sorts. |
|
|
|
* |
|
|
|
|
|
|
|
* @param {string} roleType - The type of role for which user sorts are managed ('Workspace', 'Org', or 'Project'). |
|
|
|
|
|
|
|
* @returns {object} An object containing reactive values and functions related to user sorts. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
export function useUserSorts(roleType: 'Workspace' | 'Org' | 'Project') { |
|
|
|
export function useUserSorts(roleType: 'Workspace' | 'Org' | 'Project') { |
|
|
|
const clone = rfdc() |
|
|
|
const clone = rfdc() |
|
|
@ -107,10 +109,10 @@ export function useUserSorts(roleType: 'Workspace' | 'Org' | 'Project') { |
|
|
|
|
|
|
|
|
|
|
|
const superUserIndex = data.findIndex((user) => user?.roles?.includes('super')) |
|
|
|
const superUserIndex = data.findIndex((user) => user?.roles?.includes('super')) |
|
|
|
const superUser = superUserIndex !== -1 ? data.splice(superUserIndex, 1) : null |
|
|
|
const superUser = superUserIndex !== -1 ? data.splice(superUserIndex, 1) : null |
|
|
|
// console.log('super', superUser)
|
|
|
|
|
|
|
|
let sortedData = data.sort((a, b) => { |
|
|
|
let sortedData = data.sort((a, b) => { |
|
|
|
switch (sortsConfig.field) { |
|
|
|
switch (sortsConfig.field) { |
|
|
|
case 'roles': |
|
|
|
case 'roles': { |
|
|
|
const roleA = a?.roles?.split(',')[0] |
|
|
|
const roleA = a?.roles?.split(',')[0] |
|
|
|
const roleB = b?.roles?.split(',')[0] |
|
|
|
const roleB = b?.roles?.split(',')[0] |
|
|
|
|
|
|
|
|
|
|
@ -119,23 +121,24 @@ export function useUserSorts(roleType: 'Workspace' | 'Org' | 'Project') { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return userRoleOrder.indexOf(roleB) - userRoleOrder.indexOf(roleA) |
|
|
|
return userRoleOrder.indexOf(roleB) - userRoleOrder.indexOf(roleA) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
case 'email': |
|
|
|
case 'email': { |
|
|
|
if (sortsConfig.direction === 'asc') { |
|
|
|
if (sortsConfig.direction === 'asc') { |
|
|
|
return a[sortsConfig.field]?.localeCompare(b[sortsConfig.field]) |
|
|
|
return a[sortsConfig.field]?.localeCompare(b[sortsConfig.field]) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return b[sortsConfig.field]?.localeCompare(a[sortsConfig.field]) |
|
|
|
return b[sortsConfig.field]?.localeCompare(a[sortsConfig.field]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0 |
|
|
|
return 0 |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
if (superUser && superUser.length) { |
|
|
|
if (superUser && superUser.length) { |
|
|
|
if (sortsConfig.direction === 'desc') { |
|
|
|
if (sortsConfig.direction === 'asc') { |
|
|
|
sortedData = [...sortedData, superUser[0]] |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
sortedData = [superUser[0], ...sortedData] |
|
|
|
sortedData = [superUser[0], ...sortedData] |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
sortedData = [...sortedData, superUser[0]] |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|