feat: replace CategoryMultiSelectCombo with MudSelect for category selection; implement category loading and flattening logic
Build and Deploy / build (push) Failing after 16s

This commit is contained in:
masoodafar-web
2026-01-05 02:01:05 +03:30
parent 53f56636b3
commit 31226399ae
@@ -3,7 +3,6 @@
@using Microsoft.AspNetCore.Components.Forms
@using Tizzani.MudBlazor.HtmlEditor
@using BackOffice.Common.BaseComponents
@using BackOffice.Pages.AutoComplete
@inject ISnackbar Snackbar
<MudDialog>
@@ -112,13 +111,22 @@
<MudStack Spacing="1">
<MudText Typo="Typo.subtitle2">دسته‌بندی‌ها</MudText>
<CategoryMultiSelectCombo @bind-SelectedIds="_selectedCategoryIds"
Label="انتخاب دسته‌بندی‌ها"
Disabled="_loading" />
@if (_selectedCategoryIds?.Count > 0)
<MudSelect @bind-SelectedValues="_selectedCategoryIds"
Label="انتخاب دسته‌بندی‌ها"
Variant="Variant.Outlined"
Margin="Margin.Dense"
MultiSelection="true"
Disabled="_loading"
T="long">
@foreach (var category in _categories)
{
<MudSelectItem Value="@category.Id">@category.Title</MudSelectItem>
}
</MudSelect>
@if (_selectedCategoryIds?.Any() == true)
{
<MudText Typo="Typo.caption">
تعداد دسته‌بندی‌های انتخاب‌شده: @_selectedCategoryIds.Count
تعداد دسته‌بندی‌های انتخاب‌شده: @_selectedCategoryIds.Count()
</MudText>
}
</MudStack>
@@ -166,16 +174,58 @@
private IBrowserFile? _thumbnailImageFile;
private readonly long _maxAllowedSize = (1024 * 1024) * 5;
private string? _mainImagePreview;
private List<long> _selectedCategoryIds = new();
private IEnumerable<long> _selectedCategoryIds = new List<long>();
private List<DiscountCategoryDto> _categories = new();
protected override async Task OnInitializedAsync()
{
await LoadCategories();
if (Model.CategoryIds?.Any() == true)
{
_selectedCategoryIds = Model.CategoryIds;
}
}
private async Task LoadCategories()
{
try
{
var tree = await CategoryService.GetCategoriesAsync(isActive: true);
_categories = FlattenCategories(tree);
}
catch (Exception ex)
{
Snackbar.Add($"خطا در بارگذاری دسته‌بندی‌ها: {ex.Message}", Severity.Error);
}
}
private List<DiscountCategoryDto> FlattenCategories(List<DiscountCategoryDto> categories, string prefix = "")
{
var result = new List<DiscountCategoryDto>();
foreach (var category in categories)
{
var catCopy = new DiscountCategoryDto
{
Id = category.Id,
Title = prefix + category.Title,
ParentCategoryId = category.ParentCategoryId
};
result.Add(catCopy);
if (category.Children.Any())
{
result.AddRange(FlattenCategories(category.Children.ToList(), prefix + " "));
}
}
return result;
}
private string GetCategoryPath(DiscountCategoryDto category)
{
return category.Title;
}
private async Task OnMainImageSelected(IBrowserFile? file)
{
_mainImageFile = file;