Skip to content

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

Add field history individual record delete buttons, add smarter history icon visibility (#1473)

Leendert de Borst1fc3845364d5
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Items/Details/FieldBlock.tsx b/apps/browser-extension/src/entrypoints/popup/components/Items/Details/FieldBlock.tsx
index 297845393..765752c8a 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Items/Details/FieldBlock.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Items/Details/FieldBlock.tsx
@@ -46,17 +46,40 @@ const FieldBlock: React.FC<FieldBlockProps> = ({ field, itemId, hideLabel = fals
// Check if this field has history enabled
const hasHistoryEnabled = field.EnableHistory === true;
- // Check if there's actual history available
+ /**
+ * Check if there's meaningful history available.
+ * Only show history icon if:
+ * 1. There are more than 1 history records, OR
+ * 2. There is exactly 1 history record but its value differs from current value
+ */
useEffect(() => {
if (hasHistoryEnabled && itemId && dbContext?.sqliteClient) {
try {
const history = dbContext.sqliteClient.items.getFieldHistory(itemId, field.FieldKey);
- setHistoryCount(history.length);
+
+ if (history.length > 1) {
+ // Multiple history records - always show icon
+ setHistoryCount(history.length);
+ } else if (history.length === 1) {
+ // Single history record - check if value differs from current
+ const currentValues = Array.isArray(field.Value) ? field.Value : [field.Value];
+ const currentValueJson = JSON.stringify(currentValues.filter(v => v && v.trim() !== ''));
+ const historyValueJson = history[0].ValueSnapshot;
+
+ // Only show icon if history value differs from current value
+ if (currentValueJson !== historyValueJson) {
+ setHistoryCount(1);
+ } else {
+ setHistoryCount(0);
+ }
+ } else {
+ setHistoryCount(0);
+ }
} catch (error) {
console.error('[FieldBlock] Error checking history:', error);
}
}
- }, [hasHistoryEnabled, itemId, field.FieldKey, dbContext?.sqliteClient]);
+ }, [hasHistoryEnabled, itemId, field.FieldKey, field.Value, dbContext?.sqliteClient]);
// Skip rendering if no value
if (!field.Value || (typeof field.Value === 'string' && field.Value.trim() === '')) {
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Items/Details/FieldHistoryModal.tsx b/apps/browser-extension/src/entrypoints/popup/components/Items/Details/FieldHistoryModal.tsx
index 984a166e1..2edbf31fb 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/Items/Details/FieldHistoryModal.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/Items/Details/FieldHistoryModal.tsx
@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
import ModalWrapper from '@/entrypoints/popup/components/Dialogs/ModalWrapper';
import { FormInputCopyToClipboard } from '@/entrypoints/popup/components/Forms/FormInputCopyToClipboard';
import { useDb } from '@/entrypoints/popup/context/DbContext';
+import { useVaultMutate } from '@/entrypoints/popup/hooks/useVaultMutate';
import type { FieldHistory, FieldType } from '@/utils/dist/core/models/vault';
import { FieldTypes } from '@/utils/dist/core/models/vault';
@@ -35,14 +36,19 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({
}) => {
const { t } = useTranslation();
const dbContext = useDb();
+ const { executeVaultMutationAsync } = useVaultMutate();
const [history, setHistory] = useState<FieldHistory[]>([]);
const [loading, setLoading] = useState(true);
+ const [confirmDeleteId, setConfirmDeleteId] = useState<string | null>(null);
// For non-hidden fields, show values by default
const shouldMaskByDefault = isHidden || fieldType === FieldTypes.Password || fieldType === FieldTypes.Hidden;
- useEffect(() => {
- if (!isOpen || !dbContext?.sqliteClient) {
+ /**
+ * Load field history from the database.
+ */
+ const loadHistory = (): void => {
+ if (!dbContext?.sqliteClient) {
return;
}
@@ -55,6 +61,13 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({
} finally {
setLoading(false);
}
+ };
+
+ useEffect(() => {
+ if (!isOpen) {
+ return;
+ }
+ loadHistory();
}, [isOpen, dbContext?.sqliteClient, itemId, fieldKey]);
/**
@@ -86,6 +99,27 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({
}
};
+ /**
+ * Handle delete of a history record.
+ */
+ const handleDelete = async (historyId: string): Promise<void> => {
+ if (!dbContext?.sqliteClient) {
+ return;
+ }
+
+ try {
+ // Use vault mutation to delete and sync in background
+ await executeVaultMutationAsync(async () => {
+ await dbContext.sqliteClient!.items.deleteFieldHistory(historyId);
+ });
+ // Reload history after deletion
+ loadHistory();
+ setConfirmDeleteId(null);
+ } catch (error) {
+ console.error('Error deleting field history:', error);
+ }
+ };
+
return (
<ModalWrapper
isOpen={isOpen}
@@ -106,14 +140,46 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({
<div className="space-y-3">
{history.map((record) => {
const values = parseValueSnapshot(record.ValueSnapshot);
+ const isConfirmingDelete = confirmDeleteId === record.Id;
return (
<div
key={record.Id}
className="rounded-lg p-4 border border-gray-200 dark:border-gray-700"
>
- <div className="text-sm text-gray-600 dark:text-gray-400 mb-2">
- {formatDate(record.ChangedAt)}
+ <div className="flex items-center justify-between mb-2">
+ <div className="text-sm text-gray-600 dark:text-gray-400">
+ {formatDate(record.ChangedAt)}
+ </div>
+ {isConfirmingDelete ? (
+ <div className="flex items-center gap-2">
+ <button
+ type="button"
+ onClick={() => handleDelete(record.Id)}
+ className="text-xs px-2 py-1 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 font-medium"
+ >
+ {t('common.confirm')}
+ </button>
+ <button
+ type="button"
+ onClick={() => setConfirmDeleteId(null)}
+ className="text-xs px-2 py-1 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200"
+ >
+ {t('common.cancel')}
+ </button>
+ </div>
+ ) : (
+ <button
+ type="button"
+ onClick={() => setConfirmDeleteId(record.Id)}
+ className="text-xs px-2 py-1 text-gray-500 hover:text-red-600 dark:text-gray-400 dark:hover:text-red-400 transition-colors"
+ title={t('common.delete')}
+ >
+ <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">
+ <path strokeLinecap="round" strokeLinejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
+ </svg>
+ </button>
+ )}
</div>
{values.map((value, idx) => (
diff --git a/apps/browser-extension/src/utils/db/queries/ItemQueries.ts b/apps/browser-extension/src/utils/db/queries/ItemQueries.ts
index bd6db0593..72fbf76c3 100644
--- a/apps/browser-extension/src/utils/db/queries/ItemQueries.ts
+++ b/apps/browser-extension/src/utils/db/queries/ItemQueries.ts
@@ -361,4 +361,12 @@ export class FieldHistoryQueries {
SET IsDeleted = 1, UpdatedAt = ?
WHERE Id IN (${placeholders})`;
}
+
+ /**
+ * Soft delete a single history record.
+ */
+ public static readonly SOFT_DELETE = `
+ UPDATE FieldHistories
+ SET IsDeleted = 1, UpdatedAt = ?
+ WHERE Id = ?`;
}
diff --git a/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts b/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts
index 5649db336..664a06b2e 100644
--- a/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts
+++ b/apps/browser-extension/src/utils/db/repositories/ItemRepository.ts
@@ -387,6 +387,21 @@ export class ItemRepository extends BaseRepository {
}));
}
+ /**
+ * Delete a specific field history record.
+ * @param historyId - The ID of the history record to delete
+ * @returns Number of rows affected
+ */
+ public async deleteFieldHistory(historyId: string): Promise<number> {
+ return this.withTransaction(async () => {
+ const currentDateTime = this.now();
+ return this.client.executeUpdate(FieldHistoryQueries.SOFT_DELETE, [
+ currentDateTime,
+ historyId
+ ]);
+ });
+ }
+
// ===== Private Helper Methods =====
/**
diff --git a/apps/mobile-app/components/items/FieldHistoryModal.tsx b/apps/mobile-app/components/items/FieldHistoryModal.tsx
index 79e3807fd..9e744dec1 100644
--- a/apps/mobile-app/components/items/FieldHistoryModal.tsx
+++ b/apps/mobile-app/components/items/FieldHistoryModal.tsx
@@ -1,5 +1,5 @@
import { MaterialIcons } from '@expo/vector-icons';
-import React, { useState, useEffect } from 'react';
+import React, { useState, useEffect, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import {
StyleSheet,
@@ -18,6 +18,8 @@ import { useDb } from '@/context/DbContext';
import { copyToClipboardWithExpiration } from '@/utils/ClipboardUtility';
import { useAuth } from '@/context/AuthContext';
import { ModalWrapper } from '@/components/common/ModalWrapper';
+import { useVaultMutate } from '@/hooks/useVaultMutate';
+import { useDialog } from '@/context/DialogContext';
type FieldHistoryModalProps = {
isOpen: boolean;
@@ -48,6 +50,8 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({
const colors = useColors();
const dbContext = useDb();
const { getClipboardClearTimeout } = useAuth();
+ const { executeVaultMutation } = useVaultMutate();
+ const { showConfirm } = useDialog();
const [history, setHistory] = useState<FieldHistory[]>([]);
const [loading, setLoading] = useState(true);
const [visibleValues, setVisibleValues] = useState<Set<string>>(new Set());
@@ -55,27 +59,26 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({
// For non-hidden fields, show values by default
const shouldMaskByDefault = isHidden || fieldType === FieldTypes.Password || fieldType === FieldTypes.Hidden;
+ const loadHistory = useCallback(async (): Promise<void> => {
+ if (!dbContext?.sqliteClient) return;
+
+ try {
+ setLoading(true);
+ const historyRecords = await dbContext.sqliteClient.items.getFieldHistory(itemId, fieldKey);
+ setHistory(historyRecords);
+ } catch (error) {
+ console.error('Error loading field history:', error);
+ } finally {
+ setLoading(false);
+ }
+ }, [dbContext?.sqliteClient, itemId, fieldKey]);
+
useEffect(() => {
- if (!isOpen || !dbContext?.sqliteClient) {
+ if (!isOpen) {
return;
}
-
- const loadHistory = async (): Promise<void> => {
- if (!dbContext.sqliteClient) return;
-
- try {
- setLoading(true);
- const historyRecords = await dbContext.sqliteClient.items.getFieldHistory(itemId, fieldKey);
- setHistory(historyRecords);
- } catch (error) {
- console.error('Error loading field history:', error);
- } finally {
- setLoading(false);
- }
- };
-
void loadHistory();
- }, [isOpen, dbContext?.sqliteClient, itemId, fieldKey]);
+ }, [isOpen, loadHistory]);
/**
* Format a date string to a human readable format.
@@ -106,6 +109,48 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({
}
};
+ /**
+ * Handle delete of a history record.
+ */
+ const handleDelete = async (historyId: string): Promise<void> => {
+ if (!dbContext?.sqliteClient) {
+ return;
+ }
+
+ try {
+ // Use vault mutation to delete and sync in background
+ await executeVaultMutation(async () => {
+ await dbContext.sqliteClient!.items.deleteFieldHistory(historyId);
+ });
+ // Reload history after deletion
+ await loadHistory();
+ Toast.show({
+ type: 'success',
+ text1: t('common.delete'),
+ position: 'bottom',
+ visibilityTime: 2000,
+ });
+ } catch (error) {
+ console.error('Error deleting field history:', error);
+ }
+ };
+
+ /**
+ * Show delete confirmation dialog.
+ */
+ const confirmDelete = (historyId: string): void => {
+ showConfirm(
+ t('common.delete'),
+ t('items.deleteHistoryConfirm'),
+ t('common.confirm'),
+ () => handleDelete(historyId),
+ {
+ cancelText: t('common.cancel'),
+ confirmStyle: 'destructive',
+ }
+ );
+ };
+
const styles = StyleSheet.create({
loadingContainer: {
alignItems: 'center',
@@ -129,8 +174,11 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({
overflow: 'hidden',
},
historyHeader: {
+ alignItems: 'center',
borderBottomColor: colors.accentBorder,
borderBottomWidth: 1,
+ flexDirection: 'row',
+ justifyContent: 'space-between',
paddingHorizontal: 12,
paddingVertical: 8,
},
@@ -139,6 +187,9 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({
fontSize: 12,
fontWeight: '500',
},
+ deleteButton: {
+ padding: 4,
+ },
historyValue: {
alignItems: 'center',
flexDirection: 'row',
@@ -203,6 +254,17 @@ const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({
<Text style={styles.historyDate}>
{formatDate(record.ChangedAt)}
</Text>
+ <TouchableOpacity
+ onPress={() => confirmDelete(record.Id)}
+ style={styles.deleteButton}
+ accessibilityLabel={t('common.delete')}
+ >
+ <MaterialIcons
+ name="delete-outline"
+ size={18}
+ color={colors.textMuted}
+ />
+ </TouchableOpacity>
</View>
{values.map((value, idx) => {
diff --git a/apps/mobile-app/components/items/details/FieldBlock.tsx b/apps/mobile-app/components/items/details/FieldBlock.tsx
index cf76f7c53..acc024b2f 100644
--- a/apps/mobile-app/components/items/details/FieldBlock.tsx
+++ b/apps/mobile-app/components/items/details/FieldBlock.tsx
@@ -57,7 +57,10 @@ const FieldBlock: React.FC<FieldBlockProps> = ({ field, itemId, hideLabel = fals
// Check if this field has history enabled
const hasHistoryEnabled = field.EnableHistory === true;
- // Check if there's actual history available
+ // Check if there's meaningful history available
+ // Only show history icon if:
+ // 1. There are more than 1 history records, OR
+ // 2. There is exactly 1 history record but its value differs from current value
useEffect(() => {
if (hasHistoryEnabled && itemId && dbContext?.sqliteClient) {
const checkHistory = async (): Promise<void> => {
@@ -65,7 +68,25 @@ const FieldBlock: React.FC<FieldBlockProps> = ({ field, itemId, hideLabel = fals
try {
const history = await dbContext.sqliteClient.items.getFieldHistory(itemId, field.FieldKey);
- setHistoryCount(history.length);
+
+ if (history.length > 1) {
+ // Multiple history records - always show icon
+ setHistoryCount(history.length);
+ } else if (history.length === 1) {
+ // Single history record - check if value differs from current
+ const currentValues = Array.isArray(field.Value) ? field.Value : [field.Value];
+ const currentValueJson = JSON.stringify(currentValues.filter(v => v && v.trim() !== ''));
+ const historyValueJson = history[0].ValueSnapshot;
+
+ // Only show icon if history value differs from current value
+ if (currentValueJson !== historyValueJson) {
+ setHistoryCount(1);
+ } else {
+ setHistoryCount(0);
+ }
+ } else {
+ setHistoryCount(0);
+ }
} catch (error) {
console.error('[FieldBlock] Error checking history:', error);
}
@@ -73,7 +94,7 @@ const FieldBlock: React.FC<FieldBlockProps> = ({ field, itemId, hideLabel = fals
void checkHistory();
}
- }, [hasHistoryEnabled, itemId, field.FieldKey, dbContext?.sqliteClient]);
+ }, [hasHistoryEnabled, itemId, field.FieldKey, field.Value, dbContext?.sqliteClient]);
// Skip rendering if no value
if (!field.Value || (typeof field.Value === 'string' && field.Value.trim() === '')) {
diff --git a/apps/mobile-app/i18n/locales/en.json b/apps/mobile-app/i18n/locales/en.json
index f335c0f61..2557c6f48 100644
--- a/apps/mobile-app/i18n/locales/en.json
+++ b/apps/mobile-app/i18n/locales/en.json
@@ -482,6 +482,7 @@
"viewHistory": "View history",
"history": "History",
"noHistoryAvailable": "No history available",
+ "deleteHistoryConfirm": "Are you sure you want to delete this history record?",
"deleteConfirm": "Are you sure you want to delete this item? This action cannot be undone.",
"folders": {
"folder": "Folder",
diff --git a/apps/mobile-app/utils/db/queries/ItemQueries.ts b/apps/mobile-app/utils/db/queries/ItemQueries.ts
index 0b1093fec..17a2528b0 100644
--- a/apps/mobile-app/utils/db/queries/ItemQueries.ts
+++ b/apps/mobile-app/utils/db/queries/ItemQueries.ts
@@ -364,4 +364,12 @@ export class FieldHistoryQueries {
SET IsDeleted = 1, UpdatedAt = ?
WHERE Id IN (${placeholders})`;
}
+
+ /**
+ * Soft delete a single history record.
+ */
+ public static readonly SOFT_DELETE = `
+ UPDATE FieldHistories
+ SET IsDeleted = 1, UpdatedAt = ?
+ WHERE Id = ?`;
}
diff --git a/apps/mobile-app/utils/db/repositories/ItemRepository.ts b/apps/mobile-app/utils/db/repositories/ItemRepository.ts
index caf24d63d..3a0f3aefd 100644
--- a/apps/mobile-app/utils/db/repositories/ItemRepository.ts
+++ b/apps/mobile-app/utils/db/repositories/ItemRepository.ts
@@ -221,6 +221,21 @@ export class ItemRepository extends BaseRepository {
}));
}
+ /**
+ * Delete a specific field history record.
+ * @param historyId - The ID of the history record to delete
+ * @returns Number of rows affected
+ */
+ public async deleteFieldHistory(historyId: string): Promise<number> {
+ return this.withTransaction(async () => {
+ const now = this.now();
+ return this.client.executeUpdate(FieldHistoryQueries.SOFT_DELETE, [
+ now,
+ historyId
+ ]);
+ });
+ }
+
/**
* Move an item to trash (set DeletedAt timestamp).
* @param itemId - The ID of the item to trash
diff --git a/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor b/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor
index 306fa6d49..b7c19313e 100644
--- a/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor
+++ b/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor
@@ -116,9 +116,10 @@
await base.OnParametersSetAsync();
// Check history count if field has history enabled and item ID is provided
+ // Pass current value for smart comparison (only show icon if history differs from current)
if (Field.EnableHistory && ItemId != Guid.Empty && !string.IsNullOrEmpty(Field.FieldKey))
{
- HistoryCount = await ItemService.GetFieldHistoryCountAsync(ItemId, Field.FieldKey);
+ HistoryCount = await ItemService.GetFieldHistoryCountAsync(ItemId, Field.FieldKey, Field.Value);
}
else
{
diff --git a/apps/server/AliasVault.Client/Main/Components/Fields/FieldHistoryModal.razor b/apps/server/AliasVault.Client/Main/Components/Fields/FieldHistoryModal.razor
index afa1e4fd7..70a4c9c0a 100644
--- a/apps/server/AliasVault.Client/Main/Components/Fields/FieldHistoryModal.razor
+++ b/apps/server/AliasVault.Client/Main/Components/Fields/FieldHistoryModal.razor
@@ -2,6 +2,7 @@
@using AliasVault.Client.Main.Components.Layout
@using Microsoft.Extensions.Localization
@inject ItemService ItemService
+@inject DbService DbService
@inject IStringLocalizerFactory LocalizerFactory
<ClickOutsideHandler OnClose="Close" ContentId="fieldHistoryModal">
@@ -42,8 +43,30 @@
@foreach (var record in HistoryRecords)
{
<div class="border border-gray-200 dark:border-gray-700 rounded-lg p-4">
- <div class="text-sm text-gray-500 dark:text-gray-400 mb-2">
- @FormatDate(record.ChangedAt)
+ <div class="flex items-center justify-between mb-2">
+ <div class="text-sm text-gray-500 dark:text-gray-400">
+ @FormatDate(record.ChangedAt)
+ </div>
+ @if (ConfirmDeleteId == record.Id)
+ {
+ <div class="flex items-center gap-2">
+ <span class="text-xs text-gray-500 dark:text-gray-400">@Localizer["DeleteConfirm"]</span>
+ <button @onclick="@(() => DeleteRecordAsync(record.Id))" class="text-xs px-2 py-1 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 font-medium">
+ @SharedLocalizer["Confirm"]
+ </button>
+ <button @onclick="@(() => ConfirmDeleteId = null)" class="text-xs px-2 py-1 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200">
+ @SharedLocalizer["Cancel"]
+ </button>
+ </div>
+ }
+ else
+ {
+ <button @onclick="@(() => ConfirmDeleteId = record.Id)" class="text-gray-500 hover:text-red-600 dark:text-gray-400 dark:hover:text-red-400 transition-colors" title="@SharedLocalizer["Delete"]">
+ <svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
+ </svg>
+ </button>
+ }
</div>
@{
var values = ParseValueSnapshot(record.ValueSnapshot);
@@ -76,7 +99,7 @@
<!-- Footer -->
<div class="p-4 border-t border-gray-200 dark:border-gray-700 flex justify-end">
<button @onclick="Close" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors">
- @Localizer["CloseButton"]
+ @SharedLocalizer["Close"]
</button>
</div>
</div>
@@ -86,6 +109,8 @@
@code {
private IStringLocalizer Localizer => LocalizerFactory.Create("Components.Fields.FieldHistoryModal", "AliasVault.Client");
+ private IStringLocalizer SharedLocalizer => LocalizerFactory.Create("SharedResources", "AliasVault.Client");
+
/// <summary>
/// Gets or sets the item ID.
/// </summary>
@@ -118,6 +143,7 @@
private bool IsLoading { get; set; } = true;
private List<FieldHistory> HistoryRecords { get; set; } = new();
+ private Guid? ConfirmDeleteId { get; set; }
/// <inheritdoc />
protected override async Task OnInitializedAsync()
@@ -140,6 +166,23 @@
StateHasChanged();
}
+ /// <summary>
+ /// Delete a history record.
+ /// </summary>
+ private async Task DeleteRecordAsync(Guid historyId)
+ {
+ var success = await ItemService.DeleteFieldHistoryAsync(historyId);
+ if (success)
+ {
+ // Trigger vault sync in background
+ DbService.SaveDatabaseInBackground();
+ // Reload history after deletion
+ await LoadHistoryAsync();
+ }
+
+ ConfirmDeleteId = null;
+ }
+
/// <summary>
/// Parse the value snapshot JSON to a list of values.
/// </summary>
diff --git a/apps/server/AliasVault.Client/Resources/Components/Fields/FieldHistoryModal.en.resx b/apps/server/AliasVault.Client/Resources/Components/Fields/FieldHistoryModal.en.resx
index a3a31208a..a5039d3f7 100644
--- a/apps/server/AliasVault.Client/Resources/Components/Fields/FieldHistoryModal.en.resx
+++ b/apps/server/AliasVault.Client/Resources/Components/Fields/FieldHistoryModal.en.resx
@@ -66,8 +66,8 @@
<value>No history available</value>
<comment>Message shown when no history records exist</comment>
</data>
- <data name="CloseButton" xml:space="preserve">
- <value>Close</value>
- <comment>Close button text</comment>
+ <data name="DeleteConfirm" xml:space="preserve">
+ <value>Are you sure?</value>
+ <comment>Delete confirmation text</comment>
</data>
</root>
diff --git a/apps/server/AliasVault.Client/Services/ItemService.cs b/apps/server/AliasVault.Client/Services/ItemService.cs
index bd0640f4b..ff72d6305 100644
--- a/apps/server/AliasVault.Client/Services/ItemService.cs
+++ b/apps/server/AliasVault.Client/Services/ItemService.cs
@@ -13,6 +13,7 @@ using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
+using System.Text.Json;
using System.Threading.Tasks;
using AliasClientDb;
using AliasClientDb.Models;
@@ -584,6 +585,17 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf
totp.UpdatedAt = deleteDateTime;
}
+ // Also delete field histories (queried separately since no navigation property)
+ var fieldHistories = await context.FieldHistories
+ .Where(fh => fh.ItemId == id && !fh.IsDeleted)
+ .ToListAsync();
+
+ foreach (var history in fieldHistories)
+ {
+ history.IsDeleted = true;
+ history.UpdatedAt = deleteDateTime;
+ }
+
return await dbService.SaveDatabaseAsync();
}
@@ -635,6 +647,17 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf
totp.UpdatedAt = deleteDateTime;
}
+ // Also delete field histories (queried separately since no navigation property)
+ var fieldHistories = await context.FieldHistories
+ .Where(fh => fh.ItemId == id && !fh.IsDeleted)
+ .ToListAsync();
+
+ foreach (var history in fieldHistories)
+ {
+ history.IsDeleted = true;
+ history.UpdatedAt = deleteDateTime;
+ }
+
// Save locally and sync to server in background
await context.SaveChangesAsync();
dbService.SaveDatabaseInBackground();
@@ -706,17 +729,71 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf
/// <summary>
/// Get field history count for a specific item and field.
+ /// Returns the count only if history is meaningful (more than 1 record,
+ /// or 1 record with value different from current).
/// </summary>
/// <param name="itemId">The item ID.</param>
/// <param name="fieldKey">The field key.</param>
- /// <returns>Number of history records.</returns>
- public async Task<int> GetFieldHistoryCountAsync(Guid itemId, string fieldKey)
+ /// <param name="currentValue">The current field value to compare against.</param>
+ /// <returns>Number of history records if meaningful, 0 otherwise.</returns>
+ public async Task<int> GetFieldHistoryCountAsync(Guid itemId, string fieldKey, string? currentValue = null)
{
var context = await dbService.GetDbContextAsync();
- return await context.FieldHistories
+ var historyRecords = await context.FieldHistories
.Where(fh => fh.ItemId == itemId && fh.FieldKey == fieldKey && !fh.IsDeleted)
- .CountAsync();
+ .OrderByDescending(fh => fh.ChangedAt)
+ .Take(2) // Only need to check first 2 records
+ .ToListAsync();
+
+ var count = historyRecords.Count;
+
+ if (count > 1)
+ {
+ // More than 1 history record - always show icon
+ return await context.FieldHistories
+ .Where(fh => fh.ItemId == itemId && fh.FieldKey == fieldKey && !fh.IsDeleted)
+ .CountAsync();
+ }
+
+ if (count == 1 && currentValue != null)
+ {
+ // Single history record - check if value differs from current
+ var historyValue = historyRecords[0].ValueSnapshot;
+ var currentValueJson = JsonSerializer.Serialize(new[] { currentValue }.Where(v => !string.IsNullOrWhiteSpace(v)));
+
+ // Only show icon if history value differs from current value
+ if (currentValueJson != historyValue)
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+ }
+
+ /// <summary>
+ /// Delete a specific field history record.
+ /// </summary>
+ /// <param name="historyId">The ID of the history record to delete.</param>
+ /// <returns>True if deleted, false otherwise.</returns>
+ public async Task<bool> DeleteFieldHistoryAsync(Guid historyId)
+ {
+ var context = await dbService.GetDbContextAsync();
+
+ var history = await context.FieldHistories
+ .FirstOrDefaultAsync(fh => fh.Id == historyId && !fh.IsDeleted);
+
+ if (history == null)
+ {
+ return false;
+ }
+
+ history.IsDeleted = true;
+ history.UpdatedAt = DateTime.UtcNow;
+
+ await context.SaveChangesAsync();
+ return true;
}
/// <summary>