From b563fb48c8485733176806c7a76291f13062f96c Mon Sep 17 00:00:00 2001 From: melohagan <101575380+melohagan@users.noreply.github.com> Date: Mon, 19 Feb 2024 11:09:36 +0000 Subject: [PATCH] Error when deleting selected rows that have attachment (#13063) * Deprecate selectedRowIds * Delete selected rows table * Add selectedRows to table block context * update account-portal * update account-portal * Lowercase deprecated * Make sure attachment fields are empty arrays not null * unit test --- packages/server/src/utilities/rowProcessor/attachments.ts | 3 +++ .../src/utilities/rowProcessor/tests/attachments.spec.ts | 8 ++++++++ yarn.lock | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/server/src/utilities/rowProcessor/attachments.ts b/packages/server/src/utilities/rowProcessor/attachments.ts index 799eab1d3a..c289680eb3 100644 --- a/packages/server/src/utilities/rowProcessor/attachments.ts +++ b/packages/server/src/utilities/rowProcessor/attachments.ts @@ -72,6 +72,9 @@ export class AttachmentCleanup { continue } rows.forEach(row => { + if (!Array.isArray(row[key])) { + return + } files = files.concat( row[key].map((attachment: any) => attachment.key) ) diff --git a/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts b/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts index 762ec3bb8c..43af79d82c 100644 --- a/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts +++ b/packages/server/src/utilities/rowProcessor/tests/attachments.spec.ts @@ -103,6 +103,14 @@ describe("attachment cleanup", () => { expect(mockedDeleteFiles).toBeCalledWith(BUCKET, [FILE_NAME]) }) + it("should handle row deletion and not throw when attachments are undefined", async () => { + await AttachmentCleanup.rowDelete(table(), [ + { + attach: undefined, + }, + ]) + }) + it("shouldn't cleanup attachments if row not updated", async () => { await AttachmentCleanup.rowUpdate(table(), { row: row(), oldRow: row() }) expect(mockedDeleteFiles).not.toBeCalled() diff --git a/yarn.lock b/yarn.lock index c0a11b9bf7..10acc829b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10763,7 +10763,7 @@ fetch-cookie@0.11.0: dependencies: tough-cookie "^2.3.3 || ^3.0.1 || ^4.0.0" -fflate@^0.4.1, fflate@^0.4.8: +fflate@^0.4.1: version "0.4.8" resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.4.8.tgz#f90b82aefbd8ac174213abb338bd7ef848f0f5ae" integrity sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==