Skip to content

Commit

Permalink
BUG Use more resilient method to manipulate URL of preview (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Rainville committed Dec 20, 2019
1 parent da1d990 commit 1d7a0b7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions client/src/components/HistoryViewer/HistoryViewerVersionDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import FormBuilderLoader from 'containers/FormBuilderLoader/FormBuilderLoader';
import { inject } from 'lib/Injector';
import { versionType } from 'types/versionType';
import PropTypes from 'prop-types';
import url from 'url';
import qs from 'qs';

class HistoryViewerVersionDetail extends PureComponent {
componentWillMount() {
Expand Down Expand Up @@ -89,25 +91,31 @@ class HistoryViewerVersionDetail extends PureComponent {
* @returns {Preview|null}
*/
renderPreview() {
const { version, PreviewComponent, previewState } = this.props;
const {
version: { AbsoluteLink, LastEdited, Version },
PreviewComponent,
previewState
} = this.props;

// Don't render the preview if the view mode is "edit"
if (!this.isPreviewable() || previewState === 'edit') {
return null;
}

// Build HREF for the preview
const parsedURL = url.parse(AbsoluteLink);
const parsedQs = qs.parse(parsedURL.query);
parsedQs.archiveDate = LastEdited;
const href = url.format({ ...parsedURL, search: qs.stringify(parsedQs) });
return (
<PreviewComponent
className="history-viewer__preview flexbox-area-grow" // removes default: fill-height
itemLinks={{
preview: {
Stage: {
href: `${version.AbsoluteLink}&archiveDate=${version.LastEdited}`,
type: 'text/html',
},
Stage: { href, type: 'text/html' },
},
}}
itemId={version.Version}
itemId={Version}
/>
);
}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
],
"require": {
"silverstripe/admin": "^1.3",
"silverstripe/admin": "^1.6",
"silverstripe/framework": "^4.3",
"silverstripe/versioned": "^1.3",
"silverstripe/graphql": "^2.0 || ^3.0",
Expand Down Expand Up @@ -48,4 +48,4 @@
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"devDependencies": {
"@silverstripe/eslint-config": "0.0.5",
"@silverstripe/webpack-config": "^1.3.0",
"@silverstripe/webpack-config": "^1.4.0",
"@storybook/addon-actions": "^3.4.11",
"@storybook/addons": "^3.4.11",
"@storybook/react": "^3.4.11",
Expand All @@ -72,6 +72,7 @@
"moment": "^2.21.0",
"popper.js": "^1.14.4",
"prop-types": "^15.6.2",
"qs": "^6.1.0",
"react": "^16.6.1",
"react-apollo": "^2.1.11",
"react-dom": "^16.6.1",
Expand All @@ -80,6 +81,7 @@
"react-router-redux": "^4.0.5",
"reactstrap": "^6.4.0",
"redux": "^3.3.1",
"url": "^0.11.0",
"uuid": "^3.2.1"
},
"babel": {
Expand Down
13 changes: 9 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
eslint-plugin-jsx-a11y "^5.1.1"
eslint-plugin-react "^7.3.0"

"@silverstripe/webpack-config@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@silverstripe/webpack-config/-/webpack-config-1.3.0.tgz#66b122202b659bd59f1d13e0df0e54a150d216b4"
integrity sha512-YJcS4BSICzHGUSwA+uK4V4vPx4UJw6wDJ18xwMJ8mWkKED5YJeUeIWjFi2xAGvmohDD2mtenphHJDMO9wXRBCA==
"@silverstripe/webpack-config@^1.4.0":
version "1.4.0"
resolved "https://registry.yarnpkg.com/@silverstripe/webpack-config/-/webpack-config-1.4.0.tgz#c26727f73a70ed588af9379129b16c56258d669e"
integrity sha512-6itUELU8mCx2h4xmRV1p7tlnhylG7bzbo4/ZDlBob+r2Twln99yffx7cx7v9kyqkYyp+APz89ti/9HQEpSvAig==
dependencies:
autoprefixer "^6.4.0"
babel-core "^6.24.1"
Expand Down Expand Up @@ -9464,6 +9464,11 @@ qs@6.7.0:
resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc"
integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==

qs@^6.1.0:
version "6.9.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.1.tgz#20082c65cb78223635ab1a9eaca8875a29bf8ec9"
integrity sha512-Cxm7/SS/y/Z3MHWSxXb8lIFqgqBowP5JMlTUFyJN88y0SGQhVmZnqFK/PeuMX9LzUyWsqqhNxIyg0jlzq946yA==

qs@^6.5.1:
version "6.9.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.0.tgz#d1297e2a049c53119cb49cca366adbbacc80b409"
Expand Down

0 comments on commit 1d7a0b7

Please sign in to comment.