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;
|
||||
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
|
||||
|
|
|
@ -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}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue