From d7caf08d1fa4f0ab5e28a6a9ec70bc15a129549f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sun, 8 Mar 2026 10:47:49 +0800 Subject: [PATCH] Fix design file metadata mapping in files store Co-Authored-By: Codex --- src/stores/files.ts | 9 ++++++--- tests/stores/files.test.js | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/stores/files.ts b/src/stores/files.ts index f92e8e6..eaa2a51 100644 --- a/src/stores/files.ts +++ b/src/stores/files.ts @@ -91,15 +91,16 @@ export const useFilesStore = defineStore('filesStore', { */ async fetchAllFiles() { const api = '/api/files'; - let icon = ''; - let fileType = ''; - let parentLog = ''; try { const response = await apiClient.get(api); this.allEventFiles = response.data; this.allEventFiles.forEach(o => { + let icon = ''; + let fileType = ''; + let parentLog = o.name; + switch (o.type) { case 'log': icon = 'work_history'; @@ -119,6 +120,8 @@ export const useFilesStore = defineStore('filesStore', { break; case 'design': icon = 'shape_line'; + fileType = 'Design'; + parentLog = o.name; break; } o.icon = icon; diff --git a/tests/stores/files.test.js b/tests/stores/files.test.js index 6c10211..9ac4d21 100644 --- a/tests/stores/files.test.js +++ b/tests/stores/files.test.js @@ -105,6 +105,33 @@ describe('filesStore', () => { mockGet.mockRejectedValue(new Error('Network error')); await expect(store.fetchAllFiles()).resolves.toBeUndefined(); }); + + it('maps design files without leaking metadata from previous file items', async () => { + mockGet.mockResolvedValue({ + data: [ + { + type: 'log', + name: 'order-log', + owner: { name: 'Alice' }, + updated_at: '2024-01-15T10:00:00Z', + accessed_at: null, + }, + { + type: 'design', + name: 'diagram-a', + owner: { name: 'Bob' }, + updated_at: '2024-01-16T10:00:00Z', + accessed_at: null, + }, + ], + }); + + await store.fetchAllFiles(); + + expect(store.allEventFiles[1].icon).toBe('shape_line'); + expect(store.allEventFiles[1].fileType).toBe('Design'); + expect(store.allEventFiles[1].parentLog).toBe('diagram-a'); + }); }); describe('upload', () => {