Skip to content

Commit

Permalink
Refactor reloadPage function to simplify path handling in DataFilesFo…
Browse files Browse the repository at this point in the history
…rmModal
  • Loading branch information
van-go committed Jan 6, 2025
1 parent 117b4f9 commit f72eb9c
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down

0 comments on commit f72eb9c

Please sign in to comment.