feat: new input types

This commit is contained in:
Joel 2024-08-02 11:42:48 +08:00
parent 19dfc6d9a8
commit 0480bb03c3
9 changed files with 25 additions and 18 deletions

View File

@ -25,6 +25,7 @@ export type IConfigModalProps = {
varKeys?: string[] varKeys?: string[]
onClose: () => void onClose: () => void
onConfirm: (newValue: InputVar, moreInfo?: MoreInfo) => void onConfirm: (newValue: InputVar, moreInfo?: MoreInfo) => void
supportFile?: boolean
} }
const inputClassName = 'w-full px-3 text-sm leading-9 text-gray-900 border-0 rounded-lg grow h-9 bg-gray-100 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-gray-200' const inputClassName = 'w-full px-3 text-sm leading-9 text-gray-900 border-0 rounded-lg grow h-9 bg-gray-100 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-gray-200'
@ -35,6 +36,7 @@ const ConfigModal: FC<IConfigModalProps> = ({
isShow, isShow,
onClose, onClose,
onConfirm, onConfirm,
supportFile,
}) => { }) => {
const { modelConfig } = useContext(ConfigContext) const { modelConfig } = useContext(ConfigContext)
const { t } = useTranslation() const { t } = useTranslation()
@ -88,14 +90,6 @@ const ConfigModal: FC<IConfigModalProps> = ({
Toast.notify({ type: 'error', message: t('appDebug.variableConig.errorMsg.varNameRequired') }) Toast.notify({ type: 'error', message: t('appDebug.variableConig.errorMsg.varNameRequired') })
return return
} }
// TODO: check if key already exists. should the consider the edit case
// if (varKeys.map(key => key?.trim()).includes(tempPayload.variable.trim())) {
// Toast.notify({
// type: 'error',
// message: t('appDebug.varKeyError.keyAlreadyExists', { key: tempPayload.variable }),
// })
// return
// }
if (!tempPayload.label) { if (!tempPayload.label) {
Toast.notify({ type: 'error', message: t('appDebug.variableConig.errorMsg.labelNameRequired') }) Toast.notify({ type: 'error', message: t('appDebug.variableConig.errorMsg.labelNameRequired') })
@ -136,11 +130,15 @@ const ConfigModal: FC<IConfigModalProps> = ({
<div className='space-y-2'> <div className='space-y-2'>
<Field title={t('appDebug.variableConig.fieldType')}> <Field title={t('appDebug.variableConig.fieldType')}>
<div className='flex space-x-2'> <div className='grid grid-cols-3 gap-2'>
<SelectTypeItem type={InputVarType.textInput} selected={type === InputVarType.textInput} onClick={() => handlePayloadChange('type')(InputVarType.textInput)} /> <SelectTypeItem type={InputVarType.textInput} selected={type === InputVarType.textInput} onClick={() => handlePayloadChange('type')(InputVarType.textInput)} />
<SelectTypeItem type={InputVarType.paragraph} selected={type === InputVarType.paragraph} onClick={() => handlePayloadChange('type')(InputVarType.paragraph)} /> <SelectTypeItem type={InputVarType.paragraph} selected={type === InputVarType.paragraph} onClick={() => handlePayloadChange('type')(InputVarType.paragraph)} />
<SelectTypeItem type={InputVarType.select} selected={type === InputVarType.select} onClick={() => handlePayloadChange('type')(InputVarType.select)} /> <SelectTypeItem type={InputVarType.select} selected={type === InputVarType.select} onClick={() => handlePayloadChange('type')(InputVarType.select)} />
<SelectTypeItem type={InputVarType.number} selected={type === InputVarType.number} onClick={() => handlePayloadChange('type')(InputVarType.number)} /> <SelectTypeItem type={InputVarType.number} selected={type === InputVarType.number} onClick={() => handlePayloadChange('type')(InputVarType.number)} />
{supportFile && <>
<SelectTypeItem type={InputVarType.singleFile} selected={type === InputVarType.singleFile} onClick={() => handlePayloadChange('type')(InputVarType.singleFile)} />
<SelectTypeItem type={InputVarType.multiFiles} selected={type === InputVarType.multiFiles} onClick={() => handlePayloadChange('type')(InputVarType.multiFiles)} />
</>}
</div> </div>
</Field> </Field>

View File

@ -22,7 +22,7 @@ const SelectTypeItem: FC<ISelectTypeItemProps> = ({
return ( return (
<div <div
className={cn(s.item, selected && s.selected, 'space-y-1')} className={cn('space-y-1', selected && s.selected, s.item)}
onClick={onClick} onClick={onClick}
> >
<div className='shrink-0'> <div className='shrink-0'>

View File

@ -4,7 +4,7 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
height: 58px; height: 58px;
width: 98px; /* width: 98px; */
border-radius: 8px; border-radius: 8px;
border: 1px solid #EAECF0; border: 1px solid #EAECF0;
box-shadow: 0px 1px 2px rgba(16, 24, 40, 0.05); box-shadow: 0px 1px 2px rgba(16, 24, 40, 0.05);

View File

@ -1,9 +1,8 @@
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React from 'react' import React from 'react'
import { RiAlignLeft, RiCheckboxMultipleLine, RiFileCopy2Line, RiFileList2Line, RiHashtag, RiTextSnippet } from '@remixicon/react'
import { InputVarType } from '../../../types' import { InputVarType } from '../../../types'
import { AlignLeft, LetterSpacing01 } from '@/app/components/base/icons/src/vender/line/editor'
import { CheckDone01, Hash02 } from '@/app/components/base/icons/src/vender/line/general'
type Props = { type Props = {
className?: string className?: string
@ -12,11 +11,13 @@ type Props = {
const getIcon = (type: InputVarType) => { const getIcon = (type: InputVarType) => {
return ({ return ({
[InputVarType.textInput]: LetterSpacing01, [InputVarType.textInput]: RiTextSnippet,
[InputVarType.paragraph]: AlignLeft, [InputVarType.paragraph]: RiAlignLeft,
[InputVarType.select]: CheckDone01, [InputVarType.select]: RiCheckboxMultipleLine,
[InputVarType.number]: Hash02, [InputVarType.number]: RiHashtag,
} as any)[type] || LetterSpacing01 [InputVarType.singleFile]: RiFileList2Line,
[InputVarType.multiFiles]: RiFileCopy2Line,
} as any)[type] || RiTextSnippet
} }
const InputVarTypeIcon: FC<Props> = ({ const InputVarTypeIcon: FC<Props> = ({

View File

@ -79,6 +79,7 @@ const VarItem: FC<Props> = ({
isShowEditVarModal && ( isShowEditVarModal && (
<ConfigVarModal <ConfigVarModal
isShow isShow
supportFile
payload={payload} payload={payload}
onClose={hideEditVarModal} onClose={hideEditVarModal}
onConfirm={handlePayloadChange} onConfirm={handlePayloadChange}

View File

@ -117,6 +117,7 @@ const Panel: FC<NodePanelProps<StartNodeType>> = ({
{isShowAddVarModal && ( {isShowAddVarModal && (
<ConfigVarModal <ConfigVarModal
isCreate isCreate
supportFile
isShow={isShowAddVarModal} isShow={isShowAddVarModal}
onClose={hideAddVarModal} onClose={hideAddVarModal}
onConfirm={handleAddVarConfirm} onConfirm={handleAddVarConfirm}

View File

@ -126,6 +126,8 @@ export enum InputVarType {
json = 'json', // obj, array json = 'json', // obj, array
contexts = 'contexts', // knowledge retrieval contexts = 'contexts', // knowledge retrieval
iterator = 'iterator', // iteration input iterator = 'iterator', // iteration input
singleFile = 'single-file',
multiFiles = 'multi-files',
} }
export type InputVar = { export type InputVar = {

View File

@ -311,6 +311,8 @@ const translation = {
'paragraph': 'Paragraph', 'paragraph': 'Paragraph',
'select': 'Select', 'select': 'Select',
'number': 'Number', 'number': 'Number',
'single-file': 'Single File',
'multi-files': 'File List',
'notSet': 'Not set, try typing {{input}} in the prefix prompt', 'notSet': 'Not set, try typing {{input}} in the prefix prompt',
'stringTitle': 'Form text box options', 'stringTitle': 'Form text box options',
'maxLength': 'Max length', 'maxLength': 'Max length',

View File

@ -308,6 +308,8 @@ const translation = {
'paragraph': '段落', 'paragraph': '段落',
'select': '下拉选项', 'select': '下拉选项',
'number': '数字', 'number': '数字',
'single-file': '单文件',
'multi-files': '文件列表',
'notSet': '未设置,在 Prompt 中输入 {{input}} 试试', 'notSet': '未设置,在 Prompt 中输入 {{input}} 试试',
'stringTitle': '文本框设置', 'stringTitle': '文本框设置',
'maxLength': '最大长度', 'maxLength': '最大长度',