From 1f13b10b6cf64549e915cb6977fdc97ea7372cbf Mon Sep 17 00:00:00 2001 From: Zabilsya Date: Wed, 5 Mar 2025 22:38:27 +0600 Subject: [PATCH] [DOP-24309] fix transformations field update --- src/entities/transformation/constants.ts | 23 ++++++- .../utils/prepareTransformationForm/index.ts | 2 +- .../prepareTransformationRequest/index.ts | 61 ++++++++++--------- .../TransferConnectionsCanvas.tsx | 6 +- src/shared/ui/ManagedForm/index.tsx | 7 +-- .../transfer/CreateTransfer/constants.ts | 4 +- 6 files changed, 64 insertions(+), 39 deletions(-) diff --git a/src/entities/transformation/constants.ts b/src/entities/transformation/constants.ts index 95e05290..ac722d9c 100644 --- a/src/entities/transformation/constants.ts +++ b/src/entities/transformation/constants.ts @@ -1,9 +1,30 @@ import { createContext } from 'react'; -import { ShowButtonsContextProps } from './types'; +import { ShowButtonsContextProps, Transformations, TransformationsForm, TransformationType } from './types'; const SHOW_BUTTONS_CONTEXT_INITIAL_VALUE: ShowButtonsContextProps = { isDisplayed: true, }; export const ShowButtonsContext = createContext(SHOW_BUTTONS_CONTEXT_INITIAL_VALUE); + +export const TRANSFORMATIONS_FORM_DEFAULT_VALUE: TransformationsForm = { + [TransformationType.FILTER_ROWS]: [], + [TransformationType.FILTER_COLUMNS]: [], + [TransformationType.FILTER_FILE]: [], +}; + +export const TRANSFORMATIONS_REQUEST_DEFAULT_VALUE: Transformations = [ + { + type: TransformationType.FILTER_ROWS, + filters: [], + }, + { + type: TransformationType.FILTER_COLUMNS, + filters: [], + }, + { + type: TransformationType.FILTER_FILE, + filters: [], + }, +]; diff --git a/src/entities/transformation/utils/prepareTransformationForm/index.ts b/src/entities/transformation/utils/prepareTransformationForm/index.ts index 3af5f398..ebb20479 100644 --- a/src/entities/transformation/utils/prepareTransformationForm/index.ts +++ b/src/entities/transformation/utils/prepareTransformationForm/index.ts @@ -3,7 +3,7 @@ import { parseFileSize } from '@entities/file/@x/transformation'; import { TransformationFilterFileType, Transformations, TransformationsForm, TransformationType } from '../../types'; /** Util for mapping of transformations data from backend to appropriate form value type */ -export const prepareTransformationForm = (data: Transformations): TransformationsForm => { +export const prepareTransformationForm = (data: Transformations): Partial => { return data.reduce((prev, curr) => { switch (curr.type) { case TransformationType.FILTER_ROWS: diff --git a/src/entities/transformation/utils/prepareTransformationRequest/index.ts b/src/entities/transformation/utils/prepareTransformationRequest/index.ts index 65aa8acb..fae8b29d 100644 --- a/src/entities/transformation/utils/prepareTransformationRequest/index.ts +++ b/src/entities/transformation/utils/prepareTransformationRequest/index.ts @@ -1,37 +1,40 @@ +import { TRANSFORMATIONS_FORM_DEFAULT_VALUE, TRANSFORMATIONS_REQUEST_DEFAULT_VALUE } from '../../constants'; import { TransformationFilterFileType, Transformations, TransformationsForm, TransformationType } from '../../types'; /** Util for mapping of transformations data from form value to appropriate type for backend */ export const prepareTransformationRequest = (data?: TransformationsForm): Transformations => { if (!data) { - return []; + return TRANSFORMATIONS_REQUEST_DEFAULT_VALUE; } - return (Object.keys(data) as Array).map((key) => { - switch (key) { - case TransformationType.FILTER_ROWS: - return { - type: TransformationType.FILTER_ROWS, - filters: data[key] || [], - }; - case TransformationType.FILTER_COLUMNS: - return { - type: TransformationType.FILTER_COLUMNS, - filters: data[key] || [], - }; - case TransformationType.FILTER_FILE: - return { - type: TransformationType.FILTER_FILE, - filters: (data[key] || []).map((filter) => { - switch (filter.type) { - case TransformationFilterFileType.NAME_GLOB: - case TransformationFilterFileType.NAME_REGEXP: - return filter; - case TransformationFilterFileType.FILE_SIZE_MIN: - case TransformationFilterFileType.FILE_SIZE_MAX: - return { type: filter.type, value: `${filter.extra_value}${filter.unit}` }; - } - }), - }; - } - }); + return (Object.keys({ ...TRANSFORMATIONS_FORM_DEFAULT_VALUE, ...data }) as Array).map( + (key) => { + switch (key) { + case TransformationType.FILTER_ROWS: + return { + type: TransformationType.FILTER_ROWS, + filters: data[key] || [], + }; + case TransformationType.FILTER_COLUMNS: + return { + type: TransformationType.FILTER_COLUMNS, + filters: data[key] || [], + }; + case TransformationType.FILTER_FILE: + return { + type: TransformationType.FILTER_FILE, + filters: (data[key] || []).map((filter) => { + switch (filter.type) { + case TransformationFilterFileType.NAME_GLOB: + case TransformationFilterFileType.NAME_REGEXP: + return filter; + case TransformationFilterFileType.FILE_SIZE_MIN: + case TransformationFilterFileType.FILE_SIZE_MAX: + return { type: filter.type, value: `${filter.extra_value}${filter.unit}` }; + } + }), + }; + } + }, + ); }; diff --git a/src/features/transfer/MutateTransferForm/components/TransferConnectionsCanvas/TransferConnectionsCanvas.tsx b/src/features/transfer/MutateTransferForm/components/TransferConnectionsCanvas/TransferConnectionsCanvas.tsx index ece488f4..a0120fe1 100644 --- a/src/features/transfer/MutateTransferForm/components/TransferConnectionsCanvas/TransferConnectionsCanvas.tsx +++ b/src/features/transfer/MutateTransferForm/components/TransferConnectionsCanvas/TransferConnectionsCanvas.tsx @@ -23,9 +23,9 @@ export const TransferConnectionsCanvas = ({ groupId, isDisplayedButtons = true } const initialNodes = useMemo(() => { return getInitialNodes({ groupId, - hasFilterRows: !!initialTransformations[TransformationType.FILTER_ROWS], - hasFilterColumns: !!initialTransformations[TransformationType.FILTER_COLUMNS], - hasFilterFile: !!initialTransformations[TransformationType.FILTER_FILE], + hasFilterRows: !!initialTransformations[TransformationType.FILTER_ROWS]?.length, + hasFilterColumns: !!initialTransformations[TransformationType.FILTER_COLUMNS]?.length, + hasFilterFile: !!initialTransformations[TransformationType.FILTER_FILE]?.length, }); }, [groupId, initialTransformations]); diff --git a/src/shared/ui/ManagedForm/index.tsx b/src/shared/ui/ManagedForm/index.tsx index 22c97e6b..7ddbd981 100644 --- a/src/shared/ui/ManagedForm/index.tsx +++ b/src/shared/ui/ManagedForm/index.tsx @@ -29,11 +29,10 @@ export const ManagedForm = ({ const onFinish = (values: T) => { setLoading(true); mutate(values, { - onSuccess: (response) => { + onSuccess: async (response) => { + await Promise.all(keysInvalidateQueries.map((params) => queryClient.invalidateQueries(...params))); onSuccess(response); - keysInvalidateQueries.forEach((params) => { - queryClient.invalidateQueries(...params); - }); + if (isHiddenLoadingOnSuccess) { setLoading(false); } diff --git a/src/widgets/transfer/CreateTransfer/constants.ts b/src/widgets/transfer/CreateTransfer/constants.ts index ef5d4e92..e4e7cc7a 100644 --- a/src/widgets/transfer/CreateTransfer/constants.ts +++ b/src/widgets/transfer/CreateTransfer/constants.ts @@ -1,4 +1,6 @@ +import { TRANSFORMATIONS_FORM_DEFAULT_VALUE } from '@entities/transformation'; + export const CREATE_TRANSFER_INITIAL_VALUES = { is_scheduled: false, - transformations: {}, + transformations: TRANSFORMATIONS_FORM_DEFAULT_VALUE, };