From 0345f4983eaafb4273d4b403e7ac714d342e66f5 Mon Sep 17 00:00:00 2001 From: Sanja Date: Fri, 25 Oct 2024 09:52:20 -0700 Subject: [PATCH] Implement file fetching logic when a value is present --- src/components/renderer/file-upload.vue | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/components/renderer/file-upload.vue b/src/components/renderer/file-upload.vue index 1a3acf22a..c7d43f134 100644 --- a/src/components/renderer/file-upload.vue +++ b/src/components/renderer/file-upload.vue @@ -99,6 +99,10 @@ export default { this.removeDefaultClasses(); }, mounted() { + if (this.value) { + this.fetchFiles(); + } + this.$root.$on('set-upload-data-name', (recordList, index, id) => this.listenRecordList(recordList, index, id)); @@ -621,6 +625,28 @@ export default { : null; } }, + async fetchFiles() { + const fileIds = Array.isArray(this.value) ? this.value : [this.value]; + + const fetchPromises = fileIds.map(async (file) => { + const id = file?.file ?? file; + const endpoint = `files/${id}`; + try { + const response = await ProcessMaker.apiClient.get(endpoint); + if (response?.data) { + const fileExists = this.files.some(existingFile => existingFile.id === response.data.id); + // Check if the file already exists in the list before adding it. + if (!fileExists) { + this.files.push(response.data); + } + } + } catch (error) { + console.error(`Failed to fetch file ${id}`, error); + } + }); + + return await Promise.all(fetchPromises); + }, }, };