Browse Source

fix: update collaborator state issue

pull/7276/head
Ramesh Mane 1 year ago
parent
commit
ddd4117239
  1. 25
      packages/nc-gui/components/project/AccessSettings.vue
  2. 19
      packages/nc-gui/composables/useUserSorts.ts

25
packages/nc-gui/components/project/AccessSettings.vue

@ -7,7 +7,7 @@ import {
extractRolesObj, extractRolesObj,
timeAgo, timeAgo,
} from 'nocodb-sdk' } from 'nocodb-sdk'
import type { WorkspaceUserRoles } from 'nocodb-sdk' import type { Roles, WorkspaceUserRoles } from 'nocodb-sdk'
import InfiniteLoading from 'v3-infinite-loading' import InfiniteLoading from 'v3-infinite-loading'
import { isEeUI, storeToRefs, useUserSorts } from '#imports' import { isEeUI, storeToRefs, useUserSorts } from '#imports'
@ -26,6 +26,7 @@ interface Collaborators {
email: string email: string
main_roles: OrgUserRoles main_roles: OrgUserRoles
roles: ProjectRoles roles: ProjectRoles
base_roles: Roles
workspace_roles: WorkspaceUserRoles workspace_roles: WorkspaceUserRoles
created_at: string created_at: string
} }
@ -91,28 +92,32 @@ const loadListData = async ($state: any) => {
} }
const updateCollaborator = async (collab: any, roles: ProjectRoles) => { const updateCollaborator = async (collab: any, roles: ProjectRoles) => {
const currentCollaborator = collaborators.value.find((coll) => coll.id === collab.id)!
try { try {
if ( if (
!roles || !roles ||
(roles === ProjectRoles.NO_ACCESS && !isEeUI) || (roles === ProjectRoles.NO_ACCESS && !isEeUI) ||
(collab.workspace_roles && WorkspaceRolesToProjectRoles[collab.workspace_roles as WorkspaceUserRoles] === roles && isEeUI) (currentCollaborator.workspace_roles &&
WorkspaceRolesToProjectRoles[currentCollaborator.workspace_roles as WorkspaceUserRoles] === roles &&
isEeUI)
) { ) {
await removeProjectUser(activeProjectId.value!, collab) await removeProjectUser(activeProjectId.value!, collab)
if ( if (
collab.workspace_roles && currentCollaborator.workspace_roles &&
WorkspaceRolesToProjectRoles[collab.workspace_roles as WorkspaceUserRoles] === roles && WorkspaceRolesToProjectRoles[currentCollaborator.workspace_roles as WorkspaceUserRoles] === roles &&
isEeUI isEeUI
) { ) {
collab.roles = WorkspaceRolesToProjectRoles[collab.workspace_roles as WorkspaceUserRoles] currentCollaborator.roles = WorkspaceRolesToProjectRoles[currentCollaborator.workspace_roles as WorkspaceUserRoles]
} else { } else {
collab.roles = ProjectRoles.NO_ACCESS currentCollaborator.roles = ProjectRoles.NO_ACCESS
} }
} else if (collab.base_roles) { } else if (currentCollaborator.base_roles) {
collab.roles = roles currentCollaborator.roles = roles
await updateProjectUser(activeProjectId.value!, collab) await updateProjectUser(activeProjectId.value!, collab)
} else { } else {
collab.roles = roles currentCollaborator.roles = roles
collab.base_roles = roles currentCollaborator.base_roles = roles
await createProjectUser(activeProjectId.value!, collab) await createProjectUser(activeProjectId.value!, collab)
} }
} catch (e: any) { } catch (e: any) {

19
packages/nc-gui/composables/useUserSorts.ts

@ -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]]
} }
} }

Loading…
Cancel
Save