From 5d936ad34cc30b189312d8629ecf1a4d527d9719 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 28 Dec 2023 20:52:04 +0100 Subject: [PATCH] Add UI hints for HTTP endpoint and single line fields Introduced HttpEndpointPathUIHandler to provide additional UI options for the Path input field in the HTTP Endpoint activity. This commits also adds SingleLineProps to offer more options for SingleLine input fields across different modules. The implementation improves UI component interactions. --- .../UIHints/SingleLine/SingleLineProps.cs | 12 ++++++++ .../Elsa.Http/Activities/HttpEndpoint.cs | 7 ++++- .../UIHints/HttpEndpointPathUIHandler.cs | 30 +++++++++++++++++++ .../UIHints/SingleLine/SingleLineProps.cs | 12 ++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/clients/Elsa.Api.Client/Shared/UIHints/SingleLine/SingleLineProps.cs create mode 100644 src/modules/Elsa.Http/UIHints/HttpEndpointPathUIHandler.cs create mode 100644 src/modules/Elsa.Workflows.Core/UIHints/SingleLine/SingleLineProps.cs diff --git a/src/clients/Elsa.Api.Client/Shared/UIHints/SingleLine/SingleLineProps.cs b/src/clients/Elsa.Api.Client/Shared/UIHints/SingleLine/SingleLineProps.cs new file mode 100644 index 0000000000..14520c0f39 --- /dev/null +++ b/src/clients/Elsa.Api.Client/Shared/UIHints/SingleLine/SingleLineProps.cs @@ -0,0 +1,12 @@ +namespace Elsa.Api.Client.Shared.UIHints.SingleLine; + +/// +/// Provides additional options for the SingleLine input field. +/// +public class SingleLineProps +{ + /// + /// Gets or sets adornment text. + /// + public string? AdornmentText { get; set; } +} \ No newline at end of file diff --git a/src/modules/Elsa.Http/Activities/HttpEndpoint.cs b/src/modules/Elsa.Http/Activities/HttpEndpoint.cs index 5d2919878d..978ff6c839 100644 --- a/src/modules/Elsa.Http/Activities/HttpEndpoint.cs +++ b/src/modules/Elsa.Http/Activities/HttpEndpoint.cs @@ -4,6 +4,7 @@ using Elsa.Extensions; using Elsa.Http.Bookmarks; using Elsa.Http.Contracts; +using Elsa.Http.UIHints; using Elsa.Workflows; using Elsa.Workflows.Attributes; using Elsa.Workflows.UIHints; @@ -34,7 +35,11 @@ public HttpEndpoint([CallerFilePath] string? source = default, [CallerLineNumber /// /// The path to associate with the workflow. /// - [Input(Description = "The path to associate with the workflow.")] + [Input( + Description = "The path to associate with the workflow.", + UIHint = InputUIHints.SingleLine, + UIHandler = typeof(HttpEndpointPathUIHandler) + )] public Input Path { get; set; } = default!; /// diff --git a/src/modules/Elsa.Http/UIHints/HttpEndpointPathUIHandler.cs b/src/modules/Elsa.Http/UIHints/HttpEndpointPathUIHandler.cs new file mode 100644 index 0000000000..e81a9d8402 --- /dev/null +++ b/src/modules/Elsa.Http/UIHints/HttpEndpointPathUIHandler.cs @@ -0,0 +1,30 @@ +using System.Reflection; +using Elsa.Http.Options; +using Elsa.Workflows.Contracts; +using Elsa.Workflows.UIHints; +using Elsa.Workflows.UIHints.SingleLine; +using Microsoft.Extensions.Options; + +namespace Elsa.Http.UIHints; + +/// +/// Provides additional options for the Path input field. +/// +public class HttpEndpointPathUIHandler(IOptions options) : IPropertyUIHandler +{ + /// + public ValueTask> GetUIPropertiesAsync(PropertyInfo propertyInfo, object? context, CancellationToken cancellationToken = default) + { + var baseUrl = options.Value.BaseUrl; + var apiRoutePrefix = options.Value.ApiRoutePrefix; + var completeBaseUrl = new Uri(baseUrl, apiRoutePrefix); + + return new(new Dictionary + { + [InputUIHints.SingleLine] = new SingleLineProps + { + AdornmentText = completeBaseUrl.ToString().TrimEnd('/') + '/' + }, + }); + } +} \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Core/UIHints/SingleLine/SingleLineProps.cs b/src/modules/Elsa.Workflows.Core/UIHints/SingleLine/SingleLineProps.cs new file mode 100644 index 0000000000..d6e01ed16b --- /dev/null +++ b/src/modules/Elsa.Workflows.Core/UIHints/SingleLine/SingleLineProps.cs @@ -0,0 +1,12 @@ +namespace Elsa.Workflows.UIHints.SingleLine; + +/// +/// Provides additional options for the SingleLine input field. +/// +public class SingleLineProps +{ + /// + /// Gets or sets adornment text. + /// + public string? AdornmentText { get; set; } +} \ No newline at end of file