Environment Variables: Validations and minor fixes

This commit is contained in:
vinodkiran
2023-12-12 16:19:52 +05:30
parent 947ab9dae6
commit c2e97b54ac
3 changed files with 43 additions and 32 deletions
@@ -2,7 +2,6 @@ import { z } from 'zod'
import { CallbackManagerForToolRun } from 'langchain/callbacks' import { CallbackManagerForToolRun } from 'langchain/callbacks'
import { StructuredTool, ToolParams } from 'langchain/tools' import { StructuredTool, ToolParams } from 'langchain/tools'
import { NodeVM } from 'vm2' import { NodeVM } from 'vm2'
import { logger } from "@zilliz/milvus2-sdk-node";
/* /*
* List of dependencies allowed to be import in vm2 * List of dependencies allowed to be import in vm2
@@ -26,6 +26,7 @@ import useNotifier from 'utils/useNotifier'
import { HIDE_CANVAS_DIALOG, SHOW_CANVAS_DIALOG } from 'store/actions' import { HIDE_CANVAS_DIALOG, SHOW_CANVAS_DIALOG } from 'store/actions'
import { TooltipWithParser } from '../../ui-component/tooltip/TooltipWithParser' import { TooltipWithParser } from '../../ui-component/tooltip/TooltipWithParser'
import { Dropdown } from '../../ui-component/dropdown/Dropdown' import { Dropdown } from '../../ui-component/dropdown/Dropdown'
import { SwitchInput } from '../../ui-component/switch/Switch'
const variableTypes = [ const variableTypes = [
{ {
@@ -50,29 +51,29 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm }) => {
const enqueueSnackbar = (...args) => dispatch(enqueueSnackbarAction(...args)) const enqueueSnackbar = (...args) => dispatch(enqueueSnackbarAction(...args))
const closeSnackbar = (...args) => dispatch(closeSnackbarAction(...args)) const closeSnackbar = (...args) => dispatch(closeSnackbarAction(...args))
const [name, setName] = useState('') const [variableName, setVariableName] = useState('')
const [value, setValue] = useState('') const [variableValue, setVariableValue] = useState('')
const [type, setType] = useState('') const [variableType, setVariableType] = useState('static')
const [dialogType, setDialogType] = useState('ADD')
const [variable, setVariable] = useState({}) const [variable, setVariable] = useState({})
useEffect(() => { useEffect(() => {
if (dialogProps.type === 'EDIT' && dialogProps.data) { if (dialogProps.type === 'EDIT') {
// When variable dialog is opened from Variables dashboard // When variable dialog is opened from Variables dashboard
setName(dialogProps.data.name) setVariableName(dialogProps.data.name)
setValue(dialogProps.data.value) setVariableValue(dialogProps.data.value)
setType(dialogProps.data.type) setVariableType(dialogProps.data.type)
setVariable(dialogProps.data) 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 // When variable dialog is to add a new variable
setName('') setVariableName('')
setValue('') setVariableValue('')
setType('static') setVariableType('static')
setVariable({ name: '', value: '', type: 'static' }) setDialogType('ADD')
} }
}, [dialogProps.data, dialogProps.type])
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dialogProps])
useEffect(() => { useEffect(() => {
if (show) dispatch({ type: SHOW_CANVAS_DIALOG }) if (show) dispatch({ type: SHOW_CANVAS_DIALOG })
@@ -83,9 +84,9 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm }) => {
const addNewVariable = async () => { const addNewVariable = async () => {
try { try {
const obj = { const obj = {
name: name, name: variableName,
value: value, value: variableValue,
type: type type: variableType
} }
const createResp = await variablesApi.createVariable(obj) const createResp = await variablesApi.createVariable(obj)
if (createResp.data) { if (createResp.data) {
@@ -125,9 +126,9 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm }) => {
const saveVariable = async () => { const saveVariable = async () => {
try { try {
const saveObj = { const saveObj = {
name: name, name: variableName,
value: value, value: variableValue,
type: type type: variableType
} }
const saveResp = await variablesApi.updateVariable(variable.id, saveObj) const saveResp = await variablesApi.updateVariable(variable.id, saveObj)
@@ -207,7 +208,13 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm }) => {
<div style={{ flexGrow: 1 }}></div> <div style={{ flexGrow: 1 }}></div>
</div> </div>
<OutlinedInput type='string' fullWidth key='name' onChange={(e) => setName(e.target.value)} value={name ?? ''} /> <OutlinedInput
type='string'
fullWidth
key='variableName'
onChange={(e) => setVariableName(e.target.value)}
value={variableName ?? ''}
/>
</Box> </Box>
<Box sx={{ p: 2 }}> <Box sx={{ p: 2 }}>
<div style={{ display: 'flex', flexDirection: 'row' }}> <div style={{ display: 'flex', flexDirection: 'row' }}>
@@ -217,7 +224,13 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm }) => {
</Typography> </Typography>
<div style={{ flexGrow: 1 }}></div> <div style={{ flexGrow: 1 }}></div>
</div> </div>
<OutlinedInput type='string' fullWidth key='value' onChange={(e) => setValue(e.target.value)} value={value ?? ''} /> <OutlinedInput
type='string'
fullWidth
key='variableValue'
onChange={(e) => setVariableValue(e.target.value)}
value={variableValue ?? ''}
/>
<Typography variant='subtitle2'>Leave the value empty for runtime variables. Will be populated at runtime.</Typography> <Typography variant='subtitle2'>Leave the value empty for runtime variables. Will be populated at runtime.</Typography>
</Box> </Box>
<Box sx={{ p: 2 }}> <Box sx={{ p: 2 }}>
@@ -228,11 +241,10 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm }) => {
<div style={{ flexGrow: 1 }}></div> <div style={{ flexGrow: 1 }}></div>
</div> </div>
<Dropdown <Dropdown
key='type' name='variableType'
name='variable-type'
options={variableTypes} options={variableTypes}
onSelect={(newValue) => setType(newValue)} onSelect={(newValue) => setVariableType(newValue)}
value={type ?? 'static'} value={variableType}
/> />
<Typography variant='subtitle2'> <Typography variant='subtitle2'>
Runtime: Value would be populated from env. Static: Value would be used as is. Runtime: Value would be populated from env. Static: Value would be used as is.
@@ -241,9 +253,9 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm }) => {
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<StyledButton <StyledButton
disabled={!name} disabled={!variableName || (variableType === 'static' && !variableValue)}
variant='contained' variant='contained'
onClick={() => (dialogProps.type === 'ADD' ? addNewVariable() : saveVariable())} onClick={() => (dialogType === 'ADD' ? addNewVariable() : saveVariable())}
> >
{dialogProps.confirmButtonName} {dialogProps.confirmButtonName}
</StyledButton> </StyledButton>
+2 -2
View File
@@ -95,7 +95,7 @@ const Variables = () => {
setShowVariableDialog(true) setShowVariableDialog(true)
} }
const deleteVariable = async (credential) => { const deleteVariable = async (variable) => {
const confirmPayload = { const confirmPayload = {
title: `Delete`, title: `Delete`,
description: `Delete variable ${variable.name}?`, description: `Delete variable ${variable.name}?`,
@@ -106,7 +106,7 @@ const Variables = () => {
if (isConfirmed) { if (isConfirmed) {
try { try {
const deleteResp = await variablesApi.deleteVariable(credential.id) const deleteResp = await variablesApi.deleteVariable(variable.id)
if (deleteResp.data) { if (deleteResp.data) {
enqueueSnackbar({ enqueueSnackbar({
message: 'Variable deleted', message: 'Variable deleted',