From 12a381a3fa2de057b7b7f06b9004846cd370cfe8 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Tue, 8 Oct 2024 15:29:23 -0300 Subject: [PATCH] refactor: improve parameter render component (#3995) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: update dynamic parameter in ParameterRenderComponent to false * refactor: update CodeAreaComponent to use CodeAreaModal for node toolbar * feat: Add EmptyParameterComponent to render empty parameters * refactor: Add types for parameter render component Add typescript types for the parameter render component to improve code readability and maintainability. * feat: Add EmptyParameterComponent to render empty parameters * refactor: Update RefreshParameterComponent to use InputProps Update the RefreshParameterComponent to use the InputProps interface for better code readability and maintainability. * refactor: Update InputProps in parameterRenderComponent/types.ts Update the InputProps interface in parameterRenderComponent/types.ts to remove the Partial and simplify the composition of input props. This improves code readability and maintainability. * refactor: Update InputProps in parameterRenderComponent/types.ts * refactor: Update parameterRenderComponent/types.ts to use handleOnNewValue instead of onChange Update the parameterRenderComponent/types.ts file to import the handleOnNewValueType from "@/CustomNodes/hooks/use-handle-new-value" and replace the onChange function with handleOnNewValue in the BaseInputProps interface. This change improves code readability and maintainability. * update folder structure * refactor: Update TableModal to support disabled state Update the TableModal component to include a disabled prop, allowing the modal to be disabled when necessary. This improves the flexibility and usability of the component. * refactor: Update parameterRenderComponent/types.ts to include TableComponentType Update the parameterRenderComponent/types.ts file to include the TableComponentType interface, which defines the structure for a table component. This change improves code organization and maintainability. * refactor: Update parameterRenderComponent to use TableNodeComponent from the correct folder * refactor: Update codeAreaComponent imports and props in parameterRenderComponent Update the imports and props in the parameterRenderComponent file to reflect the changes made in the codeAreaComponent file. This refactor improves code organization and maintainability. * refactor: Update parameterRenderComponent/types.ts to include CodeAreaComponentType Update the parameterRenderComponent/types.ts file to include the CodeAreaComponentType interface, which defines the structure for a code area component. This change improves code organization and maintainability. * refactor: Remove unused import of CodeAreaComponent in nodeToolbarComponent Remove the unused import of CodeAreaComponent in the nodeToolbarComponent file to improve code cleanliness and maintainability. * refactor: Remove unused import of CodeAreaComponent in nodeToolbarComponent * refactor: Remove unused import of CodeAreaComponent in nodeToolbarComponent * refactor: Remove unused import of CodeAreaComponent in codeAreaComponent/index.tsx * refactor: Remove unused import of CodeAreaComponent in parameterRenderComponent/index.tsx * refactor: Update floatComponent imports and props in parameterRenderComponent Update the imports and props in the parameterRenderComponent file to reflect the changes made in the floatComponent file. This refactor improves code organization and maintainability. * refactor: Update floatComponent imports and props in parameterRenderComponent * update int component path * update int component type * update toogle location * refactor: Update ToggleComponentType in components/index.ts Remove the ToggleComponentType interface from the components/index.ts file. This change is part of a refactoring effort to remove unused code and improve code organization. * refactor: Update ToggleComponentType in components/index.ts Remove unused ToggleComponentType interface from components/index.ts * refactor: Update ToggleShadComponent to handle new value changes Refactor the ToggleShadComponent to handle new value changes by passing the updated value to the handleOnNewValue function. This improves the functionality and maintainability of the component. * refactor: Move InputFileComponent to parameterRenderComponent/components folder Move the InputFileComponent file from the src/frontend/src/components folder to the src/frontend/src/components/parameterRenderComponent/components folder. This change improves code organization and maintainability. * refactor: Add FileComponentType interface to parameterRenderComponent/types.ts Add the FileComponentType interface to the parameterRenderComponent/types.ts file. This interface defines the fileTypes property for the FileComponentType, allowing for better type checking and documentation. This change improves code organization and maintainability. * refactor: Update InputFileComponent props in parameterRenderComponent Update the props of the InputFileComponent in the parameterRenderComponent file to match the changes made in the index.tsx file. This refactor improves code organization and maintainability. * refactor: Move PromptAreaComponent to parameterRenderComponent/components folder * update types prompt field * refactor: Update PromptAreaComponent to handle new value changes Refactor the PromptAreaComponent to handle new value changes by passing the updated value to the handleOnNewValue function. This improves the functionality and maintainability of the component. * refactor: Move LinkComponent to parameterRenderComponent/components folder * refactor: Add LinkComponentType interface to parameterRenderComponent/types.ts Add the LinkComponentType interface to the parameterRenderComponent/types.ts file. This interface defines the icon and text properties for the LinkComponentType, allowing for better type checking and documentation. This change improves code organization and maintainability. * refactor: Update LinkComponent to use InputProps in parameterRenderComponent Update the LinkComponent in parameterRenderComponent to use the InputProps interface for better type checking and consistency. This refactor improves code organization and maintainability. * refactor: Move KeypairListComponent to parameterRenderComponent/components folder * refactor: Add KeyPairListComponentType interface to parameterRenderComponent/types.ts * refactor: Update KeypairListComponent to use InputProps in parameterRenderComponent Refactor the KeypairListComponent in parameterRenderComponent to use the InputProps interface for better type checking and consistency. This refactor improves code organization and maintainability. * refactor: Move DictComponent to parameterRenderComponent/components folder * refactor: Update KeyPairListComponentType interface in parameterRenderComponent/types.ts * refactor: Update KeypairListComponent to use InputProps in parameterRenderComponent * refactor: Move InputListComponent to parameterRenderComponent/components folder Move the InputListComponent to the parameterRenderComponent/components folder for better code organization and maintainability. * refactor: Add StrRenderComponentType interface to parameterRenderComponent/types.ts * refactor: Move InputListComponent to parameterRenderComponent/components folder * refactor: Move InputListComponent to parameterRenderComponent/components folder * refactor: Move InputListComponent to parameterRenderComponent/components folder Move the InputListComponent to the parameterRenderComponent/components folder for better code organization and maintainability. * refactor: Update InputListComponent to use InputProps in parameterRenderComponent Refactor the InputListComponent in parameterRenderComponent to use the InputProps interface for better type checking and consistency. This refactor improves code organization and maintainability. * refactor: Move IOFieldView to IOModal/components folder Move the IOFieldView component to the IOModal/components folder for better code organization and maintainability. * refactor: Move DropdownComponent to parameterRenderComponent/components folder * refactor: Add DropDownComponentType interface to parameterRenderComponent/types.ts * refactor: Update DropdownComponent import in StrRenderComponent Update the import statement for DropdownComponent in StrRenderComponent to reflect its new location in the parameterRenderComponent/components folder. This refactor improves code organization and maintainability. * refactor: Update StrRenderComponent to use baseInputProps Refactor the StrRenderComponent in parameterRenderComponent to use the baseInputProps object instead of individual props for better code organization and maintainability. * refactor: Update StrRenderComponent to use TextAreaComponent from correct location Update the import statement for TextAreaComponent in StrRenderComponent to reflect its new location in the parameterRenderComponent/components folder. This refactor improves code organization and maintainability. * remove unused imports * refactor: Add TextAreaComponentType interface to parameterRenderComponent/types.ts * refactor: Update TextAreaComponent to use handleOnNewValue instead of onChange Refactor the TextAreaComponent in parameterRenderComponent to use the handleOnNewValue function instead of the onChange function for better code consistency. This change aligns with the recent updates to the component's props and improves maintainability. * refactor: Update StrRenderComponent to use baseInputProps Refactor the StrRenderComponent in parameterRenderComponent to use the baseInputProps object instead of individual props for better code organization and maintainability. * refactor: Move inputGlobalComponent to parameterRenderComponent/components folder Move the inputGlobalComponent to the parameterRenderComponent/components folder to improve code organization and maintainability. * refactor: Move inputGlobalComponent to parameterRenderComponent/components folder * refactor: Update InputGlobalComponent to use handleOnNewValue instead of onChange Refactor the InputGlobalComponent in parameterRenderComponent to use the handleOnNewValue function instead of the onChange function for better code consistency. This change aligns with the recent updates to the component's props and improves maintainability. * refactor: Update StrRenderComponent to use baseInputProps Refactor the StrRenderComponent in parameterRenderComponent to use the baseInputProps object instead of individual props for better code organization and maintainability. * refactor: Move multiselectComponent to parameterRenderComponent/components folder Move the multiselectComponent to the parameterRenderComponent/components folder to improve code organization and maintainability. * refactor: Move MultiselectComponent to parameterRenderComponent/components folder Move the MultiselectComponent to the parameterRenderComponent/components folder to improve code organization and maintainability. * refactor: Move MultiselectComponent to parameterRenderComponent/components folder * refactor: Move MultiselectComponent to parameterRenderComponent/components folder * refactor: Remove unused code in StrRenderComponent * refactor: Remove unused code in StrRenderComponent * refactor: Remove unused code in StrRenderComponent * [autofix.ci] apply automated fixes * ✨ (tableInputComponent.spec.ts): add ua-parser-js library to parse user agent information for better control handling based on OS 🔧 (tableInputComponent.spec.ts): update key press event to use the correct control key based on the user's operating system for textarea selection. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Cristhian Zanforlin Lousa --- .../components/dropdownComponent/index.tsx | 4 +- .../component/strRenderComponent/index.tsx | 102 ------- .../components}/TableNodeComponent/index.tsx | 29 +- .../components}/codeAreaComponent/index.tsx | 29 +- .../components}/dictComponent/index.tsx | 23 +- .../components/dropdownComponent/index.tsx | 27 ++ .../emptyParameterComponent/index.tsx | 11 + .../components}/floatComponent/index.tsx | 14 +- .../components}/inputFileComponent/index.tsx | 14 +- .../inputGlobalComponent/index.tsx | 65 +++-- .../components}/inputListComponent/index.tsx | 31 +-- .../components}/intComponent/index.tsx | 16 +- .../keypairListComponent/index.tsx | 23 +- .../components}/linkComponent/index.tsx | 38 +-- .../multiselectComponent/index.tsx | 79 +++--- .../components}/promptComponent/index.tsx | 20 +- .../refreshParameterComponent/index.tsx | 11 + .../components/strRenderComponent/index.tsx | 47 ++++ .../components}/textAreaComponent/index.tsx | 24 +- .../components}/toggleShadComponent/index.tsx | 31 ++- .../parameterRenderComponent/index.tsx | 257 +++++++++--------- .../parameterRenderComponent/types.ts | 84 ++++++ .../tableAdvancedToggleCellRender/index.tsx | 13 +- .../src/components/tableComponent/index.tsx | 21 ++ src/frontend/src/constants/constants.ts | 5 + .../components/JSONInput/index.tsx | 4 +- .../IOModal/components/IOFieldView/index.tsx | 39 +-- src/frontend/src/modals/tableModal/index.tsx | 56 ++-- .../components/nodeToolbarComponent/index.tsx | 19 +- src/frontend/src/types/components/index.ts | 146 +--------- .../core/unit/tableInputComponent.spec.ts | 11 +- 31 files changed, 642 insertions(+), 651 deletions(-) delete mode 100644 src/frontend/src/components/parameterRenderComponent/component/strRenderComponent/index.tsx rename src/frontend/src/components/{ => parameterRenderComponent/components}/TableNodeComponent/index.tsx (85%) rename src/frontend/src/components/{ => parameterRenderComponent/components}/codeAreaComponent/index.tsx (75%) rename src/frontend/src/components/{ => parameterRenderComponent/components}/dictComponent/index.tsx (65%) create mode 100644 src/frontend/src/components/parameterRenderComponent/components/dropdownComponent/index.tsx create mode 100644 src/frontend/src/components/parameterRenderComponent/components/emptyParameterComponent/index.tsx rename src/frontend/src/components/{ => parameterRenderComponent/components}/floatComponent/index.tsx (75%) rename src/frontend/src/components/{ => parameterRenderComponent/components}/inputFileComponent/index.tsx (90%) rename src/frontend/src/components/{ => parameterRenderComponent/components}/inputGlobalComponent/index.tsx (65%) rename src/frontend/src/components/{ => parameterRenderComponent/components}/inputListComponent/index.tsx (78%) rename src/frontend/src/components/{ => parameterRenderComponent/components}/intComponent/index.tsx (85%) rename src/frontend/src/components/{ => parameterRenderComponent/components}/keypairListComponent/index.tsx (87%) rename src/frontend/src/components/{ => parameterRenderComponent/components}/linkComponent/index.tsx (53%) rename src/frontend/src/components/{ => parameterRenderComponent/components}/multiselectComponent/index.tsx (74%) rename src/frontend/src/components/{ => parameterRenderComponent/components}/promptComponent/index.tsx (75%) rename src/frontend/src/components/parameterRenderComponent/{component => components}/refreshParameterComponent/index.tsx (79%) create mode 100644 src/frontend/src/components/parameterRenderComponent/components/strRenderComponent/index.tsx rename src/frontend/src/components/{ => parameterRenderComponent/components}/textAreaComponent/index.tsx (83%) rename src/frontend/src/components/{ => parameterRenderComponent/components}/toggleShadComponent/index.tsx (53%) create mode 100644 src/frontend/src/components/parameterRenderComponent/types.ts diff --git a/src/frontend/src/components/dropdownComponent/index.tsx b/src/frontend/src/components/dropdownComponent/index.tsx index aa1ee20d1..c8fdb96f6 100644 --- a/src/frontend/src/components/dropdownComponent/index.tsx +++ b/src/frontend/src/components/dropdownComponent/index.tsx @@ -2,7 +2,7 @@ import { PopoverAnchor } from "@radix-ui/react-popover"; import Fuse from "fuse.js"; import { cloneDeep } from "lodash"; import { ChangeEvent, useEffect, useRef, useState } from "react"; -import { DropDownComponentType } from "../../types/components"; +import { DropDownComponent } from "../../types/components"; import { cn } from "../../utils/utils"; import { default as ForwardedIconComponent } from "../genericIconComponent"; import ShadTooltip from "../shadTooltipComponent"; @@ -31,7 +31,7 @@ export default function Dropdown({ editNode = false, id = "", children, -}: DropDownComponentType): JSX.Element { +}: DropDownComponent): JSX.Element { const [open, setOpen] = useState(children ? true : false); const refButton = useRef(null); diff --git a/src/frontend/src/components/parameterRenderComponent/component/strRenderComponent/index.tsx b/src/frontend/src/components/parameterRenderComponent/component/strRenderComponent/index.tsx deleted file mode 100644 index 9f0773f67..000000000 --- a/src/frontend/src/components/parameterRenderComponent/component/strRenderComponent/index.tsx +++ /dev/null @@ -1,102 +0,0 @@ -import { handleOnNewValueType } from "@/CustomNodes/hooks/use-handle-new-value"; -import { InputFieldType } from "@/types/api"; -import Dropdown from "../../../dropdownComponent"; -import InputGlobalComponent from "../../../inputGlobalComponent"; -import InputListComponent from "../../../inputListComponent"; -import MultiselectComponent from "../../../multiselectComponent"; -import TextAreaComponent from "../../../textAreaComponent"; - -export function StrRenderComponent({ - templateData, - value, - name, - disabled, - handleOnNewValue, - editNode, - id, -}: { - templateData: Partial; - value: any; - name: string; - disabled: boolean; - handleOnNewValue: handleOnNewValueType; - editNode: boolean; - id: string; -}) { - const onChange = (value: any, dbValue?: boolean, skipSnapshot?: boolean) => { - handleOnNewValue({ value, load_from_db: dbValue }, { skipSnapshot }); - }; - - if (!templateData.options) { - return templateData?.list ? ( - - ) : templateData.multiline ? ( - { - if (templateData.password !== undefined) { - handleOnNewValue( - { password: !templateData.password }, - { skipSnapshot: true }, - ); - } - }} - id={`textarea_${id}`} - disabled={disabled} - editNode={editNode} - value={value ?? ""} - onChange={onChange} - /> - ) : ( - - ); - } - - if (!!templateData.options && !!templateData?.list) { - return ( - - ); - } - - if (!!templateData.options) { - return ( - - ); - } -} diff --git a/src/frontend/src/components/TableNodeComponent/index.tsx b/src/frontend/src/components/parameterRenderComponent/components/TableNodeComponent/index.tsx similarity index 85% rename from src/frontend/src/components/TableNodeComponent/index.tsx rename to src/frontend/src/components/parameterRenderComponent/components/TableNodeComponent/index.tsx index 6c179ec6e..113ead8be 100644 --- a/src/frontend/src/components/TableNodeComponent/index.tsx +++ b/src/frontend/src/components/parameterRenderComponent/components/TableNodeComponent/index.tsx @@ -4,19 +4,20 @@ import { DataTypeDefinition, SelectionChangedEvent } from "ag-grid-community"; import { AgGridReact } from "ag-grid-react"; import { cloneDeep } from "lodash"; import { useMemo, useRef, useState } from "react"; -import { ForwardedIconComponent } from "../../components/genericIconComponent"; -import { TableComponentType } from "../../types/components"; -import { Button } from "../ui/button"; +import { ForwardedIconComponent } from "../../../genericIconComponent"; +import { Button } from "../../../ui/button"; +import { InputProps, TableComponentType } from "../../types"; export default function TableNodeComponent({ tableTitle, description, value, - onChange, editNode = false, id = "", columns, -}: TableComponentType): JSX.Element { + handleOnNewValue, + disabled = false, +}: InputProps): JSX.Element { const dataTypeDefinitions: { [cellDataType: string]: DataTypeDefinition; } = useMemo(() => { @@ -68,7 +69,7 @@ export default function TableNodeComponent({ if (agGrid.current && !agGrid.current.api.isDestroyed()) { const rows: any = []; agGrid.current.api.forEachNode((node) => rows.push(node.data)); - onChange(rows); + handleOnNewValue({ value: rows }); } } function deleteRow() { @@ -85,7 +86,7 @@ export default function TableNodeComponent({ const toDuplicate = selectedNodes.map((node) => cloneDeep(node.data)); setSelectedNodes([]); const rows: any = []; - onChange([...value, ...toDuplicate]); + handleOnNewValue({ value: [...value, ...toDuplicate] }); } } function addRow() { @@ -93,7 +94,7 @@ export default function TableNodeComponent({ componentColumns.forEach((column) => { newRow[column.name] = null; }); - onChange([...value, newRow]); + handleOnNewValue({ value: [...value, newRow] }); } function updateComponent() { @@ -111,7 +112,11 @@ export default function TableNodeComponent({ }); return ( -
+