Add Variable available in dropdown when configuring a activity input (#5918)
* Sample to provide a ExpressionDescriptorProvider * fix variable accessor in VariableExpressionHandler * remove Variable Expression to use default one * Change the Variable Expression Provider to handle Variable Expression correctly * need to check on UI Side and Server side is valid JSON is sent. For example, if a use change from a literal value to a Variable value, the value is sent to the API and result in an exception, we cannot handle invalid json without using Try/Catch --------- Co-authored-by: Jérémie DEVILLARD <jdevillard@users.noreply.github.com> Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
This commit is contained in:
parent
684717d180
commit
3083a400d8
|
|
@ -1,3 +1,4 @@
|
|||
using Elsa.EntityFrameworkCore.Extensions;
|
||||
using Elsa.EntityFrameworkCore.Modules.Management;
|
||||
using Elsa.EntityFrameworkCore.Modules.Runtime;
|
||||
using Elsa.Extensions;
|
||||
|
|
@ -7,8 +8,8 @@ var builder = WebApplication.CreateBuilder(args);
|
|||
|
||||
builder.Services.AddElsa(elsa =>
|
||||
{
|
||||
elsa.UseWorkflowManagement(management => management.UseEntityFrameworkCore());
|
||||
elsa.UseWorkflowRuntime(runtime => runtime.UseEntityFrameworkCore());
|
||||
elsa.UseWorkflowManagement(management => management.UseEntityFrameworkCore(ef => ef.UseSqlite()));
|
||||
elsa.UseWorkflowRuntime(runtime => runtime.UseEntityFrameworkCore(ef=>ef.UseSqlite()));
|
||||
|
||||
elsa.UseWorkflowsApi();
|
||||
elsa.UseHttp();
|
||||
|
|
@ -26,12 +27,12 @@ builder.Services.AddElsa(elsa =>
|
|||
});
|
||||
|
||||
elsa.UseDefaultAuthentication();
|
||||
elsa.AddActivity<VehicleActivity>();
|
||||
elsa.AddActivity<VehicleActivity>();
|
||||
});
|
||||
|
||||
builder.Services.AddSingleton<VehicleUIHandler>();
|
||||
builder.Services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()));
|
||||
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
|
@ -41,4 +42,5 @@ app.UseAuthentication();
|
|||
app.UseAuthorization();
|
||||
app.UseWorkflowsApi();
|
||||
app.Map("/test",c=> c.UseWorkflows());
|
||||
app.Run();
|
||||
app.Run();
|
||||
|
||||
|
|
|
|||
|
|
@ -49,13 +49,23 @@ public class DefaultExpressionDescriptorProvider : IExpressionDescriptorProvider
|
|||
return CreateDescriptor<VariableExpressionHandler>(
|
||||
"Variable",
|
||||
"Variable",
|
||||
isBrowsable: false,
|
||||
isBrowsable: true,
|
||||
memoryBlockReferenceFactory: () => new Variable(),
|
||||
deserialize: context =>
|
||||
{
|
||||
var valueElement = context.JsonElement.TryGetProperty("value", out var v) ? v : default;
|
||||
var value = valueElement.Deserialize(context.MemoryBlockType, context.Options);
|
||||
return new Expression("Variable", value);
|
||||
var valueElement = context.JsonElement.TryGetProperty("value", out var v) ? v : default;
|
||||
var valueString = valueElement.GetValue()?.ToString();
|
||||
try
|
||||
{
|
||||
var value = JsonSerializer.Deserialize(valueString, context.MemoryBlockType, context.Options);
|
||||
return new Expression("Variable", value);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
return new Expression("Variable", null);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue