-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Persistence strategy at Workflow / Activity Level (#136)
* Add Persistence strategy at Workflow / Activity Level * remove using about removed Contracts * refactor and renaming to LogPersistenceMode * Refactor PersistenceTab and update project references Updated various aspects of the PersistenceTab class and its functionality to improve code quality and readability. Simplified the handling of persistence configurations and simplified the use of properties. Transitioned project reference for Elsa.Api.Client from package reference to direct project reference for better development experience in Elsa.Studio.Core. * rename GetSelectComponent2 to GetSelectComponent * Consolidate project files and update Elsa.Api.Client package This commit consolidates various project properties files into a single Directory.Build.props file, simplifying the project file structure and reducing duplication. The version of the Elsa.Api.Client package reference is updated and the package is now being directly referenced instead of via a project reference. JetBrains.Annotations usage has been removed as well. * Update package version in GitHub workflows The version of the package in the GitHub workflows has been updated from 3.1.0 to 3.2.0. This was done to ensure consistency with the project's latest release and standards. * Refactor code for readability in Settings.razor The code in Settings.razor has been cleaned up with extraneous spaces removed and alignment of attributes fixed. This modification enhances code readability and maintainability in the workflow properties' settings section. * Refactor code formatting in Settings.razor.cs Adjusted the code formatting to improve readability in Settings.razor.cs. The modifications mainly include adding extra line breaks and removing unnecessary white space. No functionality was changed in this commit. --------- Co-authored-by: Jérémie DEVILLARD <[email protected]> Co-authored-by: Sipke Schoorstra <[email protected]>
- Loading branch information
1 parent
0a3b6c0
commit 145dfbb
Showing
13 changed files
with
298 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project> | ||
|
||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" /> | ||
|
||
<PropertyGroup Label="TargetFrameworks"> | ||
<TargetFrameworks>net7.0;net8.0</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Label="Files"> | ||
<None Include="..\..\..\icon.png" Pack="true" PackagePath="\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="ConfigureAwait.Fody" PrivateAssets="All" /> | ||
<PackageReference Include="Fody" PrivateAssets="All" /> | ||
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" /> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" /> | ||
</ItemGroup> | ||
|
||
</Project> |
2 changes: 0 additions & 2 deletions
2
src/framework/Elsa.Studio.Core.BlazorServer/Extensions/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/framework/Elsa.Studio.Core.BlazorWasm/Extensions/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...mponents/WorkflowDefinitionEditor/Components/ActivityProperties/Tabs/PersistenceTab.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
@using Elsa.Api.Client.Resources.ActivityDescriptors.Models | ||
@using Elsa.Api.Client.Resources.WorkflowDefinitions.Enums | ||
@using Variant = MudBlazor.Variant | ||
@inherits StudioComponentBase | ||
|
||
|
||
@{ | ||
|
||
RenderFragment GetSelectComponent(String propertyName, IDictionary<string, LogPersistenceMode> properties) => | ||
@<MudSelect Label="@propertyName" | ||
T="LogPersistenceMode" | ||
Variant="@MudBlazor.Variant.Outlined" | ||
Value="@GetProperty(propertyName,properties)" | ||
ValueChanged="@((value) => SetProperty(propertyName,properties,value))" | ||
ToStringFunc="@(x=> x.ToString())" | ||
ReadOnly="IsReadOnly" | ||
SelectedValuesChanged="(values)=>OnBindingChanged()"> | ||
@foreach (LogPersistenceMode item in Enum.GetValues(typeof(LogPersistenceMode))) | ||
{ | ||
<MudSelectItem Value="@item"></MudSelectItem> | ||
} | ||
</MudSelect> | ||
; | ||
|
||
} | ||
<div class="pa-4"> | ||
<MudForm ReadOnly="IsReadOnly"> | ||
<MudStack Spacing="6"> | ||
<MudText Typo="Typo.overline">Default configuration</MudText> | ||
<MudSelect Label="Default Configuration" | ||
T=LogPersistenceMode | ||
Variant="@MudBlazor.Variant.Outlined" | ||
Value="@_persistenceConfiguration.Default" | ||
ValueChanged="@(async (bindingOption) => _persistenceConfiguration.Default = bindingOption)" | ||
ToStringFunc="@(x=> x.ToString())" | ||
ReadOnly="IsReadOnly" | ||
SelectedValuesChanged="(values)=>OnBindingChanged()"> | ||
@foreach (LogPersistenceMode item in Enum.GetValues(typeof(LogPersistenceMode))) | ||
{ | ||
<MudSelectItem Value="@item"></MudSelectItem> | ||
} | ||
|
||
</MudSelect> | ||
<MudDivider /> | ||
<MudText Typo="Typo.overline">Input Properties</MudText> | ||
@if(!InputDescriptors.Any()) | ||
{ | ||
<Well> | ||
<MudAlert Severity="Severity.Normal" Variant="Variant.Text">This activity does not have any input properties.</MudAlert> | ||
</Well> | ||
} | ||
@foreach(var input in InputDescriptors) | ||
{ | ||
@GetSelectComponent(input.Name, _persistenceConfiguration.Inputs); | ||
} | ||
|
||
<MudDivider /> | ||
<MudText Typo="Typo.overline">Output Properties</MudText> | ||
@if (!OutputDescriptors.Any()) | ||
{ | ||
<Well> | ||
<MudAlert Severity="Severity.Normal" Variant="Variant.Text">This activity does not have any output properties.</MudAlert> | ||
</Well> | ||
} | ||
@foreach (var output in OutputDescriptors) | ||
{ | ||
@GetSelectComponent(output.Name, _persistenceConfiguration.Outputs); | ||
} | ||
</MudStack> | ||
</MudForm> | ||
|
||
<MudOverlay Visible="@IsReadOnly" Absolute="true" /> | ||
</div> |
137 changes: 137 additions & 0 deletions
137
...nents/WorkflowDefinitionEditor/Components/ActivityProperties/Tabs/PersistenceTab.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
using Elsa.Api.Client.Extensions; | ||
using Elsa.Api.Client.Resources.ActivityDescriptors.Models; | ||
using Elsa.Api.Client.Resources.WorkflowDefinitions.Enums; | ||
using Elsa.Api.Client.Resources.WorkflowDefinitions.Models; | ||
using Elsa.Studio.Workflows.UI.Contracts; | ||
using Humanizer; | ||
using Microsoft.AspNetCore.Components; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Elsa.Studio.Workflows.Components.WorkflowDefinitionEditor.Components.ActivityProperties.Tabs; | ||
|
||
/// <summary> | ||
/// Represents the persistence tab. | ||
/// </summary> | ||
public partial class PersistenceTab | ||
{ | ||
/// An event raised when the activity is updated. | ||
[Parameter] public Func<JsonObject, Task>? OnActivityUpdated { get; set; } | ||
/// <summary> | ||
/// Gets or sets the workflow definition. | ||
/// </summary> | ||
[Parameter] | ||
public WorkflowDefinition? WorkflowDefinition { get; set; } | ||
/// <summary> | ||
/// Gets or sets the activity to edit. | ||
/// </summary> | ||
[Parameter] | ||
public JsonObject? Activity { get; set; } | ||
/// <summary> | ||
/// The workspace. | ||
/// </summary> | ||
[CascadingParameter] public IWorkspace? Workspace { get; set; } | ||
/// <summary> | ||
/// Gets or sets the activity descriptor. | ||
/// </summary> | ||
[Parameter] | ||
public ActivityDescriptor? ActivityDescriptor { get; set; } | ||
|
||
private ICollection<InputDescriptor> InputDescriptors { get; set; } = new List<InputDescriptor>(); | ||
private ICollection<OutputDescriptor> OutputDescriptors { get; set; } = new List<OutputDescriptor>(); | ||
private bool IsReadOnly => Workspace?.IsReadOnly == true; | ||
private PersistenceActivityConfiguration _persistenceConfiguration = new(); | ||
private JsonSerializerOptions _serializerOptions = default!; | ||
private const string LogPersistenceModeKey = "logPersistenceMode"; | ||
|
||
/// <inheritdoc /> | ||
protected override void OnInitialized() | ||
{ | ||
_persistenceConfiguration = new PersistenceActivityConfiguration(); | ||
_serializerOptions = new System.Text.Json.JsonSerializerOptions() | ||
{ | ||
PropertyNameCaseInsensitive = true, | ||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase | ||
}; | ||
_serializerOptions.Converters.Add(new JsonStringEnumConverter()); | ||
|
||
base.OnInitialized(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void OnParametersSet() | ||
{ | ||
if (Activity == null || ActivityDescriptor == null) | ||
return; | ||
|
||
InputDescriptors = ActivityDescriptor.Inputs.ToList(); | ||
OutputDescriptors = ActivityDescriptor.Outputs.ToList(); | ||
|
||
SetPersistenceProperties(); | ||
} | ||
|
||
private void SetPersistenceProperties() | ||
{ | ||
var customProperties = Activity?.GetProperty("customProperties"); | ||
if (customProperties == null) | ||
{ | ||
customProperties = new JsonObject(new List<KeyValuePair<string, JsonNode?>>()); | ||
Activity?.SetProperty(customProperties, "customProperties"); | ||
} | ||
|
||
var persistence = ((JsonObject)customProperties).GetProperty<PersistenceActivityConfiguration>(_serializerOptions, LogPersistenceModeKey) ?? new PersistenceActivityConfiguration(); | ||
|
||
_persistenceConfiguration = persistence; | ||
var props = _persistenceConfiguration.SerializeToNode(_serializerOptions); | ||
Activity?.SetProperty(props, "customProperties", LogPersistenceModeKey); | ||
} | ||
|
||
private async Task OnBindingChanged() | ||
{ | ||
var props = _persistenceConfiguration.SerializeToNode(_serializerOptions); | ||
Activity?.SetProperty(props, "customProperties", LogPersistenceModeKey); | ||
|
||
await RaiseActivityUpdated(); | ||
} | ||
|
||
private LogPersistenceMode GetProperty(string propertyName, IDictionary<string,LogPersistenceMode> properties) | ||
{ | ||
var prop = propertyName.Camelize(); | ||
if (properties.All(o => o.Key != prop)) | ||
properties[prop] = LogPersistenceMode.Default; | ||
return properties[prop]; | ||
} | ||
private void SetProperty(string propertyName, IDictionary<string, LogPersistenceMode> properties, LogPersistenceMode value) | ||
{ | ||
var prop = propertyName.Camelize(); | ||
properties[prop] = value; | ||
} | ||
private async Task RaiseActivityUpdated() | ||
{ | ||
if (OnActivityUpdated != null) | ||
await OnActivityUpdated(Activity!); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Defines the Persistence Strategy Configuration for an activity | ||
/// </summary> | ||
public class PersistenceActivityConfiguration | ||
{ | ||
/// <summary> | ||
/// Default Configuration Strategy for the activity | ||
/// </summary> | ||
public LogPersistenceMode Default { get; set; } = LogPersistenceMode.Default; | ||
|
||
/// <summary> | ||
/// Define Configuration Strategy for each Input properties | ||
/// </summary> | ||
public IDictionary<string, LogPersistenceMode> Inputs { get; set; } = new Dictionary<string, LogPersistenceMode>(); | ||
|
||
/// <summary> | ||
/// Define Configuration Strategy for each Output properties | ||
/// </summary> | ||
public IDictionary<string, LogPersistenceMode> Outputs { get; set; } = new Dictionary<string, LogPersistenceMode>(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.