Skip to content

Commit 1f13b10

Browse files
author
Zabilsya
committed
[DOP-24309] fix transformations field update
1 parent 9de816b commit 1f13b10

File tree

6 files changed

+64
-39
lines changed

6 files changed

+64
-39
lines changed
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
import { createContext } from 'react';
22

3-
import { ShowButtonsContextProps } from './types';
3+
import { ShowButtonsContextProps, Transformations, TransformationsForm, TransformationType } from './types';
44

55
const SHOW_BUTTONS_CONTEXT_INITIAL_VALUE: ShowButtonsContextProps = {
66
isDisplayed: true,
77
};
88

99
export const ShowButtonsContext = createContext<ShowButtonsContextProps>(SHOW_BUTTONS_CONTEXT_INITIAL_VALUE);
10+
11+
export const TRANSFORMATIONS_FORM_DEFAULT_VALUE: TransformationsForm = {
12+
[TransformationType.FILTER_ROWS]: [],
13+
[TransformationType.FILTER_COLUMNS]: [],
14+
[TransformationType.FILTER_FILE]: [],
15+
};
16+
17+
export const TRANSFORMATIONS_REQUEST_DEFAULT_VALUE: Transformations = [
18+
{
19+
type: TransformationType.FILTER_ROWS,
20+
filters: [],
21+
},
22+
{
23+
type: TransformationType.FILTER_COLUMNS,
24+
filters: [],
25+
},
26+
{
27+
type: TransformationType.FILTER_FILE,
28+
filters: [],
29+
},
30+
];

src/entities/transformation/utils/prepareTransformationForm/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { parseFileSize } from '@entities/file/@x/transformation';
33
import { TransformationFilterFileType, Transformations, TransformationsForm, TransformationType } from '../../types';
44

55
/** Util for mapping of transformations data from backend to appropriate form value type */
6-
export const prepareTransformationForm = (data: Transformations): TransformationsForm => {
6+
export const prepareTransformationForm = (data: Transformations): Partial<TransformationsForm> => {
77
return data.reduce((prev, curr) => {
88
switch (curr.type) {
99
case TransformationType.FILTER_ROWS:
Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
1+
import { TRANSFORMATIONS_FORM_DEFAULT_VALUE, TRANSFORMATIONS_REQUEST_DEFAULT_VALUE } from '../../constants';
12
import { TransformationFilterFileType, Transformations, TransformationsForm, TransformationType } from '../../types';
23

34
/** Util for mapping of transformations data from form value to appropriate type for backend */
45
export const prepareTransformationRequest = (data?: TransformationsForm): Transformations => {
56
if (!data) {
6-
return [];
7+
return TRANSFORMATIONS_REQUEST_DEFAULT_VALUE;
78
}
89

9-
return (Object.keys(data) as Array<keyof TransformationsForm>).map((key) => {
10-
switch (key) {
11-
case TransformationType.FILTER_ROWS:
12-
return {
13-
type: TransformationType.FILTER_ROWS,
14-
filters: data[key] || [],
15-
};
16-
case TransformationType.FILTER_COLUMNS:
17-
return {
18-
type: TransformationType.FILTER_COLUMNS,
19-
filters: data[key] || [],
20-
};
21-
case TransformationType.FILTER_FILE:
22-
return {
23-
type: TransformationType.FILTER_FILE,
24-
filters: (data[key] || []).map((filter) => {
25-
switch (filter.type) {
26-
case TransformationFilterFileType.NAME_GLOB:
27-
case TransformationFilterFileType.NAME_REGEXP:
28-
return filter;
29-
case TransformationFilterFileType.FILE_SIZE_MIN:
30-
case TransformationFilterFileType.FILE_SIZE_MAX:
31-
return { type: filter.type, value: `${filter.extra_value}${filter.unit}` };
32-
}
33-
}),
34-
};
35-
}
36-
});
10+
return (Object.keys({ ...TRANSFORMATIONS_FORM_DEFAULT_VALUE, ...data }) as Array<keyof TransformationsForm>).map(
11+
(key) => {
12+
switch (key) {
13+
case TransformationType.FILTER_ROWS:
14+
return {
15+
type: TransformationType.FILTER_ROWS,
16+
filters: data[key] || [],
17+
};
18+
case TransformationType.FILTER_COLUMNS:
19+
return {
20+
type: TransformationType.FILTER_COLUMNS,
21+
filters: data[key] || [],
22+
};
23+
case TransformationType.FILTER_FILE:
24+
return {
25+
type: TransformationType.FILTER_FILE,
26+
filters: (data[key] || []).map((filter) => {
27+
switch (filter.type) {
28+
case TransformationFilterFileType.NAME_GLOB:
29+
case TransformationFilterFileType.NAME_REGEXP:
30+
return filter;
31+
case TransformationFilterFileType.FILE_SIZE_MIN:
32+
case TransformationFilterFileType.FILE_SIZE_MAX:
33+
return { type: filter.type, value: `${filter.extra_value}${filter.unit}` };
34+
}
35+
}),
36+
};
37+
}
38+
},
39+
);
3740
};

src/features/transfer/MutateTransferForm/components/TransferConnectionsCanvas/TransferConnectionsCanvas.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export const TransferConnectionsCanvas = ({ groupId, isDisplayedButtons = true }
2323
const initialNodes = useMemo(() => {
2424
return getInitialNodes({
2525
groupId,
26-
hasFilterRows: !!initialTransformations[TransformationType.FILTER_ROWS],
27-
hasFilterColumns: !!initialTransformations[TransformationType.FILTER_COLUMNS],
28-
hasFilterFile: !!initialTransformations[TransformationType.FILTER_FILE],
26+
hasFilterRows: !!initialTransformations[TransformationType.FILTER_ROWS]?.length,
27+
hasFilterColumns: !!initialTransformations[TransformationType.FILTER_COLUMNS]?.length,
28+
hasFilterFile: !!initialTransformations[TransformationType.FILTER_FILE]?.length,
2929
});
3030
}, [groupId, initialTransformations]);
3131

src/shared/ui/ManagedForm/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ export const ManagedForm = <T extends object, R>({
2929
const onFinish = (values: T) => {
3030
setLoading(true);
3131
mutate(values, {
32-
onSuccess: (response) => {
32+
onSuccess: async (response) => {
33+
await Promise.all(keysInvalidateQueries.map((params) => queryClient.invalidateQueries(...params)));
3334
onSuccess(response);
34-
keysInvalidateQueries.forEach((params) => {
35-
queryClient.invalidateQueries(...params);
36-
});
35+
3736
if (isHiddenLoadingOnSuccess) {
3837
setLoading(false);
3938
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { TRANSFORMATIONS_FORM_DEFAULT_VALUE } from '@entities/transformation';
2+
13
export const CREATE_TRANSFER_INITIAL_VALUES = {
24
is_scheduled: false,
3-
transformations: {},
5+
transformations: TRANSFORMATIONS_FORM_DEFAULT_VALUE,
46
};

0 commit comments

Comments
 (0)