From d385ccd30257e59cbc98eaca3ccec9b6a9ffff11 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Mon, 24 Mar 2025 15:16:37 -0600 Subject: [PATCH] update permission groups --- .../dataset_groups/queryRequests.ts | 2 +- .../DatasetGroupAppSegments.tsx | 2 +- .../(permissions)/dataset-groups/page.tsx | 1 - .../PermissionAppSegments.tsx | 2 +- .../[permissionGroupId]/layout.tsx | 18 +++---- .../components/features/list/ListUserItem.tsx | 2 +- .../features/sidebars/SidebarSettings.tsx | 4 +- .../BusterAppLayout/AppLayoutProvider.tsx | 10 ++-- .../CollectionsIndividualPopup.tsx | 1 - .../PermissionUsersSelectedPopup.tsx | 2 - web/src/routes/helpers.tsx | 48 ++++++++++++++++++- 11 files changed, 64 insertions(+), 28 deletions(-) diff --git a/web/src/api/buster_rest/dataset_groups/queryRequests.ts b/web/src/api/buster_rest/dataset_groups/queryRequests.ts index f7094141b..840a4a352 100644 --- a/web/src/api/buster_rest/dataset_groups/queryRequests.ts +++ b/web/src/api/buster_rest/dataset_groups/queryRequests.ts @@ -240,7 +240,7 @@ export const useUpdateDatasetGroupPermissionGroups = () => { mutationFn: updateDatasetGroupPermissionGroups, onMutate: ({ data, datasetGroupId }) => { queryClient.setQueryData( - queryKeys.datasetGroupsGetDatasets(datasetGroupId).queryKey, + queryKeys.datasetGroupsGetPermissionGroups(datasetGroupId).queryKey, (oldData: GetDatasetGroupPermissionGroupsResponse[] | undefined) => { if (!oldData) return []; return oldData.map((permissionGroup) => { diff --git a/web/src/app/app/(settings_layout)/settings/(permissions)/dataset-groups/[datasetGroupId]/DatasetGroupAppSegments.tsx b/web/src/app/app/(settings_layout)/settings/(permissions)/dataset-groups/[datasetGroupId]/DatasetGroupAppSegments.tsx index 3ce75bc71..ecccd9c7c 100644 --- a/web/src/app/app/(settings_layout)/settings/(permissions)/dataset-groups/[datasetGroupId]/DatasetGroupAppSegments.tsx +++ b/web/src/app/app/(settings_layout)/settings/(permissions)/dataset-groups/[datasetGroupId]/DatasetGroupAppSegments.tsx @@ -59,7 +59,7 @@ export const DatasetGroupAppSegments: React.FC<{ return (
- +
); diff --git a/web/src/app/app/(settings_layout)/settings/(permissions)/dataset-groups/page.tsx b/web/src/app/app/(settings_layout)/settings/(permissions)/dataset-groups/page.tsx index 456707e38..3cd75d532 100644 --- a/web/src/app/app/(settings_layout)/settings/(permissions)/dataset-groups/page.tsx +++ b/web/src/app/app/(settings_layout)/settings/(permissions)/dataset-groups/page.tsx @@ -46,7 +46,6 @@ export default function Page() {
- z - + ); diff --git a/web/src/app/app/(settings_layout)/settings/(permissions)/permission-groups/[permissionGroupId]/layout.tsx b/web/src/app/app/(settings_layout)/settings/(permissions)/permission-groups/[permissionGroupId]/layout.tsx index f17b82583..edb6994ee 100644 --- a/web/src/app/app/(settings_layout)/settings/(permissions)/permission-groups/[permissionGroupId]/layout.tsx +++ b/web/src/app/app/(settings_layout)/settings/(permissions)/permission-groups/[permissionGroupId]/layout.tsx @@ -3,21 +3,15 @@ import { prefetchPermissionGroup } from '@/api/buster_rest'; import { HydrationBoundary, dehydrate } from '@tanstack/react-query'; import { PermissionGroupIndividualLayout } from './_PermissionGroupIndividualLayout'; -export default async function Layout( - props: { - children: React.ReactNode; - params: Promise<{ permissionGroupId: string }>; - } -) { +export default async function Layout(props: { + children: React.ReactNode; + params: Promise<{ permissionGroupId: string }>; +}) { const params = await props.params; - const { - permissionGroupId - } = params; + const { permissionGroupId } = params; - const { - children - } = props; + const { children } = props; const queryClient = await prefetchPermissionGroup(permissionGroupId); diff --git a/web/src/components/features/list/ListUserItem.tsx b/web/src/components/features/list/ListUserItem.tsx index c0e46849b..b203d6093 100644 --- a/web/src/components/features/list/ListUserItem.tsx +++ b/web/src/components/features/list/ListUserItem.tsx @@ -9,7 +9,7 @@ export const ListUserItem = React.memo(({ name, email }: { name: string; email: -
+
{name && {name}} {email && ( diff --git a/web/src/components/features/sidebars/SidebarSettings.tsx b/web/src/components/features/sidebars/SidebarSettings.tsx index 67a514825..35f525743 100644 --- a/web/src/components/features/sidebars/SidebarSettings.tsx +++ b/web/src/components/features/sidebars/SidebarSettings.tsx @@ -63,7 +63,7 @@ const permissionAndSecurityItems: ISidebarGroup = { export const SidebarSettings: React.FC<{}> = React.memo(({}) => { const isAdmin = useUserConfigContextSelector((x) => x.isAdmin); - const currentRoute = useAppLayoutContextSelector((x) => x.currentRoute); + const currentParentRoute = useAppLayoutContextSelector((x) => x.currentParentRoute); const content = useMemo(() => { const items = [accountItems]; @@ -78,7 +78,7 @@ export const SidebarSettings: React.FC<{}> = React.memo(({}) => { } - activeItem={currentRoute} + activeItem={currentParentRoute} footer={} /> ); diff --git a/web/src/context/BusterAppLayout/AppLayoutProvider.tsx b/web/src/context/BusterAppLayout/AppLayoutProvider.tsx index e3e8e8a04..2486432aa 100644 --- a/web/src/context/BusterAppLayout/AppLayoutProvider.tsx +++ b/web/src/context/BusterAppLayout/AppLayoutProvider.tsx @@ -1,9 +1,9 @@ 'use client'; import { BusterRoutesWithArgsRoute, createBusterRoute } from '@/routes/busterRoutes'; -import { pathNameToRoute } from '@/routes/helpers'; -import { useMemoizedFn, usePrevious } from '@/hooks'; -import { useRouter, usePathname, useSelectedLayoutSegment, useParams } from 'next/navigation'; +import { pathNameToParentRoute, pathNameToRoute } from '@/routes/helpers'; +import { useMemoizedFn } from '@/hooks'; +import { useRouter, usePathname, useParams } from 'next/navigation'; import React, { PropsWithChildren } from 'react'; import { createContext, useContextSelector } from 'use-context-selector'; @@ -12,6 +12,7 @@ export const useAppLayout = () => { const pathname = usePathname(); const params = useParams(); const currentRoute = pathNameToRoute(pathname, params); + const currentParentRoute = pathNameToParentRoute(pathname, params); const [openInviteModal, setOpenInviteModal] = React.useState(false); const onToggleInviteModal = useMemoizedFn((v?: boolean) => { @@ -57,7 +58,8 @@ export const useAppLayout = () => { currentRoute, onToggleInviteModal, openInviteModal, - onChangePage + onChangePage, + currentParentRoute }; }; diff --git a/web/src/controllers/CollectionIndividualController/CollectionsIndividualPopup.tsx b/web/src/controllers/CollectionIndividualController/CollectionsIndividualPopup.tsx index dd5feb135..40291b251 100644 --- a/web/src/controllers/CollectionIndividualController/CollectionsIndividualPopup.tsx +++ b/web/src/controllers/CollectionIndividualController/CollectionsIndividualPopup.tsx @@ -39,7 +39,6 @@ const CollectionDeleteButton: React.FC<{ const onRemoveFromCollection = useMemoizedFn(async () => { if (collection) { - console.log(selectedRowKeys, collection); await removeAssetFromCollection({ id: collectionId, assets: (collection.assets || [])?.reduce<{ type: 'metric' | 'dashboard'; id: string }[]>( diff --git a/web/src/controllers/DatasetPermissionUser/PermissionUsersSelectedPopup.tsx b/web/src/controllers/DatasetPermissionUser/PermissionUsersSelectedPopup.tsx index a7bbb7795..45c778cbb 100644 --- a/web/src/controllers/DatasetPermissionUser/PermissionUsersSelectedPopup.tsx +++ b/web/src/controllers/DatasetPermissionUser/PermissionUsersSelectedPopup.tsx @@ -38,8 +38,6 @@ const options = PERMISSION_USERS_OPTIONS.map((v) => ({ icon: v.value === 'included' ? : })); -console.log(options); - const PermissionUsersAssignButton: React.FC<{ selectedRowKeys: string[]; onSelectChange: (selectedRowKeys: string[]) => void; diff --git a/web/src/routes/helpers.tsx b/web/src/routes/helpers.tsx index 3ea2d9d58..11a231f98 100644 --- a/web/src/routes/helpers.tsx +++ b/web/src/routes/helpers.tsx @@ -21,9 +21,53 @@ export const pathNameToRoute = (pathName: string, params: any): BusterRoutes => [BusterRoutes.APP_DATASETS_ID_PERMISSIONS_OVERVIEW]: BusterRoutes.APP_DATASETS, [BusterRoutes.APP_DATASETS_ID_OVERVIEW]: BusterRoutes.APP_DATASETS, [BusterRoutes.APP_DATASETS_ID_EDITOR]: BusterRoutes.APP_DATASETS, - [BusterRoutes.APP_TERMS_ID]: BusterRoutes.APP_TERMS, - [BusterRoutes.SETTINGS_USERS_ID]: BusterRoutes.SETTINGS_USERS + [BusterRoutes.APP_TERMS_ID]: BusterRoutes.APP_TERMS }; + + if (route && paramRoutesToParent[route as string]) { + return paramRoutesToParent[route as string]; + } + + return route || BusterRoutes.ROOT; +}; + +export const pathNameToParentRoute = (pathName: string, params: any): BusterRoutes => { + const route = Object.values(BusterRoutes).find((r) => { + return r === pathName || createBusterRoute({ route: r, ...params }) === pathName; + }); + + const paramRoutesToParent: Record = { + [BusterRoutes.APP_CHAT_ID]: BusterRoutes.APP_CHAT, + [BusterRoutes.APP_CHAT_ID_DASHBOARD_ID]: BusterRoutes.APP_CHAT, + [BusterRoutes.APP_CHAT_ID_METRIC_ID]: BusterRoutes.APP_CHAT, + [BusterRoutes.APP_CHAT_ID_COLLECTION_ID]: BusterRoutes.APP_CHAT, + [BusterRoutes.APP_CHAT_ID_REASONING_ID]: BusterRoutes.APP_CHAT, + [BusterRoutes.APP_CHAT_ID_TERM_ID]: BusterRoutes.APP_CHAT, + [BusterRoutes.APP_CHAT_ID_VALUE_ID]: BusterRoutes.APP_CHAT, + [BusterRoutes.APP_METRIC_ID]: BusterRoutes.APP_METRIC, + [BusterRoutes.APP_DASHBOARD_METRICS_ID]: BusterRoutes.APP_DASHBOARDS, + [BusterRoutes.APP_DASHBOARD_ID]: BusterRoutes.APP_DASHBOARDS, + [BusterRoutes.APP_COLLECTIONS_ID]: BusterRoutes.APP_COLLECTIONS, + [BusterRoutes.APP_DATASETS_ID]: BusterRoutes.APP_DATASETS, + [BusterRoutes.APP_DATASETS_ID_PERMISSIONS_OVERVIEW]: BusterRoutes.APP_DATASETS, + [BusterRoutes.APP_DATASETS_ID_OVERVIEW]: BusterRoutes.APP_DATASETS, + [BusterRoutes.APP_DATASETS_ID_EDITOR]: BusterRoutes.APP_DATASETS, + [BusterRoutes.APP_TERMS_ID]: BusterRoutes.APP_TERMS, + [BusterRoutes.SETTINGS_USERS_ID]: BusterRoutes.SETTINGS_USERS, + [BusterRoutes.SETTINGS_USERS_ID_DATASETS]: BusterRoutes.SETTINGS_USERS, + [BusterRoutes.SETTINGS_USERS_ID_PERMISSION_GROUPS]: BusterRoutes.SETTINGS_USERS, + [BusterRoutes.SETTINGS_USERS_ID_TEAMS]: BusterRoutes.SETTINGS_USERS, + [BusterRoutes.SETTINGS_USERS_ID_DATASET_GROUPS]: BusterRoutes.SETTINGS_USERS, + [BusterRoutes.SETTINGS_DATASET_GROUPS_ID_PERMISSION_GROUPS]: + BusterRoutes.SETTINGS_DATASET_GROUPS, + [BusterRoutes.SETTINGS_DATASET_GROUPS_ID_DATASETS]: BusterRoutes.SETTINGS_DATASET_GROUPS, + [BusterRoutes.SETTINGS_DATASET_GROUPS_ID_USERS]: BusterRoutes.SETTINGS_DATASET_GROUPS, + [BusterRoutes.SETTINGS_PERMISSION_GROUPS_ID_USERS]: BusterRoutes.SETTINGS_PERMISSION_GROUPS, + [BusterRoutes.SETTINGS_PERMISSION_GROUPS_ID_DATASET_GROUPS]: + BusterRoutes.SETTINGS_PERMISSION_GROUPS, + [BusterRoutes.SETTINGS_PERMISSION_GROUPS_ID_DATASETS]: BusterRoutes.SETTINGS_PERMISSION_GROUPS + }; + if (route && paramRoutesToParent[route as string]) { return paramRoutesToParent[route as string]; }