-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[ENH] Include dropdown when using a nullable enum in an activity input #5313
Comments
To address the issue of nullable enum types not displaying options in the dropdown, you can modify the Here's a code snippet that demonstrates how you might implement this: public class StaticDropDownOptionsProvider : IActivityPropertyOptionsProvider
{
public ValueTask<IEnumerable<SelectListItem>> GetOptionsAsync(ActivityPropertyOptionsContext context)
{
var propertyType = context.Property.PropertyType;
var underlyingType = Nullable.GetUnderlyingType(propertyType);
var enumType = underlyingType ?? propertyType;
if (!enumType.IsEnum)
throw new ArgumentException("The specified property type is not an enum type.");
var enumValues = Enum.GetValues(enumType).Cast<object>()
.Select(x => new SelectListItem(x.ToString(), x.ToString()))
.ToList();
// If the enum is nullable, add a blank option to represent null.
if (underlyingType != null)
{
enumValues.Insert(0, new SelectListItem(string.Empty, null));
}
return new ValueTask<IEnumerable<SelectListItem>>(enumValues);
}
} In this code, Regarding the enhancement request, it seems like you've already identified a solution and are considering submitting a pull request. If you believe your solution is robust and doesn't negatively impact other parts of the system, I would encourage you to contribute to the project by submitting a pull request. Make sure to include unit tests that cover the new functionality and document the changes in the PR description. Before submitting the PR, you may also want to discuss your proposed changes with the Elsa community or maintainers to get feedback and ensure that it aligns with the project's goals and coding standards. If you need further assistance or have additional questions, please let me know. This comment was generated by Glime. |
… activity input
Makes perfect sense. I noticed you went ahead and submitted a PR, thanks! I'll check it out shortly. |
#5320) Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
Enhancement Request
Enhancement Overview
Using the
InputUIHints.DropDown
on an Activity Input with anenum
displays the dropdown with all the options in the studio activity editor as expected.Changing the Input
enum
to be nullable makes the dropdown no longer show any options and does not work since it is a dropdown without any options to select.Proposed Enhancement
Adding a few lines in
StaticDropDownOptionsProvider
class to check ifwrappedPropertyType
is nullable and has an underlying type that could be anenum
. Then, add a blank item option in theenumValues
list. I have taken a crack at it myself since it was so easy to run and debug elsa-core! It is such a small change and I do not know what this change could impact, but I can go through the PR process if requested.Use Cases
I have an activity that queries data. There is a
status
property that is anenum
that I would like to be able to filter by. In the meantime, I made a genericNullableEnumUIHandler
to get around this and have a few type castings. It would definitely be cleaner code to simply add theInputUIHints.DropDown
with the code below. Any pointers on a better way of having anenum
input that can be changed back to being null after selecting an option would be great.Additional Context
This generates an input with a dropdown of the enum values:
This ends up having a blank dropdown where nothing is selectable:
The text was updated successfully, but these errors were encountered: