From 77d0aac1d305fe3ecbee61b1dfdd448e47c666dc Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 6 Aug 2024 14:59:26 +0800 Subject: [PATCH] feat: support custom file type --- .../config-var/config-modal/field.tsx | 7 ++- web/app/components/base/tag-input/index.tsx | 4 +- .../nodes/_base/components/file-type-item.tsx | 49 ++++++++++++++----- .../_base/components/file-upload-setting.tsx | 19 +++++++ web/i18n/en-US/app-debug.ts | 5 ++ web/i18n/zh-Hans/app-debug.ts | 5 ++ 6 files changed, 75 insertions(+), 14 deletions(-) diff --git a/web/app/components/app/configuration/config-var/config-modal/field.tsx b/web/app/components/app/configuration/config-var/config-modal/field.tsx index 8253178486..5052f988d7 100644 --- a/web/app/components/app/configuration/config-var/config-modal/field.tsx +++ b/web/app/components/app/configuration/config-var/config-modal/field.tsx @@ -1,19 +1,22 @@ 'use client' import type { FC } from 'react' import React from 'react' +import cn from '@/utils/classnames' type Props = { + className?: string title: string children: JSX.Element } const Field: FC = ({ + className, title, children, }) => { return ( -
-
{title}
+
+
{title}
{children}
) diff --git a/web/app/components/base/tag-input/index.tsx b/web/app/components/base/tag-input/index.tsx index 7eab355a0d..745459ff35 100644 --- a/web/app/components/base/tag-input/index.tsx +++ b/web/app/components/base/tag-input/index.tsx @@ -14,6 +14,7 @@ type TagInputProps = { disableAdd?: boolean customizedConfirmKey?: 'Enter' | 'Tab' isInWorkflow?: boolean + placeholder?: string } const TagInput: FC = ({ @@ -23,6 +24,7 @@ const TagInput: FC = ({ disableRemove, customizedConfirmKey = 'Enter', isInWorkflow, + placeholder, }) => { const { t } = useTranslation() const { notify } = useToastContext() @@ -104,7 +106,7 @@ const TagInput: FC = ({ setValue(e.target.value) }} onKeyDown={handleKeyDown} - placeholder={t(isSpecialMode ? 'common.model.params.stop_sequencesPlaceholder' : 'datasetDocuments.segment.addKeyWord')} + placeholder={t(placeholder || (isSpecialMode ? 'common.model.params.stop_sequencesPlaceholder' : 'datasetDocuments.segment.addKeyWord'))} /> ) } diff --git a/web/app/components/workflow/nodes/_base/components/file-type-item.tsx b/web/app/components/workflow/nodes/_base/components/file-type-item.tsx index 43d85ad2f4..c830a7dffe 100644 --- a/web/app/components/workflow/nodes/_base/components/file-type-item.tsx +++ b/web/app/components/workflow/nodes/_base/components/file-type-item.tsx @@ -2,20 +2,25 @@ import type { FC } from 'react' import React, { useCallback } from 'react' import { useTranslation } from 'react-i18next' -import type { SupportUploadFileTypes } from '../../../types' +import { SupportUploadFileTypes } from '../../../types' import cn from '@/utils/classnames' import { FILE_EXTS } from '@/app/components/base/prompt-editor/constants' +import TagInput from '@/app/components/base/tag-input' type Props = { - type: SupportUploadFileTypes.image | SupportUploadFileTypes.document | SupportUploadFileTypes.audio | SupportUploadFileTypes.video + type: SupportUploadFileTypes.image | SupportUploadFileTypes.document | SupportUploadFileTypes.audio | SupportUploadFileTypes.video | SupportUploadFileTypes.custom selected: boolean onSelect: (type: SupportUploadFileTypes) => void + onCustomFileTypesChange?: (customFileTypes: string[]) => void + customFileTypes?: string[] } const FileTypeItem: FC = ({ type, selected, onSelect, + customFileTypes = [], + onCustomFileTypesChange = () => { }, }) => { const { t } = useTranslation() @@ -24,23 +29,45 @@ const FileTypeItem: FC = ({ onSelect(type) }, [selected, onSelect, type]) + const isCustomSelected = type === SupportUploadFileTypes.custom && selected + return (
-
- {/* TODO: Wait File type icon */} - -
-
{t(`appDebug.variableConig.file.${type}.name`)}
-
{FILE_EXTS[type].join(', ')}
-
-
+ {isCustomSelected + ? ( +
+
+ +
{t(`appDebug.variableConig.file.${type}.name`)}
+
+
+ +
+
+ ) + : ( +
+ {/* TODO: Wait File type icon */} + +
+
{t(`appDebug.variableConig.file.${type}.name`)}
+
{type !== SupportUploadFileTypes.custom ? FILE_EXTS[type].join(', ') : t('appDebug.variableConig.file.custom.description')}
+
+
+ )} +
) } diff --git a/web/app/components/workflow/nodes/_base/components/file-upload-setting.tsx b/web/app/components/workflow/nodes/_base/components/file-upload-setting.tsx index 1e062b7eb7..c657b53f85 100644 --- a/web/app/components/workflow/nodes/_base/components/file-upload-setting.tsx +++ b/web/app/components/workflow/nodes/_base/components/file-upload-setting.tsx @@ -43,6 +43,17 @@ const FileUploadSetting: FC = ({ } }, [onChange, payload]) + const handleCustomFileTypesChange = useCallback((customFileTypes: string[]) => { + const newPayload = produce(payload, (draft) => { + draft.customFileTypes = customFileTypes.map((v) => { + if (v.startsWith('.')) + return v + return `.${v}` + }) + }) + onChange(newPayload) + }, [onChange, payload]) + return (
= ({ /> )) } +