readonly for files and delete 🧨

This commit is contained in:
Nate Kelley 2025-04-09 15:25:48 -06:00
parent 871c599de8
commit f5e591b172
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
5 changed files with 30 additions and 14 deletions

View File

@ -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<string>(fileProp || '');
const showPopup = file !== fileProp && !!file;
@ -37,6 +38,7 @@ export const EditFileContainer: React.FC<{
onChange={setFile}
onMetaEnter={onSaveFilePreflight}
error={error}
readOnly={readOnly}
/>
<SaveResetFilePopup

View File

@ -5,6 +5,7 @@ import { useMemoizedFn } from '@/hooks';
import { useBusterNotifications } from '@/context/BusterNotifications';
import { useGetDashboard, useUpdateDashboard } from '@/api/buster_rest/dashboards';
import { EditFileContainer } from '@/components/features/files/EditFileContainer';
import { useIsDashboardReadOnly } from '@/context/Dashboards/useIsDashboardReadOnly';
export const DashboardViewFileController: React.FC<{
dashboardId: string;
@ -23,6 +24,10 @@ export const DashboardViewFileController: React.FC<{
saveToServer: true
});
const { isReadOnly } = useIsDashboardReadOnly({
dashboardId
});
const { file, file_name } = dashboard || {};
const updateDashboardErrorMessage = updateDashboardError?.message;
@ -41,6 +46,7 @@ export const DashboardViewFileController: React.FC<{
onSaveFile={onSaveFile}
error={updateDashboardErrorMessage}
isSaving={isUpdatingDashboard}
readOnly={isReadOnly}
/>
);
});

View File

@ -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}
/>
);
});

View File

@ -55,7 +55,8 @@ export const DashboardThreeDotMenu = React.memo(({ dashboardId }: { dashboardId:
const isEditor = canEdit(permission);
const items: DropdownItems = useMemo(
() => [
() =>
[
isFilter && filterDashboardMenu,
isEditor && addContentToDashboardMenu,
{ type: 'divider' },
@ -66,7 +67,7 @@ export const DashboardThreeDotMenu = React.memo(({ dashboardId }: { dashboardId:
{ type: 'divider' },
isEditor && renameDashboardMenu,
isOwner && deleteDashboardMenu
],
].filter(Boolean) as DropdownItems,
[
filterDashboardMenu,
addContentToDashboardMenu,

View File

@ -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: <Trash />,
onClick: async () => {
await deleteMetric({ ids: [metricId] });
onChangePage({ route: BusterRoutes.APP_METRIC });
}
}),
[metricId]