Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Refactor web app item list table view to sort all items instead of just visible items (#1557)
Leendert de Borst9fb413017d62
diff --git a/apps/server/AliasVault.Client/Main/Components/Items/ItemsTable.razor b/apps/server/AliasVault.Client/Main/Components/Items/ItemsTable.razorindex 142db6d49..dbefab46f 100644--- a/apps/server/AliasVault.Client/Main/Components/Items/ItemsTable.razor+++ b/apps/server/AliasVault.Client/Main/Components/Items/ItemsTable.razor@@ -3,7 +3,7 @@@inject NavigationManager NavigationManager<SortableTable Columns="@_tableColumns" SortColumn="@SortColumn" SortDirection="@CurrentSortDirection" OnSortChanged="HandleSortChanged">- @foreach (var credential in DisplayedCredentials)+ @foreach (var credential in Credentials){<SortableTableRow Class="cursor-pointer" OnClick="@(() => NavigateToCredential(credential.Id))"><SortableTableColumn Padding="false">@@ -27,25 +27,23 @@public List<ItemListEntry> Credentials { get; set; } = [];/// <summary>- /// Gets or sets the sort order for the credentials (used to determine initial table state).+ /// Gets or sets the current sort column./// </summary>[Parameter]- public CredentialSortOrder SortOrder { get; set; } = CredentialSortOrder.OldestFirst;+ public string SortColumn { get; set; } = "CreatedAt";/// <summary>- /// Gets or sets the column to sort by.+ /// Gets or sets the current sort direction./// </summary>- private string SortColumn { get; set; } = "CreatedAt";-- /// <summary>- /// Gets or sets the current sort direction for table column sorting.- /// </summary>- private SortDirection CurrentSortDirection { get; set; } = SortDirection.Ascending;+ [Parameter]+ public SortDirection CurrentSortDirection { get; set; } = SortDirection.Ascending;/// <summary>- /// Gets or sets whether the user has explicitly clicked a column to sort.+ /// Gets or sets the callback for when the sort changes.+ /// The parent component should handle sorting ALL items when this is invoked./// </summary>- private bool UserHasClickedColumn { get; set; } = false;+ [Parameter]+ public EventCallback<(string Column, SortDirection Direction)> OnTableSortChanged { get; set; }/// <summary>/// Gets or sets the columns to show in the table.@@ -58,93 +56,13 @@];/// <summary>- /// Gets the credentials to display, with optional column-based sorting applied.- /// </summary>- private IEnumerable<ItemListEntry> DisplayedCredentials- {- get- {- // If user has explicitly clicked a column header to sort, apply that sorting- if (UserHasClickedColumn)- {- return SortList(Credentials, SortColumn, CurrentSortDirection);- }-- // Otherwise use the pre-sorted credentials passed from parent- return Credentials;- }- }-- /// <summary>- /// Gets the default sort column based on the sort order.- /// </summary>- private string GetDefaultSortColumn()- {- return SortOrder switch- {- CredentialSortOrder.Alphabetical => "Service",- _ => "CreatedAt", // OldestFirst and NewestFirst- };- }-- /// <summary>- /// Gets the default sort direction based on the sort order.- /// </summary>- private SortDirection GetDefaultSortDirection()- {- return SortOrder switch- {- CredentialSortOrder.NewestFirst => SortDirection.Descending,- CredentialSortOrder.Alphabetical => SortDirection.Ascending,- _ => SortDirection.Ascending, // OldestFirst (default)- };- }-- /// <inheritdoc />- protected override void OnParametersSet()- {- base.OnParametersSet();-- // Only reset if the SortOrder parameter has changed- var newDefaultColumn = GetDefaultSortColumn();- var newDefaultDirection = GetDefaultSortDirection();-- if (SortColumn != newDefaultColumn || (!UserHasClickedColumn && CurrentSortDirection != newDefaultDirection))- {- SortColumn = newDefaultColumn;- CurrentSortDirection = newDefaultDirection;- UserHasClickedColumn = false; // Reset user interaction state when parameters change- }- }-- /// <summary>- /// Handles the sort changed event.+ /// Handles the sort changed event from the table header click.+ /// Notifies the parent component to apply sorting on all items./// </summary>/// <param name="sort">The sort event.</param>- private void HandleSortChanged((string column, SortDirection direction) sort)- {- SortColumn = sort.column;- CurrentSortDirection = sort.direction;- UserHasClickedColumn = true;- StateHasChanged();- }-- /// <summary>- /// Sorts the list of credentials.- /// </summary>- /// <param name="credentials">The list of credentials to sort.</param>- /// <param name="sortColumn">The column to sort by.</param>- /// <param name="sortDirection">The direction to sort by.</param>- private static IEnumerable<ItemListEntry> SortList(List<ItemListEntry> credentials, string sortColumn, SortDirection sortDirection)+ private async Task HandleSortChanged((string column, SortDirection direction) sort){- return sortColumn switch- {- "Service" => SortableTable.SortListByProperty(credentials, c => c.Service, sortDirection),- "Username" => SortableTable.SortListByProperty(credentials, c => c.Username, sortDirection),- "Email" => SortableTable.SortListByProperty(credentials, c => c.Email, sortDirection),- "CreatedAt" => SortableTable.SortListByProperty(credentials, c => c.CreatedAt, sortDirection),- _ => credentials- };+ await OnTableSortChanged.InvokeAsync((sort.column, sort.direction));}/// <summary>diff --git a/apps/server/AliasVault.Client/Main/Pages/Items/Home.razor b/apps/server/AliasVault.Client/Main/Pages/Items/Home.razorindex 5845d9cea..612607720 100644--- a/apps/server/AliasVault.Client/Main/Pages/Items/Home.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Items/Home.razor@@ -200,7 +200,11 @@ else@if (DbService.Settings.CredentialsViewMode == "table"){- <ItemsTable Credentials="@FilteredAndSortedItems.ToList()" SortOrder="@SortOrder" />+ <ItemsTable+ Credentials="@FilteredAndSortedItems.ToList()"+ SortColumn="@TableSortColumn"+ CurrentSortDirection="@TableSortDirection"+ OnTableSortChanged="HandleTableSortChanged" />}else{@@ -422,6 +426,16 @@ elseset => DbService.Settings.SetCredentialsSortOrder(value);}+ /// <summary>+ /// Gets or sets the current table sort column (for table view column header sorting).+ /// </summary>+ private string TableSortColumn { get; set; } = "CreatedAt";++ /// <summary>+ /// Gets or sets the current table sort direction (for table view column header sorting).+ /// </summary>+ private SortDirection TableSortDirection { get; set; } = SortDirection.Ascending;+/// <summary>/// Gets whether we're currently in a folder view./// </summary>@@ -475,7 +489,12 @@ else_ => filtered, // All};- // Then apply sort+ // Apply sort - use table column sort if in table view, otherwise use settings dropdown sort+ if (ViewMode == "table")+ {+ return ApplyTableSort(filtered);+ }+return SortOrder switch{CredentialSortOrder.NewestFirst => filtered.OrderByDescending(x => x.CreatedAt),@@ -485,6 +504,31 @@ else}}+ /// <summary>+ /// Applies table column sorting to the filtered items.+ /// </summary>+ /// <param name="items">The items to sort.</param>+ /// <returns>The sorted items.</returns>+ private IEnumerable<ItemListEntry> ApplyTableSort(IEnumerable<ItemListEntry> items)+ {+ return TableSortColumn switch+ {+ "Service" => TableSortDirection == SortDirection.Ascending+ ? items.OrderBy(x => x.Service ?? string.Empty)+ : items.OrderByDescending(x => x.Service ?? string.Empty),+ "Username" => TableSortDirection == SortDirection.Ascending+ ? items.OrderBy(x => x.Username ?? string.Empty)+ : items.OrderByDescending(x => x.Username ?? string.Empty),+ "Email" => TableSortDirection == SortDirection.Ascending+ ? items.OrderBy(x => x.Email ?? string.Empty)+ : items.OrderByDescending(x => x.Email ?? string.Empty),+ "CreatedAt" => TableSortDirection == SortDirection.Ascending+ ? items.OrderBy(x => x.CreatedAt)+ : items.OrderByDescending(x => x.CreatedAt),+ _ => items.OrderBy(x => x.CreatedAt), // Default+ };+ }+/// <summary>/// Gets the total number of filtered items./// </summary>@@ -575,6 +619,19 @@ elseStateHasChanged();}+ /// <summary>+ /// Handles the table column sort changed event.+ /// This applies sorting to ALL items before pagination.+ /// </summary>+ /// <param name="sort">The sort column and direction.</param>+ private void HandleTableSortChanged((string Column, SortDirection Direction) sort)+ {+ TableSortColumn = sort.Column;+ TableSortDirection = sort.Direction;+ VisibleItemCount = BatchSize; // Reset visible items when sort changes to show first N sorted items+ StateHasChanged();+ }+/// <summary>/// Loads more items for infinite scroll. Called from JavaScript via IntersectionObserver./// </summary>@@ -611,10 +668,27 @@ else{ShowSettingsDropdown = false;+ // Sync table sort state with the dropdown sort order+ SyncTableSortWithSortOrder();+// Reload the items in case the settings were changed.await LoadItemsAsync();}+ /// <summary>+ /// Synchronizes the table sort column and direction with the settings dropdown sort order.+ /// Called when the user changes the sort order via the settings dropdown.+ /// </summary>+ private void SyncTableSortWithSortOrder()+ {+ (TableSortColumn, TableSortDirection) = SortOrder switch+ {+ CredentialSortOrder.NewestFirst => ("CreatedAt", SortDirection.Descending),+ CredentialSortOrder.Alphabetical => ("Service", SortDirection.Ascending),+ _ => ("CreatedAt", SortDirection.Ascending), // OldestFirst (default)+ };+ }+/// <summary>/// Navigate to a folder./// </summary>@@ -781,6 +855,9 @@ else{await base.OnParametersSetAsync();+ // Initialize table sort state from saved sort order+ SyncTableSortWithSortOrder();+// Load folder name if in folder viewif (FolderId.HasValue){