From 9a0cfa9971ff7a6dd8cfedcc7da15ec40c01c470 Mon Sep 17 00:00:00 2001 From: Sheldon Guo Date: Wed, 2 Apr 2025 07:30:15 +0800 Subject: [PATCH] feat: support getFieldSupportedHelpers --- .../src/schema-component/antd/variable/Input.tsx | 11 +++++++---- .../antd/variable/VariableProvider.tsx | 9 +++++++++ .../src/schema-component/antd/variable/index.ts | 3 ++- .../plugins/@nocobase/plugin-action-template-print | 1 + packages/plugins/@nocobase/plugin-backups | 1 + .../@nocobase/plugin-workflow/src/client/variable.tsx | 11 ++++++++++- 6 files changed, 30 insertions(+), 6 deletions(-) create mode 160000 packages/plugins/@nocobase/plugin-action-template-print create mode 160000 packages/plugins/@nocobase/plugin-backups diff --git a/packages/core/client/src/schema-component/antd/variable/Input.tsx b/packages/core/client/src/schema-component/antd/variable/Input.tsx index 1b8f426c2b..33811eb56e 100644 --- a/packages/core/client/src/schema-component/antd/variable/Input.tsx +++ b/packages/core/client/src/schema-component/antd/variable/Input.tsx @@ -262,7 +262,7 @@ function _Input(props: VariableInputProps) { [value], ); - const selectedScopeOption = useMemo(() => findScopeOption(scope, variableSegments), [scope, variableSegments]); + const selectedScopeOption = useMemo(() => findScopeOption(options, variableSegments), [options, variableSegments]); const parsed = useMemo(() => parseValue(variableSegments, parseOptions), [parseOptions, variableSegments]); const isConstant = typeof parsed === 'string'; @@ -356,7 +356,7 @@ function _Input(props: VariableInputProps) { } } await option.loadChildren(option, activeKey, variable); - setOptions((prev) => [...prev]); + setOptions([...options]); } }; @@ -381,7 +381,7 @@ function _Input(props: VariableInputProps) { // setPrevType(next[1]); const newVariable = ConstantTypes[next[1]]?.default?.() ?? null; onChange( - composeTemplate({ fullVariable: newVariable, helpers: optionPath[optionPath.length - 1]?.helpers ?? [] }), + composeTemplate({ fullVariable: newVariable, helpers: helperObservables.helpersObs.value ?? [] }), optionPath, ); } @@ -394,7 +394,10 @@ function _Input(props: VariableInputProps) { } const variableName = next.join('.'); const option = optionPath[optionPath.length - 1]; - onChange(composeTemplate({ fullVariable: variableName, helpers: option?.helpers ?? [] }), optionPath); + onChange( + composeTemplate({ fullVariable: variableName, helpers: helperObservables.helpersObs.value ?? [] }), + optionPath, + ); }, [type, variable, onChange], ); diff --git a/packages/core/client/src/schema-component/antd/variable/VariableProvider.tsx b/packages/core/client/src/schema-component/antd/variable/VariableProvider.tsx index c5e12c8650..72befdcc25 100644 --- a/packages/core/client/src/schema-component/antd/variable/VariableProvider.tsx +++ b/packages/core/client/src/schema-component/antd/variable/VariableProvider.tsx @@ -192,3 +192,12 @@ export function useVariable() { isHelperAllowed, }; } + +export function getFieldSupportedHelpers(fieldSchema: any): string[] { + if (!fieldSchema) { + return []; + } + if (['datetimeNoTz', 'date'].includes(fieldSchema?.type)) { + return ['date.*']; + } +} diff --git a/packages/core/client/src/schema-component/antd/variable/index.ts b/packages/core/client/src/schema-component/antd/variable/index.ts index a67135fb93..8f1973a3fe 100644 --- a/packages/core/client/src/schema-component/antd/variable/index.ts +++ b/packages/core/client/src/schema-component/antd/variable/index.ts @@ -7,5 +7,6 @@ * For more information, please refer to: https://www.nocobase.com/agreement. */ -export * from './Variable'; export { TextAreaWithGlobalScope } from './TextAreaWithGlobalScope'; +export * from './Variable'; +export { getFieldSupportedHelpers } from './VariableProvider'; diff --git a/packages/plugins/@nocobase/plugin-action-template-print b/packages/plugins/@nocobase/plugin-action-template-print new file mode 160000 index 0000000000..683602770b --- /dev/null +++ b/packages/plugins/@nocobase/plugin-action-template-print @@ -0,0 +1 @@ +Subproject commit 683602770b9fdad9a8fecc71735e8e5b46b76ceb diff --git a/packages/plugins/@nocobase/plugin-backups b/packages/plugins/@nocobase/plugin-backups new file mode 160000 index 0000000000..d6a1f327a1 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-backups @@ -0,0 +1 @@ +Subproject commit d6a1f327a10cbe56ddec3d5adbb6e4adaf7a48d3 diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx index 87d358cc34..5180e9eafd 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx @@ -10,7 +10,15 @@ import { uniqBy } from 'lodash'; import React, { createContext, useCallback, useContext } from 'react'; -import { Variable, parseCollectionName, useApp, useCompile, useGlobalVariable, usePlugin } from '@nocobase/client'; +import { + Variable, + getFieldSupportedHelpers, + parseCollectionName, + useApp, + useCompile, + useGlobalVariable, + usePlugin, +} from '@nocobase/client'; import WorkflowPlugin from '.'; import { useFlowContext } from './FlowContext'; @@ -366,6 +374,7 @@ export function getCollectionFieldOptions(options): VariableOption[] { [fieldNames.label]: label, key: field.name, [fieldNames.value]: field.name, + helpers: getFieldSupportedHelpers(field), isLeaf, loadChildren: isLeaf ? null : boundLoadChildren, field,