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[]
onClose: () => 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'
@ -35,6 +36,7 @@ const ConfigModal: FC<IConfigModalProps> = ({
isShow,
onClose,
onConfirm,
supportFile,
}) => {
const { modelConfig } = useContext(ConfigContext)
const { t } = useTranslation()
@ -88,14 +90,6 @@ const ConfigModal: FC<IConfigModalProps> = ({
Toast.notify({ type: 'error', message: t('appDebug.variableConig.errorMsg.varNameRequired') })
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) {
Toast.notify({ type: 'error', message: t('appDebug.variableConig.errorMsg.labelNameRequired') })
@ -136,11 +130,15 @@ const ConfigModal: FC<IConfigModalProps> = ({
<div className='space-y-2'>
<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.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.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>
</Field>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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