Fixed bug where deletes of artifact groupings would not cascade

This commit is contained in:
Vincent Allen
2025-11-12 19:10:35 -05:00
parent b34449808f
commit 9298829db6
325 changed files with 5233 additions and 20996 deletions

View File

@@ -12,33 +12,12 @@
@using System.Linq.Expressions
@using OpenArchival.Blazor.ArtifactGroupingDisplay
@using OpenArchival.Blazor.ArchiveSearch
@* ^^^ Add this using statement to access your component and enum ^^^ *@
<MudAutocomplete FullWidth="true"
AutoFocus="string.IsNullOrEmpty(SearchTerms)"
Placeholder="Search"
T="string"
Variant="Variant.Outlined"
AdornmentIcon="@Icons.Material.Filled.Search"
Class="mt-5"
@bind-Text="@SearchTerms"
OnKeyDown="HandleSearchKeyDown" />
<ArchiveSearchBar @bind-SelectedFilter="_selectedFilter"
SearchTermsChanged="OnSearchSubmittedAsync" />
<MudExpansionPanel Text="Filter...">
<MudText Typo="Typo.caption"></MudText>
<MudDivider></MudDivider>
<MudRadioGroup T="SearchFilterType" @bind-SelectedOption="_selectedFilter">
<MudRadio Option="SearchFilterType.All" T="SearchFilterType">All</MudRadio>
<MudRadio Option="SearchFilterType.Tags" T="SearchFilterType">Tags</MudRadio>
<MudRadio Option="SearchFilterType.Defects" T="SearchFilterType">Defects</MudRadio>
<MudRadio Option="SearchFilterType.ListedNames" T="SearchFilterType">Listed Names</MudRadio>
<MudRadio Option="SearchFilterType.Title" T="SearchFilterType">Title</MudRadio>
<MudRadio Option="SearchFilterType.Description" T="SearchFilterType">Description</MudRadio>
<MudRadio Option="SearchFilterType.Filenames" T="SearchFilterType">Filenames</MudRadio>
<MudRadio Option="SearchFilterType.ArtifactTranscriptions" T="SearchFilterType">Artifact Transcriptions</MudRadio>
</MudRadioGroup>
</MudExpansionPanel>
@if (_totalResults > 0)
{
<MudGrid Justify="Justify.FlexStart" Class="mt-1 ml-1 mb-2">
@@ -46,6 +25,7 @@
<MudButton Class="ml-1" StartIcon="@Icons.Material.Filled.Clear" OnClick="OnClearResults" Variant="Variant.Filled" Color="Color.Primary" Size="Size.Small">Clear</MudButton>
</MudGrid>
}
@if (_artifactGroupings.Count > 0)
{
<MudGrid>
@@ -58,9 +38,10 @@
</MudGrid>
<MudPaper Class="d-flex justify-center py-2 mt-4" Elevation="0">
<MudPagination Count="_totalPages" Page="_currentPage" SelectedPageChanged="OnPageChangedAsync" />
@* === HERE IS THE FIX === *@
<MudPagination Count="_totalPages" Selected="_currentPage" SelectedChanged="OnPageChangedAsync" />
</MudPaper>
}
}
else
{
@foreach (SearchPageSliderEntry entry in _sliderEntries)
@@ -73,22 +54,12 @@ else
@inject ILogger<SearchArchive> Logger;
@inject NavigationManager NavigationManager;
@code {
public enum SearchFilterType
{
All,
Tags,
Defects,
ListedNames,
Title,
Description,
Filenames,
ArtifactTranscriptions
}
[Parameter]
public string SearchTerms { get; set; } = "";
private SearchFilterType _selectedFilter = SearchFilterType.All;
// This enum is now defined in your ArchiveSearchBar component/namespace
private ArchiveSearchFilterType _selectedFilter = ArchiveSearchFilterType.All;
private List<ArtifactGrouping> _artifactGroupings { get; set; } = [];
private int _currentPage { get; set; } = 1;
private int _totalPages { get; set; } = 0;
@@ -108,17 +79,22 @@ else
}
await using var context = await ContextFactory.CreateDbContextAsync();
_sliderEntries = await context.SearchPageSliderEntries.Include(e=>e.FilterTags).ToListAsync();
_sliderEntries = await context.SearchPageSliderEntries.Include(e => e.FilterTags).ToListAsync();
}
private async Task HandleSearchKeyDown(Microsoft.AspNetCore.Components.Web.KeyboardEventArgs args)
/// <summary>
/// Called by the ArchiveSearchBar component's 'SearchTermsChanged' event.
/// </summary>
private async Task OnSearchSubmittedAsync(string searchTerms)
{
if (args.Key != "Enter" || string.IsNullOrWhiteSpace(SearchTerms))
if (string.IsNullOrWhiteSpace(searchTerms))
{
OnClearResults(null);
return;
}
NavigationManager.NavigateTo($"/search/{SearchTerms}");
SearchTerms = searchTerms;
NavigationManager.NavigateTo($"/search/{Uri.EscapeDataString(SearchTerms)}", replace: true);
await PerformSearchAsync();
}
@@ -127,31 +103,31 @@ else
/// </summary>
private async Task PerformSearchAsync()
{
// Determine which filter expression to use based on the radio button selection
// Determine which filter expression to use
switch (_selectedFilter)
{
case SearchFilterType.Tags:
case ArchiveSearchFilterType.Tags:
_currentFilterPredicate = x => x.TagsSearchVector.Matches(SearchTerms);
break;
case SearchFilterType.Title:
case ArchiveSearchFilterType.Title:
_currentFilterPredicate = x => x.TitleSearchVector.Matches(SearchTerms);
break;
case SearchFilterType.Description:
case ArchiveSearchFilterType.Description:
_currentFilterPredicate = x => x.DescriptionSearchVector.Matches(SearchTerms);
break;
case SearchFilterType.Defects:
case ArchiveSearchFilterType.Defects:
_currentFilterPredicate = x => x.DefectsSearchVector.Matches(SearchTerms);
break;
case SearchFilterType.Filenames:
case ArchiveSearchFilterType.Filenames:
_currentFilterPredicate = x => x.FilenamesSearchVector.Matches(SearchTerms);
break;
case SearchFilterType.ArtifactTranscriptions:
case ArchiveSearchFilterType.ArtifactTranscriptions:
_currentFilterPredicate = x => x.FileContentSearchVector.Matches(SearchTerms);
break;
case SearchFilterType.ListedNames:
_currentFilterPredicate = x => x.ListedNamesSearchVector.Matches(SearchTerms);
case ArchiveSearchFilterType.ListedNames:
_currentFilterPredicate = x => x.ListedNamesSearchVector.Matches(SearchTerms);
break;
case SearchFilterType.All:
case ArchiveSearchFilterType.All:
default:
_currentFilterPredicate = x => x.AllSearchVector.Matches(SearchTerms);
break;
@@ -187,20 +163,26 @@ else
// The query uses the dynamically set filter predicate
_artifactGroupings = await context.ArtifactGroupings
.Where(_currentFilterPredicate)
.Include(x => x.ChildArtifactEntries)
.ThenInclude(x => x.Files)
.OrderBy(x => x.Id)
.Skip((_currentPage - 1) * PageSize)
.Take(PageSize)
.ToListAsync();
.Where(_currentFilterPredicate)
.Include(x => x.ChildArtifactEntries)
.ThenInclude(x => x.Files)
.OrderBy(x => x.Id)
.Skip((_currentPage - 1) * PageSize)
.Take(PageSize)
.ToListAsync();
StateHasChanged();
}
private void OnClearResults(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
{
_totalResults = 0;
_artifactGroupings.Clear();
_currentPage = 1;
_totalPages = 0;
SearchTerms = "";
NavigationManager.NavigateTo("/search", replace: true);
StateHasChanged();
}