feat: support order change

This commit is contained in:
Joel 2024-08-30 14:34:46 +08:00
parent 976efd93a1
commit 61d989f413
5 changed files with 15 additions and 2 deletions

View File

@ -1,6 +1,7 @@
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React, { useCallback } from 'react' import React, { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import { SUB_VARIABLES } from '../../if-else/default' import { SUB_VARIABLES } from '../../if-else/default'
import type { Item } from '@/app/components/base/select' import type { Item } from '@/app/components/base/select'
import { SimpleSelect as Select } from '@/app/components/base/select' import { SimpleSelect as Select } from '@/app/components/base/select'
@ -18,6 +19,7 @@ const SubVariablePicker: FC<Props> = ({
onChange, onChange,
className, className,
}) => { }) => {
const { t } = useTranslation()
const subVarOptions = SUB_VARIABLES.map(item => ({ const subVarOptions = SUB_VARIABLES.map(item => ({
value: item, value: item,
name: item, name: item,
@ -46,7 +48,7 @@ const SubVariablePicker: FC<Props> = ({
defaultValue={value} defaultValue={value}
onSelect={handleChange} onSelect={handleChange}
className='!text-[13px]' className='!text-[13px]'
placeholder='Select sub variable key' placeholder={t('workflow.nodes.listFilter.selectVariableKeyPlaceholder')!}
optionClassName='pl-4 pr-5 py-0' optionClassName='pl-4 pr-5 py-0'
renderOption={renderOption} renderOption={renderOption}
/> />

View File

@ -32,6 +32,7 @@ const Panel: FC<NodePanelProps<ListFilterNodeType>> = ({
handleFilterChange, handleFilterChange,
handleLimitChange, handleLimitChange,
handleOrderByEnabledChange, handleOrderByEnabledChange,
handleOrderByKeyChange,
handleOrderByTypeChange, handleOrderByTypeChange,
} = useConfig(id, data) } = useConfig(id, data)
@ -81,7 +82,7 @@ const Panel: FC<NodePanelProps<ListFilterNodeType>> = ({
<div className='grow mr-2'> <div className='grow mr-2'>
<SubVariablePicker <SubVariablePicker
value={inputs.order_by.key as string} value={inputs.order_by.key as string}
onChange={() => { }} onChange={handleOrderByKeyChange}
/> />
</div> </div>
)} )}

View File

@ -106,6 +106,13 @@ const useConfig = (id: string, payload: ListFilterNodeType) => {
setInputs(newInputs) setInputs(newInputs)
}, [inputs, setInputs]) }, [inputs, setInputs])
const handleOrderByKeyChange = useCallback((key: string) => {
const newInputs = produce(inputs, (draft) => {
draft.order_by.key = key
})
setInputs(newInputs)
}, [inputs, setInputs])
const handleOrderByTypeChange = useCallback((type: OrderBy) => { const handleOrderByTypeChange = useCallback((type: OrderBy) => {
return () => { return () => {
const newInputs = produce(inputs, (draft) => { const newInputs = produce(inputs, (draft) => {
@ -126,6 +133,7 @@ const useConfig = (id: string, payload: ListFilterNodeType) => {
handleFilterChange, handleFilterChange,
handleLimitChange, handleLimitChange,
handleOrderByEnabledChange, handleOrderByEnabledChange,
handleOrderByKeyChange,
handleOrderByTypeChange, handleOrderByTypeChange,
} }
} }

View File

@ -562,6 +562,7 @@ const translation = {
listFilter: { listFilter: {
inputVar: 'Input Variable', inputVar: 'Input Variable',
filterCondition: 'Filter Condition', filterCondition: 'Filter Condition',
selectVariableKeyPlaceholder: 'Select sub variable key',
limit: 'Limit', limit: 'Limit',
orderBy: 'Order by', orderBy: 'Order by',
asc: 'ASC', asc: 'ASC',

View File

@ -562,6 +562,7 @@ const translation = {
listFilter: { listFilter: {
inputVar: '输入变量', inputVar: '输入变量',
filterCondition: '过滤条件', filterCondition: '过滤条件',
selectVariableKeyPlaceholder: '选择子变量的 Key',
limit: '限制', limit: '限制',
orderBy: '排序', orderBy: '排序',
asc: '升序', asc: '升序',