Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Share the displayed folder even from path ending with / #2993

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
)
})
})
Loading