PR requested changes

This commit is contained in:
axeleron007 2021-10-01 14:49:49 +03:00
parent 899cd2993a
commit 4949c402bc
8 changed files with 110 additions and 71 deletions

View file

@ -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 (
<div class="elsa-mt-3">
<a href="#"
onClick={e => 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}
</a>
@ -165,7 +168,7 @@ export class ElsaScriptProperty {
{fieldHint ? <p class="elsa-mt-2 elsa-text-sm elsa-text-gray-500">{fieldHint}</p> : undefined}
<input type="hidden" name={fieldName} value={value}/>
{renderValidationResult()}
{renderCustomButton()}
{renderComponentCustomButton()}
</div>
}
}

View file

@ -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<string> {
@ -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 {
</p>
</div>
))}
{hasBody ? renderUseAsSchemaButton() : undefined}
{hasBody ? renderComponentCustomButton() : undefined}
{renderActivityTestError()}
</div>
);
};
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 (
<div class="elsa-py-3 elsa-flex elsa-justify-between elsa-text-sm elsa-font-medium">
<button type="button"
onClick={() => this.onUseAsSchemaClick(message)}
onClick={() => this.onComponentCustomButtonClick(message)}
class="elsa-ml-0 elsa-w-full elsa-inline-flex elsa-justify-center elsa-rounded-md elsa-border elsa-border-transparent elsa-shadow-sm elsa-px-4 elsa-py-2 elsa-bg-blue-600 elsa-text-base elsa-font-medium elsa-text-white hover:elsa-bg-blue-700 focus:elsa-outline-none focus:elsa-ring-2 focus:elsa-ring-offset-2 focus:elsa-ring-blue-500 sm:elsa-ml-3 sm:elsa-w-auto sm:elsa-text-sm">
{t('UseAsSchema')}
{label}
</button>
</div>
)
)
};
const renderLoader = function () {
@ -708,8 +726,7 @@ export class ElsaWorkflowDefinitionEditorScreen {
registerClickOutside(this, el, () => {
this.handleContextMenuTestChange(0, 0, false, null);
})
}
>
}>
<div class="elsa-rounded-lg elsa-shadow-lg elsa-ring-1 elsa-ring-black elsa-ring-opacity-5 elsa-overflow-hidden">
{!!message ? renderMessage() : renderLoader()}
</div>

View file

@ -9,8 +9,7 @@
},
"ConnectionContextMenu":{
"Paste": "Paste",
},
'UseAsSchema': 'Use as Schema'
}
}
},
'nl-NL': {
@ -23,8 +22,7 @@
},
"ConnectionContextMenu":{
"Paste": "Plakken",
},
'UseAsSchema': 'Gebruik als schema'
}
}
}
};

View file

@ -324,6 +324,7 @@ export class SyntaxNames {
}
export interface WorkflowTestActivityMessage {
activityType: string;
workflowInstanceId: string;
correlationId: string;
activityId: string;

View file

@ -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;
}

View file

@ -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 = `<p>${bodyDisplay}</p>`;
}
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) {

View file

@ -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,

View file

@ -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!;