Browse Source

fix: small changes

feat/user-management-sort
Ramesh Mane 9 months ago
parent
commit
f8ad8c155d
  1. 5
      packages/nc-gui/components/account/UserList.vue
  2. 2
      packages/nc-gui/components/account/UserMenu.vue
  3. 4
      packages/nc-gui/components/project/AccessSettings.vue
  4. 18
      packages/nc-gui/composables/useUserSorts.ts
  5. 3
      packages/nc-gui/lang/en.json

5
packages/nc-gui/components/account/UserList.vue

@ -28,12 +28,12 @@ const { user: loggedInUser } = useGlobal()
const { copy } = useCopy() const { copy } = useCopy()
const { sorts, sortDirection, loadSorts, saveOrUpdate, handleGetSortsData } = useUserSorts('Org') const { sorts, sortDirection, loadSorts, saveOrUpdate, handleGetSortedData } = useUserSorts('Org')
const users = ref<UserType[]>([]) const users = ref<UserType[]>([])
const sortedUsers = computed(() => { const sortedUsers = computed(() => {
return handleGetSortsData(users.value, sorts.value) as UserType[] return handleGetSortedData(users.value, sorts.value) as UserType[]
}) })
const currentPage = ref(1) const currentPage = ref(1)
@ -93,7 +93,6 @@ const updateRole = async (userId: string, roles: string) => {
if (user.id === userId) { if (user.id === userId) {
user.roles = roles user.roles = roles
} }
return user
}) })
$e('a:org-user:role-updated', { role: roles }) $e('a:org-user:role-updated', { role: roles })

2
packages/nc-gui/components/account/UserMenu.vue

@ -10,7 +10,7 @@ const { field, direction, handleUserSort } = defineProps<{
const isOpen = ref(false) const isOpen = ref(false)
const sortUserBy = async (direction?: UsersSortType['direction']) => { const sortUserBy = (direction?: UsersSortType['direction']) => {
handleUserSort({ handleUserSort({
field, field,
direction, direction,

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

@ -17,7 +17,7 @@ const { activeProjectId } = storeToRefs(basesStore)
const { orgRoles, baseRoles } = useRoles() const { orgRoles, baseRoles } = useRoles()
const { sorts, sortDirection, loadSorts, saveOrUpdate, handleGetSortsData } = useUserSorts('Project') const { sorts, sortDirection, loadSorts, saveOrUpdate, handleGetSortedData } = useUserSorts('Project')
const isSuper = computed(() => orgRoles.value?.[OrgUserRoles.SUPER_ADMIN]) const isSuper = computed(() => orgRoles.value?.[OrgUserRoles.SUPER_ADMIN])
@ -40,7 +40,7 @@ const isSearching = ref(false)
const accessibleRoles = ref<(typeof ProjectRoles)[keyof typeof ProjectRoles][]>([]) const accessibleRoles = ref<(typeof ProjectRoles)[keyof typeof ProjectRoles][]>([])
const sortedCollaborators = computed(() => { const sortedCollaborators = computed(() => {
return handleGetSortsData(collaborators.value, sorts.value) return handleGetSortedData(collaborators.value, sorts.value)
}) })
const loadCollaborators = async () => { const loadCollaborators = async () => {

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

@ -44,15 +44,17 @@ export function useUserSorts(roleType: 'Workspace' | 'Org' | 'Project') {
const sortConfig = storedConfig ? JSON.parse(storedConfig) : ({} as Record<string, UsersSortType>) const sortConfig = storedConfig ? JSON.parse(storedConfig) : ({} as Record<string, UsersSortType>)
if (sortConfig && isValidSortConfig(sortConfig)) { if (sortConfig && isValidSortConfig(sortConfig)) {
sorts.value = sortConfig
// Load user-specific sort configurations or default configurations // Load user-specific sort configurations or default configurations
sorts.value = user.value?.id ? sortConfig[user.value.id] || {} : sortConfig[defaultUserId] || {} sorts.value = user.value?.id ? sortConfig[user.value.id] || {} : sortConfig[defaultUserId] || {}
} else { } else {
// remove sortConfig from localStorage if it's invalid throw new Error('Invalid sort config stored in local storage')
localStorage.removeItem(userSortConfigKey)
sorts.value = {}
} }
} catch { } catch (error) {
console.error(error)
// remove sortConfig from localStorage in case of error
localStorage.removeItem(userSortConfigKey)
// Set sorts to an empty obj in case of an error // Set sorts to an empty obj in case of an error
sorts.value = {} sorts.value = {}
} }
@ -88,7 +90,7 @@ export function useUserSorts(roleType: 'Workspace' | 'Org' | 'Project') {
localStorage.setItem(userSortConfigKey, JSON.stringify(sortConfig)) localStorage.setItem(userSortConfigKey, JSON.stringify(sortConfig))
} catch (error) { } catch (error) {
console.error('Error while retrieving sort configuration from local storage:', error) console.error('Error while saving sort configuration into local storage:', error)
} }
} }
@ -100,7 +102,7 @@ export function useUserSorts(roleType: 'Workspace' | 'Org' | 'Project') {
* @returns A new array containing sorted objects. * @returns A new array containing sorted objects.
* @template T - The type of objects in the input array. * @template T - The type of objects in the input array.
*/ */
function handleGetSortsData<T extends Record<string, any>>(data: T[], sortsConfig: UsersSortType = sorts.value): T[] { function handleGetSortedData<T extends Record<string, any>>(data: T[], sortsConfig: UsersSortType = sorts.value): T[] {
let userRoleOrder: string[] = [] let userRoleOrder: string[] = []
if (roleType === 'Workspace') { if (roleType === 'Workspace') {
userRoleOrder = Object.values(WorkspaceUserRoles) userRoleOrder = Object.values(WorkspaceUserRoles)
@ -171,5 +173,5 @@ export function useUserSorts(roleType: 'Workspace' | 'Org' | 'Project') {
return true return true
} }
return { sorts, sortDirection, loadSorts, saveOrUpdate, handleGetSortsData } return { sorts, sortDirection, loadSorts, saveOrUpdate, handleGetSortedData }
} }

3
packages/nc-gui/lang/en.json

@ -189,8 +189,7 @@
"shift": "Shift", "shift": "Shift",
"enter": "Enter", "enter": "Enter",
"seconds": "Seconds", "seconds": "Seconds",
"paste": "Paste", "paste": "Paste"
"resetSort": "Reset Sort"
}, },
"objects": { "objects": {
"workspace": "Workspace", "workspace": "Workspace",

Loading…
Cancel
Save