mirror of
https://github.com/nocobase/nocobase.git
synced 2026-09-24 16:02:20 +08:00
fix(plugin-workflow-javascript): register script instruction class (#9826)
This commit is contained in:
@@ -14,6 +14,11 @@ import { ValueBlock } from '@nocobase/plugin-workflow/client';
|
||||
import { lang } from '../locale';
|
||||
|
||||
export default class extends V2ScriptInstruction {
|
||||
constructor() {
|
||||
super();
|
||||
this.bindTranslate(lang);
|
||||
}
|
||||
|
||||
useInitializers(node: { id: string | number; title?: string }): SchemaInitializerItemType {
|
||||
return {
|
||||
name: node.title ?? `#${node.id}`,
|
||||
|
||||
+26
@@ -9,6 +9,7 @@
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { PluginWorkflowScriptClient } from '../';
|
||||
import V1ScriptInstruction from '../ScriptInstruction';
|
||||
import { lang } from '../../locale';
|
||||
import V2ScriptInstruction from '../../client-v2/nodes/script';
|
||||
@@ -34,4 +35,29 @@ describe('ScriptInstruction compatibility', () => {
|
||||
resultTitle: lang('Script result'),
|
||||
});
|
||||
});
|
||||
|
||||
it('registers the v1 instruction as a class to avoid cross-entry instanceof checks', async () => {
|
||||
const calls: unknown[][] = [];
|
||||
const plugin = Object.create(PluginWorkflowScriptClient.prototype) as PluginWorkflowScriptClient & {
|
||||
app: {
|
||||
pm: {
|
||||
get: () => {
|
||||
registerInstruction: (...args: unknown[]) => number;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
plugin.app = {
|
||||
pm: {
|
||||
get: () => ({
|
||||
registerInstruction: (...args: unknown[]) => calls.push(args),
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
await plugin.load();
|
||||
|
||||
expect(calls).toEqual([['script', V1ScriptInstruction]]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ import { lang } from '../locale';
|
||||
export class PluginWorkflowScriptClient extends Plugin {
|
||||
async load() {
|
||||
const workflow = this.app.pm.get('workflow') as WorkflowPlugin;
|
||||
workflow.registerInstruction('script', new ScriptInstruction().bindTranslate(lang));
|
||||
workflow.registerInstruction('script', ScriptInstruction);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user