From 6ba7b77de28059c37b918cde48cafa7db7820eb0 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 22 Apr 2025 16:54:45 -0600 Subject: [PATCH 1/5] Update AvatarUserButton.stories.tsx --- web/src/components/ui/avatar/AvatarUserButton.stories.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/src/components/ui/avatar/AvatarUserButton.stories.tsx b/web/src/components/ui/avatar/AvatarUserButton.stories.tsx index 32dfe0a6d..0b5830fac 100644 --- a/web/src/components/ui/avatar/AvatarUserButton.stories.tsx +++ b/web/src/components/ui/avatar/AvatarUserButton.stories.tsx @@ -3,7 +3,8 @@ import { AvatarUserButton } from './AvatarUserButton'; const defaultUser = { username: 'John Doe', - avatarUrl: 'https://i.pravatar.cc/200', + avatarUrl: + 'https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=200&h=200&q=80', email: 'john.doe@example.com' }; From 0c344a6e56273ef34b8797e37f5adf454d876952 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 22 Apr 2025 17:01:12 -0600 Subject: [PATCH 2/5] Update layout.tsx --- web/src/app/app/layout.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/web/src/app/app/layout.tsx b/web/src/app/app/layout.tsx index 9e7ce7b94..acaa24f0c 100644 --- a/web/src/app/app/layout.tsx +++ b/web/src/app/app/layout.tsx @@ -33,12 +33,13 @@ export default async function Layout({ const userInfo = queryClient.getQueryData(queryKeys.userGetUserMyself.queryKey); const newUserRoute = createBusterRoute({ route: BusterRoutes.NEW_USER }); + const loginRoute = createBusterRoute({ route: BusterRoutes.AUTH_LOGIN }); - if ( - (!userInfo?.organizations?.[0]?.id || !userInfo?.user?.name) && - !supabaseContext.user?.is_anonymous && - pathname !== newUserRoute - ) { + if (supabaseContext.user?.is_anonymous && pathname !== loginRoute) { + return ; + } + + if ((!userInfo?.organizations?.[0]?.id || !userInfo?.user?.name) && pathname !== newUserRoute) { return ; } From 01f069a6fa6a17ce23aaee34f2b70119b085ae97 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 22 Apr 2025 17:05:18 -0600 Subject: [PATCH 3/5] asset type to route --- web/src/components/features/config/assetIcons.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/src/components/features/config/assetIcons.tsx b/web/src/components/features/config/assetIcons.tsx index 6dc97fb77..5844e14bf 100644 --- a/web/src/components/features/config/assetIcons.tsx +++ b/web/src/components/features/config/assetIcons.tsx @@ -35,7 +35,10 @@ export const assetTypeToRoute = (assetType: ShareAssetType, assetId: string) => return createBusterRoute({ route: BusterRoutes.APP_DASHBOARD_ID, dashboardId: assetId }); case ShareAssetType.COLLECTION: return createBusterRoute({ route: BusterRoutes.APP_COLLECTIONS_ID, collectionId: assetId }); + case ShareAssetType.CHAT: + return createBusterRoute({ route: BusterRoutes.APP_CHAT_ID, chatId: assetId }); default: + console.warn('Asset type to route not found', assetType, assetId); return ''; } }; From 8d556404c020c9ddb9312bb2f7750f088167ff7d Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 22 Apr 2025 17:15:07 -0600 Subject: [PATCH 4/5] only show popup if they are an editor --- web/src/context/Dashboards/useIsDashboardChanged.tsx | 2 ++ .../context/Dashboards/useIsDashboardReadOnly.tsx | 7 +++++-- web/src/context/Metrics/useIsMetricReadOnly.tsx | 5 ++++- .../DashboardViewDashboardController.tsx | 2 +- .../MetricViewChart/MetricViewChart.tsx | 12 +++++++----- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/web/src/context/Dashboards/useIsDashboardChanged.tsx b/web/src/context/Dashboards/useIsDashboardChanged.tsx index 93f8df728..4691ccb2d 100644 --- a/web/src/context/Dashboards/useIsDashboardChanged.tsx +++ b/web/src/context/Dashboards/useIsDashboardChanged.tsx @@ -52,6 +52,8 @@ export const useIsDashboardChanged = ({ dashboardId }: { dashboardId: string | u ); }, [originalDashboard, currentDashboard]); + console.log('isDashboardChanged', { isDashboardChanged, originalDashboard, currentDashboard }); + return { onResetDashboardToOriginal, isDashboardChanged diff --git a/web/src/context/Dashboards/useIsDashboardReadOnly.tsx b/web/src/context/Dashboards/useIsDashboardReadOnly.tsx index d8150a175..fecf42ccc 100644 --- a/web/src/context/Dashboards/useIsDashboardReadOnly.tsx +++ b/web/src/context/Dashboards/useIsDashboardReadOnly.tsx @@ -1,5 +1,5 @@ import { useGetDashboard } from '@/api/buster_rest/dashboards'; -import { canEdit } from '@/lib/share'; +import { canEdit, getIsOwner } from '@/lib/share'; import { useMemo } from 'react'; import last from 'lodash/last'; import { useChatLayoutContextSelector } from '@/layouts/ChatLayout'; @@ -44,11 +44,14 @@ export const useIsDashboardReadOnly = ({ return false; }, [isError, isFetched, dashboardData, isVersionHistoryMode, isViewingOldVersion]); + const isEditor = canEdit(dashboardData?.permission); + return { isVersionHistoryMode, isReadOnly, isViewingOldVersion, isFetched, - isError + isError, + isEditor }; }; diff --git a/web/src/context/Metrics/useIsMetricReadOnly.tsx b/web/src/context/Metrics/useIsMetricReadOnly.tsx index 9bb1cd57d..06f6f3e1f 100644 --- a/web/src/context/Metrics/useIsMetricReadOnly.tsx +++ b/web/src/context/Metrics/useIsMetricReadOnly.tsx @@ -51,11 +51,14 @@ export const useIsMetricReadOnly = ({ isViewingOldVersion ]); + const isEditor = canEdit(metricData?.permission); + return { isFetched, isError, isVersionHistoryMode, isReadOnly, - isViewingOldVersion + isViewingOldVersion, + isEditor }; }; diff --git a/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardViewDashboardController.tsx b/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardViewDashboardController.tsx index e2219f01d..aaad23205 100644 --- a/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardViewDashboardController.tsx +++ b/web/src/controllers/DashboardController/DashboardViewDashboardController/DashboardViewDashboardController.tsx @@ -63,7 +63,7 @@ export const DashboardViewDashboardController: React.FC<{ readOnly={isReadOnly} /> - {!isVersionHistoryMode && !isViewingOldVersion && ( + {!isReadOnly && !isVersionHistoryMode && !isViewingOldVersion && ( )} diff --git a/web/src/controllers/MetricController/MetricViewChart/MetricViewChart.tsx b/web/src/controllers/MetricController/MetricViewChart/MetricViewChart.tsx index 18bcdc78a..0c2dfd425 100644 --- a/web/src/controllers/MetricController/MetricViewChart/MetricViewChart.tsx +++ b/web/src/controllers/MetricController/MetricViewChart/MetricViewChart.tsx @@ -57,10 +57,12 @@ export const MetricViewChart: React.FC<{ const { name, description, time_frame, evaluation_score, evaluation_summary } = metric || {}; const isTable = metric?.chart_config.selectedChartType === ChartType.Table; - const { isReadOnly, isVersionHistoryMode, isViewingOldVersion } = useIsMetricReadOnly({ - metricId, - readOnly: readOnlyProp - }); + const { isReadOnly, isEditor, isVersionHistoryMode, isViewingOldVersion } = useIsMetricReadOnly( + { + metricId, + readOnly: readOnlyProp + } + ); const loadingData = !isFetchedMetricData; const errorData = !!metricDataError; const showEvaluation = !!evaluation_score && !!evaluation_summary; @@ -109,7 +111,7 @@ export const MetricViewChart: React.FC<{ /> - {!isVersionHistoryMode && !isViewingOldVersion && ( + {!isReadOnly && !isVersionHistoryMode && !isViewingOldVersion && ( )} From 8f0f4ae6da6d685e1543ef4294a0a85b15c0eb49 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Tue, 22 Apr 2025 17:19:59 -0600 Subject: [PATCH 5/5] update is metric changed logic --- .../charts/stories/scatterData_problematic1.ts | 2 -- .../Dashboards/useIsDashboardChanged.tsx | 18 ++++++++++++++---- web/src/context/Metrics/useIsMetricChanged.tsx | 10 +++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/web/src/components/ui/charts/stories/scatterData_problematic1.ts b/web/src/components/ui/charts/stories/scatterData_problematic1.ts index dd29d60a4..174422bf4 100644 --- a/web/src/components/ui/charts/stories/scatterData_problematic1.ts +++ b/web/src/components/ui/charts/stories/scatterData_problematic1.ts @@ -9016,8 +9016,6 @@ export const scatterDataProblematic1 = { } }; -console.log(scatterDataProblematic1); - export const scatterConfig_problematic1 = { selectedChartType: ChartType.Scatter, columnLabelFormats: { diff --git a/web/src/context/Dashboards/useIsDashboardChanged.tsx b/web/src/context/Dashboards/useIsDashboardChanged.tsx index 4691ccb2d..2989e0de8 100644 --- a/web/src/context/Dashboards/useIsDashboardChanged.tsx +++ b/web/src/context/Dashboards/useIsDashboardChanged.tsx @@ -7,6 +7,8 @@ import { dashboardQueryKeys } from '@/api/query_keys/dashboard'; import { compareObjectsByKeys } from '@/lib/objects'; import { useMemo } from 'react'; import { create } from 'mutative'; +import { canEdit } from '@/lib/share'; +import last from 'lodash/last'; export const useIsDashboardChanged = ({ dashboardId }: { dashboardId: string | undefined }) => { const queryClient = useQueryClient(); @@ -19,11 +21,18 @@ export const useIsDashboardChanged = ({ dashboardId }: { dashboardId: string | u name: x.dashboard.name, description: x.dashboard.description, config: x.dashboard.config, - file: x.dashboard.file + file: x.dashboard.file, + permission: x.permission, + versions: x.versions, + version_number: x.dashboard.version_number }) } ); + const isLatestVersion = useMemo(() => { + return currentDashboard?.version_number === last(currentDashboard?.versions)?.version_number; + }, [currentDashboard]); + const onResetDashboardToOriginal = useMemoizedFn(() => { const options = dashboardQueryKeys.dashboardGetDashboard( dashboardId || '', @@ -39,7 +48,10 @@ export const useIsDashboardChanged = ({ dashboardId }: { dashboardId: string | u refetchCurrentDashboard(); }); + const isEditor = canEdit(currentDashboard?.permission); + const isDashboardChanged = useMemo(() => { + if (!isEditor || !isLatestVersion || !currentDashboard || !originalDashboard) return false; return ( !originalDashboard || !currentDashboard || @@ -50,9 +62,7 @@ export const useIsDashboardChanged = ({ dashboardId }: { dashboardId: string | u 'file' ]) ); - }, [originalDashboard, currentDashboard]); - - console.log('isDashboardChanged', { isDashboardChanged, originalDashboard, currentDashboard }); + }, [originalDashboard, isEditor, currentDashboard, isLatestVersion]); return { onResetDashboardToOriginal, diff --git a/web/src/context/Metrics/useIsMetricChanged.tsx b/web/src/context/Metrics/useIsMetricChanged.tsx index 50617ad97..cb401db1d 100644 --- a/web/src/context/Metrics/useIsMetricChanged.tsx +++ b/web/src/context/Metrics/useIsMetricChanged.tsx @@ -6,6 +6,7 @@ import { useGetMetric } from '@/api/buster_rest/metrics'; import { compareObjectsByKeys } from '@/lib/objects'; import { useMemo } from 'react'; import last from 'lodash/last'; +import { canEdit } from '@/lib/share'; export const useIsMetricChanged = ({ metricId }: { metricId: string | undefined }) => { const queryClient = useQueryClient(); @@ -25,7 +26,8 @@ export const useIsMetricChanged = ({ metricId }: { metricId: string | undefined chart_config: x.chart_config, file: x.file, version_number: x.version_number, - versions: x.versions + versions: x.versions, + permission: x.permission }) } ); @@ -44,8 +46,10 @@ export const useIsMetricChanged = ({ metricId }: { metricId: string | undefined refetchCurrentMetric(); }); + const isEditor = canEdit(currentMetric?.permission); + const isMetricChanged = useMemo(() => { - if (!originalMetric || !isLatestVersion) return false; + if (!isEditor || !originalMetric || !isLatestVersion || !currentMetric) return false; return ( !currentMetric || @@ -57,7 +61,7 @@ export const useIsMetricChanged = ({ metricId }: { metricId: string | undefined 'version_number' ]) ); - }, [originalMetric, currentMetric, isLatestVersion]); + }, [originalMetric, currentMetric, isLatestVersion, isEditor]); return { onResetMetricToOriginal,