mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 03:36:36 +08:00
refactor: update CustomActions type to use structured props across form components
This commit is contained in:
parent
5aaa06c8b0
commit
583db24ee7
@ -4,8 +4,14 @@ import { useFormContext } from '../..'
|
|||||||
import Button from '../../../button'
|
import Button from '../../../button'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
|
export type CustomActionsProps = {
|
||||||
|
form: FormType
|
||||||
|
isSubmitting: boolean
|
||||||
|
canSubmit: boolean
|
||||||
|
}
|
||||||
|
|
||||||
type ActionsProps = {
|
type ActionsProps = {
|
||||||
CustomActions?: (form: FormType) => React.ReactNode | React.JSX.Element
|
CustomActions?: (props: CustomActionsProps) => React.ReactNode | React.JSX.Element
|
||||||
}
|
}
|
||||||
|
|
||||||
const Actions = ({
|
const Actions = ({
|
||||||
@ -20,7 +26,7 @@ const Actions = ({
|
|||||||
])
|
])
|
||||||
|
|
||||||
if (CustomActions)
|
if (CustomActions)
|
||||||
return CustomActions(form)
|
return CustomActions({ form, isSubmitting, canSubmit })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import type { TransferMethod } from '@/types/app'
|
import type { TransferMethod } from '@/types/app'
|
||||||
import type { FormType } from '../..'
|
|
||||||
import type { Option } from '../../../select/pure'
|
import type { Option } from '../../../select/pure'
|
||||||
|
import type { CustomActionsProps } from '../../components/form/actions'
|
||||||
|
|
||||||
export enum BaseFieldType {
|
export enum BaseFieldType {
|
||||||
textInput = 'textInput',
|
textInput = 'textInput',
|
||||||
@ -55,6 +55,6 @@ export type BaseConfiguration = {
|
|||||||
export type BaseFormProps = {
|
export type BaseFormProps = {
|
||||||
initialData?: Record<string, any>
|
initialData?: Record<string, any>
|
||||||
configurations: BaseConfiguration[]
|
configurations: BaseConfiguration[]
|
||||||
CustomActions?: (form: FormType) => React.ReactNode
|
CustomActions?: (props: CustomActionsProps) => React.ReactNode
|
||||||
onSubmit: (value: Record<string, any>) => void
|
onSubmit: (value: Record<string, any>) => void
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ type DataSourceOptionsProps = {
|
|||||||
onSelect: (option: Datasource) => void
|
onSelect: (option: Datasource) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: replace all icons with tool icon_url
|
||||||
const DATA_SOURCE_ICONS = {
|
const DATA_SOURCE_ICONS = {
|
||||||
[DataSourceType.FILE]: File as React.FC<React.SVGProps<SVGSVGElement>>,
|
[DataSourceType.FILE]: File as React.FC<React.SVGProps<SVGSVGElement>>,
|
||||||
[DataSourceType.NOTION]: Notion as React.FC<React.SVGProps<SVGSVGElement>>,
|
[DataSourceType.NOTION]: Notion as React.FC<React.SVGProps<SVGSVGElement>>,
|
||||||
@ -21,6 +22,8 @@ const DATA_SOURCE_ICONS = {
|
|||||||
[DataSourceProvider.waterCrawl]: Watercrawl as React.FC<React.SVGProps<SVGSVGElement>>,
|
[DataSourceProvider.waterCrawl]: Watercrawl as React.FC<React.SVGProps<SVGSVGElement>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type KeyType = keyof typeof DATA_SOURCE_ICONS
|
||||||
|
|
||||||
const DataSourceOptions = ({
|
const DataSourceOptions = ({
|
||||||
datasourceNodeId,
|
datasourceNodeId,
|
||||||
onSelect,
|
onSelect,
|
||||||
@ -47,7 +50,7 @@ const DataSourceOptions = ({
|
|||||||
key={option.value}
|
key={option.value}
|
||||||
label={option.label}
|
label={option.label}
|
||||||
selected={datasourceNodeId === option.value}
|
selected={datasourceNodeId === option.value}
|
||||||
Icon={DATA_SOURCE_ICONS[option.type as keyof typeof DATA_SOURCE_ICONS]}
|
Icon={DATA_SOURCE_ICONS[option.type as KeyType]}
|
||||||
onClick={handelSelect.bind(null, option.value)}
|
onClick={handelSelect.bind(null, option.value)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@ -45,7 +45,7 @@ const FileUploader = ({
|
|||||||
const hideUpload = notSupportBatchUpload && fileList.length > 0
|
const hideUpload = notSupportBatchUpload && fileList.length > 0
|
||||||
|
|
||||||
const { data: fileUploadConfigResponse } = useFileUploadConfig()
|
const { data: fileUploadConfigResponse } = useFileUploadConfig()
|
||||||
const { data: supportFileTypesResponse } = useFileSupportTypes()
|
const { data: supportFileTypesResponse } = useFileSupportTypes() // Todo: replace with extensions configured in node
|
||||||
const supportTypes = supportFileTypesResponse?.allowed_extensions || []
|
const supportTypes = supportFileTypesResponse?.allowed_extensions || []
|
||||||
const supportTypesShowNames = (() => {
|
const supportTypesShowNames = (() => {
|
||||||
const extensionMap: { [key: string]: string } = {
|
const extensionMap: { [key: string]: string } = {
|
||||||
|
|||||||
@ -1,18 +1,19 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import Button from '@/app/components/base/button'
|
import Button from '@/app/components/base/button'
|
||||||
import type { FormType } from '@/app/components/base/form'
|
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import type { CustomActionsProps } from '@/app/components/base/form/components/form/actions'
|
||||||
|
|
||||||
type ActionsProps = {
|
type ActionsProps = {
|
||||||
form: FormType
|
formParams: CustomActionsProps
|
||||||
onBack: () => void
|
onBack: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const Actions = ({
|
const Actions = ({
|
||||||
form,
|
formParams,
|
||||||
onBack,
|
onBack,
|
||||||
}: ActionsProps) => {
|
}: ActionsProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const { form, isSubmitting, canSubmit } = formParams
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex items-center justify-end gap-x-2 p-4 pt-2'>
|
<div className='flex items-center justify-end gap-x-2 p-4 pt-2'>
|
||||||
@ -27,6 +28,8 @@ const Actions = ({
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
form.handleSubmit()
|
form.handleSubmit()
|
||||||
}}
|
}}
|
||||||
|
disabled={isSubmitting || !canSubmit}
|
||||||
|
loading={isSubmitting}
|
||||||
>
|
>
|
||||||
{t('datasetPipeline.operations.process')}
|
{t('datasetPipeline.operations.process')}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@ -2,8 +2,8 @@ import { generateZodSchema } from '@/app/components/base/form/form-scenarios/bas
|
|||||||
import { useConfigurations } from './hooks'
|
import { useConfigurations } from './hooks'
|
||||||
import Options from './options'
|
import Options from './options'
|
||||||
import Actions from './actions'
|
import Actions from './actions'
|
||||||
import type { FormType } from '@/app/components/base/form'
|
|
||||||
import { useCallback } from 'react'
|
import { useCallback } from 'react'
|
||||||
|
import type { CustomActionsProps } from '@/app/components/base/form/components/form/actions'
|
||||||
|
|
||||||
type DocumentProcessingProps = {
|
type DocumentProcessingProps = {
|
||||||
dataSourceNodeId: string
|
dataSourceNodeId: string
|
||||||
@ -19,8 +19,8 @@ const DocumentProcessing = ({
|
|||||||
const { initialData, configurations } = useConfigurations(dataSourceNodeId)
|
const { initialData, configurations } = useConfigurations(dataSourceNodeId)
|
||||||
const schema = generateZodSchema(configurations)
|
const schema = generateZodSchema(configurations)
|
||||||
|
|
||||||
const renderCustomActions = useCallback((form: FormType) => (
|
const renderCustomActions = useCallback((props: CustomActionsProps) => (
|
||||||
<Actions form={form} onBack={onBack} />
|
<Actions formParams={props} onBack={onBack} />
|
||||||
), [onBack])
|
), [onBack])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { FormType } from '@/app/components/base/form'
|
|
||||||
import { useAppForm } from '@/app/components/base/form'
|
import { useAppForm } from '@/app/components/base/form'
|
||||||
|
import type { CustomActionsProps } from '@/app/components/base/form/components/form/actions'
|
||||||
import BaseField from '@/app/components/base/form/form-scenarios/base/field'
|
import BaseField from '@/app/components/base/form/form-scenarios/base/field'
|
||||||
import type { BaseConfiguration } from '@/app/components/base/form/form-scenarios/base/types'
|
import type { BaseConfiguration } from '@/app/components/base/form/form-scenarios/base/types'
|
||||||
import Toast from '@/app/components/base/toast'
|
import Toast from '@/app/components/base/toast'
|
||||||
@ -9,7 +9,7 @@ type OptionsProps = {
|
|||||||
initialData: Record<string, any>
|
initialData: Record<string, any>
|
||||||
configurations: BaseConfiguration[]
|
configurations: BaseConfiguration[]
|
||||||
schema: ZodSchema
|
schema: ZodSchema
|
||||||
CustomActions: (form: FormType) => React.JSX.Element
|
CustomActions: (props: CustomActionsProps) => React.JSX.Element
|
||||||
onSubmit: (data: Record<string, any>) => void
|
onSubmit: (data: Record<string, any>) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user