refactor(plugin-workflow): add isAvailable check for adding node (#2898)

This commit is contained in:
Junyi 2023-10-23 21:15:55 +08:00 committed by GitHub
parent 08f213bc16
commit ab9457c7fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 6 deletions

View File

@ -28,7 +28,11 @@ export function AddButton({ upstream, branchIndex = null }: AddButtonProps) {
]
.filter((group) => instructionList.filter((item) => item.group === group.key).length)
.map((group) => {
const groupInstructions = instructionList.filter((item) => item.group === group.key);
const groupInstructions = instructionList.filter(
(item) =>
item.group === group.key &&
(item.isAvailable ? item.isAvailable({ workflow, upstream, branchIndex }) : true),
);
return {
...group,

View File

@ -3,7 +3,7 @@ export * from './Branch';
export * from './FlowContext';
export * from './nodes';
export { triggers, useTrigger, getTriggersOptions } from './triggers';
export { useWorkflowVariableOptions } from './variable';
export { useWorkflowVariableOptions, getCollectionFieldOptions } from './variable';
import { Plugin } from '@nocobase/client';
import React from 'react';

View File

@ -13,14 +13,15 @@ import {
useResourceActionContext,
} from '@nocobase/client';
import { Registry, parse, str2moment } from '@nocobase/utils/client';
import { Alert, App, Button, Dropdown, Input, Tag, message } from 'antd';
import { App, Button, Dropdown, Input, Tag, message } from 'antd';
import React, { useContext, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { AddButton } from '../AddButton';
import { useFlowContext } from '../FlowContext';
import { DrawerDescription } from '../components/DrawerDescription';
import { StatusButton } from '../components/StatusButton';
import { JobStatusOptionsMap } from '../constants';
import { NAMESPACE, lang } from '../locale';
import { lang } from '../locale';
import useStyles from '../style';
import { VariableOption, VariableOptions } from '../variable';
import aggregate from './aggregate';
@ -36,7 +37,6 @@ import query from './query';
import request from './request';
import sql from './sql';
import update from './update';
import { StatusButton } from '../components/StatusButton';
export interface Instruction {
title: string;
@ -54,6 +54,7 @@ export interface Instruction {
useScopeVariables?(node, options?): VariableOptions;
useInitializers?(node): SchemaInitializerItemOptions | null;
initializers?: { [key: string]: any };
isAvailable?(ctx: object): boolean;
}
export const instructions = new Registry<Instruction>();

View File

@ -8,7 +8,7 @@ import { useWorkflowVariableOptions } from '../variable';
export default {
title: `{{t("SQL action", { ns: "${NAMESPACE}" })}}`,
type: 'sql',
group: 'extended',
group: 'collection',
description: `{{t("Execute a SQL statement in database.", { ns: "${NAMESPACE}" })}}`,
fieldset: {
sql: {