From c2e97b54acfa741f091881287e744a38b713c522 Mon Sep 17 00:00:00 2001 From: vinodkiran Date: Tue, 12 Dec 2023 16:19:52 +0530 Subject: [PATCH] Environment Variables: Validations and minor fixes --- .../components/nodes/tools/CustomTool/core.ts | 1 - .../views/variables/AddEditVariableDialog.js | 70 +++++++++++-------- packages/ui/src/views/variables/index.js | 4 +- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/packages/components/nodes/tools/CustomTool/core.ts b/packages/components/nodes/tools/CustomTool/core.ts index b7b1f6a6..8bae726c 100644 --- a/packages/components/nodes/tools/CustomTool/core.ts +++ b/packages/components/nodes/tools/CustomTool/core.ts @@ -2,7 +2,6 @@ import { z } from 'zod' import { CallbackManagerForToolRun } from 'langchain/callbacks' import { StructuredTool, ToolParams } from 'langchain/tools' import { NodeVM } from 'vm2' -import { logger } from "@zilliz/milvus2-sdk-node"; /* * List of dependencies allowed to be import in vm2 diff --git a/packages/ui/src/views/variables/AddEditVariableDialog.js b/packages/ui/src/views/variables/AddEditVariableDialog.js index db2116b0..85c40e44 100644 --- a/packages/ui/src/views/variables/AddEditVariableDialog.js +++ b/packages/ui/src/views/variables/AddEditVariableDialog.js @@ -26,6 +26,7 @@ import useNotifier from 'utils/useNotifier' import { HIDE_CANVAS_DIALOG, SHOW_CANVAS_DIALOG } from 'store/actions' import { TooltipWithParser } from '../../ui-component/tooltip/TooltipWithParser' import { Dropdown } from '../../ui-component/dropdown/Dropdown' +import { SwitchInput } from '../../ui-component/switch/Switch' const variableTypes = [ { @@ -50,29 +51,29 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm }) => { const enqueueSnackbar = (...args) => dispatch(enqueueSnackbarAction(...args)) const closeSnackbar = (...args) => dispatch(closeSnackbarAction(...args)) - const [name, setName] = useState('') - const [value, setValue] = useState('') - const [type, setType] = useState('') + const [variableName, setVariableName] = useState('') + const [variableValue, setVariableValue] = useState('') + const [variableType, setVariableType] = useState('static') + const [dialogType, setDialogType] = useState('ADD') const [variable, setVariable] = useState({}) useEffect(() => { - if (dialogProps.type === 'EDIT' && dialogProps.data) { + if (dialogProps.type === 'EDIT') { // When variable dialog is opened from Variables dashboard - setName(dialogProps.data.name) - setValue(dialogProps.data.value) - setType(dialogProps.data.type) + setVariableName(dialogProps.data.name) + setVariableValue(dialogProps.data.value) + setVariableType(dialogProps.data.type) setVariable(dialogProps.data) - } else if (dialogProps.type === 'ADD' && dialogProps.data) { + setDialogType('EDIT') + } else if (dialogProps.type === 'ADD') { // When variable dialog is to add a new variable - setName('') - setValue('') - setType('static') - setVariable({ name: '', value: '', type: 'static' }) + setVariableName('') + setVariableValue('') + setVariableType('static') + setDialogType('ADD') } - - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [dialogProps]) + }, [dialogProps.data, dialogProps.type]) useEffect(() => { if (show) dispatch({ type: SHOW_CANVAS_DIALOG }) @@ -83,9 +84,9 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm }) => { const addNewVariable = async () => { try { const obj = { - name: name, - value: value, - type: type + name: variableName, + value: variableValue, + type: variableType } const createResp = await variablesApi.createVariable(obj) if (createResp.data) { @@ -125,9 +126,9 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm }) => { const saveVariable = async () => { try { const saveObj = { - name: name, - value: value, - type: type + name: variableName, + value: variableValue, + type: variableType } const saveResp = await variablesApi.updateVariable(variable.id, saveObj) @@ -207,7 +208,13 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm }) => {
- setName(e.target.value)} value={name ?? ''} /> + setVariableName(e.target.value)} + value={variableName ?? ''} + />
@@ -217,7 +224,13 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm }) => {
- setValue(e.target.value)} value={value ?? ''} /> + setVariableValue(e.target.value)} + value={variableValue ?? ''} + /> Leave the value empty for runtime variables. Will be populated at runtime.
@@ -228,11 +241,10 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm }) => {
setType(newValue)} - value={type ?? 'static'} + onSelect={(newValue) => setVariableType(newValue)} + value={variableType} /> Runtime: Value would be populated from env. Static: Value would be used as is. @@ -241,9 +253,9 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm }) => { (dialogProps.type === 'ADD' ? addNewVariable() : saveVariable())} + onClick={() => (dialogType === 'ADD' ? addNewVariable() : saveVariable())} > {dialogProps.confirmButtonName} diff --git a/packages/ui/src/views/variables/index.js b/packages/ui/src/views/variables/index.js index ccec36d3..9399eb20 100644 --- a/packages/ui/src/views/variables/index.js +++ b/packages/ui/src/views/variables/index.js @@ -95,7 +95,7 @@ const Variables = () => { setShowVariableDialog(true) } - const deleteVariable = async (credential) => { + const deleteVariable = async (variable) => { const confirmPayload = { title: `Delete`, description: `Delete variable ${variable.name}?`, @@ -106,7 +106,7 @@ const Variables = () => { if (isConfirmed) { try { - const deleteResp = await variablesApi.deleteVariable(credential.id) + const deleteResp = await variablesApi.deleteVariable(variable.id) if (deleteResp.data) { enqueueSnackbar({ message: 'Variable deleted',