| | | 1 | | using System.Reflection; |
| | | 2 | | using Elsa.Extensions; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Workflows.UIHints.RadioList; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// A base class for providing options to populate a checklist UI component. This class is intended to be inherited to i |
| | | 8 | | /// custom radiolist data logic by overriding the `GetItemsAsync` method. |
| | | 9 | | /// </summary> |
| | | 10 | | public abstract class RadioListOptionsProviderBase : PropertyUIHandlerBase |
| | | 11 | | { |
| | 0 | 12 | | protected virtual bool RefreshOnChange => false; |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public override async ValueTask<IDictionary<string, object>> GetUIPropertiesAsync(PropertyInfo propertyInfo, object? |
| | | 16 | | { |
| | 0 | 17 | | var items = await GetItemsAsync(propertyInfo, context, cancellationToken); |
| | 0 | 18 | | var props = new RadioListProps |
| | 0 | 19 | | { |
| | 0 | 20 | | RadioList = new() |
| | 0 | 21 | | { |
| | 0 | 22 | | Items = items.ToList() |
| | 0 | 23 | | } |
| | 0 | 24 | | }; |
| | | 25 | | |
| | 0 | 26 | | var options = new Dictionary<string, object> |
| | 0 | 27 | | { |
| | 0 | 28 | | [InputUIHints.RadioList] = props |
| | 0 | 29 | | }; |
| | | 30 | | |
| | 0 | 31 | | options.AddRange(GetUIPropertyAdditionalOptions()); |
| | | 32 | | |
| | 0 | 33 | | return options; |
| | 0 | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Implement this to provide items to the radio list. |
| | | 38 | | /// </summary> |
| | | 39 | | protected abstract ValueTask<ICollection<RadioListItem>> GetItemsAsync(PropertyInfo propertyInfo, object? context, C |
| | | 40 | | |
| | | 41 | | protected virtual IDictionary<string, object> GetUIPropertyAdditionalOptions() |
| | | 42 | | { |
| | 0 | 43 | | var options = new Dictionary<string, object>(); |
| | 0 | 44 | | if (RefreshOnChange) options["Refresh"] = true; |
| | 0 | 45 | | return options; |
| | | 46 | | } |
| | | 47 | | } |