From ee75237c2a9f03dc756bb7aed05db05947764c52 Mon Sep 17 00:00:00 2001 From: nayeongkim Date: Tue, 10 Dec 2024 11:30:40 +0900 Subject: [PATCH] feat: create page editable status custom hook Signed-off-by: NaYeong,Kim --- .../composables/page-editable-status/index.ts | 18 +++++ .../components/BookmarkDetailContainer.vue | 24 +----- .../BookmarkManagementDetailTable.vue | 23 +----- .../components/WorkspaceGroupTabGroupUser.vue | 20 +---- .../components/WorkspaceGroupTabWorkspace.vue | 19 +---- .../pages/admin/AdminBookmarkPage.vue | 26 +------ .../AdminDomainSettingsAppearancePage.vue | 30 +------ ...nSettingsAutoDormancyConfigurationPage.vue | 26 +------ ...minDomainSettingsDomainInformationPage.vue | 26 +------ .../pages/admin/AdminWorkspaceGroupPage.vue | 21 +---- .../pages/admin/AdminWorkspacesPage.vue | 26 +------ .../alert-manager/pages/AlertDetailPage.vue | 27 +------ .../pages/EscalationPolicyPage.vue | 25 +----- .../CloudServiceHistoryDetailNoteTab.vue | 28 +------ .../components/CollectorMainContents.vue | 23 +----- .../components/MetricExplorerHeader.vue | 22 +----- .../components/MetricExplorerLSBMetric.vue | 23 +----- .../pages/CollectorDetailPage.vue | 27 +------ .../pages/ServiceAccountDetailPage.vue | 24 +----- .../pages/ServiceAccountPage.vue | 19 +---- .../pages/admin/AdminCollectorDetailPage.vue | 32 +------- .../components/BudgetDetailHeading.vue | 23 +----- .../components/CostAnalysisHeader.vue | 24 +----- .../components/CostAnalysisQuerySection.vue | 25 +----- .../components/DataSourceManagementTabs.vue | 25 +----- .../cost-explorer/pages/BudgetMainPage.vue | 22 +----- .../cost-explorer/pages/CostReportPage.vue | 28 +------ ...tingsAnomalyDetectionConfigurationPage.vue | 78 +++++++------------ .../pages/admin/AdminBudgetMainPage.vue | 27 +------ .../src/services/dashboards/DashboardsLSB.vue | 16 +--- .../dashboards/pages/DashboardsMainPage.vue | 20 +---- .../src/services/iam/pages/AppMainPage.vue | 24 +----- .../src/services/iam/pages/UserMainPage.vue | 23 +----- .../iam/pages/admin/AdminRolePage.vue | 29 +------ .../pages/admin/AdminNoticeDetailPage.vue | 23 +----- .../info/pages/admin/AdminNoticeMainPage.vue | 22 +----- .../components/DomainLandingStartBanner.vue | 17 +--- .../workspace-landing/LandingContents.vue | 24 +----- 38 files changed, 141 insertions(+), 818 deletions(-) create mode 100644 apps/web/src/common/composables/page-editable-status/index.ts diff --git a/apps/web/src/common/composables/page-editable-status/index.ts b/apps/web/src/common/composables/page-editable-status/index.ts new file mode 100644 index 0000000000..ccf767d09a --- /dev/null +++ b/apps/web/src/common/composables/page-editable-status/index.ts @@ -0,0 +1,18 @@ +import { computed, reactive } from 'vue'; + +import { useUserStore } from '@/store/user/user-store'; + +import type { PageAccessMap } from '@/lib/access-control/config'; + +import { useCurrentMenuId } from '@/common/composables/current-menu-id'; + +export const usePageEditableStatus = (): boolean|undefined => { + const userStore = useUserStore(); + const userGetters = userStore.getters; + + const storeState = reactive({ + pageAccessPermissionMap: computed(() => userGetters.pageAccessPermissionMap), + }); + + return storeState.pageAccessPermissionMap[useCurrentMenuId()]?.write; +}; diff --git a/apps/web/src/services/advanced/components/BookmarkDetailContainer.vue b/apps/web/src/services/advanced/components/BookmarkDetailContainer.vue index dbec189d9e..811035b1ab 100644 --- a/apps/web/src/services/advanced/components/BookmarkDetailContainer.vue +++ b/apps/web/src/services/advanced/components/BookmarkDetailContainer.vue @@ -6,7 +6,7 @@ import { import type { TranslateResult } from 'vue-i18n'; import { useRoute, useRouter } from 'vue-router/composables'; -import { at, clone } from 'lodash'; +import { at } from 'lodash'; import { PHeading, PButton, PContextMenu, PI, PIconButton, PStatus, PHeadingLayout, @@ -18,15 +18,10 @@ import { i18n } from '@/translations'; import { makeAdminRouteName } from '@/router/helpers/route-helper'; -import { useUserStore } from '@/store/user/user-store'; - -import type { PageAccessMap } from '@/lib/access-control/config'; -import type { MenuId } from '@/lib/menu/config'; -import { MENU_ID } from '@/lib/menu/config'; - import { BOOKMARK_MODAL_TYPE } from '@/common/components/bookmark/constant/constant'; import { useBookmarkStore } from '@/common/components/bookmark/store/bookmark-store'; import type { BookmarkModalType, BookmarkItem } from '@/common/components/bookmark/type/type'; +import { usePageEditableStatus } from '@/common/composables/page-editable-status'; import WorkspaceLogoIcon from '@/common/modules/navigations/top-bar/modules/top-bar-header/WorkspaceLogoIcon.vue'; import { gray } from '@/styles/colors'; @@ -35,11 +30,8 @@ import { getWorkspaceInfo, workspaceStateFormatter } from '@/services/advanced/c import { WORKSPACE_STATE } from '@/services/advanced/constants/workspace-constant'; import { ADVANCED_ROUTE } from '@/services/advanced/routes/route-constant'; import { useBookmarkPageStore } from '@/services/advanced/store/bookmark-page-store'; -import { COST_EXPLORER_ROUTE } from '@/services/cost-explorer/routes/route-constant'; import { WORKSPACE_HOME_ROUTE } from '@/services/workspace-home/routes/route-constant'; - -const userStore = useUserStore(); const bookmarkStore = useBookmarkStore(); const bookmarkState = bookmarkStore.state; const bookmarkPageStore = useBookmarkPageStore(); @@ -56,7 +48,6 @@ const storeState = reactive({ selectedIndices: computed(() => bookmarkPageState.selectedIndices), bookmarkFolderList: computed(() => bookmarkPageState.bookmarkFolderList), bookmarkList: computed(() => bookmarkPageGetters.bookmarkList), - pageAccessPermissionMap: computed(() => userStore.getters.pageAccessPermissionMap), }); const state = reactive({ visibleMenu: false, @@ -83,16 +74,7 @@ const state = reactive({ return state.workspaceInfo?.name || ''; }), workspaceInfo: computed(() => getWorkspaceInfo(state.group, storeState.workspaceList)), - selectedMenuId: computed(() => { - const reversedMatched = clone(route.matched).reverse(); - const closestRoute = reversedMatched.find((d) => d.meta?.menuId !== undefined); - const targetMenuId: MenuId = closestRoute?.meta?.menuId || MENU_ID.WORKSPACE_HOME; - if (route.name === COST_EXPLORER_ROUTE.LANDING._NAME) { - return ''; - } - return targetMenuId; - }), - hasReadWriteAccess: computed(() => storeState.pageAccessPermissionMap[state.selectedMenuId]?.write), + hasReadWriteAccess: computed(() => usePageEditableStatus()), }); const hideMenu = () => { diff --git a/apps/web/src/services/advanced/components/BookmarkManagementDetailTable.vue b/apps/web/src/services/advanced/components/BookmarkManagementDetailTable.vue index c9ab3362b1..c8043a2e15 100644 --- a/apps/web/src/services/advanced/components/BookmarkManagementDetailTable.vue +++ b/apps/web/src/services/advanced/components/BookmarkManagementDetailTable.vue @@ -2,8 +2,6 @@ import { computed, reactive, watch } from 'vue'; import { useRoute, useRouter } from 'vue-router/composables'; -import { clone } from 'lodash'; - import type { ConsoleFilter } from '@cloudforet/core-lib/query/type'; import { PToolboxTable, PLazyImg, PI, PDataLoader, PSelectStatus, PSelectDropdown, @@ -20,15 +18,10 @@ import { i18n } from '@/translations'; import { makeAdminRouteName } from '@/router/helpers/route-helper'; -import { useUserStore } from '@/store/user/user-store'; - -import type { PageAccessMap } from '@/lib/access-control/config'; -import type { MenuId } from '@/lib/menu/config'; -import { MENU_ID } from '@/lib/menu/config'; - import { BOOKMARK_MODAL_TYPE } from '@/common/components/bookmark/constant/constant'; import { useBookmarkStore } from '@/common/components/bookmark/store/bookmark-store'; import type { BookmarkItem } from '@/common/components/bookmark/type/type'; +import { usePageEditableStatus } from '@/common/composables/page-editable-status'; import { gray } from '@/styles/colors'; @@ -36,13 +29,11 @@ import { makeSearchQueryTagsHandler, makeValueHandler } from '@/services/advance import { BOOKMARK_TYPE, PageSizeOptions } from '@/services/advanced/constants/bookmark-constant'; import { ADVANCED_ROUTE } from '@/services/advanced/routes/route-constant'; import { useBookmarkPageStore } from '@/services/advanced/store/bookmark-page-store'; -import { COST_EXPLORER_ROUTE } from '@/services/cost-explorer/routes/route-constant'; const bookmarkStore = useBookmarkStore(); const bookmarkPageStore = useBookmarkPageStore(); const bookmarkPageState = bookmarkPageStore.state; const bookmarkPageGetters = bookmarkPageStore.getters; -const userStore = useUserStore(); const route = useRoute(); const router = useRouter(); @@ -57,21 +48,11 @@ const storeState = reactive({ loading: computed(() => bookmarkPageState.loading), selectedType: computed(() => bookmarkPageState.selectedType), searchFilter: computed(() => bookmarkPageState.searchFilter), - pageAccessPermissionMap: computed(() => userStore.getters.pageAccessPermissionMap), }); const state = reactive({ group: computed(() => route.params.group), folder: computed(() => route.params.folder), - selectedMenuId: computed(() => { - const reversedMatched = clone(route.matched).reverse(); - const closestRoute = reversedMatched.find((d) => d.meta?.menuId !== undefined); - const targetMenuId: MenuId = closestRoute?.meta?.menuId || MENU_ID.WORKSPACE_HOME; - if (route.name === COST_EXPLORER_ROUTE.LANDING._NAME) { - return ''; - } - return targetMenuId; - }), - hasReadWriteAccess: computed(() => storeState.pageAccessPermissionMap[state.selectedMenuId]?.write), + hasReadWriteAccess: computed(() => usePageEditableStatus()), }); const tableState = reactive({ fields: computed(() => [ diff --git a/apps/web/src/services/advanced/components/WorkspaceGroupTabGroupUser.vue b/apps/web/src/services/advanced/components/WorkspaceGroupTabGroupUser.vue index b78a120a35..888bcd4917 100644 --- a/apps/web/src/services/advanced/components/WorkspaceGroupTabGroupUser.vue +++ b/apps/web/src/services/advanced/components/WorkspaceGroupTabGroupUser.vue @@ -2,9 +2,6 @@ import { reactive, watch, onUnmounted, computed, } from 'vue'; -import { useRoute } from 'vue-router/composables'; - -import { clone } from 'lodash'; import { SpaceConnector } from '@cloudforet/core-lib/space-connector'; import { @@ -21,12 +18,10 @@ import type { WorkspaceGroupUpdateRoleParameters } from '@/schema/identity/works import type { WorkspaceUser } from '@/schema/identity/workspace-group/model'; import { i18n } from '@/translations'; -import { useUserStore } from '@/store/user/user-store'; - -import type { PageAccessMap } from '@/lib/access-control/config'; import { showSuccessMessage } from '@/lib/helper/notice-alert-helper'; import ErrorHandler from '@/common/composables/error/errorHandler'; +import { usePageEditableStatus } from '@/common/composables/page-editable-status'; import { useRoleFormatter, groupUserStateFormatter } from '@/services/advanced/composables/refined-table-data'; import { useSelectDropDownList } from '@/services/advanced/composables/use-select-drop-down-list'; @@ -37,22 +32,11 @@ const workspaceGroupPageStore = useWorkspaceGroupPageStore(); const workspaceGroupPageState = workspaceGroupPageStore.state; const userTabState = workspaceGroupPageStore.userTabState; const workspaceGroupPageGetters = workspaceGroupPageStore.getters; -const userStore = useUserStore(); - -const route = useRoute(); const emit = defineEmits<{(e: 'refresh', payload: { isGroupUser?: boolean, isWorkspace?: boolean }): void; }>(); -const storeState = reactive({ - pageAccessPermissionMap: computed(() => userStore.getters.pageAccessPermissionMap), -}); const state = reactive({ - selectedMenuId: computed(() => { - const reversedMatched = clone(route.matched).reverse(); - const closestRoute = reversedMatched.find((d) => d.meta?.menuId !== undefined); - return closestRoute?.meta?.menuId; - }), - hasReadWriteAccess: computed(() => storeState.pageAccessPermissionMap[state.selectedMenuId]?.write), + hasReadWriteAccess: computed(() => usePageEditableStatus()), }); const tableState = reactive({ fields: computed(() => { diff --git a/apps/web/src/services/advanced/components/WorkspaceGroupTabWorkspace.vue b/apps/web/src/services/advanced/components/WorkspaceGroupTabWorkspace.vue index 703f4741f1..f6e7b72ad2 100644 --- a/apps/web/src/services/advanced/components/WorkspaceGroupTabWorkspace.vue +++ b/apps/web/src/services/advanced/components/WorkspaceGroupTabWorkspace.vue @@ -2,10 +2,8 @@ import { computed, onMounted, reactive, watch, } from 'vue'; -import { useRoute } from 'vue-router/composables'; import dayjs from 'dayjs'; -import { clone } from 'lodash'; import { PButton, PHeading, PI, PLink, PStatus, PToolboxTable, PTooltip, PHeadingLayout, @@ -22,8 +20,7 @@ import { useAllReferenceStore } from '@/store/reference/all-reference-store'; import type { WorkspaceReferenceMap } from '@/store/reference/workspace-reference-store'; import { useUserStore } from '@/store/user/user-store'; -import type { PageAccessMap } from '@/lib/access-control/config'; - +import { usePageEditableStatus } from '@/common/composables/page-editable-status'; import WorkspaceLogoIcon from '@/common/modules/navigations/top-bar/modules/top-bar-header/WorkspaceLogoIcon.vue'; import { gray } from '@/styles/colors'; @@ -35,7 +32,6 @@ import { ASSET_INVENTORY_ROUTE } from '@/services/asset-inventory/routes/route-c import { IAM_ROUTE } from '@/services/iam/routes/route-constant'; import { WORKSPACE_HOME_ROUTE } from '@/services/workspace-home/routes/route-constant'; - const workspaceGroupPageStore = useWorkspaceGroupPageStore(); const workspaceGroupPageState = workspaceGroupPageStore.state; const workspaceTabState = workspaceGroupPageStore.workspaceTabState; @@ -43,23 +39,12 @@ const workspaceGroupPageGetters = workspaceGroupPageStore.getters; const allReferenceStore = useAllReferenceStore(); const userStore = useUserStore(); -const route = useRoute(); - -const storeState = reactive({ - pageAccessPermissionMap: computed(() => userStore.getters.pageAccessPermissionMap), -}); - interface WorkspaceTableItem extends WorkspaceModel { remove_button: WorkspaceModel; } const state = reactive({ - selectedMenuId: computed(() => { - const reversedMatched = clone(route.matched).reverse(); - const closestRoute = reversedMatched.find((d) => d.meta?.menuId !== undefined); - return closestRoute?.meta?.menuId; - }), - hasReadWriteAccess: computed(() => storeState.pageAccessPermissionMap[state.selectedMenuId]?.write), + hasReadWriteAccess: computed(() => usePageEditableStatus()), currency: computed(() => workspaceGroupPageGetters.currency), }); const tableState = reactive({ diff --git a/apps/web/src/services/advanced/pages/admin/AdminBookmarkPage.vue b/apps/web/src/services/advanced/pages/admin/AdminBookmarkPage.vue index 62599bc5a7..2445f6e040 100644 --- a/apps/web/src/services/advanced/pages/admin/AdminBookmarkPage.vue +++ b/apps/web/src/services/advanced/pages/admin/AdminBookmarkPage.vue @@ -3,9 +3,8 @@ import { vOnClickOutside } from '@vueuse/components'; import { computed, reactive, } from 'vue'; -import { useRoute } from 'vue-router/composables'; -import { at, clone } from 'lodash'; +import { at } from 'lodash'; import { PHeading, PButton, PContextMenu, PHeadingLayout, @@ -14,28 +13,19 @@ import type { MenuItem } from '@cloudforet/mirinae/src/controls/context-menu/typ import { i18n } from '@/translations'; -import { useUserStore } from '@/store/user/user-store'; - -import type { PageAccessMap } from '@/lib/access-control/config'; -import type { MenuId } from '@/lib/menu/config'; -import { MENU_ID } from '@/lib/menu/config'; - import { BOOKMARK_MODAL_TYPE } from '@/common/components/bookmark/constant/constant'; import { useBookmarkStore } from '@/common/components/bookmark/store/bookmark-store'; import type { BookmarkModalType, BookmarkItem } from '@/common/components/bookmark/type/type'; +import { usePageEditableStatus } from '@/common/composables/page-editable-status'; import BookmarkManagementTable from '@/services/advanced/components/BookmarkManagementTable.vue'; import { useBookmarkPageStore } from '@/services/advanced/store/bookmark-page-store'; -import { COST_EXPLORER_ROUTE } from '@/services/cost-explorer/routes/route-constant'; const bookmarkStore = useBookmarkStore(); const bookmarkState = bookmarkStore.state; const bookmarkPageStore = useBookmarkPageStore(); const bookmarkPageState = bookmarkPageStore.state; const bookmarkPageGetters = bookmarkPageStore.getters; -const userStore = useUserStore(); - -const route = useRoute(); const storeState = reactive({ modalType: computed(() => bookmarkState.modal.type), @@ -43,7 +33,6 @@ const storeState = reactive({ bookmarkFolderList: computed(() => bookmarkPageState.bookmarkFolderList), bookmarkList: computed(() => bookmarkPageGetters.bookmarkList), selectedIndices: computed(() => bookmarkPageGetters.selectedIndices), - pageAccessPermissionMap: computed(() => userStore.getters.pageAccessPermissionMap), }); const state = reactive({ visibleMenu: false, @@ -57,16 +46,7 @@ const state = reactive({ name: BOOKMARK_MODAL_TYPE.FOLDER, }, ])), - selectedMenuId: computed(() => { - const reversedMatched = clone(route.matched).reverse(); - const closestRoute = reversedMatched.find((d) => d.meta?.menuId !== undefined); - const targetMenuId: MenuId = closestRoute?.meta?.menuId || MENU_ID.WORKSPACE_HOME; - if (route.name === COST_EXPLORER_ROUTE.LANDING._NAME) { - return ''; - } - return targetMenuId; - }), - hasReadWriteAccess: computed(() => storeState.pageAccessPermissionMap[state.selectedMenuId]?.write), + hasReadWriteAccess: computed(() => usePageEditableStatus()), }); const hideMenu = () => { diff --git a/apps/web/src/services/advanced/pages/admin/AdminDomainSettingsAppearancePage.vue b/apps/web/src/services/advanced/pages/admin/AdminDomainSettingsAppearancePage.vue index 03742c58fa..d16345bdfc 100644 --- a/apps/web/src/services/advanced/pages/admin/AdminDomainSettingsAppearancePage.vue +++ b/apps/web/src/services/advanced/pages/admin/AdminDomainSettingsAppearancePage.vue @@ -1,8 +1,6 @@ diff --git a/apps/web/src/services/landing/components/workspace-landing/LandingContents.vue b/apps/web/src/services/landing/components/workspace-landing/LandingContents.vue index 7e177184b8..a904319ca0 100644 --- a/apps/web/src/services/landing/components/workspace-landing/LandingContents.vue +++ b/apps/web/src/services/landing/components/workspace-landing/LandingContents.vue @@ -3,9 +3,9 @@ import { useWindowSize } from '@vueuse/core'; import { computed, onMounted, onUnmounted, reactive, } from 'vue'; -import { useRoute, useRouter } from 'vue-router/composables'; +import { useRouter } from 'vue-router/composables'; -import { clone, sortBy } from 'lodash'; +import { sortBy } from 'lodash'; import { PButton, PDataLoader, PDivider, screens, @@ -18,10 +18,7 @@ import { makeAdminRouteName } from '@/router/helpers/route-helper'; import { useUserWorkspaceStore } from '@/store/app-context/workspace/user-workspace-store'; import { useUserStore } from '@/store/user/user-store'; -import type { PageAccessMap } from '@/lib/access-control/config'; -import type { MenuId } from '@/lib/menu/config'; -import { MENU_ID } from '@/lib/menu/config'; - +import { usePageEditableStatus } from '@/common/composables/page-editable-status'; import { useFavoriteStore } from '@/common/modules/favorites/favorite-button/store/favorite-store'; import type { FavoriteItem } from '@/common/modules/favorites/favorite-button/type'; import { useRecentStore } from '@/common/modules/navigations/stores/recent-store'; @@ -31,7 +28,6 @@ import { RECENT_TYPE } from '@/common/modules/navigations/type'; import { gray } from '@/styles/colors'; import { ADVANCED_ROUTE } from '@/services/advanced/routes/route-constant'; -import { COST_EXPLORER_ROUTE } from '@/services/cost-explorer/routes/route-constant'; import LandingGroupWorkspaces from '@/services/landing/components/workspace-landing/landing-group-workspaces/LandingGroupWorkspaces.vue'; import LandingAllWorkspaces from '@/services/landing/components/workspace-landing/LandingAllWorkspaces.vue'; import LandingEmptyContents from '@/services/landing/components/workspace-landing/LandingEmptyContents.vue'; @@ -39,7 +35,6 @@ import LandingRecentVisits from '@/services/landing/components/workspace-landing import LandingSearch from '@/services/landing/components/workspace-landing/LandingSearch.vue'; import { useLandingPageStore } from '@/services/landing/store/landing-page-store'; - const userWorkspaceStore = useUserWorkspaceStore(); const workspaceStoreGetters = userWorkspaceStore.getters; const favoriteStore = useFavoriteStore(); @@ -50,7 +45,6 @@ const landingPageStore = useLandingPageStore(); const landingPageStoreGetters = landingPageStore.getters; const router = useRouter(); -const route = useRoute(); const { width } = useWindowSize(); const userStore = useUserStore(); @@ -65,7 +59,6 @@ const storeState = reactive({ workspaceId: i.data.workspace_id, itemId: i.data.id, }))), - pageAccessPermissionMap: computed(() => userStore.getters.pageAccessPermissionMap), }); const state = reactive({ searchText: '', @@ -75,16 +68,7 @@ const state = reactive({ ? storeState.workspaceList.filter((item) => item.name.toLowerCase()?.includes(state.searchText.toLowerCase())) : storeState.workspaceList)), refinedWorkspaceList: computed(() => (state.searchText ? state.searchedWorkspaceList : storeState.workspaceList)), - selectedMenuId: computed(() => { - const reversedMatched = clone(route.matched).reverse(); - const closestRoute = reversedMatched.find((d) => d.meta?.menuId !== undefined); - const targetMenuId: MenuId = closestRoute?.meta?.menuId || MENU_ID.WORKSPACE_HOME; - if (route.name === COST_EXPLORER_ROUTE.LANDING._NAME) { - return ''; - } - return targetMenuId; - }), - hasReadWriteAccess: computed(() => storeState.pageAccessPermissionMap[state.selectedMenuId]?.write), + hasReadWriteAccess: computed(() => usePageEditableStatus()), }); const handleSearch = (value: string) => {