From 0a1e2242736f5f4da7e66282e4a1087d11312c21 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Thu, 15 Sep 2022 20:59:56 +0200 Subject: [PATCH] fix(nc-gui): cleanup sidebar state on scope dispose --- packages/nc-gui/composables/useSidebar/index.ts | 6 +++++- packages/nc-gui/composables/useUIPermission/index.ts | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui/composables/useSidebar/index.ts b/packages/nc-gui/composables/useSidebar/index.ts index c2a83345ae..9a1f678661 100644 --- a/packages/nc-gui/composables/useSidebar/index.ts +++ b/packages/nc-gui/composables/useSidebar/index.ts @@ -1,5 +1,5 @@ import { useStorage } from '@vueuse/core' -import { MemStorage, useInjectionState, watch } from '#imports' +import { MemStorage, onScopeDispose, useInjectionState, watch } from '#imports' interface UseSidebarProps { hasSidebar?: boolean @@ -72,6 +72,10 @@ const useSidebarStorage = () => { export const provideSidebar = (id: string, props: UseSidebarProps = {}) => { const sidebarStorage = useSidebarStorage() + onScopeDispose(() => { + sidebarStorage.remove(id) + }) + if (!sidebarStorage.has(id)) { const sidebar = createSidebar(id, props) diff --git a/packages/nc-gui/composables/useUIPermission/index.ts b/packages/nc-gui/composables/useUIPermission/index.ts index 10bd5b151c..212bf23355 100644 --- a/packages/nc-gui/composables/useUIPermission/index.ts +++ b/packages/nc-gui/composables/useUIPermission/index.ts @@ -1,3 +1,4 @@ +import { isString } from '@vueuse/core' import type { Permission } from './rolePermissions' import rolePermissions from './rolePermissions' import { USER_PROJECT_ROLES, computed, useGlobal, useState } from '#imports' @@ -9,7 +10,7 @@ export function useUIPermission() { const projectRoles = useState>(USER_PROJECT_ROLES, () => ({})) const baseRoles = computed(() => { - let userRoles = typeof user.value?.roles === 'string' ? user.value?.roles : ({ ...(user.value?.roles || {}) } as Roles) + let userRoles = isString(user.value?.roles) ? user.value?.roles : ({ ...(user.value?.roles || {}) } as Roles) // if string populate key-value paired object if (typeof userRoles === 'string') {