From f72eb9cc88cb8829e40fec2621bf704afff088bd Mon Sep 17 00:00:00 2001 From: van-go <35277477+van-go@users.noreply.github.com> Date: Mon, 6 Jan 2025 14:33:26 -0600 Subject: [PATCH] Refactor reloadPage function to simplify path handling in DataFilesFormModal --- .../DataFilesModals/DataFilesFormModal.jsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/client/src/components/DataFiles/DataFilesModals/DataFilesFormModal.jsx b/client/src/components/DataFiles/DataFilesModals/DataFilesFormModal.jsx index dcf830a75..f454eac98 100644 --- a/client/src/components/DataFiles/DataFilesModals/DataFilesFormModal.jsx +++ b/client/src/components/DataFiles/DataFilesModals/DataFilesFormModal.jsx @@ -15,22 +15,21 @@ const DataFilesFormModal = () => { const history = useHistory(); const location = useLocation(); - const reloadPage = (updatedPath = '') => { + const reloadPage = (updatedPath = '') => { let projectUrl = location.pathname.replace( /(\/projects\/[^/]+\/[^/]+\/?.*)/, '$1' ); - + if (projectUrl.endsWith('/')) { projectUrl = projectUrl.slice(0, -1); } - - // Avoid appending updatedPath if it's already part of projectUrl - const path = - updatedPath && !projectUrl.endsWith(updatedPath) - ? `${projectUrl}/${updatedPath}` - : projectUrl; - + + // Replace the last segment with the updatedPath + const path = updatedPath + ? projectUrl.replace(/[^/]+$/, updatedPath).replace(/\/\//g, '/') + : projectUrl; + history.replace(path); };