fix(plugin-workflow): fix sql transaction and locale (#3444)

* fix(plugin-workflow): fix sql transaction and locale

* fix(plugin-workflow): fix locale
This commit is contained in:
Junyi 2024-01-27 09:37:40 +08:00 committed by GitHub
parent 05581694c7
commit f7b62ed42b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 62 additions and 11 deletions

View File

@ -37,7 +37,7 @@ export default class extends Plugin {
this.app.acl.allow('users_jobs', ['list', 'get', 'submit'], 'loggedIn');
const workflowPlugin = this.app.getPlugin<WorkflowPlugin>(WorkflowPlugin);
const workflowPlugin = this.app.pm.get(WorkflowPlugin) as WorkflowPlugin;
workflowPlugin.registerInstruction('manual', ManualInstruction);
}
}

View File

@ -3,6 +3,8 @@ import { css } from '@nocobase/client';
import { Instruction, WorkflowVariableRawTextArea, defaultFieldNames } from '@nocobase/plugin-workflow/client';
import { NAMESPACE } from '../locale';
import { Trans } from 'react-i18next';
import React from 'react';
export default class extends Instruction {
title = `{{t("SQL action", { ns: "${NAMESPACE}" })}}`;
@ -14,7 +16,7 @@ export default class extends Instruction {
type: 'string',
required: true,
title: 'SQL',
description: `{{t("Usage of SQL query result is not supported yet.", { ns: "${NAMESPACE}" })}}`,
description: '{{sqlDescription()}}',
'x-decorator': 'FormItem',
'x-component': 'WorkflowVariableRawTextArea',
'x-component-props': {
@ -26,6 +28,19 @@ export default class extends Instruction {
},
},
};
scope = {
sqlDescription() {
return (
<Trans ns={NAMESPACE}>
{'SQL query result could be used through '}
<a href="https://docs-cn.nocobase.com/plugins/workflow-json-query" target="_blank" rel="noreferrer">
{'JSON query node'}
</a>
{' (Commercial plugin).'}
</Trans>
);
},
};
components = {
WorkflowVariableRawTextArea,
};

View File

@ -1,6 +1,6 @@
import { useTranslation } from 'react-i18next';
export const NAMESPACE = 'workflow-sql';
export const NAMESPACE = '@nocobase/plugin-workflow-sql';
export function useLang(key: string, options = {}) {
const { t } = usePluginTranslation(options);

View File

@ -1,5 +1,5 @@
{
"SQL action": "SQL 操作",
"Execute a SQL statement in database": "在数据库中执行一个 SQL 语句",
"Usage of SQL query result is not supported yet.": "SQL 执行的结果暂不支持使用。"
"Execute a SQL statement in database.": "在数据库中执行一个 SQL 语句",
"SQL query result could be used through <1>JSON query node</1> (Commercial plugin).": "SQL 执行的结果可在 <1>JSON 解析节点</1> 中使用(商业插件)。"
}

View File

@ -11,7 +11,7 @@ export default class extends Instruction {
}
const result = await sequelize.query(sql, {
// transaction: processor.transaction,
transaction: processor.transaction,
// plain: true,
// model: db.getCollection(node.config.collection).model
});

View File

@ -1,4 +1,4 @@
import Database from '@nocobase/database';
import Database, { fn } from '@nocobase/database';
import { Application } from '@nocobase/server';
import { EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow';
import { getApp, sleep } from '@nocobase/plugin-workflow-test';
@ -166,4 +166,33 @@ describe('workflow > instructions > sql', () => {
expect(queryJob.result).toBeNull();
});
});
describe('run in sync mode', () => {
it('sync workflow', async () => {
const w2 = await WorkflowModel.create({
enabled: true,
sync: true,
type: 'collection',
config: {
mode: 1,
collection: 'categories',
},
});
const n1 = await w2.createNode({
type: 'sql',
config: {
sql: `select count(id) from ${PostCollection.quotedTableName()}`,
},
});
const CategoryRepo = db.getCollection('categories').repository;
const category = await CategoryRepo.create({ values: { title: 't1' } });
const [execution] = await w2.getExecutions();
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
const [job] = await execution.getJobs();
expect(job.status).toBe(JOB_STATUS.RESOLVED);
});
});
});

View File

@ -3,7 +3,7 @@ import { NAMESPACE } from '../locale';
import { JOB_STATUS } from '../constants';
export default class extends Instruction {
title = '{{t("End process")}}';
title = `{{t("End process", { ns: "${NAMESPACE}" })}}`;
type = 'end';
group = 'control';
description = `{{t("End the process immediately, with set status.", { ns: "${NAMESPACE}" })}}`;

View File

@ -92,7 +92,7 @@ const workflowFieldset = {
sync: {
type: 'boolean',
title: `{{ t("Execute mode", { ns: "${NAMESPACE}" }) }}`,
description: `{{ t("Could not be changed after created.", { ns: "${NAMESPACE}" }) }}`,
description: `{{ t("Execute workflow asynchronously or synchronously based on trigger type, and could not be changed after created.", { ns: "${NAMESPACE}" }) }}`,
'x-decorator': 'FormItem',
'x-component': 'SyncOptionSelect',
'x-component-props': {
@ -105,7 +105,7 @@ const workflowFieldset = {
{
label: `{{ t("Synchronously", { ns: "${NAMESPACE}" }) }}`,
value: true,
tooltip: `{{ t("For user actions that require immediate feedback. Can not use asynchronous nodes in such mode.", { ns: "${NAMESPACE}" }) }}`,
tooltip: `{{ t("For user actions that require immediate feedback. Can not use asynchronous nodes in such mode, and it is not recommended to perform time-consuming operations under synchronous mode.", { ns: "${NAMESPACE}" }) }}`,
},
],
},

View File

@ -27,6 +27,14 @@
"Trigger time": "触发时间",
"Triggered at": "触发时间",
"Execute mode": "执行模式",
"Execute workflow asynchronously or synchronously based on trigger type, and could not be changed after created.": "基于触发类型异步或同步执行工作流,创建后不可更改。",
"Asynchronously": "异步",
"Synchronously": "同步",
"Will be executed in the background as a queued task.": "将作为队列任务在后台执行。",
"For user actions that require immediate feedback. Can not use asynchronous nodes in such mode, and it is not recommended to perform time-consuming operations under synchronous mode.":
"适用于需要即时反馈的用户操作。不能在此模式下使用异步节点,并且不建议在同步模式下执行耗时的操作。",
"Bind workflows": "绑定工作流",
"Workflow will be triggered after submitting succeeded.": "提交成功后触发工作流。",
"Workflow will be triggered after saving succeeded.": "保存成功后触发工作流。",

View File

@ -6,7 +6,6 @@ export default class extends Migration {
async up() {
const { db } = this.context;
const PluginModel = db.getModel('applicationPlugins');
const JobRepo = db.getRepository('jobs');
await db.sequelize.transaction(async (transaction) => {
const jobs = await JobRepo.find({