|
|
@ -1,7 +1,7 @@ |
|
|
|
import rfdc from 'rfdc' |
|
|
|
import rfdc from 'rfdc' |
|
|
|
|
|
|
|
import { OrgUserRoles, ProjectRoles, WorkspaceUserRoles } from 'nocodb-sdk' |
|
|
|
import type { UsersSortType } from '~/lib' |
|
|
|
import type { UsersSortType } from '~/lib' |
|
|
|
import { useGlobal } from '#imports' |
|
|
|
import { useGlobal } from '#imports' |
|
|
|
import { extractRolesObj, ProjectRoles, OrgUserRoles, WorkspaceUserRoles } from 'nocodb-sdk' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Hook for managing user sorts and sort configurations. |
|
|
|
* Hook for managing user sorts and sort configurations. |
|
|
@ -105,28 +105,27 @@ export function useUserSorts(roleType: 'Workspace' | 'Org' | 'Project') { |
|
|
|
|
|
|
|
|
|
|
|
data = clone(data) |
|
|
|
data = clone(data) |
|
|
|
|
|
|
|
|
|
|
|
let superUserIndex = data.findIndex((user) => user?.roles?.includes('super')) |
|
|
|
const superUserIndex = data.findIndex((user) => user?.roles?.includes('super')) |
|
|
|
let superUser = superUserIndex !== -1 ? data.splice(superUserIndex, 1) : null |
|
|
|
const superUser = superUserIndex !== -1 ? data.splice(superUserIndex, 1) : null |
|
|
|
// console.log('super', superUser)
|
|
|
|
// 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] |
|
|
|
|
|
|
|
|
|
|
|
if (sortsConfig.direction === 'asc') { |
|
|
|
if (sortsConfig.direction === 'asc') { |
|
|
|
return userRoleOrder.indexOf(roleA) - userRoleOrder.indexOf(roleB) |
|
|
|
return userRoleOrder.indexOf(roleA) - userRoleOrder.indexOf(roleB) |
|
|
|
} else if (sortsConfig.direction === 'desc') { |
|
|
|
} 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 if (sortsConfig.direction === 'desc') { |
|
|
|
} else { |
|
|
|
return b[sortsConfig.field]?.localeCompare(a[sortsConfig.field]) |
|
|
|
return b[sortsConfig.field]?.localeCompare(a[sortsConfig.field]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0 |
|
|
|
return 0 |
|
|
|