Skip to content

Commit

Permalink
feat: Upgrade cozy-viewer & cozy-sharing and apply BC
Browse files Browse the repository at this point in the history
And remove `HOME_LINK_HREF`,
the same link is now provided by `useSharingInfos`.
  • Loading branch information
Merkur39 committed Jan 27, 2025
1 parent d4879f1 commit 270f037
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 43 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@
"cozy-minilog": "3.9.1",
"cozy-realtime": "4.6.0",
"cozy-scripts": "^8.4.0",
"cozy-sharing": "^20.0.0",
"cozy-sharing": "^21.1.0",
"cozy-stack-client": "^52.0.0",
"cozy-ui": "^116.0.0",
"cozy-viewer": "^13.3.1",
"cozy-viewer": "^15.0.0",
"date-fns": "2.30.0",
"diacritics": "1.3.0",
"filesize": "10.1.6",
Expand Down
5 changes: 3 additions & 2 deletions src/components/Button/CozyHomeLink.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import PropTypes from 'prop-types'
import React from 'react'

import { useSharingInfos } from 'cozy-sharing'
import { ButtonLink, useI18n } from 'cozy-ui/transpiled/react'

import CozyHomeLinkIcon from 'components/Button/CozyHomeLinkIcon'
import { HOME_LINK_HREF } from 'constants/config'

const CozyHomeLink = ({ className }) => {
const { t } = useI18n()
const { createCozyLink } = useSharingInfos
return (
<ButtonLink
label={t('Share.create-cozy')}
icon={CozyHomeLinkIcon}
className={className}
href={HOME_LINK_HREF}
href={createCozyLink}
size="normal"
/>
)
Expand Down
1 change: 0 additions & 1 deletion src/constants/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ export const APPS_DIR_PATH = '/.cozy_apps'
export const TRASH_DIR_PATH = '/.cozy_trash'
export const KONNECTORS_DIR_PATH = '/.cozy_konnectors'
export const FILES_FETCH_LIMIT = 100
export const HOME_LINK_HREF = 'https://manager.cozycloud.cc/cozy/create'
export const MAX_PAYLOAD_SIZE_IN_GB = 5
export const MAX_PAYLOAD_SIZE = MAX_PAYLOAD_SIZE_IN_GB * 1024 * 1024 * 1024
4 changes: 2 additions & 2 deletions src/modules/public/LightFileViewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const LightFileViewer = ({ files, isPublic }) => {
const { isDesktop, isMobile } = useBreakpoints()
const { pathname } = useLocation()
const navigate = useNavigate()
const { loading, isSharingShortcutCreated, discoveryLink } = sharingInfos
const { loading, isSharingShortcutCreated, addSharingLink } = sharingInfos

const onlyOfficeOpener = useCallback(
file => {
Expand Down Expand Up @@ -82,7 +82,7 @@ const LightFileViewer = ({ files, isPublic }) => {
<FooterActionButtons>
{isAddToMyCozyDisplayed && (
<OpenSharingLinkButton
link={discoveryLink}
link={addSharingLink}
isSharingShortcutCreated={isSharingShortcutCreated}
isShortLabel
fullWidth
Expand Down
4 changes: 2 additions & 2 deletions src/modules/public/LightFileViewer.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jest.mock('cozy-intent', () => ({
useWebviewIntent: () => ({ call: () => {} })
}))
jest.mock('cozy-ui/transpiled/react/providers/Breakpoints', () => ({
...jest.requireActual('cozy-ui/transpiled/react/providers/Breakpoints'),
__esModule: true,
default: jest.fn(),
BreakpointsProvider: ({ children }) => children
default: jest.fn()
}))
// used inside cozy-viewer
jest.mock('cozy-client/dist/models/permission', () => ({
Expand Down
4 changes: 2 additions & 2 deletions src/modules/public/PublicToolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const PublicToolbar = ({
sharingInfos,
className
}) => {
const { loading, discoveryLink } = sharingInfos
const { loading, addSharingLink } = sharingInfos

if (loading) return null
return (
<div
className={cx('u-flex u-flex-justify-end', className)}
data-testid="public-toolbar"
>
{!discoveryLink ? (
{!addSharingLink ? (
<PublicToolbarByLink
files={files}
hasWriteAccess={hasWriteAccess}
Expand Down
8 changes: 4 additions & 4 deletions src/modules/public/PublicToolbarByLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import React from 'react'

import { useClient } from 'cozy-client'
import { useVaultClient } from 'cozy-keys-lib'
import { openSharingLink } from 'cozy-sharing'
import { createCozySharingLink, useSharingInfos } from 'cozy-sharing'
import { makeActions } from 'cozy-ui/transpiled/react/ActionsMenu/Actions'
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert'
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'

import { BarRightOnMobile } from 'components/Bar'
import { HOME_LINK_HREF } from 'constants/config'
import { addItems, download, hr, select } from 'modules/actions'
import AddMenuProvider from 'modules/drive/AddMenu/AddMenuProvider'
import AddButton from 'modules/drive/Toolbar/components/AddButton'
Expand All @@ -30,6 +29,7 @@ const PublicToolbarByLink = ({
const { showAlert } = useAlert()
const client = useClient()
const vaultClient = useVaultClient()
const { createCozyLink } = useSharingInfos()

const isMoreMenuDisplayed = files.length > 1

Expand All @@ -39,15 +39,15 @@ const PublicToolbarByLink = ({
files.length > 1 && select,
addItems,
isMobile && (files.length > 1 || hasWriteAccess) && hr,
isMobile && openSharingLink
isMobile && createCozySharingLink
],
{
t,
showAlert,
client,
vaultClient,
showSelectionBar,
link: HOME_LINK_HREF,
createCozyLink,
hasWriteAccess
}
)
Expand Down
23 changes: 17 additions & 6 deletions src/modules/public/PublicToolbarCozyToCozy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import React from 'react'

import { useClient } from 'cozy-client'
import { useVaultClient } from 'cozy-keys-lib'
import { openSharingLink, OpenSharingLinkButton } from 'cozy-sharing'
import {
addToCozySharingLink,
syncToCozySharingLink,
OpenSharingLinkButton
} from 'cozy-sharing'
import { makeActions } from 'cozy-ui/transpiled/react/ActionsMenu/Actions'
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert'
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints'
Expand All @@ -17,8 +21,13 @@ import PublicToolbarMoreMenu from 'modules/public/PublicToolbarMoreMenu'
import { useSelectionContext } from 'modules/selection/SelectionProvider'

const PublicToolbarCozyToCozy = ({ sharingInfos, files }) => {
const { loading, discoveryLink, sharing, isSharingShortcutCreated } =
sharingInfos
const {
loading,
addSharingLink,
syncSharingLink,
sharing,
isSharingShortcutCreated
} = sharingInfos
const { isMobile } = useBreakpoints()
const { t } = useI18n()
const { showAlert } = useAlert()
Expand All @@ -37,7 +46,8 @@ const PublicToolbarCozyToCozy = ({ sharingInfos, files }) => {
isMobile && download,
files.length > 1 && select,
((isMobile && files.length > 0) || files.length > 1) && hr,
isOnSharedFolder && openSharingLink
isOnSharedFolder && addToCozySharingLink,
isOnSharedFolder && syncToCozySharingLink
],
{
t,
Expand All @@ -46,7 +56,8 @@ const PublicToolbarCozyToCozy = ({ sharingInfos, files }) => {
vaultClient,
showSelectionBar,
isSharingShortcutCreated,
link: discoveryLink
addSharingLink,
syncSharingLink
}
)

Expand All @@ -56,7 +67,7 @@ const PublicToolbarCozyToCozy = ({ sharingInfos, files }) => {
{!isMobile && !isSharingShortcutCreated && isOnSharedFolder && (
<OpenSharingLinkButton
className="u-ml-half"
link={discoveryLink}
link={addSharingLink}
isSharingShortcutCreated={isSharingShortcutCreated}
/>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/views/OnlyOffice/Title.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Title = () => {
<SharingBannerPlugin />
) : null}
{isAddToMyCozyFabDisplayed && (
<OpenSharingLinkFabButton link={sharingInfos.discoveryLink} />
<OpenSharingLinkFabButton link={sharingInfos.addSharingLink} />
)}
</div>
)
Expand Down
41 changes: 31 additions & 10 deletions src/modules/views/OnlyOffice/Toolbar/index.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React from 'react'

import { openSharingLink, OpenSharingLinkButton } from 'cozy-sharing'
import {
addToCozySharingLink,
createCozySharingLink,
syncToCozySharingLink,
OpenSharingLinkButton
} from 'cozy-sharing'
import { makeActions } from 'cozy-ui/transpiled/react/ActionsMenu/Actions'
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'

import FilesRealTimeQueries from 'components/FilesRealTimeQueries'
import { HOME_LINK_HREF } from 'constants/config'
import { useRedirectLink } from 'hooks/useRedirectLink'
import PublicToolbarMoreMenu from 'modules/public/PublicToolbarMoreMenu'
import { useOnlyOfficeContext } from 'modules/views/OnlyOffice/OnlyOfficeProvider'
Expand All @@ -23,7 +27,13 @@ const Toolbar = ({ sharingInfos }) => {
const { isMobile } = useBreakpoints()
const { t } = useI18n()
const { fileId, isPublic, isEditorReady } = useOnlyOfficeContext()
const { discoveryLink, isSharingShortcutCreated, loading } = sharingInfos
const {
addSharingLink,
syncSharingLink,
createCozyLink,
isSharingShortcutCreated,
loading
} = sharingInfos

const { data: fileWithPath } = useFileWithPath(fileId)
const { redirectBack, canRedirect } = useRedirectLink({ isPublic })
Expand All @@ -35,14 +45,25 @@ const Toolbar = ({ sharingInfos }) => {
}
// Check if the share shortcut has not yet been added
const isShareNotAdded = !loading && !isSharingShortcutCreated
// Check if you are sharing Cozy to Cozy (Link sharing is on the `/public` route)
const isCozyToCozySharing = window.location.pathname === '/preview'

// discoveryLink exists only in cozy to cozy sharing
const link = discoveryLink || HOME_LINK_HREF
const actions = makeActions([openSharingLink], {
t,
link,
isSharingShortcutCreated
})
// addSharingLink exists only in cozy to cozy sharing
const link = isCozyToCozySharing ? addSharingLink : createCozyLink
const actions = makeActions(
[
!isCozyToCozySharing && createCozySharingLink,
isCozyToCozySharing && addToCozySharingLink,
isCozyToCozySharing && syncToCozySharingLink
],
{
t,
addSharingLink,
syncSharingLink,
createCozyLink,
isSharingShortcutCreated
}
)

return (
<>
Expand Down
5 changes: 3 additions & 2 deletions src/modules/views/OnlyOffice/Toolbar/index.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ client.collection = () => ({
})
})
const defaultSharingInfos = {
discoveryLink: '',
addSharingLink: '',
isSharingShortcutCreated: false,
loading: false
loading: false,
createCozyLink: 'http://cozy.tools'
}
const setup = ({
isReadOnly = false,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/views/Public/PublicFolderView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ const PublicFolderView = () => {
</AddMenuProvider>
)}
{isAddToMyCozyFabDisplayed && (
<OpenSharingLinkFabButton link={sharingInfos.discoveryLink} />
<OpenSharingLinkFabButton link={sharingInfos.addSharingLink} />
)}
<Outlet />
</Content>
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6658,10 +6658,10 @@ cozy-scripts@^8.4.0:
webpack-dev-server "3.10.3"
webpack-merge "4.2.2"

cozy-sharing@^20.0.0:
version "20.0.0"
resolved "https://registry.yarnpkg.com/cozy-sharing/-/cozy-sharing-20.0.0.tgz#75e8da9ba586e5246ab61a492cef5ca76a2a2018"
integrity sha512-fq9ah106L+BFsr8BuGLMw1JNjqieYaDA4y/AHMvt2UbuDUGOkwGJ/evhedastPaxJY0faga+HkKNNX4TzNqo8A==
cozy-sharing@^21.1.0:
version "21.1.0"
resolved "https://registry.yarnpkg.com/cozy-sharing/-/cozy-sharing-21.1.0.tgz#20d371a6fbc307255b452c1d1446cc478b777c03"
integrity sha512-hnAvoNRsyapOdDO6OgkUCLbhRviBUq2kPCtgY5q8fIsMCmZkrUTsbNcuLKti6jOxFRv3qSLxgzvacHA+6AoJ0g==
dependencies:
"@cozy/minilog" "^1.0.0"
classnames "^2.2.6"
Expand Down Expand Up @@ -6746,10 +6746,10 @@ cozy-ui@^116.0.0:
react-swipeable-views "^0.13.3"
rooks "^5.11.2"

cozy-viewer@^13.3.1:
version "13.3.1"
resolved "https://registry.yarnpkg.com/cozy-viewer/-/cozy-viewer-13.3.1.tgz#a4043ffe96f66c89b995068afb8437f2a9d1f5f2"
integrity sha512-uE0zy/RlxLmShejszZY677WQtVA/rk8RoHacX6eRTeuLjl8U5nqoHKEylvVtPACV7jH8o3WIw9ZdrZkcQDX7JA==
cozy-viewer@^15.0.0:
version "15.0.0"
resolved "https://registry.yarnpkg.com/cozy-viewer/-/cozy-viewer-15.0.0.tgz#e28b731015f845a38112ae3883e0d7cad05b4058"
integrity sha512-Sbj0ycKVU0N4uCmsP5b6hRS1PubPjn+qaoCiXXiHun44xNv07js05nyuqok8Eup5Q/EdJvE1XKAzEoEQZLtS1w==
dependencies:
classnames "^2.2.5"
hammerjs "^2.0.8"
Expand Down

0 comments on commit 270f037

Please sign in to comment.