< Summary

Information
Class: Elsa.Workflows.UIHints.Dropdown.DropDownOptionsProviderBase
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/UIHints/Dropdown/DropDownOptionsProviderBase.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 50
Line coverage: 100%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_RefreshOnChange()100%11100%
get_Priority()100%11100%
GetUIPropertiesAsync()100%11100%
GetUIPropertyAdditionalOptions()50%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/UIHints/Dropdown/DropDownOptionsProviderBase.cs

#LineLine coverage
 1using System.Reflection;
 2using Elsa.Extensions;
 3
 4namespace 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>
 10public abstract class DropDownOptionsProviderBase : IPropertyUIHandler
 11{
 58012    protected virtual bool RefreshOnChange => false;
 13
 1917014    public float Priority { get; }
 15
 16    /// <inheritdoc />
 17    public virtual async ValueTask<IDictionary<string, object>> GetUIPropertiesAsync(PropertyInfo propertyInfo, object? 
 18    {
 58019        var selectListItems = await GetItemsAsync(propertyInfo, context, cancellationToken);
 58020        var props = new DropDownProps
 58021        {
 58022            SelectList = new(selectListItems)
 58023        };
 24
 58025        var options = new Dictionary<string, object>
 58026        {
 58027            [InputUIHints.DropDown] = props
 58028        };
 29
 58030        options.AddRange(GetUIPropertyAdditionalOptions());
 31
 58032        return options;
 58033    }
 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    {
 58046        var options = new Dictionary<string, object>();
 58047        if (RefreshOnChange) options["Refresh"] = true;
 58048        return options;
 49    }
 50}