From 619bb6d2c7495cb92e23462357949c8852c617c9 Mon Sep 17 00:00:00 2001 From: Ben Elferink Date: Tue, 22 Oct 2024 14:45:44 +0300 Subject: [PATCH] feat: custom fields with state management --- .../action-custom-fields.tsx | 12 ++-- .../main/actions/choose-action-body/index.tsx | 24 ++++++-- .../webapp/hooks/actions/useActionFormData.ts | 60 ++++++++++++++++--- 3 files changed, 78 insertions(+), 18 deletions(-) diff --git a/frontend/webapp/containers/main/actions/choose-action-body/action-custom-fields.tsx b/frontend/webapp/containers/main/actions/choose-action-body/action-custom-fields.tsx index 259a62233..7d782038c 100644 --- a/frontend/webapp/containers/main/actions/choose-action-body/action-custom-fields.tsx +++ b/frontend/webapp/containers/main/actions/choose-action-body/action-custom-fields.tsx @@ -4,6 +4,8 @@ import type { ActionsType } from '@/types' interface ActionCustomFieldsProps { actionType?: ActionsType + value: any + setValue: (value: any) => void } const FieldWrapper = styled.div` @@ -15,13 +17,13 @@ const FieldTitle = styled(Text)` margin-bottom: 12px; ` -const ActionCustomFields: React.FC = ({ actionType }) => { +const ActionCustomFields: React.FC = ({ actionType, value, setValue }) => { switch (actionType) { case 'AddClusterInfo': return ( Attributes to add - console.log(arr)} /> + setValue(arr)} /> ) @@ -29,7 +31,7 @@ const ActionCustomFields: React.FC = ({ actionType }) = return ( Attributes to delete - console.log(arr)} /> + setValue(arr)} /> ) @@ -37,7 +39,7 @@ const ActionCustomFields: React.FC = ({ actionType }) = return ( Attributes to rename - console.log(arr)} /> + setValue(arr)} /> ) @@ -45,7 +47,7 @@ const ActionCustomFields: React.FC = ({ actionType }) = return ( Attributes to mask - console.log(arr)} /> + setValue(arr)} /> ) 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 94e3fe6ab..4e2b20eef 100644 --- a/frontend/webapp/containers/main/actions/choose-action-body/index.tsx +++ b/frontend/webapp/containers/main/actions/choose-action-body/index.tsx @@ -1,4 +1,4 @@ -import React, { Fragment } from 'react' +import React, { Fragment, useEffect, useMemo } from 'react' import styled from 'styled-components' import { CheckboxList, DocsButton, Input, Text, TextArea } from '@/reuseable-components' import { MONITORING_OPTIONS } from '@/components/setup/destination/utils' @@ -26,7 +26,13 @@ interface ChooseActionContentProps { } const ChooseActionBody: React.FC = ({ action }) => { - const { actionName, setActionName, actionNotes, setActionNotes, exportedSignals, setExportedSignals } = useActionFormData() + const { formData, handleFormChange, resetFormData, exportedSignals, setExportedSignals } = useActionFormData() + + useEffect(() => { + return () => { + resetFormData() + } + }, []) return ( @@ -49,14 +55,22 @@ const ChooseActionBody: React.FC = ({ action }) => { Action name - setActionName(value)} /> + handleFormChange('name', value)} + /> - + handleFormChange('details', JSON.stringify(val))} + /> Notes -