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

Fixed ordering in workflow definitions #84

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@
</ToolBarContent>
<HeaderContent>
<MudTh>
<MudTableSortLabel SortLabel="ID" T="WorkflowDefinitionSummary">ID</MudTableSortLabel>
<MudTableSortLabel SortLabel="ID" T="WorkflowDefinitionRow">ID</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortLabel="Name" T="WorkflowDefinitionSummary">Name</MudTableSortLabel>
<MudTableSortLabel SortLabel="Name" T="WorkflowDefinitionRow">Name</MudTableSortLabel>
</MudTh>
<MudTh Style="text-align:left">
<MudTableSortLabel SortLabel="LatestVersion" T="WorkflowDefinitionSummary" Style="text-align: right;">Latest version</MudTableSortLabel>
<MudTableSortLabel SortLabel="LatestVersion" T="WorkflowDefinitionRow" Style="text-align: right;">Latest version</MudTableSortLabel>
</MudTh>
<MudTh Style="text-align:left">
<MudTableSortLabel SortLabel="PublishedVersion" T="WorkflowDefinitionSummary" Style="text-align: right;">Published version</MudTableSortLabel>
<MudTableSortLabel SortLabel="PublishedVersion" T="WorkflowDefinitionRow" Style="text-align: right;">Published version</MudTableSortLabel>
</MudTh>
<MudTh>
Description
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Elsa.Api.Client.Converters;
using Elsa.Api.Client.Resources.WorkflowDefinitions.Enums;
using Elsa.Api.Client.Resources.WorkflowDefinitions.Models;
using Elsa.Api.Client.Resources.WorkflowDefinitions.Responses;
using Elsa.Api.Client.Shared.Models;
Expand Down Expand Up @@ -37,11 +38,17 @@ private async Task<TableData<WorkflowDefinitionRow>> ServerReload(TableState sta
var request = new ListWorkflowDefinitionsRequest
{
Page = state.Page,
PageSize = state.PageSize
PageSize = state.PageSize,
OrderBy = GetOrderBy(state.SortLabel),
OrderDirection = state.SortDirection == SortDirection.Descending
? OrderDirection.Descending
: OrderDirection.Ascending
};

var latestWorkflowDefinitionsResponse = await WorkflowDefinitionService.ListAsync(request, VersionOptions.Latest);
var unpublishedWorkflowDefinitionIds = latestWorkflowDefinitionsResponse.Items.Where(x => !x.IsPublished).Select(x => x.DefinitionId).ToList();
var latestWorkflowDefinitionsResponse =
await WorkflowDefinitionService.ListAsync(request, VersionOptions.Latest);
var unpublishedWorkflowDefinitionIds = latestWorkflowDefinitionsResponse.Items.Where(x => !x.IsPublished)
.Select(x => x.DefinitionId).ToList();

var publishedWorkflowDefinitions = await WorkflowDefinitionService.ListAsync(new ListWorkflowDefinitionsRequest
{
Expand All @@ -60,11 +67,30 @@ private async Task<TableData<WorkflowDefinitionRow>> ServerReload(TableState sta
: publishedWorkflowDefinitions.Items.FirstOrDefault(x => x.DefinitionId == definition.DefinitionId);
var publishedVersionNumber = publishedVersion?.Version;

return new WorkflowDefinitionRow(definition.Id, definition.DefinitionId, latestVersionNumber, publishedVersionNumber, definition.Name, definition.Description, definition.IsPublished);
return new WorkflowDefinitionRow(
definition.Id,
definition.DefinitionId,
latestVersionNumber,
publishedVersionNumber,
definition.Name,
definition.Description,
definition.IsPublished);
})
.ToList();

return new TableData<WorkflowDefinitionRow> { TotalItems = (int)_totalCount, Items = latestWorkflowDefinitions };
return new TableData<WorkflowDefinitionRow>
{ TotalItems = (int)_totalCount, Items = latestWorkflowDefinitions };
}

private OrderByWorkflowDefinition? GetOrderBy(string sortLabel)
{
return sortLabel switch
{
"Name" => OrderByWorkflowDefinition.Name,
"Version" => OrderByWorkflowDefinition.Version,
"Created" => OrderByWorkflowDefinition.Created,
_ => null
};
}

private async Task OnCreateWorkflowClicked()
Expand All @@ -91,7 +117,9 @@ private async Task OnCreateWorkflowClicked()
if (!dialogResult.Canceled)
{
var newWorkflowModel = (WorkflowMetadataModel)dialogResult.Data;
var result = await WorkflowDefinitionService.CreateNewDefinitionAsync(newWorkflowModel.Name!, newWorkflowModel.Description!);
var result =
await WorkflowDefinitionService.CreateNewDefinitionAsync(newWorkflowModel.Name!,
newWorkflowModel.Description!);

result.OnSuccess(definition => Edit(definition.DefinitionId));
result.OnFailed(errors => Snackbar.Add(string.Join(Environment.NewLine, errors.Errors)));
Expand Down Expand Up @@ -121,7 +149,8 @@ private void OnRowClick(TableRowClickEventArgs<WorkflowDefinitionRow> e)

private async Task OnDeleteClicked(WorkflowDefinitionRow workflowDefinitionRow)
{
var result = await DialogService.ShowMessageBox("Delete workflow?", "Are you sure you want to delete this workflow?", yesText: "Delete", cancelText: "Cancel");
var result = await DialogService.ShowMessageBox("Delete workflow?",
"Are you sure you want to delete this workflow?", yesText: "Delete", cancelText: "Cancel");

if (result != true)
return;
Expand All @@ -133,14 +162,17 @@ private async Task OnDeleteClicked(WorkflowDefinitionRow workflowDefinitionRow)

private async Task OnDownloadClicked(WorkflowDefinitionRow workflowDefinitionRow)
{
var download = await WorkflowDefinitionService.ExportDefinitionAsync(workflowDefinitionRow.DefinitionId, VersionOptions.Latest);
var download =
await WorkflowDefinitionService.ExportDefinitionAsync(workflowDefinitionRow.DefinitionId,
VersionOptions.Latest);
var fileName = $"{workflowDefinitionRow.Name.Kebaberize()}.json";
await Files.DownloadFileFromStreamAsync(fileName, download.Content);
}

private async Task OnBulkDeleteClicked()
{
var result = await DialogService.ShowMessageBox("Delete selected workflows?", "Are you sure you want to delete the selected workflows?", yesText: "Delete", cancelText: "Cancel");
var result = await DialogService.ShowMessageBox("Delete selected workflows?",
"Are you sure you want to delete the selected workflows?", yesText: "Delete", cancelText: "Cancel");

if (result != true)
return;
Expand All @@ -152,7 +184,8 @@ private async Task OnBulkDeleteClicked()

private async Task OnBulkPublishClicked()
{
var result = await DialogService.ShowMessageBox("Publish selected workflows?", "Are you sure you want to publish the selected workflows?", yesText: "Publish", cancelText: "Cancel");
var result = await DialogService.ShowMessageBox("Publish selected workflows?",
"Are you sure you want to publish the selected workflows?", yesText: "Publish", cancelText: "Cancel");

if (result != true)
return;
Expand All @@ -162,19 +195,25 @@ private async Task OnBulkPublishClicked()

if (response.Published.Count > 0)
{
var message = response.Published.Count == 1 ? "One workflow is published" : $"{response.Published.Count} workflows are published";
var message = response.Published.Count == 1
? "One workflow is published"
: $"{response.Published.Count} workflows are published";
Snackbar.Add(message, Severity.Success, options => { options.SnackbarVariant = Variant.Filled; });
}

if (response.AlreadyPublished.Count > 0)
{
var message = response.AlreadyPublished.Count == 1 ? "One workflow is already published" : $"{response.AlreadyPublished.Count} workflows are already published";
var message = response.AlreadyPublished.Count == 1
? "One workflow is already published"
: $"{response.AlreadyPublished.Count} workflows are already published";
Snackbar.Add(message, Severity.Info, options => { options.SnackbarVariant = Variant.Filled; });
}

if (response.NotFound.Count > 0)
{
var message = response.NotFound.Count == 1 ? "One workflow is not found" : $"{response.NotFound.Count} workflows are not found";
var message = response.NotFound.Count == 1
? "One workflow is not found"
: $"{response.NotFound.Count} workflows are not found";
Snackbar.Add(message, Severity.Warning, options => { options.SnackbarVariant = Variant.Filled; });
}

Expand All @@ -183,7 +222,8 @@ private async Task OnBulkPublishClicked()

private async Task OnBulkRetractClicked()
{
var result = await DialogService.ShowMessageBox("Unpublish selected workflows?", "Are you sure you want to unpublish the selected workflows?", yesText: "Unpublish", cancelText: "Cancel");
var result = await DialogService.ShowMessageBox("Unpublish selected workflows?",
"Are you sure you want to unpublish the selected workflows?", yesText: "Unpublish", cancelText: "Cancel");

if (result != true)
return;
Expand All @@ -193,19 +233,25 @@ private async Task OnBulkRetractClicked()

if (response.Retracted.Count > 0)
{
var message = response.Retracted.Count == 1 ? "One workflow is unpublished" : $"{response.Retracted.Count} workflows are unpublished";
var message = response.Retracted.Count == 1
? "One workflow is unpublished"
: $"{response.Retracted.Count} workflows are unpublished";
Snackbar.Add(message, Severity.Success, options => { options.SnackbarVariant = Variant.Filled; });
}

if (response.AlreadyRetracted.Count > 0)
{
var message = response.AlreadyRetracted.Count == 1 ? "One workflow is already unpublished" : $"{response.AlreadyRetracted.Count} workflows are already unpublished";
var message = response.AlreadyRetracted.Count == 1
? "One workflow is already unpublished"
: $"{response.AlreadyRetracted.Count} workflows are already unpublished";
Snackbar.Add(message, Severity.Info, options => { options.SnackbarVariant = Variant.Filled; });
}

if (response.NotFound.Count > 0)
{
var message = response.NotFound.Count == 1 ? "One workflow is not found" : $"{response.NotFound.Count} workflows are not found";
var message = response.NotFound.Count == 1
? "One workflow is not found"
: $"{response.NotFound.Count} workflows are not found";
Snackbar.Add(message, Severity.Warning, options => { options.SnackbarVariant = Variant.Filled; });
}

Expand Down Expand Up @@ -252,5 +298,6 @@ private async Task OnRetractClicked(string definitionId)
Snackbar.Add("Workflow retracted", Severity.Success, options => { options.SnackbarVariant = Variant.Filled; });
}

private record WorkflowDefinitionRow(string Id, string DefinitionId, int LatestVersion, int? PublishedVersion, string? Name, string? Description, bool IsPublished);
private record WorkflowDefinitionRow(string Id, string DefinitionId, int LatestVersion, int? PublishedVersion,
string? Name, string? Description, bool IsPublished);
}
Loading