From 0e7cb9e5cfcd983bddebcf982ebf5436c1be2e5d Mon Sep 17 00:00:00 2001 From: Junyi Date: Thu, 7 Dec 2023 21:46:58 +0800 Subject: [PATCH] refactor(plugin-workflow): split workflow features into plugins (#3115) * refactor(plugin-workflow): split manual and dynamic calculation into plugins * refactor(plugin-workflow): move loop to plugin * refactor(plugin-workflow): move parallel to plugin * fix(plugin-dynamic-calculation): fix package title * fix(plugin-workflow): fix plugin name * refactor(plugin-workflow): move delay to plugin * refactor(plugin-workflow): simplify exporting names * refactor(plugin-workflow): move aggregate to plugin * refactor(plugin-workflow): move sql to plugin * refactor(plugin-workflow): move reqeust to plugin * refactor(plugin-workflow): move form trigger to plugin * refactor(plugin-workflow): move locale to plugins * fix(plugin-workflow): fix test cases * fix(plugin-workflow-request): package name typo * fix(plugin-workflow): remove clean db from testkit * fix(plugin-workflow-sql): skip independent case * fix(plugin-workflow-sql): skip independent case * fix(plugin-workflow-delay): fix test cases * test(plugin-workflow-delay): fix test cases * test(plugin-workflow-delay): fix test cases * test(plugin-workflow-delay): fix test cases * test(plugin-workflow-delay): fix test cases * fix(plugin-workflow): fix migration version matching * test(plugin-workflow): fix test case * refactor(plugin-workflow): correct exporting of testkit * fix(plugin-workflow): fix testkit and require module * refactor(plugin-workflow): add workflow-test package for testing * test(plugin-workflow): test weird case * fix(plugin-workflow-test): remove workflow dependency to avoid cycling * fix(plugin-workflow): fix migration version * fix(plugin-workflow): fix migration and packages * fix(plugin-workflow): fix package dependencies * fix(preset): fix builtin list in preset * fix(plugin-workflow): add package entry file * fix(plugin-workflow): fix migrations * refactor(plugin-workflow): remove require * fix(plugin-workflow): fix locale namespace * fix(plugin-workflow): fix merged errors * fix(plugin-workflow): fix import cycling references * refactor(plugin-workflow): change instruction and triggers to classes in client * fix(plugin-workflow): fix migration version --- .../plugin-workflow-aggregate/LICENSE | 661 ++++++++++++++++++ .../plugin-workflow-aggregate/README.md | 9 + .../plugin-workflow-aggregate/README.zh-CN.md | 9 + .../plugin-workflow-aggregate/client.d.ts | 2 + .../plugin-workflow-aggregate/client.js | 1 + .../plugin-workflow-aggregate/package.json | 24 + .../plugin-workflow-aggregate/server.d.ts | 2 + .../plugin-workflow-aggregate/server.js | 1 + .../src/client/AggregateInstruction.tsx} | 84 ++- .../src/client/index.ts | 19 + .../plugin-workflow-aggregate/src/index.ts | 2 + .../src/locale/en-US.json | 12 + .../src/locale/index.ts | 12 + .../src/locale/zh-CN.json | 12 + .../src/server/AggregateInstruction.ts} | 11 +- .../src/server/Plugin.ts | 14 + .../src/server/__tests__/instruction.test.ts} | 12 +- .../src/server/index.ts | 1 + .../@nocobase/plugin-workflow-delay/LICENSE | 661 ++++++++++++++++++ .../@nocobase/plugin-workflow-delay/README.md | 9 + .../plugin-workflow-delay/README.zh-CN.md | 9 + .../plugin-workflow-delay/client.d.ts | 2 + .../@nocobase/plugin-workflow-delay/client.js | 1 + .../plugin-workflow-delay/package.json | 24 + .../plugin-workflow-delay/server.d.ts | 2 + .../@nocobase/plugin-workflow-delay/server.js | 1 + .../src/client/DelayInstruction.tsx | 87 +++ .../plugin-workflow-delay/src/client/index.ts | 19 + .../plugin-workflow-delay/src/index.ts | 2 + .../src/locale/en-US.json | 9 + .../src/locale/es-ES.json | 8 + .../src/locale/fr-FR.json | 8 + .../plugin-workflow-delay/src/locale/index.ts | 12 + .../src/locale/pt-BR.json | 8 + .../src/locale/zh-CN.json | 9 + .../src/server/DelayInstruction.ts} | 28 +- .../src/server/Plugin.ts | 14 + .../src/server/__tests__/instruction.test.ts} | 18 +- .../plugin-workflow-delay/src/server/index.ts | 1 + .../LICENSE | 661 ++++++++++++++++++ .../README.md | 9 + .../README.zh-CN.md | 9 + .../client.d.ts | 2 + .../client.js | 1 + .../package.json | 33 + .../server.d.ts | 2 + .../server.js | 1 + .../src/client/DynamicCalculation.tsx | 98 +++ .../src/client}/DynamicExpression.tsx | 2 +- .../src/client/Provider.tsx | 22 + .../src/client}/expression.tsx | 0 .../src/client/index.ts | 28 + .../src/index.ts | 2 + .../src/locale/en-US.json | 11 + .../src/locale/index.ts | 12 + .../src/locale/zh-CN.json | 11 + .../src/server/DynamicCalculation.ts | 29 + .../src/server/Plugin.ts | 19 + .../__tests__/collections/categories.ts | 19 + .../src/server/__tests__/instruction.test.ts | 115 +++ .../src/server}/expression-field.ts | 0 .../src/server/index.ts | 1 + .../plugin-workflow-form-trigger/LICENSE | 661 ++++++++++++++++++ .../plugin-workflow-form-trigger/README.md | 9 + .../README.zh-CN.md | 9 + .../plugin-workflow-form-trigger/client.d.ts | 2 + .../plugin-workflow-form-trigger/client.js | 1 + .../plugin-workflow-form-trigger/package.json | 24 + .../plugin-workflow-form-trigger/server.d.ts | 2 + .../plugin-workflow-form-trigger/server.js | 1 + .../src/client/FormTrigger.tsx | 118 ++++ .../src/client/index.ts | 19 + .../plugin-workflow-form-trigger/src/index.ts | 2 + .../src/locale/en-US.json | 8 + .../src/locale/index.ts | 12 + .../src/locale/zh-CN.json | 8 + .../src/server/FormTrigger.ts} | 13 +- .../src/server/Plugin.ts | 14 + .../src/server/__tests__/trigger.test.ts} | 10 +- .../src/server/index.ts | 1 + .../@nocobase/plugin-workflow-loop/LICENSE | 661 ++++++++++++++++++ .../@nocobase/plugin-workflow-loop/README.md | 9 + .../plugin-workflow-loop/README.zh-CN.md | 9 + .../plugin-workflow-loop/client.d.ts | 2 + .../@nocobase/plugin-workflow-loop/client.js | 1 + .../plugin-workflow-loop/package.json | 24 + .../plugin-workflow-loop/server.d.ts | 2 + .../@nocobase/plugin-workflow-loop/server.js | 1 + .../src/client/LoopInstruction.tsx} | 58 +- .../plugin-workflow-loop/src/client/index.ts | 19 + .../plugin-workflow-loop/src/index.ts | 2 + .../src/locale/en-US.json | 9 + .../plugin-workflow-loop/src/locale/index.ts | 12 + .../src/locale/zh-CN.json | 9 + .../src/server/LoopInstruction.ts} | 14 +- .../plugin-workflow-loop/src/server/Plugin.ts | 14 + .../src/server/__tests__/instruction.test.ts} | 151 +++- .../plugin-workflow-loop/src/server/index.ts | 1 + .../@nocobase/plugin-workflow-manual/LICENSE | 661 ++++++++++++++++++ .../plugin-workflow-manual/README.md | 9 + .../plugin-workflow-manual/README.zh-CN.md | 9 + .../plugin-workflow-manual/client.d.ts | 2 + .../plugin-workflow-manual/client.js | 1 + .../plugin-workflow-manual/package.json | 33 + .../plugin-workflow-manual/server.d.ts | 2 + .../plugin-workflow-manual/server.js | 1 + .../src/client}/WorkflowTodo.tsx | 30 +- .../client}/WorkflowTodoBlockInitializer.tsx | 0 .../src/client/index.ts | 42 ++ .../client/instruction}/AssigneesSelect.tsx | 4 +- .../instruction}/DetailsBlockProvider.tsx | 6 +- .../instruction}/FormBlockInitializer.tsx | 3 +- .../client/instruction}/FormBlockProvider.tsx | 0 .../src/client/instruction}/ModeConfig.tsx | 55 +- .../src/client/instruction}/SchemaConfig.tsx | 31 +- .../src/client/instruction}/forms/create.tsx | 0 .../src/client/instruction}/forms/custom.tsx | 10 +- .../src/client/instruction}/forms/update.tsx | 4 +- .../src/client/instruction}/index.tsx | 47 +- .../src/client/instruction}/utils.ts | 9 - .../plugin-workflow-manual/src/index.ts | 2 + .../src/locale/en-US.json | 30 + .../src/locale/index.ts | 12 + .../src/locale/zh-CN.json | 30 + .../src/server/ManualInstruction.ts} | 41 +- .../src/server/Plugin.ts | 48 ++ .../__tests__/collections/categories.ts | 12 - .../server/__tests__/collections/comments.ts | 0 .../src/server/__tests__/collections/posts.ts | 4 - .../server/__tests__/collections/replies.ts | 0 .../src/server/__tests__/collections/tags.ts | 0 .../src/server/__tests__/instruction.test.ts} | 8 +- .../src/server}/actions.ts | 7 +- .../src/server}/collecions/jobs.ts | 0 .../src/server}/collecions/users.ts | 0 .../src/server}/collecions/users_jobs.ts | 0 .../src/server}/forms/create.ts | 4 +- .../src/server}/forms/index.ts | 5 +- .../src/server}/forms/update.ts | 4 +- .../src/server/index.ts | 1 + .../plugin-workflow-parallel/LICENSE | 661 ++++++++++++++++++ .../plugin-workflow-parallel/README.md | 9 + .../plugin-workflow-parallel/README.zh-CN.md | 9 + .../plugin-workflow-parallel/client.d.ts | 2 + .../plugin-workflow-parallel/client.js | 1 + .../plugin-workflow-parallel/package.json | 25 + .../plugin-workflow-parallel/server.d.ts | 2 + .../plugin-workflow-parallel/server.js | 1 + .../src/client/ParallelInstruction.tsx} | 61 +- .../src/client/index.ts | 19 + .../plugin-workflow-parallel/src/index.ts | 2 + .../src/locale/en-US.json | 11 + .../src/locale/es-ES.json | 10 + .../src/locale/fr-FR.json | 10 + .../src/locale/index.ts | 12 + .../src/locale/ja-JP.json | 7 + .../src/locale/pt-BR.json | 10 + .../src/locale/ru-RU.json | 7 + .../src/locale/tr-TR.json | 7 + .../src/locale/zh-CN.json | 11 + .../src/server/ParallelInstruction.ts} | 12 +- .../src/server/Plugin.ts | 14 + .../src/server/__tests__/instruction.test.ts} | 129 +++- .../src/server/index.ts | 1 + .../@nocobase/plugin-workflow-request/LICENSE | 661 ++++++++++++++++++ .../plugin-workflow-request/README.md | 9 + .../plugin-workflow-request/README.zh-CN.md | 9 + .../plugin-workflow-request/client.d.ts | 2 + .../plugin-workflow-request/client.js | 1 + .../plugin-workflow-request/package.json | 24 + .../plugin-workflow-request/server.d.ts | 2 + .../plugin-workflow-request/server.js | 1 + .../src/client/RequestInstruction.tsx} | 30 +- .../src/client/index.ts | 19 + .../plugin-workflow-request/src/index.ts | 2 + .../src/locale/en-US.json | 20 + .../src/locale/es-ES.json | 19 + .../src/locale/fr-FR.json | 19 + .../src/locale/index.ts | 12 + .../src/locale/pt-BR.json | 19 + .../src/locale/zh-CN.json | 20 + .../src/server/Plugin.ts | 14 + .../src/server/RequestInstruction.ts} | 9 +- .../src/server/__tests__/instruction.test.ts} | 40 +- .../src/server/index.ts | 1 + .../@nocobase/plugin-workflow-sql/LICENSE | 661 ++++++++++++++++++ .../@nocobase/plugin-workflow-sql/README.md | 9 + .../plugin-workflow-sql/README.zh-CN.md | 9 + .../@nocobase/plugin-workflow-sql/client.d.ts | 2 + .../@nocobase/plugin-workflow-sql/client.js | 1 + .../plugin-workflow-sql/package.json | 24 + .../@nocobase/plugin-workflow-sql/server.d.ts | 2 + .../@nocobase/plugin-workflow-sql/server.js | 1 + .../src/client/SQLInstruction.tsx} | 28 +- .../plugin-workflow-sql/src/client/index.ts | 19 + .../plugin-workflow-sql/src/index.ts | 2 + .../plugin-workflow-sql/src/locale/en-US.json | 5 + .../plugin-workflow-sql/src/locale/index.ts | 12 + .../plugin-workflow-sql/src/locale/zh-CN.json | 5 + .../plugin-workflow-sql/src/server/Plugin.ts | 14 + .../src/server/SQLInstruction.ts} | 9 +- .../src/server/__tests__/instruction.test.ts} | 31 +- .../plugin-workflow-sql/src/server/index.ts | 1 + .../@nocobase/plugin-workflow-test/LICENSE | 661 ++++++++++++++++++ .../@nocobase/plugin-workflow-test/README.md | 9 + .../plugin-workflow-test/package.json | 17 + .../plugin-workflow-test/server.d.ts | 2 + .../@nocobase/plugin-workflow-test/server.js | 1 + .../plugin-workflow-test/src/client/index.ts | 0 .../plugin-workflow-test/src/index.ts | 2 + .../src/server/collections/categories.ts | 15 + .../src/server/collections/comments.ts | 24 + .../src/server/collections/posts.ts | 40 ++ .../src/server/collections/replies.ts | 9 + .../src/server/collections/tags.ts | 15 + .../src/server/functions.ts | 3 + .../plugin-workflow-test/src/server/index.ts | 78 +++ .../src/server/instructions.ts | 66 ++ .../@nocobase/plugin-workflow/package.json | 5 +- .../plugin-workflow/src/client/AddButton.tsx | 12 +- .../src/client/ExecutionCanvas.tsx | 12 +- ...{WorkflowProvider.tsx => WorkflowPane.tsx} | 32 +- .../components/CollectionBlockInitializer.tsx | 3 +- .../src/client/components/Duration.tsx | 54 -- .../src/client/components/NullRender.tsx | 3 - .../src/client/components/index.ts | 5 + .../hooks/useTriggerWorkflowActionProps.ts | 75 ++ .../plugin-workflow/src/client/index.tsx | 75 +- .../src/client/nodes/calculation.tsx | 131 +--- .../src/client/nodes/condition.tsx | 58 +- .../src/client/nodes/create.tsx | 33 +- .../src/client/nodes/delay.tsx | 37 - .../src/client/nodes/destroy.tsx | 26 +- .../src/client/nodes/index.tsx | 49 +- .../src/client/nodes/query.tsx | 33 +- .../src/client/nodes/update.tsx | 26 +- .../src/client/triggers/collection.tsx | 30 +- .../src/client/triggers/form.tsx | 165 ----- .../src/client/triggers/index.tsx | 41 +- .../src/client/triggers/schedule/index.tsx | 30 +- .../plugin-workflow/src/client/utils.ts | 9 + .../plugin-workflow/src/client/variable.tsx | 9 +- .../plugin-workflow/src/locale/en-US.json | 33 +- .../plugin-workflow/src/locale/es-ES.json | 33 +- .../plugin-workflow/src/locale/fr-FR.json | 33 +- .../plugin-workflow/src/locale/ja-JP.json | 5 - .../plugin-workflow/src/locale/pt-BR.json | 33 +- .../plugin-workflow/src/locale/ru-RU.json | 5 - .../plugin-workflow/src/locale/tr-TR.json | 5 - .../plugin-workflow/src/locale/zh-CN.json | 156 ++--- .../plugin-workflow/src/server/Plugin.ts | 47 +- .../plugin-workflow/src/server/Processor.ts | 2 +- .../src/server/__tests__/Plugin.test.ts | 2 +- .../src/server/__tests__/Processor.test.ts | 266 +------ .../__tests__/actions/executions.test.ts | 2 +- .../server/__tests__/actions/nodes.test.ts | 2 +- .../__tests__/actions/workflows.test.ts | 2 +- .../src/server/__tests__/index.ts | 97 --- .../instructions/calculation.test.ts | 77 +- .../__tests__/instructions/condition.test.ts | 107 ++- .../__tests__/instructions/create.test.ts | 2 +- .../__tests__/instructions/destroy.test.ts | 2 +- .../__tests__/instructions/query.test.ts | 2 +- .../__tests__/instructions/update.test.ts | 2 +- .../__tests__/triggers/collection.test.ts | 3 +- .../__tests__/triggers/schedule.test.ts | 2 +- .../src/server/fields/index.ts | 7 - .../plugin-workflow/src/server/index.ts | 2 +- ...lculation.ts => CalculationInstruction.ts} | 12 +- .../{condition.ts => ConditionInstruction.ts} | 12 +- .../{create.ts => CreateInstruction.ts} | 12 +- .../{destroy.ts => DestroyInstruction.ts} | 12 +- .../{query.ts => QueryInstruction.ts} | 11 +- .../{update.ts => UpdateInstruction.ts} | 11 +- .../src/server/instructions/index.ts | 55 +- .../20231122143143-split-to-plugins.ts | 72 ++ .../{collection.ts => CollectionTrigger.ts} | 2 +- .../{schedule.ts => ScheduleTrigger.ts} | 3 +- .../src/server/triggers/index.ts | 18 +- packages/presets/nocobase/package.json | 9 + packages/presets/nocobase/src/server/index.ts | 9 + 281 files changed, 10033 insertions(+), 1816 deletions(-) create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/LICENSE create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/README.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/README.zh-CN.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/client.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/client.js create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/package.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/server.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/server.js rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/aggregate.tsx => plugin-workflow-aggregate/src/client/AggregateInstruction.tsx} (86%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/src/client/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/src/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/src/locale/en-US.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/src/locale/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/src/locale/zh-CN.json rename packages/plugins/@nocobase/{plugin-workflow/src/server/instructions/aggregate.ts => plugin-workflow-aggregate/src/server/AggregateInstruction.ts} (88%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/Plugin.ts rename packages/plugins/@nocobase/{plugin-workflow/src/server/__tests__/instructions/aggregate.test.ts => plugin-workflow-aggregate/src/server/__tests__/instruction.test.ts} (97%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/LICENSE create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/README.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/README.zh-CN.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/client.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/client.js create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/package.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/server.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/server.js create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/src/client/DelayInstruction.tsx create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/src/client/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/src/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/src/locale/en-US.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/src/locale/es-ES.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/src/locale/fr-FR.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/src/locale/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/src/locale/pt-BR.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/src/locale/zh-CN.json rename packages/plugins/@nocobase/{plugin-workflow/src/server/instructions/delay.ts => plugin-workflow-delay/src/server/DelayInstruction.ts} (81%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/src/server/Plugin.ts rename packages/plugins/@nocobase/{plugin-workflow/src/server/__tests__/instructions/delay.test.ts => plugin-workflow-delay/src/server/__tests__/instruction.test.ts} (92%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-delay/src/server/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/LICENSE create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/README.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/README.zh-CN.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/client.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/client.js create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/package.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/server.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/server.js create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/client/DynamicCalculation.tsx rename packages/plugins/@nocobase/{plugin-workflow/src/client/components => plugin-workflow-dynamic-calculation/src/client}/DynamicExpression.tsx (96%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/client/Provider.tsx rename packages/plugins/@nocobase/{plugin-workflow/src/client/interfaces => plugin-workflow-dynamic-calculation/src/client}/expression.tsx (100%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/client/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/locale/en-US.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/locale/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/locale/zh-CN.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/server/DynamicCalculation.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/server/Plugin.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/server/__tests__/collections/categories.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/server/__tests__/instruction.test.ts rename packages/plugins/@nocobase/{plugin-workflow/src/server/fields => plugin-workflow-dynamic-calculation/src/server}/expression-field.ts (100%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-dynamic-calculation/src/server/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/LICENSE create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/README.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/README.zh-CN.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/client.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/client.js create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/package.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/server.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/server.js create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/src/client/FormTrigger.tsx create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/src/client/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/src/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/src/locale/en-US.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/src/locale/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/src/locale/zh-CN.json rename packages/plugins/@nocobase/{plugin-workflow/src/server/triggers/form.ts => plugin-workflow-form-trigger/src/server/FormTrigger.ts} (93%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/src/server/Plugin.ts rename packages/plugins/@nocobase/{plugin-workflow/src/server/__tests__/triggers/form.test.ts => plugin-workflow-form-trigger/src/server/__tests__/trigger.test.ts} (97%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-form-trigger/src/server/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/LICENSE create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/README.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/README.zh-CN.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/client.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/client.js create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/package.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/server.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/server.js rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/loop.tsx => plugin-workflow-loop/src/client/LoopInstruction.tsx} (74%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/src/client/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/src/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/src/locale/en-US.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/src/locale/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/src/locale/zh-CN.json rename packages/plugins/@nocobase/{plugin-workflow/src/server/instructions/loop.ts => plugin-workflow-loop/src/server/LoopInstruction.ts} (93%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/src/server/Plugin.ts rename packages/plugins/@nocobase/{plugin-workflow/src/server/__tests__/instructions/loop.test.ts => plugin-workflow-loop/src/server/__tests__/instruction.test.ts} (69%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-loop/src/server/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/LICENSE create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/README.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/README.zh-CN.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/client.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/client.js create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/package.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/server.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/server.js rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/manual => plugin-workflow-manual/src/client}/WorkflowTodo.tsx (95%) rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/manual => plugin-workflow-manual/src/client}/WorkflowTodoBlockInitializer.tsx (100%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/src/client/index.ts rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/manual => plugin-workflow-manual/src/client/instruction}/AssigneesSelect.tsx (91%) rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/manual => plugin-workflow-manual/src/client/instruction}/DetailsBlockProvider.tsx (91%) rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/manual => plugin-workflow-manual/src/client/instruction}/FormBlockInitializer.tsx (96%) rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/manual => plugin-workflow-manual/src/client/instruction}/FormBlockProvider.tsx (100%) rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/manual => plugin-workflow-manual/src/client/instruction}/ModeConfig.tsx (51%) rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/manual => plugin-workflow-manual/src/client/instruction}/SchemaConfig.tsx (95%) rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/manual => plugin-workflow-manual/src/client/instruction}/forms/create.tsx (100%) rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/manual => plugin-workflow-manual/src/client/instruction}/forms/custom.tsx (98%) rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/manual => plugin-workflow-manual/src/client/instruction}/forms/update.tsx (98%) rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/manual => plugin-workflow-manual/src/client/instruction}/index.tsx (81%) rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/manual => plugin-workflow-manual/src/client/instruction}/utils.ts (66%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/src/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/src/locale/en-US.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/src/locale/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/src/locale/zh-CN.json rename packages/plugins/@nocobase/{plugin-workflow/src/server/instructions/manual/index.ts => plugin-workflow-manual/src/server/ManualInstruction.ts} (78%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/src/server/Plugin.ts rename packages/plugins/@nocobase/{plugin-workflow => plugin-workflow-manual}/src/server/__tests__/collections/categories.ts (58%) rename packages/plugins/@nocobase/{plugin-workflow => plugin-workflow-manual}/src/server/__tests__/collections/comments.ts (100%) rename packages/plugins/@nocobase/{plugin-workflow => plugin-workflow-manual}/src/server/__tests__/collections/posts.ts (91%) rename packages/plugins/@nocobase/{plugin-workflow => plugin-workflow-manual}/src/server/__tests__/collections/replies.ts (100%) rename packages/plugins/@nocobase/{plugin-workflow => plugin-workflow-manual}/src/server/__tests__/collections/tags.ts (100%) rename packages/plugins/@nocobase/{plugin-workflow/src/server/__tests__/instructions/manual.test.ts => plugin-workflow-manual/src/server/__tests__/instruction.test.ts} (99%) rename packages/plugins/@nocobase/{plugin-workflow/src/server/instructions/manual => plugin-workflow-manual/src/server}/actions.ts (92%) rename packages/plugins/@nocobase/{plugin-workflow/src/server/instructions/manual => plugin-workflow-manual/src/server}/collecions/jobs.ts (100%) rename packages/plugins/@nocobase/{plugin-workflow/src/server/instructions/manual => plugin-workflow-manual/src/server}/collecions/users.ts (100%) rename packages/plugins/@nocobase/{plugin-workflow/src/server/instructions/manual => plugin-workflow-manual/src/server}/collecions/users_jobs.ts (100%) rename packages/plugins/@nocobase/{plugin-workflow/src/server/instructions/manual => plugin-workflow-manual/src/server}/forms/create.ts (85%) rename packages/plugins/@nocobase/{plugin-workflow/src/server/instructions/manual => plugin-workflow-manual/src/server}/forms/index.ts (73%) rename packages/plugins/@nocobase/{plugin-workflow/src/server/instructions/manual => plugin-workflow-manual/src/server}/forms/update.ts (86%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-manual/src/server/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/LICENSE create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/README.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/README.zh-CN.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/client.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/client.js create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/package.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/server.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/server.js rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/parallel.tsx => plugin-workflow-parallel/src/client/ParallelInstruction.tsx} (81%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/src/client/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/src/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/src/locale/en-US.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/src/locale/es-ES.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/src/locale/fr-FR.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/src/locale/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/src/locale/ja-JP.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/src/locale/pt-BR.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/src/locale/ru-RU.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/src/locale/tr-TR.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/src/locale/zh-CN.json rename packages/plugins/@nocobase/{plugin-workflow/src/server/instructions/parallel.ts => plugin-workflow-parallel/src/server/ParallelInstruction.ts} (95%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/src/server/Plugin.ts rename packages/plugins/@nocobase/{plugin-workflow/src/server/__tests__/instructions/parallel.test.ts => plugin-workflow-parallel/src/server/__tests__/instruction.test.ts} (77%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-parallel/src/server/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/LICENSE create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/README.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/README.zh-CN.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/client.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/client.js create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/package.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/server.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/server.js rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/request.tsx => plugin-workflow-request/src/client/RequestInstruction.tsx} (91%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/src/client/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/src/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/src/locale/en-US.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/src/locale/es-ES.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/src/locale/fr-FR.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/src/locale/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/src/locale/pt-BR.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/src/locale/zh-CN.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/src/server/Plugin.ts rename packages/plugins/@nocobase/{plugin-workflow/src/server/instructions/request.ts => plugin-workflow-request/src/server/RequestInstruction.ts} (89%) rename packages/plugins/@nocobase/{plugin-workflow/src/server/__tests__/instructions/request.test.ts => plugin-workflow-request/src/server/__tests__/instruction.test.ts} (88%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-request/src/server/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/LICENSE create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/README.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/README.zh-CN.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/client.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/client.js create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/package.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/server.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/server.js rename packages/plugins/@nocobase/{plugin-workflow/src/client/nodes/sql.tsx => plugin-workflow-sql/src/client/SQLInstruction.tsx} (67%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/src/client/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/src/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/src/locale/en-US.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/src/locale/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/src/locale/zh-CN.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/src/server/Plugin.ts rename packages/plugins/@nocobase/{plugin-workflow/src/server/instructions/sql.ts => plugin-workflow-sql/src/server/SQLInstruction.ts} (79%) rename packages/plugins/@nocobase/{plugin-workflow/src/server/__tests__/instructions/sql.test.ts => plugin-workflow-sql/src/server/__tests__/instruction.test.ts} (88%) create mode 100644 packages/plugins/@nocobase/plugin-workflow-sql/src/server/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/LICENSE create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/README.md create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/package.json create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/server.d.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/server.js create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/src/client/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/src/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/src/server/collections/categories.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/src/server/collections/comments.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/src/server/collections/posts.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/src/server/collections/replies.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/src/server/collections/tags.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/src/server/functions.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/src/server/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow-test/src/server/instructions.ts rename packages/plugins/@nocobase/plugin-workflow/src/client/{WorkflowProvider.tsx => WorkflowPane.tsx} (51%) delete mode 100644 packages/plugins/@nocobase/plugin-workflow/src/client/components/Duration.tsx delete mode 100644 packages/plugins/@nocobase/plugin-workflow/src/client/components/NullRender.tsx create mode 100644 packages/plugins/@nocobase/plugin-workflow/src/client/components/index.ts create mode 100644 packages/plugins/@nocobase/plugin-workflow/src/client/hooks/useTriggerWorkflowActionProps.ts delete mode 100644 packages/plugins/@nocobase/plugin-workflow/src/client/nodes/delay.tsx delete mode 100644 packages/plugins/@nocobase/plugin-workflow/src/client/triggers/form.tsx delete mode 100644 packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/index.ts delete mode 100644 packages/plugins/@nocobase/plugin-workflow/src/server/fields/index.ts rename packages/plugins/@nocobase/plugin-workflow/src/server/instructions/{calculation.ts => CalculationInstruction.ts} (85%) rename packages/plugins/@nocobase/plugin-workflow/src/server/instructions/{condition.ts => ConditionInstruction.ts} (96%) rename packages/plugins/@nocobase/plugin-workflow/src/server/instructions/{create.ts => CreateInstruction.ts} (82%) rename packages/plugins/@nocobase/plugin-workflow/src/server/instructions/{destroy.ts => DestroyInstruction.ts} (70%) rename packages/plugins/@nocobase/plugin-workflow/src/server/instructions/{query.ts => QueryInstruction.ts} (90%) rename packages/plugins/@nocobase/plugin-workflow/src/server/instructions/{update.ts => UpdateInstruction.ts} (78%) create mode 100644 packages/plugins/@nocobase/plugin-workflow/src/server/migrations/20231122143143-split-to-plugins.ts rename packages/plugins/@nocobase/plugin-workflow/src/server/triggers/{collection.ts => CollectionTrigger.ts} (99%) rename packages/plugins/@nocobase/plugin-workflow/src/server/triggers/{schedule.ts => ScheduleTrigger.ts} (99%) diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/LICENSE b/packages/plugins/@nocobase/plugin-workflow-aggregate/LICENSE new file mode 100644 index 000000000..0ad25db4b --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/README.md b/packages/plugins/@nocobase/plugin-workflow-aggregate/README.md new file mode 100644 index 000000000..e83d0373a --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/README.md @@ -0,0 +1,9 @@ +# workflow + +English | [中文](./README.zh-CN.md) + +## 安装激活 + +内置插件无需手动安装激活。 + +## 使用方法 diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/README.zh-CN.md b/packages/plugins/@nocobase/plugin-workflow-aggregate/README.zh-CN.md new file mode 100644 index 000000000..e690848dd --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/README.zh-CN.md @@ -0,0 +1,9 @@ +# workflow + +[English](./README.md) | 中文 + +## 安装激活 + +内置插件无需手动安装激活。 + +## 使用方法 diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/client.d.ts b/packages/plugins/@nocobase/plugin-workflow-aggregate/client.d.ts new file mode 100644 index 000000000..6c459cbac --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/client.d.ts @@ -0,0 +1,2 @@ +export * from './dist/client'; +export { default } from './dist/client'; diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/client.js b/packages/plugins/@nocobase/plugin-workflow-aggregate/client.js new file mode 100644 index 000000000..b6e3be70e --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/client.js @@ -0,0 +1 @@ +module.exports = require('./dist/client/index.js'); diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/package.json b/packages/plugins/@nocobase/plugin-workflow-aggregate/package.json new file mode 100644 index 000000000..1cc040d3e --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/package.json @@ -0,0 +1,24 @@ +{ + "name": "@nocobase/plugin-workflow-aggregate", + "displayName": "Workflow: Aggregate node", + "displayName.zh-CN": "工作流:聚合查询节点", + "description": "Used to aggregate data against the database in workflow, such as: statistics, sum, average, etc.", + "description.zh-CN": "可用于在工作流中对数据库进行聚合查询,如:统计数量、求和、平均值等。", + "version": "0.17.0-alpha.3", + "license": "AGPL-3.0", + "main": "./dist/server/index.js", + "devDependencies": { + "antd": "5.x", + "react": "18.x", + "react-i18next": "^11.15.1" + }, + "peerDependencies": { + "@nocobase/client": "0.x", + "@nocobase/database": "0.x", + "@nocobase/plugin-workflow": ">=0.17.0-alpha.3", + "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", + "@nocobase/server": "0.x", + "@nocobase/test": "0.x" + }, + "gitHead": "ce588eefb0bfc50f7d5bbee575e0b5e843bf6644" +} diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/server.d.ts b/packages/plugins/@nocobase/plugin-workflow-aggregate/server.d.ts new file mode 100644 index 000000000..c41081ddc --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/server.d.ts @@ -0,0 +1,2 @@ +export * from './dist/server'; +export { default } from './dist/server'; diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/server.js b/packages/plugins/@nocobase/plugin-workflow-aggregate/server.js new file mode 100644 index 000000000..972842039 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/server.js @@ -0,0 +1 @@ +module.exports = require('./dist/server/index.js'); diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/aggregate.tsx b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/client/AggregateInstruction.tsx similarity index 86% rename from packages/plugins/@nocobase/plugin-workflow/src/client/nodes/aggregate.tsx rename to packages/plugins/@nocobase/plugin-workflow-aggregate/src/client/AggregateInstruction.tsx index 0b4f725e5..11bf256a3 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/aggregate.tsx +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/client/AggregateInstruction.tsx @@ -5,17 +5,25 @@ import React, { useCallback, useEffect, useState } from 'react'; import { SchemaComponentContext, SchemaInitializerItemType, + css, useCollectionDataSource, + useCollectionFilterOptions, useCollectionManager, useCompile, } from '@nocobase/client'; -import { FieldsSelect } from '../components/FieldsSelect'; -import { FilterDynamicComponent } from '../components/FilterDynamicComponent'; -import { ValueBlock } from '../components/ValueBlock'; -import { NAMESPACE, lang } from '../locale'; -import { collection, filter } from '../schemas/collection'; -import { BaseTypeSets, defaultFieldNames, nodesOptions, triggerOptions } from '../variable'; +import { + FieldsSelect, + FilterDynamicComponent, + ValueBlock, + BaseTypeSets, + defaultFieldNames, + nodesOptions, + triggerOptions, + Instruction, +} from '@nocobase/plugin-workflow/client'; + +import { NAMESPACE, useLang } from '../locale'; function matchToManyField(field): boolean { // const fieldPrefix = `${field.name}.`; @@ -136,12 +144,12 @@ function AssociatedConfig({ value, onChange, ...props }): JSX.Element { // { key: '{{$context.data.id}}', collection: "collection.association", field } // select data based -export default { - title: `{{t("Aggregate", { ns: "${NAMESPACE}" })}}`, - type: 'aggregate', - group: 'collection', - description: `{{t("Counting, summing, finding maximum, minimum, and average values for multiple records of a collection or associated data of a record.", { ns: "${NAMESPACE}" })}}`, - fieldset: { +export default class extends Instruction { + title = `{{t("Aggregate", { ns: "${NAMESPACE}" })}}`; + type = 'aggregate'; + group = 'collection'; + description = `{{t("Counting, summing, finding maximum, minimum, and average values for multiple records of a collection or associated data of a record.", { ns: "${NAMESPACE}" })}}`; + fieldset = { aggregator: { type: 'string', title: `{{t("Aggregator function", { ns: "${NAMESPACE}" })}}`, @@ -206,14 +214,12 @@ export default { 'x-component': 'Grid.Col', properties: { collection: { - ...collection, + type: 'string', + required: true, + 'x-decorator': 'FormItem', + 'x-component': 'CollectionSelect', title: `{{t("Data of collection", { ns: "${NAMESPACE}" })}}`, - 'x-component-props': { - ...collection['x-component-props'], - className: null, - }, 'x-reactions': [ - ...collection['x-reactions'], { dependencies: ['associated'], fulfill: { @@ -320,7 +326,24 @@ export default { ], }, filter: { - ...filter, + type: 'object', + title: '{{t("Filter")}}', + 'x-decorator': 'FormItem', + 'x-component': 'Filter', + 'x-component-props': { + useProps() { + const { values } = useForm(); + const options = useCollectionFilterOptions(values?.collection); + return { + options, + className: css` + position: relative; + width: 100%; + `, + }; + }, + dynamicComponent: 'FilterDynamicComponent', + }, 'x-reactions': [ { dependencies: ['collection'], @@ -334,18 +357,17 @@ export default { }, }, }, - }, - view: {}, - scope: { + }; + scope = { useCollectionDataSource, - }, - components: { + }; + components = { SchemaComponentContext, FilterDynamicComponent, FieldsSelect, ValueBlock, AssociatedConfig, - }, + }; useVariables({ key, title }, { types, fieldNames = defaultFieldNames }) { if ( types && @@ -357,19 +379,21 @@ export default { [fieldNames.value]: key, [fieldNames.label]: title, }; - }, + } useInitializers(node): SchemaInitializerItemType | null { + // eslint-disable-next-line react-hooks/rules-of-hooks + const resultTitle = useLang('Query result'); if (!node.config.collection) { return null; } return { - name: node.title ?? `#${node.id}`, + name: `#${node.id}`, type: 'item', title: node.title ?? `#${node.id}`, Component: ValueBlock.Initializer, node, - resultTitle: lang('Query result'), + resultTitle, }; - }, -}; + } +} diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/src/client/index.ts b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/client/index.ts new file mode 100644 index 000000000..b39b536de --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/client/index.ts @@ -0,0 +1,19 @@ +import { Plugin } from '@nocobase/client'; +import WorkflowPlugin from '@nocobase/plugin-workflow/client'; + +import AggregateInstruction from './AggregateInstruction'; + +export default class extends Plugin { + async afterAdd() { + // await this.app.pm.add() + } + + async beforeLoad() {} + + // You can get and modify the app instance here + async load() { + const workflow = this.app.pm.get('workflow') as WorkflowPlugin; + const aggregateInstruction = new AggregateInstruction(); + workflow.instructions.register(aggregateInstruction.type, aggregateInstruction); + } +} diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/src/index.ts b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/index.ts new file mode 100644 index 000000000..7e74612df --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/index.ts @@ -0,0 +1,2 @@ +export * from './server'; +export { default } from './server'; diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/src/locale/en-US.json b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/locale/en-US.json new file mode 100644 index 000000000..ea7c9f855 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/locale/en-US.json @@ -0,0 +1,12 @@ +{ + "Aggregate": "Aggregate", + "Counting, summing, finding maximum, minimum, and average values for multiple records of a collection or associated data of a record.": + "Counting, summing, finding maximum, minimum, and average values for multiple records of a collection or associated data of a record.", + "Aggregator function": "Aggregator function", + "Target type": "Target type", + "Data of collection": "Data of collection", + "Data of associated collection": "Data of associated collection", + "Field to aggregate": "Field to aggregate", + "Distinct": "Distinct", + "Query result": "Query result" +} diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/src/locale/index.ts b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/locale/index.ts new file mode 100644 index 000000000..4c2c1a3e9 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/locale/index.ts @@ -0,0 +1,12 @@ +import { useTranslation } from 'react-i18next'; + +export const NAMESPACE = 'workflow-aggregate'; + +export function useLang(key: string, options = {}) { + const { t } = usePluginTranslation(options); + return t(key); +} + +export function usePluginTranslation(options) { + return useTranslation(NAMESPACE, options); +} diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/src/locale/zh-CN.json b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/locale/zh-CN.json new file mode 100644 index 000000000..f3b9df436 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/locale/zh-CN.json @@ -0,0 +1,12 @@ +{ + "Aggregate": "聚合查询", + "Counting, summing, finding maximum, minimum, and average values for multiple records of a collection or associated data of a record.": + "对一个数据表里的多条数据或者一条数据里的关系数据进行统计、求和、求最大值、最小值、平均值。", + "Aggregator function": "聚合函数", + "Target type": "目标类型", + "Data of collection": "数据表数据", + "Data of associated collection": "关联数据表数据", + "Field to aggregate": "聚合字段", + "Distinct": "去重", + "Query result": "查询结果" +} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/aggregate.ts b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/AggregateInstruction.ts similarity index 88% rename from packages/plugins/@nocobase/plugin-workflow/src/server/instructions/aggregate.ts rename to packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/AggregateInstruction.ts index 42c8d6178..4f3e7f486 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/aggregate.ts +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/AggregateInstruction.ts @@ -1,8 +1,5 @@ import { BelongsToManyRepository, DataTypes, HasManyRepository } from '@nocobase/database'; - -import Processor from '../Processor'; -import { JOB_STATUS } from '../constants'; -import type { FlowNodeModel } from '../types'; +import { Processor, Instruction, JOB_STATUS, FlowNodeModel } from '@nocobase/plugin-workflow'; const aggregators = { count: 'count', @@ -12,7 +9,7 @@ const aggregators = { max: 'max', }; -export default { +export default class extends Instruction { async run(node: FlowNodeModel, input, processor: Processor) { const { aggregator, associated, collection, association = {}, params = {} } = node.config; const options = processor.getParsedValue(params, node.id); @@ -38,5 +35,5 @@ export default { result: options.dataType === DataTypes.DOUBLE ? Number(result) : result, status: JOB_STATUS.RESOLVED, }; - }, -}; + } +} diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/Plugin.ts b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/Plugin.ts new file mode 100644 index 000000000..2cde92f57 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/Plugin.ts @@ -0,0 +1,14 @@ +import { Plugin } from '@nocobase/server'; +import WorkflowPlugin from '@nocobase/plugin-workflow'; + +import AggregateInstruction from './AggregateInstruction'; + +export default class extends Plugin { + workflow: WorkflowPlugin; + + async load() { + const workflowPlugin = this.app.getPlugin('workflow') as WorkflowPlugin; + this.workflow = workflowPlugin; + workflowPlugin.instructions.register('aggregate', new AggregateInstruction(workflowPlugin)); + } +} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/aggregate.test.ts b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/__tests__/instruction.test.ts similarity index 97% rename from packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/aggregate.test.ts rename to packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/__tests__/instruction.test.ts index 5b67c9523..3bb1efe94 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/aggregate.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/__tests__/instruction.test.ts @@ -1,6 +1,8 @@ -import { Application } from '@nocobase/server'; import Database from '@nocobase/database'; -import { getApp, sleep } from '..'; +import { Application } from '@nocobase/server'; +import { getApp, sleep } from '@nocobase/plugin-workflow-test'; + +import Plugin from '..'; describe('workflow > instructions > aggregate', () => { let app: Application; @@ -12,16 +14,18 @@ describe('workflow > instructions > aggregate', () => { let workflow; beforeEach(async () => { - app = await getApp(); + app = await getApp({ + plugins: [Plugin], + }); db = app.db; WorkflowModel = db.getCollection('workflows').model; + WorkflowModel = db.getCollection('workflows').model; PostRepo = db.getCollection('posts').repository; CommentRepo = db.getCollection('comments').repository; TagRepo = db.getCollection('tags').repository; workflow = await WorkflowModel.create({ - title: 'test workflow', enabled: true, type: 'collection', config: { diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/index.ts b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/index.ts new file mode 100644 index 000000000..3b60b3bee --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/index.ts @@ -0,0 +1 @@ +export { default } from './Plugin'; diff --git a/packages/plugins/@nocobase/plugin-workflow-delay/LICENSE b/packages/plugins/@nocobase/plugin-workflow-delay/LICENSE new file mode 100644 index 000000000..0ad25db4b --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-delay/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/packages/plugins/@nocobase/plugin-workflow-delay/README.md b/packages/plugins/@nocobase/plugin-workflow-delay/README.md new file mode 100644 index 000000000..e83d0373a --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-delay/README.md @@ -0,0 +1,9 @@ +# workflow + +English | [中文](./README.zh-CN.md) + +## 安装激活 + +内置插件无需手动安装激活。 + +## 使用方法 diff --git a/packages/plugins/@nocobase/plugin-workflow-delay/README.zh-CN.md b/packages/plugins/@nocobase/plugin-workflow-delay/README.zh-CN.md new file mode 100644 index 000000000..e690848dd --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-delay/README.zh-CN.md @@ -0,0 +1,9 @@ +# workflow + +[English](./README.md) | 中文 + +## 安装激活 + +内置插件无需手动安装激活。 + +## 使用方法 diff --git a/packages/plugins/@nocobase/plugin-workflow-delay/client.d.ts b/packages/plugins/@nocobase/plugin-workflow-delay/client.d.ts new file mode 100644 index 000000000..6c459cbac --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-delay/client.d.ts @@ -0,0 +1,2 @@ +export * from './dist/client'; +export { default } from './dist/client'; diff --git a/packages/plugins/@nocobase/plugin-workflow-delay/client.js b/packages/plugins/@nocobase/plugin-workflow-delay/client.js new file mode 100644 index 000000000..b6e3be70e --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-delay/client.js @@ -0,0 +1 @@ +module.exports = require('./dist/client/index.js'); diff --git a/packages/plugins/@nocobase/plugin-workflow-delay/package.json b/packages/plugins/@nocobase/plugin-workflow-delay/package.json new file mode 100644 index 000000000..51a1bdd3c --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-delay/package.json @@ -0,0 +1,24 @@ +{ + "name": "@nocobase/plugin-workflow-delay", + "displayName": "Workflow: Delay node", + "displayName.zh-CN": "工作流:延时节点", + "description": "Could be used in workflow parallel branch for waiting other branches.", + "description.zh-CN": "可用于工作流并行分支中等待其他分支执行完成。", + "version": "0.17.0-alpha.3", + "license": "AGPL-3.0", + "main": "./dist/server/index.js", + "devDependencies": { + "antd": "5.x", + "react": "18.x", + "react-i18next": "^11.15.1" + }, + "peerDependencies": { + "@nocobase/client": "0.x", + "@nocobase/database": "0.x", + "@nocobase/plugin-workflow": ">=0.17.0-alpha.3", + "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3", + "@nocobase/server": "0.x", + "@nocobase/test": "0.x" + }, + "gitHead": "ce588eefb0bfc50f7d5bbee575e0b5e843bf6644" +} diff --git a/packages/plugins/@nocobase/plugin-workflow-delay/server.d.ts b/packages/plugins/@nocobase/plugin-workflow-delay/server.d.ts new file mode 100644 index 000000000..c41081ddc --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-delay/server.d.ts @@ -0,0 +1,2 @@ +export * from './dist/server'; +export { default } from './dist/server'; diff --git a/packages/plugins/@nocobase/plugin-workflow-delay/server.js b/packages/plugins/@nocobase/plugin-workflow-delay/server.js new file mode 100644 index 000000000..972842039 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-delay/server.js @@ -0,0 +1 @@ +module.exports = require('./dist/server/index.js'); diff --git a/packages/plugins/@nocobase/plugin-workflow-delay/src/client/DelayInstruction.tsx b/packages/plugins/@nocobase/plugin-workflow-delay/src/client/DelayInstruction.tsx new file mode 100644 index 000000000..a6eb137e5 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow-delay/src/client/DelayInstruction.tsx @@ -0,0 +1,87 @@ +import React from 'react'; +import { InputNumber, Select } from 'antd'; +import { css, useCompile } from '@nocobase/client'; +import { Instruction, JOB_STATUS } from '@nocobase/plugin-workflow/client'; + +import { NAMESPACE } from '../locale'; + +const UnitOptions = [ + { value: 1_000, label: `{{t('Seconds', { ns: "workflow" })}}` }, + { value: 60_000, label: `{{t('Minutes', { ns: "workflow" })}}` }, + { value: 3600_000, label: `{{t('Hours', { ns: "workflow" })}}` }, + { value: 86400_000, label: `{{t('Days', { ns: "workflow" })}}` }, + { value: 604800_000, label: `{{t('Weeks', { ns: "workflow" })}}` }, +]; + +function getNumberOption(v) { + return UnitOptions.slice() + .reverse() + .find((item) => !(v % item.value)); +} + +function Duration({ value = 60000, onChange }) { + const compile = useCompile(); + const option = getNumberOption(value); + const quantity = Math.round(value / option.value); + + return ( +
+ onChange(Math.round(v * option.value))} + className="auto-width" + /> + onChange(Math.round(quantity * unit))} - className="auto-width" - > - {UnitOptions.map((item) => ( - - {lang(item.label)} - - ))} - -
- ); -} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/components/NullRender.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/components/NullRender.tsx deleted file mode 100644 index 27d621412..000000000 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/components/NullRender.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export function NullRender() { - return null; -} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/components/index.ts b/packages/plugins/@nocobase/plugin-workflow/src/client/components/index.ts new file mode 100644 index 000000000..3190699da --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/components/index.ts @@ -0,0 +1,5 @@ +export * from './CollectionBlockInitializer'; +export * from './FieldsSelect'; +export * from './FilterDynamicComponent'; +export * from './RadioWithTooltip'; +export * from './ValueBlock'; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/hooks/useTriggerWorkflowActionProps.ts b/packages/plugins/@nocobase/plugin-workflow/src/client/hooks/useTriggerWorkflowActionProps.ts new file mode 100644 index 000000000..5849622fa --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/hooks/useTriggerWorkflowActionProps.ts @@ -0,0 +1,75 @@ +import { useNavigate } from 'react-router-dom'; +import { App, message } from 'antd'; +import { useField, useFieldSchema, useForm } from '@formily/react'; + +import { + useAPIClient, + useActionContext, + useBlockRequestContext, + useCollectValuesToSubmit, + useCompile, +} from '@nocobase/client'; +import { isURL } from '@nocobase/utils/client'; + +export function useTriggerWorkflowsActionProps() { + const api = useAPIClient(); + const form = useForm(); + const { field, __parent } = useBlockRequestContext(); + const { setVisible } = useActionContext(); + const navigate = useNavigate(); + const actionSchema = useFieldSchema(); + const actionField = useField(); + const compile = useCompile(); + const { modal } = App.useApp(); + const collectValues = useCollectValuesToSubmit(); + + const filterKeys = actionField.componentProps.filterKeys || []; + + return { + async onClick() { + const { onSuccess, skipValidator, triggerWorkflows } = actionSchema?.['x-action-settings'] ?? {}; + if (!skipValidator) { + await form.submit(); + } + const values = await collectValues(); + actionField.data = field.data || {}; + actionField.data.loading = true; + try { + const data = await api.resource('workflows').trigger({ + values, + filterKeys: filterKeys, + // TODO(refactor): should change to inject by plugin + triggerWorkflows: triggerWorkflows?.length + ? triggerWorkflows.map((row) => [row.workflowKey, row.context].filter(Boolean).join('!')).join(',') + : undefined, + }); + actionField.data.loading = false; + actionField.data.data = data; + __parent?.service?.refresh?.(); + setVisible?.(false); + if (!onSuccess?.successMessage) { + return; + } + if (onSuccess?.manualClose) { + modal.success({ + title: compile(onSuccess?.successMessage), + onOk: async () => { + await form.reset(); + if (onSuccess?.redirecting && onSuccess?.redirectTo) { + if (isURL(onSuccess.redirectTo)) { + window.location.href = onSuccess.redirectTo; + } else { + navigate(onSuccess.redirectTo); + } + } + }, + }); + } else { + message.success(compile(onSuccess?.successMessage)); + } + } catch (error) { + actionField.data.loading = false; + } + }, + }; +} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/index.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/index.tsx index e4aa2dba2..a03e59b28 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/index.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/index.tsx @@ -2,38 +2,53 @@ export * from './Branch'; export * from './FlowContext'; export * from './constants'; export * from './nodes'; +export { Trigger, useTrigger } from './triggers'; +export * from './variable'; +export * from './components'; +export * from './utils'; +export * from './hooks/useGetAriaLabelOfAddButton'; export { default as useStyles } from './style'; -export { getTriggersOptions, triggers, useTrigger } from './triggers'; export * from './variable'; export { getCollectionFieldOptions, useWorkflowVariableOptions } from './variable'; -import { Plugin } from '@nocobase/client'; import React from 'react'; + +import { Plugin } from '@nocobase/client'; +import { Registry } from '@nocobase/utils/client'; + import { ExecutionPage } from './ExecutionPage'; import { WorkflowPage } from './WorkflowPage'; -import { WorkflowPane, WorkflowProvider } from './WorkflowProvider'; -import { DynamicExpression } from './components/DynamicExpression'; -import { instructions } from './nodes'; -import { addActionButton, addBlockButton } from './nodes/manual/SchemaConfig'; -import { WorkflowTodo } from './nodes/manual/WorkflowTodo'; -import { WorkflowTodoBlockInitializer } from './nodes/manual/WorkflowTodoBlockInitializer'; -import { addCustomFormField } from './nodes/manual/forms/custom'; -import { getTriggersOptions, triggers } from './triggers'; -import { useTriggerWorkflowsActionProps } from './triggers/form'; -import { NAMESPACE } from './locale'; +import { WorkflowPane } from './WorkflowPane'; +import { Trigger } from './triggers'; +import CollectionTrigger from './triggers/collection'; +import ScheduleTrigger from './triggers/schedule'; +import { Instruction } from './nodes'; +import CalculationInstruction from './nodes/calculation'; +import ConditionInstruction from './nodes/condition'; +import QueryInstruction from './nodes/query'; +import CreateInstruction from './nodes/create'; +import UpdateInstruction from './nodes/update'; +import DestroyInstruction from './nodes/destroy'; +import { useTriggerWorkflowsActionProps } from './hooks/useTriggerWorkflowActionProps'; import { getWorkflowDetailPath, getWorkflowExecutionsPath } from './constant'; +import { NAMESPACE } from './locale'; -export class WorkflowPlugin extends Plugin { - triggers = triggers; - getTriggersOptions = getTriggersOptions; - instructions = instructions; +export default class extends Plugin { + triggers = new Registry(); + instructions = new Registry(); + getTriggersOptions = () => { + return Array.from(this.triggers.getEntities()).map(([value, { title, ...options }]) => ({ + value, + label: title, + color: 'gold', + options, + })); + }; async load() { this.addRoutes(); this.addScopes(); this.addComponents(); - this.app.addProvider(WorkflowProvider); - this.addSchemaInitializers(); this.app.pluginSettingsManager.add(NAMESPACE, { icon: 'PartitionOutlined', @@ -41,19 +56,16 @@ export class WorkflowPlugin extends Plugin { Component: WorkflowPane, aclSnippet: 'pm.workflow.workflows', }); - } - addSchemaInitializers() { - this.app.schemaInitializerManager.add(addBlockButton); - this.app.schemaInitializerManager.add(addActionButton); - this.app.schemaInitializerManager.add(addCustomFormField); + this.triggers.register('collection', new CollectionTrigger()); + this.triggers.register('schedule', new ScheduleTrigger()); - const blockInitializers = this.app.schemaInitializerManager.get('BlockInitializers'); - blockInitializers.add('otherBlocks.workflowTodos', { - title: `{{t("Workflow todos", { ns: "${NAMESPACE}" })}}`, - Component: 'WorkflowTodoBlockInitializer', - icon: 'CheckSquareOutlined', - }); + this.instructions.register('calculation', new CalculationInstruction()); + this.instructions.register('condition', new ConditionInstruction()); + this.instructions.register('query', new QueryInstruction()); + this.instructions.register('create', new CreateInstruction()); + this.instructions.register('update', new UpdateInstruction()); + this.instructions.register('destroy', new DestroyInstruction()); } addScopes() { @@ -66,9 +78,6 @@ export class WorkflowPlugin extends Plugin { this.app.addComponents({ WorkflowPage, ExecutionPage, - WorkflowTodo, - WorkflowTodoBlockInitializer, - DynamicExpression, }); } @@ -83,5 +92,3 @@ export class WorkflowPlugin extends Plugin { }); } } - -export default WorkflowPlugin; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/calculation.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/calculation.tsx index 54aa4e9f4..dcf4d9ab1 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/calculation.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/calculation.tsx @@ -1,75 +1,19 @@ -import { FormItem, FormLayout } from '@formily/antd-v5'; -import { SchemaInitializerItemType, Variable, defaultFieldNames, useCollectionManager } from '@nocobase/client'; +import { SchemaInitializerItemType, defaultFieldNames } from '@nocobase/client'; import { Evaluator, evaluators, getOptions } from '@nocobase/evaluators/client'; -import { Radio } from 'antd'; -import React from 'react'; -import { useTranslation } from 'react-i18next'; + import { RadioWithTooltip } from '../components/RadioWithTooltip'; import { ValueBlock } from '../components/ValueBlock'; import { renderEngineReference } from '../components/renderEngineReference'; import { NAMESPACE, lang } from '../locale'; -import { BaseTypeSets, WorkflowVariableInput, WorkflowVariableTextArea, useWorkflowVariableOptions } from '../variable'; +import { BaseTypeSets, WorkflowVariableTextArea } from '../variable'; +import { Instruction } from '.'; -function useDynamicExpressionCollectionFieldMatcher(field): boolean { - if (!['belongsTo', 'hasOne'].includes(field.type)) { - return false; - } - - if (this.getCollection(field.collectionName)?.template === 'expression') { - return true; - } - - const fields = this.getCollectionFields(field.target); - return fields.some((f) => f.interface === 'expression'); -} - -const DynamicConfig = ({ value, onChange }) => { - const { t } = useTranslation(); - const { getCollectionFields, getCollection } = useCollectionManager(); - const scope = useWorkflowVariableOptions({ - types: [useDynamicExpressionCollectionFieldMatcher.bind({ getCollectionFields, getCollection })], - }); - - return ( - - - { - onChange(ev.target.value); - }} - > - {t('Static', { ns: NAMESPACE })} - {t('Dynamic', { ns: NAMESPACE })} - - - {value !== false ? ( - - onChange(v)} scope={scope} /> - - ) : null} - - ); -}; - -export default { - title: `{{t("Calculation", { ns: "${NAMESPACE}" })}}`, - type: 'calculation', - group: 'control', - description: `{{t("Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression. The expression can be static or dynamic one from an expression collections.", { ns: "${NAMESPACE}" })}}`, - fieldset: { - dynamic: { - type: 'string', - 'x-component': 'DynamicConfig', - // description: `{{t("Select the dynamic expression queried from the upstream node. You need to query it from an expression collection.", { ns: "${NAMESPACE}" })}}`, - default: false, - }, +export default class extends Instruction { + title = `{{t("Calculation", { ns: "${NAMESPACE}" })}}`; + type = 'calculation'; + group = 'control'; + description = `{{t("Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression.", { ns: "${NAMESPACE}" })}}`; + fieldset = { engine: { type: 'string', title: `{{t("Calculation engine", { ns: "${NAMESPACE}" })}}`, @@ -80,14 +24,6 @@ export default { }, required: true, default: 'math.js', - 'x-reactions': { - dependencies: ['dynamic'], - fulfill: { - state: { - visible: '{{$deps[0] === false}}', - }, - }, - }, }, expression: { type: 'string', @@ -109,14 +45,6 @@ export default { } }, 'x-reactions': [ - { - dependencies: ['dynamic'], - fulfill: { - state: { - visible: '{{$deps[0] === false}}', - }, - }, - }, { dependencies: ['engine'], fulfill: { @@ -128,38 +56,15 @@ export default { ], required: true, }, - scope: { - type: 'string', - title: `{{t("Variable datasource", { ns: "${NAMESPACE}" })}}`, - 'x-decorator': 'FormItem', - 'x-component': 'WorkflowVariableInput', - 'x-component-props': { - changeOnSelect: true, - variableOptions: { - types: [{ type: 'reference', options: { collection: '*', entity: true } }], - }, - }, - 'x-reactions': { - dependencies: ['dynamic'], - fulfill: { - state: { - visible: '{{$deps[0]}}', - }, - }, - }, - }, - }, - view: {}, - scope: { + }; + scope = { renderEngineReference, - }, - components: { - WorkflowVariableInput, + }; + components = { WorkflowVariableTextArea, RadioWithTooltip, - DynamicConfig, ValueBlock, - }, + }; useVariables({ key, title }, { types, fieldNames = defaultFieldNames }) { if ( types && @@ -171,7 +76,7 @@ export default { [fieldNames.value]: key, [fieldNames.label]: title, }; - }, + } useInitializers(node): SchemaInitializerItemType { return { name: node.title ?? `#${node.id}`, @@ -181,5 +86,5 @@ export default { node, resultTitle: lang('Calculation result'), }; - }, -}; + } +} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/condition.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/condition.tsx index cc129cb6c..b40331d8e 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/condition.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/condition.tsx @@ -5,14 +5,14 @@ import { Registry } from '@nocobase/utils/client'; import { Button, Select } from 'antd'; import React from 'react'; import { Trans, useTranslation } from 'react-i18next'; -import { NodeDefaultView } from '.'; +import { Instruction, NodeDefaultView } from '.'; import { Branch } from '../Branch'; import { RadioWithTooltip, RadioWithTooltipOption } from '../components/RadioWithTooltip'; import { renderEngineReference } from '../components/renderEngineReference'; import { useFlowContext } from '../FlowContext'; import { lang, NAMESPACE } from '../locale'; import useStyles from '../style'; -import { useWorkflowVariableOptions } from '../variable'; +import { useWorkflowVariableOptions, WorkflowVariableTextArea } from '../variable'; interface Calculator { name: string; @@ -321,12 +321,12 @@ function CalculationConfig({ value, onChange }) { return onChange({ ...rule, group })} />; } -export default { - title: `{{t("Condition", { ns: "${NAMESPACE}" })}}`, - type: 'condition', - group: 'control', - description: `{{t('Based on boolean result of the calculation to determine whether to "continue" or "exit" the process, or continue on different branches of "yes" and "no".', { ns: "${NAMESPACE}" })}}`, - fieldset: { +export default class extends Instruction { + title = `{{t("Condition", { ns: "${NAMESPACE}" })}}`; + type = 'condition'; + group = 'control'; + description = `{{t('Based on boolean result of the calculation to determine whether to "continue" or "exit" the process, or continue on different branches of "yes" and "no".', { ns: "${NAMESPACE}" })}}`; + fieldset = { rejectOnFalse: { type: 'boolean', title: `{{t("Mode", { ns: "${NAMESPACE}" })}}`, @@ -379,7 +379,7 @@ export default { type: 'string', title: `{{t("Condition expression", { ns: "${NAMESPACE}" })}}`, 'x-decorator': 'FormItem', - 'x-component': 'CalculationExpression', + 'x-component': 'WorkflowVariableTextArea', ['x-validator'](value, rules, { form }) { const { values } = form; const { evaluate } = evaluators.get(values.engine); @@ -404,9 +404,8 @@ export default { }, required: true, }, - }, - view: {}, - options: [ + }; + options = [ { label: `{{t('Continue when "Yes"', { ns: "${NAMESPACE}" })}}`, key: 'rejectOnFalse', @@ -417,10 +416,24 @@ export default { key: 'branch', value: { rejectOnFalse: false }, }, - ], - component: function Component({ data }) { + ]; + + scope = { + renderEngineReference, + useWorkflowVariableOptions, + }; + components = { + CalculationConfig, + WorkflowVariableTextArea, + RadioWithTooltip, + }; + + Component({ data }) { + // eslint-disable-next-line react-hooks/rules-of-hooks const { t } = useTranslation(); + // eslint-disable-next-line react-hooks/rules-of-hooks const { nodes } = useFlowContext(); + // eslint-disable-next-line react-hooks/rules-of-hooks const { styles } = useStyles(); const { id, @@ -444,18 +457,5 @@ export default { )} ); - }, - scope: { - renderEngineReference, - useWorkflowVariableOptions, - }, - components: { - CalculationConfig, - CalculationExpression(props) { - const scope = useWorkflowVariableOptions(); - - return ; - }, - RadioWithTooltip, - }, -}; + } +} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/create.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/create.tsx index 19a100b2f..58189bb0a 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/create.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/create.tsx @@ -5,13 +5,14 @@ import CollectionFieldset from '../components/CollectionFieldset'; import { NAMESPACE } from '../locale'; import { appends, collection, values } from '../schemas/collection'; import { getCollectionFieldOptions } from '../variable'; +import { Instruction } from '.'; -export default { - title: `{{t("Create record", { ns: "${NAMESPACE}" })}}`, - type: 'create', - group: 'collection', - description: `{{t("Add new record to a collection. You can use variables from upstream nodes to assign values to fields.", { ns: "${NAMESPACE}" })}}`, - fieldset: { +export default class extends Instruction { + title = `{{t("Create record", { ns: "${NAMESPACE}" })}}`; + type = 'create'; + group = 'collection'; + description = `{{t("Add new record to a collection. You can use variables from upstream nodes to assign values to fields.", { ns: "${NAMESPACE}" })}}`; + fieldset = { collection, // multiple: { // type: 'boolean', @@ -30,16 +31,17 @@ export default { appends, }, }, - }, - view: {}, - scope: { + }; + scope = { useCollectionDataSource, - }, - components: { + }; + components = { CollectionFieldset, - }, + }; useVariables({ key: name, title, 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(); // const depth = config?.params?.appends?.length // ? config?.params?.appends.reduce((max, item) => Math.max(max, item.split('.').length), 1) @@ -65,7 +67,7 @@ export default { }); return result; - }, + } useInitializers(node): SchemaInitializerItemType | null { if (!node.config.collection) { return null; @@ -79,6 +81,5 @@ export default { collection: node.config.collection, dataSource: `{{$jobsMapByNodeKey.${node.key}}}`, }; - }, - initializers: {}, -}; + } +} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/delay.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/delay.tsx deleted file mode 100644 index cfd3331d6..000000000 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/delay.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import Duration from '../components/Duration'; -import { JOB_STATUS } from '../constants'; -import { NAMESPACE } from '../locale'; - -export default { - title: `{{t("Delay", { ns: "${NAMESPACE}" })}}`, - type: 'delay', - group: 'control', - description: `{{t("Delay a period of time and then continue or exit the process. Can be used to set wait or timeout times in parallel branches.", { ns: "${NAMESPACE}" })}}`, - fieldset: { - duration: { - type: 'number', - title: `{{t("Duration", { ns: "${NAMESPACE}" })}}`, - 'x-decorator': 'FormItem', - 'x-component': 'Duration', - default: 60000, - required: true, - }, - endStatus: { - type: 'number', - title: `{{t("End Status", { ns: "${NAMESPACE}" })}}`, - 'x-decorator': 'FormItem', - 'x-component': 'Radio.Group', - enum: [ - { label: `{{t("Succeed and continue", { ns: "${NAMESPACE}" })}}`, value: JOB_STATUS.RESOLVED }, - { label: `{{t("Fail and exit", { ns: "${NAMESPACE}" })}}`, value: JOB_STATUS.FAILED }, - ], - required: true, - default: JOB_STATUS.RESOLVED, - }, - }, - view: {}, - scope: {}, - components: { - Duration, - }, -}; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/destroy.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/destroy.tsx index 08655ea4d..37ab758cf 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/destroy.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/destroy.tsx @@ -3,14 +3,15 @@ import { useCollectionDataSource } from '@nocobase/client'; import { FilterDynamicComponent } from '../components/FilterDynamicComponent'; import { collection, filter } from '../schemas/collection'; import { isValidFilter } from '../utils'; +import { Instruction } from '.'; import { NAMESPACE, lang } from '../locale'; -export default { - title: '{{t("Delete record")}}', - type: 'destroy', - group: 'collection', - description: `{{t("Delete records of a collection. Could use variables in workflow context as filter. All records match the filter will be deleted.", { ns: "${NAMESPACE}" })}}`, - fieldset: { +export default class extends Instruction { + title = '{{t("Delete record")}}'; + type = 'destroy'; + group = 'collection'; + description = `{{t("Delete records of a collection. Could use variables in workflow context as filter. All records match the filter will be deleted.", { ns: "${NAMESPACE}" })}}`; + fieldset = { collection, params: { type: 'object', @@ -23,12 +24,11 @@ export default { }, }, }, - }, - view: {}, - scope: { + }; + scope = { useCollectionDataSource, - }, - components: { + }; + components = { FilterDynamicComponent, - }, -}; + }; +} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/index.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/index.tsx index 493ab70fa..24b026a3c 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/index.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/index.tsx @@ -16,10 +16,12 @@ import { useAPIClient, useActionContext, useCompile, + usePlugin, useResourceActionContext, } from '@nocobase/client'; -import { Registry, parse, str2moment } from '@nocobase/utils/client'; +import { parse, str2moment } from '@nocobase/utils/client'; +import WorkflowPlugin from '..'; import { AddButton } from '../AddButton'; import { useFlowContext } from '../FlowContext'; import { DrawerDescription } from '../components/DrawerDescription'; @@ -30,21 +32,7 @@ import { lang } from '../locale'; import useStyles from '../style'; import { VariableOption, VariableOptions } from '../variable'; -import aggregate from './aggregate'; -import calculation from './calculation'; -import condition from './condition'; -import create from './create'; -import delay from './delay'; -import destroy from './destroy'; -import loop from './loop'; -import manual from './manual'; -import parallel from './parallel'; -import query from './query'; -import request from './request'; -import sql from './sql'; -import update from './update'; - -export interface Instruction { +export abstract class Instruction { title: string; type: string; group: string; @@ -54,33 +42,13 @@ export interface Instruction { view?: ISchema; scope?: { [key: string]: any }; components?: { [key: string]: any }; - component?(props): JSX.Element; + Component?(props): JSX.Element; useVariables?(node, options?): VariableOption; useScopeVariables?(node, options?): VariableOptions; useInitializers?(node): SchemaInitializerItemType | null; - initializers?: { [key: string]: any }; isAvailable?(ctx: object): boolean; } -export const instructions = new Registry(); - -instructions.register('calculation', calculation); -instructions.register('condition', condition); -instructions.register('parallel', parallel); -instructions.register('loop', loop); -instructions.register('delay', delay); - -instructions.register('manual', manual); - -instructions.register('query', query); -instructions.register('create', create); -instructions.register('update', update); -instructions.register('destroy', destroy); -instructions.register('aggregate', aggregate); - -instructions.register('request', request); -instructions.register('sql', sql); - function useUpdateAction() { const form = useForm(); const api = useAPIClient(); @@ -144,7 +112,8 @@ export function useUpstreamScopes(node) { export function Node({ data }) { const { styles } = useStyles(); const { getAriaLabel } = useGetAriaLabelOfAddButton(data); - const { component: Component = NodeDefaultView } = instructions.get(data.type); + const workflowPlugin = usePlugin(WorkflowPlugin); + const { Component = NodeDefaultView } = workflowPlugin.instructions.get(data.type); return ( @@ -284,8 +253,8 @@ export function NodeDefaultView(props) { const api = useAPIClient(); const { workflow, refresh } = useFlowContext() ?? {}; const { styles } = useStyles(); - - const instruction = instructions.get(data.type); + const workflowPlugin = usePlugin(WorkflowPlugin); + const instruction = workflowPlugin.instructions.get(data.type); const detailText = workflow.executed ? '{{t("View")}}' : '{{t("Configure")}}'; const typeTitle = compile(instruction.title); diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/query.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/query.tsx index de481e49a..d02f6036c 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/query.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/query.tsx @@ -14,13 +14,14 @@ import { FilterDynamicComponent } from '../components/FilterDynamicComponent'; import { NAMESPACE } from '../locale'; import { appends, collection, filter, pagination, sort } from '../schemas/collection'; import { WorkflowVariableInput, getCollectionFieldOptions } from '../variable'; +import { Instruction } from '.'; -export default { - title: `{{t("Query record", { ns: "${NAMESPACE}" })}}`, - type: 'query', - group: 'collection', - description: `{{t("Query records from a collection. You can use variables from upstream nodes as query conditions.", { ns: "${NAMESPACE}" })}}`, - fieldset: { +export default class extends Instruction { + title = `{{t("Query record", { ns: "${NAMESPACE}" })}}`; + type = 'query'; + group = 'collection'; + description = `{{t("Query records from a collection. You can use variables from upstream nodes as query conditions.", { ns: "${NAMESPACE}" })}}`; + fieldset = { collection, multiple: { type: 'boolean', @@ -55,9 +56,8 @@ export default { 'x-component': 'Checkbox', 'x-content': `{{t("Exit when query result is null", { ns: "${NAMESPACE}" })}}`, }, - }, - view: {}, - scope: { + }; + scope = { useCollectionDataSource, useSortableFields() { const compile = useCompile(); @@ -82,15 +82,17 @@ export default { }; }); }, - }, - components: { + }; + components = { ArrayItems, FilterDynamicComponent, SchemaComponentContext, WorkflowVariableInput, - }, + }; useVariables({ key: name, title, 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(); // const depth = config?.params?.appends?.length // ? config?.params?.appends.reduce((max, item) => Math.max(max, item.split('.').length), 1) @@ -116,7 +118,7 @@ export default { }); return result; - }, + } useInitializers(node): SchemaInitializerItemType | null { if (!node.config.collection || node.config.multiple) { return null; @@ -130,6 +132,5 @@ export default { collection: node.config.collection, dataSource: `{{$jobsMapByNodeKey.${node.key}}}`, }; - }, - initializers: {}, -}; + } +} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/update.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/update.tsx index 1e12cec33..df5c0c290 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/update.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/update.tsx @@ -10,6 +10,7 @@ import { RadioWithTooltip } from '../components/RadioWithTooltip'; import { NAMESPACE, lang } from '../locale'; import { collection, filter, values } from '../schemas/collection'; import { isValidFilter } from '../utils'; +import { Instruction } from '.'; function IndividualHooksRadioWithTooltip({ onChange, ...props }) { const { getCollectionFields } = useCollectionManager(); @@ -39,12 +40,12 @@ function IndividualHooksRadioWithTooltip({ onChange, ...props }) { return ; } -export default { - title: `{{t("Update record", { ns: "${NAMESPACE}" })}}`, - type: 'update', - group: 'collection', - description: `{{t("Update records of a collection. You can use variables from upstream nodes as query conditions and field values.", { ns: "${NAMESPACE}" })}}`, - fieldset: { +export default class extends Instruction { + title = `{{t("Update record", { ns: "${NAMESPACE}" })}}`; + type = 'update'; + group = 'collection'; + description = `{{t("Update records of a collection. You can use variables from upstream nodes as query conditions and field values.", { ns: "${NAMESPACE}" })}}`; + fieldset = { collection, params: { type: 'object', @@ -87,14 +88,13 @@ export default { }, }, }, - }, - view: {}, - scope: { + }; + scope = { useCollectionDataSource, - }, - components: { + }; + components = { FilterDynamicComponent, CollectionFieldset, IndividualHooksRadioWithTooltip, - }, -}; + }; +} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/collection.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/collection.tsx index 6e3da9a09..1f1aecbc5 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/collection.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/collection.tsx @@ -4,6 +4,7 @@ import { FieldsSelect } from '../components/FieldsSelect'; import { NAMESPACE, lang } from '../locale'; import { appends, collection, filter } from '../schemas/collection'; import { getCollectionFieldOptions } from '../variable'; +import { Trigger } from '.'; const COLLECTION_TRIGGER_MODE = { CREATED: 1, @@ -19,11 +20,11 @@ const collectionModeOptions = [ { label: `{{t("After record deleted", { ns: "${NAMESPACE}" })}}`, value: COLLECTION_TRIGGER_MODE.DELETED }, ]; -export default { - title: `{{t("Collection event", { ns: "${NAMESPACE}" })}}`, - type: 'collection', - description: `{{t("Event will be triggered on collection data row created, updated or deleted.", { ns: "${NAMESPACE}" })}}`, - fieldset: { +export default class extends Trigger { + title = `{{t("Collection event", { ns: "${NAMESPACE}" })}}`; + type = 'collection'; + description = `{{t("Event will be triggered on collection data row created, updated or deleted.", { ns: "${NAMESPACE}" })}}`; + fieldset = { collection: { ...collection, ['x-reactions']: [ @@ -139,15 +140,17 @@ export default { }, ], }, - }, - scope: { + }; + scope = { useCollectionDataSource, - }, - components: { + }; + components = { FieldsSelect, - }, + }; 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(); const rootFields = [ { @@ -172,7 +175,7 @@ export default { getCollectionFields, }); return result; - }, + } useInitializers(config): SchemaInitializerItemType | null { if (!config.collection) { return null; @@ -187,6 +190,5 @@ export default { collection: config.collection, dataSource: '{{$context.data}}', }; - }, - initializers: {}, -}; + } +} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/form.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/form.tsx deleted file mode 100644 index 97a2abd78..000000000 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/form.tsx +++ /dev/null @@ -1,165 +0,0 @@ -import { useField, useFieldSchema, useForm } from '@formily/react'; -import { - SchemaInitializerItemType, - useAPIClient, - useActionContext, - useBlockRequestContext, - useCollectValuesToSubmit, - useCollectionDataSource, - useCollectionManager, - useCompile, -} from '@nocobase/client'; -import { isURL, parse } from '@nocobase/utils/client'; -import { App, message } from 'antd'; -import omit from 'lodash/omit'; -import { useNavigate } from 'react-router-dom'; -import { CollectionBlockInitializer } from '../components/CollectionBlockInitializer'; -import { NAMESPACE, lang } from '../locale'; -import { appends, collection } from '../schemas/collection'; -import { getCollectionFieldOptions } from '../variable'; - -export default { - title: `{{t("Form event", { ns: "${NAMESPACE}" })}}`, - type: 'form', - description: `{{t("Event triggers when submitted a workflow bound form action.", { ns: "${NAMESPACE}" })}}`, - fieldset: { - collection: { - ...collection, - title: `{{t("Form data model", { ns: "${NAMESPACE}" })}}`, - description: `{{t("Use a collection to match form data.", { ns: "${NAMESPACE}" })}}`, - ['x-reactions']: [ - ...collection['x-reactions'], - { - target: 'appends', - effects: ['onFieldValueChange'], - fulfill: { - state: { - value: [], - }, - }, - }, - ], - }, - appends: { - ...appends, - title: `{{t("Associations to use", { ns: "${NAMESPACE}" })}}`, - }, - }, - scope: { - useCollectionDataSource, - }, - components: {}, - useVariables(config, options) { - const compile = useCompile(); - const { getCollectionFields } = useCollectionManager(); - const rootFields = [ - { - collectionName: config.collection, - name: 'data', - type: 'hasOne', - target: config.collection, - uiSchema: { - title: lang('Trigger data'), - }, - }, - { - collectionName: 'users', - name: 'user', - type: 'hasOne', - target: 'users', - uiSchema: { - title: lang('User submitted form'), - }, - }, - ]; - 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, - dataSource: '{{$context.data}}', - }; - }, - initializers: {}, - useActionTriggerable: true, -}; - -export function useTriggerWorkflowsActionProps() { - const api = useAPIClient(); - const form = useForm(); - const { field, __parent } = useBlockRequestContext(); - const { setVisible } = useActionContext(); - const navigate = useNavigate(); - const actionSchema = useFieldSchema(); - const actionField = useField(); - const compile = useCompile(); - const { modal } = App.useApp(); - const collectValues = useCollectValuesToSubmit(); - - const filterKeys = actionField.componentProps.filterKeys || []; - - return { - async onClick() { - const { onSuccess, skipValidator, triggerWorkflows } = actionSchema?.['x-action-settings'] ?? {}; - if (!skipValidator) { - await form.submit(); - } - const values = await collectValues(); - actionField.data = field.data || {}; - actionField.data.loading = true; - try { - const data = await api.resource('workflows').trigger({ - values, - filterKeys: filterKeys, - // TODO(refactor): should change to inject by plugin - triggerWorkflows: triggerWorkflows?.length - ? triggerWorkflows.map((row) => [row.workflowKey, row.context].filter(Boolean).join('!')).join(',') - : undefined, - }); - actionField.data.loading = false; - actionField.data.data = data; - __parent?.service?.refresh?.(); - setVisible?.(false); - if (!onSuccess?.successMessage) { - return; - } - if (onSuccess?.manualClose) { - modal.success({ - title: compile(onSuccess?.successMessage), - onOk: async () => { - await form.reset(); - if (onSuccess?.redirecting && onSuccess?.redirectTo) { - if (isURL(onSuccess.redirectTo)) { - window.location.href = onSuccess.redirectTo; - } else { - navigate(onSuccess.redirectTo); - } - } - }, - }); - } else { - message.success(compile(onSuccess?.successMessage)); - } - } catch (error) { - actionField.data.loading = false; - } - }, - }; -} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/index.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/index.tsx index 06e835bf6..a655a45e6 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/index.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/index.tsx @@ -1,6 +1,10 @@ +import React, { useCallback, useEffect, useMemo, useState } from 'react'; +import { Button, Input, Tag, message } from 'antd'; +import { cloneDeep } from 'lodash'; import { InfoOutlined } from '@ant-design/icons'; import { createForm } from '@formily/core'; import { ISchema, useForm } from '@formily/react'; + import { ActionContextProvider, FormProvider, @@ -11,20 +15,16 @@ import { useAPIClient, useActionContext, useCompile, + usePlugin, useResourceActionContext, } from '@nocobase/client'; -import { Registry } from '@nocobase/utils/client'; -import { Button, Input, Tag, message } from 'antd'; -import { cloneDeep } from 'lodash'; -import React, { useCallback, useEffect, useMemo, useState } from 'react'; + +import WorkflowPlugin from '..'; import { useFlowContext } from '../FlowContext'; import { DrawerDescription } from '../components/DrawerDescription'; import { NAMESPACE, lang } from '../locale'; import useStyles from '../style'; import { VariableOptions } from '../variable'; -import collection from './collection'; -import formTrigger from './form'; -import schedule from './schedule/'; function useUpdateConfigAction() { const form = useForm(); @@ -52,7 +52,7 @@ function useUpdateConfigAction() { }; } -export interface Trigger { +export abstract class Trigger { title: string; type: string; description?: string; @@ -67,23 +67,16 @@ export interface Trigger { useActionTriggerable?: boolean | (() => boolean); } -export const triggers = new Registry(); - -triggers.register(formTrigger.type, formTrigger); -triggers.register(collection.type, collection); -triggers.register(schedule.type, schedule); - function TriggerExecution() { const compile = useCompile(); const { workflow, execution } = useFlowContext(); const { styles } = useStyles(); + const trigger = useTrigger(); if (!execution) { return null; } - const trigger = triggers.get(workflow.type); - return ( { const [formValueChanged, setFormValueChanged] = useState(false); const { styles } = useStyles(); const compile = useCompile(); + const trigger = useTrigger(); - const { title, type, executed } = workflow; - const trigger = triggers.get(type); + const { title, executed } = workflow; const typeTitle = compile(trigger.title); const { fieldset, scope, components } = trigger; const detailText = executed ? '{{t("View")}}' : '{{t("Configure")}}'; @@ -341,15 +334,7 @@ export const TriggerConfig = () => { }; export function useTrigger() { + const workflowPlugin = usePlugin(WorkflowPlugin); const { workflow } = useFlowContext(); - return triggers.get(workflow.type); -} - -export function getTriggersOptions() { - return Array.from(triggers.getEntities()).map(([value, { title, ...options }]) => ({ - value, - label: title, - color: 'gold', - options, - })); + return workflowPlugin.triggers.get(workflow.type); } diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/schedule/index.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/schedule/index.tsx index b142d52ec..8fd6f1618 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/schedule/index.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/triggers/schedule/index.tsx @@ -3,28 +3,31 @@ import { SchemaInitializerItemType, useCollectionDataSource, useCollectionManage import { CollectionBlockInitializer } from '../../components/CollectionBlockInitializer'; import { NAMESPACE, lang } from '../../locale'; import { getCollectionFieldOptions } from '../../variable'; +import { Trigger } from '..'; import { ScheduleConfig } from './ScheduleConfig'; import { SCHEDULE_MODE } from './constants'; -export default { - title: `{{t("Schedule event", { ns: "${NAMESPACE}" })}}`, - type: 'schedule', - description: `{{t("Event will be scheduled and triggered base on time conditions.", { ns: "${NAMESPACE}" })}}`, - fieldset: { +export default class extends Trigger { + title = `{{t("Schedule event", { ns: "${NAMESPACE}" })}}`; + type = 'schedule'; + description = `{{t("Event will be scheduled and triggered base on time conditions.", { ns: "${NAMESPACE}" })}}`; + fieldset = { config: { type: 'void', 'x-component': 'ScheduleConfig', 'x-component-props': {}, }, - }, - scope: { + }; + scope = { useCollectionDataSource, - }, - components: { + }; + components = { ScheduleConfig, - }, + }; useVariables(config, opts) { + // eslint-disable-next-line react-hooks/rules-of-hooks const compile = useCompile(); + // eslint-disable-next-line react-hooks/rules-of-hooks const { getCollectionFields } = useCollectionManager(); const options: any[] = []; if (!opts?.types || opts.types.includes('date')) { @@ -59,7 +62,7 @@ export default { } } return options; - }, + } useInitializers(config): SchemaInitializerItemType | null { if (!config.collection) { return null; @@ -73,6 +76,5 @@ export default { collection: config.collection, dataSource: '{{$context.data}}', }; - }, - initializers: {}, -}; + } +} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/utils.ts b/packages/plugins/@nocobase/plugin-workflow/src/client/utils.ts index 80b71c321..1f6a9743b 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/utils.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/utils.ts @@ -34,3 +34,12 @@ export function isValidFilter(condition) { return true; }); } + +export function traverseSchema(schema, fn) { + fn(schema); + if (schema.properties) { + Object.keys(schema.properties).forEach((key) => { + traverseSchema(schema.properties[key], fn); + }); + } +} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx index e57f7a891..680b5621d 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/variable.tsx @@ -1,11 +1,11 @@ import React from 'react'; -import { Variable, useCompile } from '@nocobase/client'; +import { Variable, useCompile, usePlugin } from '@nocobase/client'; import { useFlowContext } from './FlowContext'; import { NAMESPACE, lang } from './locale'; -import { instructions, useAvailableUpstreams, useNodeContext, useUpstreamScopes } from './nodes'; -import { triggers } from './triggers'; +import { useAvailableUpstreams, useNodeContext, useUpstreamScopes } from './nodes'; +import WorkflowPlugin from '.'; export type VariableOption = { key?: string; @@ -43,6 +43,7 @@ export const nodesOptions = { label: `{{t("Node result", { ns: "${NAMESPACE}" })}}`, value: '$jobsMapByNodeKey', useOptions(options: OptionsOfUseVariableOptions) { + const { instructions } = usePlugin(WorkflowPlugin); const current = useNodeContext(); const upstreams = useAvailableUpstreams(current); const result: VariableOption[] = []; @@ -61,6 +62,7 @@ export const triggerOptions = { label: `{{t("Trigger variables", { ns: "${NAMESPACE}" })}}`, value: '$context', useOptions(options: OptionsOfUseVariableOptions) { + const { triggers } = usePlugin(WorkflowPlugin); const { workflow } = useFlowContext(); const trigger = triggers.get(workflow.type); return trigger?.useVariables?.(workflow.config, options) ?? null; @@ -72,6 +74,7 @@ export const scopeOptions = { value: '$scopes', useOptions(options: OptionsOfUseVariableOptions) { const { fieldNames = defaultFieldNames, current } = options; + const { instructions } = usePlugin(WorkflowPlugin); const source = useNodeContext(); const from = current ?? source; const scopes = useUpstreamScopes(from); diff --git a/packages/plugins/@nocobase/plugin-workflow/src/locale/en-US.json b/packages/plugins/@nocobase/plugin-workflow/src/locale/en-US.json index 470de82e9..27ef21b6d 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/locale/en-US.json +++ b/packages/plugins/@nocobase/plugin-workflow/src/locale/en-US.json @@ -84,20 +84,6 @@ "Continue when \"Yes\"": "Continue when \"Yes\"", "Branch into \"Yes\" and \"No\"": "Branch into \"Yes\" and \"No\"", "Conditions": "Conditions", - "Parallel branch": "Parallel branch", - "Add branch": "Add branch", - "All succeeded": "All succeeded", - "Any succeeded": "Any succeeded", - "Any succeeded or failed": "Any succeeded or failed", - "Continue after all branches succeeded": "Continue after all branches succeeded", - "Continue after any branch succeeded": "Continue after any branch succeeded", - "Continue after any branch succeeded, or exit after any branch failed": "Continue after any branch succeeded, or exit after any branch failed", - "Delay": "Delay", - "Duration": "Duration", - "End Status": "End Status", - "Select status": "Select status", - "Succeed and continue": "Succeed and continue", - "Fail and exit": "Fail and exit", "Create record": "Create record", "Update record": "Update record", "Query record": "Query record", @@ -108,22 +94,5 @@ "Trigger in executed workflow cannot be modified": "Trigger in executed workflow cannot be modified", "Node in executed workflow cannot be modified": "Node in executed workflow cannot be modified", "Can not delete": "Can not delete", - "The result of this node has been referenced by other nodes ({{nodes}}), please remove the usage before deleting.": "The result of this node has been referenced by other nodes ({{nodes}}), please remove the usage before deleting.", - "HTTP request": "HTTP request", - "HTTP method": "HTTP method", - "URL": "URL", - "Headers": "Headers", - "Add request header": "Add request header", - "Parameters": "Parameters", - "Add parameter": "Add parameter", - "Body": "Body", - "Use variable": "Use variable", - "Format": "Format", - "Insert": "Insert", - "Timeout config": "Timeout config", - "ms": "ms", - "Input request data": "Input request data", - "Only support standard JSON data": "Only support standard JSON data", - "\"Content-Type\" only support \"application/json\", and no need to specify": "\"Content-Type\" only support \"application/json\", and no need to specify", - "Ignore fail request and continue workflow": "Ignore fail request and continue workflow" + "The result of this node has been referenced by other nodes ({{nodes}}), please remove the usage before deleting.": "The result of this node has been referenced by other nodes ({{nodes}}), please remove the usage before deleting." } diff --git a/packages/plugins/@nocobase/plugin-workflow/src/locale/es-ES.json b/packages/plugins/@nocobase/plugin-workflow/src/locale/es-ES.json index b3c948a1e..fddb324d6 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/locale/es-ES.json +++ b/packages/plugins/@nocobase/plugin-workflow/src/locale/es-ES.json @@ -84,20 +84,6 @@ "Continue when \"Yes\"": "Continuar cuando \"Sí\"", "Branch into \"Yes\" and \"No\"": "Ramificarse en \"Sí\" y \"No\"", "Conditions": "Condiciones", - "Parallel branch": "Rama paralela", - "Add branch": "Añadir rama", - "All succeeded": "Todo correcto", - "Any succeeded": "Cualquiera con éxito", - "Any succeeded or failed": "Cualquiera tuvo éxito o falló", - "Continue after all branches succeeded": "Continuar después que todas las ramas han tenido éxito", - "Continue after any branch succeeded": "Continuar después que cualquier rama tenga éxito", - "Continue after any branch succeeded, or exit after any branch failed": "Continuar después de que cualquier rama tenga éxito, o salir después de que cualquier rama falle", - "Delay": "Retraso", - "Duration": "Duración", - "End Status": "Estado Final", - "Select status": "Seleccionar estado", - "Succeed and continue": "Éxito y continuar", - "Fail and exit": "Falla y sale", "Create record": "Crear registro", "Update record": "Actualizar registro", "Query record": "Consultar registro", @@ -108,22 +94,5 @@ "Trigger in executed workflow cannot be modified": "No se puede modificar el desencadenante en el flujo de trabajo ejecutado", "Node in executed workflow cannot be modified": "Nodo en flujo de trabajo ejecutado no puede ser modificado", "Can not delete": "No se puede eliminar", - "The result of this node has been referenced by other nodes ({{nodes}}), please remove the usage before deleting.": "El resultado de este nodo ha sido referenciado por otros nodos ({{nodes}}", - "HTTP request": "Petición HTTP", - "HTTP method": "Método HTTP", - "URL": "URL", - "Headers": "Encabezados", - "Add request header": "Añadir encabezado de petición", - "Parameters": "Parámetros", - "Add parameter": "Añadir parámetro", - "Body": "Cuerpo", - "Use variable": "Utilizar variable", - "Format": "Formato", - "Insert": "Insertar", - "Timeout config": "Tiempo de espera config", - "ms": "ms", - "Input request data": "Datos de solicitud de entrada", - "Only support standard JSON data": "Sólo admite datos JSON estándar", - "\"Content-Type\" only support \"application/json\", and no need to specify": "\"Content-Type\" sólo admite \"application/json\", y no es necesario especificar", - "Ignore fail request and continue workflow": "Ignorar solicitud fallida y continuar flujo de trabajo" + "The result of this node has been referenced by other nodes ({{nodes}}), please remove the usage before deleting.": "El resultado de este nodo ha sido referenciado por otros nodos ({{nodes}}" } diff --git a/packages/plugins/@nocobase/plugin-workflow/src/locale/fr-FR.json b/packages/plugins/@nocobase/plugin-workflow/src/locale/fr-FR.json index 2d34c45aa..e38a851f3 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/locale/fr-FR.json +++ b/packages/plugins/@nocobase/plugin-workflow/src/locale/fr-FR.json @@ -84,20 +84,6 @@ "Continue when \"Yes\"": "Continuer quand \"Oui\"", "Branch into \"Yes\" and \"No\"": "Brancher sur \"Oui\" et \"Non\"", "Conditions": "Conditions", - "Parallel branch": "Branche parallèle", - "Add branch": "Ajouter une branche", - "All succeeded": "Tous réussis", - "Any succeeded": "Un réussi", - "Any succeeded or failed": "Un réussi ou un échoué", - "Continue after all branches succeeded": "Continuer après la réussite de toutes les branches", - "Continue after any branch succeeded": "Continuer après la réussite d'une branche", - "Continue after any branch succeeded, or exit after any branch failed": "Continuer après la réussite d'une branche, ou quitter après l'échec d'une branche", - "Delay": "Délai", - "Duration": "Durée", - "End Status": "Statut de fin", - "Select status": "Sélectionner un statut", - "Succeed and continue": "Réussir et continuer", - "Fail and exit": "Échouer et quitter", "Create record": "Créer un enregistrement", "Update record": "Mettre à jour un enregistrement", "Query record": "Interroger un enregistrement", @@ -108,22 +94,5 @@ "Trigger in executed workflow cannot be modified": "Le déclencheur dans le workflow exécuté ne peut pas être modifié", "Node in executed workflow cannot be modified": "Le nœud dans le workflow exécuté ne peut pas être modifié", "Can not delete": "Impossible de supprimer", - "The result of this node has been referenced by other nodes ({{nodes}}), please remove the usage before deleting.": "Le résultat de ce nœud a été référencé par d'autres nœuds ({{nodes}}), veuillez supprimer son utilisation avant de le supprimer.", - "HTTP request": "Requête HTTP", - "HTTP method": "Méthode HTTP", - "URL": "URL", - "Headers": "En-têtes", - "Add request header": "Ajouter un en-tête de requête", - "Parameters": "Paramètres", - "Add parameter": "Ajouter un paramètre", - "Body": "Corps", - "Use variable": "Utiliser une variable", - "Format": "Format", - "Insert": "Insérer", - "Timeout config": "Configuration du délai d'expiration", - "ms": "ms", - "Input request data": "Entrée des données de requête", - "Only support standard JSON data": "Prend uniquement en charge les données JSON standard", - "\"Content-Type\" only support \"application/json\", and no need to specify": "\"Content-Type\" prend uniquement en charge \"application/json\" et n'a pas besoin d'être spécifié", - "Ignore fail request and continue workflow": "Ignorer l'échec de la requête et continuer le workflow" + "The result of this node has been referenced by other nodes ({{nodes}}), please remove the usage before deleting.": "Le résultat de ce nœud a été référencé par d'autres nœuds ({{nodes}}), veuillez supprimer son utilisation avant de le supprimer." } diff --git a/packages/plugins/@nocobase/plugin-workflow/src/locale/ja-JP.json b/packages/plugins/@nocobase/plugin-workflow/src/locale/ja-JP.json index e275cca78..65bccf5bb 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/locale/ja-JP.json +++ b/packages/plugins/@nocobase/plugin-workflow/src/locale/ja-JP.json @@ -70,11 +70,6 @@ "Continue when \"Yes\"": "「はい」の場合に続行", "Branch into \"Yes\" and \"No\"": "「はい」と「いいえ」で分岐して続行", "Conditions": "条件設定", - "Parallel branch": "分岐", - "All succeeded": "すべて成功", - "Any succeeded": "いずれかが成功", - "Continue after all branches succeeded": "すべての分岐が成功した後に続行", - "Continue after any branch succeeded": "いずれかの分岐が成功した後に続行", "Create record": "レコード追加", "Update record": "レコード更新", "Query record": "クエリ レコード", diff --git a/packages/plugins/@nocobase/plugin-workflow/src/locale/pt-BR.json b/packages/plugins/@nocobase/plugin-workflow/src/locale/pt-BR.json index 09e044385..425455a49 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/locale/pt-BR.json +++ b/packages/plugins/@nocobase/plugin-workflow/src/locale/pt-BR.json @@ -84,20 +84,6 @@ "Continue when \"Yes\"": "Continuar quando \"Sim\"", "Branch into \"Yes\" and \"No\"": "Ramo em \"Sim\" e \"Não\"", "Conditions": "Condições", - "Parallel branch": "Ramo paralelo", - "Add branch": "Adicionar ramo", - "All succeeded": "Todos com sucesso", - "Any succeeded": "Qualquer um com sucesso", - "Any succeeded or failed": "Qualquer um com sucesso ou falha", - "Continue after all branches succeeded": "Continuar após todos os ramos com sucesso", - "Continue after any branch succeeded": "Continuar após qualquer ramo com sucesso", - "Continue after any branch succeeded, or exit after any branch failed": "Continuar após qualquer ramo com sucesso ou sair após qualquer ramo falhar", - "Delay": "Atraso", - "Duration": "Duração", - "End Status": "Status final", - "Select status": "Selecionar status", - "Succeed and continue": "Ter sucesso e continuar", - "Fail and exit": "Falhar e sair", "Create record": "Criar registro", "Update record": "Atualizar registro", "Query record": "Consultar registro", @@ -108,22 +94,5 @@ "Trigger in executed workflow cannot be modified": "O acionador em fluxo de trabalho executado não pode ser modificado", "Node in executed workflow cannot be modified": "O nó em fluxo de trabalho executado não pode ser modificado", "Can not delete": "Não é possível excluir", - "The result of this node has been referenced by other nodes ({{nodes}}), please remove the usage before deleting.": "O resultado deste nó foi referenciado por outros nós ({{nodes}}), por favor, remova a referência antes de excluir.", - "HTTP request": "Requisição HTTP", - "HTTP method": "Método HTTP", - "URL": "URL", - "Headers": "Cabeçalhos", - "Add request header": "Adicionar cabeçalho de requisição", - "Parameters": "Parâmetros", - "Add parameter": "Adicionar parâmetro", - "Body": "Corpo", - "Use variable": "Usar variável", - "Format": "Formato", - "Insert": "Inserir", - "Timeout config": "Configuração de tempo limite", - "ms": "ms", - "Input request data": "Dados de entrada da requisição", - "Only support standard JSON data": "Suporta somente dados JSON padrão", - "\"Content-Type\" only support \"application/json\", and no need to specify": "\"Content-Type\" somente suporta \"application/json\" e não precisa ser especificado", - "Ignore fail request and continue workflow": "Ignorar falhas na requisição e continuar o fluxo de trabalho" + "The result of this node has been referenced by other nodes ({{nodes}}), please remove the usage before deleting.": "O resultado deste nó foi referenciado por outros nós ({{nodes}}), por favor, remova a referência antes de excluir." } diff --git a/packages/plugins/@nocobase/plugin-workflow/src/locale/ru-RU.json b/packages/plugins/@nocobase/plugin-workflow/src/locale/ru-RU.json index 540e1685c..8b7293354 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/locale/ru-RU.json +++ b/packages/plugins/@nocobase/plugin-workflow/src/locale/ru-RU.json @@ -70,11 +70,6 @@ "Continue when \"Yes\"": "Продолжить когда \"Да\"", "Branch into \"Yes\" and \"No\"": "Разветвление на \"Да\" and \"Нет\"", "Conditions": "Условия", - "Parallel branch": "Параллельная ветвь", - "All succeeded": "Всё успешно", - "Any succeeded": "Что-то успешно", - "Continue after all branches succeeded": "Продолжать после успеха на всех ветвях", - "Continue after any branch succeeded": "Продолжать после успеха на любой из ветвей", "Create record": "Создать запись", "Update record": "Обновить запись", "Query record": "Запрос записи", diff --git a/packages/plugins/@nocobase/plugin-workflow/src/locale/tr-TR.json b/packages/plugins/@nocobase/plugin-workflow/src/locale/tr-TR.json index fd84515ee..8b8dfafcc 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/locale/tr-TR.json +++ b/packages/plugins/@nocobase/plugin-workflow/src/locale/tr-TR.json @@ -70,11 +70,6 @@ "Continue when \"Yes\"": "\"Evet\" durumunda devam", "Branch into \"Yes\" and \"No\"": "\"Evet\" ve \"Hayır\" olarak dallandırın", "Conditions": "Koşullar", - "Parallel branch": "Paralel dal", - "All succeeded": "Hepsi başarılı", - "Any succeeded": "Herhangi biri başarılı", - "Continue after all branches succeeded": "Tüm dallar başarılı olduktan sonra devam et", - "Continue after any branch succeeded": "Herhangi bir dal başarılı olduktan sonra devam et", "Create record": "Kayıt oluştur", "Update record": "Kayıt güncelle", "Query record": "Sorgu kaydı", diff --git a/packages/plugins/@nocobase/plugin-workflow/src/locale/zh-CN.json b/packages/plugins/@nocobase/plugin-workflow/src/locale/zh-CN.json index 5b023d8ca..b55bdaf4d 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/locale/zh-CN.json +++ b/packages/plugins/@nocobase/plugin-workflow/src/locale/zh-CN.json @@ -2,9 +2,9 @@ "Workflow": "工作流", "Execution history": "执行历史", "Clear all executions": "清除所有执行记录", - "Clear executions will not reset executed count, and started executions will not be deleted, are you sure you want to delete them all?": "清空执行记录不会重置执行次数,且执行中的也不会被删除,确定要删除所有执行记录吗?", + "Clear executions will not reset executed count, and started executions will not be deleted, are you sure you want to delete them all?": + "清空执行记录不会重置执行次数,且执行中的也不会被删除,确定要删除所有执行记录吗?", "Executed": "已执行", - "Sync": "同步", "Sync enabled status of all workflows from database": "从数据库同步所有工作流的启用状态", "Trigger type": "触发方式", "Status": "状态", @@ -18,19 +18,15 @@ "Loading": "加载中", "Load failed": "加载失败", "Use transaction": "启用事务", - "Data operation nodes in workflow will run in a same transaction until any interruption. Any failure will cause data rollback, and will also rollback the history of the execution.": "工作流中的节点将在同一个事务中运行。任何失败都会导致数据回滚,同时也会回滚相应的执行历史。", + "Data operation nodes in workflow will run in a same transaction until any interruption. Any failure will cause data rollback, and will also rollback the history of the execution.": + "工作流中的节点将在同一个事务中运行。任何失败都会导致数据回滚,同时也会回滚相应的执行历史。", "Auto delete history when execution is on end status": "执行结束后自动删除对应状态的历史记录", "Trigger": "触发器", "Trigger variables": "触发器变量", "Trigger data": "触发数据", "Trigger time": "触发时间", "Triggered at": "触发时间", - "Form event": "表单事件", - "Event triggers when submitted a workflow bound form action.": "在提交绑定工作流的表单操作按钮后触发。", - "Form data model": "表单数据模型", - "Use a collection to match form data.": "使用一个数据表来匹配表单数据。", - "Associations to use": "待使用的关系数据", - "User submitted form": "提交表单的用户", + "Bind workflows": "绑定工作流", "Workflow will be triggered after submitting succeeded.": "提交成功后触发工作流。", "Workflow will be triggered after saving succeeded.": "保存成功后触发工作流。", @@ -42,17 +38,20 @@ "Full form data": "完整表单数据", "Select context": "选择上下文", "Collection event": "数据表事件", - "Event will be triggered on collection data row created, updated or deleted.": "当数据表中的数据被新增、更新或删除时触发。", + "Event will be triggered on collection data row created, updated or deleted.": + "当数据表中的数据被新增、更新或删除时触发。", "Trigger on": "触发时机", "After record added": "新增数据后", "After record updated": "更新数据后", "After record added or updated": "新增或更新数据后", "After record deleted": "删除数据后", "Changed fields": "发生变动的字段", - "Triggered only if one of the selected fields changes. If unselected, it means that it will be triggered when any field changes. When record is added or deleted, any field is considered to have been changed.": "只有被选中的某个字段发生变动时才会触发。如果不选择,则表示任何字段变动时都会触发。新增或删除数据时,任意字段都被认为发生变动。", + "Triggered only if one of the selected fields changes. If unselected, it means that it will be triggered when any field changes. When record is added or deleted, any field is considered to have been changed.": + "只有被选中的某个字段发生变动时才会触发。如果不选择,则表示任何字段变动时都会触发。新增或删除数据时,任意字段都被认为发生变动。", "Only triggers when match conditions": "满足以下条件才触发", "Preload associations": "预加载关联数据", - "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.": "请选中需要在后续节点中被访问的关系字段。超过两层的对多关联可能会导致性能问题,请谨慎使用。", + "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.": + "请选中需要在后续节点中被访问的关系字段。超过两层的对多关联可能会导致性能问题,请谨慎使用。", "Schedule event": "定时任务", "Event will be scheduled and triggered base on time conditions.": "基于时间条件进行定时触发的事件。", "Trigger mode": "触发模式", @@ -85,11 +84,13 @@ "Node result": "节点数据", "Variable key of node": "节点变量标识", "Calculator": "运算", - "Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression. The expression can be static or dynamic one from an expression collections.": "基于计算引擎对一个表达式进行计算,并获得一个值作为结果。表达式中可以使用上游节点里的变量。表达式可以是静态的,也可以是表达式表中的动态表达式。", + "Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression. The expression can be static or dynamic one from an expression collections.": + "基于计算引擎对一个表达式进行计算,并获得一个值作为结果。表达式中可以使用上游节点里的变量。表达式可以是静态的,也可以是表达式表中的动态表达式。", "String operation": "字符串", "System variables": "系统变量", "System time": "系统时间", "Date variables": "日期变量", + "Executed at": "执行于", "Queueing": "队列中", "On going": "进行中", @@ -101,8 +102,10 @@ "Canceled": "已取消", "Rejected": "已拒绝", "Retry needed": "需重试", + "Triggered but still waiting in queue to execute.": "已触发但仍在队列中等待执行。", - "Started and executing, maybe waiting for an async callback (manual, delay etc.).": "已开始执行,可能在等待异步回调(人工、延时等)。", + "Started and executing, maybe waiting for an async callback (manual, delay etc.).": + "已开始执行,可能在等待异步回调(人工、延时等)。", "Successfully finished.": "成功完成。", "Failed to satisfy node configurations.": "未满足节点配置造成的失败。", "Some node meets error.": "某个节点出错。", @@ -110,25 +113,16 @@ "Manually canceled whole execution when waiting.": "等待时被手动取消整个执行。", "Rejected from a manual node.": "被人工节点拒绝继续。", "General failed but should do another try.": "执行失败,需重试。", - "Continue the process": "继续流程", - "Terminate the process": "终止流程", - "Save temporarily": "暂存", + "Operations": "操作", - "This node contains branches, deleting will also be preformed to them, are you sure?": "节点包含分支,将同时删除其所有分支下的子节点,确定继续?", + "This node contains branches, deleting will also be preformed to them, are you sure?": + "节点包含分支,将同时删除其所有分支下的子节点,确定继续?", "Control": "流程控制", "Collection operations": "数据表操作", "Manual": "人工处理", - "Could be used for manually submitting data, and determine whether to continue or exit. Workflow will generate a todo item for assigned user when it reaches a manual node, and continue processing after user submits the form.": "可用于人工提交数据,并决定是否继续或退出流程。工作流在执行到人工节点时会为被指派的用户生成待办事项,直到用户提交对应表单后继续处理该流程。", - "Values preset in this form will override user submitted ones when continue or reject.": "表单中预设的字段值会在用户提交继续或拒绝时覆盖相应字段的值。", "Extended types": "扩展类型", "Node type": "节点类型", "Calculation": "运算", - "Expression type": "表达式类型", - "Static": "静态", - "Dynamic": "动态", - "Select dynamic expression": "选择动态表达式", - "Select the dynamic expression queried from the upstream node. You need to query it from an expression collection.": "从上游节点中选择查询出来的动态表达式。你需要从动态表达式类型的数据表中查询。", - "Variable datasource": "变量数据源", "Calculation engine": "运算引擎", "Basic": "基础", "Calculation expression": "运算表达式", @@ -139,110 +133,44 @@ "False": "假", "concat": "连接", "Condition": "条件判断", - "Based on boolean result of the calculation to determine whether to \"continue\" or \"exit\" the process, or continue on different branches of \"yes\" and \"no\".": "基于运算结果的真假来决定“继续”或“退出”流程,或者在“是”与“否”的分支上分别继续。", + "Based on boolean result of the calculation to determine whether to \"continue\" or \"exit\" the process, or continue on different branches of \"yes\" and \"no\".": + "基于运算结果的真假来决定“继续”或“退出”流程,或者在“是”与“否”的分支上分别继续。", "Mode": "模式", "Continue when \"Yes\"": "“是”则继续", "Branch into \"Yes\" and \"No\"": "“是”和“否”分别继续", "Condition expression": "条件表达式", - "Parallel branch": "分支", - "Run multiple branch processes in parallel.": "并行运行多个分支流程。", - "Add branch": "增加分支", - "All succeeded": "全部成功", - "Any succeeded": "任意成功", - "Any succeeded or failed": "任意成功或失败", - "Continue after all branches succeeded": "全部分支都成功后才能继续", - "Continue after any branch succeeded": "任意分支成功后就继续", - "Continue after any branch succeeded, or exit after any branch failed.": "任意分支成功就继续流程,或者任意分支失败就退出流程。", - "Loop": "循环", - "Loop target": "循环对象", - "Loop index": "当前索引", - "Loop length": "循环长度", - "By using a loop node, you can perform the same operation on multiple sets of data. The source of these sets can be either multiple records from a query node or multiple associated records of a single record. Loop node can also be used for iterating a certain number of times or for looping through each character in a string. However, excessive looping may cause performance issues, so use with caution.": "使用循环节点可以对多条数据进行同样的操作,多条数据的来源可以是查询节点的多条结果,或者一条数据的多条关系数据。也可以用于一定次数的循环,或者对字符串中每一个字符的循环处理。循环次数过高可能引起性能问题,请谨慎使用。", - "Scope variables": "局域变量", - "A single number will be treated as a loop count, a single string will be treated as an array of characters, and other non-array values will be converted to arrays. The loop node ends when the loop count is reached, or when the array loop is completed. You can also add condition nodes to the loop to terminate it.": "单一数字值将被视为循环次数,单一字符串值将被视为字符数组,其他非数组值将被转换为数组。达到循环次数,或者将数组循环完成后,循环节点结束。你也可以在循环中添加条件节点,以终止循环。", - "Delay": "延时", - "Delay a period of time and then continue or exit the process. Can be used to set wait or timeout times in parallel branches.": "延时一段时间,然后继续或退出流程。可以用于并行分支中等待其他分支或设置超时时间。", - "Duration": "时长", - "End Status": "到时状态", - "Select status": "选择状态", - "Succeed and continue": "通过并继续", - "Fail and exit": "失败并退出", - "Assignee": "负责人", - "Assignees": "负责人", - "User interface": "操作界面", - "Configure user interface": "配置界面", - "View user interface": "查看界面", - "Separately": "分别处理", - "Each user has own task": "每个人处理各自的任务", - "Collaboratively": "协作处理", - "Everyone shares one task": "所有人共享同一个任务", - "Negotiation": "协商机制", - "All pass": "全部通过", - "Everyone should pass": "每个人通过才通过", - "Any pass": "任意通过", - "Anyone pass": "任何一人通过即通过", - "Field name existed in form": "表单中已有对应标识的字段", - "Custom form": "自定义表单", - "Data record": "数据记录", - "Create record form": "新增数据表单", - "Update record form": "更新数据表单", - "Filter settings": "筛选设置", "Create record": "新增数据", - "Add new record to a collection. You can use variables from upstream nodes to assign values to fields.": "向一个数据表中添加新的数据。可以使用上游节点里的变量为字段赋值。", + "Add new record to a collection. You can use variables from upstream nodes to assign values to fields.": + "向一个数据表中添加新的数据。可以使用上游节点里的变量为字段赋值。", "Update record": "更新数据", - "Update records of a collection. You can use variables from upstream nodes as query conditions and field values.": "更新一个数据表中的数据。可以使用上游节点里的变量作为查询条件和数据值。", + "Update records of a collection. You can use variables from upstream nodes as query conditions and field values.": + "更新一个数据表中的数据。可以使用上游节点里的变量作为查询条件和数据值。", "Update mode": "更新模式", "Update in a batch": "批量更新", "Update one by one": "逐条更新", - "Update all eligible data at one time, which has better performance when the amount of data is large. But the updated data will not trigger other workflows, and will not record audit logs.": "一次性更新所有符合条件的数据,在数据量较大时有比较好的性能;但被更新的数据不会触发其他工作流,也不会记录更新日志。", - "The updated data can trigger other workflows, and the audit log will also be recorded. But it is usually only applicable to several or dozens of pieces of data, otherwise there will be performance problems.": "被更新的数据可以再次触发其他工作流,也会记录更新日志;但通常只适用于数条或数十条数据,否则会有性能问题。", + "Update all eligible data at one time, which has better performance when the amount of data is large. But the updated data will not trigger other workflows, and will not record audit logs.": + "一次性更新所有符合条件的数据,在数据量较大时有比较好的性能;但被更新的数据不会触发其他工作流,也不会记录更新日志。", + "The updated data can trigger other workflows, and the audit log will also be recorded. But it is usually only applicable to several or dozens of pieces of data, otherwise there will be performance problems.": + "被更新的数据可以再次触发其他工作流,也会记录更新日志;但通常只适用于数条或数十条数据,否则会有性能问题。", "Query record": "查询数据", - "Query records from a collection. You can use variables from upstream nodes as query conditions.": "查询一个数据表中的数据。可以使用上游节点里的变量作为查询条件。", + "Query records from a collection. You can use variables from upstream nodes as query conditions.": + "查询一个数据表中的数据。可以使用上游节点里的变量作为查询条件。", "Allow multiple records as result": "允许结果是多条数据", - "If checked, when there are multiple records in the query result, an array will be returned as the result, which can be operated on one by one using a loop node. Otherwise, only one record will be returned.": "选中后,当查询结果有多条记录时,会返回数组作为结果,可以使用循环节点对它逐条操作;否则,仅返回一条数据。", + "If checked, when there are multiple records in the query result, an array will be returned as the result, which can be operated on one by one using a loop node. Otherwise, only one record will be returned.": + "选中后,当查询结果有多条记录时,会返回数组作为结果,可以使用循环节点对它逐条操作;否则,仅返回一条数据。", "Exit when query result is null": "查询结果为空时,退出流程", "Please select collection first": "请先选择数据表", "Only update records matching conditions": "只更新满足条件的数据", "Please add at least one condition": "请添加至少一个条件", - "Unassigned fields will be set to default values, and those without default values will be set to null.": "未被赋值的字段将被设置为默认值,没有默认值的设置为空值。", + "Unassigned fields will be set to default values, and those without default values will be set to null.": + "未被赋值的字段将被设置为默认值,没有默认值的设置为空值。", + "Delete record": "删除数据", - "Delete records of a collection. Could use variables in workflow context as filter. All records match the filter will be deleted.": "删除一个数据表中的数据。可以使用上游节点里的变量作为过滤条件。所有满足条件的数据都将被删除。", - "Aggregate": "聚合查询", - "Counting, summing, finding maximum, minimum, and average values for multiple records of a collection or associated data of a record.": "对一个数据表里的多条数据或者一条数据里的关系数据进行统计、求和、求最大值、最小值、平均值。", - "Aggregator function": "聚合函数", - "Target type": "目标类型", - "Data of collection": "数据表数据", - "Data of associated collection": "关联数据表数据", - "Field to aggregate": "聚合字段", - "Distinct": "去重", - "Query result": "查询结果", + "Delete records of a collection. Could use variables in workflow context as filter. All records match the filter will be deleted.": + "删除一个数据表中的数据。可以使用上游节点里的变量作为过滤条件。所有满足条件的数据都将被删除。", + "Executed workflow cannot be modified": "已经执行过的工作流不能被修改", "Can not delete": "无法删除", - "The result of this node has been referenced by other nodes ({{nodes}}), please remove the usage before deleting.": "该节点的执行结果已被其他节点({{nodes}})引用,删除前请先移除引用。", - "HTTP request": "HTTP 请求", - "Send HTTP request to a URL. You can use the variables in the upstream nodes as request headers, parameters and request body.": "向指定 URL 发送 HTTP 请求。可以使用上游节点里的变量作为请求头、参数和请求体。", - "HTTP method": "HTTP 方法", - "URL": "地址", - "Headers": "请求头", - "Add request header": "添加请求头", - "Parameters": "参数", - "Add parameter": "添加参数", - "Body": "请求体", - "Use variable": "使用变量", - "Format": "格式化", - "Insert": "插入", - "Timeout config": "超时设置", - "ms": "毫秒", - "Input request data": "输入请求数据", - "Only support standard JSON data": "仅支持标准 JSON 数据", - "\"Content-Type\" only support \"application/json\", and no need to specify": "\"Content-Type\" 请求头仅支持 \"application/json\",无需填写", - "Ignore failed request and continue workflow": "忽略失败的请求并继续工作流", - "Workflow todos": "工作流待办", - "Task": "任务", - "Dynamic expression": "动态表达式", - "An expression for calculation in each rows": "每行数据计算规则不同时使用", - "Unconfigured": "未配置", - "SQL action": "SQL 操作", - "Execute a SQL statement in database": "在数据库中执行一个 SQL 语句", - "Usage of SQL query result is not supported yet.": "SQL 执行的结果暂不支持使用。" + "The result of this node has been referenced by other nodes ({{nodes}}), please remove the usage before deleting.": + "该节点的执行结果已被其他节点({{nodes}})引用,删除前请先移除引用。" } diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/Plugin.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/Plugin.ts index 39811b262..50156d747 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/Plugin.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/Plugin.ts @@ -11,16 +11,24 @@ import { createLogger, getLoggerFilePath, getLoggerLevel, Logger, LoggerOptions import Processor from './Processor'; import initActions from './actions'; import { EXECUTION_STATUS } from './constants'; -import initFields from './fields'; import initFunctions, { CustomFunction } from './functions'; -import initInstructions, { Instruction } from './instructions'; -import initTriggers, { Trigger } from './triggers'; +import type Trigger from './triggers'; +import CollectionTrigger from './triggers/CollectionTrigger'; +import ScheduleTrigger from './triggers/ScheduleTrigger'; +import type Instruction from './instructions'; +import CalculationInstruction from './instructions/CalculationInstruction'; +import ConditionInstruction from './instructions/ConditionInstruction'; +import CreateInstruction from './instructions/CreateInstruction'; +import DestroyInstruction from './instructions/DestroyInstruction'; +import QueryInstruction from './instructions/QueryInstruction'; +import UpdateInstruction from './instructions/UpdateInstruction'; import type { ExecutionModel, JobModel, WorkflowModel } from './types'; type Pending = [ExecutionModel, JobModel?]; type ID = number | string; + export default class WorkflowPlugin extends Plugin { instructions: Registry = new Registry(); triggers: Registry = new Registry(); @@ -43,7 +51,7 @@ export default class WorkflowPlugin extends Plugin { const logger = createLogger({ transports: [ - 'console', + ...(process.env.NODE_ENV !== 'production' ? ['console'] : []), new winston.transports.File({ filename: getLoggerFilePath('workflows', date, `${workflowId}.log`), level: getLoggerLevel(), @@ -102,13 +110,38 @@ export default class WorkflowPlugin extends Plugin { } }; + initTriggers(more: { [key: string]: T | { new (p: Plugin): T } } = {}) { + const { triggers } = this; + + triggers.register('collection', new CollectionTrigger(this)); + triggers.register('schedule', new ScheduleTrigger(this)); + + for (const [name, trigger] of Object.entries(more)) { + triggers.register(name, typeof trigger === 'function' ? new trigger(this) : trigger); + } + } + + initInstructions(more: { [key: string]: T | { new (p: Plugin): T } } = {}) { + const { instructions } = this; + + instructions.register('calculation', new CalculationInstruction(this)); + instructions.register('condition', new ConditionInstruction(this)); + instructions.register('create', new CreateInstruction(this)); + instructions.register('destroy', new DestroyInstruction(this)); + instructions.register('query', new QueryInstruction(this)); + instructions.register('update', new UpdateInstruction(this)); + + for (const [name, instruction] of Object.entries({ ...more })) { + instructions.register(name, typeof instruction === 'function' ? new instruction(this) : instruction); + } + } + async load() { const { db, options } = this; - initFields(this); initActions(this); - initTriggers(this, options.triggers); - initInstructions(this, options.instructions); + this.initTriggers(options.triggers); + this.initInstructions(options.instructions); initFunctions(this, options.functions); this.loggerCache = new LRUCache({ diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/Processor.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/Processor.ts index fd8a36632..d7ed3dbac 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/Processor.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/Processor.ts @@ -2,7 +2,7 @@ import { Model, Transaction, Transactionable } from '@nocobase/database'; import { appendArrayColumn } from '@nocobase/evaluators'; import { Logger } from '@nocobase/logger'; import { parse } from '@nocobase/utils'; -import Plugin from '.'; +import type Plugin from './Plugin'; import { EXECUTION_STATUS, JOB_STATUS } from './constants'; import { Runner } from './instructions'; import type { ExecutionModel, FlowNodeModel, JobModel } from './types'; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/Plugin.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/Plugin.test.ts index 024af7509..64411fe7b 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/Plugin.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/Plugin.test.ts @@ -1,6 +1,6 @@ import { MockServer } from '@nocobase/test'; import Database from '@nocobase/database'; -import { getApp, sleep } from '.'; +import { getApp, sleep } from '@nocobase/plugin-workflow-test'; import { EXECUTION_STATUS } from '../constants'; describe('workflow > Plugin', () => { diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/Processor.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/Processor.test.ts index 8608ebde8..d6431d8ab 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/Processor.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/Processor.test.ts @@ -1,10 +1,10 @@ import Database from '@nocobase/database'; -import { Application } from '@nocobase/server'; -import { getApp, sleep } from '.'; +import { MockServer } from '@nocobase/test'; +import { getApp, sleep } from '@nocobase/plugin-workflow-test'; import { BRANCH_INDEX, EXECUTION_STATUS, JOB_STATUS } from '../constants'; describe('workflow > Processor', () => { - let app: Application; + let app: MockServer; let db: Database; let PostRepo; let WorkflowModel; @@ -168,7 +168,7 @@ describe('workflow > Processor', () => { describe('manual nodes', () => { it('manual node should suspend execution, and could be manually resume', async () => { const n1 = await workflow.createNode({ - type: 'manual', + type: 'prompt', }); const n2 = await workflow.createNode({ @@ -282,7 +282,7 @@ describe('workflow > Processor', () => { }); const n2 = await workflow.createNode({ - type: 'manual', + type: 'prompt', branchIndex: BRANCH_INDEX.ON_TRUE, upstreamId: n1.id, }); @@ -354,260 +354,4 @@ describe('workflow > Processor', () => { expect(jobs.length).toEqual(2); }); }); - - describe('branch: mixed', () => { - it('condition branches contains parallel', async () => { - const n1 = await workflow.createNode({ - type: 'condition', - }); - - const n2 = await workflow.createNode({ - type: 'parallel', - branchIndex: BRANCH_INDEX.ON_TRUE, - upstreamId: n1.id, - }); - - const n3 = await workflow.createNode({ - type: 'manual', - upstreamId: n2.id, - branchIndex: 0, - }); - - const n4 = await workflow.createNode({ - title: 'parallel echo', - type: 'echo', - upstreamId: n2.id, - branchIndex: 1, - }); - - const n5 = await workflow.createNode({ - title: 'last echo', - type: 'echo', - upstreamId: n1.id, - }); - - await n1.setDownstream(n5); - - const post = await PostRepo.create({ values: { title: 't1' } }); - - await sleep(500); - - const [execution] = await workflow.getExecutions(); - expect(execution.status).toEqual(EXECUTION_STATUS.STARTED); - - const pendingJobs = await execution.getJobs(); - expect(pendingJobs.length).toBe(4); - - const pending = pendingJobs.find((item) => item.nodeId === n3.id); - pending.set({ - status: JOB_STATUS.RESOLVED, - result: 123, - }); - pending.execution = execution; - await plugin.resume(pending); - - await sleep(500); - - expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED); - const jobs = await execution.getJobs({ order: [['id', 'ASC']] }); - expect(jobs.length).toEqual(5); - }); - - it('condition contains loop (target as 0)', async () => { - const n1 = await workflow.createNode({ - type: 'condition', - }); - - const n2 = await workflow.createNode({ - type: 'loop', - branchIndex: BRANCH_INDEX.ON_TRUE, - upstreamId: n1.id, - config: { - target: 0, - }, - }); - - const n3 = await workflow.createNode({ - type: 'echo', - branchIndex: 0, - upstreamId: n2.id, - }); - - const n4 = await workflow.createNode({ - type: 'echo', - upstreamId: n1.id, - }); - - await n1.setDownstream(n4); - - const post = await PostRepo.create({ values: { title: 't1' } }); - - await sleep(500); - - const [e1] = await workflow.getExecutions(); - expect(e1.status).toEqual(EXECUTION_STATUS.RESOLVED); - const jobs = await e1.getJobs({ order: [['id', 'ASC']] }); - expect(jobs.length).toBe(3); - expect(jobs[0].status).toBe(JOB_STATUS.RESOLVED); - }); - - it('condition contains loop (target as 2)', async () => { - const n1 = await workflow.createNode({ - type: 'condition', - }); - - const n2 = await workflow.createNode({ - type: 'loop', - branchIndex: BRANCH_INDEX.ON_TRUE, - upstreamId: n1.id, - config: { - target: 2, - }, - }); - - const n3 = await workflow.createNode({ - type: 'echo', - branchIndex: 0, - upstreamId: n2.id, - }); - - const n4 = await workflow.createNode({ - type: 'echo', - upstreamId: n1.id, - }); - - await n1.setDownstream(n4); - - const post = await PostRepo.create({ values: { title: 't1' } }); - - await sleep(500); - - const [e1] = await workflow.getExecutions(); - expect(e1.status).toEqual(EXECUTION_STATUS.RESOLVED); - const jobs = await e1.getJobs({ order: [['id', 'ASC']] }); - expect(jobs.length).toBe(5); - expect(jobs[0].status).toBe(JOB_STATUS.RESOLVED); - }); - - it('parallel branches contains condition', async () => { - const n1 = await workflow.createNode({ - type: 'parallel', - }); - - const n2 = await workflow.createNode({ - type: 'manual', - upstreamId: n1.id, - branchIndex: 0, - }); - - const n3 = await workflow.createNode({ - type: 'condition', - upstreamId: n1.id, - branchIndex: 1, - }); - - const n4 = await workflow.createNode({ - title: 'condition echo', - type: 'echo', - upstreamId: n3.id, - branchIndex: BRANCH_INDEX.ON_TRUE, - }); - - const n5 = await workflow.createNode({ - title: 'last echo', - type: 'echo', - upstreamId: n1.id, - }); - - await n1.setDownstream(n5); - - const post = await PostRepo.create({ values: { title: 't1' } }); - - await sleep(500); - - const [e1] = await workflow.getExecutions(); - expect(e1.status).toEqual(EXECUTION_STATUS.STARTED); - - const pendingJobs = await e1.getJobs(); - expect(pendingJobs.length).toBe(4); - - const pending = pendingJobs.find((item) => item.nodeId === n2.id); - pending.set({ - status: JOB_STATUS.RESOLVED, - result: 123, - }); - pending.execution = e1; - await plugin.resume(pending); - - await sleep(500); - - const [e2] = await workflow.getExecutions(); - expect(e2.status).toEqual(EXECUTION_STATUS.RESOLVED); - const jobs = await e2.getJobs({ order: [['id', 'ASC']] }); - expect(jobs.length).toEqual(5); - }); - - it('loop branch contains parallel branches', async () => { - const n1 = await workflow.createNode({ - type: 'loop', - config: { - target: 2, - }, - }); - - const n2 = await workflow.createNode({ - type: 'parallel', - branchIndex: 0, - upstreamId: n1.id, - config: { - mode: 'any', - }, - }); - - const n3 = await workflow.createNode({ - type: 'condition', - config: { - rejectOnFalse: true, - calculation: { - calculator: '<', - operands: [`{{$scopes.${n1.id}.item}}`, 1], - }, - }, - branchIndex: 0, - upstreamId: n2.id, - }); - const n4 = await workflow.createNode({ - type: 'echo', - upstreamId: n3.id, - }); - await n3.setDownstream(n4); - - const n5 = await workflow.createNode({ - type: 'condition', - config: { - rejectOnFalse: true, - calculation: { - calculator: '<', - operands: [`{{$scopes.${n1.id}.item}}`, 1], - }, - }, - branchIndex: 1, - upstreamId: n2.id, - }); - const n6 = await workflow.createNode({ - type: 'echo', - upstreamId: n5.id, - }); - await n5.setDownstream(n6); - - const post = await PostRepo.create({ values: { title: 't1' } }); - - await sleep(1000); - - const [e1] = await workflow.getExecutions(); - expect(e1.status).toEqual(EXECUTION_STATUS.FAILED); - const e1jobs = await e1.getJobs(); - expect(e1jobs.length).toBe(7); - }); - }); }); diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/executions.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/executions.test.ts index bbc265236..408e7a70a 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/executions.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/executions.test.ts @@ -1,6 +1,6 @@ import { MockServer } from '@nocobase/test'; import Database from '@nocobase/database'; -import { getApp, sleep } from '..'; +import { getApp, sleep } from '@nocobase/plugin-workflow-test'; import { EXECUTION_STATUS } from '../../constants'; describe('workflow > actions > executions', () => { diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/nodes.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/nodes.test.ts index c7224a6aa..b8b834393 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/nodes.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/nodes.test.ts @@ -1,6 +1,6 @@ import { MockServer } from '@nocobase/test'; import Database from '@nocobase/database'; -import { getApp, sleep } from '..'; +import { getApp, sleep } from '@nocobase/plugin-workflow-test'; describe('workflow > actions > workflows', () => { let app: MockServer; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/workflows.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/workflows.test.ts index 53b28c0c5..50bc92abc 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/workflows.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/workflows.test.ts @@ -1,6 +1,6 @@ import { MockServer } from '@nocobase/test'; import Database from '@nocobase/database'; -import { getApp, sleep } from '..'; +import { getApp, sleep } from '@nocobase/plugin-workflow-test'; describe('workflow > actions > workflows', () => { let app: MockServer; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/index.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/index.ts deleted file mode 100644 index b15154e71..000000000 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/index.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { ApplicationOptions } from '@nocobase/server'; -import { MockServer, mockServer } from '@nocobase/test'; -import lodash from 'lodash'; -import path from 'path'; -import Plugin from '..'; -import { JOB_STATUS } from '../constants'; -import type { FlowNodeModel } from '../types'; - -export function sleep(ms: number) { - return new Promise((resolve) => { - setTimeout(resolve, ms); - }); -} - -interface MockAppOptions extends ApplicationOptions { - manual?: boolean; -} - -export async function getApp({ manual, ...options }: MockAppOptions = {}): Promise { - const app = mockServer(options); - - app.plugin(Plugin, { - name: 'workflow', - instructions: { - echo: { - run({ config = {} }: FlowNodeModel, { result }, processor) { - return { - status: JOB_STATUS.RESOLVED, - result: config.path == null ? result : lodash.get(result, config.path), - }; - }, - }, - - error: { - run(node, input, processor) { - throw new Error('definite error'); - }, - }, - - pending: { - run(node, input, processor) { - return { - status: JOB_STATUS.PENDING, - }; - }, - }, - - 'prompt->error': { - run(node, input, processor) { - return { - status: JOB_STATUS.PENDING, - }; - }, - resume(node, input, processor) { - throw new Error('input failed'); - }, - }, - - customizedSuccess: { - run(node, input, processor) { - return { - status: 100, - }; - }, - }, - - customizedError: { - run(node, input, processor) { - return { - status: -100, - }; - }, - }, - }, - functions: { - no1: () => 1, - }, - }); - - await app.load(); - - await app.db.import({ - directory: path.resolve(__dirname, './collections'), - }); - - try { - await app.db.sync(); - } catch (error) { - console.error(error); - } - - if (!manual) { - await app.start(); - } - - return app; -} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/calculation.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/calculation.test.ts index d9c7cf433..f3432c589 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/calculation.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/calculation.test.ts @@ -1,6 +1,6 @@ import { Application } from '@nocobase/server'; import Database from '@nocobase/database'; -import { getApp, sleep } from '..'; +import { getApp, sleep } from '@nocobase/plugin-workflow-test'; import { JOB_STATUS } from '../../constants'; describe('workflow > instructions > calculation', () => { @@ -187,79 +187,4 @@ describe('workflow > instructions > calculation', () => { expect(job.result).toBe('at1'); }); }); - - describe('dynamic expression', () => { - it('dynamic expression field in current table', async () => { - const n1 = await workflow.createNode({ - type: 'calculation', - config: { - dynamic: '{{$context.data.category}}', - scope: '{{$context.data}}', - }, - }); - - const post = await PostRepo.create({ - values: { - title: 't1', - category: { - engine: 'math.js', - expression: '1 + {{read}}', - }, - }, - }); - - await sleep(500); - - const [execution] = await workflow.getExecutions(); - const [job] = await execution.getJobs(); - expect(job.result).toBe(1); - }); - - it('dynamic expression field in association table', async () => { - const n1 = await workflow.createNode({ - type: 'query', - config: { - collection: 'categories', - params: { - filter: { - $and: [{ id: '{{$context.data.categoryId}}' }], - }, - }, - }, - }); - - const n2 = await workflow.createNode({ - type: 'calculation', - config: { - dynamic: `{{$jobsMapByNodeKey.${n1.key}}}`, - scope: '{{$context.data}}', - }, - upstreamId: n1.id, - }); - - await n1.setDownstream(n2); - - const category = await CategoryRepo.create({ - values: { - title: 'c1', - engine: 'math.js', - expression: '1 + {{read}}', - }, - }); - - const post = await PostRepo.create({ - values: { - title: 't1', - categoryId: category.id, - }, - }); - - await sleep(500); - - const [execution] = await workflow.getExecutions(); - const jobs = await execution.getJobs({ order: [['id', 'ASC']] }); - expect(jobs.length).toBe(2); - expect(jobs[1].result).toBe(1); - }); - }); }); diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/condition.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/condition.test.ts index 71644a907..ba6fc145c 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/condition.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/condition.test.ts @@ -1,7 +1,7 @@ import Database from '@nocobase/database'; import { Application } from '@nocobase/server'; -import { getApp, sleep } from '..'; -import { BRANCH_INDEX, EXECUTION_STATUS } from '../../constants'; +import { getApp, sleep } from '@nocobase/plugin-workflow-test'; +import { BRANCH_INDEX, EXECUTION_STATUS, JOB_STATUS } from '../../constants'; describe('workflow > instructions > condition', () => { let app: Application; @@ -30,9 +30,42 @@ describe('workflow > instructions > condition', () => { afterEach(() => app.destroy()); - describe('config.rejectOnFalse', () => {}); + describe('config.rejectOnFalse', () => { + it('false to exit', async () => { + const n1 = await workflow.createNode({ + type: 'condition', + config: { + engine: 'basic', + calculation: { + calculator: 'equal', + operands: [0, 1], + }, + rejectOnFalse: true, + }, + }); - describe('single calculation', () => { + const n2 = await workflow.createNode({ + type: 'echo', + upstreamId: n1.id, + }); + + await n1.setDownstream(n2); + + const post = await PostRepo.create({ values: {} }); + + await sleep(500); + + const [execution] = await workflow.getExecutions(); + expect(execution.status).toEqual(EXECUTION_STATUS.FAILED); + + const jobs = await execution.getJobs(); + expect(jobs.length).toBe(1); + expect(jobs[0].status).toBe(JOB_STATUS.FAILED); + expect(jobs[0].result).toBe(false); + }); + }); + + describe('branching', () => { it('calculation to true downstream', async () => { const n1 = await workflow.createNode({ type: 'condition', @@ -112,6 +145,72 @@ describe('workflow > instructions > condition', () => { expect(jobs.length).toEqual(2); expect(jobs[1].result).toEqual(false); }); + + it('branch false and branch false to continue', async () => { + await db.sequelize.transaction(async (transaction) => { + const n1 = await workflow.createNode( + { + type: 'condition', + config: { + engine: 'basic', + calculation: { + calculator: 'equal', + operands: [0, 1], + }, + }, + }, + { transaction }, + ); + + const n2 = await workflow.createNode( + { + type: 'condition', + config: { + engine: 'basic', + calculation: { + calculator: 'equal', + operands: [0, 1], + }, + }, + upstreamId: n1.id, + branchIndex: BRANCH_INDEX.ON_FALSE, + }, + { transaction }, + ); + + const n3 = await workflow.createNode( + { + type: 'echo', + upstreamId: n2.id, + branchIndex: BRANCH_INDEX.ON_TRUE, + }, + { transaction }, + ); + + const n4 = await workflow.createNode( + { + type: 'echo', + upstreamId: n1.id, + }, + { transaction }, + ); + + await n1.setDownstream(n4, { transaction }); + }); + + const post = await PostRepo.create({ values: { title: 't1' } }); + + await sleep(500); + + const [execution] = await workflow.getExecutions(); + expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED); + + const jobs = await execution.getJobs({ order: [['id', 'ASC']] }); + console.log('------', jobs); + expect(jobs.length).toBe(3); + expect(jobs[0].result).toBe(false); + expect(jobs[1].result).toBe(false); + }); }); describe('group calculation', () => { diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/create.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/create.test.ts index 53274acb8..40a9e85c7 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/create.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/create.test.ts @@ -1,6 +1,6 @@ import { Application } from '@nocobase/server'; import Database from '@nocobase/database'; -import { getApp, sleep } from '..'; +import { getApp, sleep } from '@nocobase/plugin-workflow-test'; describe('workflow > instructions > create', () => { let app: Application; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/destroy.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/destroy.test.ts index d51067c96..e8d5e3e00 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/destroy.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/destroy.test.ts @@ -1,6 +1,6 @@ import { Application } from '@nocobase/server'; import Database from '@nocobase/database'; -import { getApp, sleep } from '..'; +import { getApp, sleep } from '@nocobase/plugin-workflow-test'; describe('workflow > instructions > destroy', () => { let app: Application; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/query.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/query.test.ts index c1d1eb413..0165f23be 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/query.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/query.test.ts @@ -1,6 +1,6 @@ import { Application } from '@nocobase/server'; import Database from '@nocobase/database'; -import { getApp, sleep } from '..'; +import { getApp, sleep } from '@nocobase/plugin-workflow-test'; import { EXECUTION_STATUS, JOB_STATUS } from '../../constants'; describe('workflow > instructions > query', () => { diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/update.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/update.test.ts index c20485afc..a44ca888d 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/update.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/instructions/update.test.ts @@ -1,6 +1,6 @@ import { Application } from '@nocobase/server'; import Database from '@nocobase/database'; -import { getApp, sleep } from '..'; +import { getApp, sleep } from '@nocobase/plugin-workflow-test'; import type { WorkflowModel as WorkflowModelType } from '../../types'; describe('workflow > instructions > update', () => { diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts index 71a00f03c..a689c7527 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts @@ -1,6 +1,6 @@ import { Application } from '@nocobase/server'; import Database from '@nocobase/database'; -import { getApp, sleep } from '..'; +import { getApp, sleep } from '@nocobase/plugin-workflow-test'; import { EXECUTION_STATUS } from '../../constants'; describe('workflow > triggers > collection', () => { @@ -88,6 +88,7 @@ describe('workflow > triggers > collection', () => { storage: db.options.storage, database: db.options.database, }, + cleanDb: false, }); db = app.db; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/schedule.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/schedule.test.ts index 0dca12786..03a41462b 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/schedule.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/schedule.test.ts @@ -1,6 +1,6 @@ import { Application } from '@nocobase/server'; import Database from '@nocobase/database'; -import { getApp, sleep } from '..'; +import { getApp, sleep } from '@nocobase/plugin-workflow-test'; describe.skip('workflow > triggers > schedule', () => { let app: Application; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/fields/index.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/fields/index.ts deleted file mode 100644 index da056c83d..000000000 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/fields/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { ExpressionField } from './expression-field'; - -export default function (plugin) { - plugin.db.registerFieldTypes({ - expression: ExpressionField, - }); -} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/index.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/index.ts index ad40bebf9..5a5c6f40a 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/index.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/index.ts @@ -1,6 +1,6 @@ export * from './utils'; export * from './constants'; -export type * from './instructions'; +export * from './instructions'; export { Trigger } from './triggers'; export { default as Processor } from './Processor'; export { default } from './Plugin'; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/calculation.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/CalculationInstruction.ts similarity index 85% rename from packages/plugins/@nocobase/plugin-workflow/src/server/instructions/calculation.ts rename to packages/plugins/@nocobase/plugin-workflow/src/server/instructions/CalculationInstruction.ts index 476bbc2fb..9e742c05d 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/calculation.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/CalculationInstruction.ts @@ -1,17 +1,17 @@ import { Evaluator, evaluators } from '@nocobase/evaluators'; import { parse } from '@nocobase/utils'; import { Instruction } from '.'; -import { Processor } from '..'; +import type Processor from '../Processor'; import { JOB_STATUS } from '../constants'; import type { FlowNodeModel } from '../types'; -interface CalculationConfig { +export interface CalculationConfig { dynamic?: boolean | string; engine?: string; expression?: string; } -export default { +export class CalculationInstruction extends Instruction { async run(node: FlowNodeModel, prevJob, processor: Processor) { const { dynamic = false } = node.config || {}; let { engine = 'math.js', expression = '' } = node.config; @@ -37,5 +37,7 @@ export default { status: JOB_STATUS.ERROR, }; } - }, -} as Instruction; + } +} + +export default CalculationInstruction; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/condition.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/ConditionInstruction.ts similarity index 96% rename from packages/plugins/@nocobase/plugin-workflow/src/server/instructions/condition.ts rename to packages/plugins/@nocobase/plugin-workflow/src/server/instructions/ConditionInstruction.ts index a0fcd33c3..3ba591c9c 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/condition.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/ConditionInstruction.ts @@ -1,7 +1,7 @@ import { evaluators } from '@nocobase/evaluators'; import { Registry } from '@nocobase/utils'; import { Instruction } from '.'; -import { Processor } from '..'; +import type Processor from '../Processor'; import { JOB_STATUS } from '../constants'; import type { FlowNodeModel, JobModel } from '../types'; @@ -116,7 +116,7 @@ function logicCalculate(calculation?: Calculation) { return calculate(calculation as CalculationItem); } -export default { +export class ConditionInstruction extends Instruction { async run(node: FlowNodeModel, prevJob, processor: Processor) { const { engine, calculation, expression, rejectOnFalse } = node.config || {}; const evaluator = evaluators.get(engine); @@ -162,7 +162,7 @@ export default { await processor.run(branchNode, savedJob); return null; - }, + } async resume(node: FlowNodeModel, branchJob: JobModel, processor: Processor) { const job = processor.findBranchParentJob(branchJob, node) as JobModel; @@ -174,5 +174,7 @@ export default { // pass control to upper scope by ending current scope return processor.exit(branchJob.status); - }, -} as Instruction; + } +} + +export default ConditionInstruction; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/create.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/CreateInstruction.ts similarity index 82% rename from packages/plugins/@nocobase/plugin-workflow/src/server/instructions/create.ts rename to packages/plugins/@nocobase/plugin-workflow/src/server/instructions/CreateInstruction.ts index f5e7deed8..edc2ca967 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/create.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/CreateInstruction.ts @@ -1,9 +1,11 @@ import { JOB_STATUS } from '../constants'; import { toJSON } from '../utils'; +import type Processor from '../Processor'; import type { FlowNodeModel } from '../types'; +import { Instruction } from '.'; -export default { - async run(node: FlowNodeModel, input, processor) { +export class CreateInstruction extends Instruction { + async run(node: FlowNodeModel, input, processor: Processor) { const { collection, params: { appends = [], ...params } = {} } = node.config; const { repository, model } = (node.constructor).database.getCollection(collection); @@ -35,5 +37,7 @@ export default { result: toJSON(result), status: JOB_STATUS.RESOLVED, }; - }, -}; + } +} + +export default CreateInstruction; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/destroy.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/DestroyInstruction.ts similarity index 70% rename from packages/plugins/@nocobase/plugin-workflow/src/server/instructions/destroy.ts rename to packages/plugins/@nocobase/plugin-workflow/src/server/instructions/DestroyInstruction.ts index a57f78bb7..f6e4be160 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/destroy.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/DestroyInstruction.ts @@ -1,8 +1,10 @@ +import { Instruction } from '.'; +import type Processor from '../Processor'; import { JOB_STATUS } from '../constants'; import type { FlowNodeModel } from '../types'; -export default { - async run(node: FlowNodeModel, input, processor) { +export class DestroyInstruction extends Instruction { + async run(node: FlowNodeModel, input, processor: Processor) { const { collection, params = {} } = node.config; const repo = (node.constructor).database.getRepository(collection); @@ -19,5 +21,7 @@ export default { result, status: JOB_STATUS.RESOLVED, }; - }, -}; + } +} + +export default DestroyInstruction; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/query.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/QueryInstruction.ts similarity index 90% rename from packages/plugins/@nocobase/plugin-workflow/src/server/instructions/query.ts rename to packages/plugins/@nocobase/plugin-workflow/src/server/instructions/QueryInstruction.ts index 52be2c48e..3f13aeaf0 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/query.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/QueryInstruction.ts @@ -1,11 +1,12 @@ import { DEFAULT_PAGE, DEFAULT_PER_PAGE, utils } from '@nocobase/actions'; -import Processor from '../Processor'; +import type Processor from '../Processor'; import { JOB_STATUS } from '../constants'; import type { FlowNodeModel } from '../types'; import { toJSON } from '../utils'; +import { Instruction } from '.'; -export default { +export class QueryInstruction extends Instruction { async run(node: FlowNodeModel, input, processor: Processor) { const { collection, multiple, params = {}, failOnEmpty = false } = node.config; @@ -49,5 +50,7 @@ export default { result: toJSON(result), status: JOB_STATUS.RESOLVED, }; - }, -}; + } +} + +export default QueryInstruction; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/update.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/UpdateInstruction.ts similarity index 78% rename from packages/plugins/@nocobase/plugin-workflow/src/server/instructions/update.ts rename to packages/plugins/@nocobase/plugin-workflow/src/server/instructions/UpdateInstruction.ts index a13888028..e95ef41ee 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/update.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/UpdateInstruction.ts @@ -1,8 +1,9 @@ -import Processor from '../Processor'; +import type Processor from '../Processor'; import { JOB_STATUS } from '../constants'; import type { FlowNodeModel } from '../types'; +import { Instruction } from '.'; -export default { +export class UpdateInstruction extends Instruction { async run(node: FlowNodeModel, input, processor: Processor) { const { collection, params = {} } = node.config; @@ -20,5 +21,7 @@ export default { result: result.length ?? result, status: JOB_STATUS.RESOLVED, }; - }, -}; + } +} + +export default UpdateInstruction; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/index.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/index.ts index 4ddec04f1..4985d3682 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/index.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/instructions/index.ts @@ -1,10 +1,7 @@ -import path from 'path'; - -import { requireModule } from '@nocobase/utils'; import { Transactionable } from '@nocobase/database'; -import Plugin from '..'; -import Processor from '../Processor'; +import type Plugin from '../Plugin'; +import type Processor from '../Processor'; import type { FlowNodeModel } from '../types'; @@ -20,48 +17,16 @@ export type Runner = (node: FlowNodeModel, input: any, processor: Processor) => // what should a instruction do? // - base on input and context, do any calculations or system call (io), and produce a result or pending. -export interface Instruction { - run: Runner; +export abstract class Instruction { + constructor(public plugin: Plugin) {} - // for start node in main flow (or branch) to resume when manual sub branch triggered - resume?: Runner; + abstract run(node: FlowNodeModel, input: any, processor: Processor): InstructionResult; - getScope?: (node: FlowNodeModel, data: any, processor: Processor) => any; + resume?(node: FlowNodeModel, input: any, processor: Processor): InstructionResult; - duplicateConfig?: (node: FlowNodeModel, options: Transactionable) => object | Promise; + getScope?(node: FlowNodeModel, data: any, processor: Processor): any; + + duplicateConfig?(node: FlowNodeModel, options: Transactionable): object | Promise; } -type InstructionConstructor = { new (p: Plugin): T }; - -export default function (plugin, more: { [key: string]: T | InstructionConstructor } = {}) { - const { instructions } = plugin; - - const natives = [ - 'calculation', - 'condition', - 'parallel', - 'loop', - 'delay', - 'manual', - 'query', - 'create', - 'update', - 'destroy', - 'aggregate', - 'request', - 'sql', - ].reduce( - (result, key) => - Object.assign(result, { - [key]: requireModule(path.isAbsolute(key) ? key : path.join(__dirname, key)), - }), - {}, - ); - - for (const [name, instruction] of Object.entries({ ...more, ...natives })) { - instructions.register( - name, - typeof instruction === 'function' ? new (instruction as InstructionConstructor)(plugin) : instruction, - ); - } -} +export default Instruction; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/migrations/20231122143143-split-to-plugins.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/migrations/20231122143143-split-to-plugins.ts new file mode 100644 index 000000000..5685eab18 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/migrations/20231122143143-split-to-plugins.ts @@ -0,0 +1,72 @@ +import { Migration } from '@nocobase/server'; + +export default class extends Migration { + async up() { + const match = await this.app.version.satisfies('<0.17.0-alpha.4'); + if (!match) { + return; + } + const { db } = this.context; + + const PluginModel = db.getModel('applicationPlugins'); + const NodeRepo = db.getRepository('flow_nodes'); + await db.sequelize.transaction(async (transaction) => { + await [ + '@nocobase/plugin-workflow-aggregate', + '@nocobase/plugin-workflow-delay', + '@nocobase/plugin-workflow-dynamic-calculation', + '@nocobase/plugin-workflow-loop', + '@nocobase/plugin-workflow-manual', + '@nocobase/plugin-workflow-parallel', + '@nocobase/plugin-workflow-request', + '@nocobase/plugin-workflow-sql', + '@nocobase/plugin-workflow-form-trigger', + ].reduce( + (promise, packageName) => + promise.then(async () => { + const existed = await PluginModel.findOne({ where: { packageName }, transaction }); + if (!existed) { + await PluginModel.create( + { + name: packageName, + packageName, + version: '0.17.0-alpha.1', + enabled: true, + installed: true, + builtin: true, + }, + { transaction }, + ); + } + }), + Promise.resolve(), + ); + + const nodes = await NodeRepo.find({ + transaction, + }); + + await nodes.reduce( + (promise, node) => + promise.then(() => { + if (node.type === 'calculation' && node.config.dynamic) { + node.set({ + type: 'dynamic-calculation', + config: { + expression: node.config.dynamic, + scope: node.config.scope, + }, + }); + node.changed('config', true); + } + + return node.save({ + silent: true, + transaction, + }); + }), + Promise.resolve(), + ); + }); + } +} diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/collection.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/CollectionTrigger.ts similarity index 99% rename from packages/plugins/@nocobase/plugin-workflow/src/server/triggers/collection.ts rename to packages/plugins/@nocobase/plugin-workflow/src/server/triggers/CollectionTrigger.ts index bff06ba99..2ce9a30b8 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/collection.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/CollectionTrigger.ts @@ -1,5 +1,5 @@ import { Collection, Model } from '@nocobase/database'; -import { Trigger } from '..'; +import Trigger from '.'; import { toJSON } from '../utils'; import type { WorkflowModel } from '../types'; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/schedule.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/ScheduleTrigger.ts similarity index 99% rename from packages/plugins/@nocobase/plugin-workflow/src/server/triggers/schedule.ts rename to packages/plugins/@nocobase/plugin-workflow/src/server/triggers/ScheduleTrigger.ts index c3834d749..3561f6706 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/schedule.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/ScheduleTrigger.ts @@ -1,6 +1,7 @@ import { fn, literal, Op, where } from '@nocobase/database'; import parser from 'cron-parser'; -import Plugin, { Trigger } from '..'; +import type Plugin from '../Plugin'; +import Trigger from '.'; import type { WorkflowModel } from '../types'; export type ScheduleOnField = diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/index.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/index.ts index 698b3e5f3..1d7874276 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/index.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/triggers/index.ts @@ -1,9 +1,5 @@ -import path from 'path'; - -import { requireModule } from '@nocobase/utils'; import { Transactionable } from '@nocobase/database'; - -import Plugin from '..'; +import type Plugin from '../Plugin'; import type { WorkflowModel } from '../types'; export abstract class Trigger { @@ -13,14 +9,4 @@ export abstract class Trigger { duplicateConfig?(workflow: WorkflowModel, options: Transactionable): object | Promise; } -export default function (plugin, more: { [key: string]: { new (p: Plugin): T } } = {}) { - const { triggers } = plugin; - - triggers.register('collection', new (requireModule(path.join(__dirname, 'collection')))(plugin)); - triggers.register('form', new (requireModule(path.join(__dirname, 'form')))(plugin)); - triggers.register('schedule', new (requireModule(path.join(__dirname, 'schedule')))(plugin)); - - for (const [name, TClass] of Object.entries(more)) { - triggers.register(name, new TClass(plugin)); - } -} +export default Trigger; diff --git a/packages/presets/nocobase/package.json b/packages/presets/nocobase/package.json index dc21d654e..aa843cf55 100644 --- a/packages/presets/nocobase/package.json +++ b/packages/presets/nocobase/package.json @@ -45,6 +45,15 @@ "@nocobase/plugin-users": "0.17.0-alpha.3", "@nocobase/plugin-verification": "0.17.0-alpha.3", "@nocobase/plugin-workflow": "0.17.0-alpha.3", + "@nocobase/plugin-workflow-aggregate": "0.17.0-alpha.3", + "@nocobase/plugin-workflow-delay": "0.17.0-alpha.3", + "@nocobase/plugin-workflow-dynamic-calculation": "0.17.0-alpha.3", + "@nocobase/plugin-workflow-form-trigger": "0.17.0-alpha.3", + "@nocobase/plugin-workflow-loop": "0.17.0-alpha.3", + "@nocobase/plugin-workflow-manual": "0.17.0-alpha.3", + "@nocobase/plugin-workflow-parallel": "0.17.0-alpha.3", + "@nocobase/plugin-workflow-request": "0.17.0-alpha.3", + "@nocobase/plugin-workflow-sql": "0.17.0-alpha.3", "@nocobase/server": "0.17.0-alpha.3", "cronstrue": "^2.11.0" }, diff --git a/packages/presets/nocobase/src/server/index.ts b/packages/presets/nocobase/src/server/index.ts index 57fe75246..6934fc1cf 100644 --- a/packages/presets/nocobase/src/server/index.ts +++ b/packages/presets/nocobase/src/server/index.ts @@ -17,6 +17,15 @@ export class PresetNocoBase extends Plugin { 'acl', 'china-region', 'workflow', + 'workflow-aggregate', + 'workflow-delay', + 'workflow-dynamic-calculation', + 'workflow-form-trigger', + 'workflow-loop', + 'workflow-manual', + 'workflow-parallel', + 'workflow-request', + 'workflow-sql', 'client', 'export', 'import',