From f5e591b172ea712da91f99663e59cdd73787d88b Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Wed, 9 Apr 2025 15:25:48 -0600 Subject: [PATCH] =?UTF-8?q?readonly=20for=20files=20and=20delete=20?= =?UTF-8?q?=F0=9F=A7=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../features/files/EditFileContainer.tsx | 4 ++- .../DashboardViewFileController.tsx | 6 +++++ .../MetricViewFile/MetricViewFile.tsx | 6 +++++ .../DashboardThreeDotMenu.tsx | 25 ++++++++++--------- .../MetricThreeDotMenu.tsx | 3 ++- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/web/src/components/features/files/EditFileContainer.tsx b/web/src/components/features/files/EditFileContainer.tsx index 38d5fe5c5..9296a808e 100644 --- a/web/src/components/features/files/EditFileContainer.tsx +++ b/web/src/components/features/files/EditFileContainer.tsx @@ -10,8 +10,9 @@ export const EditFileContainer: React.FC<{ error: string | undefined; isSaving: boolean | undefined; language?: string; + readOnly: boolean | undefined; }> = React.memo( - ({ fileName, error, isSaving, file: fileProp = '', onSaveFile, language = 'yaml' }) => { + ({ fileName, readOnly, error, isSaving, file: fileProp = '', onSaveFile, language = 'yaml' }) => { const [file, setFile] = useState(fileProp || ''); const showPopup = file !== fileProp && !!file; @@ -37,6 +38,7 @@ export const EditFileContainer: React.FC<{ onChange={setFile} onMetaEnter={onSaveFilePreflight} error={error} + readOnly={readOnly} /> ); }); diff --git a/web/src/controllers/MetricController/MetricViewFile/MetricViewFile.tsx b/web/src/controllers/MetricController/MetricViewFile/MetricViewFile.tsx index f72ffe8b5..74d73147d 100644 --- a/web/src/controllers/MetricController/MetricViewFile/MetricViewFile.tsx +++ b/web/src/controllers/MetricController/MetricViewFile/MetricViewFile.tsx @@ -5,6 +5,7 @@ import { useMemoizedFn } from '@/hooks'; import { useBusterNotifications } from '@/context/BusterNotifications'; import { useGetMetric, useUpdateMetric } from '@/api/buster_rest/metrics'; import { EditFileContainer } from '@/components/features/files/EditFileContainer'; +import { useIsMetricReadOnly } from '@/context/Metrics/useIsMetricReadOnly'; export const MetricViewFile: React.FC<{ metricId: string }> = React.memo(({ metricId }) => { const { data: metric } = useGetMetric( @@ -28,6 +29,10 @@ export const MetricViewFile: React.FC<{ metricId: string }> = React.memo(({ metr wait: 0 }); + const { isReadOnly } = useIsMetricReadOnly({ + metricId + }); + const updateMetricErrorMessage = updateMetricError?.message; const { file, file_name } = metric || {}; @@ -47,6 +52,7 @@ export const MetricViewFile: React.FC<{ metricId: string }> = React.memo(({ metr onSaveFile={onSaveFile} error={updateMetricErrorMessage} isSaving={isUpdatingMetric} + readOnly={isReadOnly} /> ); }); diff --git a/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/DashboardContainerHeaderButtons/DashboardThreeDotMenu.tsx b/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/DashboardContainerHeaderButtons/DashboardThreeDotMenu.tsx index b8f8eeec4..d8c82130e 100644 --- a/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/DashboardContainerHeaderButtons/DashboardThreeDotMenu.tsx +++ b/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/DashboardContainerHeaderButtons/DashboardThreeDotMenu.tsx @@ -55,18 +55,19 @@ export const DashboardThreeDotMenu = React.memo(({ dashboardId }: { dashboardId: const isEditor = canEdit(permission); const items: DropdownItems = useMemo( - () => [ - isFilter && filterDashboardMenu, - isEditor && addContentToDashboardMenu, - { type: 'divider' }, - isOwner && shareMenu, - collectionSelectMenu, - favoriteDashboard, - versionHistoryItems, - { type: 'divider' }, - isEditor && renameDashboardMenu, - isOwner && deleteDashboardMenu - ], + () => + [ + isFilter && filterDashboardMenu, + isEditor && addContentToDashboardMenu, + { type: 'divider' }, + isOwner && shareMenu, + collectionSelectMenu, + favoriteDashboard, + versionHistoryItems, + { type: 'divider' }, + isEditor && renameDashboardMenu, + isOwner && deleteDashboardMenu + ].filter(Boolean) as DropdownItems, [ filterDashboardMenu, addContentToDashboardMenu, diff --git a/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/MetricContainerHeaderButtons/MetricThreeDotMenu.tsx b/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/MetricContainerHeaderButtons/MetricThreeDotMenu.tsx index 612fc26e0..cff9feef9 100644 --- a/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/MetricContainerHeaderButtons/MetricThreeDotMenu.tsx +++ b/web/src/layouts/ChatLayout/FileContainer/FileContainerHeader/MetricContainerHeaderButtons/MetricThreeDotMenu.tsx @@ -49,7 +49,6 @@ import { ShareMenuContent } from '@/components/features/ShareMenu/ShareMenuConte import { canEdit, getIsEffectiveOwner, getIsOwner } from '@/lib/share'; import { getShareAssetConfig } from '@/components/features/ShareMenu/helpers'; import { useAppLayoutContextSelector } from '@/context/BusterAppLayout'; -import { assetParamsToRoute } from '@/layouts/ChatLayout/ChatLayoutContext/helpers'; import { BusterRoutes, createBusterRoute } from '@/routes'; import { useListVersionDropdownItems } from '@/components/features/versionHistory/useListVersionDropdownItems'; @@ -453,6 +452,7 @@ const useDownloadPNGSelectMenu = ({ metricId }: { metricId: string }) => { const useDeleteMetricSelectMenu = ({ metricId }: { metricId: string }) => { const { mutateAsync: deleteMetric } = useDeleteMetric(); + const onChangePage = useAppLayoutContextSelector((x) => x.onChangePage); return useMemo( () => ({ @@ -461,6 +461,7 @@ const useDeleteMetricSelectMenu = ({ metricId }: { metricId: string }) => { icon: , onClick: async () => { await deleteMetric({ ids: [metricId] }); + onChangePage({ route: BusterRoutes.APP_METRIC }); } }), [metricId]