From 573f653789839b8f86242543ef4b4dbafa543ab6 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 1 Aug 2024 11:40:55 +0800 Subject: [PATCH] feat: order by --- .../list-filter/components/limit-config.tsx | 50 ++++++++++--------- .../workflow/nodes/list-filter/default.ts | 11 +++- .../workflow/nodes/list-filter/panel.tsx | 38 +++++++++++++- .../workflow/nodes/list-filter/use-config.ts | 20 +++++++- web/i18n/en-US/workflow.ts | 3 ++ web/i18n/zh-Hans/workflow.ts | 3 ++ 6 files changed, 98 insertions(+), 27 deletions(-) diff --git a/web/app/components/workflow/nodes/list-filter/components/limit-config.tsx b/web/app/components/workflow/nodes/list-filter/components/limit-config.tsx index 6e40346e50..10a5493f6a 100644 --- a/web/app/components/workflow/nodes/list-filter/components/limit-config.tsx +++ b/web/app/components/workflow/nodes/list-filter/components/limit-config.tsx @@ -71,30 +71,32 @@ const LimitConfig: FC = ({ /> } > - {payload && ( -
- handleLimitSizeChange(e.target.value)} - onBlur={handleBlur} - disabled={readonly || !payload?.enabled} - /> - -
- )} + {payload?.enabled + ? ( +
+ handleLimitSizeChange(e.target.value)} + onBlur={handleBlur} + disabled={readonly || !payload?.enabled} + /> + +
+ ) + : null} ) diff --git a/web/app/components/workflow/nodes/list-filter/default.ts b/web/app/components/workflow/nodes/list-filter/default.ts index 5fe4b44a8d..899e3e7117 100644 --- a/web/app/components/workflow/nodes/list-filter/default.ts +++ b/web/app/components/workflow/nodes/list-filter/default.ts @@ -1,12 +1,21 @@ import { BlockEnum } from '../../types' import type { NodeDefault } from '../../types' -import { type ListFilterNodeType } from './types' +import { type ListFilterNodeType, OrderBy } from './types' import { ALL_CHAT_AVAILABLE_BLOCKS, ALL_COMPLETION_AVAILABLE_BLOCKS } from '@/app/components/workflow/constants' const i18nPrefix = 'workflow.errorMsg' const nodeDefault: NodeDefault = { defaultValue: { variable: [], + orderBy: { + enabled: false, + key: '', + value: OrderBy.ASC, + }, + limit: { + enabled: false, + size: 10, + }, }, getAvailablePrevNodes(isChatMode: boolean) { const nodes = isChatMode diff --git a/web/app/components/workflow/nodes/list-filter/panel.tsx b/web/app/components/workflow/nodes/list-filter/panel.tsx index 186fda5ae7..75082561e9 100644 --- a/web/app/components/workflow/nodes/list-filter/panel.tsx +++ b/web/app/components/workflow/nodes/list-filter/panel.tsx @@ -3,11 +3,13 @@ import React from 'react' import { useTranslation } from 'react-i18next' import VarReferencePicker from '../_base/components/variable/var-reference-picker' import OutputVars, { VarItem } from '../_base/components/output-vars' +import OptionCard from '../_base/components/option-card' import useConfig from './use-config' -import type { ListFilterNodeType } from './types' +import { type ListFilterNodeType, OrderBy } from './types' import LimitConfig from './components/limit-config' import Field from '@/app/components/workflow/nodes/_base/components/field' import { type NodePanelProps } from '@/app/components/workflow/types' +import Switch from '@/app/components/base/switch' const i18nPrefix = 'workflow.nodes.listFilter' @@ -23,6 +25,8 @@ const Panel: FC> = ({ handleVarChanges, filterVar, handleLimitChange, + handleOrderByEnabledChange, + handleOrderByTypeChange, } = useConfig(id, data) return ( @@ -41,6 +45,38 @@ const Panel: FC> = ({ /> + + } + > + {inputs.orderBy?.enabled + ? ( +
+
Variable Picker placeholder
+
+ + +
+
+ ) + : null} +
+ { setInputs(newInputs) }, [inputs, setInputs]) + const handleOrderByEnabledChange = useCallback((enabled: boolean) => { + const newInputs = produce(inputs, (draft) => { + draft.orderBy.enabled = enabled + }) + setInputs(newInputs) + }, [inputs, setInputs]) + + const handleOrderByTypeChange = useCallback((type: OrderBy) => { + return () => { + const newInputs = produce(inputs, (draft) => { + draft.orderBy.value = type + }) + setInputs(newInputs) + } + }, [inputs, setInputs]) + return { readOnly, inputs, filterVar, handleVarChanges, handleLimitChange, + handleOrderByEnabledChange, + handleOrderByTypeChange, } } diff --git a/web/i18n/en-US/workflow.ts b/web/i18n/en-US/workflow.ts index 1c7db5d192..88c0668ccd 100644 --- a/web/i18n/en-US/workflow.ts +++ b/web/i18n/en-US/workflow.ts @@ -502,6 +502,9 @@ const translation = { listFilter: { inputVar: 'Input Variable', limit: 'Limit', + orderBy: 'Order by', + asc: 'ASC', + desc: 'DESC', outputVars: { result: 'Filter result', first_record: 'First record', diff --git a/web/i18n/zh-Hans/workflow.ts b/web/i18n/zh-Hans/workflow.ts index 359f95b89f..026be2241e 100644 --- a/web/i18n/zh-Hans/workflow.ts +++ b/web/i18n/zh-Hans/workflow.ts @@ -502,6 +502,9 @@ const translation = { listFilter: { inputVar: '输入变量', limit: '限制', + orderBy: '排序', + asc: '升序', + desc: '降序', outputVars: { result: '过滤结果', first_record: '第一条记录',