Refactor code for improved clarity and modern syntax
Refactored multiple classes to align with modern C# coding practices such as object initializers and nullable type handling. Added a new base class for checklist dropdown providers to enhance UI configuration extensibility. Simplified constructors for feature classes by adopting record-like syntax, improving readability and maintainability.
This commit is contained in:
parent
0bca6913b9
commit
255bb26dff
|
|
@ -0,0 +1,35 @@
|
|||
using System.Reflection;
|
||||
|
||||
namespace Elsa.Workflows.UIHints.CheckList;
|
||||
|
||||
/// <summary>
|
||||
/// A base class for providing options to populate a checklist UI component. This class is intended to be inherited to implement
|
||||
/// custom checklist data logic by overriding the `GetItemsAsync` method.
|
||||
/// </summary>
|
||||
public abstract class CheckListOptionsProviderBase : IPropertyUIHandler
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async ValueTask<IDictionary<string, object>> GetUIPropertiesAsync(PropertyInfo propertyInfo, object? context, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var items = await GetItemsAsync(propertyInfo, context, cancellationToken);
|
||||
var props = new CheckListProps
|
||||
{
|
||||
CheckList = new()
|
||||
{
|
||||
Items = items.ToList()
|
||||
}
|
||||
};
|
||||
|
||||
var options = new Dictionary<string, object>
|
||||
{
|
||||
[InputUIHints.CheckList] = props
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implement this to provide items to the dropdown list.
|
||||
/// </summary>
|
||||
protected abstract ValueTask<ICollection<CheckListItem>> GetItemsAsync(PropertyInfo propertyInfo, object? context, CancellationToken cancellationToken);
|
||||
}
|
||||
|
|
@ -25,7 +25,7 @@ public class StaticCheckListOptionsProvider : IPropertyUIHandler
|
|||
|
||||
var props = new CheckListProps
|
||||
{
|
||||
CheckList = new CheckList
|
||||
CheckList = new()
|
||||
{
|
||||
Items = selectListItems.ToList()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ namespace Elsa.Workflows.Management.Features;
|
|||
[DependsOn(typeof(WorkflowsFeature))]
|
||||
[DependsOn(typeof(WorkflowDefinitionsFeature))]
|
||||
[DependsOn(typeof(WorkflowInstancesFeature))]
|
||||
[PublicAPI]
|
||||
public class WorkflowManagementFeature : FeatureBase
|
||||
[UsedImplicitly]
|
||||
public class WorkflowManagementFeature(IModule module) : FeatureBase(module)
|
||||
{
|
||||
private const string PrimitivesCategory = "Primitives";
|
||||
private const string LookupsCategory = "Lookups";
|
||||
|
|
@ -56,11 +56,6 @@ public class WorkflowManagementFeature : FeatureBase
|
|||
private LogPersistenceMode LogPersistenceMode { get; set; } = LogPersistenceMode.Include;
|
||||
private bool IsReadOnlyMode { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public WorkflowManagementFeature(IModule module) : base(module)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A set of activity types to make available to the system.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ public class TaskReporter(IBookmarkQueue bookmarkQueue, IStimulusHasher stimulus
|
|||
private static readonly string ActivityTypeName = ActivityTypeNameHelper.GenerateTypeName<RunTask>();
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task ReportCompletionAsync(string taskId, object? result = default, CancellationToken cancellationToken = default)
|
||||
public async Task ReportCompletionAsync(string taskId, object? result = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var stimulus = new RunTaskStimulus(taskId, default!);
|
||||
var stimulus = new RunTaskStimulus(taskId, null!);
|
||||
|
||||
var input = new Dictionary<string, object>
|
||||
{
|
||||
|
|
@ -24,7 +24,7 @@ public class TaskReporter(IBookmarkQueue bookmarkQueue, IStimulusHasher stimulus
|
|||
{
|
||||
ActivityTypeName = ActivityTypeName,
|
||||
StimulusHash = stimulusHasher.Hash(ActivityTypeName, stimulus),
|
||||
Options = new ResumeBookmarkOptions
|
||||
Options = new()
|
||||
{
|
||||
Input = input
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ public static class ModuleExtensions
|
|||
/// <summary>
|
||||
/// Creates a new Elsa module and adds the <see cref="ElsaFeature"/> to it.
|
||||
/// </summary>
|
||||
public static IModule AddElsa(this IServiceCollection services, Action<IModule>? configure = default)
|
||||
public static IModule AddElsa(this IServiceCollection services, Action<IModule>? configure = null)
|
||||
{
|
||||
var module = services.GetOrCreateModule();
|
||||
module.Configure<AppFeature>(app => app.Configurator = configure);
|
||||
module.Configure<AppFeature>(app => app.Configurator += configure);
|
||||
module.Apply();
|
||||
|
||||
return module;
|
||||
|
|
@ -27,7 +27,7 @@ public static class ModuleExtensions
|
|||
/// <summary>
|
||||
/// Configures the Elsa module.
|
||||
/// </summary>
|
||||
public static IModule ConfigureElsa(this IServiceCollection services, Action<IModule>? configure = default)
|
||||
public static IModule ConfigureElsa(this IServiceCollection services, Action<IModule>? configure = null)
|
||||
{
|
||||
var module = services.GetOrCreateModule();
|
||||
|
||||
|
|
|
|||
|
|
@ -8,13 +8,8 @@ namespace Elsa.Features;
|
|||
/// A wrapper for invoking application-specific configuration, ensuring it is invoked lastly.
|
||||
/// </summary>
|
||||
[DependsOn(typeof(ElsaFeature))]
|
||||
public class AppFeature : FeatureBase
|
||||
public class AppFeature(IModule module) : FeatureBase(module)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public AppFeature(IModule module) : base(module)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The configurator to invoke.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Reference in a new issue