Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add generic history modal component (#1404)
Leendert de Borst5d7a59f3b5eb
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Credentials/Details/FieldBlock.tsx b/apps/browser-extension/src/entrypoints/popup/components/Credentials/Details/FieldBlock.tsxindex a4ba33706..ee713ebb7 100644--- a/apps/browser-extension/src/entrypoints/popup/components/Credentials/Details/FieldBlock.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/Credentials/Details/FieldBlock.tsx@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';import { useTranslation } from 'react-i18next';import { FormInputCopyToClipboard } from '@/entrypoints/popup/components/Forms/FormInputCopyToClipboard';-import PasswordHistoryModal from './PasswordHistoryModal';+import FieldHistoryModal from './FieldHistoryModal';import { useDb } from '@/entrypoints/popup/context/DbContext';import type { ItemField } from '@/utils/dist/shared/models/vault';@@ -79,6 +79,33 @@ const FieldBlock: React.FC<FieldBlockProps> = ({ field, itemId }) => {const value = values[0];+ // History button component that can be added to any field label+ const HistoryButton = historyCount > 0 && itemId ? (+ <button+ type="button"+ onClick={() => setShowHistoryModal(true)}+ className="ml-2 inline-flex items-center text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 focus:outline-none"+ title={t('credentials.viewHistory')}+ >+ <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">+ <path strokeLinecap="round" strokeLinejoin="round" d="M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />+ </svg>+ </button>+ ) : null;++ // History modal component+ const HistoryModal = showHistoryModal && itemId ? (+ <FieldHistoryModal+ isOpen={showHistoryModal}+ onClose={() => setShowHistoryModal(false)}+ itemId={itemId}+ fieldKey={field.FieldKey}+ fieldLabel={field.Label}+ fieldType={field.FieldType}+ isHidden={field.IsHidden}+ />+ ) : null;+// Render based on field typeswitch (field.FieldType) {case 'Password':@@ -88,18 +115,7 @@ const FieldBlock: React.FC<FieldBlockProps> = ({ field, itemId }) => {<div><label htmlFor={field.FieldKey} className="block mb-2 text-sm font-medium text-gray-700 dark:text-gray-300">{field.Label}- {historyCount > 0 && itemId && (- <button- type="button"- onClick={() => setShowHistoryModal(true)}- className="ml-2 inline-flex items-center text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 focus:outline-none"- title={t('credentials.viewHistory')}- >- <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor">- <path strokeLinecap="round" strokeLinejoin="round" d="M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />- </svg>- </button>- )}+ {HistoryButton}</label><div className="relative"><input@@ -130,15 +146,7 @@ const FieldBlock: React.FC<FieldBlockProps> = ({ field, itemId }) => {</div></div></div>- {showHistoryModal && itemId && (- <PasswordHistoryModal- isOpen={showHistoryModal}- onClose={() => setShowHistoryModal(false)}- itemId={itemId}- fieldKey={field.FieldKey}- fieldLabel={field.Label}- />- )}+ {HistoryModal}</>);@@ -167,12 +175,43 @@ const FieldBlock: React.FC<FieldBlockProps> = ({ field, itemId }) => {case 'Text':default:return (- <FormInputCopyToClipboard- id={field.FieldKey}- label={field.Label}- value={value}- type="text"- />+ <>+ <div>+ <label htmlFor={field.FieldKey} className="block mb-2 text-sm font-medium text-gray-700 dark:text-gray-300">+ {field.Label}+ {HistoryButton}+ </label>+ <div className="relative">+ <input+ type="text"+ id={field.FieldKey}+ readOnly+ value={value}+ className="w-full px-3 py-2.5 bg-white border border-gray-300 text-gray-900 text-sm rounded-lg shadow-sm focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:placeholder-gray-400"+ />+ <div className="absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2">+ <button+ type="button"+ onClick={async () => {+ try {+ await navigator.clipboard.writeText(value);+ } catch (err) {+ console.error('Failed to copy:', err);+ }+ }}+ className="p-1 text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white transition-colors duration-200"+ title={t('common.copyToClipboard')}+ >+ <svg className="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">+ <rect x="9" y="9" width="13" height="13" rx="2" ry="2" />+ <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />+ </svg>+ </button>+ </div>+ </div>+ </div>+ {HistoryModal}+ </>);}};diff --git a/apps/browser-extension/src/entrypoints/popup/components/Credentials/Details/PasswordHistoryModal.tsx b/apps/browser-extension/src/entrypoints/popup/components/Credentials/Details/FieldHistoryModal.tsxsimilarity index 78%rename from apps/browser-extension/src/entrypoints/popup/components/Credentials/Details/PasswordHistoryModal.tsxrename to apps/browser-extension/src/entrypoints/popup/components/Credentials/Details/FieldHistoryModal.tsxindex 08ae7c06f..6064bbcbe 100644--- a/apps/browser-extension/src/entrypoints/popup/components/Credentials/Details/PasswordHistoryModal.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/Credentials/Details/FieldHistoryModal.tsx@@ -3,33 +3,42 @@ import { useTranslation } from 'react-i18next';import { useDb } from '@/entrypoints/popup/context/DbContext';-import type { FieldHistory } from '@/utils/dist/shared/models/vault';+import type { FieldHistory, FieldType } from '@/utils/dist/shared/models/vault';-interface PasswordHistoryModalProps {+interface FieldHistoryModalProps {isOpen: boolean;onClose: () => void;itemId: string;fieldKey: string;fieldLabel: string;+ fieldType: FieldType;+ isHidden: boolean;}/**- * Modal component for displaying password history.- * Shows historical values with dates, passwords hidden by default.+ * Modal component for displaying field value history.+ * Shows historical values with dates.+ * For hidden/password fields, values are masked by default.+ * For other fields, values are visible by default.*/-const PasswordHistoryModal: React.FC<PasswordHistoryModalProps> = ({+const FieldHistoryModal: React.FC<FieldHistoryModalProps> = ({isOpen,onClose,itemId,fieldKey,- fieldLabel+ fieldLabel,+ fieldType,+ isHidden}) => {const { t } = useTranslation();const dbContext = useDb();const [history, setHistory] = useState<FieldHistory[]>([]);- const [visiblePasswords, setVisiblePasswords] = useState<Set<string>>(new Set());+ const [visibleValues, setVisibleValues] = useState<Set<string>>(new Set());const [loading, setLoading] = useState(true);+ // For non-hidden fields, show values by default+ const shouldMaskByDefault = isHidden || fieldType === 'Password' || fieldType === 'Hidden';+useEffect(() => {if (!isOpen || !dbContext?.sqliteClient) {return;@@ -50,8 +59,8 @@ const PasswordHistoryModal: React.FC<PasswordHistoryModalProps> = ({return null;}- const togglePasswordVisibility = (historyId: string): void => {- setVisiblePasswords(prev => {+ const toggleValueVisibility = (historyId: string): void => {+ setVisibleValues(prev => {const newSet = new Set(prev);if (newSet.has(historyId)) {newSet.delete(historyId);@@ -132,7 +141,9 @@ const PasswordHistoryModal: React.FC<PasswordHistoryModalProps> = ({<div className="space-y-3">{history.map((record) => {const values = parseValueSnapshot(record.ValueSnapshot);- const isVisible = visiblePasswords.has(record.Id);+ // For hidden fields, check if this record is explicitly set to visible+ // For non-hidden fields, always show values (no toggle needed)+ const isVisible = shouldMaskByDefault ? visibleValues.has(record.Id) : true;return (<div@@ -143,13 +154,15 @@ const PasswordHistoryModal: React.FC<PasswordHistoryModalProps> = ({<div className="text-sm text-gray-600 dark:text-gray-400">{formatDate(record.ChangedAt)}</div>- <button- type="button"- onClick={() => togglePasswordVisibility(record.Id)}- className="text-sm text-primary-600 hover:text-primary-700 dark:text-primary-400 dark:hover:text-primary-300 focus:outline-none"- >- {isVisible ? t('common.hide') : t('common.show')}- </button>+ {shouldMaskByDefault && (+ <button+ type="button"+ onClick={() => toggleValueVisibility(record.Id)}+ className="text-sm text-primary-600 hover:text-primary-700 dark:text-primary-400 dark:hover:text-primary-300 focus:outline-none"+ >+ {isVisible ? t('common.hide') : t('common.show')}+ </button>+ )}</div>{values.map((value, idx) => (@@ -157,8 +170,8 @@ const PasswordHistoryModal: React.FC<PasswordHistoryModalProps> = ({key={idx}className="flex items-center gap-2 mt-2">- <div className="flex-1 font-mono text-sm bg-white dark:bg-gray-800 rounded px-3 py-2 border border-gray-200 dark:border-gray-600">- {isVisible ? value : '\u2022'.repeat(12)}+ <div className="flex-1 font-mono text-sm bg-white dark:bg-gray-800 rounded px-3 py-2 border border-gray-200 dark:border-gray-600 break-all">+ {shouldMaskByDefault && !isVisible ? '\u2022'.repeat(12) : value}</div><buttontype="button"@@ -195,4 +208,4 @@ const PasswordHistoryModal: React.FC<PasswordHistoryModalProps> = ({);};-export default PasswordHistoryModal;+export default FieldHistoryModal;