diff --git a/src/elements/content-preview/ContentPreview.js b/src/elements/content-preview/ContentPreview.js index 51d15e5109..9e6ade8101 100644 --- a/src/elements/content-preview/ContentPreview.js +++ b/src/elements/content-preview/ContentPreview.js @@ -144,6 +144,7 @@ type Props = { logoUrl?: string, measureRef: Function, messages?: StringMap, + comparedPanel?: React.Node, onAnnotator: Function, onAnnotatorEvent: Function, onBeforeNavigate?: (targetFileId: string) => boolean | Promise, @@ -1018,6 +1019,7 @@ class ContentPreview extends React.PureComponent { enableBoundingBoxHighlights, features, fileOptions, + comparedPanel, onAnnotatorEvent, onAnnotator, onContentInsightsEventReport, @@ -1375,6 +1377,10 @@ class ContentPreview extends React.PureComponent { * @return {void} */ navigateLeft = () => { + if (this.props.comparedPanel !== undefined) { + return; + } + const currentIndex = this.getFileIndex(); const newIndex = currentIndex === 0 ? 0 : currentIndex - 1; if (newIndex !== currentIndex) { @@ -1389,7 +1395,11 @@ class ContentPreview extends React.PureComponent { * @return {void} */ navigateRight = () => { - const { collection }: Props = this.props; + const { collection, comparedPanel }: Props = this.props; + if (comparedPanel !== undefined) { + return; + } + const currentIndex = this.getFileIndex(); const newIndex = currentIndex === collection.length - 1 ? collection.length - 1 : currentIndex + 1; if (newIndex !== currentIndex) { @@ -1465,7 +1475,7 @@ class ContentPreview extends React.PureComponent { * @return {void} */ onKeyDown = (event: SyntheticKeyboardEvent) => { - const { useHotkeys, renderCustomPreview }: Props = this.props; + const { comparedPanel, useHotkeys, renderCustomPreview }: Props = this.props; // Skip ContentPreview hotkeys when custom content is provided to prevent conflicts. // Custom components must implement their own keyboard shortcuts (arrow navigation, etc) @@ -1491,12 +1501,16 @@ class ContentPreview extends React.PureComponent { if (!consumed) { switch (key) { case 'ArrowLeft': - this.navigateLeft(); - consumed = true; + if (comparedPanel === undefined) { + this.navigateLeft(); + consumed = true; + } break; case 'ArrowRight': - this.navigateRight(); - consumed = true; + if (comparedPanel === undefined) { + this.navigateRight(); + consumed = true; + } break; default: // no-op @@ -1671,6 +1685,7 @@ class ContentPreview extends React.PureComponent { hasHeader, hasProviders, hideSidebar, + comparedPanel, history, isLarge, isVeryLarge, @@ -1729,6 +1744,7 @@ class ContentPreview extends React.PureComponent { const currentVersionId = getProp(file, 'file_version.id'); const selectedVersionId = getProp(selectedVersion, 'id', currentVersionId); const onHeaderClose = currentVersionId === selectedVersionId ? onClose : this.updateVersionToCurrent; + const isComparedPanelMode = comparedPanel !== undefined; /* eslint-disable jsx-a11y/no-static-element-interactions */ /* eslint-disable jsx-a11y/no-noninteractive-tabindex */ @@ -1761,7 +1777,12 @@ class ContentPreview extends React.PureComponent { selectedVersion={selectedVersion} /> )} -
+
{ isLoading={isLoading} isLoadingDeferred={isLoadingDeferred} /> - + {!isComparedPanelMode && ( + + )}
+ {comparedPanel} {file && !hideSidebar && ( { }); }); + describe('comparedPanel prop', () => { + const collection = ['123', '456', '789']; + const comparedPanel =
compared pane
; + + test('should render comparedPanel between the viewer and sidebar', () => { + const wrapper = getWrapper({ + fileId: '123', + comparedPanel, + }); + wrapper.setState({ + currentFileId: '123', + file: { id: '123', name: 'test.pdf' }, + }); + + const bodyDiv = wrapper.find('.bcpr-body'); + expect(bodyDiv.hasClass('bcpr-body--with-compared-panel')).toBe(true); + expect(bodyDiv.children().length).toBe(3); + expect(bodyDiv.children().at(0).hasClass('bcpr-container')).toBe(true); + expect(bodyDiv.children().at(1).hasClass('compared-panel-content')).toBe(true); + }); + + test('should not add the compared-panel body class when comparedPanel is omitted', () => { + const wrapper = getWrapper({ + fileId: '123', + }); + wrapper.setState({ + currentFileId: '123', + file: { id: '123', name: 'test.pdf' }, + }); + + const bodyDiv = wrapper.find('.bcpr-body'); + expect(bodyDiv.hasClass('bcpr-body--with-compared-panel')).toBe(false); + expect(bodyDiv.children().length).toBe(2); + }); + + test('should not render PreviewNavigation when comparedPanel is provided', () => { + const wrapper = getWrapper({ + fileId: '456', + collection, + comparedPanel, + }); + wrapper.setState({ + currentFileId: '456', + file: { id: '456', name: 'test.pdf' }, + }); + + expect(wrapper.find('PreviewNavigation').exists()).toBe(false); + }); + + test('should not render PreviewNavigation when comparedPanel is null', () => { + const wrapper = getWrapper({ + fileId: '456', + collection, + comparedPanel: null, + }); + wrapper.setState({ + currentFileId: '456', + file: { id: '456', name: 'test.pdf' }, + }); + + expect(wrapper.find('PreviewNavigation').exists()).toBe(false); + }); + + test('should render PreviewNavigation when comparedPanel is omitted', () => { + const wrapper = getWrapper({ + fileId: '456', + collection, + }); + wrapper.setState({ + currentFileId: '456', + file: { id: '456', name: 'test.pdf' }, + }); + + expect(wrapper.find('PreviewNavigation').exists()).toBe(true); + }); + + test('should not navigate when comparedPanel is provided', () => { + const wrapper = getWrapper({ + fileId: '456', + collection, + comparedPanel, + }); + wrapper.setState({ currentFileId: '456' }); + const instance = wrapper.instance(); + instance.navigateToIndex = jest.fn(); + + instance.navigateLeft(); + instance.navigateRight(); + + expect(instance.navigateToIndex).not.toHaveBeenCalled(); + }); + }); + describe('npm preview load path (useNpmBoxContentPreview)', () => { const createPreviewModule = () => ({ Preview: function Preview() {