diff --git a/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/add-cluster-info.tsx b/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/add-cluster-info.tsx new file mode 100644 index 000000000..3534faf59 --- /dev/null +++ b/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/add-cluster-info.tsx @@ -0,0 +1,61 @@ +import React, { useMemo } from 'react'; +import styled from 'styled-components'; +import { KeyValueInputsList, Text } from '@/reuseable-components'; + +const FieldWrapper = styled.div` + width: 100%; + margin: 8px 0; +`; + +const FieldTitle = styled(Text)` + margin-bottom: 12px; +`; + +type Props = { + value: string; + setValue: (value: string) => void; +}; + +type Parsed = { + clusterAttributes: { + attributeName: string; + attributeStringValue: string; + }[]; +}; + +const AddClusterInfo: React.FC = ({ value, setValue }) => { + const mappedValue = useMemo( + () => + value ? (JSON.parse(value) as Parsed).clusterAttributes.map((obj) => ({ key: obj.attributeName, value: obj.attributeStringValue })) : undefined, + [value] + ); + + const handleChange = ( + arr: { + key: string; + value: string; + }[] + ) => { + const payload: Parsed = { + clusterAttributes: [], + }; + + arr.forEach((obj) => { + payload.clusterAttributes.push({ + attributeName: obj.key, + attributeStringValue: obj.value, + }); + }); + + setValue(JSON.stringify(payload)); + }; + + return ( + + Attributes to add + + + ); +}; + +export default AddClusterInfo; diff --git a/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/delete-attributes.tsx b/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/delete-attributes.tsx new file mode 100644 index 000000000..84507cb85 --- /dev/null +++ b/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/delete-attributes.tsx @@ -0,0 +1,42 @@ +import React, { useMemo } from 'react'; +import styled from 'styled-components'; +import { InputList, Text } from '@/reuseable-components'; + +const FieldWrapper = styled.div` + width: 100%; + margin: 8px 0; +`; + +const FieldTitle = styled(Text)` + margin-bottom: 12px; +`; + +type Props = { + value: string; + setValue: (value: string) => void; +}; + +type Parsed = { + attributeNamesToDelete: string[]; +}; + +const DeleteAttributes: React.FC = ({ value, setValue }) => { + const mappedValue = useMemo(() => (value ? (JSON.parse(value) as Parsed).attributeNamesToDelete : undefined), [value]); + + const handleChange = (arr: string[]) => { + const payload: Parsed = { + attributeNamesToDelete: arr, + }; + + setValue(JSON.stringify(payload)); + }; + + return ( + + Attributes to delete + + + ); +}; + +export default DeleteAttributes; diff --git a/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/index.tsx b/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/index.tsx new file mode 100644 index 000000000..ccd1a04ff --- /dev/null +++ b/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/index.tsx @@ -0,0 +1,45 @@ +import { ActionsType } from '@/types'; +import AddClusterInfo from './add-cluster-info'; +import DeleteAttributes from './delete-attributes'; +import RenameAttributes from './rename-attributes'; +import PiiMasking from './pii-masking'; + +interface ActionCustomFieldsProps { + actionType?: ActionsType; + value: string; + setValue: (value: string) => void; +} + +const ActionCustomFields: React.FC = ({ actionType, value, setValue }) => { + switch (actionType) { + case ActionsType.ADD_CLUSTER_INFO: { + return ; + } + + case ActionsType.DELETE_ATTRIBUTES: { + return ; + } + + case ActionsType.RENAME_ATTRIBUTES: { + return ; + } + + case ActionsType.PII_MASKING: { + return ; + } + + case ActionsType.ERROR_SAMPLER: + return null; + + case ActionsType.PROBABILISTIC_SAMPLER: + return null; + + case ActionsType.LATENCY_SAMPLER: + return null; + + default: + return null; + } +}; + +export default ActionCustomFields; diff --git a/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/pii-masking.tsx b/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/pii-masking.tsx new file mode 100644 index 000000000..e286ffb82 --- /dev/null +++ b/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/pii-masking.tsx @@ -0,0 +1,42 @@ +import React, { useMemo } from 'react'; +import styled from 'styled-components'; +import { InputList, Text } from '@/reuseable-components'; + +const FieldWrapper = styled.div` + width: 100%; + margin: 8px 0; +`; + +const FieldTitle = styled(Text)` + margin-bottom: 12px; +`; + +type Props = { + value: string; + setValue: (value: string) => void; +}; + +type Parsed = { + piiCategories: string[]; +}; + +const PiiMasking: React.FC = ({ value, setValue }) => { + const mappedValue = useMemo(() => (value ? (JSON.parse(value) as Parsed).piiCategories : undefined), [value]); + + const handleChange = (arr: string[]) => { + const payload: Parsed = { + piiCategories: arr, + }; + + setValue(JSON.stringify(payload)); + }; + + return ( + + Attributes to mask + + + ); +}; + +export default PiiMasking; diff --git a/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/rename-attributes.tsx b/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/rename-attributes.tsx new file mode 100644 index 000000000..209977015 --- /dev/null +++ b/frontend/webapp/containers/main/actions/choose-action-body/custom-fields/rename-attributes.tsx @@ -0,0 +1,56 @@ +import React, { useMemo } from 'react'; +import styled from 'styled-components'; +import { KeyValueInputsList, Text } from '@/reuseable-components'; + +const FieldWrapper = styled.div` + width: 100%; + margin: 8px 0; +`; + +const FieldTitle = styled(Text)` + margin-bottom: 12px; +`; + +type Props = { + value: string; + setValue: (value: string) => void; +}; + +type Parsed = { + renames: { + [oldKey: string]: string; + }; +}; + +const RenameAttributes: React.FC = ({ value, setValue }) => { + const mappedValue = useMemo( + () => (value ? Object.entries((JSON.parse(value) as Parsed).renames).map(([k, v]) => ({ key: k, value: v })) : undefined), + [value] + ); + + const handleChange = ( + arr: { + key: string; + value: string; + }[] + ) => { + const payload: Parsed = { + renames: {}, + }; + + arr.forEach((obj) => { + payload.renames[obj.key] = obj.value; + }); + + setValue(JSON.stringify(payload)); + }; + + return ( + + Attributes to rename + + + ); +}; + +export default RenameAttributes; diff --git a/frontend/webapp/containers/main/actions/choose-action-body/index.tsx b/frontend/webapp/containers/main/actions/choose-action-body/index.tsx index 682a4bfb4..6190373e3 100644 --- a/frontend/webapp/containers/main/actions/choose-action-body/index.tsx +++ b/frontend/webapp/containers/main/actions/choose-action-body/index.tsx @@ -1,6 +1,6 @@ import React from 'react'; import styled from 'styled-components'; -import ActionCustomFields from './action-custom-fields'; +import ActionCustomFields from './custom-fields'; import { ActionFormData } from '@/hooks/actions/useActionFormData'; import { type ActionOption } from '../choose-action-modal/action-options'; import { DocsButton, Input, Text, TextArea } from '@/reuseable-components'; @@ -52,11 +52,7 @@ const ChooseActionBody: React.FC = ({ action, formData /> - handleFormChange('details', JSON.stringify(val))} - /> + handleFormChange('details', val)} /> Notes