Skip to content

Commit

Permalink
fix: Remove scenario where sharingModal lose state
Browse files Browse the repository at this point in the history
fetchFilesPaths would return wrong filePaths for directories
This would trigger a cascading rerender scenario,
creating a side effect where the SharingModal would end up thinking
it has no sharedChild, rendering the wrong view
and allowing mistakingly the user to share the parent of a shared dir
If a document is a directory
we directly use its path
  • Loading branch information
acezard committed Mar 1, 2024
1 parent 6b0ee53 commit 43e583a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/cozy-sharing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"prepublishOnly": "yarn build",
"test": "env NODE_ENV=test jest --env=jest-environment-jsdom-sixteen",
"lint": "cd .. && yarn eslint --ext js,jsx packages/cozy-sharing",
"watch": "yarn build --watch",
"start": "yarn build --watch",
"watch": "yarn run start",
"watch:doc:react": "(cd ../.. && TARGET=cozy-sharing yarn watch:doc:react)"
},
"dependencies": {
Expand Down
9 changes: 9 additions & 0 deletions packages/cozy-sharing/src/helpers/files.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* Fetches the file paths for the given files.
* Should not be used for directories.
*
* @param {Object} client - The cozy-client instance.
* @param {string} doctype - The type of document.
* @param {Array} files - The array of files.
* @returns {Promise<Array>} - The array of file paths.
*/
export const fetchFilesPaths = async (client, doctype, files) => {
const parentDirIds = files
.map(f => f.dir_id)
Expand Down
4 changes: 4 additions & 0 deletions packages/cozy-sharing/src/hooks/useFetchDocumentPath.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const useFetchDocumentPath = (client, document) => {
useEffect(() => {
;(async () => {
try {
const isDirectory = document.type === 'directory'

if (isDirectory) return setDocumentPath(document.path)

const path = await fetchFilesPaths(client, document._type, [document])
setDocumentPath(path[0])
// eslint-disable-next-line
Expand Down

0 comments on commit 43e583a

Please sign in to comment.