refactor: rename InputType to InputTypeEnum and update related usages for consistency

This commit is contained in:
twwu 2025-05-26 09:48:17 +08:00
parent db4958be05
commit ccefd41606
5 changed files with 17 additions and 19 deletions

View File

@ -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 {

View File

@ -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<string>()
const field = useFieldContext<InputType>()
const inputTypeOptions = useInputTypeOptions(supportFile)
const renderTrigger = useCallback((option: FileTypeSelectOption | undefined, open: boolean) => {
@ -44,7 +44,7 @@ const InputTypeSelectField = ({
<CustomSelect<FileTypeSelectOption>
value={field.state.value}
options={inputTypeOptions}
onChange={value => field.handleChange(value)}
onChange={value => field.handleChange(value as InputType)}
triggerProps={{
className: 'gap-x-0.5',
}}

View File

@ -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<typeof InputTypeEnum>
export type FileTypeSelectOption = {
value: string
value: InputType
label: string
Icon: RemixiconComponentType
type: string

View File

@ -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({

View File

@ -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<DataSourceNotionWorkspace[]>()
const [notionData, setNotionData] = useState<DataSourceNotionWorkspace[]>([])
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<string>, Set<string>] = useMemo(() => {
const selectedPagesId = new Set<string>()
const boundPagesId = new Set<string>()
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<Set<string>>(new Set(defaultSelectedPagesId))
@ -116,7 +112,7 @@ const NotionPageSelector = ({
<div className='flex grow items-center gap-x-1'>
<WorkspaceSelector
value={currentWorkspaceId || firstWorkspaceId}
items={notionWorkspaces}
items={notionData}
onSelect={handleSelectWorkspace}
/>
</div>