Refactor-rename PortMode to PortType
This commit is contained in:
parent
b996d1d393
commit
de9b3e866b
|
|
@ -116,13 +116,13 @@ export interface OutputDescriptor extends PropertyDescriptor {
|
|||
export interface Port {
|
||||
name: string;
|
||||
displayName: string;
|
||||
mode: PortMode;
|
||||
type: PortType;
|
||||
isBrowsable?: boolean;
|
||||
}
|
||||
|
||||
export enum PortMode {
|
||||
export enum PortType {
|
||||
Embedded = 'Embedded',
|
||||
Port = 'Port'
|
||||
Flow = 'Flow'
|
||||
}
|
||||
|
||||
export interface CompletionCallbackState {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {Component, h, Prop, State, Event, EventEmitter, Listen, Element} from "@stencil/core";
|
||||
import {ActivityIconProducer, ActivityIconRegistry, PortProviderRegistry} from "../../services";
|
||||
import {Container} from "typedi";
|
||||
import {Activity, ActivityDescriptor, ActivityKind, ActivitySelectedArgs, ChildActivitySelectedArgs, EditChildActivityArgs, Port, PortMode} from "../../models";
|
||||
import {Activity, ActivityDescriptor, ActivityKind, ActivitySelectedArgs, ChildActivitySelectedArgs, EditChildActivityArgs, Port, PortType} from "../../models";
|
||||
import descriptorsStore from "../../data/descriptors-store";
|
||||
import {isNullOrWhitespace} from "../../utils";
|
||||
import FlowchartTunnel from "./state";
|
||||
|
|
@ -52,7 +52,7 @@ export class DefaultActivityTemplate {
|
|||
{({nodeMap}) => {
|
||||
const activity: Activity = nodeMap[activityId];
|
||||
const ports = portProvider.getOutboundPorts({activityDescriptor, activity});
|
||||
const embeddedPorts = ports.filter(x => x.mode == PortMode.Embedded && x.isBrowsable !== false);
|
||||
const embeddedPorts = ports.filter(x => x.type == PortType.Embedded && x.isBrowsable !== false);
|
||||
const canStartWorkflow = activity?.customProperties?.CanStartWorkflow ?? activity?.canStartWorkflow ?? false;
|
||||
const icon = this.icon;
|
||||
const hasIcon = !!icon;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import {Node} from "@antv/x6";
|
|||
import {Container, Service} from "typedi"
|
||||
import {ActivityNodeHandler, UINodeContext, UIPortContext} from "./activity-node-handler";
|
||||
import {PortProviderContext, PortProviderRegistry} from "../../services";
|
||||
import {PortMode} from "../../models";
|
||||
import {PortType} from "../../models";
|
||||
import {v4 as uuid} from 'uuid';
|
||||
|
||||
@Service()
|
||||
|
|
@ -34,12 +34,12 @@ export class DefaultNodeHandler implements ActivityNodeHandler {
|
|||
const {activityDescriptor, activity} = context;
|
||||
const provider = this.portProviderRegistry.get(activityDescriptor.typeName);
|
||||
const providerContext: PortProviderContext = {activityDescriptor, activity};
|
||||
const inPorts = [{name: 'In', displayName: null, mode: PortMode.Port}];
|
||||
let outPorts = provider.getOutboundPorts(providerContext).filter(x => x.mode == PortMode.Port);
|
||||
const inPorts = [{name: 'In', displayName: null, mode: PortType.Flow}];
|
||||
let outPorts = provider.getOutboundPorts(providerContext).filter(x => x.type == PortType.Flow);
|
||||
|
||||
// In a flowchart, always add a Done port to connect the next node.
|
||||
if (outPorts.length == 0)
|
||||
outPorts = [{name: 'Done', displayName: 'Done', mode: PortMode.Port}];
|
||||
outPorts = [{name: 'Done', displayName: 'Done', type: PortType.Flow}];
|
||||
|
||||
if (outPorts.length == 1)
|
||||
outPorts[0].displayName = null;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import 'reflect-metadata';
|
||||
import {Service} from "typedi";
|
||||
import {Activity, ActivityInput, InputDescriptor, ObjectExpression, Port, PortMode} from "../../../models";
|
||||
import {Activity, ActivityInput, InputDescriptor, ObjectExpression, Port, PortType} from "../../../models";
|
||||
import {PortProvider, PortProviderContext} from "../../../services";
|
||||
import {FlowSendHttpRequest} from "./models";
|
||||
|
||||
|
|
@ -15,13 +15,13 @@ export class FlowHttpRequestPortProvider implements PortProvider {
|
|||
|
||||
const expectedStatusCodes = activity.expectedStatusCodes as ActivityInput;
|
||||
|
||||
if(!expectedStatusCodes)
|
||||
if (!expectedStatusCodes)
|
||||
return [];
|
||||
|
||||
const statusCodesJson = (expectedStatusCodes.expression as ObjectExpression).value;
|
||||
const statusCodes = JSON.parse(statusCodesJson) as Array<string>;
|
||||
const catchAllPort = {name: 'Unmatched status code', displayName: 'Unmatched status code', mode: PortMode.Port};
|
||||
const outcomes = [...statusCodes.map(x => ({name: x.toString(), displayName: x.toString(), mode: PortMode.Port})), catchAllPort];
|
||||
const catchAllPort: Port = {name: 'Unmatched status code', displayName: 'Unmatched status code', type: PortType.Flow};
|
||||
const outcomes: Port[] = [...statusCodes.map(x => ({name: x.toString(), displayName: x.toString(), type: PortType.Flow})), catchAllPort];
|
||||
|
||||
return outcomes;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import 'reflect-metadata';
|
||||
import {Service} from "typedi";
|
||||
import {Activity, Port, PortMode} from "../../../models";
|
||||
import {Activity, Port, PortType} from "../../../models";
|
||||
import {PortProvider, PortProviderContext} from "../../../services";
|
||||
import {HttpStatusCodeCase, SendHttpRequest} from "./models";
|
||||
|
||||
|
|
@ -10,12 +10,12 @@ export class HttpRequestPortProvider implements PortProvider {
|
|||
getOutboundPorts(context: PortProviderContext): Array<Port> {
|
||||
const activity = context.activity as SendHttpRequest;
|
||||
|
||||
if(activity == null)
|
||||
if (activity == null)
|
||||
return [];
|
||||
|
||||
const defaultPort = {name: 'unmatchedStatusCode', displayName: 'Unmatched status code', mode: PortMode.Embedded}; // Hide the port from the designer until the editor uI is finished.
|
||||
const defaultPort: Port = {name: 'unmatchedStatusCode', displayName: 'Unmatched status code', type: PortType.Embedded}; // Hide the port from the designer until the editor uI is finished.
|
||||
const statusCodes = activity.expectedStatusCodes ?? [];
|
||||
const ports = statusCodes.map(x => ({name: x.statusCode.toString(), displayName: x.statusCode.toString(), mode: PortMode.Embedded}));
|
||||
const ports: Port[] = statusCodes.map(x => ({name: x.statusCode.toString(), displayName: x.statusCode.toString(), type: PortType.Embedded}));
|
||||
|
||||
return [...ports, defaultPort];
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ export class HttpRequestPortProvider implements PortProvider {
|
|||
resolvePort(portName: string, context: PortProviderContext): Activity | Array<Activity> {
|
||||
const activity = context.activity as SendHttpRequest;
|
||||
|
||||
if(portName == 'unmatchedStatusCode')
|
||||
if (portName == 'unmatchedStatusCode')
|
||||
return activity.unmatchedStatusCode;
|
||||
|
||||
const expectedStatusCodes: Array<HttpStatusCodeCase> = activity.expectedStatusCodes ?? [];
|
||||
|
|
@ -32,9 +32,9 @@ export class HttpRequestPortProvider implements PortProvider {
|
|||
}
|
||||
|
||||
assignPort(portName: string, activity: Activity, context: PortProviderContext) {
|
||||
const sendHttpRequestActivity = context.activity as SendHttpRequest;
|
||||
const sendHttpRequestActivity = context.activity as SendHttpRequest;
|
||||
|
||||
if(portName == 'unmatchedStatusCode') {
|
||||
if (portName == 'unmatchedStatusCode') {
|
||||
sendHttpRequestActivity.unmatchedStatusCode = activity;
|
||||
return;
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ export class HttpRequestPortProvider implements PortProvider {
|
|||
const statusCodes = sendHttpRequestActivity.expectedStatusCodes ?? [];
|
||||
const matchingStatusCode = statusCodes.find(x => x.statusCode.toString() === portName);
|
||||
|
||||
if(!matchingStatusCode)
|
||||
if (!matchingStatusCode)
|
||||
return;
|
||||
|
||||
matchingStatusCode.activity = activity;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import 'reflect-metadata';
|
||||
import {Service} from "typedi";
|
||||
import {Activity, Port, PortMode} from "../../../models";
|
||||
import {Activity, Port, PortType} from "../../../models";
|
||||
import {FlowSwitchActivity} from "./models";
|
||||
import {PortProvider, PortProviderContext} from "../../../services";
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ export class FlowSwitchPortProvider implements PortProvider {
|
|||
return [];
|
||||
|
||||
const cases = activity.cases ?? [];
|
||||
return cases.map(x => ({name: x.label, displayName: x.label, mode: PortMode.Port}));
|
||||
return cases.map(x => ({name: x.label, displayName: x.label, type: PortType.Flow}));
|
||||
}
|
||||
|
||||
resolvePort(portName: string, context: PortProviderContext): Activity | Array<Activity> {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import 'reflect-metadata';
|
||||
import {Service} from "typedi";
|
||||
import {Activity, Port, PortMode} from "../../../models";
|
||||
import {Activity, Port, PortType} from "../../../models";
|
||||
import {SwitchActivity, SwitchCase} from "./models";
|
||||
import {PortProvider, PortProviderContext} from "../../../services";
|
||||
|
||||
|
|
@ -10,25 +10,25 @@ export class SwitchPortProvider implements PortProvider {
|
|||
getOutboundPorts(context: PortProviderContext): Array<Port> {
|
||||
const activity = context.activity as SwitchActivity;
|
||||
|
||||
if(activity == null)
|
||||
if (activity == null)
|
||||
return [];
|
||||
|
||||
const cases = activity.cases ?? [];
|
||||
const ports = cases.map(x => ({name: x.label, displayName: x.label, mode: PortMode.Embedded}));
|
||||
const defaultPort = {name: 'default', displayName: 'Default', mode: PortMode.Embedded};
|
||||
const ports: Port[] = cases.map(x => ({name: x.label, displayName: x.label, type: PortType.Embedded}));
|
||||
const defaultPort: Port = {name: 'default', displayName: 'Default', type: PortType.Embedded};
|
||||
return [...ports, defaultPort];
|
||||
}
|
||||
|
||||
resolvePort(portName: string, context: PortProviderContext): Activity | Array<Activity> {
|
||||
const activity = context.activity as SwitchActivity;
|
||||
|
||||
if(portName == 'default')
|
||||
if (portName == 'default')
|
||||
return activity.default;
|
||||
|
||||
const cases: Array<SwitchCase> = activity.cases ?? [];
|
||||
const caseItem = cases.find(x => x.label == portName);
|
||||
|
||||
if(!caseItem)
|
||||
if (!caseItem)
|
||||
return null;
|
||||
|
||||
return caseItem.activity;
|
||||
|
|
@ -37,7 +37,7 @@ export class SwitchPortProvider implements PortProvider {
|
|||
assignPort(portName: string, activity: Activity, context: PortProviderContext) {
|
||||
const switchActivity = context.activity as SwitchActivity;
|
||||
|
||||
if(portName == 'default') {
|
||||
if (portName == 'default') {
|
||||
switchActivity.default = activity;
|
||||
return;
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ export class SwitchPortProvider implements PortProvider {
|
|||
const cases: Array<SwitchCase> = switchActivity.cases ?? [];
|
||||
const caseItem = cases.find(x => x.label == portName);
|
||||
|
||||
if(!caseItem)
|
||||
if (!caseItem)
|
||||
return null;
|
||||
|
||||
caseItem.activity = activity;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,27 @@
|
|||
namespace Elsa.Workflows.Core.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a port on an activity.
|
||||
/// </summary>
|
||||
public class Port
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the port.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the display name of the port.
|
||||
/// </summary>
|
||||
public string? DisplayName { get; set; }
|
||||
public PortMode Mode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the type of the port.
|
||||
/// </summary>
|
||||
public PortType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the visibility of the port.
|
||||
/// </summary>
|
||||
public bool IsBrowsable { get; set; } = true;
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
namespace Elsa.Workflows.Core.Models;
|
||||
|
||||
public enum PortMode
|
||||
{
|
||||
Embedded,
|
||||
Port
|
||||
}
|
||||
17
src/modules/Elsa.Workflows.Core/Models/PortType.cs
Normal file
17
src/modules/Elsa.Workflows.Core/Models/PortType.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
namespace Elsa.Workflows.Core.Models;
|
||||
|
||||
/// <summary>
|
||||
/// The type of a port.
|
||||
/// </summary>
|
||||
public enum PortType
|
||||
{
|
||||
/// <summary>
|
||||
/// A port that is embedded in the activity.
|
||||
/// </summary>
|
||||
Embedded,
|
||||
|
||||
/// <summary>
|
||||
/// A flow port.
|
||||
/// </summary>
|
||||
Flow
|
||||
}
|
||||
|
|
@ -53,14 +53,14 @@ public class ActivityDescriber : IActivityDescriber
|
|||
{
|
||||
Name = portAttr?.Name ?? prop.Name,
|
||||
DisplayName = portAttr?.DisplayName ?? portAttr?.Name ?? prop.Name,
|
||||
Mode = PortMode.Embedded,
|
||||
Type = PortType.Embedded,
|
||||
IsBrowsable = portAttr != null && (portBrowsableAttr == null || portBrowsableAttr.Browsable)
|
||||
};
|
||||
|
||||
var flowNodeAttr = activityType.GetCustomAttribute<FlowNodeAttribute>();
|
||||
var flowPorts = flowNodeAttr?.Outcomes.Select(x => new Port
|
||||
{
|
||||
Mode = PortMode.Port,
|
||||
Type = PortType.Flow,
|
||||
Name = x,
|
||||
DisplayName = x
|
||||
}).ToDictionary(x => x.Name) ?? new Dictionary<string, Port>();
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class WorkflowDefinitionActivityProvider : IActivityProvider
|
|||
Name = outcome,
|
||||
DisplayName = outcome,
|
||||
IsBrowsable = true,
|
||||
Mode = PortMode.Port
|
||||
Type = PortType.Flow
|
||||
}).ToList();
|
||||
|
||||
var rootPort = new Port
|
||||
|
|
@ -64,7 +64,7 @@ public class WorkflowDefinitionActivityProvider : IActivityProvider
|
|||
Name = nameof(WorkflowDefinitionActivity.Root),
|
||||
DisplayName = "Root",
|
||||
IsBrowsable = false,
|
||||
Mode = PortMode.Embedded
|
||||
Type = PortType.Embedded
|
||||
};
|
||||
|
||||
ports.Insert(0, rootPort);
|
||||
|
|
|
|||
Loading…
Reference in a new issue