From 72c30c7739a47b42d0f2dbb60c171d914bd3790c Mon Sep 17 00:00:00 2001 From: yashashk Date: Wed, 13 Nov 2024 16:55:51 +0530 Subject: [PATCH 1/2] #OBS-I304 : Fixed add transformations and pii section --- .../AddTransformationExpression.tsx | 236 ++++++++++-------- .../Processing/ProcessingSection/Pii/Pii.tsx | 113 +++++++-- 2 files changed, 228 insertions(+), 121 deletions(-) diff --git a/web-console-v2/src/pages/StepsPages/Processing/ProcessingSection/AddTransformationExpression/AddTransformationExpression.tsx b/web-console-v2/src/pages/StepsPages/Processing/ProcessingSection/AddTransformationExpression/AddTransformationExpression.tsx index cca7033c..90f7e2fe 100644 --- a/web-console-v2/src/pages/StepsPages/Processing/ProcessingSection/AddTransformationExpression/AddTransformationExpression.tsx +++ b/web-console-v2/src/pages/StepsPages/Processing/ProcessingSection/AddTransformationExpression/AddTransformationExpression.tsx @@ -6,12 +6,20 @@ import { DialogActions, DialogContent, DialogTitle, - Popover + Popover, + Grid, + FormControl, + InputLabel, + Select, + MenuItem, + TextField, + FormLabel, + RadioGroup, + FormControlLabel, + Radio } from '@mui/material'; -import TransformationForm from 'components/Form/DynamicForm'; -import {v4 as uuidv4} from 'uuid'; -import schema from './Schema'; -import React, { useEffect, useRef, useState } from 'react'; +import { v4 as uuidv4 } from 'uuid'; +import React, { useEffect, useState } from 'react'; import * as _ from 'lodash'; import { Stack } from '@mui/material'; import CloseOutlinedIcon from '@mui/icons-material/CloseOutlined'; @@ -20,7 +28,6 @@ import JSONataPlayground from 'components/JsonPlay/JSONataPlayground'; import { evaluateDataType } from 'pages/StepsPages/Processing/utils/dataTypeUtil'; import { Alert } from '@mui/material'; import en from 'utils/locales/en.json'; -import { useAsyncDebounce } from 'react-table'; interface FormData { [key: string]: unknown; @@ -40,33 +47,30 @@ interface TransformationFormProps { } const AddTransformationExpression = (props: any) => { - const { data, handleAddOrEdit, onClose, edit = false, transformationOptions, jsonData } = props; + const { data, handleAddOrEdit, onClose, edit = false, transformationOptions, jsonData, } = props; + const [anchorEl, setAnchorEl] = useState(null); const [evaluationData, setEvaluationData] = useState(''); const [stateId, setStateId] = useState(uuidv4()) const [transformErrors, setTransformErrors] = useState(false); - const [extraErrors, setExtraErrors] = useState({}); const open = Boolean(anchorEl); - const [formErrors, setFormErrors] = useState([]); - const [formData, setFormData] = useState<{ [key: string]: any }>({}); - - if (!_.isEmpty(transformationOptions)) - _.set( - schema, - ['schema', 'properties', 'section', 'properties', 'transformations', 'enum'], - transformationOptions - ); + const [formData, setFormData] = useState({ + section: { + transformations: '', + transformationType: '', + transformationMode: 'Strict' + } + }); useEffect(() => { if (!_.isEmpty(data)) { - const type = _.get(data, ['transformationType']); - + const type = _.get(data, ['transformation']); const existingData = { section: { transformations: _.get(data, ['column']), - transformationType: _.isEqual(type, 'custom') ? 'jsonata' : type, + transformationType: type, transformationMode: _.get(data, ['transformationMode']), expression: _.get(data, ['transformation']) } @@ -81,32 +85,17 @@ const AddTransformationExpression = (props: any) => { setAnchorEl(event.currentTarget); }; - const handleClose = async () => { - - const newData = {...formData}; - const keyPath = ['section', 'expression']; - _.set(newData, keyPath, evaluationData); - setFormData(newData); - setFormErrors([]) - if (evaluationData) { - const newExtraErrors = { + const handleClose = () => { + if (!transformationTypeError) { + setFormData((prevState: any) => ({ + ...prevState, section: { - expression: { - __errors: [] - } + ...prevState.section, + transformationType: evaluationData } - }; - try { - await evaluateDataType(evaluationData, jsonData); - setExtraErrors(newExtraErrors); - } catch (error) { - const message = _.get(error, 'message'); - _.set(newExtraErrors, ['section', 'expression', '__errors', 0], message); - setFormErrors([message]); - setExtraErrors(newExtraErrors) - } + })); } - setStateId(uuidv4()) + setAnchorEl(null); }; @@ -114,10 +103,6 @@ const AddTransformationExpression = (props: any) => { setAnchorEl(null); }; - const isJsonata = true; - - const jsonataData = _.get(formData, ['section', 'expression']); - const onHandleClick = async () => { const newData = _.get(formData, ['section']); const array = []; @@ -133,7 +118,7 @@ const AddTransformationExpression = (props: any) => { field_key: _.get(newData, ['transformations'], ''), transformation_function: { type: 'jsonata', - expr: _.get(newData, ['expression'], ''), + expr: _.get(newData, ['transformationType'], ''), category: 'transform' }, mode: _.get(newData, ['transformationMode'], '') @@ -141,48 +126,66 @@ const AddTransformationExpression = (props: any) => { action: 'upsert' }; - const datatype = await evaluateDataType(_.get(newData, ['expression'], ''), jsonData); - _.set( - obj, - ['value', 'transformation_function', 'datatype'], - _.get(datatype, 'data_type') - ); + try { + const datatype = await evaluateDataType(_.get(newData, ['transformationType'], ''), jsonData); + _.set( + obj, + ['value', 'transformation_function', 'datatype'], + _.get(datatype, 'data_type') + ); - array.push(obj); - handleAddOrEdit(array); - onClose(); + array.push(obj); + handleAddOrEdit(array); + onClose(); + } + catch (error) { + const message = _.get(error, 'message', 'Invalid transformation type'); + setTransformationTypeError(message); + } }; - const handleChange: TransformationFormProps['onChange'] = useAsyncDebounce(async (formData, errors) => { - - const expression = _.get(formData, ['section', 'expression']); - const newExtraErrors = { - section: { - expression: { - __errors: [] - } + const transformationType = _.get(formData, ['section', 'transformationType']); + const handleErrors = async () => { + if (transformationType) { + try { + await evaluateDataType(transformationType, jsonData); + setTransformationTypeError(null); + setStateId(uuidv4()); + } catch (error) { + const message = _.get(error, 'message', 'Invalid transformation type'); + setTransformationTypeError(message); } - }; + } + }; - if (errors) { - setFormErrors(errors); - } else { - setFormErrors([]); + useEffect(() => { + handleErrors() + if (_.isEmpty(transformationType)) { + setTransformationTypeError(null) } + }, [transformationType]) - if (expression) { - try { - await evaluateDataType(expression, jsonData); - } catch (error) { - const message = _.get(error, 'message'); - _.set(newExtraErrors, ['section', 'expression', '__errors', 0], message); - setFormErrors([message]); + const [transformationTypeError, setTransformationTypeError] = useState(null); + const handleInputChange: any = (event: React.ChangeEvent) => { + const { name, value } = event.target; + setFormData((prevState: any) => ({ + ...prevState, + section: { + ...prevState.section, + [name]: value } - } - setExtraErrors(newExtraErrors); - setFormData(formData); - setStateId(uuidv4()) - }, 800); + })); + }; + + const handleRadioChange = (event: React.ChangeEvent) => { + setFormData((prevState: any) => ({ + ...prevState, + section: { + ...prevState.section, + transformationMode: event.target.value + } + })); + }; return ( <> @@ -209,21 +212,55 @@ const AddTransformationExpression = (props: any) => { ) : null} - - + + + + Select Field + + + + + + + + + Skip On Transformation Failure? + + + } label="Yes" /> + } label="No" /> + + + + @@ -231,7 +268,6 @@ const AddTransformationExpression = (props: any) => { -