diff --git a/apps/web/src/common/composables/current-menu-id/index.ts b/apps/web/src/common/composables/current-menu-id/index.ts index b34a729948..e26eacdb13 100644 --- a/apps/web/src/common/composables/current-menu-id/index.ts +++ b/apps/web/src/common/composables/current-menu-id/index.ts @@ -1,3 +1,5 @@ +import type { Ref } from 'vue'; +import { computed, reactive, toRef } from 'vue'; import { useRoute } from 'vue-router/composables'; import { clone } from 'lodash'; @@ -5,15 +7,22 @@ import { clone } from 'lodash'; import { MENU_ID } from '@/lib/menu/config'; -import { COST_EXPLORER_ROUTE } from '@/services/cost-explorer/routes/route-constant'; +interface UseCurrentMenuIdReturnType { + currentMenuId: Ref; +} -export const useCurrentMenuId = (): string => { +export const useCurrentMenuId = (): UseCurrentMenuIdReturnType => { const route = useRoute(); - const reversedMatched = clone(route.matched).reverse(); - const closestRoute = reversedMatched.find((d) => d.meta?.menuId !== undefined); - const targetMenuId = closestRoute?.meta?.menuId || MENU_ID.WORKSPACE_HOME; - if (route.name === COST_EXPLORER_ROUTE.LANDING._NAME) { - return ''; - } - return targetMenuId; + + const state = reactive({ + currentMenuId: computed(() => { + const reversedMatched = clone(route.matched).reverse(); + const closestRoute = reversedMatched.find((d) => d.meta?.menuId !== undefined); + return closestRoute?.meta?.menuId || MENU_ID.WORKSPACE_HOME; + }), + }); + + return { + currentMenuId: toRef(state, 'currentMenuId'), + }; }; diff --git a/apps/web/src/common/composables/page-editable-status/index.ts b/apps/web/src/common/composables/page-editable-status/index.ts index ccf767d09a..a77d60f18c 100644 --- a/apps/web/src/common/composables/page-editable-status/index.ts +++ b/apps/web/src/common/composables/page-editable-status/index.ts @@ -1,4 +1,5 @@ -import { computed, reactive } from 'vue'; +import type { Ref } from 'vue'; +import { computed, reactive, toRef } from 'vue'; import { useUserStore } from '@/store/user/user-store'; @@ -6,13 +7,25 @@ import type { PageAccessMap } from '@/lib/access-control/config'; import { useCurrentMenuId } from '@/common/composables/current-menu-id'; -export const usePageEditableStatus = (): boolean|undefined => { +interface UsePageEditableStatusReturnType { + hasReadWriteAccess: Ref; +} + +export const usePageEditableStatus = (): UsePageEditableStatusReturnType => { const userStore = useUserStore(); const userGetters = userStore.getters; + const { currentMenuId } = useCurrentMenuId(); + const storeState = reactive({ pageAccessPermissionMap: computed(() => userGetters.pageAccessPermissionMap), }); - return storeState.pageAccessPermissionMap[useCurrentMenuId()]?.write; + const state = reactive({ + hasReadWriteAccess: computed(() => storeState.pageAccessPermissionMap[currentMenuId.value]?.write), + }); + + return { + hasReadWriteAccess: toRef(state, 'hasReadWriteAccess'), + }; }; diff --git a/apps/web/src/common/modules/navigations/gnb/GNBNavigationRail.vue b/apps/web/src/common/modules/navigations/gnb/GNBNavigationRail.vue index 3a370213dd..39f5b9bb7c 100644 --- a/apps/web/src/common/modules/navigations/gnb/GNBNavigationRail.vue +++ b/apps/web/src/common/modules/navigations/gnb/GNBNavigationRail.vue @@ -49,6 +49,8 @@ const route = useRoute(); const router = useRouter(); const { width } = useWindowSize(); +const { currentMenuId } = useCurrentMenuId(); + const storeState = reactive({ isHideNavRail: computed(() => gnbGetters.isHideNavRail), isMinimizeNavRail: computed(() => gnbGetters.isMinimizeNavRail), @@ -89,6 +91,12 @@ const state = reactive({ }); return result; }), + selectedMenuId: computed(() => { + if (route.name === COST_EXPLORER_ROUTE.LANDING._NAME) { + return ''; + } + return currentMenuId.value; + }), }); const handleMouseEvent = (value: boolean) => { @@ -157,7 +165,7 @@ onMounted(async () => { :to="(item.type === 'header' && item.subMenuList?.length > 0) ? '' : item.to" class="service-menu" :class="{ - 'is-selected': useCurrentMenuId().split('.').includes(item.id) && item.type !== 'header', + 'is-selected': state.selectedMenuId.split('.').includes(item.id) && item.type !== 'header', 'is-only-label': item.type === 'header' && item.subMenuList?.length > 0 }" > diff --git a/apps/web/src/common/modules/navigations/top-bar/modules/top-bar-header/TopBarWorkspaces.vue b/apps/web/src/common/modules/navigations/top-bar/modules/top-bar-header/TopBarWorkspaces.vue index 0ac1cff949..1e3ded313f 100644 --- a/apps/web/src/common/modules/navigations/top-bar/modules/top-bar-header/TopBarWorkspaces.vue +++ b/apps/web/src/common/modules/navigations/top-bar/modules/top-bar-header/TopBarWorkspaces.vue @@ -53,6 +53,8 @@ const favoriteStore = useFavoriteStore(); const favoriteGetters = favoriteStore.getters; const recentStore = useRecentStore(); +const { currentMenuId } = useCurrentMenuId(); + const router = useRouter(); const selectDropdownRef = ref(null); @@ -79,9 +81,8 @@ const selectWorkspace = (name: string): void => { if (!workspaceId || workspaceId === storeState.currentWorkspaceId) return; appContextStore.setGlobalGrantLoading(true); - const targetMenuId: string = useCurrentMenuId(); userWorkspaceStore.setCurrentWorkspace(workspaceId); - router.push({ name: MENU_INFO_MAP[targetMenuId].routeName, params: { workspaceId } }).catch(() => {}); + router.push({ name: MENU_INFO_MAP[currentMenuId.value].routeName, params: { workspaceId } }).catch(() => {}); }; const formatMenuItems = (menuItems: WorkspaceModel[] = []): MenuItem[] => { const result = menuItems.length > 0 ? [ diff --git a/apps/web/src/services/advanced/AdvancedLSB.vue b/apps/web/src/services/advanced/AdvancedLSB.vue index 1225523c98..59c388ee0e 100644 --- a/apps/web/src/services/advanced/AdvancedLSB.vue +++ b/apps/web/src/services/advanced/AdvancedLSB.vue @@ -1,6 +1,4 @@ diff --git a/apps/web/src/services/advanced/components/BookmarkDetailContainer.vue b/apps/web/src/services/advanced/components/BookmarkDetailContainer.vue index 811035b1ab..7894e19788 100644 --- a/apps/web/src/services/advanced/components/BookmarkDetailContainer.vue +++ b/apps/web/src/services/advanced/components/BookmarkDetailContainer.vue @@ -38,6 +38,8 @@ const bookmarkPageStore = useBookmarkPageStore(); const bookmarkPageState = bookmarkPageStore.state; const bookmarkPageGetters = bookmarkPageStore.getters; +const { hasReadWriteAccess } = usePageEditableStatus(); + const route = useRoute(); const router = useRouter(); @@ -74,7 +76,6 @@ const state = reactive({ return state.workspaceInfo?.name || ''; }), workspaceInfo: computed(() => getWorkspaceInfo(state.group, storeState.workspaceList)), - hasReadWriteAccess: computed(() => usePageEditableStatus()), }); const hideMenu = () => { @@ -186,7 +187,7 @@ onUnmounted(() => { v-bind="workspaceStateFormatter( WORKSPACE_STATE.DORMANT)" class="capitalize state" /> - - -
(() => allReferenceStore.getters.plugin), @@ -117,7 +119,6 @@ const historyLinkQueryHelper = new QueryHelper(); const state = reactive({ loading: computed(() => collectorPageState.loading.collectorList), - hasReadWriteAccess: computed(() => usePageEditableStatus()), searchTags: computed(() => { const tags = searchQueryHelper.setFilters(collectorPageState.searchFilters).queryTags; return tags.reduce((r: QueryItem[], d: any): QueryItem[] => { @@ -265,7 +266,7 @@ onMounted(async () => { @refresh="fetchCollectorList" @export="handleExportExcel" > -