From 4949c402bcde19306148ec5e0903254cf839bc15 Mon Sep 17 00:00:00 2001 From: axeleron007 Date: Fri, 1 Oct 2021 14:49:49 +0300 Subject: [PATCH] PR requested changes --- .../elsa-script-property.tsx | 35 ++++++------ ...elsa-workflow-definition-editor-screen.tsx | 55 ++++++++++++------- .../localizations.ts | 6 +- .../src/models/domain.ts | 1 + .../src/models/events.ts | 18 ++++-- .../src/plugins/http-endpoint-plugin.tsx | 45 +++++++++++---- .../ActivityExecutionResultExecutedHandler.cs | 20 ++----- .../Models/WorkflowTestMessage.cs | 1 + 8 files changed, 110 insertions(+), 71 deletions(-) diff --git a/src/designer/elsa-workflows-studio/src/components/editors/properties/elsa-script-property/elsa-script-property.tsx b/src/designer/elsa-workflows-studio/src/components/editors/properties/elsa-script-property/elsa-script-property.tsx index b87d6905d..9d15715fe 100644 --- a/src/designer/elsa-workflows-studio/src/components/editors/properties/elsa-script-property/elsa-script-property.tsx +++ b/src/designer/elsa-workflows-studio/src/components/editors/properties/elsa-script-property/elsa-script-property.tsx @@ -3,7 +3,8 @@ import { ActivityDefinitionProperty, ActivityPropertyDescriptor, ActivityValidatingContext, - ConfigureScriptPropertyCustomButtonContext, + ConfigureComponentCustomButtonContext, + ComponentCustomButtonClickContext, EventTypes} from "../../../../models"; import {createElsaClient, eventBus} from "../../../../services"; import Tunnel from '../../../../data/workflow-editor'; @@ -26,12 +27,12 @@ export class ElsaScriptProperty { @State() currentValue?: string; monacoEditor: HTMLElsaMonacoElement; - private activityValidatingContext: ActivityValidatingContext = null; - private scriptPropertyCustomButtonContext: ConfigureScriptPropertyCustomButtonContext = null; + activityValidatingContext: ActivityValidatingContext = null; + configureComponentCustomButtonContext: ConfigureComponentCustomButtonContext = null; async componentWillLoad() { this.currentValue = this.propertyModel.expressions['Literal']; - this.configureScriptPropertyCustomButton(); + this.configureComponentCustomButton(); this.validate(this.currentValue); } @@ -42,13 +43,14 @@ export class ElsaScriptProperty { await this.monacoEditor.addJavaScriptLib(libSource, libUri); } - async configureScriptPropertyCustomButton() { - this.scriptPropertyCustomButtonContext = { + async configureComponentCustomButton() { + this.configureComponentCustomButtonContext = { + component: 'elsa-script-property', activityType: this.context, prop: this.propertyDescriptor.name, data: null }; - await eventBus.emit(EventTypes.ScriptPropertyLoadingCustomButton, this, this.scriptPropertyCustomButtonContext); + await eventBus.emit(EventTypes.ComponentLoadingCustomButton, this, this.configureComponentCustomButtonContext); } mapSyntaxToLanguage(syntax: string): any { @@ -63,14 +65,15 @@ export class ElsaScriptProperty { } } - onCustomButtonClick(e: Event) { + onComponentCustomButtonClick(e: Event) { e.preventDefault(); - this.scriptPropertyCustomButtonContext = { + const componentCustomButtonClickContext: ComponentCustomButtonClickContext = { + component: 'elsa-script-property', activityType: this.context, prop: this.propertyDescriptor.name, - data: null + params: null }; - eventBus.emit(EventTypes.ScriptPropertyCustomButtonClick, this, this.scriptPropertyCustomButtonContext); + eventBus.emit(EventTypes.ComponentCustomButtonClick, this, componentCustomButtonClickContext); } onMonacoValueChanged(e: MonacoValueChangedArgs) { @@ -117,16 +120,16 @@ export class ElsaScriptProperty { ) } - const renderCustomButton = () => { - if (this.scriptPropertyCustomButtonContext.data == null) + const renderComponentCustomButton = () => { + if (this.configureComponentCustomButtonContext.data == null) return; - const label = this.scriptPropertyCustomButtonContext.data.label; + const label = this.configureComponentCustomButtonContext.data.label; return (
this.onCustomButtonClick(e)} + onClick={e => this.onComponentCustomButtonClick(e)} class="elsa-relative elsa-inline-flex elsa-items-center elsa-px-4 elsa-py-2 elsa-border elsa-border-gray-300 elsa-text-sm elsa-leading-5 elsa-font-medium elsa-rounded-md elsa-text-gray-700 elsa-bg-white hover:elsa-text-gray-500 focus:elsa-outline-none focus:elsa-shadow-outline-blue focus:elsa-border-blue-300 active:elsa-bg-gray-100 active:elsa-text-gray-700 elsa-transition elsa-ease-in-out elsa-duration-150"> {label} @@ -165,7 +168,7 @@ export class ElsaScriptProperty { {fieldHint ?

{fieldHint}

: undefined} {renderValidationResult()} - {renderCustomButton()} + {renderComponentCustomButton()}
} } diff --git a/src/designer/elsa-workflows-studio/src/components/screens/workflow-definition-editor/elsa-workflow-definition-editor-screen/elsa-workflow-definition-editor-screen.tsx b/src/designer/elsa-workflows-studio/src/components/screens/workflow-definition-editor/elsa-workflow-definition-editor-screen/elsa-workflow-definition-editor-screen.tsx index a3316c888..0210e8f95 100644 --- a/src/designer/elsa-workflows-studio/src/components/screens/workflow-definition-editor/elsa-workflow-definition-editor-screen/elsa-workflow-definition-editor-screen.tsx +++ b/src/designer/elsa-workflows-studio/src/components/screens/workflow-definition-editor/elsa-workflow-definition-editor-screen/elsa-workflow-definition-editor-screen.tsx @@ -3,8 +3,9 @@ import {RouterHistory, injectHistory} from '@stencil/router'; import { ActivityDefinition, ActivityDescriptor, - ActivityModel, - ActivityUpdatedContext, + ActivityModel, + ConfigureComponentCustomButtonContext, + ComponentCustomButtonClickContext, ConnectionDefinition, ConnectionModel, EventTypes, @@ -25,7 +26,6 @@ import {i18n} from "i18next"; import {loadTranslations} from "../../../i18n/i18n-loader"; import {resources} from "./localizations"; import * as collection from 'lodash/collection'; -import {convert} from 'json-to-json-schema'; @Component({ tag: 'elsa-workflow-definition-editor-screen', @@ -78,6 +78,7 @@ export class ElsaWorkflowDefinitionEditorScreen { i18next: i18n; el: HTMLElement; designer: HTMLElsaDesignerTreeElement; + configureComponentCustomButtonContext: ConfigureComponentCustomButtonContext = null; @Method() async getServerUrl(): Promise { @@ -189,6 +190,16 @@ export class ElsaWorkflowDefinitionEditorScreen { eventBus.detach(EventTypes.TestActivityMessageReceived, this.onTestActivityMessageReceived); } + async configureComponentCustomButton(message: WorkflowTestActivityMessage) { + this.configureComponentCustomButtonContext = { + component: 'elsa-workflow-definition-editor-screen', + activityType: message.activityType, + prop: null, + data: null + }; + await eventBus.emit(EventTypes.ComponentLoadingCustomButton, this, this.configureComponentCustomButtonContext); + } + t = (key: string) => this.i18next.t(key); async loadActivityDescriptors() { @@ -574,16 +585,18 @@ export class ElsaWorkflowDefinitionEditorScreen { ); } - async onUseAsSchemaClick(message: WorkflowTestActivityMessage) { - const value = message.data["Body"]; + async onComponentCustomButtonClick(message: WorkflowTestActivityMessage) { let workflowModel = {...this.workflowModel}; const activityModel = workflowModel.activities.find(x => x.activityId == message.activityId); + const value = message.data["Body"]; - const context: ActivityUpdatedContext = { - activityModel: activityModel, - data: JSON.stringify(convert(value), null, 1) - }; - eventBus.emit(EventTypes.ActivityPluginUpdated, this, context); + const componentCustomButtonClickContext: ComponentCustomButtonClickContext = { + component: 'elsa-workflow-definition-editor-screen', + activityType: message.activityType, + prop: null, + params: [activityModel, value] + }; + eventBus.emit(EventTypes.ComponentCustomButtonClick, this, componentCustomButtonClickContext); } renderTestActivityMenu = () => { @@ -614,7 +627,9 @@ export class ElsaWorkflowDefinitionEditorScreen { const renderMessage = () => { if (message == undefined || !message) - return + return; + + this.configureComponentCustomButton(message); const t = (x, params?) => this.i18next.t(x, params); const filteredData = {}; @@ -670,25 +685,28 @@ export class ElsaWorkflowDefinitionEditorScreen {

))} - {hasBody ? renderUseAsSchemaButton() : undefined} + {hasBody ? renderComponentCustomButton() : undefined} {renderActivityTestError()} ); }; - const renderUseAsSchemaButton = () => { + const renderComponentCustomButton = () => { - const t = (x, params?) => this.i18next.t(x, params); + if (this.configureComponentCustomButtonContext.data == null) + return; + + const label = this.configureComponentCustomButtonContext.data.label; return (
- ) + ) }; const renderLoader = function () { @@ -708,8 +726,7 @@ export class ElsaWorkflowDefinitionEditorScreen { registerClickOutside(this, el, () => { this.handleContextMenuTestChange(0, 0, false, null); }) - } - > + }>
{!!message ? renderMessage() : renderLoader()}
diff --git a/src/designer/elsa-workflows-studio/src/components/screens/workflow-definition-editor/elsa-workflow-definition-editor-screen/localizations.ts b/src/designer/elsa-workflows-studio/src/components/screens/workflow-definition-editor/elsa-workflow-definition-editor-screen/localizations.ts index 43153ecec..e09fb4ff5 100644 --- a/src/designer/elsa-workflows-studio/src/components/screens/workflow-definition-editor/elsa-workflow-definition-editor-screen/localizations.ts +++ b/src/designer/elsa-workflows-studio/src/components/screens/workflow-definition-editor/elsa-workflow-definition-editor-screen/localizations.ts @@ -9,8 +9,7 @@ }, "ConnectionContextMenu":{ "Paste": "Paste", - }, - 'UseAsSchema': 'Use as Schema' + } } }, 'nl-NL': { @@ -23,8 +22,7 @@ }, "ConnectionContextMenu":{ "Paste": "Plakken", - }, - 'UseAsSchema': 'Gebruik als schema' + } } } }; \ No newline at end of file diff --git a/src/designer/elsa-workflows-studio/src/models/domain.ts b/src/designer/elsa-workflows-studio/src/models/domain.ts index 58772ed84..bb1905359 100644 --- a/src/designer/elsa-workflows-studio/src/models/domain.ts +++ b/src/designer/elsa-workflows-studio/src/models/domain.ts @@ -324,6 +324,7 @@ export class SyntaxNames { } export interface WorkflowTestActivityMessage { + activityType: string; workflowInstanceId: string; correlationId: string; activityId: string; diff --git a/src/designer/elsa-workflows-studio/src/models/events.ts b/src/designer/elsa-workflows-studio/src/models/events.ts index 7100f0d39..e5fffb546 100644 --- a/src/designer/elsa-workflows-studio/src/models/events.ts +++ b/src/designer/elsa-workflows-studio/src/models/events.ts @@ -40,8 +40,8 @@ export const EventTypes = { PasteActivity: 'paste-activity', TestActivityMessageReceived: 'test-activity-message-received', FlyoutPanelTabSelected: 'flyout-panel-tab-selected', - ScriptPropertyLoadingCustomButton: 'script-property-loading-custom-button', - ScriptPropertyCustomButtonClick: 'script-property-custom-button-click' + ComponentLoadingCustomButton: 'component-loading-custom-button', + ComponentCustomButtonClick: 'component-custom-button-click' }; export interface AddActivityEventArgs { @@ -92,8 +92,16 @@ export interface ConfigureWorkflowRegistryUpdatingContext { params: any; } -export interface ConfigureScriptPropertyCustomButtonContext { - activityType: string - prop: string, +export interface ConfigureComponentCustomButtonContext { + component: string; + activityType: string; + prop: string; data?: any; } + +export interface ComponentCustomButtonClickContext { + component: string; + activityType: string; + prop: string; + params: any; +} diff --git a/src/designer/elsa-workflows-studio/src/plugins/http-endpoint-plugin.tsx b/src/designer/elsa-workflows-studio/src/plugins/http-endpoint-plugin.tsx index 22bd93b86..f8610e763 100644 --- a/src/designer/elsa-workflows-studio/src/plugins/http-endpoint-plugin.tsx +++ b/src/designer/elsa-workflows-studio/src/plugins/http-endpoint-plugin.tsx @@ -4,18 +4,20 @@ import { ActivityUpdatedContext, ActivityValidatingContext, EventTypes, - ConfigureScriptPropertyCustomButtonContext, + ConfigureComponentCustomButtonContext, + ComponentCustomButtonClickContext, SyntaxNames} from "../models"; import {htmlEncode} from "../utils/utils"; import Ajv from "ajv" +import {convert} from 'json-to-json-schema'; export class HttpEndpointPlugin implements ElsaPlugin { constructor() { eventBus.on(EventTypes.ActivityDesignDisplaying, this.onActivityDisplaying); eventBus.on(EventTypes.ActivityPluginUpdated, this.onActivityUpdated); eventBus.on(EventTypes.ActivityPluginValidating, this.onActivityValidating); - eventBus.on(EventTypes.ScriptPropertyLoadingCustomButton, this.onLoadingCustomButton); - eventBus.on(EventTypes.ScriptPropertyCustomButtonClick, this.onCustomButtonClick); + eventBus.on(EventTypes.ComponentLoadingCustomButton, this.onComponentLoadingCustomButton); + eventBus.on(EventTypes.ComponentCustomButtonClick, this.onComponentCustomButtonClick); } onActivityDisplaying(context: ActivityDesignDisplayContext) { @@ -31,19 +33,40 @@ export class HttpEndpointPlugin implements ElsaPlugin { context.bodyDisplay = `

${bodyDisplay}

`; } - onLoadingCustomButton(context: ConfigureScriptPropertyCustomButtonContext) { - if (context.activityType !== 'HttpEndpoint' || context.prop !== 'Schema') + onComponentLoadingCustomButton(context: ConfigureComponentCustomButtonContext) { + if (context.activityType !== 'HttpEndpoint') return; - const label: string = 'Convert to Json Schema'; - context.data = {label}; + if (context.component === 'elsa-script-property') { + if (context.prop !== 'Schema') + return; + const label: string = 'Convert to Json Schema'; + context.data = {label}; + } + + if (context.component === 'elsa-workflow-definition-editor-screen') { + const label: string = 'Use as Schema'; + context.data = {label}; + } } - onCustomButtonClick(context: ConfigureScriptPropertyCustomButtonContext) { - if (context.activityType !== 'HttpEndpoint' || context.prop !== 'Schema') + onComponentCustomButtonClick(context: ComponentCustomButtonClickContext) { + if (context.activityType !== 'HttpEndpoint') return; - - window.open('https://www.convertsimple.com/convert-json-to-json-schema/'); + + if (context.component === 'elsa-script-property') { + if (context.prop !== 'Schema') + return; + window.open('https://www.convertsimple.com/convert-json-to-json-schema/'); + } + + if (context.component === 'elsa-workflow-definition-editor-screen') { + const activityUpdatedContext: ActivityUpdatedContext = { + activityModel: context.params[0], + data: JSON.stringify(convert(context.params[1]), null, 1) + }; + eventBus.emit(EventTypes.ActivityPluginUpdated, this, activityUpdatedContext); + } } onActivityUpdated(context: ActivityUpdatedContext) { diff --git a/src/server/Elsa.Server.Api/Handlers/ActivityExecutionResultExecutedHandler.cs b/src/server/Elsa.Server.Api/Handlers/ActivityExecutionResultExecutedHandler.cs index aebf2b11e..176921848 100644 --- a/src/server/Elsa.Server.Api/Handlers/ActivityExecutionResultExecutedHandler.cs +++ b/src/server/Elsa.Server.Api/Handlers/ActivityExecutionResultExecutedHandler.cs @@ -24,7 +24,6 @@ namespace Elsa.Server.Api.Handlers public async Task Handle(ActivityExecutionResultExecuted notification, CancellationToken cancellationToken) { var context = notification.ActivityExecutionContext; - //string? path = default; var signalRConnectionId = context.WorkflowExecutionContext.WorkflowInstance.GetMetadata("signalRConnectionId")?.ToString(); if (string.IsNullOrWhiteSpace(signalRConnectionId)) return; @@ -34,26 +33,15 @@ namespace Elsa.Server.Api.Handlers ["Outcomes"] = JToken.FromObject(context.Outcomes) }; - //if (context.ActivityBlueprint.Type == "HttpEndpoint") - //{ - var body = context.Input != null ? ((dynamic)context.Input).Body : null; - - if (body != null) - data["Body"] = JToken.FromObject(body); - - // var activityData = context.WorkflowInstance.ActivityData.FirstOrDefault(x => x.Key == notification.ActivityExecutionContext.ActivityId); - // var pathProperty = activityData.Value.FirstOrDefault(x => x.Key == "Path"); - // if (pathProperty.Value != null) - // { - // path = pathProperty.Value.ToString(); - // } - //} + var body = context.Input != null ? ((dynamic)context.Input).Body : null; + if (body != null) + data["Body"] = JToken.FromObject(body); var activityData = context.WorkflowInstance.ActivityData.FirstOrDefault(x => x.Key == notification.ActivityExecutionContext.ActivityId).Value; var message = new WorkflowTestMessage { - //Path = path, + ActivityType = context.ActivityBlueprint.Type, WorkflowInstanceId = context.WorkflowInstance.Id, CorrelationId = context.CorrelationId, ActivityId = context.ActivityId, diff --git a/src/server/Elsa.Server.Api/Models/WorkflowTestMessage.cs b/src/server/Elsa.Server.Api/Models/WorkflowTestMessage.cs index e73b45183..a5dc9dec1 100644 --- a/src/server/Elsa.Server.Api/Models/WorkflowTestMessage.cs +++ b/src/server/Elsa.Server.Api/Models/WorkflowTestMessage.cs @@ -4,6 +4,7 @@ namespace Elsa.Server.Api.Models { public class WorkflowTestMessage { + public string ActivityType { get; set; } = default!; public string WorkflowInstanceId { get; set; } = default!; public string CorrelationId { get; set; } = default!; public string ActivityId { get; set; } = default!;