From 521e02d33f47f1df6e6969b6da424cb2ef1ca574 Mon Sep 17 00:00:00 2001 From: Mike <36415632+Mike-Heneghan@users.noreply.github.com> Date: Mon, 13 Nov 2023 17:25:56 +0000 Subject: [PATCH] fix: bug with file requirements not changing on delete of file (#2417) * fix: resolve bug where deleting a file didn't remove label - Reinstate the `merge` which updates state directly - This isn't best practice but does show how the bug started happening * refactor: update the remove method to avoid direct state update - Create a clone of fileList before removing the file - Remove the file and update state with the setter --- .../src/@planx/components/FileUploadAndLabel/Public.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/editor.planx.uk/src/@planx/components/FileUploadAndLabel/Public.tsx b/editor.planx.uk/src/@planx/components/FileUploadAndLabel/Public.tsx index 87decf9a4e..e11537ca0e 100644 --- a/editor.planx.uk/src/@planx/components/FileUploadAndLabel/Public.tsx +++ b/editor.planx.uk/src/@planx/components/FileUploadAndLabel/Public.tsx @@ -240,11 +240,12 @@ function Component(props: Props) { ), ); setFileUploadStatus(`${slot.file.path} was deleted`); - removeSlots( + const updatedFileList = removeSlots( getTagsForSlot(slot.id, fileList), slot, fileList, ); + setFileList(updatedFileList); }} /> );