mirror of https://github.com/buster-so/buster.git
drop query param on save to server
This commit is contained in:
parent
fe5848c079
commit
024552c864
|
@ -1,4 +1,5 @@
|
|||
import { type QueryClient, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useNavigate } from '@tanstack/react-router';
|
||||
import last from 'lodash/last';
|
||||
import { create } from 'mutative';
|
||||
import type { BusterCollection } from '@/api/asset_interfaces/collection';
|
||||
|
@ -27,6 +28,7 @@ import {
|
|||
export const useSaveMetric = (params?: { updateOnSave?: boolean }) => {
|
||||
const updateOnSave = params?.updateOnSave || false;
|
||||
const queryClient = useQueryClient();
|
||||
const navigate = useNavigate();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: updateMetric,
|
||||
|
@ -60,6 +62,11 @@ export const useSaveMetric = (params?: { updateOnSave?: boolean }) => {
|
|||
if (updateOnSave && data) {
|
||||
setMetricQueryData(queryClient, newMetric);
|
||||
}
|
||||
navigate({
|
||||
to: '.',
|
||||
ignoreBlocker: true,
|
||||
search: (prev) => ({ ...prev, metric_version_number: undefined }),
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
@ -361,7 +368,6 @@ export const useUpdateMetric = (params: {
|
|||
newMetricPartial: Omit<Partial<BusterMetric>, 'status'> & { id: string }
|
||||
) => {
|
||||
const { newMetric, prevMetric } = combineAndUpdateMetric(newMetricPartial);
|
||||
console.log('newMetric', newMetric);
|
||||
|
||||
if (newMetric && prevMetric && saveToServer) {
|
||||
return await saveMetricToServer(newMetric, prevMetric);
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
import React from 'react';
|
||||
import { useGetMetric, useUpdateMetric } from '@/api/buster_rest/metrics';
|
||||
import { EditFileContainer } from '@/components/features/files/EditFileContainer';
|
||||
import { useBusterNotifications } from '@/context/BusterNotifications';
|
||||
import { useIsMetricReadOnly } from '@/context/Metrics/useIsMetricReadOnly';
|
||||
import { useMemoizedFn } from '@/hooks/useMemoizedFn';
|
||||
|
||||
export const MetricViewFile: React.FC<{ metricId: string }> = React.memo(({ metricId }) => {
|
||||
const { data: metric } = useGetMetric(
|
||||
{ id: metricId },
|
||||
{
|
||||
select: ({ file, file_name }) => ({
|
||||
file,
|
||||
file_name,
|
||||
}),
|
||||
}
|
||||
);
|
||||
const { openSuccessMessage } = useBusterNotifications();
|
||||
const {
|
||||
mutateAsync: updateMetric,
|
||||
isPending: isUpdatingMetric,
|
||||
error: updateMetricError,
|
||||
} = useUpdateMetric({
|
||||
updateOnSave: true,
|
||||
saveToServer: true,
|
||||
updateVersion: false,
|
||||
});
|
||||
|
||||
const { isReadOnly } = useIsMetricReadOnly({
|
||||
metricId,
|
||||
});
|
||||
|
||||
const updateMetricErrorMessage = updateMetricError?.message;
|
||||
|
||||
const { file, file_name } = metric || {};
|
||||
|
||||
const onSaveFile = useMemoizedFn(async (file: string) => {
|
||||
await updateMetric({
|
||||
file,
|
||||
id: metricId,
|
||||
});
|
||||
openSuccessMessage(`${file_name} saved`);
|
||||
});
|
||||
|
||||
return (
|
||||
<EditFileContainer
|
||||
fileName={file_name}
|
||||
file={file}
|
||||
onSaveFile={onSaveFile}
|
||||
error={updateMetricErrorMessage}
|
||||
isSaving={isUpdatingMetric}
|
||||
readOnly={isReadOnly}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
MetricViewFile.displayName = 'MetricViewFile';
|
|
@ -1 +0,0 @@
|
|||
export * from './MetricViewFile';
|
Loading…
Reference in New Issue