Commit 077de17c authored by Joel's avatar Joel

feat: support config modal edit

parent f6c07c99
...@@ -19,10 +19,8 @@ import Switch from '@/app/components/base/switch' ...@@ -19,10 +19,8 @@ import Switch from '@/app/components/base/switch'
export type IConfigModalProps = { export type IConfigModalProps = {
isCreate?: boolean isCreate?: boolean
payload?: InputVar payload?: InputVar
type?: string
isShow: boolean isShow: boolean
onClose: () => void onClose: () => void
// onConfirm: (newValue: { type: string; value: any }) => void
onConfirm: (newValue: InputVar) => void onConfirm: (newValue: InputVar) => void
} }
...@@ -54,13 +52,20 @@ const ConfigModal: FC<IConfigModalProps> = ({ ...@@ -54,13 +52,20 @@ const ConfigModal: FC<IConfigModalProps> = ({
}, []) }, [])
const handleConfirm = () => { const handleConfirm = () => {
if (!tempPayload.variable) {
Toast.notify({ type: 'error', message: t('appDebug.variableConig.errorMsg.varNameRequired') })
return
}
if (!tempPayload.label) {
Toast.notify({ type: 'error', message: t('appDebug.variableConig.errorMsg.labelNameRequired') })
return
}
if (isStringInput) { if (isStringInput) {
onConfirm(tempPayload) onConfirm(tempPayload)
// onConfirm({ type: type, value: tempMaxLength })
} }
else { else {
if (options?.length === 0) { if (options?.length === 0) {
Toast.notify({ type: 'error', message: 'At least one option requied' }) Toast.notify({ type: 'error', message: t('appDebug.variableConig.errorMsg.atLeastOneOption') })
return return
} }
const obj: Record<string, boolean> = {} const obj: Record<string, boolean> = {}
...@@ -73,7 +78,7 @@ const ConfigModal: FC<IConfigModalProps> = ({ ...@@ -73,7 +78,7 @@ const ConfigModal: FC<IConfigModalProps> = ({
obj[o] = true obj[o] = true
}) })
if (hasRepeatedItem) { if (hasRepeatedItem) {
Toast.notify({ type: 'error', message: 'Has repeat items' }) Toast.notify({ type: 'error', message: t('appDebug.variableConig.errorMsg.optionRepeat') })
return return
} }
onConfirm(tempPayload) onConfirm(tempPayload)
...@@ -124,7 +129,7 @@ const ConfigModal: FC<IConfigModalProps> = ({ ...@@ -124,7 +129,7 @@ const ConfigModal: FC<IConfigModalProps> = ({
)} )}
{type === InputVarType.select && ( {type === InputVarType.select && (
<Field title={t('appDebug.variableConig.options')}> <Field title={t('appDebug.variableConig.options')}>
<ConfigSelect options={options!} onChange={handlePayloadChange('options')} /> <ConfigSelect options={options || []} onChange={handlePayloadChange('options')} />
</Field> </Field>
)} )}
......
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React, { useRef } from 'react' import React, { useCallback, useRef } from 'react'
import { useHover } from 'ahooks' import { useBoolean, useHover } from 'ahooks'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import InputVarTypeIcon from '../../_base/components/input-var-type-icon' import InputVarTypeIcon from '../../_base/components/input-var-type-icon'
import type { InputVar } from '@/app/components/workflow/types' import type { InputVar } from '@/app/components/workflow/types'
import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
import { Edit03 } from '@/app/components/base/icons/src/vender/solid/general' import { Edit03 } from '@/app/components/base/icons/src/vender/solid/general'
import { Trash03 } from '@/app/components/base/icons/src/vender/line/general' import { Trash03 } from '@/app/components/base/icons/src/vender/line/general'
import ConfigVarModal from '@/app/components/app/configuration/config-var/config-modal'
type Props = { type Props = {
readonly: boolean readonly: boolean
...@@ -19,11 +20,22 @@ type Props = { ...@@ -19,11 +20,22 @@ type Props = {
const VarItem: FC<Props> = ({ const VarItem: FC<Props> = ({
readonly, readonly,
payload, payload,
onChange,
onRemove,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const ref = useRef(null) const ref = useRef(null)
const isHovering = useHover(ref) const isHovering = useHover(ref)
const [isShowEditVarModal, {
setTrue: showEditVarModal,
setFalse: hideEditVarModal,
}] = useBoolean(false)
const handlePayloadChange = useCallback((payload: InputVar) => {
onChange(payload)
hideEditVarModal()
}, [onChange, hideEditVarModal])
return ( return (
<div ref={ref} className='flex items-center h-8 justify-between px-2.5 bg-white rounded-lg border border-gray-200 shadow-xs cursor-pointer hover:shadow-md'> <div ref={ref} className='flex items-center h-8 justify-between px-2.5 bg-white rounded-lg border border-gray-200 shadow-xs cursor-pointer hover:shadow-md'>
<div className='flex items-center space-x-1 grow w-0'> <div className='flex items-center space-x-1 grow w-0'>
...@@ -44,15 +56,25 @@ const VarItem: FC<Props> = ({ ...@@ -44,15 +56,25 @@ const VarItem: FC<Props> = ({
) )
: (!readonly && ( : (!readonly && (
<> <>
<div className='mr-1 p-1 rounded-md cursor-pointer hover:bg-black/5'> <div onClick={showEditVarModal} className='mr-1 p-1 rounded-md cursor-pointer hover:bg-black/5'>
<Edit03 className='w-4 h-4 text-gray-500' /> <Edit03 className='w-4 h-4 text-gray-500' />
</div> </div>
<div className='p-1 rounded-md cursor-pointer hover:bg-black/5'> <div onClick={onRemove} className='p-1 rounded-md cursor-pointer hover:bg-black/5'>
<Trash03 className='w-4 h-4 text-gray-500' /> <Trash03 className='w-4 h-4 text-gray-500' />
</div> </div>
</> </>
))} ))}
</div> </div>
{
isShowEditVarModal && (
<ConfigVarModal
isShow
payload={payload}
onClose={hideEditVarModal}
onConfirm={handlePayloadChange}
/>
)
}
</div> </div>
) )
} }
......
...@@ -283,6 +283,13 @@ const translation = { ...@@ -283,6 +283,13 @@ const translation = {
'varName': 'Variable Name', 'varName': 'Variable Name',
'labelName': 'Label Name', 'labelName': 'Label Name',
'required': 'Required', 'required': 'Required',
'errorMsg': {
varNameRequired: 'Variable name is required',
labelNameRequired: 'Label name is required',
varNameCanBeRepeat: 'Variable name can not be repeated',
atLeastOneOption: 'At least one option is required',
optionRepeat: 'Has repeat options',
},
}, },
vision: { vision: {
name: 'Vision', name: 'Vision',
......
...@@ -248,9 +248,6 @@ const translation = { ...@@ -248,9 +248,6 @@ const translation = {
action: '操作', action: '操作',
typeString: '文本', typeString: '文本',
typeSelect: '下拉选项', typeSelect: '下拉选项',
varName: '变量名称',
labelName: '显示名称',
required: '必填',
}, },
varKeyError: { varKeyError: {
canNoBeEmpty: '变量不能为空', canNoBeEmpty: '变量不能为空',
...@@ -279,6 +276,16 @@ const translation = { ...@@ -279,6 +276,16 @@ const translation = {
'options': '选项', 'options': '选项',
'addOption': '添加选项', 'addOption': '添加选项',
'apiBasedVar': '基于 API 的变量', 'apiBasedVar': '基于 API 的变量',
'varName': '变量名称',
'labelName': '显示名称',
'required': '必填',
'errorMsg': {
varNameRequired: '变量名称必填',
labelNameRequired: '显示名称必填',
varNameCanBeRepeat: '变量名称不能重复',
atLeastOneOption: '至少需要一个选项',
optionRepeat: '选项不能重复',
},
}, },
vision: { vision: {
name: '视觉', name: '视觉',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment