< Summary

Information
Class: Elsa.Workflows.PropertyUIHandlerResolver
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Services/PropertyUIHandlerResolver.cs
Line coverage
96%
Covered lines: 25
Uncovered lines: 1
Coverable lines: 26
Total lines: 58
Line coverage: 96.1%
Branch coverage
94%
Covered branches: 17
Total branches: 18
Branch coverage: 94.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetUIPropertiesAsync()94.44%181895.45%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Services/PropertyUIHandlerResolver.cs

#LineLine coverage
 1using System.Reflection;
 2using Elsa.Workflows.Attributes;
 3using Elsa.Workflows.Models;
 4using Microsoft.Extensions.DependencyInjection;
 5
 6namespace Elsa.Workflows;
 7
 8/// <inheritdoc />
 5289public class PropertyUIHandlerResolver(IServiceScopeFactory scopeFactory) : IPropertyUIHandlerResolver
 10{
 11    /// <inheritdoc />
 12    public async ValueTask<IDictionary<string, object>> GetUIPropertiesAsync(PropertyInfo propertyInfo, object? context,
 13    {
 1733714        var inputAttribute = propertyInfo.GetCustomAttribute<InputAttribute>();
 1733715        var result = new Dictionary<string, object>();
 16
 1733717        var uiHandlers = new List<Type>();
 18
 1733719        if (inputAttribute?.UIHandler != null)
 116020            uiHandlers.Add(inputAttribute.UIHandler);
 21
 1733722        if (inputAttribute?.UIHandlers != null)
 023            uiHandlers.AddRange(inputAttribute.UIHandlers);
 24
 1733725        using var scope = scopeFactory.CreateScope();
 1733726        var uiHintHandlers = scope.ServiceProvider.GetServices<IUIHintHandler>();
 27
 1733728        var isWrapperProperty = typeof(Input).IsAssignableFrom(propertyInfo.PropertyType);
 1733729        var wrapperPropertyType = !isWrapperProperty ? propertyInfo.PropertyType : propertyInfo.PropertyType.GenericType
 1733730        var uiHint = ActivityDescriber.GetUIHint(wrapperPropertyType, inputAttribute);
 1733731        if (!string.IsNullOrWhiteSpace(uiHint))
 32        {
 7315833            var uiHintHandler = uiHintHandlers.FirstOrDefault(x => x.UIHint == uiHint);
 34
 1733735            if (uiHintHandler != null)
 36            {
 300337                var defaultHandlers = await uiHintHandler.GetPropertyUIHandlersAsync(propertyInfo, cancellationToken);
 300338                uiHandlers.AddRange(defaultHandlers);
 39            }
 40        }
 41
 42        // Handlers are sorted by priority so that those with higher priority are processed last.
 43        // This allows them to override any existing property values set by lower-priority handlers.
 44        // For example, a default UI hint handler might provide dropdown options, but a custom module can supply its own
 13543145        var availablePropertyUIHandlers = scope.ServiceProvider.GetServices<IPropertyUIHandler>().OrderBy(x => x.Priorit
 13659146        var matchedPropertyHandlers = availablePropertyUIHandlers.Where(x => uiHandlers.Contains(x.GetType())).OrderBy(x
 47
 4287248        foreach (var handler in matchedPropertyHandlers)
 49        {
 409950            var properties = await handler.GetUIPropertiesAsync(propertyInfo, context, cancellationToken);
 51
 1279852            foreach (var property in properties)
 230053                result[property.Key] = property.Value;
 54        }
 55
 1733756        return result;
 1733757    }
 58}