Feature
Create possibility to populate possible outcomes in designer from custom activity property's values basing on information in IActivity implementation (server side only)
Reality
There are several builtin activities that populates possible outcomes from their property's values (e.g. SendHttpRequest.SupportedStatusCodes, Fork.Branches).
Such support is hard-coded in JavaScript code of Elsa.Designer.Components.Web.
There is support of IOutcomesProvider implemented as fix for issue #873, but it cannot be used for requested feature
Suggestion
Either extend ActivityAttribute with DynamicOutcomesPropertyName property, or extend ActivityInputAttribute with TreatValuesAsOutcomes
[ActivityInput(
Hint = "A list of possible HTTP status codes to handle.",
UIHint = ActivityInputUIHints.MultiText,
DefaultSyntax = SyntaxNames.Json,
TreatValuesAsOutcomes = true,
DefaultValue = new[] { 200 },
SupportedSyntaxes = new[] { SyntaxNames.Json, SyntaxNames.JavaScript, SyntaxNames.Liquid }
)]
public ICollection<int>? SupportedStatusCodes { get; set; } = new HashSet<int>(new[] { 200 });
Remove the following code from custom plugins
onActivityDesignDisplaying(context: ActivityDesignDisplayContext) {
const activityModel = context.activityModel;
if (activityModel.type !== 'SendHttpRequest')
return;
const props = activityModel.properties || [];
const syntax = SyntaxNames.Json;
const branches = props.find(x => x.name == 'SupportedStatusCodes') || {expressions: {'Json': '[]'}, syntax: syntax};
const expression = branches.expressions[syntax] || [];
let outcomes = !!expression['$values'] ? expression['$values'] : Array.isArray(expression) ? expression : parseJson(expression) || [];
context.outcomes = [...outcomes, 'Done', 'Unsupported Status Code'];
}
Replace by general DynamicOutcomesPlugin with the following code
class DynamicOutcomesPlugin {
constructor() {
eventBus.on(EventTypes.ActivityDesignDisplaying, this.onActivityDesignDisplaying);
}
onActivityDesignDisplaying = (context) => {
const props = context.activityModel.properties || [];
const syntax = SyntaxNames.Json;
let dynamicOutcomes = [];
props
.filter(prop => prop.treatValuesAsOutcomes))
.forEach(prop => {
const expression = prop.expressions[syntax] || [];
const dynamicPropertyOutcomes = !!expression['$values'] ? expression['$values'] : Array.isArray(expression) ? expression : parseJson(expression) || [];
dynamicOutcomes = [...dynamicOutcomes, ...dynamicPropertyOutcomes];
});
context.outcomes = [...dynamicOutcomes, ...context.outcomes];
}
}
Benefits
Feature implementation will allow to get rid of
- Code duplication in JS
- IActivity implementation becomes closer to be fully self-descriptive
Minor existing issue
Outcomes of UserTask activity still contains obsolete expression
Outcomes = new[] { OutcomeNames.Done, "x => x.state.actions" }
Feature
Create possibility to populate possible outcomes in designer from custom activity property's values basing on information in IActivity implementation (server side only)
Reality
There are several builtin activities that populates possible outcomes from their property's values (e.g.
SendHttpRequest.SupportedStatusCodes,Fork.Branches).Such support is hard-coded in JavaScript code of Elsa.Designer.Components.Web.
There is support of
IOutcomesProviderimplemented as fix for issue #873, but it cannot be used for requested featureSuggestion
Either extend
ActivityAttributewithDynamicOutcomesPropertyNameproperty, or extendActivityInputAttributewithTreatValuesAsOutcomesRemove the following code from custom plugins
Replace by general DynamicOutcomesPlugin with the following code
Benefits
Feature implementation will allow to get rid of
Minor existing issue
Outcomes of UserTask activity still contains obsolete expression