Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] A custom dropdown options provider is not working #6189

Closed
jayachandra21 opened this issue Dec 7, 2024 · 2 comments
Closed

[BUG] A custom dropdown options provider is not working #6189

jayachandra21 opened this issue Dec 7, 2024 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@jayachandra21
Copy link

Description

A custom dropdown options provider is not working.

Steps to Reproduce

  1. Detailed Steps:
  • Class with VehicleUIHandler which inherits from DropDownOptionsProviderBase.
public class VehicleUIHandler : DropDownOptionsProviderBase
{
    private readonly Random _random = new();

    protected override ValueTask<ICollection<SelectListItem>> GetItemsAsync(PropertyInfo propertyInfo, object? context, CancellationToken cancellationToken)
    {
        var items = new List<SelectListItem>
        {
            new("BMW", "1"),
            new("Tesla", "2"),
            new("Peugeot", "3"),
            new(_random.Next(100).ToString(), "4")
        };

        return new(items);
    }
}

  • Configures the specified property to refresh the UI when the property value changes.
public class RefreshUIHandler : IPropertyUIHandler
{
    public ValueTask<IDictionary<string, object>> GetUIPropertiesAsync(PropertyInfo propertyInfo, object? context, CancellationToken cancellationToken = default)
    {
        IDictionary<string, object> result = new Dictionary<string, object>
        {
            { "Refresh", true }
        };
        return ValueTask.FromResult(result);
    }
}
  • Register in the UI handler.

builder.Services.AddSingleton<VehicleUIHandler>();

  • Custom Activity VehicleActivity
public class VehicleActivity : Activity<string>
{
    [Input(
        Description = "The content type to use when sending the request.",
        UIHint = InputUIHints.DropDown,
        UIHandlers = [typeof(VehicleUIHandler), typeof(RefreshUIHandler)]
    )]
    public Input<string> Brand { get; set; } = default!;
}
  • In the activity Input property is shows the empty list

image

  1. Reproduction Rate: every time

  2. Additional Configuration:

Expected Behavior

The Vehicle activity suppose to show the list items mentioned in the VehicleUIHandler.

Actual Behavior

It not listing the items. It means dropdown is empty.

Environment

  • Elsa Package Version: Elsa 3.3.0 RC3
  • Operating System: Windows
  • Browser and Version: Chrome

Troubleshooting Attempts

  • Tried to debug the VehicleUIHandler class but debugger is not hitting the same class.
@jayachandra21 jayachandra21 added the bug Something isn't working label Dec 7, 2024
@sfmskywalker sfmskywalker added this to the Elsa 3.3 milestone Dec 7, 2024
@sfmskywalker sfmskywalker moved this to Triage in ELSA 3 Dec 7, 2024
@sfmskywalker sfmskywalker self-assigned this Dec 7, 2024
@sfmskywalker
Copy link
Member

Turned out that the sample project registered the handler incorrectly. Here's how to do it correctly:

builder.Services.AddScoped<IPropertyUIHandler, VehicleUIHandler>();
builder.Services.AddScoped<IPropertyUIHandler, RefreshUIHandler>();

After doing that, it will work.
The sample project has been updated.

Thanks for reporting!

@github-project-automation github-project-automation bot moved this from Triage to Done in ELSA 3 Dec 12, 2024
@Suchiman
Copy link
Contributor

Huh indeed, that fixed it, in 3.1 it was not necessary to register them with DI at all but in 3.3 it doesn't work without it being registered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

3 participants