Skip to content

Commit

Permalink
NEW: GraphQL 4 Compatibility (#184)
Browse files Browse the repository at this point in the history
* Begin JS refactor

* New graphql 3 compat

* Clean up travis

* Add BC tests

* Fix cms version

* behat debug

* Fix version casing

* Build, add behat delays

* Fix versionFrom/to

* Replace tests
  • Loading branch information
Aaron Carlino authored Nov 12, 2020
1 parent 6839d04 commit 721403f
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 138 deletions.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ matrix:
env: DB=MYSQL PHPUNIT_TEST=1 COMPOSER_ARG=--prefer-lowest
- php: 7.1
env: DB=PGSQL PHPUNIT_TEST=1
- php: 7.1
env: DB=PGSQL PHPUNIT_TEST=1 BACKWARD_COMPAT=1
- php: 7.2
env: DB=MYSQL PHPUNIT_TEST=1
- php: 7.3
env: DB=MYSQL PDO=1 PHPUNIT_COVERAGE_TEST=1
- php: 7.3
env: DB=MYSQL PDO=1 PHPUNIT_COVERAGE_TEST=1 BACKWARD_COMPAT=1
- php: 7.3
env: DB=MYSQL BEHAT_TEST=1
- php: 7.3
env: DB=MYSQL BEHAT_TEST=1 BACKWARD_COMPAT=1
- php: 7.4
env: DB=MYSQL PHPUNIT_TEST=1 PHPCS_TEST=1
- php: 7.4
Expand All @@ -55,6 +61,12 @@ before_script:
- composer validate
- if [[ $DB == PGSQL ]]; then composer require --prefer-dist --no-update silverstripe/postgresql:2.x-dev; fi
- composer require --no-update silverstripe/recipe-testing:^1 silverstripe/recipe-cms:4.x-dev

######## Remove once GraphQL 4 is merged #########
- composer require silverstripe/cms:"dev-pulls/4/schemageddon as 4.x-dev" silverstripe/admin:"dev-pulls/1/schemageddon as 1.x-dev" silverstripe/asset-admin:"dev-pulls/1/schemageddon as 1.x-dev" silverstripe/versioned:"dev-pulls/1/schemageddon as 1.x-dev" silverstripe/graphql:"4.x-dev as 3.x-dev" --no-update
- 'if [[ $BACKWARD_COMPAT ]]; then composer require silverstripe/graphql:"dev-pulls/3/schemageddon-compat as 3.x-dev" --no-update; fi'
##################################################

- composer update --prefer-source $COMPOSER_ARG

# Remove preinstalled Chrome (google-chrome)
Expand Down
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

31 changes: 14 additions & 17 deletions client/src/components/HistoryViewer/HistoryViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ class HistoryViewer extends Component {
*/
getVersions() {
const { versions } = this.props;
const edges = (versions && versions.Versions && versions.Versions.edges)
? versions.Versions.edges
return (versions && versions.versions && versions.versions.nodes)
? versions.versions.nodes
: [];
return edges.map((version) => version.node);
}

/**
Expand Down Expand Up @@ -107,13 +106,13 @@ class HistoryViewer extends Component {
const { currentVersion } = this.props;

// Check whether the "current version" (in the store) is the latest draft
if (currentVersion && currentVersion.LatestDraftVersion === true) {
if (currentVersion && currentVersion.latestDraftVersion === true) {
return currentVersion;
}

// Look for one in the list of available versions
const latestDraftVersion = this.getVersions()
.filter(version => version.LatestDraftVersion === true);
.filter(version => version.latestDraftVersion === true);

if (latestDraftVersion.length) {
return latestDraftVersion[0];
Expand Down Expand Up @@ -216,13 +215,13 @@ class HistoryViewer extends Component {
const schemaVersionReplacements = {
':id': recordId,
':class': recordClass,
':version': currentVersion.Version,
':version': currentVersion.version,
};
const schemaCompareReplacements = {
':id': recordId,
':class': recordClass,
':from': versionFrom.Version || 0,
':to': versionTo.Version || 0,
':from': versionFrom.version || 0,
':to': versionTo.version || 0,
};
const schemaSearch = compare ? /:id|:class|:from|:to/g : /:id|:class|:version/g;
const schemaReplacements = compare ? schemaCompareReplacements : schemaVersionReplacements;
Expand All @@ -232,7 +231,7 @@ class HistoryViewer extends Component {

const props = {
// comparison shows two versions as one, so by nature cannot be a single 'latest' version.
isLatestVersion: !compare && latestVersion && latestVersion.Version === version.Version,
isLatestVersion: !compare && latestVersion && latestVersion.version === version.version,
isPreviewable,
recordId,
schemaUrl: schemaUrl.replace(schemaSearch, (match) => schemaReplacements[match]),
Expand Down Expand Up @@ -268,8 +267,8 @@ class HistoryViewer extends Component {
return null;
}

const totalVersions = versions.Versions
? versions.Versions.pageInfo.totalCount
const totalVersions = versions.versions
? versions.versions.pageInfo.totalCount
: 0;

if (totalVersions <= limit) {
Expand Down Expand Up @@ -399,13 +398,11 @@ HistoryViewer.propTypes = {
VersionDetailComponent: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
CompareWarningComponent: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
versions: PropTypes.shape({
Versions: PropTypes.shape({
versions: PropTypes.shape({
pageInfo: PropTypes.shape({
totalCount: PropTypes.number,
}),
edges: PropTypes.arrayOf(PropTypes.shape({
node: versionType,
})),
nodes: PropTypes.arrayOf(versionType),
}),
}),
page: PropTypes.number,
Expand All @@ -427,11 +424,11 @@ HistoryViewer.defaultProps = {
isPreviewable: false,
schemaUrl: '',
versions: {
Versions: {
versions: {
pageInfo: {
totalCount: 0,
},
edges: [],
nodes: [],
},
},
};
Expand Down
16 changes: 8 additions & 8 deletions client/src/components/HistoryViewer/HistoryViewerVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ class HistoryViewerVersion extends Component {
const { version } = this.props;
let member = {};

if (version.Published && version.Publisher) {
member = version.Publisher;
} else if (version.Author) {
member = version.Author;
if (version.published && version.publisher) {
member = version.publisher;
} else if (version.author) {
member = version.author;
}

return `${member.FirstName || ''} ${member.Surname || ''}`;
return `${member.firstName || ''} ${member.surname || ''}`;
}

/**
Expand Down Expand Up @@ -96,7 +96,7 @@ class HistoryViewerVersion extends Component {
*/
handleClose() {
const { onSelect, version, compare, compare: { versionFrom } } = this.props;
if (versionFrom && versionFrom.Version === version.Version) {
if (versionFrom && versionFrom.version === version.version) {
// Ensures we set the correct thing. C.f. logic in mapDispatchToProps -> onSelect
delete compare.versionFrom;
}
Expand Down Expand Up @@ -220,7 +220,7 @@ class HistoryViewerVersion extends Component {
tabIndex={0}
>
<span className="history-viewer__version-no" role="cell">
{version.Version}
{version.version}
</span>
<StateComponent
version={version}
Expand Down Expand Up @@ -290,7 +290,7 @@ export default compose(
({ version }) => {
let context = 'VersionedAdmin.HistoryViewer.HistoryViewerVersion';
if (version) {
context += `.${version.Version}`;
context += `.${version.version}`;
}
return context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class HistoryViewerVersionDetail extends PureComponent {
*/
renderPreview() {
const {
version: { AbsoluteLink, LastEdited, Version },
version: { absoluteLink, lastEdited, version },
PreviewComponent,
previewState
} = this.props;
Expand All @@ -103,9 +103,9 @@ class HistoryViewerVersionDetail extends PureComponent {
}

// Build HREF for the preview
const parsedURL = url.parse(AbsoluteLink);
const parsedURL = url.parse(absoluteLink);
const parsedQs = qs.parse(parsedURL.query);
parsedQs.archiveDate = LastEdited;
parsedQs.archiveDate = lastEdited;
const href = url.format({ ...parsedURL, search: qs.stringify(parsedQs) });
return (
<PreviewComponent
Expand All @@ -115,7 +115,7 @@ class HistoryViewerVersionDetail extends PureComponent {
Stage: { href, type: 'text/html' },
},
}}
itemId={Version}
itemId={version}
/>
);
}
Expand All @@ -137,7 +137,7 @@ class HistoryViewerVersionDetail extends PureComponent {
identifier="HistoryViewer.VersionDetail.Toolbar"
isLatestVersion={isLatestVersion}
recordId={recordId}
versionId={version.Version}
versionId={version.version}
isPreviewable={this.isPreviewable()}
/>
);
Expand Down Expand Up @@ -178,7 +178,6 @@ class HistoryViewerVersionDetail extends PureComponent {
'history-viewer__version-detail': true,
'history-viewer__version-detail--compare': this.isCompareMode(),
};

return (
<div className="flexbox-area-grow fill-height">
<CompareWarningComponent fixed />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class HistoryViewerVersionList extends PureComponent {
isVersionActive(version) {
const { currentVersion, compare, compare: { versionFrom, versionTo } } = this.props;

const isCurrent = currentVersion && currentVersion.Version === version.Version;
const isCompareFrom = versionFrom && versionFrom.Version === version.Version;
const isCompareTo = versionTo && versionTo.Version === version.Version;
const isCurrent = currentVersion && currentVersion.version === version.version;
const isCompareFrom = versionFrom && versionFrom.version === version.version;
const isCompareTo = versionTo && versionTo.version === version.version;

return (!compare && isCurrent) || isCompareFrom || isCompareTo;
}
Expand Down Expand Up @@ -109,7 +109,7 @@ class HistoryViewerVersionList extends PureComponent {
{
versions.map((version) => (
<VersionComponent
key={version.Version}
key={version.version}
isActive={this.isVersionActive(version)}
version={version}
compare={compare}
Expand Down
12 changes: 6 additions & 6 deletions client/src/components/HistoryViewer/HistoryViewerVersionState.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class HistoryViewerVersionState extends Component {
getPublishedState() {
const { version } = this.props;

if (version.Version === 1) {
if (version.version === 1) {
return i18n._t('HistoryViewer.Created', 'Created');
}

if (version.Published) {
if (version.Deleted) {
if (version.Draft) {
if (version.published) {
if (version.deleted) {
if (version.draft) {
return i18n._t('HistoryViewer.Archived', 'Archived');
}
return i18n._t('HistoryViewer.Unpublished', 'Unpublished');
Expand All @@ -50,7 +50,7 @@ class HistoryViewerVersionState extends Component {
*/
getDate() {
moment.locale(i18n.detectLocale());
return moment(this.props.version.LastEdited).format('L LT');
return moment(this.props.version.lastEdited).format('L LT');
}

/**
Expand All @@ -61,7 +61,7 @@ class HistoryViewerVersionState extends Component {
getBadges() {
const { version, isActive, BadgeComponent } = this.props;

if (version.LiveVersion) {
if (version.liveVersion) {
return (
<BadgeComponent
status="success"
Expand Down
Loading

0 comments on commit 721403f

Please sign in to comment.