tachybase_todo/packages/plugins/@nocobase/plugin-workflow-action-trigger/src/client/ActionTrigger.tsx
Junyi d691e4c7e6
feat(plugin-workflow): support multiple data source in workflow (#3739)
* feat(plugin-workflow): support multiple data source in workflow

* fix(plugin-workflow): fix test cases

* test(plugin-workflow-sql): debug test case

* fix(plugin-workflow): fix collection trigger creation without config

* test(plugin-workflow-sql): debug test case

* fix: workflow e2e test

* chore(ci): disable console intercept in vitest

* chore(ci): disable console intercept in vitest

* chore(ci): disable console intercept in vitest

* chore(ci): disable console intercept in vitest

* test(plugin-workflow-sql): debug test case

* test: approval e2e

* fix: remove pro-plugins from packages

* refactor(plugin-workflow): support pass collection from props to CollectionBlockInitializer

* test(plugin-workflow): add test case

* fix(plugin-workflow): disable modification of executed workflow

* fix: e2ePageObjectModel

* fix: load data source when data source load failed (#3793)

* chore: console.log

* fix(subTable): fix sorting rule setting (#3795)

* fix: through collection support search (#3800)

* fix(client): visible -> useVisible

* fix(client): fix action designer error occured in custom form (#3801)

* fix(client): fix action designer error occured in custom form

* fix(client): fix from the source

* chore(module): remove submodule

* fix(plugin-workflow): fix client cycling import

* fix(plugin-workflow): fix collection event name

* fix(plugin-workflow): fix undefined ref

---------

Co-authored-by: hongboji <j414562100@qq.com>
Co-authored-by: ChengLei Shao <chareice@live.com>
Co-authored-by: Zeke Zhang <958414905@qq.com>
Co-authored-by: katherinehhh <shunai.tang@hand-china.com>
Co-authored-by: chenos <chenlinxh@gmail.com>
2024-03-25 14:46:22 +08:00

137 lines
4.1 KiB
TypeScript

import { useForm } from '@formily/react';
import {
SchemaInitializerItemType,
useCollectionDataSource,
useCollectionManager_deprecated,
useCompile,
} from '@nocobase/client';
import {
Trigger,
CollectionBlockInitializer,
getCollectionFieldOptions,
useWorkflowAnyExecuted,
} from '@nocobase/plugin-workflow/client';
import { NAMESPACE, useLang } from '../locale';
export default class extends Trigger {
title = `{{t("Action event", { ns: "${NAMESPACE}" })}}`;
description = `{{t("Triggers after specific operations on data are submitted, such as create, update, delete, etc., or directly submitting a record to the workflow.", { ns: "${NAMESPACE}" })}}`;
fieldset = {
collection: {
type: 'string',
required: true,
'x-decorator': 'FormItem',
'x-component': 'DataSourceCollectionCascader',
'x-disabled': '{{ useWorkflowAnyExecuted() }}',
title: `{{t("Collection", { ns: "${NAMESPACE}" })}}`,
description: `{{t("Which collection record belongs to.", { ns: "${NAMESPACE}" })}}`,
'x-reactions': [
{
target: 'appends',
effects: ['onFieldValueChange'],
fulfill: {
state: {
value: [],
},
},
},
],
},
appends: {
type: 'array',
title: `{{t("Associations to use", { ns: "${NAMESPACE}" })}}`,
description: `{{t("Please select the associated fields that need to be accessed in subsequent nodes. With more than two levels of to-many associations may cause performance issue, please use with caution.", { ns: "workflow" })}}`,
'x-decorator': 'FormItem',
'x-component': 'AppendsTreeSelect',
'x-component-props': {
title: 'Preload associations',
multiple: true,
useCollection() {
const { values } = useForm();
return values?.collection;
},
},
'x-reactions': [
{
dependencies: ['collection'],
fulfill: {
state: {
visible: '{{!!$deps[0]}}',
},
},
},
],
},
};
scope = {
useCollectionDataSource,
useWorkflowAnyExecuted,
};
isActionTriggerable = (config, context) => {
return ['create', 'update', 'customize:update', 'customize:triggerWorkflows'].includes(context.action);
};
useVariables(config, options) {
// eslint-disable-next-line react-hooks/rules-of-hooks
const compile = useCompile();
// eslint-disable-next-line react-hooks/rules-of-hooks
const { getCollectionFields } = useCollectionManager_deprecated();
// eslint-disable-next-line react-hooks/rules-of-hooks
const langTriggerData = useLang('Trigger data');
// eslint-disable-next-line react-hooks/rules-of-hooks
const langUserSubmittedForm = useLang('User submitted action');
// eslint-disable-next-line react-hooks/rules-of-hooks
const langRoleSubmittedForm = useLang('Role of user submitted action');
const rootFields = [
{
collectionName: config.collection,
name: 'data',
type: 'hasOne',
target: config.collection,
uiSchema: {
title: langTriggerData,
},
},
{
collectionName: 'users',
name: 'user',
type: 'hasOne',
target: 'users',
uiSchema: {
title: langUserSubmittedForm,
},
},
{
name: 'roleName',
uiSchema: {
title: langRoleSubmittedForm,
},
},
];
const result = getCollectionFieldOptions({
// depth,
appends: ['data', 'user', ...(config.appends?.map((item) => `data.${item}`) || [])],
...options,
fields: rootFields,
compile,
getCollectionFields,
});
return result;
}
useInitializers(config): SchemaInitializerItemType | null {
if (!config.collection) {
return null;
}
return {
name: 'triggerData',
type: 'item',
key: 'triggerData',
title: `{{t("Trigger data", { ns: "${NAMESPACE}" })}}`,
Component: CollectionBlockInitializer,
collection: config.collection,
dataPath: '$context.data',
};
}
}