From bf205e149e10cbcbcf5f69a279cbae6effd71c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Poizat?= Date: Wed, 25 Jan 2023 10:10:50 +0100 Subject: [PATCH] feat(Viewer): Add componentsProps and support OnlyOfficeViewer inside onlyOfficeProps is now deprecated --- react/Viewer/Readme.md | 17 +++++++++++------ react/Viewer/Viewer.jsx | 16 ++++++++++++++-- react/Viewer/ViewerContainer.jsx | 12 +++++++++++- react/Viewer/components/ViewerByFile.jsx | 22 ++++++++++++++++++---- 4 files changed, 54 insertions(+), 13 deletions(-) diff --git a/react/Viewer/Readme.md b/react/Viewer/Readme.md index 6d09553a2e..5c3c8b2540 100644 --- a/react/Viewer/Readme.md +++ b/react/Viewer/Readme.md @@ -23,7 +23,7 @@ The `Viewer` can display an **information panel** to show additional information * **showClose** : `` – Whether to show close button in toolbar * **showNavigation** : `` – Whether to show left and right arrows to navigate between files * **renderFallbackExtraContent** : `` – A render prop that is called when a file can't be displayed -* **onlyOfficeProps** : `` – Used to open an Only Office file +* **onlyOfficeProps** : `` – Used to open an Only Office file (deprecated) * **disablePanel** : `` – Show/Hide the panel containing more information about the file only on Desktop * **disableFooter** : `` – Show/Hide the panel containing more information about the file only on Phone & Tablet devices * **editPathByModelProps** : `` – Edit path by model properties @@ -31,7 +31,10 @@ The `Viewer` can display an **information panel** to show additional information * **page** : `` – URL used to edit the file when editing a `page` type metadata (side of the document) * **onChangeRequest** : `` - Called with (nextFile, nextIndex) when the user requests to navigate to another file * **onCloseRequest** : `` - Called when the user wants to leave the Viewer - +* **componentsProps** : `` – Props passed to components with the same name + * **OnlyOfficeViewer** : `` – Used to open an Only Office file + * **isEnabled** : `` – Whether Only Office is enabled on the server + * **opener** : `` – To open the Only Office file ### Demo ```jsx @@ -209,16 +212,18 @@ const editPathByModelProps = { currentURL={state.currentURL} showNavigation={variant.navigation} editPathByModelProps={editPathByModelProps} - onlyOfficeProps={{ - isEnabled: variant.onlyOfficeEnabled, - opener: () => alert('This is a demo, no Only Office opener here') - }} toolbarProps={{ showToolbar: variant.toolbar, showClose: state.showToolbarCloseButton }} onCloseRequest={toggleViewer} onChangeRequest={onFileChange} + componentsProps={{ + OnlyOfficeViewer: { + isEnabled: variant.onlyOfficeEnabled, + opener: () => alert('This is a demo, no Only Office opener here') + } + }} > diff --git a/react/Viewer/Viewer.jsx b/react/Viewer/Viewer.jsx index f95a03bbdf..b6c11664bc 100644 --- a/react/Viewer/Viewer.jsx +++ b/react/Viewer/Viewer.jsx @@ -71,7 +71,8 @@ class Viewer extends Component { showNavigation, renderFallbackExtraContent, validForPanel, - onlyOfficeProps + onlyOfficeProps, + componentsProps } = this.props // this `expanded` property makes the next/previous controls cover the displayed image @@ -96,6 +97,7 @@ class Viewer extends Component { onClose={this.onClose} renderFallbackExtraContent={renderFallbackExtraContent} onlyOfficeProps={onlyOfficeProps} + componentsProps={componentsProps} /> @@ -125,7 +127,17 @@ Viewer.propTypes = { /** To open the Only Office file */ opener: PropTypes.func }), - validForPanel: PropTypes.bool + validForPanel: PropTypes.bool, + /* Props passed to components with the same name */ + componentsProps: PropTypes.shape({ + /** Used to open an Only Office file */ + OnlyOfficeViewer: PropTypes.shape({ + /** Whether Only Office is enabled on the server */ + isEnabled: PropTypes.bool, + /** To open the Only Office file */ + opener: PropTypes.func + }) + }) } export default Viewer diff --git a/react/Viewer/ViewerContainer.jsx b/react/Viewer/ViewerContainer.jsx index b513c1fb02..a2fb0f47bf 100644 --- a/react/Viewer/ViewerContainer.jsx +++ b/react/Viewer/ViewerContainer.jsx @@ -102,7 +102,17 @@ ViewerContainer.propTypes = { /** Show/Hide the panel containing more information about the file only on Desktop */ disablePanel: PropTypes.bool, /** Show/Hide the panel containing more information about the file only on Phone & Tablet devices */ - disableFooter: PropTypes.bool + disableFooter: PropTypes.bool, + /* Props passed to components with the same name */ + componentsProps: PropTypes.shape({ + /** Used to open an Only Office file */ + OnlyOfficeViewer: PropTypes.shape({ + /** Whether Only Office is enabled on the server */ + isEnabled: PropTypes.bool, + /** To open the Only Office file */ + opener: PropTypes.func + }) + }) } ViewerContainer.defaultProps = { diff --git a/react/Viewer/components/ViewerByFile.jsx b/react/Viewer/components/ViewerByFile.jsx index 51128b64dd..d74a3203fb 100644 --- a/react/Viewer/components/ViewerByFile.jsx +++ b/react/Viewer/components/ViewerByFile.jsx @@ -19,6 +19,10 @@ import OnlyOfficeViewer from '../ViewersByFile/OnlyOfficeViewer' import { useEncrypted } from '../providers/EncryptedProvider' +import createDepreciationLogger from '../../helpers/createDepreciationLogger' + +const logDepecratedOnlyOfficeProps = createDepreciationLogger() + const { isPlainText } = models.file export const getViewerComponentName = ({ @@ -60,10 +64,19 @@ const ViewerByFile = ({ gesturesRef, onSwipe, onlyOfficeProps, - breakpoints: { isDesktop } + breakpoints: { isDesktop }, + componentsProps }) => { - const isOnlyOfficeEnabled = onlyOfficeProps && onlyOfficeProps.isEnabled - const onlyOfficeOpener = onlyOfficeProps && onlyOfficeProps.opener + if (onlyOfficeProps) { + logDepecratedOnlyOfficeProps( + 'onlyOfficeProps in Viewer is deprecated. Please use componentsProps.OnlyOfficeViewer instead.' + ) + } + + const isOnlyOfficeEnabled = + componentsProps?.OnlyOfficeViewer?.isEnabled || onlyOfficeProps?.isEnabled + const onlyOfficeOpener = + componentsProps?.OnlyOfficeViewer?.opener || onlyOfficeProps?.opener const { url } = useEncrypted() @@ -99,7 +112,8 @@ ViewerByFile.propTypes = { // gestures, gesturesRef and onSwipe are got from ViewerControls gestures: PropTypes.object, gesturesRef: PropTypes.object, - onSwipe: PropTypes.func + onSwipe: PropTypes.func, + componentsProps: PropTypes.object } export default withBreakpoints()(ViewerByFile)