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

Conditional inputs #6410

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

LukasBenner
Copy link

@LukasBenner LukasBenner commented Feb 14, 2025

This pull request introduces new functionality to support conditional inputs in the Elsa workflows. The changes include adding new attributes and models to handle conditional inputs and state dropdowns, and updating existing descriptors to incorporate these new features.

This PR is a refined version of PR #5343 for the issue #186.
The corresponding PR in elsa-studio is 418

New Attributes and Models:

Updated Descriptors:

Integration with Existing Code:

These changes enhance the Elsa workflows by allowing more dynamic and state-dependent input configurations.

A example usage of the conditional inputs could look like this:

using Elsa.Extensions;
using Elsa.Workflows;
using Elsa.Workflows.Attributes.Conditional;
using Elsa.Workflows.Models;

namespace Elsa.Server.Web;

public class CondActivity : CodeActivity
{

    [StateDropdownInput(
        ["double", "string"],
        DefaultValue = "double")]
    public Input<string> ApiName{ get; set; } = default;
    
    [ConditionalInput(["double"], Description = "Double")]
    public Input<double> DoubleInput {get; set;} = default;

    [ConditionalInput(["string"], Description = "String")]
    public Input<string> StringInput {get; set;} = default;

    protected override void Execute(ActivityExecutionContext context)
    {
        object? value = null;
        if (ApiName.Get(context) == "double")
            value = DoubleInput.Get(context);
        else if (ApiName.Get(context) == "string")
            value = StringInput.Get(context);
        Console.WriteLine(value);
    }
}

This change is Reviewable

@LukasBenner
Copy link
Author

@dotnet-policy-service agree company="Mitutoyo CTL Germany GmbH"

@LukasBenner LukasBenner changed the title Conditional inputs in elsa 3 Conditional inputs Feb 14, 2025
@bobhauser
Copy link
Contributor

bobhauser commented Feb 14, 2025

I'm not sure if your use case is similar to the one we had or not... Our use case is that we have a RunScript task that offers a list of separately controlled scripts that can be selected to be run. Each script has a a different set of parameters which could be configured. The solution we came up with was to support maps of script parameter and Input. So for one script you could have a "param1" parameter that is an Input<string>, and a "param2" that is an Input<bool> - and a different script could have completely different arguments. This is the PR that implements this: #5429. We don't use Elsa Studio, so there is certainly a gap there.

Your case could be completely different, and if it is, please just ignore this comment.

@LukasBenner
Copy link
Author

Thanks for your comment @bobhauser.
I think there are indeed some similarities between these PRs.
But I think the usecases aren't exactly the same.
The idea behind this PR is to show inputs in the UI based on the state of the activity which can be altered by e.g. a StateDropdownInput.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants