Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Update credentials table sort logic (#578)

Leendert de Borstd5e83d2319b7
diff --git a/src/AliasVault.Client/Main/Components/Credentials/CredentialCard.razor b/src/AliasVault.Client/Main/Components/Credentials/CredentialCard.razor
index 5c048b81a..c8c9631db 100644
--- a/src/AliasVault.Client/Main/Components/Credentials/CredentialCard.razor
+++ b/src/AliasVault.Client/Main/Components/Credentials/CredentialCard.razor
@@ -16,6 +16,9 @@
[Parameter]
public required CredentialListEntry Obj { get; set; }
+ /// <summary>
+ /// Navigate to the details page of the credential.
+ /// </summary>
private void ShowDetails()
{
// Redirect to view page instead for now.
diff --git a/src/AliasVault.Client/Main/Components/Credentials/CredentialsTable.razor b/src/AliasVault.Client/Main/Components/Credentials/CredentialsTable.razor
index cfe3e6d54..80a7b238c 100644
--- a/src/AliasVault.Client/Main/Components/Credentials/CredentialsTable.razor
+++ b/src/AliasVault.Client/Main/Components/Credentials/CredentialsTable.razor
@@ -1,7 +1,8 @@
@using AliasVault.RazorComponents.Tables
+@inject NavigationManager NavigationManager
<SortableTable Columns="@_tableColumns" SortColumn="@SortColumn" SortDirection="@SortDirection" OnSortChanged="HandleSortChanged">
- @foreach (var credential in Credentials)
+ @foreach (var credential in SortedCredentials)
{
<SortableTableRow Class="cursor-pointer" OnClick="@(() => NavigateToCredential(credential.Id))">
<SortableTableColumn>
@@ -12,7 +13,7 @@
</SortableTableColumn>
<SortableTableColumn>@credential.Username</SortableTableColumn>
<SortableTableColumn>@credential.Email</SortableTableColumn>
- <SortableTableColumn>@credential.CreateDate.ToString("yyyy-MM-dd")</SortableTableColumn>
+ <SortableTableColumn>@credential.CreatedAt.ToString("yyyy-MM-dd")</SortableTableColumn>
</SortableTableRow>
}
</SortableTable>
@@ -24,9 +25,20 @@
[Parameter]
public List<CredentialListEntry> Credentials { get; set; } = [];
+ /// <summary>
+ /// Gets or sets the default sort direction that is applied to the provided credentials list.
+ /// </summary>
+ [Parameter]
+ public SortDirection SortDirection { get; set; } = SortDirection.Ascending;
+
+ /// <summary>
+ /// Gets or sets the column to sort by.
+ /// </summary>
private string SortColumn { get; set; } = "CreatedAt";
- private SortDirection SortDirection { get; set; } = SortDirection.Ascending;
+ /// <summary>
+ /// Gets or sets the columns to show in the table.
+ /// </summary>
private readonly List<TableColumn> _tableColumns = [
new TableColumn { Title = "Service", PropertyName = "Service" },
new TableColumn { Title = "Username", PropertyName = "Username" },
@@ -34,6 +46,15 @@
new TableColumn { Title = "Created", PropertyName = "CreatedAt" }
];
+ /// <summary>
+ /// Gets or sets the sorted credentials.
+ /// </summary>
+ private IEnumerable<CredentialListEntry> SortedCredentials => SortList(Credentials, SortColumn, SortDirection);
+
+ /// <summary>
+ /// Handles the sort changed event.
+ /// </summary>
+ /// <param name="sort">The sort event.</param>
private void HandleSortChanged((string column, SortDirection direction) sort)
{
SortColumn = sort.column;
@@ -41,11 +62,30 @@
StateHasChanged();
}
- private void NavigateToCredential(Guid credentialId)
+ /// <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<CredentialListEntry> SortList(List<CredentialListEntry> credentials, string sortColumn, SortDirection sortDirection)
{
- Navigation.NavigateTo($"/credentials/{credentialId}");
+ 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
+ };
}
- [Inject]
- private NavigationManager Navigation { get; set; } = default!;
+ /// <summary>
+ /// Navigates to the credential details page.
+ /// </summary>
+ /// <param name="credentialId">The ID of the credential to navigate to.</param>
+ private void NavigateToCredential(Guid credentialId)
+ {
+ NavigationManager.NavigateTo($"/credentials/{credentialId}");
+ }
}
diff --git a/src/AliasVault.Client/Main/Models/CredentialListEntry.cs b/src/AliasVault.Client/Main/Models/CredentialListEntry.cs
index 99f6e346f..0de235560 100644
--- a/src/AliasVault.Client/Main/Models/CredentialListEntry.cs
+++ b/src/AliasVault.Client/Main/Models/CredentialListEntry.cs
@@ -40,5 +40,5 @@ public sealed class CredentialListEntry
/// <summary>
/// Gets or sets the alias create date.
/// </summary>
- public DateTime CreateDate { get; set; }
+ public DateTime CreatedAt { get; set; }
}
diff --git a/src/AliasVault.Client/Main/Pages/Credentials/Home.razor b/src/AliasVault.Client/Main/Pages/Credentials/Home.razor
index 4cd7d00ae..1dcc37287 100644
--- a/src/AliasVault.Client/Main/Pages/Credentials/Home.razor
+++ b/src/AliasVault.Client/Main/Pages/Credentials/Home.razor
@@ -1,6 +1,7 @@
@page "/credentials"
@inherits MainBase
@inject CredentialService CredentialService
+@using AliasVault.RazorComponents.Tables
<LayoutPageTitle>Home</LayoutPageTitle>
@@ -18,7 +19,7 @@
@if (ShowSettingsDropdown)
{
- <ClickOutsideHandler OnClose="ClosePopup" ContentId="settingsDropdown,settingsButton">
+ <ClickOutsideHandler OnClose="CloseSettingsPopup" ContentId="settingsDropdown,settingsButton">
<div id="settingsDropdown" class="absolute right-0 z-10 mt-2 min-w-[220px] origin-top-right rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none dark:bg-gray-700">
<div class="p-4">
<div class="mb-4">
@@ -53,7 +54,7 @@ else
@if (DbService.Settings.CredentialsViewMode == "table")
{
<div class="px-4">
- <CredentialsTable Credentials="@(DbService.Settings.CredentialsSortOrder == "desc" ? Credentials.OrderByDescending(x => x.CreateDate).ToList() : Credentials)" />
+ <CredentialsTable Credentials="Credentials" SortDirection="@(SortOrder == "desc" ? SortDirection.Descending : SortDirection.Ascending)" />
</div>
}
else
@@ -68,7 +69,7 @@ else
</div>
</div>
}
- @foreach (var credential in DbService.Settings.CredentialsSortOrder == "desc" ? Credentials.OrderByDescending(x => x.CreateDate).ToList() : Credentials)
+ @foreach (var credential in Credentials)
{
<CredentialCard Obj="@credential"/>
}
@@ -77,41 +78,71 @@ else
}
@code {
+ /// <summary>
+ /// Gets or sets whether the credentials are being loaded.
+ /// </summary>
private bool IsLoading { get; set; } = true;
+
+ /// <summary>
+ /// Gets or sets the credentials.
+ /// </summary>
private List<CredentialListEntry> Credentials { get; set; } = new();
+
+ /// <summary>
+ /// Gets or sets whether the settings dropdown is shown.
+ /// </summary>
private bool ShowSettingsDropdown { get; set; }
+ /// <summary>
+ /// Gets or sets the view mode for the credentials.
+ /// </summary>
private string ViewMode
{
get => DbService.Settings.CredentialsViewMode;
set => DbService.Settings.SetCredentialsViewMode(value);
}
+ /// <summary>
+ /// Gets or sets the sort order for the credentials.
+ /// </summary>
private string SortOrder
{
get => DbService.Settings.CredentialsSortOrder;
set => DbService.Settings.SetCredentialsSortOrder(value);
}
+ /// <summary>
+ /// Toggles the settings dropdown.
+ /// </summary>
private void ToggleSettingsDropdown()
{
ShowSettingsDropdown = !ShowSettingsDropdown;
StateHasChanged();
}
+ /// <summary>
+ /// Updates the view mode.
+ /// </summary>
private void UpdateViewMode()
{
ShowSettingsDropdown = false;
StateHasChanged();
}
- private void UpdateSortOrder()
+ /// <summary>
+ /// Updates the sort order.
+ /// </summary>
+ private async Task UpdateSortOrder()
{
ShowSettingsDropdown = false;
+ await LoadCredentialsAsync();
StateHasChanged();
}
- private void ClosePopup()
+ /// <summary>
+ /// Closes the settings dropdown.
+ /// </summary>
+ private void CloseSettingsPopup()
{
ShowSettingsDropdown = false;
StateHasChanged();
@@ -128,6 +159,9 @@ else
}
}
+ /// <summary>
+ /// Loads and/or refreshesthe credentials.
+ /// </summary>
private async Task LoadCredentialsAsync()
{
IsLoading = true;
@@ -151,11 +185,11 @@ else
switch (DbService.Settings.CredentialsSortOrder)
{
case "desc":
- credentialListEntries = credentialListEntries.OrderByDescending(x => x.CreateDate).ToList();
+ credentialListEntries = credentialListEntries.OrderByDescending(x => x.CreatedAt).ToList();
break;
default:
- credentialListEntries = credentialListEntries.OrderBy(x => x.CreateDate).ToList();
+ credentialListEntries = credentialListEntries.OrderBy(x => x.CreatedAt).ToList();
break;
}
diff --git a/src/AliasVault.Client/Services/CredentialService.cs b/src/AliasVault.Client/Services/CredentialService.cs
index fdb66aca4..362170f51 100644
--- a/src/AliasVault.Client/Services/CredentialService.cs
+++ b/src/AliasVault.Client/Services/CredentialService.cs
@@ -353,7 +353,7 @@ public sealed class CredentialService(HttpClient httpClient, DbService dbService
Service = x.Service.Name,
Username = x.Username,
Email = x.Alias.Email,
- CreateDate = x.CreatedAt,
+ CreatedAt = x.CreatedAt,
})
.ToListAsync();
}