mirror of https://github.com/buster-so/buster.git
readonly for files and delete 🧨
This commit is contained in:
parent
871c599de8
commit
f5e591b172
|
@ -10,8 +10,9 @@ export const EditFileContainer: React.FC<{
|
||||||
error: string | undefined;
|
error: string | undefined;
|
||||||
isSaving: boolean | undefined;
|
isSaving: boolean | undefined;
|
||||||
language?: string;
|
language?: string;
|
||||||
|
readOnly: boolean | undefined;
|
||||||
}> = React.memo(
|
}> = 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 [file, setFile] = useState<string>(fileProp || '');
|
||||||
|
|
||||||
const showPopup = file !== fileProp && !!file;
|
const showPopup = file !== fileProp && !!file;
|
||||||
|
@ -37,6 +38,7 @@ export const EditFileContainer: React.FC<{
|
||||||
onChange={setFile}
|
onChange={setFile}
|
||||||
onMetaEnter={onSaveFilePreflight}
|
onMetaEnter={onSaveFilePreflight}
|
||||||
error={error}
|
error={error}
|
||||||
|
readOnly={readOnly}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SaveResetFilePopup
|
<SaveResetFilePopup
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { useMemoizedFn } from '@/hooks';
|
||||||
import { useBusterNotifications } from '@/context/BusterNotifications';
|
import { useBusterNotifications } from '@/context/BusterNotifications';
|
||||||
import { useGetDashboard, useUpdateDashboard } from '@/api/buster_rest/dashboards';
|
import { useGetDashboard, useUpdateDashboard } from '@/api/buster_rest/dashboards';
|
||||||
import { EditFileContainer } from '@/components/features/files/EditFileContainer';
|
import { EditFileContainer } from '@/components/features/files/EditFileContainer';
|
||||||
|
import { useIsDashboardReadOnly } from '@/context/Dashboards/useIsDashboardReadOnly';
|
||||||
|
|
||||||
export const DashboardViewFileController: React.FC<{
|
export const DashboardViewFileController: React.FC<{
|
||||||
dashboardId: string;
|
dashboardId: string;
|
||||||
|
@ -23,6 +24,10 @@ export const DashboardViewFileController: React.FC<{
|
||||||
saveToServer: true
|
saveToServer: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { isReadOnly } = useIsDashboardReadOnly({
|
||||||
|
dashboardId
|
||||||
|
});
|
||||||
|
|
||||||
const { file, file_name } = dashboard || {};
|
const { file, file_name } = dashboard || {};
|
||||||
const updateDashboardErrorMessage = updateDashboardError?.message;
|
const updateDashboardErrorMessage = updateDashboardError?.message;
|
||||||
|
|
||||||
|
@ -41,6 +46,7 @@ export const DashboardViewFileController: React.FC<{
|
||||||
onSaveFile={onSaveFile}
|
onSaveFile={onSaveFile}
|
||||||
error={updateDashboardErrorMessage}
|
error={updateDashboardErrorMessage}
|
||||||
isSaving={isUpdatingDashboard}
|
isSaving={isUpdatingDashboard}
|
||||||
|
readOnly={isReadOnly}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { useMemoizedFn } from '@/hooks';
|
||||||
import { useBusterNotifications } from '@/context/BusterNotifications';
|
import { useBusterNotifications } from '@/context/BusterNotifications';
|
||||||
import { useGetMetric, useUpdateMetric } from '@/api/buster_rest/metrics';
|
import { useGetMetric, useUpdateMetric } from '@/api/buster_rest/metrics';
|
||||||
import { EditFileContainer } from '@/components/features/files/EditFileContainer';
|
import { EditFileContainer } from '@/components/features/files/EditFileContainer';
|
||||||
|
import { useIsMetricReadOnly } from '@/context/Metrics/useIsMetricReadOnly';
|
||||||
|
|
||||||
export const MetricViewFile: React.FC<{ metricId: string }> = React.memo(({ metricId }) => {
|
export const MetricViewFile: React.FC<{ metricId: string }> = React.memo(({ metricId }) => {
|
||||||
const { data: metric } = useGetMetric(
|
const { data: metric } = useGetMetric(
|
||||||
|
@ -28,6 +29,10 @@ export const MetricViewFile: React.FC<{ metricId: string }> = React.memo(({ metr
|
||||||
wait: 0
|
wait: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { isReadOnly } = useIsMetricReadOnly({
|
||||||
|
metricId
|
||||||
|
});
|
||||||
|
|
||||||
const updateMetricErrorMessage = updateMetricError?.message;
|
const updateMetricErrorMessage = updateMetricError?.message;
|
||||||
|
|
||||||
const { file, file_name } = metric || {};
|
const { file, file_name } = metric || {};
|
||||||
|
@ -47,6 +52,7 @@ export const MetricViewFile: React.FC<{ metricId: string }> = React.memo(({ metr
|
||||||
onSaveFile={onSaveFile}
|
onSaveFile={onSaveFile}
|
||||||
error={updateMetricErrorMessage}
|
error={updateMetricErrorMessage}
|
||||||
isSaving={isUpdatingMetric}
|
isSaving={isUpdatingMetric}
|
||||||
|
readOnly={isReadOnly}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -55,18 +55,19 @@ export const DashboardThreeDotMenu = React.memo(({ dashboardId }: { dashboardId:
|
||||||
const isEditor = canEdit(permission);
|
const isEditor = canEdit(permission);
|
||||||
|
|
||||||
const items: DropdownItems = useMemo(
|
const items: DropdownItems = useMemo(
|
||||||
() => [
|
() =>
|
||||||
isFilter && filterDashboardMenu,
|
[
|
||||||
isEditor && addContentToDashboardMenu,
|
isFilter && filterDashboardMenu,
|
||||||
{ type: 'divider' },
|
isEditor && addContentToDashboardMenu,
|
||||||
isOwner && shareMenu,
|
{ type: 'divider' },
|
||||||
collectionSelectMenu,
|
isOwner && shareMenu,
|
||||||
favoriteDashboard,
|
collectionSelectMenu,
|
||||||
versionHistoryItems,
|
favoriteDashboard,
|
||||||
{ type: 'divider' },
|
versionHistoryItems,
|
||||||
isEditor && renameDashboardMenu,
|
{ type: 'divider' },
|
||||||
isOwner && deleteDashboardMenu
|
isEditor && renameDashboardMenu,
|
||||||
],
|
isOwner && deleteDashboardMenu
|
||||||
|
].filter(Boolean) as DropdownItems,
|
||||||
[
|
[
|
||||||
filterDashboardMenu,
|
filterDashboardMenu,
|
||||||
addContentToDashboardMenu,
|
addContentToDashboardMenu,
|
||||||
|
|
|
@ -49,7 +49,6 @@ import { ShareMenuContent } from '@/components/features/ShareMenu/ShareMenuConte
|
||||||
import { canEdit, getIsEffectiveOwner, getIsOwner } from '@/lib/share';
|
import { canEdit, getIsEffectiveOwner, getIsOwner } from '@/lib/share';
|
||||||
import { getShareAssetConfig } from '@/components/features/ShareMenu/helpers';
|
import { getShareAssetConfig } from '@/components/features/ShareMenu/helpers';
|
||||||
import { useAppLayoutContextSelector } from '@/context/BusterAppLayout';
|
import { useAppLayoutContextSelector } from '@/context/BusterAppLayout';
|
||||||
import { assetParamsToRoute } from '@/layouts/ChatLayout/ChatLayoutContext/helpers';
|
|
||||||
import { BusterRoutes, createBusterRoute } from '@/routes';
|
import { BusterRoutes, createBusterRoute } from '@/routes';
|
||||||
import { useListVersionDropdownItems } from '@/components/features/versionHistory/useListVersionDropdownItems';
|
import { useListVersionDropdownItems } from '@/components/features/versionHistory/useListVersionDropdownItems';
|
||||||
|
|
||||||
|
@ -453,6 +452,7 @@ const useDownloadPNGSelectMenu = ({ metricId }: { metricId: string }) => {
|
||||||
|
|
||||||
const useDeleteMetricSelectMenu = ({ metricId }: { metricId: string }) => {
|
const useDeleteMetricSelectMenu = ({ metricId }: { metricId: string }) => {
|
||||||
const { mutateAsync: deleteMetric } = useDeleteMetric();
|
const { mutateAsync: deleteMetric } = useDeleteMetric();
|
||||||
|
const onChangePage = useAppLayoutContextSelector((x) => x.onChangePage);
|
||||||
|
|
||||||
return useMemo(
|
return useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
|
@ -461,6 +461,7 @@ const useDeleteMetricSelectMenu = ({ metricId }: { metricId: string }) => {
|
||||||
icon: <Trash />,
|
icon: <Trash />,
|
||||||
onClick: async () => {
|
onClick: async () => {
|
||||||
await deleteMetric({ ids: [metricId] });
|
await deleteMetric({ ids: [metricId] });
|
||||||
|
onChangePage({ route: BusterRoutes.APP_METRIC });
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
[metricId]
|
[metricId]
|
||||||
|
|
Loading…
Reference in New Issue