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