From be516a5ea6878c77e42a113ca8750742f08c376b Mon Sep 17 00:00:00 2001 From: Fayaz Ahmed <15716057+fayazara@users.noreply.github.com> Date: Tue, 1 Nov 2022 16:20:09 +0530 Subject: [PATCH] fix: Filename issue while editing a macro with attachment action (#5775) --- .../dashboard/helper/specs/macrosFixtures.js | 23 +++++++++++++++++++ .../helper/specs/macrosHelper.spec.js | 17 +++++++++++++- .../dashboard/i18n/locale/en/automation.json | 2 +- .../dashboard/settings/macros/MacroForm.vue | 7 ++++++ .../dashboard/settings/macros/MacroNode.vue | 5 ++++ .../dashboard/settings/macros/MacroNodes.vue | 18 ++++++++++++++- .../dashboard/settings/macros/macroHelper.js | 9 ++++++++ 7 files changed, 78 insertions(+), 3 deletions(-) diff --git a/app/javascript/dashboard/helper/specs/macrosFixtures.js b/app/javascript/dashboard/helper/specs/macrosFixtures.js index 745168d40..efbcb979c 100644 --- a/app/javascript/dashboard/helper/specs/macrosFixtures.js +++ b/app/javascript/dashboard/helper/specs/macrosFixtures.js @@ -69,3 +69,26 @@ export const labels = [ show_on_sidebar: true, }, ]; + +export const files = [ + { + id: 76, + macro_id: 77, + file_type: 'image/jpeg', + account_id: 1, + file_url: + 'http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBYUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--aa41b5a779a83c1d86b28475a5cf0bd17f41f0ff/fayaz_cropped.jpeg', + blob_id: 88, + filename: 'fayaz_cropped.jpeg', + }, + { + id: 82, + macro_id: 77, + file_type: 'image/png', + account_id: 1, + file_url: + 'http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBZdz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--260fda80b77409ffaaac10b96681fba447600545/screenshot.png', + blob_id: 94, + filename: 'screenshot.png', + }, +]; diff --git a/app/javascript/dashboard/helper/specs/macrosHelper.spec.js b/app/javascript/dashboard/helper/specs/macrosHelper.spec.js index 649eff8c5..a09aa3bc3 100644 --- a/app/javascript/dashboard/helper/specs/macrosHelper.spec.js +++ b/app/javascript/dashboard/helper/specs/macrosHelper.spec.js @@ -3,9 +3,10 @@ import { resolveActionName, resolveLabels, resolveTeamIds, + getFileName, } from '../../routes/dashboard/settings/macros/macroHelper'; import { MACRO_ACTION_TYPES } from '../../routes/dashboard/settings/macros/constants'; -import { teams, labels } from './macrosFixtures'; +import { teams, labels, files } from './macrosFixtures'; describe('#emptyMacro', () => { const defaultMacro = { @@ -50,3 +51,17 @@ describe('#resolveLabels', () => { expect(resolveLabels(labels, ['sales', 'billing'])).toEqual(resolvedLabels); }); }); + +describe('#getFileName', () => { + it('returns the correct file name from the list of files', () => { + expect(getFileName(files[0].blob_id, 'send_attachment', files)).toEqual( + files[0].filename + ); + expect(getFileName(files[1].blob_id, 'send_attachment', files)).toEqual( + files[1].filename + ); + expect(getFileName(files[0].blob_id, 'wrong_action', files)).toEqual(''); + expect(getFileName(null, 'send_attachment', files)).toEqual(''); + expect(getFileName(files[0].blob_id, 'send_attachment', [])).toEqual(''); + }); +}); diff --git a/app/javascript/dashboard/i18n/locale/en/automation.json b/app/javascript/dashboard/i18n/locale/en/automation.json index 5d291814e..e05ecd9ec 100644 --- a/app/javascript/dashboard/i18n/locale/en/automation.json +++ b/app/javascript/dashboard/i18n/locale/en/automation.json @@ -109,7 +109,7 @@ "UPLOAD_ERROR": "Could not upload attachment, Please try again", "LABEL_IDLE": "Upload Attachment", "LABEL_UPLOADING": "Uploading...", - "LABEL_UPLOADED": "Succesfully Uploaded", + "LABEL_UPLOADED": "Successfully Uploaded", "LABEL_UPLOAD_FAILED": "Upload Failed" } } diff --git a/app/javascript/dashboard/routes/dashboard/settings/macros/MacroForm.vue b/app/javascript/dashboard/routes/dashboard/settings/macros/MacroForm.vue index 95db0ed65..fb7d992a2 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/macros/MacroForm.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/macros/MacroForm.vue @@ -3,6 +3,7 @@
[], }, + files: { + type: Array, + default: () => [], + }, }, computed: { actionData: { @@ -61,6 +72,11 @@ export default { }, }, }, + methods: { + fileName() { + return getFileName(...arguments); + }, + }, }; diff --git a/app/javascript/dashboard/routes/dashboard/settings/macros/macroHelper.js b/app/javascript/dashboard/routes/dashboard/settings/macros/macroHelper.js index 584deeb5e..48525ce40 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/macros/macroHelper.js +++ b/app/javascript/dashboard/routes/dashboard/settings/macros/macroHelper.js @@ -31,3 +31,12 @@ export const resolveLabels = (labels, ids) => { }) .join(', '); }; + +export const getFileName = (id, actionType, files) => { + if (!id || !files) return ''; + if (actionType === 'send_attachment') { + const file = files.find(item => item.blob_id === id); + if (file) return file.filename.toString(); + } + return ''; +};