diff --git a/client/src/components/DataFiles/DataFilesModals/DataFilesFormModal.jsx b/client/src/components/DataFiles/DataFilesModals/DataFilesFormModal.jsx index 29b5be8e6..f454eac98 100644 --- a/client/src/components/DataFiles/DataFilesModals/DataFilesFormModal.jsx +++ b/client/src/components/DataFiles/DataFilesModals/DataFilesFormModal.jsx @@ -15,18 +15,21 @@ const DataFilesFormModal = () => { const history = useHistory(); const location = useLocation(); - const reloadPage = (updatedPath = '') => { - // Updated regex to capture the URL up until the last project segment + const reloadPage = (updatedPath = '') => { let projectUrl = location.pathname.replace( - /(\/projects\/[^/]+\/[^/]+)\/?.*/, + /(\/projects\/[^/]+\/[^/]+\/?.*)/, '$1' ); - + if (projectUrl.endsWith('/')) { projectUrl = projectUrl.slice(0, -1); } - - const path = updatedPath ? `${projectUrl}/${updatedPath}` : `${projectUrl}`; + + // Replace the last segment with the updatedPath + const path = updatedPath + ? projectUrl.replace(/[^/]+$/, updatedPath).replace(/\/\//g, '/') + : 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 dee4f5f24..d84bff65b 100644 --- a/client/src/redux/sagas/_custom/drp.sagas.js +++ b/client/src/redux/sagas/_custom/drp.sagas.js @@ -50,9 +50,10 @@ function* executeOperation( ? `${path}/${file.path.split('/').pop()}` : path; + // 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);