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

Define inputs in reusable objects #3148

Merged
merged 2 commits into from
Jun 23, 2022
Merged

Define inputs in reusable objects #3148

merged 2 commits into from
Jun 23, 2022

Conversation

stuartmcgillivray
Copy link

@stuartmcgillivray stuartmcgillivray commented Jun 22, 2022

Expanding ActivtyInput functionality to allow classes to be used for re-usable input properties across activities.

Overview

ActivityInputObjectAttribute

The ActivityInputObjectAttribute identifies a class to extract ActivityInputs from.

A category can be provided on the ActivityInputObjectAttribute that will be added to all of the properties in that class that don't provide their own category.

        [ActivityInputObject(Category ="Example Category")]
        public ExtraProperties Example { get; set; }

Designer

The properties will appear in the designer form as if they were added directly to the activity.

Examples

Setting Category with ActivityInputObjectAttribute

image

    public class ExtraProperties
    {
        [ActivityInput(Hint = "The base URL.",
            UIHint = ActivityInputUIHints.SingleLine,
            SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.Liquid, SyntaxNames.JavaScript })]
        public string BaseUrl { get; set; }

        [ActivityInput(Hint = "The REST Port.",
            UIHint = ActivityInputUIHints.SingleLine,
            SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.Liquid, SyntaxNames.JavaScript })]
        public int? RestPort { get; set; }

        [ActivityInput(Hint = "The Grant Type to authenticate.",
            UIHint = ActivityInputUIHints.SingleLine,
            SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.Liquid, SyntaxNames.JavaScript })]
        public string GrantType { get; set; }

        [ActivityInput(Hint = "The Username to authenticate.",
            UIHint = ActivityInputUIHints.SingleLine,
            SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.Liquid, SyntaxNames.JavaScript })]
        public string RestUsername { get; set; }

        [ActivityInput(Hint = "The Password to authenticate",
            UIHint = ActivityInputUIHints.SingleLine,
            SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.Liquid, SyntaxNames.JavaScript })]
        public string RestPassword { get; set; }
    }

    public class ExampleActivity : Activity
    {

        [ActivityInputObject(Category = "Example Category")]
        public ExtraProperties Example { get; set; }

        [ActivityInput(Hint = "The text to write.", SupportedSyntaxes = new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid })]
        public string? Text { get; set; }

        private readonly TextWriter _output;

        protected override async ValueTask<IActivityExecutionResult> OnExecuteAsync(ActivityExecutionContext context)
        {
            return Done();
        }
    }

Overwrite ActivityInputObjectAttribute Category

image

public class ExtraProperties
{
        [ActivityInput(Category = "Rest Configuration",
            Hint = "The base URL.",
            UIHint = ActivityInputUIHints.SingleLine,
            SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.Liquid, SyntaxNames.JavaScript })]
        public string BaseUrl { get; set; }

        [ActivityInput(Category = "Rest Configuration",
            Hint = "The REST Port.",
            UIHint = ActivityInputUIHints.SingleLine,
            SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.Liquid, SyntaxNames.JavaScript })]
        public int? RestPort { get; set; }

        [ActivityInput(Category = "Rest Configuration",
            Hint = "The Grant Type to authenticate.",
            UIHint = ActivityInputUIHints.SingleLine,
            SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.Liquid, SyntaxNames.JavaScript })]
        public string GrantType { get; set; }

        [ActivityInput(Category = "Rest Configuration",
            Hint = "The Username to authenticate.",
            UIHint = ActivityInputUIHints.SingleLine,
            SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.Liquid, SyntaxNames.JavaScript })]
        public string RestUsername { get; set; }

        [ActivityInput(Category = "Rest Configuration",
            Hint = "The Password to authenticate",
            UIHint = ActivityInputUIHints.SingleLine,
            SupportedSyntaxes = new[] { SyntaxNames.Literal, SyntaxNames.Liquid, SyntaxNames.JavaScript })]
        public string RestPassword { get; set; }
}

public class ExampleActivity : Activity
{

        [ActivityInputObject(Category ="Example Category")]
        public ExtraProperties Example { get; set; }

        [ActivityInput(Hint = "The text to write.", SupportedSyntaxes = new[] { SyntaxNames.JavaScript, SyntaxNames.Liquid })]
        public string? Text { get; set; }

        protected override async ValueTask<IActivityExecutionResult> OnExecuteAsync(ActivityExecutionContext context)
        {
            return Done();
        }
}

@sfmskywalker
Copy link
Member

That is awesome!

@sfmskywalker sfmskywalker merged commit c4bade7 into elsa-workflows:master Jun 23, 2022
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.

None yet

2 participants