From 34b0fbccc4751a103c6dd589b828be885dd20a48 Mon Sep 17 00:00:00 2001 From: Sanja Date: Fri, 25 Oct 2024 10:26:43 -0700 Subject: [PATCH] Implement file fetching logic when a value is present --- src/components/renderer/file-upload.vue | 28 ++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/components/renderer/file-upload.vue b/src/components/renderer/file-upload.vue index ceeb00bb7..a9a209a6b 100644 --- a/src/components/renderer/file-upload.vue +++ b/src/components/renderer/file-upload.vue @@ -158,6 +158,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)); @@ -699,7 +703,29 @@ export default { }, cfSkipFileUpload() { this.$emit('cf-skip-file-upload'); - } + }, + 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); + }, }, };