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

Prevent duplicate 'Default' switch cases #155

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- 'main'
- 'feature/*'
- 'issue/*'
- 'enhancement/*'
- 'patch/*'
- 'fix/*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
using Elsa.Api.Client.Shared.Models;
using Elsa.Studio.Workflows.Domain.Contexts;
using Elsa.Studio.Workflows.Domain.Providers;
using JetBrains.Annotations;

namespace Elsa.Studio.ActivityPortProviders.Providers;

/// <summary>
/// Provides ports for the FlowSwitch activity based on its cases.
/// </summary>
[UsedImplicitly]
public class FlowSwitchPortProvider : ActivityPortProviderBase
{
/// <inheritdoc />
Expand All @@ -23,7 +25,7 @@ public override IEnumerable<Port> GetPorts(PortProviderContext context)
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};

var cases = context.Activity.GetProperty<List<SwitchCase>>(options, "cases") ?? new List<SwitchCase>();

foreach (var @case in cases)
Expand All @@ -36,6 +38,9 @@ public override IEnumerable<Port> GetPorts(PortProviderContext context)
};
}

if (cases.Any(x => x.Label == "Default"))
yield break;

yield return new Port
{
Name = "Default",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SwitchPortProvider : ActivityPortProviderBase
/// <inheritdoc />
public override IEnumerable<Port> GetPorts(PortProviderContext context)
{
var cases = GetCases(context.Activity);
var cases = GetCases(context.Activity).ToList();

foreach (var @case in cases)
{
Expand All @@ -31,6 +31,9 @@ public override IEnumerable<Port> GetPorts(PortProviderContext context)
};
}

if (cases.Any(x => GetLabel(x) == "Default"))
yield break;

yield return new Port
{
Name = "Default",
Expand Down