From 2a3983402e9b41c8bd3522b16fab6501585f7498 Mon Sep 17 00:00:00 2001 From: van-go <35277477+van-go@users.noreply.github.com> Date: Wed, 4 Dec 2024 11:52:49 -0600 Subject: [PATCH] Refactor path generation logic in DataFilesFormModal --- .../DataFiles/DataFilesModals/DataFilesFormModal.jsx | 6 +++++- client/src/redux/sagas/_custom/drp.sagas.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/client/src/components/DataFiles/DataFilesModals/DataFilesFormModal.jsx b/client/src/components/DataFiles/DataFilesModals/DataFilesFormModal.jsx index b13617b93..f245c804f 100644 --- a/client/src/components/DataFiles/DataFilesModals/DataFilesFormModal.jsx +++ b/client/src/components/DataFiles/DataFilesModals/DataFilesFormModal.jsx @@ -25,7 +25,11 @@ const DataFilesFormModal = () => { projectUrl = projectUrl.slice(0, -1); } - const path = updatedPath ? `${projectUrl}/${updatedPath}` : projectUrl; + // Avoid appending updatedPath if it's already part of projectUrl + const path = updatedPath && !projectUrl.endsWith(updatedPath) + ? `${projectUrl}/${updatedPath}` + : projectUrl; + history.replace(path); }; diff --git a/client/src/redux/sagas/_custom/drp.sagas.js b/client/src/redux/sagas/_custom/drp.sagas.js index f18b4719c..7a6908d81 100644 --- a/client/src/redux/sagas/_custom/drp.sagas.js +++ b/client/src/redux/sagas/_custom/drp.sagas.js @@ -53,7 +53,7 @@ function* executeOperation( // Check if the file name has changed. If not, keep the same path const reloadPath = isEdit && file.name !== values.name - ? newPath.replace(`/${file.name}`, `/${values.name}`) + ? newPath.replace(new RegExp(`/${file.name}$`), `/${values.name}`) : newPath; yield call(reloadCallback, reloadPath);