tachybase_todo/packages/plugins/@nocobase/plugin-workflow-action-trigger/src/client/index.ts
Junyi c2b121cda6
feat(plugin-workflow-form-trigger): add trigger button to all single record action bar (#3563)
* feat(plugin-workflow-form-trigger): add trigger button to all single record actionbar

* fix(plugin-workflow-form-trigger): fix button style and triggering

* fix(plugin-workflow): fix unused hook ref in workflow

* fix(plugin-workflow-form-trigger): fix button style

* refactor(plugin-workflow-action-trigger): change plugin name

* fix(plugin-workflow-action-trigger): fix unmigrated stuff

* fix(plugin-workflow-action-trigger): fix test case

* fix(plugin-workflow-action-trigger): fix test case

* fix(presets): fix package name

* fix(plugin-workflow-action-trigger): fix e2e test and migration

* fix(plugin-workflow-action-trigger): fix migration

* fix(plugin-workflow-action-trigger): fix migration

* fix(plugin-workflow-action-trigger): fix migration

* feat(plugin-workflow-action-trigger): add destroy to trigger

* fix(plugin-workflow-action-trigger): fix appends select

* fix(plugin-workflow-action-trigger): remove support for destroy action

* fix(plugin-workflow-action-trigger): fix collection check

* fix(plugin-workflow-action-trigger): fix test case

* fix(plugin-workflow-action-trigger): fix test case

* fix(plugin-workflow-action-trigger): fix test case
2024-03-06 14:42:20 +08:00

101 lines
3.9 KiB
TypeScript

import { Plugin, SchemaInitializerItemType } from '@nocobase/client';
import WorkflowPlugin, {
useTriggerWorkflowsActionProps,
useRecordTriggerWorkflowsActionProps,
} from '@nocobase/plugin-workflow/client';
import ActionTrigger from './ActionTrigger';
const submitToWorkflowActionInitializer: SchemaInitializerItemType = {
name: 'submitToWorkflow',
title: '{{t("Submit to workflow", { ns: "workflow" })}}',
Component: 'CustomizeActionInitializer',
schema: {
title: '{{t("Submit to workflow", { ns: "workflow" })}}',
'x-component': 'Action',
'x-component-props': {
useProps: '{{ useTriggerWorkflowsActionProps }}',
},
'x-designer': 'Action.Designer',
'x-action-settings': {
// assignedValues: {},
skipValidator: false,
onSuccess: {
manualClose: true,
redirecting: false,
successMessage: '{{t("Submitted successfully")}}',
},
triggerWorkflows: [],
},
'x-action': 'customize:triggerWorkflows',
},
};
const recordTriggerWorkflowActionInitializer: SchemaInitializerItemType = {
name: 'submitToWorkflow',
title: '{{t("Submit to workflow", { ns: "workflow" })}}',
Component: 'CustomizeActionInitializer',
schema: {
title: '{{t("Submit to workflow", { ns: "workflow" })}}',
'x-component': 'Action',
'x-component-props': {
useProps: '{{ useRecordTriggerWorkflowsActionProps }}',
},
'x-designer': 'Action.Designer',
'x-action-settings': {
// assignedValues: {},
onSuccess: {
manualClose: true,
redirecting: false,
successMessage: '{{t("Submitted successfully")}}',
},
triggerWorkflows: [],
},
'x-action': 'customize:triggerWorkflows',
},
};
const recordTriggerWorkflowActionLinkInitializer = {
...recordTriggerWorkflowActionInitializer,
schema: {
...recordTriggerWorkflowActionInitializer.schema,
'x-component': 'Action.Link',
},
};
export default class extends Plugin {
async load() {
const workflow = this.app.pm.get('workflow') as WorkflowPlugin;
workflow.registerTrigger('action', ActionTrigger);
this.app.addScopes({
useTriggerWorkflowsActionProps,
useRecordTriggerWorkflowsActionProps,
});
const FormActionInitializers = this.app.schemaInitializerManager.get('FormActionInitializers');
FormActionInitializers.add('customize.submitToWorkflow', submitToWorkflowActionInitializer);
const CreateFormActionInitializers = this.app.schemaInitializerManager.get('CreateFormActionInitializers');
CreateFormActionInitializers.add('customize.submitToWorkflow', submitToWorkflowActionInitializer);
const UpdateFormActionInitializers = this.app.schemaInitializerManager.get('UpdateFormActionInitializers');
UpdateFormActionInitializers.add('customize.submitToWorkflow', submitToWorkflowActionInitializer);
const DetailsActionInitializers = this.app.schemaInitializerManager.get('DetailsActionInitializers');
DetailsActionInitializers.add('customize.submitToWorkflow', recordTriggerWorkflowActionInitializer);
const ReadPrettyFormActionInitializers = this.app.schemaInitializerManager.get('ReadPrettyFormActionInitializers');
ReadPrettyFormActionInitializers.add('customize.submitToWorkflow', recordTriggerWorkflowActionInitializer);
const TableActionColumnInitializers = this.app.schemaInitializerManager.get('TableActionColumnInitializers');
TableActionColumnInitializers.add('customize.submitToWorkflow', recordTriggerWorkflowActionLinkInitializer);
const GridCardItemActionInitializers = this.app.schemaInitializerManager.get('GridCardItemActionInitializers');
GridCardItemActionInitializers.add('customize.submitToWorkflow', recordTriggerWorkflowActionLinkInitializer);
const ListItemActionInitializers = this.app.schemaInitializerManager.get('ListItemActionInitializers');
ListItemActionInitializers.add('customize.submitToWorkflow', recordTriggerWorkflowActionLinkInitializer);
}
}