mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-20 05:19:08 +08:00
feat: sub var picker
This commit is contained in:
parent
573f653789
commit
81383d7c74
@ -24,7 +24,7 @@ const defaultItems = [
|
|||||||
export type Item = {
|
export type Item = {
|
||||||
value: number | string
|
value: number | string
|
||||||
name: string
|
name: string
|
||||||
}
|
} & Record<string, any>
|
||||||
|
|
||||||
export type ISelectProps = {
|
export type ISelectProps = {
|
||||||
className?: string
|
className?: string
|
||||||
@ -38,6 +38,13 @@ export type ISelectProps = {
|
|||||||
placeholder?: string
|
placeholder?: string
|
||||||
overlayClassName?: string
|
overlayClassName?: string
|
||||||
optionClassName?: string
|
optionClassName?: string
|
||||||
|
renderOption?: ({
|
||||||
|
item,
|
||||||
|
selected,
|
||||||
|
}: {
|
||||||
|
item: Item
|
||||||
|
selected: boolean
|
||||||
|
}) => React.ReactNode
|
||||||
}
|
}
|
||||||
const Select: FC<ISelectProps> = ({
|
const Select: FC<ISelectProps> = ({
|
||||||
className,
|
className,
|
||||||
@ -49,6 +56,7 @@ const Select: FC<ISelectProps> = ({
|
|||||||
bgClassName = 'bg-gray-100',
|
bgClassName = 'bg-gray-100',
|
||||||
overlayClassName,
|
overlayClassName,
|
||||||
optionClassName,
|
optionClassName,
|
||||||
|
renderOption,
|
||||||
}) => {
|
}) => {
|
||||||
const [query, setQuery] = useState('')
|
const [query, setQuery] = useState('')
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
@ -61,6 +69,7 @@ const Select: FC<ISelectProps> = ({
|
|||||||
defaultSelect = existed
|
defaultSelect = existed
|
||||||
|
|
||||||
setSelectedItem(defaultSelect)
|
setSelectedItem(defaultSelect)
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [defaultValue])
|
}, [defaultValue])
|
||||||
|
|
||||||
const filteredItems: Item[]
|
const filteredItems: Item[]
|
||||||
@ -120,24 +129,30 @@ const Select: FC<ISelectProps> = ({
|
|||||||
value={item}
|
value={item}
|
||||||
className={({ active }: { active: boolean }) =>
|
className={({ active }: { active: boolean }) =>
|
||||||
classNames(
|
classNames(
|
||||||
optionClassName,
|
|
||||||
'relative cursor-default select-none py-2 pl-3 pr-9 rounded-lg hover:bg-gray-100 text-gray-700',
|
'relative cursor-default select-none py-2 pl-3 pr-9 rounded-lg hover:bg-gray-100 text-gray-700',
|
||||||
active ? 'bg-gray-100' : '',
|
active ? 'bg-gray-100' : '',
|
||||||
|
optionClassName,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{({ /* active, */ selected }) => (
|
{({ /* active, */ selected }) => (
|
||||||
<>
|
<>
|
||||||
<span className={classNames('block', selected && 'font-normal')}>{item.name}</span>
|
{renderOption
|
||||||
{selected && (
|
? renderOption({ item, selected })
|
||||||
<span
|
: (
|
||||||
className={classNames(
|
<>
|
||||||
'absolute inset-y-0 right-0 flex items-center pr-4 text-gray-700',
|
<span className={classNames('block', selected && 'font-normal')}>{item.name}</span>
|
||||||
)}
|
{selected && (
|
||||||
>
|
<span
|
||||||
<CheckIcon className="h-5 w-5" aria-hidden="true" />
|
className={classNames(
|
||||||
</span>
|
'absolute inset-y-0 right-0 flex items-center pr-4 text-gray-700',
|
||||||
)}
|
)}
|
||||||
|
>
|
||||||
|
<CheckIcon className="h-5 w-5" aria-hidden="true" />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Combobox.Option>
|
</Combobox.Option>
|
||||||
@ -157,6 +172,8 @@ const SimpleSelect: FC<ISelectProps> = ({
|
|||||||
disabled = false,
|
disabled = false,
|
||||||
onSelect,
|
onSelect,
|
||||||
placeholder,
|
placeholder,
|
||||||
|
optionClassName,
|
||||||
|
renderOption,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const localPlaceholder = placeholder || t('common.placeholder.select')
|
const localPlaceholder = placeholder || t('common.placeholder.select')
|
||||||
@ -169,6 +186,7 @@ const SimpleSelect: FC<ISelectProps> = ({
|
|||||||
defaultSelect = existed
|
defaultSelect = existed
|
||||||
|
|
||||||
setSelectedItem(defaultSelect)
|
setSelectedItem(defaultSelect)
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [defaultValue])
|
}, [defaultValue])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -218,24 +236,30 @@ const SimpleSelect: FC<ISelectProps> = ({
|
|||||||
<Listbox.Option
|
<Listbox.Option
|
||||||
key={item.value}
|
key={item.value}
|
||||||
className={({ active }) =>
|
className={({ active }) =>
|
||||||
`relative cursor-pointer select-none py-2 pl-3 pr-9 rounded-lg hover:bg-gray-100 text-gray-700 ${active ? 'bg-gray-100' : ''
|
classNames(
|
||||||
}`
|
`relative cursor-pointer select-none py-2 pl-3 pr-9 rounded-lg hover:bg-gray-100 text-gray-700 ${active ? 'bg-gray-100' : ''}`,
|
||||||
|
optionClassName,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
value={item}
|
value={item}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
{({ /* active, */ selected }) => (
|
{({ /* active, */ selected }) => (
|
||||||
<>
|
<>
|
||||||
<span className={classNames('block', selected && 'font-normal')}>{item.name}</span>
|
{renderOption
|
||||||
{selected && (
|
? renderOption({ item, selected })
|
||||||
<span
|
: (<>
|
||||||
className={classNames(
|
<span className={classNames('block', selected && 'font-normal')}>{item.name}</span>
|
||||||
'absolute inset-y-0 right-0 flex items-center pr-4 text-gray-700',
|
{selected && (
|
||||||
|
<span
|
||||||
|
className={classNames(
|
||||||
|
'absolute inset-y-0 right-0 flex items-center pr-4 text-gray-700',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<CheckIcon className="h-5 w-5" aria-hidden="true" />
|
||||||
|
</span>
|
||||||
)}
|
)}
|
||||||
>
|
</>)}
|
||||||
<CheckIcon className="h-5 w-5" aria-hidden="true" />
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Listbox.Option>
|
</Listbox.Option>
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
'use client'
|
||||||
|
import type { FC } from 'react'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
const FilterCondition: FC = () => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
export default React.memo(FilterCondition)
|
@ -0,0 +1,36 @@
|
|||||||
|
'use client'
|
||||||
|
import type { FC } from 'react'
|
||||||
|
import React from 'react'
|
||||||
|
import { SimpleSelect as Select } from '@/app/components/base/select'
|
||||||
|
import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
|
||||||
|
|
||||||
|
const SubVariablePicker: FC = () => {
|
||||||
|
const renderOption = ({ item }: { item: Record<string, any> }) => {
|
||||||
|
return (
|
||||||
|
<div className='flex items-center h-6 justify-between'>
|
||||||
|
<div className='flex items-center h-full'>
|
||||||
|
<Variable02 className='mr-[5px] w-3.5 h-3.5 text-text-accent' />
|
||||||
|
<span className='text-text-secondary system-sm-medium'>{item.name}</span>
|
||||||
|
</div>
|
||||||
|
<span className='text-text-tertiary system-xs-regular'>{item.type}</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Select
|
||||||
|
items={[
|
||||||
|
{ value: '1', name: 'name', type: 'string' },
|
||||||
|
{ value: '2', name: 'age', type: 'number' },
|
||||||
|
]}
|
||||||
|
defaultValue={'1'}
|
||||||
|
allowSearch
|
||||||
|
onSelect={() => { }}
|
||||||
|
placeholder='Select sub variable key'
|
||||||
|
optionClassName='pl-4 pr-5 py-0'
|
||||||
|
renderOption={renderOption}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
export default React.memo(SubVariablePicker)
|
@ -5,6 +5,7 @@ import VarReferencePicker from '../_base/components/variable/var-reference-picke
|
|||||||
import OutputVars, { VarItem } from '../_base/components/output-vars'
|
import OutputVars, { VarItem } from '../_base/components/output-vars'
|
||||||
import OptionCard from '../_base/components/option-card'
|
import OptionCard from '../_base/components/option-card'
|
||||||
import useConfig from './use-config'
|
import useConfig from './use-config'
|
||||||
|
import SubVariablePicker from './components/sub-variable-picker'
|
||||||
import { type ListFilterNodeType, OrderBy } from './types'
|
import { type ListFilterNodeType, OrderBy } from './types'
|
||||||
import LimitConfig from './components/limit-config'
|
import LimitConfig from './components/limit-config'
|
||||||
import Field from '@/app/components/workflow/nodes/_base/components/field'
|
import Field from '@/app/components/workflow/nodes/_base/components/field'
|
||||||
@ -59,7 +60,7 @@ const Panel: FC<NodePanelProps<ListFilterNodeType>> = ({
|
|||||||
{inputs.orderBy?.enabled
|
{inputs.orderBy?.enabled
|
||||||
? (
|
? (
|
||||||
<div className='flex items-center justify-between'>
|
<div className='flex items-center justify-between'>
|
||||||
<div className='grow'>Variable Picker placeholder</div>
|
<div className='grow mr-2'><SubVariablePicker /></div>
|
||||||
<div className='shrink-0 flex space-x-1'>
|
<div className='shrink-0 flex space-x-1'>
|
||||||
<OptionCard
|
<OptionCard
|
||||||
title={t(`${i18nPrefix}.asc`)}
|
title={t(`${i18nPrefix}.asc`)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user