Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add typed ItemFilter enum (#2413)
Leendert de Borst32a124af4611
diff --git a/apps/browser-extension/src/entrypoints/popup/components/Items/ItemFilterDropdown.tsx b/apps/browser-extension/src/entrypoints/popup/components/Items/ItemFilterDropdown.tsxindex 18ae70cf9..86693b9c2 100644--- a/apps/browser-extension/src/entrypoints/popup/components/Items/ItemFilterDropdown.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/Items/ItemFilterDropdown.tsx@@ -1,4 +1,4 @@-import { isItemTypeFilter, type ItemFilterType } from '@aliasvault/client/items/ItemFilters';+import { ItemFilter, isItemTypeFilter, type ItemFilterType } from '@aliasvault/client/items/ItemFilters';import React, { useState } from 'react';import { useTranslation } from 'react-i18next';@@ -106,8 +106,8 @@ const ItemFilterDropdown: React.FC<ItemFilterDropdownProps> = ({<div className="py-1"><div className="relative"><button- onClick={() => handleSelectFilter('all')}- className={itemRowClass(activeFilter === 'all')}+ onClick={() => handleSelectFilter(ItemFilter.All)}+ className={itemRowClass(activeFilter === ItemFilter.All)}>{t('items.title')}</button>@@ -155,20 +155,20 @@ const ItemFilterDropdown: React.FC<ItemFilterDropdownProps> = ({})}<div className="border-t border-gray-200 dark:border-gray-700 my-1" /><button- onClick={() => handleSelectFilter('passkeys')}- className={itemRowClass(activeFilter === 'passkeys')}+ onClick={() => handleSelectFilter(ItemFilter.Passkeys)}+ className={itemRowClass(activeFilter === ItemFilter.Passkeys)}>{t('common.passkeys')}</button><button- onClick={() => handleSelectFilter('attachments')}- className={itemRowClass(activeFilter === 'attachments')}+ onClick={() => handleSelectFilter(ItemFilter.Attachments)}+ className={itemRowClass(activeFilter === ItemFilter.Attachments)}>{t('common.attachments')}</button><button- onClick={() => handleSelectFilter('totp')}- className={itemRowClass(activeFilter === 'totp')}+ onClick={() => handleSelectFilter(ItemFilter.Totp)}+ className={itemRowClass(activeFilter === ItemFilter.Totp)}>{t('items.filters.totp')}</button>diff --git a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsxindex 11f273068..a98c18e36 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/items/ItemsList.tsx@@ -1,7 +1,7 @@import { isSameItem, scopedKey } from '@aliasvault/client/database/ItemRef';import { CredentialSortOrder } from '@aliasvault/client/database/repositories/SettingsRepository';import { canHaveSubfolders, getDescendantFolderIds, getFolderPath, getRecursiveItemCount, isItemInFolder, isSharedFolder } from '@aliasvault/client/items/FolderUtils';-import { applySearchFilter, applyTypeFilter, isItemTypeFilter, parseItemFilterType, type ItemFilterType } from '@aliasvault/client/items/ItemFilters';+import { ItemFilter, applySearchFilter, applyTypeFilter, isItemTypeFilter, parseItemFilterType, type ItemFilterType } from '@aliasvault/client/items/ItemFilters';import { multiManifestRendering } from '@aliasvault/client/sharing/MultiManifestRendering';import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';import { useTranslation } from 'react-i18next';@@ -67,7 +67,7 @@ const getStoredFilter = (): ItemFilterType => {try {const stored = localStorage.getItem(FILTER_STORAGE_KEY);if (!stored) {- return 'all';+ return ItemFilter.All;}const { filter, timestamp } = JSON.parse(stored);@@ -76,12 +76,12 @@ const getStoredFilter = (): ItemFilterType => {// Check if expired (5 minutes)if (now - timestamp > FILTER_EXPIRY_MS) {localStorage.removeItem(FILTER_STORAGE_KEY);- return 'all';+ return ItemFilter.All;}return filter as ItemFilterType;} catch {- return 'all';+ return ItemFilter.All;}};@@ -228,7 +228,7 @@ const ItemsList: React.FC = () => {const state = location.state as { resetFilters?: boolean } | null;if (state?.resetFilters) {setSearchTerm('');- setItemFilterType('all');+ setItemFilterType(ItemFilter.All);localStorage.removeItem(FILTER_STORAGE_KEY);// Clear the state to prevent re-triggering on subsequent rendersnavigate(location.pathname, { replace: true, state: {} });@@ -540,13 +540,13 @@ const ItemsList: React.FC = () => {*/const getFilterTitle = () : string => {switch (filterType) {- case 'passkeys':+ case ItemFilter.Passkeys:return t('common.passkeys');- case 'attachments':+ case ItemFilter.Attachments:return t('common.attachments');- case 'totp':+ case ItemFilter.Totp:return t('items.filters.totp');- case 'all':+ case ItemFilter.All:if (currentFolderId && currentFolderName) {return currentFolderName;}@@ -934,7 +934,7 @@ const ItemsList: React.FC = () => {)}{/* Current-site suggestion: show a suggestion for the current site's matching item(s) to quickly view/open them. */}- {items.length > CURRENT_SITE_SUGGESTION_MIN_ITEMS && !currentFolderId && !searchTerm && filterType === 'all' && (+ {items.length > CURRENT_SITE_SUGGESTION_MIN_ITEMS && !currentFolderId && !searchTerm && filterType === ItemFilter.All && (<CurrentSiteSuggestion items={items} onSearch={setSearchTerm} />)}@@ -952,18 +952,18 @@ const ItemsList: React.FC = () => {) : filteredItems.length === 0 && folders.length === 0 && !hasItemsInFoldersOnly && !currentFolderId ? (<div className="text-gray-500 dark:text-gray-400 space-y-3 mb-10">{/* Show filter/search-specific messages only when actively filtering or searching */}- {(filterType !== 'all' || searchTerm) && (+ {(filterType !== ItemFilter.All || searchTerm) && (<><p>{/* Different messages based on what's causing no results */}- {searchTerm && filterType !== 'all'+ {searchTerm && filterType !== ItemFilter.All// Both search and filter active? t('items.noMatchingItemsWithFilter', { filter: getFilterTitle(), search: searchTerm }): searchTerm// Only search active? t('items.noMatchingItemsSearch', { search: searchTerm })// Only filter active (no search)- : filterType !== 'all'+ : filterType !== ItemFilter.All? t('items.noMatchingItems'): t('items.noMatchingItems')}@@ -982,10 +982,10 @@ const ItemsList: React.FC = () => {{t('items.clearSearch')}</button>)}- {filterType !== 'all' && (+ {filterType !== ItemFilter.All && (<buttononClick={() => {- setItemFilterType('all');+ setItemFilterType(ItemFilter.All);localStorage.removeItem(FILTER_STORAGE_KEY);}}className="inline-flex items-center gap-1 px-3 py-1.5 text-sm bg-orange-100 dark:bg-orange-900/30 hover:bg-orange-200 dark:hover:bg-orange-900/50 text-orange-700 dark:text-orange-300 rounded-lg transition-colors"@@ -1111,7 +1111,7 @@ const ItemsList: React.FC = () => {)}{/* Clear filter/search pills at bottom of list when filtering or searching */}- {(filterType !== 'all' || searchTerm) && (+ {(filterType !== ItemFilter.All || searchTerm) && (<div className="flex flex-wrap justify-center gap-2 mt-4 pt-4">{searchTerm && (<button@@ -1125,10 +1125,10 @@ const ItemsList: React.FC = () => {{t('items.clearSearch')}</button>)}- {filterType !== 'all' && (+ {filterType !== ItemFilter.All && (<buttononClick={() => {- setItemFilterType('all');+ setItemFilterType(ItemFilter.All);localStorage.removeItem(FILTER_STORAGE_KEY);}}className="inline-flex items-center gap-1 px-3 py-1.5 text-sm bg-orange-100 dark:bg-orange-900/30 hover:bg-orange-200 dark:hover:bg-orange-900/50 text-orange-700 dark:text-orange-300 rounded-lg transition-colors"diff --git a/apps/mobile-app/app/(tabs)/items/folder/[manifestId]/[id].tsx b/apps/mobile-app/app/(tabs)/items/folder/[manifestId]/[id].tsxindex a08df652b..15fb092eb 100644--- a/apps/mobile-app/app/(tabs)/items/folder/[manifestId]/[id].tsx+++ b/apps/mobile-app/app/(tabs)/items/folder/[manifestId]/[id].tsx@@ -1,8 +1,8 @@import { scopedKey, type ItemRef } from '@aliasvault/client/database/ItemRef';import { canHaveSubfolders, getRecursiveItemCount, isSharedFolder } from '@aliasvault/client/items/FolderUtils';-import { applyTypeFilter, isItemTypeFilter, parseItemFilterType, type ItemFilterType } from '@aliasvault/client/items/ItemFilters';+import { ItemFilter, applyTypeFilter, isItemTypeFilter, parseItemFilterType, type ItemFilterType } from '@aliasvault/client/items/ItemFilters';import { multiManifestRendering } from '@aliasvault/client/sharing/MultiManifestRendering';-import { getFieldValue, FieldKey, ItemTypes } from '@aliasvault/models/vault';+import { getFieldValue, FieldKey } from '@aliasvault/models/vault';import MaterialIcons from '@expo/vector-icons/MaterialIcons';import { useNavigation, useRouter, useLocalSearchParams } from 'expo-router';import { useState, useEffect, useCallback, useRef, useMemo } from 'react';@@ -51,7 +51,7 @@ import type { ItemType } from '@aliasvault/models/vault';* Item type filter option configuration.*/type ItemTypeOption = {- type: ItemType;+ type: ItemFilterType;titleKey: string;iconName: keyof typeof MaterialIcons.glyphMap;};@@ -60,10 +60,10 @@ type ItemTypeOption = {* Available item type filter options with icons.*/const ITEM_TYPE_OPTIONS: ItemTypeOption[] = [- { type: ItemTypes.Login, titleKey: 'itemTypes.login.title', iconName: 'key' },- { type: ItemTypes.Alias, titleKey: 'itemTypes.alias.title', iconName: 'person' },- { type: ItemTypes.CreditCard, titleKey: 'itemTypes.creditCard.title', iconName: 'credit-card' },- { type: ItemTypes.Note, titleKey: 'itemTypes.note.title', iconName: 'description' },+ { type: ItemFilter.Login, titleKey: 'itemTypes.login.title', iconName: 'key' },+ { type: ItemFilter.Alias, titleKey: 'itemTypes.alias.title', iconName: 'person' },+ { type: ItemFilter.CreditCard, titleKey: 'itemTypes.creditCard.title', iconName: 'credit-card' },+ { type: ItemFilter.Note, titleKey: 'itemTypes.note.title', iconName: 'description' },];/**@@ -109,15 +109,15 @@ export default function FolderViewScreen(): React.ReactNode {/*** Get the title based on the active filter.- * Shows "Items" for 'all' filter since folder name is already in the navigation header.+ * Shows "Items" for the All filter since folder name is already in the navigation header.*/const getFilterTitle = useCallback((): string => {switch (filterType) {- case 'passkeys':+ case ItemFilter.Passkeys:return t('items.filters.passkeys');- case 'attachments':+ case ItemFilter.Attachments:return t('common.attachments');- case 'all':+ case ItemFilter.All:return t('items.title');default:if (isItemTypeFilter(filterType)) {@@ -661,16 +661,16 @@ export default function FolderViewScreen(): React.ReactNode {<TouchableOpacitystyle={[styles.filterMenuItem,- filterType === 'all' && styles.filterMenuItemActive+ filterType === ItemFilter.All && styles.filterMenuItemActive]}onPress={() => {- setFilterType('all');+ setFilterType(ItemFilter.All);setShowFilterMenu(false);}}><ThemedText style={[styles.filterMenuItemText,- filterType === 'all' && styles.filterMenuItemTextActive+ filterType === ItemFilter.All && styles.filterMenuItemTextActive]}>{t('items.filters.all')}</ThemedText>@@ -713,16 +713,16 @@ export default function FolderViewScreen(): React.ReactNode {<TouchableOpacitystyle={[styles.filterMenuItem,- filterType === 'passkeys' && styles.filterMenuItemActive+ filterType === ItemFilter.Passkeys && styles.filterMenuItemActive]}onPress={() => {- setFilterType('passkeys');+ setFilterType(ItemFilter.Passkeys);setShowFilterMenu(false);}}><ThemedText style={[styles.filterMenuItemText,- filterType === 'passkeys' && styles.filterMenuItemTextActive+ filterType === ItemFilter.Passkeys && styles.filterMenuItemTextActive]}>{t('items.filters.passkeys')}</ThemedText>@@ -732,16 +732,16 @@ export default function FolderViewScreen(): React.ReactNode {<TouchableOpacitystyle={[styles.filterMenuItem,- filterType === 'attachments' && styles.filterMenuItemActive+ filterType === ItemFilter.Attachments && styles.filterMenuItemActive]}onPress={() => {- setFilterType('attachments');+ setFilterType(ItemFilter.Attachments);setShowFilterMenu(false);}}><ThemedText style={[styles.filterMenuItemText,- filterType === 'attachments' && styles.filterMenuItemTextActive+ filterType === ItemFilter.Attachments && styles.filterMenuItemTextActive]}>{t('common.attachments')}</ThemedText>diff --git a/apps/mobile-app/app/(tabs)/items/index.tsx b/apps/mobile-app/app/(tabs)/items/index.tsxindex 88391128b..44268809c 100644--- a/apps/mobile-app/app/(tabs)/items/index.tsx+++ b/apps/mobile-app/app/(tabs)/items/index.tsx@@ -1,8 +1,8 @@import { scopedKey, type ItemRef } from '@aliasvault/client/database/ItemRef';import { CredentialSortOrder } from '@aliasvault/client/database/repositories/SettingsRepository';import { getRecursiveItemCount, isSharedFolder } from '@aliasvault/client/items/FolderUtils';-import { applyTypeFilter, isItemTypeFilter, type ItemFilterType } from '@aliasvault/client/items/ItemFilters';-import { getFieldValue, FieldKey, ItemTypes } from '@aliasvault/models/vault';+import { ItemFilter, applyTypeFilter, isItemTypeFilter, type ItemFilterType } from '@aliasvault/client/items/ItemFilters';+import { getFieldValue, FieldKey } from '@aliasvault/models/vault';import MaterialIcons from '@expo/vector-icons/MaterialIcons';import { useNavigation, useRouter, useLocalSearchParams } from 'expo-router';import { useState, useEffect, useCallback, useRef, useMemo } from 'react';@@ -50,7 +50,7 @@ import type { ItemType } from '@aliasvault/models/vault';* Item type filter option configuration.*/type ItemTypeOption = {- type: ItemType;+ type: ItemFilterType;titleKey: string;iconName: keyof typeof MaterialIcons.glyphMap;};@@ -59,10 +59,10 @@ type ItemTypeOption = {* Available item type filter options with icons.*/const ITEM_TYPE_OPTIONS: ItemTypeOption[] = [- { type: ItemTypes.Login, titleKey: 'itemTypes.login.title', iconName: 'key' },- { type: ItemTypes.Alias, titleKey: 'itemTypes.alias.title', iconName: 'person' },- { type: ItemTypes.CreditCard, titleKey: 'itemTypes.creditCard.title', iconName: 'credit-card' },- { type: ItemTypes.Note, titleKey: 'itemTypes.note.title', iconName: 'description' },+ { type: ItemFilter.Login, titleKey: 'itemTypes.login.title', iconName: 'key' },+ { type: ItemFilter.Alias, titleKey: 'itemTypes.alias.title', iconName: 'person' },+ { type: ItemFilter.CreditCard, titleKey: 'itemTypes.creditCard.title', iconName: 'credit-card' },+ { type: ItemFilter.Note, titleKey: 'itemTypes.note.title', iconName: 'description' },];/**@@ -91,7 +91,7 @@ export default function ItemsScreen(): React.ReactNode {// Search and filter stateconst [searchQuery, setSearchQuery] = useState('');- const [filterType, setFilterType] = useState<ItemFilterType>('all');+ const [filterType, setFilterType] = useState<ItemFilterType>(ItemFilter.All);const [showFilterMenu, setShowFilterMenu] = useState(false);const [sortOrder, setSortOrder] = useState<CredentialSortOrder>(CredentialSortOrder.NewestFirst);const [showSortMenu, setShowSortMenu] = useState(false);@@ -209,13 +209,13 @@ export default function ItemsScreen(): React.ReactNode {*/const getFilterTitle = useCallback((): string => {switch (filterType) {- case 'passkeys':+ case ItemFilter.Passkeys:return t('items.filters.passkeys');- case 'attachments':+ case ItemFilter.Attachments:return t('common.attachments');- case 'totp':+ case ItemFilter.Totp:return t('items.filters.totp');- case 'all':+ case ItemFilter.All:return t('items.title');default:if (isItemTypeFilter(filterType)) {@@ -833,7 +833,7 @@ export default function ItemsScreen(): React.ReactNode {*/const getMessage = (): string => {// Both search and filter active- if (searchQuery && filterType !== 'all') {+ if (searchQuery && filterType !== ItemFilter.All) {return t('items.noMatchingItemsWithFilter', { filter: getFilterTitle(), search: searchQuery });}// Only search active@@ -841,7 +841,7 @@ export default function ItemsScreen(): React.ReactNode {return t('items.noMatchingItemsSearch', { search: searchQuery });}// Only filter active (no search)- if (filterType !== 'all') {+ if (filterType !== ItemFilter.All) {return t('items.noMatchingItems');}// All items are in folders - show helpful message@@ -852,7 +852,7 @@ export default function ItemsScreen(): React.ReactNode {return t('items.noItemsFound');};- const showClearButtons = searchQuery || filterType !== 'all';+ const showClearButtons = searchQuery || filterType !== ItemFilter.All;return (<View style={styles.emptyContainer}>@@ -870,10 +870,10 @@ export default function ItemsScreen(): React.ReactNode {<Text style={styles.clearSearchButtonText}>{t('items.clearSearch')}</Text></TouchableOpacity>)}- {filterType !== 'all' && (+ {filterType !== ItemFilter.All && (<TouchableOpacitystyle={styles.clearFilterButton}- onPress={() => setFilterType('all')}+ onPress={() => setFilterType(ItemFilter.All)}><MaterialIcons name="close" size={16} color={colors.primary} /><Text style={styles.clearFilterButtonText}>{t('items.clearFilter')}</Text>@@ -891,7 +891,7 @@ export default function ItemsScreen(): React.ReactNode {*/const renderListFooter = (): React.ReactNode => {// Don't show footer if loading, no items, or no active filter/search- if (isLoadingItems || filteredItems.length === 0 || (filterType === 'all' && !searchQuery)) {+ if (isLoadingItems || filteredItems.length === 0 || (filterType === ItemFilter.All && !searchQuery)) {return null;}@@ -906,10 +906,10 @@ export default function ItemsScreen(): React.ReactNode {<Text style={styles.clearSearchButtonText}>{t('items.clearSearch')}</Text></TouchableOpacity>)}- {filterType !== 'all' && (+ {filterType !== ItemFilter.All && (<TouchableOpacitystyle={styles.clearFilterButton}- onPress={() => setFilterType('all')}+ onPress={() => setFilterType(ItemFilter.All)}><MaterialIcons name="close" size={16} color={colors.primary} /><Text style={styles.clearFilterButtonText}>{t('items.clearFilter')}</Text>diff --git a/apps/mobile-app/components/items/ItemFilterMenu.tsx b/apps/mobile-app/components/items/ItemFilterMenu.tsxindex 91db32455..7c5c9c150 100644--- a/apps/mobile-app/components/items/ItemFilterMenu.tsx+++ b/apps/mobile-app/components/items/ItemFilterMenu.tsx@@ -3,8 +3,7 @@ import { useTranslation } from 'react-i18next';import { Platform, StyleSheet, TouchableOpacity, View } from 'react-native';import { useSafeAreaInsets } from 'react-native-safe-area-context';-import { ItemTypes, type ItemType } from '@aliasvault/models/vault';-import type { ItemFilterType } from '@aliasvault/client/items/ItemFilters';+import { ItemFilter, type ItemFilterType } from '@aliasvault/client/items/ItemFilters';import { useColors } from '@/hooks/useColorScheme';@@ -18,16 +17,16 @@ import { ThemedView } from '@/components/themed/ThemedView';export type ItemFilterSelection = ItemFilterType | 'deleted';type ItemTypeOption = {- type: ItemType;+ type: ItemFilterType;titleKey: string;iconName: keyof typeof MaterialIcons.glyphMap;};const ITEM_TYPE_OPTIONS: ItemTypeOption[] = [- { type: ItemTypes.Login, titleKey: 'itemTypes.login.title', iconName: 'key' },- { type: ItemTypes.Alias, titleKey: 'itemTypes.alias.title', iconName: 'person' },- { type: ItemTypes.CreditCard, titleKey: 'itemTypes.creditCard.title', iconName: 'credit-card' },- { type: ItemTypes.Note, titleKey: 'itemTypes.note.title', iconName: 'description' },+ { type: ItemFilter.Login, titleKey: 'itemTypes.login.title', iconName: 'key' },+ { type: ItemFilter.Alias, titleKey: 'itemTypes.alias.title', iconName: 'person' },+ { type: ItemFilter.CreditCard, titleKey: 'itemTypes.creditCard.title', iconName: 'credit-card' },+ { type: ItemFilter.Note, titleKey: 'itemTypes.note.title', iconName: 'description' },];interface ItemFilterMenuProps {@@ -178,9 +177,9 @@ export function ItemFilterMenu({<TouchableOpacity style={styles.backdrop} activeOpacity={1} onPress={onClose} /><ThemedView style={styles.overlay}>{/* All items + show folders toggle */}- <View style={[styles.item, styles.itemWithToggle, isActive('all') && styles.itemActive]}>- <TouchableOpacity style={styles.itemLabel} onPress={() => handlePickFilter('all')}>- <ThemedText style={[styles.itemText, isActive('all') && styles.itemTextActive]}>+ <View style={[styles.item, styles.itemWithToggle, isActive(ItemFilter.All) && styles.itemActive]}>+ <TouchableOpacity style={styles.itemLabel} onPress={() => handlePickFilter(ItemFilter.All)}>+ <ThemedText style={[styles.itemText, isActive(ItemFilter.All) && styles.itemTextActive]}>{t('items.filters.all')}</ThemedText></TouchableOpacity>@@ -228,26 +227,26 @@ export function ItemFilterMenu({{/* Passkeys / Attachments / TOTP */}<TouchableOpacity- style={[styles.item, isActive('passkeys') && styles.itemActive]}- onPress={() => handlePickFilter('passkeys')}+ style={[styles.item, isActive(ItemFilter.Passkeys) && styles.itemActive]}+ onPress={() => handlePickFilter(ItemFilter.Passkeys)}>- <ThemedText style={[styles.itemText, isActive('passkeys') && styles.itemTextActive]}>+ <ThemedText style={[styles.itemText, isActive(ItemFilter.Passkeys) && styles.itemTextActive]}>{t('items.filters.passkeys')}</ThemedText></TouchableOpacity><TouchableOpacity- style={[styles.item, isActive('attachments') && styles.itemActive]}- onPress={() => handlePickFilter('attachments')}+ style={[styles.item, isActive(ItemFilter.Attachments) && styles.itemActive]}+ onPress={() => handlePickFilter(ItemFilter.Attachments)}>- <ThemedText style={[styles.itemText, isActive('attachments') && styles.itemTextActive]}>+ <ThemedText style={[styles.itemText, isActive(ItemFilter.Attachments) && styles.itemTextActive]}>{t('common.attachments')}</ThemedText></TouchableOpacity><TouchableOpacity- style={[styles.item, isActive('totp') && styles.itemActive]}- onPress={() => handlePickFilter('totp')}+ style={[styles.item, isActive(ItemFilter.Totp) && styles.itemActive]}+ onPress={() => handlePickFilter(ItemFilter.Totp)}>- <ThemedText style={[styles.itemText, isActive('totp') && styles.itemTextActive]}>+ <ThemedText style={[styles.itemText, isActive(ItemFilter.Totp) && styles.itemTextActive]}>{t('items.filters.totp')}</ThemedText></TouchableOpacity>diff --git a/apps/web/src/components/items/ItemFilterDropdown.tsx b/apps/web/src/components/items/ItemFilterDropdown.tsxindex 8873e94b6..bec1a4d41 100644--- a/apps/web/src/components/items/ItemFilterDropdown.tsx+++ b/apps/web/src/components/items/ItemFilterDropdown.tsx@@ -1,5 +1,4 @@-import { type ItemFilterType } from '@aliasvault/client/items/ItemFilters';-import { ItemTypes } from '@aliasvault/models/vault';+import { ItemFilter, type ItemFilterType } from '@aliasvault/client/items/ItemFilters';import React, { useCallback, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';@@ -77,8 +76,8 @@ const ItemFilterDropdown: React.FC<ItemFilterDropdownProps> = ({ title, count, a{isOpen && (<div ref={menuRef} className="absolute left-0 top-full z-40 mt-2 w-56 origin-top-left rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none dark:bg-gray-700"><div className="py-1">- <div className={`flex items-center justify-between px-4 py-2 ${isActive('all') ? 'bg-orange-50 dark:bg-orange-900/20' : ''}`}>- <button onClick={() => pickFilter('all')} className={`text-left text-sm hover:text-gray-900 dark:hover:text-white ${isActive('all') ? 'text-orange-600 dark:text-orange-400' : 'text-gray-700 dark:text-gray-300'}`}>+ <div className={`flex items-center justify-between px-4 py-2 ${isActive(ItemFilter.All) ? 'bg-orange-50 dark:bg-orange-900/20' : ''}`}>+ <button onClick={() => pickFilter(ItemFilter.All)} className={`text-left text-sm hover:text-gray-900 dark:hover:text-white ${isActive(ItemFilter.All) ? 'text-orange-600 dark:text-orange-400' : 'text-gray-700 dark:text-gray-300'}`}>{t('pages.main.items.home.FilterAllOption')}</button>{showFoldersToggle && (@@ -95,26 +94,26 @@ const ItemFilterDropdown: React.FC<ItemFilterDropdownProps> = ({ title, count, a</div><div className="border-t border-gray-200 dark:border-gray-600 my-1"></div>- <button onClick={() => pickFilter(ItemTypes.Login)} className={rowClass(ItemTypes.Login, true)}>- <svg className={iconClass(ItemTypes.Login)} fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <button onClick={() => pickFilter(ItemFilter.Login)} className={rowClass(ItemFilter.Login, true)}>+ <svg className={iconClass(ItemFilter.Login)} fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z" /></svg>{t('components.main.items.itemTypeSelector.TypeLogin')}</button>- <button onClick={() => pickFilter(ItemTypes.Alias)} className={rowClass(ItemTypes.Alias, true)}>- <svg className={iconClass(ItemTypes.Alias)} fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <button onClick={() => pickFilter(ItemFilter.Alias)} className={rowClass(ItemFilter.Alias, true)}>+ <svg className={iconClass(ItemFilter.Alias)} fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" /></svg>{t('components.main.items.itemTypeSelector.TypeAlias')}</button>- <button onClick={() => pickFilter(ItemTypes.CreditCard)} className={rowClass(ItemTypes.CreditCard, true)}>- <svg className={iconClass(ItemTypes.CreditCard)} fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <button onClick={() => pickFilter(ItemFilter.CreditCard)} className={rowClass(ItemFilter.CreditCard, true)}>+ <svg className={iconClass(ItemFilter.CreditCard)} fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" /></svg>{t('components.main.items.itemTypeSelector.TypeCreditCard')}</button>- <button onClick={() => pickFilter(ItemTypes.Note)} className={rowClass(ItemTypes.Note, true)}>- <svg className={iconClass(ItemTypes.Note)} fill="none" stroke="currentColor" viewBox="0 0 24 24">+ <button onClick={() => pickFilter(ItemFilter.Note)} className={rowClass(ItemFilter.Note, true)}>+ <svg className={iconClass(ItemFilter.Note)} fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" /></svg>{t('components.main.items.itemTypeSelector.TypeNote')}@@ -122,13 +121,13 @@ const ItemFilterDropdown: React.FC<ItemFilterDropdownProps> = ({ title, count, a<div className="border-t border-gray-200 dark:border-gray-600 my-1"></div>- <button onClick={() => pickFilter('passkeys')} className={rowClass('passkeys', false)}>+ <button onClick={() => pickFilter(ItemFilter.Passkeys)} className={rowClass(ItemFilter.Passkeys, false)}>{t('pages.main.items.home.FilterPasskeysOption')}</button>- <button onClick={() => pickFilter('attachments')} className={rowClass('attachments', false)}>+ <button onClick={() => pickFilter(ItemFilter.Attachments)} className={rowClass(ItemFilter.Attachments, false)}>{t('pages.main.items.home.FilterAttachmentsOption')}</button>- <button onClick={() => pickFilter('totp')} className={rowClass('totp', false)}>+ <button onClick={() => pickFilter(ItemFilter.Totp)} className={rowClass(ItemFilter.Totp, false)}>{t('pages.main.items.home.FilterTotpOption')}</button>diff --git a/core/client/src/items/ItemFilters.ts b/core/client/src/items/ItemFilters.tsindex cfb5c3384..6677f8e0b 100644--- a/core/client/src/items/ItemFilters.ts+++ b/core/client/src/items/ItemFilters.ts@@ -3,14 +3,23 @@ import { ItemTypes } from '@aliasvault/models/vault';import type { Item, ItemType } from '@aliasvault/models/vault';/**- * Filter types for the items list.- * - 'all': Show all items- * - 'passkeys': Show only items with passkeys- * - 'attachments': Show only items with attachments- * - 'totp': Show only items with 2FA codes- * - ItemType values: Filter by specific item type (Login, Alias, CreditCard, Note)+ * Filters for the items list: feature filters plus one per item type. The values appear as-is in route params.*/-export type ItemFilterType = 'all' | 'passkeys' | 'attachments' | 'totp' | ItemType;+export const ItemFilter = {+ All: 'all',+ Passkeys: 'passkeys',+ Attachments: 'attachments',+ Totp: 'totp',+ Login: ItemTypes.Login,+ Alias: ItemTypes.Alias,+ CreditCard: ItemTypes.CreditCard,+ Note: ItemTypes.Note,+} as const;++/**+ * A filter value for the items list.+ */+export type ItemFilterType = typeof ItemFilter[keyof typeof ItemFilter];/*** Check if a filter is an item type filter (Login, Alias, CreditCard, Note).@@ -20,20 +29,17 @@ export function isItemTypeFilter(filter: ItemFilterType): filter is ItemType {}/**- * Parse a filter value from a URL/route param. Returns 'all' if the value is missing+ * Parse a filter value from a URL/route param. Returns `ItemFilter.All` if the value is missing* or doesn't match a known filter, so an unexpected param can't break the screen.*/export function parseItemFilterType(value: string | null | undefined): ItemFilterType {if (!value) {- return 'all';- }- if (value === 'all' || value === 'passkeys' || value === 'attachments' || value === 'totp') {- return value;+ return ItemFilter.All;}- if (isItemTypeFilter(value as ItemFilterType)) {- return value as ItemType;+ if (Object.values(ItemFilter).includes(value as ItemFilterType)) {+ return value as ItemFilterType;}- return 'all';+ return ItemFilter.All;}/**@@ -47,18 +53,18 @@ export type FilterableItem = Pick<Item, 'ItemType' | 'HasPasskey' | 'HasAttachme* stay consistent when a filter is active, folder counts only include matching items.*/export function applyTypeFilter<T extends FilterableItem>(items: T[], filterType: ItemFilterType): T[] {- if (filterType === 'all') {+ if (filterType === ItemFilter.All) {return items;}return items.filter((item: T) => {- if (filterType === 'passkeys') {+ if (filterType === ItemFilter.Passkeys) {return item.HasPasskey === true;}- if (filterType === 'attachments') {+ if (filterType === ItemFilter.Attachments) {return item.HasAttachment === true;}- if (filterType === 'totp') {+ if (filterType === ItemFilter.Totp) {return item.HasTotp === true;}if (isItemTypeFilter(filterType)) {