| | | 1 | | using System.Reflection; |
| | | 2 | | using Elsa.Extensions; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Workflows.UIHints.Dropdown; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// A base class for providing options to populate a dropdown UI component. This class is intended to be inherited to im |
| | | 8 | | /// custom dropdown data logic by overriding the `GetItemsAsync` method. |
| | | 9 | | /// </summary> |
| | | 10 | | public abstract class DropDownOptionsProviderBase : IPropertyUIHandler |
| | | 11 | | { |
| | 580 | 12 | | protected virtual bool RefreshOnChange => false; |
| | | 13 | | |
| | 19170 | 14 | | public float Priority { get; } |
| | | 15 | | |
| | | 16 | | /// <inheritdoc /> |
| | | 17 | | public virtual async ValueTask<IDictionary<string, object>> GetUIPropertiesAsync(PropertyInfo propertyInfo, object? |
| | | 18 | | { |
| | 580 | 19 | | var selectListItems = await GetItemsAsync(propertyInfo, context, cancellationToken); |
| | 580 | 20 | | var props = new DropDownProps |
| | 580 | 21 | | { |
| | 580 | 22 | | SelectList = new(selectListItems) |
| | 580 | 23 | | }; |
| | | 24 | | |
| | 580 | 25 | | var options = new Dictionary<string, object> |
| | 580 | 26 | | { |
| | 580 | 27 | | [InputUIHints.DropDown] = props |
| | 580 | 28 | | }; |
| | | 29 | | |
| | 580 | 30 | | options.AddRange(GetUIPropertyAdditionalOptions()); |
| | | 31 | | |
| | 580 | 32 | | return options; |
| | 580 | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Implement this to provide items to the dropdown list. |
| | | 37 | | /// </summary> |
| | | 38 | | protected abstract ValueTask<ICollection<SelectListItem>> GetItemsAsync(PropertyInfo propertyInfo, object? context, |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Override this to provide additional options to the list |
| | | 42 | | /// </summary> |
| | | 43 | | /// <returns></returns> |
| | | 44 | | protected virtual IDictionary<string, object> GetUIPropertyAdditionalOptions() |
| | | 45 | | { |
| | 580 | 46 | | var options = new Dictionary<string, object>(); |
| | 580 | 47 | | if (RefreshOnChange) options["Refresh"] = true; |
| | 580 | 48 | | return options; |
| | | 49 | | } |
| | | 50 | | } |