From d93b548d80deab53277362d86da07fab19deff3f Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Tue, 2 Jan 2024 08:15:24 +0000 Subject: [PATCH] fix: small changes --- .../nc-gui/components/account/UserList.vue | 5 ++--- .../nc-gui/components/account/UserMenu.vue | 2 +- .../components/project/AccessSettings.vue | 4 ++-- packages/nc-gui/composables/useUserSorts.ts | 18 ++++++++++-------- packages/nc-gui/lang/en.json | 3 +-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/nc-gui/components/account/UserList.vue b/packages/nc-gui/components/account/UserList.vue index 7cf2fae139..b73f89c4d8 100644 --- a/packages/nc-gui/components/account/UserList.vue +++ b/packages/nc-gui/components/account/UserList.vue @@ -28,12 +28,12 @@ const { user: loggedInUser } = useGlobal() const { copy } = useCopy() -const { sorts, sortDirection, loadSorts, saveOrUpdate, handleGetSortsData } = useUserSorts('Org') +const { sorts, sortDirection, loadSorts, saveOrUpdate, handleGetSortedData } = useUserSorts('Org') const users = ref([]) const sortedUsers = computed(() => { - return handleGetSortsData(users.value, sorts.value) as UserType[] + return handleGetSortedData(users.value, sorts.value) as UserType[] }) const currentPage = ref(1) @@ -93,7 +93,6 @@ const updateRole = async (userId: string, roles: string) => { if (user.id === userId) { user.roles = roles } - return user }) $e('a:org-user:role-updated', { role: roles }) diff --git a/packages/nc-gui/components/account/UserMenu.vue b/packages/nc-gui/components/account/UserMenu.vue index dcaa2425eb..f125eeae3b 100644 --- a/packages/nc-gui/components/account/UserMenu.vue +++ b/packages/nc-gui/components/account/UserMenu.vue @@ -10,7 +10,7 @@ const { field, direction, handleUserSort } = defineProps<{ const isOpen = ref(false) -const sortUserBy = async (direction?: UsersSortType['direction']) => { +const sortUserBy = (direction?: UsersSortType['direction']) => { handleUserSort({ field, direction, diff --git a/packages/nc-gui/components/project/AccessSettings.vue b/packages/nc-gui/components/project/AccessSettings.vue index 6a6f182931..1cc3c8899c 100644 --- a/packages/nc-gui/components/project/AccessSettings.vue +++ b/packages/nc-gui/components/project/AccessSettings.vue @@ -18,7 +18,7 @@ const { activeProjectId } = storeToRefs(basesStore) 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]) @@ -40,7 +40,7 @@ const isSearching = ref(false) const accessibleRoles = ref<(typeof ProjectRoles)[keyof typeof ProjectRoles][]>([]) const sortedCollaborators = computed(() => { - return handleGetSortsData(collaborators.value, sorts.value) + return handleGetSortedData(collaborators.value, sorts.value) }) const loadCollaborators = async () => { diff --git a/packages/nc-gui/composables/useUserSorts.ts b/packages/nc-gui/composables/useUserSorts.ts index 73c021baeb..0907e16361 100644 --- a/packages/nc-gui/composables/useUserSorts.ts +++ b/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) if (sortConfig && isValidSortConfig(sortConfig)) { - sorts.value = sortConfig // Load user-specific sort configurations or default configurations sorts.value = user.value?.id ? sortConfig[user.value.id] || {} : sortConfig[defaultUserId] || {} } else { - // remove sortConfig from localStorage if it's invalid - localStorage.removeItem(userSortConfigKey) - sorts.value = {} + throw new Error('Invalid sort config stored in local storage') } - } 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 sorts.value = {} } @@ -88,7 +90,7 @@ export function useUserSorts(roleType: 'Workspace' | 'Org' | 'Project') { localStorage.setItem(userSortConfigKey, JSON.stringify(sortConfig)) } 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. * @template T - The type of objects in the input array. */ - function handleGetSortsData>(data: T[], sortsConfig: UsersSortType = sorts.value): T[] { + function handleGetSortedData>(data: T[], sortsConfig: UsersSortType = sorts.value): T[] { let userRoleOrder: string[] = [] if (roleType === 'Workspace') { userRoleOrder = Object.values(WorkspaceUserRoles) @@ -171,5 +173,5 @@ export function useUserSorts(roleType: 'Workspace' | 'Org' | 'Project') { return true } - return { sorts, sortDirection, loadSorts, saveOrUpdate, handleGetSortsData } + return { sorts, sortDirection, loadSorts, saveOrUpdate, handleGetSortedData } } diff --git a/packages/nc-gui/lang/en.json b/packages/nc-gui/lang/en.json index ae26001223..bd37f1b56e 100644 --- a/packages/nc-gui/lang/en.json +++ b/packages/nc-gui/lang/en.json @@ -189,8 +189,7 @@ "shift": "Shift", "enter": "Enter", "seconds": "Seconds", - "paste": "Paste", - "resetSort": "Reset Sort" + "paste": "Paste" }, "objects": { "workspace": "Workspace",