From ccefd4160677e6c196ee8930d5ad95bc9bad0fca Mon Sep 17 00:00:00 2001 From: twwu Date: Mon, 26 May 2025 09:48:17 +0800 Subject: [PATCH] refactor: rename InputType to InputTypeEnum and update related usages for consistency --- .../components/field/input-type-select/hooks.tsx | 4 ++-- .../components/field/input-type-select/index.tsx | 6 +++--- .../components/field/input-type-select/types.tsx | 6 ++++-- .../components/input-field/editor/form/schema.ts | 4 ++-- .../data-source/notion/notion-page-selector.tsx | 16 ++++++---------- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/web/app/components/base/form/components/field/input-type-select/hooks.tsx b/web/app/components/base/form/components/field/input-type-select/hooks.tsx index 7ec5b40474..b77ddad4ca 100644 --- a/web/app/components/base/form/components/field/input-type-select/hooks.tsx +++ b/web/app/components/base/form/components/field/input-type-select/hooks.tsx @@ -1,4 +1,4 @@ -import { InputType } from './types' +import { InputTypeEnum } from './types' import { PipelineInputVarType } from '@/models/pipeline' import { useTranslation } from 'react-i18next' import { @@ -39,7 +39,7 @@ const DATA_TYPE = { export const useInputTypeOptions = (supportFile: boolean) => { const { t } = useTranslation() - const options = supportFile ? InputType.options : InputType.exclude(['file', 'file-list']).options + const options = supportFile ? InputTypeEnum.options : InputTypeEnum.exclude(['file', 'file-list']).options return options.map((value) => { return { diff --git a/web/app/components/base/form/components/field/input-type-select/index.tsx b/web/app/components/base/form/components/field/input-type-select/index.tsx index 279c0ff43e..d86ea13980 100644 --- a/web/app/components/base/form/components/field/input-type-select/index.tsx +++ b/web/app/components/base/form/components/field/input-type-select/index.tsx @@ -6,7 +6,7 @@ import type { LabelProps } from '../../label' import Label from '../../label' import { useCallback } from 'react' import Trigger from './trigger' -import type { FileTypeSelectOption } from './types' +import type { FileTypeSelectOption, InputType } from './types' import { useInputTypeOptions } from './hooks' import Option from './option' @@ -24,7 +24,7 @@ const InputTypeSelectField = ({ className, ...customSelectProps }: InputTypeSelectFieldProps) => { - const field = useFieldContext() + const field = useFieldContext() const inputTypeOptions = useInputTypeOptions(supportFile) const renderTrigger = useCallback((option: FileTypeSelectOption | undefined, open: boolean) => { @@ -44,7 +44,7 @@ const InputTypeSelectField = ({ value={field.state.value} options={inputTypeOptions} - onChange={value => field.handleChange(value)} + onChange={value => field.handleChange(value as InputType)} triggerProps={{ className: 'gap-x-0.5', }} diff --git a/web/app/components/base/form/components/field/input-type-select/types.tsx b/web/app/components/base/form/components/field/input-type-select/types.tsx index 8f059c0faa..99cbae4d23 100644 --- a/web/app/components/base/form/components/field/input-type-select/types.tsx +++ b/web/app/components/base/form/components/field/input-type-select/types.tsx @@ -1,7 +1,7 @@ import type { RemixiconComponentType } from '@remixicon/react' import { z } from 'zod' -export const InputType = z.enum([ +export const InputTypeEnum = z.enum([ 'text-input', 'paragraph', 'number-input', @@ -11,8 +11,10 @@ export const InputType = z.enum([ 'file-list', ]) +export type InputType = z.infer + export type FileTypeSelectOption = { - value: string + value: InputType label: string Icon: RemixiconComponentType type: string diff --git a/web/app/components/rag-pipeline/components/input-field/editor/form/schema.ts b/web/app/components/rag-pipeline/components/input-field/editor/form/schema.ts index 9ac28a5f1e..4dfa85a559 100644 --- a/web/app/components/rag-pipeline/components/input-field/editor/form/schema.ts +++ b/web/app/components/rag-pipeline/components/input-field/editor/form/schema.ts @@ -3,7 +3,7 @@ import type { TFunction } from 'i18next' import { z } from 'zod' import type { SchemaOptions } from './types' import { PipelineInputVarType } from '@/models/pipeline' -import { InputType } from '@/app/components/base/form/components/field/input-type-select/types' +import { InputTypeEnum } from '@/app/components/base/form/components/field/input-type-select/types' export const TEXT_MAX_LENGTH = 256 @@ -24,7 +24,7 @@ export const SupportedFileTypes = z.enum([ export const createInputFieldSchema = (type: PipelineInputVarType, t: TFunction, options: SchemaOptions) => { const { maxFileUploadLimit } = options const commonSchema = z.object({ - type: InputType, + type: InputTypeEnum, variable: z.string({ invalid_type_error: t('appDebug.varKeyError.notValid', { key: t('appDebug.variableConfig.varName') }), }).nonempty({ diff --git a/web/app/components/rag-pipeline/components/panel/test-run/data-source/notion/notion-page-selector.tsx b/web/app/components/rag-pipeline/components/panel/test-run/data-source/notion/notion-page-selector.tsx index 8d759def6b..ca79c1a9ed 100644 --- a/web/app/components/rag-pipeline/components/panel/test-run/data-source/notion/notion-page-selector.tsx +++ b/web/app/components/rag-pipeline/components/panel/test-run/data-source/notion/notion-page-selector.tsx @@ -30,7 +30,7 @@ const NotionPageSelector = ({ const { t } = useTranslation() const pipeline_id = useDatasetDetailContextWithSelector(s => s.dataset?.pipeline_id) const { mutateAsync: getNotionPages } = useDatasourceNodeRun() - const [notionData, setNotionData] = useState() + const [notionData, setNotionData] = useState([]) const [searchValue, setSearchValue] = useState('') const [currentWorkspaceId, setCurrentWorkspaceId] = useState('') @@ -50,17 +50,13 @@ const NotionPageSelector = ({ // eslint-disable-next-line react-hooks/exhaustive-deps }, []) - const notionWorkspaces = useMemo(() => { - return notionData || [] - }, [notionData]) - - const firstWorkspaceId = notionWorkspaces[0]?.workspace_id - const currentWorkspace = notionWorkspaces.find(workspace => workspace.workspace_id === currentWorkspaceId) + const firstWorkspaceId = notionData[0]?.workspace_id + const currentWorkspace = notionData.find(workspace => workspace.workspace_id === currentWorkspaceId) const PagesMapAndSelectedPagesId: [DataSourceNotionPageMap, Set, Set] = useMemo(() => { const selectedPagesId = new Set() const boundPagesId = new Set() - const pagesMap = notionWorkspaces.reduce((prev: DataSourceNotionPageMap, next: DataSourceNotionWorkspace) => { + const pagesMap = notionData.reduce((prev: DataSourceNotionPageMap, next: DataSourceNotionWorkspace) => { next.pages.forEach((page) => { if (page.is_bound) { selectedPagesId.add(page.page_id) @@ -75,7 +71,7 @@ const NotionPageSelector = ({ return prev }, {}) return [pagesMap, selectedPagesId, boundPagesId] - }, [notionWorkspaces]) + }, [notionData]) const defaultSelectedPagesId = [...Array.from(PagesMapAndSelectedPagesId[1]), ...(value || [])] const [selectedPagesId, setSelectedPagesId] = useState>(new Set(defaultSelectedPagesId)) @@ -116,7 +112,7 @@ const NotionPageSelector = ({