Skip to content

Commit

Permalink
fix: Share the displayed folder even from path ending with /
Browse files Browse the repository at this point in the history
  • Loading branch information
cballevre committed Sep 26, 2023
1 parent 04d622f commit 72866c0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/drive/web/modules/drive/Toolbar/share/ShareButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useLocation, useNavigate } from 'react-router-dom'
import { ShareButton } from 'cozy-sharing'

import { useDisplayedFolder } from 'drive/hooks'
import { getPathToShareDisplayedFolder } from 'drive/web/modules/drive/Toolbar/share/helpers'
import styles from './styles.styl'

const ShareButtonWithProps = ({ isDisabled }) => {
Expand All @@ -13,7 +14,7 @@ const ShareButtonWithProps = ({ isDisabled }) => {
const { pathname } = useLocation()

const share = () => {
navigate(`${pathname}/share`)
navigate(getPathToShareDisplayedFolder(pathname))
}

return (
Expand Down
3 changes: 2 additions & 1 deletion src/drive/web/modules/drive/Toolbar/share/ShareItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { ActionMenuItem } from 'cozy-ui/transpiled/react/deprecated/ActionMenu'
import Icon from 'cozy-ui/transpiled/react/Icon'
import ShareIcon from 'cozy-ui/transpiled/react/Icons/Share'

import { getPathToShareDisplayedFolder } from 'drive/web/modules/drive/Toolbar/share/helpers'
import styles from 'drive/styles/toolbar.styl'

const ShareItem = ({ displayedFolder, navigate, pathname }) => {
const { t } = useI18n()

const share = () => {
navigate(`${pathname}/share`)
navigate(getPathToShareDisplayedFolder(pathname))
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { SharedRecipients } from 'cozy-sharing'
import { useLocation, useNavigate } from 'react-router-dom'

import { useDisplayedFolder } from 'drive/hooks'
import { getPathToShareDisplayedFolder } from 'drive/web/modules/drive/Toolbar/share/helpers'

const SharedRecipientsComponent = () => {
const displayedFolder = useDisplayedFolder()
const navigate = useNavigate()
const { pathname } = useLocation()

const share = () => {
navigate(`${pathname}/share`)
navigate(getPathToShareDisplayedFolder(pathname))
}

return (
Expand Down
8 changes: 8 additions & 0 deletions src/drive/web/modules/drive/Toolbar/share/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Get the path to share the displayed folder
* @param {string} pathname Current path
* @returns Next path
*/
export function getPathToShareDisplayedFolder(pathname) {
return `${pathname}${pathname.endsWith('/') ? '' : '/'}share`
}
15 changes: 15 additions & 0 deletions src/drive/web/modules/drive/Toolbar/share/helpers.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getPathToShareDisplayedFolder } from 'drive/web/modules/drive/Toolbar/share/helpers'

describe('getPathToShareDisplayedFolder', () => {
it('should return path to displayed folder share modal', () => {
expect(getPathToShareDisplayedFolder('/path/to/folder/123')).toBe(
'/path/to/folder/123/share'
)
})

it('should return correct path if pathname ends with /', () => {
expect(getPathToShareDisplayedFolder('/path/to/folder/123/')).toBe(
'/path/to/folder/123/share'
)
})
})

0 comments on commit 72866c0

Please sign in to comment.