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(OO): The edit button must be displayed for OO shares with write access #3315

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions src/modules/views/OnlyOffice/Title.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import { useSearchParams } from 'react-router-dom'

import { SharingBannerPlugin, OpenSharingLinkFabButton } from 'cozy-sharing'
import { useSharingInfos } from 'cozy-sharing'
Expand All @@ -20,6 +21,7 @@ const useStyles = makeStyles(theme => ({
}))

const Title = () => {
const [searchParams] = useSearchParams(window.location.search)
const { isMobile } = useBreakpoints()
const { fileId, isPublic, isEditorModeView, isTrashed } =
useOnlyOfficeContext()
Expand All @@ -30,15 +32,19 @@ const Title = () => {
// Check if the sharing shortcut has already been created (but not synced)
const isShareAlreadyAdded = !loading && isSharingShortcutCreated
// Check if you are sharing Cozy to Cozy (Link sharing is on the `/public` route)
const isPreview = window.location.pathname === '/preview'
const isCozyToCozySharing = window.location.pathname === '/preview'
// Check if you are sharing Cozy to Cozy synced (Also on the `/public` route)
const isCozyToCozySharingSynced = searchParams.has('username')
// Show the sharing banner plugin only on shared links view and cozy to cozy sharing view(not added)
const isSharingBannerPluginDisplayed =
isPublic && (!isShareAlreadyAdded || !isPreview)
isPublic &&
(!isShareAlreadyAdded || !isCozyToCozySharing) &&
!isCozyToCozySharingSynced

const showDialogToolbar = isEditorModeView || !isMobile

const isAddToMyCozyFabDisplayed =
isMobile && isPreview && !isShareAlreadyAdded
isMobile && isCozyToCozySharing && !isShareAlreadyAdded

return (
<div style={{ zIndex: 'var(--zIndex-nav)' }}>
Expand Down
15 changes: 6 additions & 9 deletions src/modules/views/OnlyOffice/Toolbar/EditButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import LightbulbIcon from 'cozy-ui/transpiled/react/Icons/Lightbulb'
import RenameIcon from 'cozy-ui/transpiled/react/Icons/Rename'
import Tooltip from 'cozy-ui/transpiled/react/Tooltip'
import Typography from 'cozy-ui/transpiled/react/Typography'
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
import { makeStyles } from 'cozy-ui/transpiled/react/styles'

Expand Down Expand Up @@ -109,21 +108,19 @@ const EditButton = ({ openTooltip }) => {
}

const EditButtonWrapper = () => {
const { isMobile } = useBreakpoints()
const { editorMode } = useOnlyOfficeContext()
const { isEditorModeView, isPublic } = useOnlyOfficeContext()

const { data: settings, ...appSettingsQueryResult } = useQuery(
getAppSettingQuery.definition,
getAppSettingQuery.options
{ ...getAppSettingQuery.options, enabled: !isPublic }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

je serai plutôt pour faire un wrapper qui va tester si on est public ou non, et selon, retourner un composant (sans requête) ou un autre (avec requête). On évite maintenant de conditionner les requêtes.

Copy link
Member Author

@Merkur39 Merkur39 Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On évite maintenant de conditionner les requêtes

Ah ? Je n'avais plus ça en tête, je pensais les problème liés réglés 🤔
C'est assez dommage de multiplier les wrapper pour remplacer un attribut totalement légitime.

)
const hideOOEditTooltip = settings?.[0]?.hideOOEditTooltip
const openTooltip = isQueryLoading(appSettingsQueryResult)
? false
: !hideOOEditTooltip && editorMode === 'view' && canWriteOfficeDocument()

if (isMobile) {
return null
}
: !isPublic &&
!hideOOEditTooltip &&
isEditorModeView &&
canWriteOfficeDocument()

return <EditButton openTooltip={openTooltip} />
}
Expand Down
23 changes: 20 additions & 3 deletions src/modules/views/OnlyOffice/Toolbar/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import { useSearchParams } from 'react-router-dom'

import {
addToCozySharingLink,
Expand All @@ -22,12 +23,15 @@ import HomeIcon from 'modules/views/OnlyOffice/Toolbar/HomeIcon'
import HomeLinker from 'modules/views/OnlyOffice/Toolbar/HomeLinker'
import Separator from 'modules/views/OnlyOffice/Toolbar/Separator'
import Sharing from 'modules/views/OnlyOffice/Toolbar/Sharing'
import { isOfficeEditingEnabled } from 'modules/views/OnlyOffice/helpers'
import { useFileWithPath } from 'modules/views/hooks'

const Toolbar = ({ sharingInfos }) => {
const { isMobile } = useBreakpoints()
const { isMobile, isDesktop } = useBreakpoints()
const [searchParams] = useSearchParams(window.location.search)
const { isEditorReady, isReadOnly, isTrashed, fileId, isPublic } =
useOnlyOfficeContext()
const { t } = useI18n()
const { fileId, isPublic, isEditorReady } = useOnlyOfficeContext()
const {
addSharingLink,
syncSharingLink,
Expand All @@ -48,6 +52,8 @@ const Toolbar = ({ sharingInfos }) => {
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'
// Check if you are sharing Cozy to Cozy synced (Also on the `/public` route)
const isCozyToCozySharingSynced = searchParams.has('username')

// addSharingLink exists only in cozy to cozy sharing
const link = isCozyToCozySharing ? addSharingLink : createCozyLink
Expand All @@ -65,6 +71,15 @@ const Toolbar = ({ sharingInfos }) => {
isSharingShortcutCreated
}
)
const showEditButton =
!isMobile &&
isEditorReady &&
!isReadOnly &&
!isTrashed &&
isOfficeEditingEnabled(isDesktop)

const showSharingLinkButton =
isPublic && !isMobile && isShareNotAdded && !isCozyToCozySharingSynced

return (
<>
Expand All @@ -88,12 +103,14 @@ const Toolbar = ({ sharingInfos }) => {
)}
<FileName fileWithPath={fileWithPath} isPublic={isPublic} />
</div>
{isPublic && !isMobile && isShareNotAdded && (
{showSharingLinkButton && (
<OpenSharingLinkButton
link={link}
isSharingShortcutCreated={isSharingShortcutCreated}
variant={showEditButton ? 'secondary' : 'primary'}
/>
)}
{showEditButton && <EditButton />}

{isPublic && (
<PublicToolbarMoreMenu files={[fileWithPath]} actions={actions} />
Expand Down
Loading