From 1125ff76a061cb83f49c3dd7c619d3abf1a40fe5 Mon Sep 17 00:00:00 2001 From: Junyi Date: Fri, 28 Jul 2023 22:48:12 +0700 Subject: [PATCH] refactor(plugin-workflow): allow system values to be assigned in create and update node (#2345) --- .../src/client/components/CollectionFieldset.tsx | 12 ++---------- .../plugins/workflow/src/client/nodes/update.tsx | 13 +++++++------ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/packages/plugins/workflow/src/client/components/CollectionFieldset.tsx b/packages/plugins/workflow/src/client/components/CollectionFieldset.tsx index 89d39b8b5..98909b5cf 100644 --- a/packages/plugins/workflow/src/client/components/CollectionFieldset.tsx +++ b/packages/plugins/workflow/src/client/components/CollectionFieldset.tsx @@ -32,14 +32,6 @@ function AssociationInput(props) { return ; } -export function useCollectionUIFields(collection) { - const { getCollectionFields } = useCollectionManager(); - - return getCollectionFields(collection).filter( - (field) => !field.hidden && (field.uiSchema ? !field.uiSchema['x-read-pretty'] : false), - ); -} - // NOTE: observer for watching useProps const CollectionFieldSet = observer( ({ value, disabled, onChange, filter }: any) => { @@ -47,11 +39,11 @@ const CollectionFieldSet = observer( const { t } = useTranslation(); const compile = useCompile(); const form = useForm(); - const { getCollection } = useCollectionManager(); + const { getCollection, getCollectionFields } = useCollectionManager(); const scope = useWorkflowVariableOptions(); const { values: config } = form; const collectionName = config?.collection; - const collectionFields = useCollectionUIFields(collectionName); + const collectionFields = getCollectionFields(collectionName); const fields = filter ? collectionFields.filter(filter.bind(config)) : collectionFields; const unassignedFields = useMemo(() => fields.filter((field) => !value || !(field.name in value)), [fields, value]); diff --git a/packages/plugins/workflow/src/client/nodes/update.tsx b/packages/plugins/workflow/src/client/nodes/update.tsx index a26693722..1e12cec33 100644 --- a/packages/plugins/workflow/src/client/nodes/update.tsx +++ b/packages/plugins/workflow/src/client/nodes/update.tsx @@ -1,20 +1,21 @@ +import { useField, useForm } from '@formily/react'; import React from 'react'; -import { useForm, useField } from '@formily/react'; -import { useCollectionDataSource } from '@nocobase/client'; +import { useCollectionDataSource, useCollectionManager } from '@nocobase/client'; +import CollectionFieldset from '../components/CollectionFieldset'; import { FilterDynamicComponent } from '../components/FilterDynamicComponent'; -import CollectionFieldset, { useCollectionUIFields } from '../components/CollectionFieldset'; -import { isValidFilter } from '../utils'; +import { RadioWithTooltip } from '../components/RadioWithTooltip'; import { NAMESPACE, lang } from '../locale'; import { collection, filter, values } from '../schemas/collection'; -import { RadioWithTooltip } from '../components/RadioWithTooltip'; +import { isValidFilter } from '../utils'; function IndividualHooksRadioWithTooltip({ onChange, ...props }) { + const { getCollectionFields } = useCollectionManager(); const form = useForm(); const { collection } = form.values; - const fields = useCollectionUIFields(collection); + const fields = getCollectionFields(collection); const field = useField(); function onValueChange({ target }) {