From 9a376e411638121ff3def8ebec5da51a14cc771f Mon Sep 17 00:00:00 2001 From: Junyi Date: Fri, 9 Jun 2023 11:09:22 +0700 Subject: [PATCH] refactor(plugin-workflow): change node config api render to component (#2014) * refactor(plugin-workflow): change node config api render to component * fix(plugin-workflow): fix trigger drawer error and remove unused api * fix(plugin-workflow): fix return value of request node run phase * fix(client): fix classname order in action button --- .../client/src/schema-component/antd/action/Action.tsx | 2 +- packages/plugins/workflow/src/client/nodes/condition.tsx | 2 +- packages/plugins/workflow/src/client/nodes/index.tsx | 8 ++++---- packages/plugins/workflow/src/client/nodes/loop.tsx | 2 +- packages/plugins/workflow/src/client/nodes/parallel.tsx | 2 +- packages/plugins/workflow/src/client/triggers/index.tsx | 5 ++--- .../plugins/workflow/src/server/instructions/request.ts | 2 +- 7 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/action/Action.tsx b/packages/core/client/src/schema-component/antd/action/Action.tsx index 4bc2d2c2b..8555c356d 100644 --- a/packages/core/client/src/schema-component/antd/action/Action.tsx +++ b/packages/core/client/src/schema-component/antd/action/Action.tsx @@ -140,7 +140,7 @@ export const Action: ComposedAction = observer( } }} component={tarComponent || Button} - className={classnames(className, actionDesignerCss)} + className={classnames(actionDesignerCss, className)} > {title || compile(fieldSchema.title)} diff --git a/packages/plugins/workflow/src/client/nodes/condition.tsx b/packages/plugins/workflow/src/client/nodes/condition.tsx index c77ac2e22..5ce957618 100644 --- a/packages/plugins/workflow/src/client/nodes/condition.tsx +++ b/packages/plugins/workflow/src/client/nodes/condition.tsx @@ -413,7 +413,7 @@ export default { value: { rejectOnFalse: false }, }, ], - render: function Renderer(data) { + component: function Component({ data }) { const { t } = useTranslation(); const { nodes } = useFlowContext(); const { diff --git a/packages/plugins/workflow/src/client/nodes/index.tsx b/packages/plugins/workflow/src/client/nodes/index.tsx index ddb799123..3e35779df 100644 --- a/packages/plugins/workflow/src/client/nodes/index.tsx +++ b/packages/plugins/workflow/src/client/nodes/index.tsx @@ -51,7 +51,7 @@ export interface Instruction { view?: ISchema; scope?: { [key: string]: any }; components?: { [key: string]: any }; - render?(props): JSX.Element; + component?(props): JSX.Element; endding?: boolean; useVariables?(node, options?): VariableOptions; useScopeVariables?(node, options?): VariableOptions; @@ -137,13 +137,13 @@ export function useUpstreamScopes(node) { } export function Node({ data }) { - const instruction = instructions.get(data.type); + const { component: Component = NodeDefaultView, endding } = instructions.get(data.type); return (
- {instruction.render ? instruction.render(data) : } - {!instruction.endding ? ( + + {!endding ? ( ) : (
node.upstreamId === data.id && node.branchIndex != null); diff --git a/packages/plugins/workflow/src/client/nodes/parallel.tsx b/packages/plugins/workflow/src/client/nodes/parallel.tsx index e9e825814..03d5a5fc7 100644 --- a/packages/plugins/workflow/src/client/nodes/parallel.tsx +++ b/packages/plugins/workflow/src/client/nodes/parallel.tsx @@ -44,7 +44,7 @@ export default { }, }, view: {}, - render(data) { + component: function Component({ data }) { const { id, config: { mode }, diff --git a/packages/plugins/workflow/src/client/triggers/index.tsx b/packages/plugins/workflow/src/client/triggers/index.tsx index d2444dd7a..80c1bafba 100644 --- a/packages/plugins/workflow/src/client/triggers/index.tsx +++ b/packages/plugins/workflow/src/client/triggers/index.tsx @@ -58,7 +58,6 @@ export interface Trigger { view?: ISchema; scope?: { [key: string]: any }; components?: { [key: string]: any }; - render?(props): React.ReactNode; useInitializers?(config): SchemaInitializerItemOptions | null; initializers?: any; } @@ -86,7 +85,7 @@ function TriggerExecution() { 'x-component-props': { title: , shape: 'circle', - className: cx(nodeJobButtonClass, 'workflow-node-job-button'), + className: nodeJobButtonClass, type: 'primary', }, properties: { @@ -178,7 +177,7 @@ export const TriggerConfig = () => { } const whiteSet = new Set(['workflow-node-meta', 'workflow-node-config-button', 'ant-input-disabled']); for (let el = ev.target; el && el !== ev.currentTarget; el = el.parentNode) { - if ((Array.from(el.classList) as string[]).some((name: string) => whiteSet.has(name))) { + if ((Array.from(el.classList ?? []) as string[]).some((name: string) => whiteSet.has(name))) { setEditingConfig(true); ev.stopPropagation(); return; diff --git a/packages/plugins/workflow/src/server/instructions/request.ts b/packages/plugins/workflow/src/server/instructions/request.ts index 135e1eb93..5b1db106a 100644 --- a/packages/plugins/workflow/src/server/instructions/request.ts +++ b/packages/plugins/workflow/src/server/instructions/request.ts @@ -73,7 +73,7 @@ export default class implements Instruction { this.plugin.app.logger.info(`[Workflow] request (#${node.id}) sent to "${config.url}", waiting for response...`); - return job; + return null; } async resume(node: FlowNodeModel, job, processor: Processor) {