Simplify CheckListOptions logic
Refactor `StaticCheckListOptionsProvider` to inherit from the new `CheckListOptionsProviderBase` and streamline checklist item generation logic.
This commit is contained in:
parent
d44b081848
commit
f8968b5cfc
19
src/apps/Elsa.Server.Web/Activities/CheckedActivity.cs
Normal file
19
src/apps/Elsa.Server.Web/Activities/CheckedActivity.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
using Elsa.Extensions;
|
||||
using Elsa.Workflows;
|
||||
using Elsa.Workflows.Attributes;
|
||||
using Elsa.Workflows.Models;
|
||||
using Elsa.Workflows.UIHints;
|
||||
using Elsa.Workflows.UIHints.CheckList;
|
||||
|
||||
namespace Elsa.Server.Web.Activities;
|
||||
|
||||
public class CheckedActivity : CodeActivity<string[]>
|
||||
{
|
||||
[Input(UIHint = InputUIHints.CheckList, UIHandler = typeof(StaticCheckListOptionsProvider), Options = new[]{"A", "B", "C"})]
|
||||
public Input<string[]> CheckedItems { get; set; }
|
||||
|
||||
protected override void Execute(ActivityExecutionContext context)
|
||||
{
|
||||
context.SetResult(CheckedItems.GetOrDefault(context));
|
||||
}
|
||||
}
|
||||
|
|
@ -6,32 +6,22 @@ namespace Elsa.Workflows.UIHints.CheckList;
|
|||
/// <summary>
|
||||
/// Provides static drop-down options for a given property.
|
||||
/// </summary>
|
||||
public class StaticCheckListOptionsProvider : IPropertyUIHandler
|
||||
public class StaticCheckListOptionsProvider : CheckListOptionsProviderBase
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public ValueTask<IDictionary<string, object>> GetUIPropertiesAsync(PropertyInfo propertyInfo, object? context, CancellationToken cancellationToken = default)
|
||||
protected override ValueTask<ICollection<CheckListItem>> GetItemsAsync(PropertyInfo propertyInfo, object? context, CancellationToken cancellationToken)
|
||||
{
|
||||
var inputAttribute = propertyInfo.GetCustomAttribute<InputAttribute>();
|
||||
var inputOptions = inputAttribute?.Options;
|
||||
var dictionary = new Dictionary<string, object>();
|
||||
|
||||
if (inputOptions == null)
|
||||
return new(dictionary);
|
||||
return new([]);
|
||||
|
||||
var selectListItems = (inputOptions as ICollection<string>)?.Select(x => new CheckListItem(x, x)).ToList();
|
||||
|
||||
if (selectListItems == null)
|
||||
return new(dictionary);
|
||||
|
||||
var props = new CheckListProps
|
||||
{
|
||||
CheckList = new()
|
||||
{
|
||||
Items = selectListItems.ToList()
|
||||
}
|
||||
};
|
||||
|
||||
dictionary[InputUIHints.CheckList] = props;
|
||||
return new(dictionary);
|
||||
return new([]);
|
||||
|
||||
return new(selectListItems);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue