app selector support scope

pull/12372/head
JzoNg 1 year ago
parent 6d2b2d7810
commit 5c6916354e

@ -112,6 +112,7 @@ export type CredentialFormSchemaBase = {
tooltip?: TypeWithI18N tooltip?: TypeWithI18N
show_on: FormShowOnObject[] show_on: FormShowOnObject[]
url?: string url?: string
scope?: string
} }
export type CredentialFormSchemaTextInput = CredentialFormSchemaBase & { max_length?: number; placeholder?: TypeWithI18N } export type CredentialFormSchemaTextInput = CredentialFormSchemaBase & { max_length?: number; placeholder?: TypeWithI18N }

@ -351,6 +351,7 @@ const Form: FC<FormProps> = ({
variable, variable,
label, label,
required, required,
scope,
} = formSchema as (CredentialFormSchemaTextInput | CredentialFormSchemaSecretInput) } = formSchema as (CredentialFormSchemaTextInput | CredentialFormSchemaSecretInput)
return ( return (
@ -366,6 +367,7 @@ const Form: FC<FormProps> = ({
</div> </div>
<AppSelector <AppSelector
disabled={readonly} disabled={readonly}
scope={scope}
value={value[variable]} value={value[variable]}
onSelect={item => handleFormChange(variable, { ...item, type: FormTypeEnum.appSelector } as any)} onSelect={item => handleFormChange(variable, { ...item, type: FormTypeEnum.appSelector } as any)}
/> />

@ -17,6 +17,7 @@ import type { App } from '@/types/app'
type Props = { type Props = {
appList: App[] appList: App[]
scope: string
disabled: boolean disabled: boolean
trigger: React.ReactNode trigger: React.ReactNode
placement?: Placement placement?: Placement
@ -27,6 +28,7 @@ type Props = {
} }
const AppPicker: FC<Props> = ({ const AppPicker: FC<Props> = ({
scope,
appList, appList,
disabled, disabled,
trigger, trigger,
@ -38,8 +40,16 @@ const AppPicker: FC<Props> = ({
}) => { }) => {
const [searchText, setSearchText] = useState('') const [searchText, setSearchText] = useState('')
const filteredAppList = useMemo(() => { const filteredAppList = useMemo(() => {
return (appList || []).filter(app => app.name.toLowerCase().includes(searchText.toLowerCase())).filter(app => (app.mode !== 'advanced-chat' && app.mode !== 'workflow') || !!app.workflow) return (appList || [])
}, [appList, searchText]) .filter(app => app.name.toLowerCase().includes(searchText.toLowerCase()))
.filter(app => (app.mode !== 'advanced-chat' && app.mode !== 'workflow') || !!app.workflow)
.filter(app => scope === 'all'
|| (scope === 'completion' && app.mode === 'completion')
|| (scope === 'workflow' && app.mode === 'workflow')
|| (scope === 'chat' && app.mode === 'advanced-chat')
|| (scope === 'chat' && app.mode === 'agent-chat')
|| (scope === 'chat' && app.mode === 'chat'))
}, [appList, scope, searchText])
const getAppType = (app: App) => { const getAppType = (app: App) => {
switch (app.mode) { switch (app.mode) {
case 'advanced-chat': case 'advanced-chat':
@ -74,7 +84,7 @@ const AppPicker: FC<Props> = ({
</PortalToFollowElemTrigger> </PortalToFollowElemTrigger>
<PortalToFollowElemContent className='z-[1000]'> <PortalToFollowElemContent className='z-[1000]'>
<div className="relative w-[356px] min-h-20 rounded-xl bg-components-panel-bg-blur border-[0.5px] border-components-panel-border shadow-lg"> <div className="relative w-[356px] min-h-20 rounded-xl backdrop-blur-sm bg-components-panel-bg-blur border-[0.5px] border-components-panel-border shadow-lg">
<div className='p-2 pb-1'> <div className='p-2 pb-1'>
<Input <Input
showLeftIcon showLeftIcon

@ -23,6 +23,7 @@ type Props = {
inputs: Record<string, any> inputs: Record<string, any>
files?: any[] files?: any[]
} }
scope?: string
disabled?: boolean disabled?: boolean
placement?: Placement placement?: Placement
offset?: OffsetOptions offset?: OffsetOptions
@ -35,6 +36,7 @@ type Props = {
} }
const AppSelector: FC<Props> = ({ const AppSelector: FC<Props> = ({
value, value,
scope,
disabled, disabled,
placement = 'bottom', placement = 'bottom',
offset = 4, offset = 4,
@ -53,6 +55,7 @@ const AppSelector: FC<Props> = ({
return undefined return undefined
return appList.data.find(app => app.id === value.app_id) return appList.data.find(app => app.id === value.app_id)
}, [appList?.data, value]) }, [appList?.data, value])
const [isShowChooseApp, setIsShowChooseApp] = useState(false) const [isShowChooseApp, setIsShowChooseApp] = useState(false)
const handleSelectApp = (app: App) => { const handleSelectApp = (app: App) => {
const clearValue = app.id !== value?.app_id const clearValue = app.id !== value?.app_id
@ -103,7 +106,7 @@ const AppSelector: FC<Props> = ({
/> />
</PortalToFollowElemTrigger> </PortalToFollowElemTrigger>
<PortalToFollowElemContent className='z-[1000]'> <PortalToFollowElemContent className='z-[1000]'>
<div className="relative w-[389px] min-h-20 rounded-xl bg-components-panel-bg-blur border-[0.5px] border-components-panel-border shadow-lg"> <div className="relative w-[389px] min-h-20 rounded-xl backdrop-blur-sm bg-components-panel-bg-blur border-[0.5px] border-components-panel-border shadow-lg">
<div className='px-4 py-3 flex flex-col gap-1'> <div className='px-4 py-3 flex flex-col gap-1'>
<div className='h-6 flex items-center system-sm-semibold text-text-secondary'>{t('app.appSelector.label')}</div> <div className='h-6 flex items-center system-sm-semibold text-text-secondary'>{t('app.appSelector.label')}</div>
<AppPicker <AppPicker
@ -120,6 +123,7 @@ const AppSelector: FC<Props> = ({
disabled={false} disabled={false}
appList={appList?.data || []} appList={appList?.data || []}
onSelect={handleSelectApp} onSelect={handleSelectApp}
scope={scope || 'all'}
/> />
</div> </div>
{/* app inputs config panel */} {/* app inputs config panel */}

Loading…
Cancel
Save