AI-native design editor. Open-source Figma alternative.
fix(app): remove a file from Recents from its own menu, as Figma does (#1749)
Danila Poyarkove7bb024ecc7f
diff --git a/changes/1749/changed.md b/changes/1749/changed.mdnew file mode 100644index 000000000..bce19c07b--- /dev/null+++ b/changes/1749/changed.md@@ -0,0 +1 @@+- Recent files leave the list one at a time, from Remove from recent in each file's menu, instead of a button that cleared the whole list.diff --git a/packages/vue/src/i18n/locales/de/files.json b/packages/vue/src/i18n/locales/de/files.jsonindex 9167a05e0..998a72441 100644--- a/packages/vue/src/i18n/locales/de/files.json+++ b/packages/vue/src/i18n/locales/de/files.json@@ -36,6 +36,7 @@"noMatchingFiles": "Keine Dateien entsprechen „{query}“.","documentActions": "Aktionen für {name}","deleteDocument": "Löschen",+ "removeFromRecent": "Aus „Zuletzt verwendet“ entfernen","deleteDocumentConfirmation": "„{name}“ löschen?","deleteDocumentDescription": "Das Dokument wird für alle gelöscht, die es öffnen können. Das lässt sich nicht rückgängig machen.","deleteDocumentFailed": "„{name}“ konnte nicht gelöscht werden. Versuche es erneut.",diff --git a/packages/vue/src/i18n/locales/es/files.json b/packages/vue/src/i18n/locales/es/files.jsonindex 02cb9c838..ba625bdc3 100644--- a/packages/vue/src/i18n/locales/es/files.json+++ b/packages/vue/src/i18n/locales/es/files.json@@ -36,6 +36,7 @@"noMatchingFiles": "Ningún archivo coincide con «{query}».","documentActions": "Acciones de {name}","deleteDocument": "Eliminar",+ "removeFromRecent": "Quitar de recientes","deleteDocumentConfirmation": "¿Eliminar «{name}»?","deleteDocumentDescription": "El documento se elimina para todas las personas que pueden abrirlo. No se puede deshacer.","deleteDocumentFailed": "No se pudo eliminar «{name}». Inténtalo de nuevo.",diff --git a/packages/vue/src/i18n/locales/fr/files.json b/packages/vue/src/i18n/locales/fr/files.jsonindex 6a35944c1..79ac47c51 100644--- a/packages/vue/src/i18n/locales/fr/files.json+++ b/packages/vue/src/i18n/locales/fr/files.json@@ -36,6 +36,7 @@"noMatchingFiles": "Aucun fichier ne correspond à « {query} ».","documentActions": "Actions pour {name}","deleteDocument": "Supprimer",+ "removeFromRecent": "Retirer des récents","deleteDocumentConfirmation": "Supprimer « {name} » ?","deleteDocumentDescription": "Le document est supprimé pour toutes les personnes qui peuvent l’ouvrir. Cette action est irréversible.","deleteDocumentFailed": "Impossible de supprimer « {name} ». Réessayez.",diff --git a/packages/vue/src/i18n/locales/it/files.json b/packages/vue/src/i18n/locales/it/files.jsonindex 95c69d530..310541a7e 100644--- a/packages/vue/src/i18n/locales/it/files.json+++ b/packages/vue/src/i18n/locales/it/files.json@@ -36,6 +36,7 @@"noMatchingFiles": "Nessun file corrisponde a «{query}».","documentActions": "Azioni per {name}","deleteDocument": "Elimina",+ "removeFromRecent": "Rimuovi dai recenti","deleteDocumentConfirmation": "Eliminare «{name}»?","deleteDocumentDescription": "Il documento viene eliminato per tutti coloro che possono aprirlo. L’operazione non può essere annullata.","deleteDocumentFailed": "Impossibile eliminare «{name}». Riprova.",diff --git a/packages/vue/src/i18n/locales/ja/files.json b/packages/vue/src/i18n/locales/ja/files.jsonindex 2bfcc64c4..bac17dd31 100644--- a/packages/vue/src/i18n/locales/ja/files.json+++ b/packages/vue/src/i18n/locales/ja/files.json@@ -36,6 +36,7 @@"noMatchingFiles": "「{query}」に一致するファイルはありません。","documentActions": "{name} の操作","deleteDocument": "削除",+ "removeFromRecent": "最近使用した項目から削除","deleteDocumentConfirmation": "「{name}」を削除しますか?","deleteDocumentDescription": "このドキュメントは開けるすべての人に対して削除されます。この操作は元に戻せません。","deleteDocumentFailed": "「{name}」を削除できませんでした。もう一度お試しください。",diff --git a/packages/vue/src/i18n/locales/pl/files.json b/packages/vue/src/i18n/locales/pl/files.jsonindex ed45016df..a296f59d8 100644--- a/packages/vue/src/i18n/locales/pl/files.json+++ b/packages/vue/src/i18n/locales/pl/files.json@@ -36,6 +36,7 @@"noMatchingFiles": "Brak plików pasujących do „{query}”.","documentActions": "Działania dla {name}","deleteDocument": "Usuń",+ "removeFromRecent": "Usuń z ostatnich","deleteDocumentConfirmation": "Usunąć „{name}”?","deleteDocumentDescription": "Dokument zostanie usunięty dla wszystkich, którzy mogą go otworzyć. Tej operacji nie można cofnąć.","deleteDocumentFailed": "Nie udało się usunąć „{name}”. Spróbuj ponownie.",diff --git a/packages/vue/src/i18n/locales/ru/files.json b/packages/vue/src/i18n/locales/ru/files.jsonindex e3cedb671..07609a7b3 100644--- a/packages/vue/src/i18n/locales/ru/files.json+++ b/packages/vue/src/i18n/locales/ru/files.json@@ -36,6 +36,7 @@"noMatchingFiles": "Нет файлов по запросу «{query}».","documentActions": "Действия с {name}","deleteDocument": "Удалить",+ "removeFromRecent": "Убрать из недавних","deleteDocumentConfirmation": "Удалить «{name}»?","deleteDocumentDescription": "Документ будет удалён для всех, кто может его открыть. Это действие нельзя отменить.","deleteDocumentFailed": "Не удалось удалить «{name}». Попробуйте ещё раз.",diff --git a/packages/vue/src/i18n/locales/zh-cn/files.json b/packages/vue/src/i18n/locales/zh-cn/files.jsonindex 274a2ef82..17d64beb7 100644--- a/packages/vue/src/i18n/locales/zh-cn/files.json+++ b/packages/vue/src/i18n/locales/zh-cn/files.json@@ -36,6 +36,7 @@"noMatchingFiles": "没有与“{query}”匹配的文件。","documentActions": "{name} 的操作","deleteDocument": "删除",+ "removeFromRecent": "从最近使用中移除","deleteDocumentConfirmation": "删除“{name}”?","deleteDocumentDescription": "该文档将对所有可以打开它的人删除。此操作无法撤销。","deleteDocumentFailed": "无法删除“{name}”。请重试。",diff --git a/packages/vue/src/i18n/messages/files.ts b/packages/vue/src/i18n/messages/files.tsindex 0c6333ada..9190baaa8 100644--- a/packages/vue/src/i18n/messages/files.ts+++ b/packages/vue/src/i18n/messages/files.ts@@ -46,6 +46,7 @@ export const filesMessageDefaults = {noMatchingFiles: params('No files match “{query}”.'),documentActions: params('Actions for {name}'),deleteDocument: 'Delete',+ removeFromRecent: 'Remove from recent',deleteDocumentConfirmation: params('Delete “{name}”?'),deleteDocumentDescription:'The document is deleted for everyone who can open it. This can’t be undone.',diff --git a/src/components/home/document/DocumentEntry.vue b/src/components/home/document/DocumentEntry.vueindex e75d1299d..9738ebbea 100644--- a/src/components/home/document/DocumentEntry.vue+++ b/src/components/home/document/DocumentEntry.vue@@ -43,8 +43,11 @@ const {previewURL?: string | nullview?: 'grid' | 'list'disabled?: boolean- /** Labels of the entry's menu, opened from its ⋯ button or by right-clicking; none without them. */- menu?: { actions: string; delete: string }+ /**+ * Labels of the entry's menu, opened from its ⋯ button or by right-clicking; none without them.+ * `destructive: false` marks an item that only takes the entry off a list, such as Recents.+ */+ menu?: { actions: string; delete: string; destructive?: boolean }class?: HTMLAttributes['class']}>()const emit = defineEmits<{ open: []; delete: [] }>()@@ -53,7 +56,12 @@ const { files } = useI18n()const kindLabel = computed(() =>kind ? { design: files.value.createDesign, board: files.value.createBoard }[kind] : null)-const menuUI = useMenuUI({ content: 'min-w-40', item: 'justify-start gap-2 text-error' })+const menuUI = computed(() =>+ useMenuUI({+ content: 'min-w-40',+ item: menu?.destructive === false ? 'justify-start gap-2' : 'justify-start gap-2 text-error'+ })+)</script><template>@@ -123,7 +131,8 @@ const menuUI = useMenuUI({ content: 'min-w-40', item: 'justify-start gap-2 text-data-test-id="home-document-delete"@select="emit('delete')">- <icon-lucide-trash-2 :class="menuUI.icon" />+ <icon-lucide-trash-2 v-if="menu.destructive !== false" :class="menuUI.icon" />+ <icon-lucide-x v-else :class="menuUI.icon" />{{ menu.delete }}</DropdownMenuItem></MenuScrollArea>@@ -135,7 +144,8 @@ const menuUI = useMenuUI({ content: 'min-w-40', item: 'justify-start gap-2 text-<ContextMenuContent :class="menuUI.content"><MenuScrollArea><ContextMenuItem :class="menuUI.item" @select="emit('delete')">- <icon-lucide-trash-2 :class="menuUI.icon" />+ <icon-lucide-trash-2 v-if="menu.destructive !== false" :class="menuUI.icon" />+ <icon-lucide-x v-else :class="menuUI.icon" />{{ menu.delete }}</ContextMenuItem></MenuScrollArea>diff --git a/src/components/home/recent/RecentFilesSection.vue b/src/components/home/recent/RecentFilesSection.vueindex c587a7dc0..1993a583c 100644--- a/src/components/home/recent/RecentFilesSection.vue+++ b/src/components/home/recent/RecentFilesSection.vue@@ -5,11 +5,10 @@ import { useViewportKind } from '@open-pencil/vue/editor/viewport-kind'import { useI18n } from '@open-pencil/vue/i18n'import { useDateFormat } from '@/app/i18n/date'-import { clearRecentFiles, recentDocumentKind, type RecentDocument } from '@/app/recent-files'+import { forgetRecentDocument, recentDocumentKind, type RecentDocument } from '@/app/recent-files'import type { RecentFilesWorkspace } from '@/app/recent-files/workspace'import DocumentEntry from '@/components/home/document/DocumentEntry.vue'import type { DocumentKindFilter } from '@/components/home/document/filter'-import IconButton from '@/components/ui/button/IconButton.vue'import AppSelect from '@/components/ui/select/AppSelect.vue'import SegmentedControl from '@/components/ui/select/SegmentedControl.vue'@@ -27,13 +26,22 @@ const kindOptions = computed(() => [{ value: 'design', label: files.value.createDesign },{ value: 'board', label: files.value.createBoard }])-const { panels, files, common } = useI18n()+const { panels, files } = useI18n()const { isTouch } = useViewportKind()const dates = useDateFormat()const previewURL = workspace.previewURLconst vWorkspacePreview = workspace.previewDirectiveconst hasRecentFiles = computed(() => workspace.documents.value.length > 0)+/** As Figma's Recents: a file leaves the list from its own menu; nothing clears all of it. */+function recentMenu(document: RecentDocument) {+ return {+ actions: files.value.documentActions({ name: document.name }),+ delete: files.value.removeFromRecent,+ destructive: false+ }+}+/** A file's last change; a file that never reported one shows nothing. */function formattedDate(updatedAt: string): string {return Date.parse(updatedAt) === 0 ? '' : dates.format(updatedAt, 'dateTime')@@ -48,15 +56,6 @@ function formattedDate(updatedAt: string): string {<p class="mt-0.5 text-pretty text-xs text-muted">{{ files.recentFilesDescription }}</p></div><div class="col-span-2 flex items-center justify-end gap-1 sm:col-span-1">- <IconButton- v-if="hasRecentFiles"- :label="common.clear"- class="size-10 sm:size-7"- data-test-id="recent-files-clear"- @click="clearRecentFiles"- >- <icon-lucide-trash-2 class="size-3.5" />- </IconButton><AppSelectv-model="kind":label="files.fileKind"@@ -94,7 +93,9 @@ function formattedDate(updatedAt: string): string {:kind="recentDocumentKind(document)":metadata="formattedDate(document.updatedAt)":previewURL="previewURL(document.id)"+ :menu="recentMenu(document)"@open="emit('open', document)"+ @delete="forgetRecentDocument(document.id)"/></div>@@ -106,7 +107,9 @@ function formattedDate(updatedAt: string): string {:name="document.name":kind="recentDocumentKind(document)":metadata="formattedDate(document.updatedAt)"+ :menu="recentMenu(document)"@open="emit('open', document)"+ @delete="forgetRecentDocument(document.id)"/></div>diff --git a/tests/e2e/app/recent-files.spec.ts b/tests/e2e/app/recent-files.spec.tsindex 8dced3b89..01e888e3a 100644--- a/tests/e2e/app/recent-files.spec.ts+++ b/tests/e2e/app/recent-files.spec.ts@@ -33,12 +33,48 @@ test.describe('a populated recent files list', () => {}})+ test('a file leaves Recents from its menu, which keeps no clear-all control', async ({+ page+ }) => {+ await page.goto('/?recent-files')+ await page.getByTestId('recent-files-home').waitFor()+ // As in Figma's Recents, the list has no control that clears all of it.+ await expect(+ page.getByTestId('recent-files-home').getByRole('button', { name: /clear/i })+ ).toHaveCount(0)+ const openButton = (name: RegExp) =>+ page.locator('[data-slot="trigger"]').and(page.getByRole('button', { name }))+ const removed = openButton(/Recent design 0\b/)+ await expect(removed).toHaveCount(1)++ await page.getByRole('button', { name: 'Actions for Recent design 0', exact: true }).click()+ await page.getByRole('menuitem', { name: 'Remove from recent', exact: true }).click()+ await expect(removed).toHaveCount(0)+ await expect(openButton(/Recent design 1\b/)).toHaveCount(1)++ await page.reload()+ await page.getByTestId('recent-files-home').waitFor()+ await expect(openButton(/Recent design 1\b/)).toHaveCount(1)+ await expect(removed).toHaveCount(0)++ // The list view offers the same item, from a right-click as well as the ⋯ button.+ await page.getByRole('button', { name: 'List view', exact: true }).click()+ const listed = openButton(/Recent design 1\b/)+ await listed.click({ button: 'right' })+ await page.getByRole('menuitem', { name: 'Remove from recent', exact: true }).click()+ await expect(listed).toHaveCount(0)+ await expect(openButton(/Recent design 2\b/)).toHaveCount(1)+ })+test('the recent files limit in General settings updates the list and persists', async ({page}) => {await page.goto('/?recent-files')await page.getByTestId('recent-files-home').waitFor()- const documents = page.getByRole('button', { name: /Recent design/ })+ // Each file's open button, not its actions menu.+ const documents = page+ .locator('[data-slot="trigger"]')+ .and(page.getByRole('button', { name: /Recent design/ }))await expect(documents).toHaveCount(10)await page.keyboard.press(process.platform === 'darwin' ? 'Meta+,' : 'Control+,')