Browse Source

fix: Invalid notification filtering has been fixed

pull/1568/head
colin 3 weeks ago
parent
commit
f85f3914b7
  1. 1
      aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Blazor/Localization/Resources/ElsaStudioBlazor/en.json
  2. 1
      aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Blazor/Localization/Resources/ElsaStudioBlazor/zh-Hans.json
  3. 27
      aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Components/NotificationPicker.razor
  4. 106
      aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Components/NotificationPicker.razor.cs
  5. 155
      aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Components/NotificationSelectDialog.razor
  6. 3
      aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext/LINGYUN/Abp/ElsaNext/UIHints/AbpElsaUIHints.cs

1
aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Blazor/Localization/Resources/ElsaStudioBlazor/en.json

@ -5,6 +5,7 @@
"Menu:WorkflowDefinitions": "Workflow Definitions",
"Menu:WorkflowInstances": "Workflow Instances",
"Menu:Settings": "Settings",
"Select": "Select",
"14 days": "14 days",
"180 days": "180 days",
"30 days": "30 days",

1
aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Blazor/Localization/Resources/ElsaStudioBlazor/zh-Hans.json

@ -5,6 +5,7 @@
"Menu:WorkflowDefinitions": "工作流定义",
"Menu:WorkflowInstances": "工作流实例",
"Menu:Settings": "设置",
"Select": "选择",
"180 days": "180 天",
"30 days": "30 天",
"7 days": "7 天",

27
aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Components/NotificationPicker.razor

@ -1,4 +1,4 @@
@using Elsa.Api.Client.Shared.UIHints.DropDown
@using LINGYUN.Abp.ElsaNext.Studio.Blazor.Components
@inject ILocalizer Localizer
@inherits StudioComponentBase
@ -6,25 +6,18 @@
var inputDescriptor = EditorContext.InputDescriptor;
var displayName = inputDescriptor.DisplayName;
var description = inputDescriptor.Description;
var selectedValue = GetSelectedValue();
}
<ExpressionInput EditorContext="@EditorContext">
<ChildContent>
<MudSelectExtended
T="SelectListItem"
Label="@Localizer[displayName]"
Variant="Variant.Outlined"
HelperText="@Localizer[description]"
Margin="Margin.Dense"
Value="@selectedValue"
SearchBox="true"
OnSearchStringChange="OnSearch"
ItemCollection="@_items"
ToStringFunc="@(item => item?.Text ?? "")"
ValueChanged="OnValueChanged"
ReadOnly="EditorContext.IsReadOnly"
Disabled="EditorContext.IsReadOnly">
</MudSelectExtended>
<MudTextFieldEx Value="@(_selectedItem?.Text ?? string.Empty)"
Label="@Localizer[displayName]"
HelperText="@Localizer[description]"
Variant="Variant.Outlined"
Margin="Margin.Dense"
ReadOnly="true"
Disabled="EditorContext.IsReadOnly"
OnFieldClick="@(_ => OpenSelectDialogAsync())"
AdornmentIcons="GetAdornmentIcons()" />
</ChildContent>
</ExpressionInput>

106
aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Components/NotificationPicker.razor.cs

@ -1,54 +1,110 @@
using Elsa.Api.Client.Shared.UIHints.DropDown;
using Elsa.Studio.Models;
using LINGYUN.Abp.ElsaNext.Studio.Blazor.Components;
using LINGYUN.Abp.Notifications;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using System.Collections.Generic;
using System.Linq;
using MudBlazor;
using System.Threading.Tasks;
namespace LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor.Components;
public partial class NotificationPicker
{
private ICollection<SelectListItem> _items = [];
private IReadOnlyList<SelectListItem> _notifications = [];
private SelectListItem? _selectedItem;
[Parameter] public DisplayInputEditorContext EditorContext { get; set; } = null!;
[Inject] protected IDialogService DialogService { get; set; } = null!;
[Inject] private IStringLocalizerFactory StringLocalizerFactory { get; set; } = null!;
[Inject] private INotificationDefinitionManager NotificationDefinitionManager { get; set; } = null!;
private SelectListItem? GetSelectedValue()
protected async override Task OnInitializedAsync()
{
var value = EditorContext.GetLiteralValueOrDefault();
return _items.FirstOrDefault(x => x.Value == value);
}
var selectedItem = await ResolveSelectedItemAsync();
private void OnSearch(string? filter)
{
_items = _notifications
.WhereIf(!string.IsNullOrWhiteSpace(filter), x => x.Text.Contains(filter!))
.Take(10)
.ToList();
if (selectedItem != null)
{
await InvokeAsync(() => _selectedItem = selectedItem);
}
}
private async Task OnValueChanged(SelectListItem? value)
private async Task<SelectListItem?> ResolveSelectedItemAsync()
{
await EditorContext.UpdateValueOrLiteralExpressionAsync(value?.Value ?? "");
var value = EditorContext.GetLiteralValueOrDefault();
if (string.IsNullOrWhiteSpace(value))
{
return null;
}
var notificationDefine = await NotificationDefinitionManager.GetOrNullAsync(value);
if (notificationDefine != null)
{
return new SelectListItem(notificationDefine.DisplayName.Localize(StringLocalizerFactory), notificationDefine.Name);
}
return new SelectListItem(value, value);
}
protected async override Task OnInitializedAsync()
private async Task OpenSelectDialogAsync()
{
var notifications = await NotificationDefinitionManager.GetNotificationsAsync();
if (EditorContext.IsReadOnly)
{
return;
}
_notifications = notifications
.Select(notification =>
new SelectListItem(
notification.DisplayName.Localize(StringLocalizerFactory), notification.Name))
.OrderBy(x => x.Text)
.ToList();
var inputDescriptor = EditorContext.InputDescriptor;
var parameters = new DialogParameters<NotificationSelectDialog>
{
{ x => x.Title, Localizer[inputDescriptor.DisplayName ?? inputDescriptor.Name] },
{ x => x.SelectedValue, _selectedItem?.Value }
};
var options = new DialogOptions
{
CloseOnEscapeKey = true,
FullWidth = true,
MaxWidth = MaxWidth.Medium
};
_items = _notifications.Take(10).ToList();
var dialog = await DialogService.ShowAsync<NotificationSelectDialog>(string.Empty, parameters, options);
var result = await dialog.Result;
if (result is { Canceled: false, Data: SelectListItem item })
{
await InvokeAsync(async () =>
{
_selectedItem = item;
await EditorContext.UpdateValueOrLiteralExpressionAsync(item.Value);
});
}
}
private MudTextFieldExIcon[] GetAdornmentIcons() =>
[
new()
{
Icon = Icons.Material.Filled.Search,
Tooltip = Localizer["Search"],
Disabled = EditorContext.IsReadOnly,
OnClick = OpenSelectDialogAsync
},
new()
{
Icon = Icons.Material.Filled.Clear,
Tooltip = Localizer["Clear"],
Visible = _selectedItem != null,
Disabled = EditorContext.IsReadOnly,
OnClick = ClearAsync
}
];
private async Task ClearAsync()
{
await InvokeAsync(async () =>
{
_selectedItem = null;
await EditorContext.UpdateValueOrLiteralExpressionAsync(string.Empty);
});
}
}

155
aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext.Studio.Notifications.Blazor/Components/NotificationSelectDialog.razor

@ -0,0 +1,155 @@
@using System.Threading
@using Elsa.Api.Client.Shared.UIHints.DropDown
@using LINGYUN.Abp.Notifications
@using Microsoft.Extensions.Localization
@inject ILocalizer Localizer
@implements IDisposable
<MudDialog>
<TitleContent>
<MudText Typo="Typo.h6">@Title</MudText>
</TitleContent>
<DialogContent>
<MudStack Spacing="3">
<MudTextField T="string"
Value="_searchText"
ValueChanged="OnSearchTextChangedAsync"
Immediate="true"
Placeholder="@Localizer["Search"]"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.Search"
Variant="Variant.Outlined"
Margin="Margin.Dense" />
<MudTable T="SelectListItem"
@ref="_table"
ServerData="LoadTenantsAsync"
Dense="true"
Hover="true"
Breakpoint="Breakpoint.None"
OnRowClick="OnRowClickAsync">
<HeaderContent>
<MudTh>@Localizer["Name"]</MudTh>
<MudTh Style="text-align:right" />
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="@Localizer["Name"]">@context.Text</MudTd>
<MudTd DataLabel="" Style="text-align:right">
@if (context.Value == SelectedValue)
{
<MudIcon Icon="@Icons.Material.Filled.Check" Color="Color.Success" Size="Size.Small" />
}
else
{
<MudButton Size="Size.Small" Variant="Variant.Text" Color="Color.Primary" OnClick="@(() => SelectAsync(context))">
@Localizer["Select"]
</MudButton>
}
</MudTd>
</RowTemplate>
<PagerContent>
<MudTablePager
PageSizeOptions="new int[] { 10, 25, 50, 100 }"/>
</PagerContent>
<NoRecordsContent>
<MudText Typo="Typo.body2">@Localizer["No results found"]</MudText>
</NoRecordsContent>
</MudTable>
</MudStack>
</DialogContent>
<DialogActions>
<MudButton Variant="Variant.Text" OnClick="CancelAsync">@Localizer["Cancel"]</MudButton>
</DialogActions>
</MudDialog>
@code {
private const int DebounceIntervalMilliseconds = 350;
private MudTable<SelectListItem>? _table;
private string? _searchText;
private CancellationTokenSource? _debounceCancellationTokenSource;
[CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!;
[Parameter] public string Title { get; set; } = string.Empty;
[Parameter] public string? SelectedValue { get; set; }
[Inject] private IStringLocalizerFactory StringLocalizerFactory { get; set; } = null!;
[Inject] private INotificationDefinitionManager NotificationDefinitionManager { get; set; } = null!;
public void Dispose()
{
_debounceCancellationTokenSource?.Cancel();
_debounceCancellationTokenSource?.Dispose();
}
private async Task OnSearchTextChangedAsync(string? searchValue)
{
_searchText = searchValue;
_debounceCancellationTokenSource?.Cancel();
_debounceCancellationTokenSource?.Dispose();
_debounceCancellationTokenSource = new CancellationTokenSource();
try
{
await Task.Delay(DebounceIntervalMilliseconds, _debounceCancellationTokenSource.Token);
var table = _table;
if (table != null)
{
await InvokeAsync(() => table.ReloadServerData());
}
}
catch (OperationCanceledException)
{
}
}
private async Task<TableData<SelectListItem>> LoadTenantsAsync(TableState state, CancellationToken cancellationToken)
{
var filter = string.IsNullOrWhiteSpace(_searchText) ? null : _searchText.Trim();
var notifications = await NotificationDefinitionManager.GetNotificationsAsync();
var items = notifications
.Select(notification => new SelectListItem(
notification.DisplayName.Localize(StringLocalizerFactory),
notification.Name))
.WhereIf(!string.IsNullOrWhiteSpace(filter), x => x.Text.Contains(filter!) || x.Value.Contains(filter!))
.OrderBy(x => x.Text)
.Skip(state.Page * state.PageSize)
.Take(state.PageSize)
.ToList();
return new TableData<SelectListItem>
{
Items = items,
TotalItems = notifications.Count,
};
}
private async Task OnRowClickAsync(TableRowClickEventArgs<SelectListItem> args)
{
await SelectAsync(args.Item);
}
private Task SelectAsync(SelectListItem? item)
{
if (item == null)
{
return Task.CompletedTask;
}
MudDialog.Close(DialogResult.Ok(item));
return Task.CompletedTask;
}
private void CancelAsync()
{
MudDialog.Cancel();
}
}

3
aspnet-core/modules/elsa/LINGYUN.Abp.ElsaNext/LINGYUN/Abp/ElsaNext/UIHints/AbpElsaUIHints.cs

@ -1,7 +1,8 @@
namespace LINGYUN.Abp.ElsaNext.UIHints;
namespace LINGYUN.Abp.ElsaNext.UIHints;
public static class AbpElsaUIHints
{
public const string TenantPicker = "tenant-picker";
public const string UserPicker = "user-picker";
public const string UserPickerMultiple = "user-picker-multiple";
}

Loading…
Cancel
Save