import type { FC } from 'react' import React from 'react' import useSWR from 'swr' import { useTranslation } from 'react-i18next' import { useContext } from 'use-context-selector' import VarReferencePicker from '../_base/components/variable/var-reference-picker' import OutputVars, { VarItem } from '../_base/components/output-vars' import Split from '../_base/components/split' import { useNodeHelpLink } from '../_base/hooks/use-node-help-link' import useConfig from './use-config' import type { DocExtractorNodeType } from './types' import { fetchSupportFileTypes } from '@/service/datasets' import Field from '@/app/components/workflow/nodes/_base/components/field' import { BlockEnum, type NodePanelProps } from '@/app/components/workflow/types' import I18n from '@/context/i18n' import { LanguagesSupported } from '@/i18n/language' const i18nPrefix = 'workflow.nodes.docExtractor' const Panel: FC> = ({ id, data, }) => { const { t } = useTranslation() const { locale } = useContext(I18n) const link = useNodeHelpLink(BlockEnum.DocExtractor) const { data: supportFileTypesResponse } = useSWR({ url: '/files/support-type' }, fetchSupportFileTypes) const supportTypes = supportFileTypesResponse?.allowed_extensions || [] const supportTypesShowNames = (() => { const extensionMap: { [key: string]: string } = { md: 'markdown', pptx: 'pptx', htm: 'html', xlsx: 'xlsx', docx: 'docx', } return [...supportTypes] .map(item => extensionMap[item] || item) // map to standardized extension .map(item => item.toLowerCase()) // convert to lower case .filter((item, index, self) => self.indexOf(item) === index) // remove duplicates .join(locale !== LanguagesSupported[1] ? ', ' : '、 ') })() const { readOnly, inputs, handleVarChanges, filterVar, } = useConfig(id, data) return (
<>
{t(`${i18nPrefix}.supportFileTypes`, { types: supportTypesShowNames })} {t(`${i18nPrefix}.learnMore`)}
) } export default React.memo(Panel)