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

pull/21398/head
twwu 11 months ago
parent db4958be05
commit ccefd41606

@ -1,4 +1,4 @@
import { InputType } from './types' import { InputTypeEnum } from './types'
import { PipelineInputVarType } from '@/models/pipeline' import { PipelineInputVarType } from '@/models/pipeline'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { import {
@ -39,7 +39,7 @@ const DATA_TYPE = {
export const useInputTypeOptions = (supportFile: boolean) => { export const useInputTypeOptions = (supportFile: boolean) => {
const { t } = useTranslation() 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 options.map((value) => {
return { return {

@ -6,7 +6,7 @@ import type { LabelProps } from '../../label'
import Label from '../../label' import Label from '../../label'
import { useCallback } from 'react' import { useCallback } from 'react'
import Trigger from './trigger' import Trigger from './trigger'
import type { FileTypeSelectOption } from './types' import type { FileTypeSelectOption, InputType } from './types'
import { useInputTypeOptions } from './hooks' import { useInputTypeOptions } from './hooks'
import Option from './option' import Option from './option'
@ -24,7 +24,7 @@ const InputTypeSelectField = ({
className, className,
...customSelectProps ...customSelectProps
}: InputTypeSelectFieldProps) => { }: InputTypeSelectFieldProps) => {
const field = useFieldContext<string>() const field = useFieldContext<InputType>()
const inputTypeOptions = useInputTypeOptions(supportFile) const inputTypeOptions = useInputTypeOptions(supportFile)
const renderTrigger = useCallback((option: FileTypeSelectOption | undefined, open: boolean) => { const renderTrigger = useCallback((option: FileTypeSelectOption | undefined, open: boolean) => {
@ -44,7 +44,7 @@ const InputTypeSelectField = ({
<CustomSelect<FileTypeSelectOption> <CustomSelect<FileTypeSelectOption>
value={field.state.value} value={field.state.value}
options={inputTypeOptions} options={inputTypeOptions}
onChange={value => field.handleChange(value)} onChange={value => field.handleChange(value as InputType)}
triggerProps={{ triggerProps={{
className: 'gap-x-0.5', className: 'gap-x-0.5',
}} }}

@ -1,7 +1,7 @@
import type { RemixiconComponentType } from '@remixicon/react' import type { RemixiconComponentType } from '@remixicon/react'
import { z } from 'zod' import { z } from 'zod'
export const InputType = z.enum([ export const InputTypeEnum = z.enum([
'text-input', 'text-input',
'paragraph', 'paragraph',
'number-input', 'number-input',
@ -11,8 +11,10 @@ export const InputType = z.enum([
'file-list', 'file-list',
]) ])
export type InputType = z.infer<typeof InputTypeEnum>
export type FileTypeSelectOption = { export type FileTypeSelectOption = {
value: string value: InputType
label: string label: string
Icon: RemixiconComponentType Icon: RemixiconComponentType
type: string type: string

@ -3,7 +3,7 @@ import type { TFunction } from 'i18next'
import { z } from 'zod' import { z } from 'zod'
import type { SchemaOptions } from './types' import type { SchemaOptions } from './types'
import { PipelineInputVarType } from '@/models/pipeline' 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 export const TEXT_MAX_LENGTH = 256
@ -24,7 +24,7 @@ export const SupportedFileTypes = z.enum([
export const createInputFieldSchema = (type: PipelineInputVarType, t: TFunction, options: SchemaOptions) => { export const createInputFieldSchema = (type: PipelineInputVarType, t: TFunction, options: SchemaOptions) => {
const { maxFileUploadLimit } = options const { maxFileUploadLimit } = options
const commonSchema = z.object({ const commonSchema = z.object({
type: InputType, type: InputTypeEnum,
variable: z.string({ variable: z.string({
invalid_type_error: t('appDebug.varKeyError.notValid', { key: t('appDebug.variableConfig.varName') }), invalid_type_error: t('appDebug.varKeyError.notValid', { key: t('appDebug.variableConfig.varName') }),
}).nonempty({ }).nonempty({

@ -30,7 +30,7 @@ const NotionPageSelector = ({
const { t } = useTranslation() const { t } = useTranslation()
const pipeline_id = useDatasetDetailContextWithSelector(s => s.dataset?.pipeline_id) const pipeline_id = useDatasetDetailContextWithSelector(s => s.dataset?.pipeline_id)
const { mutateAsync: getNotionPages } = useDatasourceNodeRun() const { mutateAsync: getNotionPages } = useDatasourceNodeRun()
const [notionData, setNotionData] = useState<DataSourceNotionWorkspace[]>() const [notionData, setNotionData] = useState<DataSourceNotionWorkspace[]>([])
const [searchValue, setSearchValue] = useState('') const [searchValue, setSearchValue] = useState('')
const [currentWorkspaceId, setCurrentWorkspaceId] = useState('') const [currentWorkspaceId, setCurrentWorkspaceId] = useState('')
@ -50,17 +50,13 @@ const NotionPageSelector = ({
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []) }, [])
const notionWorkspaces = useMemo(() => { const firstWorkspaceId = notionData[0]?.workspace_id
return notionData || [] const currentWorkspace = notionData.find(workspace => workspace.workspace_id === currentWorkspaceId)
}, [notionData])
const firstWorkspaceId = notionWorkspaces[0]?.workspace_id
const currentWorkspace = notionWorkspaces.find(workspace => workspace.workspace_id === currentWorkspaceId)
const PagesMapAndSelectedPagesId: [DataSourceNotionPageMap, Set<string>, Set<string>] = useMemo(() => { const PagesMapAndSelectedPagesId: [DataSourceNotionPageMap, Set<string>, Set<string>] = useMemo(() => {
const selectedPagesId = new Set<string>() const selectedPagesId = new Set<string>()
const boundPagesId = 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) => { next.pages.forEach((page) => {
if (page.is_bound) { if (page.is_bound) {
selectedPagesId.add(page.page_id) selectedPagesId.add(page.page_id)
@ -75,7 +71,7 @@ const NotionPageSelector = ({
return prev return prev
}, {}) }, {})
return [pagesMap, selectedPagesId, boundPagesId] return [pagesMap, selectedPagesId, boundPagesId]
}, [notionWorkspaces]) }, [notionData])
const defaultSelectedPagesId = [...Array.from(PagesMapAndSelectedPagesId[1]), ...(value || [])] const defaultSelectedPagesId = [...Array.from(PagesMapAndSelectedPagesId[1]), ...(value || [])]
const [selectedPagesId, setSelectedPagesId] = useState<Set<string>>(new Set(defaultSelectedPagesId)) const [selectedPagesId, setSelectedPagesId] = useState<Set<string>>(new Set(defaultSelectedPagesId))
@ -116,7 +112,7 @@ const NotionPageSelector = ({
<div className='flex grow items-center gap-x-1'> <div className='flex grow items-center gap-x-1'>
<WorkspaceSelector <WorkspaceSelector
value={currentWorkspaceId || firstWorkspaceId} value={currentWorkspaceId || firstWorkspaceId}
items={notionWorkspaces} items={notionData}
onSelect={handleSelectWorkspace} onSelect={handleSelectWorkspace}
/> />
</div> </div>

Loading…
Cancel
Save