< 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 />
 5729public class PropertyUIHandlerResolver(IServiceScopeFactory scopeFactory) : IPropertyUIHandlerResolver
 10{
 11    /// <inheritdoc />
 12    public async ValueTask<IDictionary<string, object>> GetUIPropertiesAsync(PropertyInfo propertyInfo, object? context,
 13    {
 2254414        var inputAttribute = propertyInfo.GetCustomAttribute<InputAttribute>();
 2254415        var result = new Dictionary<string, object>();
 16
 2254417        var uiHandlers = new List<Type>();
 18
 2254419        if (inputAttribute?.UIHandler != null)
 158720            uiHandlers.Add(inputAttribute.UIHandler);
 21
 2254422        if (inputAttribute?.UIHandlers != null)
 023            uiHandlers.AddRange(inputAttribute.UIHandlers);
 24
 2254425        using var scope = scopeFactory.CreateScope();
 2254426        var uiHintHandlers = scope.ServiceProvider.GetServices<IUIHintHandler>();
 27
 2254428        var isWrapperProperty = typeof(Input).IsAssignableFrom(propertyInfo.PropertyType);
 2254429        var wrapperPropertyType = !isWrapperProperty ? propertyInfo.PropertyType : propertyInfo.PropertyType.GenericType
 2254430        var uiHint = ActivityDescriber.GetUIHint(wrapperPropertyType, inputAttribute);
 2254431        if (!string.IsNullOrWhiteSpace(uiHint))
 32        {
 9633633            var uiHintHandler = uiHintHandlers.FirstOrDefault(x => x.UIHint == uiHint);
 34
 2254435            if (uiHintHandler != null)
 36            {
 405237                var defaultHandlers = await uiHintHandler.GetPropertyUIHandlersAsync(propertyInfo, cancellationToken);
 405238                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
 18848545        var availablePropertyUIHandlers = scope.ServiceProvider.GetServices<IPropertyUIHandler>().OrderBy(x => x.Priorit
 19013746        var matchedPropertyHandlers = availablePropertyUIHandlers.Where(x => uiHandlers.Contains(x.GetType())).OrderBy(x
 47
 5623248        foreach (var handler in matchedPropertyHandlers)
 49        {
 557250            var properties = await handler.GetUIPropertiesAsync(propertyInfo, context, cancellationToken);
 51
 1771252            foreach (var property in properties)
 328453                result[property.Key] = property.Value;
 54        }
 55
 2254456        return result;
 2254457    }
 58}