Skip to content

Commit ef8e89c

Browse files
committed
[DOP-33475] Обработка ошибок в компоненте для работы с SQL
1 parent a809051 commit ef8e89c

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/entities/transformation/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ const SHOW_BUTTONS_CONTEXT_INITIAL_VALUE: ShowButtonsContextProps = {
1515
isDisplayed: true,
1616
};
1717

18+
export const TRANSFORMATION_RESPONSE_LOCATION_POSITION = {
19+
CATEGORY: 1,
20+
TRANSFORMATION_TYPE: 3,
21+
};
22+
1823
export const ShowButtonsContext = createContext<ShowButtonsContextProps>(SHOW_BUTTONS_CONTEXT_INITIAL_VALUE);
1924

2025
export const TRANSFORMATIONS_FORM_DEFAULT_VALUE: TransformationsForm = {

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@ import { FormFieldError } from '@shared/config';
22

33
import { TransformationType } from '../../types';
44

5+
import { TRANSFORMATION_RESPONSE_LOCATION_POSITION } from './../../constants';
6+
57
/** Util for preparing received errors for use on a form */
68
export const prepareTransformationFormError = (errors: FormFieldError[]): FormFieldError[] => {
79
return errors.map((error) => {
810
const { location } = error;
9-
if (location[1] !== 'transformations') return error;
11+
if (location[TRANSFORMATION_RESPONSE_LOCATION_POSITION.CATEGORY] !== 'transformations') return error;
1012

11-
switch ((location as string[])[3] as TransformationType) {
13+
switch (
14+
(location as string[])[TRANSFORMATION_RESPONSE_LOCATION_POSITION.TRANSFORMATION_TYPE] as TransformationType
15+
) {
1216
case TransformationType.FILTER_SQL:
1317
//location : ['body', 'transformations', 3, 'sql', 'query']
1418
/* From the backend, the error record comes in a simple form in accordance with the api.
1519
Return it to the state it was stored in the form */
16-
const newLocation = location.slice(0, 4).concat(0).concat(location.slice(4));
20+
const insertPosition = TRANSFORMATION_RESPONSE_LOCATION_POSITION.TRANSFORMATION_TYPE + 1;
21+
const newLocation = location.slice(0, insertPosition).concat(0).concat(location.slice(insertPosition));
1722
return { ...error, location: newLocation } as FormFieldError;
1823

1924
default:

0 commit comments

Comments
 (0)