Skip to content

Commit

Permalink
Refactor path generation logic in DataFilesFormModal and executeOpera…
Browse files Browse the repository at this point in the history
…tion function in drp.sagas.js
  • Loading branch information
van-go committed Dec 4, 2024
1 parent 2a39834 commit 27dd865
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ const DataFilesFormModal = () => {
/(\/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;
const path =
updatedPath && !projectUrl.endsWith(updatedPath)
? `${projectUrl}/${updatedPath}`
: projectUrl;

history.replace(path);
};

const { form, selectedFile, formName, additionalData, useReloadCallback } =
useSelector((state) => state.files.modalProps.dynamicform);
const isOpen = useSelector((state) => state.files.modals.dynamicform);
Expand Down
4 changes: 2 additions & 2 deletions client/src/redux/sagas/_custom/drp.sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ function* executeOperation(
isEdit && file.path === params.path
? `${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(new RegExp(`/${file.name}$`), `/${values.name}`)
: newPath;

yield call(reloadCallback, reloadPath);
}

Expand Down

0 comments on commit 27dd865

Please sign in to comment.