Skip to content

Commit

Permalink
NEW: GraphQL 4 compat (#63)
Browse files Browse the repository at this point in the history
* NEW GraphQL 3.5.0 compat

Changed field names to lowercase for forwards compat with GraphQL v4

* NEW GraphQL v4 support

* ESLint fixes

* It's working

Co-authored-by: Ingo Schommer <[email protected]>
  • Loading branch information
Aaron Carlino and chillu authored Jun 24, 2021
1 parent 0dd2a12 commit 990fde3
Show file tree
Hide file tree
Showing 33 changed files with 451 additions and 459 deletions.
25 changes: 25 additions & 0 deletions _config/graphql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
Name: versioned-snapshot-admin-graphql
---
SilverStripe\GraphQL\Schema\Schema:
schemas:
admin:
src:
- 'silverstripe/versioned-snapshot-admin: _graphql'
SilverStripe\Core\Injector\Injector:
SilverStripe\GraphQL\Schema\Registry\PluginRegistry:
constructor:
- 'SilverStripe\SnapshotAdmin\SnapshotHistoryPlugin'

---
Name: versioned-snapshot-admin-sitetree
Only:
moduleexists: silverstripe/cms
---
SilverStripe\GraphQL\Schema\Schema:
schemas:
admin:
models:
SilverStripe\CMS\Model\SiteTree:
fields:
className: true
20 changes: 20 additions & 0 deletions _graphql/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
config:
modelConfig:
DataObject:
plugins:
snapshotHistory: true
models:
SilverStripe\Security\Member:
fields:
firstName: true
surname: true
enums:
SnapshotActivityType:
values:
- ADDED
- CREATED
- DELETED
- MODIFIED
- PUBLISHED
- UNPUBLISHED
- REMOVED
8 changes: 1 addition & 7 deletions client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/js/bundle.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions client/dist/styles/bundle.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css.map

Large diffs are not rendered by default.

48 changes: 23 additions & 25 deletions client/src/components/HistoryViewer/HistoryViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,23 @@ class HistoryViewer extends Component {
*/
getVersions() {
const { versions } = this.props;
const edges = (versions && versions.SnapshotHistory && versions.SnapshotHistory.edges)
? versions.SnapshotHistory.edges
const nodes = (versions && versions.snapshotHistory && versions.snapshotHistory.nodes)
? versions.snapshotHistory.nodes
: [];
return edges.map(({ node }) => {
return {
return nodes.map(node => ({
...node,
...node.OriginVersion,
...node.originVersion,
// Snapshots author is authoritative
Author: {
...node.Author
author: {
...node.author
},
AbsoluteLink: (node.IsFullVersion && node.OriginVersion)
? node.OriginVersion.AbsoluteLink
: versions.AbsoluteLink,
Version: node.IsFullVersion && node.OriginVersion
? node.OriginVersion.Version
: node.BaseVersion,
}
});
absoluteLink: (node.isFullVersion && node.originVersion)
? node.originVersion.absoluteLink
: versions.absoluteLink,
version: node.isFullVersion && node.originVersion
? node.originVersion.version
: node.baseVersion,
}));
}

/**
Expand All @@ -120,13 +118,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 @@ -236,13 +234,13 @@ class HistoryViewer extends Component {

// Currently previewMode === MODE_VERSION is disabled as it displays incorrect relations.

schemaVersionReplacements[':date'] = currentVersion.LastEdited;
schemaVersionReplacements[':date'] = currentVersion.lastEdited;

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|:date/g;
const schemaReplacements = compare ? schemaCompareReplacements : schemaVersionReplacements;
Expand All @@ -251,7 +249,7 @@ class HistoryViewer extends Component {
const latestVersion = this.getLatestVersion();
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,
typeName,
Expand Down Expand Up @@ -288,8 +286,8 @@ class HistoryViewer extends Component {
return null;
}

const totalVersions = versions.SnapshotHistory
? versions.SnapshotHistory.pageInfo.totalCount
const totalVersions = versions.snapshotHistory
? versions.snapshotHistory.pageInfo.totalCount
: 0;

if (totalVersions <= limit) {
Expand Down Expand Up @@ -419,7 +417,7 @@ 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,
}),
Expand Down Expand Up @@ -448,7 +446,7 @@ HistoryViewer.defaultProps = {
typeName: '',
schemaUrl: '',
versions: {
Versions: {
versions: {
pageInfo: {
totalCount: 0,
},
Expand Down
10 changes: 5 additions & 5 deletions client/src/components/HistoryViewer/HistoryViewerSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ class HistoryViewerSnapshot extends Component {

render() {
const { version, StateComponent, FormActionComponent, isComparing, isActive } = this.props;
const { Author: { FirstName, Surname } } = version;
const author = `${FirstName || ''} ${Surname || ''}`;
const { author: { firstName, surname } } = version;
const author = `${firstName || ''} ${surname || ''}`;
const rowTitle = i18n._t('HistoryViewerSnapshot.GO_TO_SNAPSHOT', 'Go to snapshot at {date}');

return (
<li className={this.getClassNames()} role="row">
<span
className="history-viewer__version-link"
role="button"
title={i18n.inject(rowTitle, { date: version.LastEdited })}
title={i18n.inject(rowTitle, { date: version.lastEdited })}
onClick={this.handleClick}
onKeyUp={this.handleKeyUp}
tabIndex={isComparing ? -1 : 0}
>
<span className="history-viewer__message" role="cell">
<span>{version.ActivityAgo}</span>
<span>{version.activityAgo}</span>
{' '}
<small className="text-muted">{getDateFromVersion(version)}</small>
</span>
Expand Down Expand Up @@ -116,7 +116,7 @@ HistoryViewerSnapshot.propTypes = {
function mapDispatchToProps(dispatch) {
return {
onSelect(selectedVersion) {
const func = selectedVersion.IsFullVersion ? showVersion : showDate;
const func = selectedVersion.isFullVersion ? showVersion : showDate;
dispatch(func(selectedVersion));
dispatch(clearMessages());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component as VersionedState } from './HistoryViewerVersionState';
import { inject } from 'lib/Injector';
import React from 'react';

class HistoryViewerSnapshotState extends VersionedState {
translateType(type) {
Expand All @@ -25,14 +26,15 @@ class HistoryViewerSnapshotState extends VersionedState {
}

getPublishedState() {
const { ActivityDescription, ActivityType } = this.props.version;
const { activityDescription, activityType } = this.props.version;

const prefix = this.translateType(ActivityType);
const lines = ActivityDescription.split('\n');
const prefix = this.translateType(activityType);
const lines = activityDescription.split('\n');
if (lines.length > 1) {
// eslint-disable-next-line react/no-array-index-key
return lines.map((l, i) => <div key={i}>{l}</div>);
}
return `${prefix} ${ActivityDescription}`;
return `${prefix} ${activityDescription}`;
}

getBadges() {
Expand Down
56 changes: 27 additions & 29 deletions client/src/components/HistoryViewer/HistoryViewerToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class HistoryViewerToolbar extends Component {
return rollback({ variables: {
id: recordId,
toVersion: versionId
}}).then(() => handler(versionId));
} }).then(() => handler(versionId));
}

handleToggleRevertTooltip() {
Expand Down Expand Up @@ -63,41 +63,39 @@ class HistoryViewerToolbar extends Component {

return (
<RollbackMutation typeName={typeName}>
{(rollback) => {
return (
<div className="toolbar toolbar--south">
<div className="btn-toolbar">
<FormActionComponent
id="HistoryRevertButton"
onClick={() => this.handleRevert(rollback)}
icon="back-in-time"
name="revert"
attributes={{
{(rollback) => (
<div className="toolbar toolbar--south">
<div className="btn-toolbar">
<FormActionComponent
id="HistoryRevertButton"
onClick={() => this.handleRevert(rollback)}
icon="back-in-time"
name="revert"
attributes={{
title: revertButtonTitle,
}}
data={{
data={{
buttonStyle: 'warning'
}}
disabled={isLatestVersion || isReverting || !canRollback}
loading={isReverting}
title={i18n._t('HistoryViewerToolbar.REVERT_TO_VERSION', 'Revert to this version')}
/>
{ !canRollback && (
<Tooltip
trigger="click hover focus"
placement="top"
isOpen={revertTooltipOpen}
toggle={this.handleToggleRevertTooltip}
target="HistoryRevertButton"
>
{rollbackMessage}
</Tooltip>
disabled={isLatestVersion || isReverting || !canRollback}
loading={isReverting}
title={i18n._t('HistoryViewerToolbar.REVERT_TO_VERSION', 'Revert to this version')}
/>
{ !canRollback && (
<Tooltip
trigger="click hover focus"
placement="top"
isOpen={revertTooltipOpen}
toggle={this.handleToggleRevertTooltip}
target="HistoryRevertButton"
>
{rollbackMessage}
</Tooltip>
)}
{ isPreviewable && <ViewModeComponent id="history-viewer-edit-mode" area="edit" /> }
{ isPreviewable && <ViewModeComponent id="history-viewer-edit-mode" area="edit" /> }
</div>
</div>
)
}}
)}
</RollbackMutation>
);
}
Expand Down
10 changes: 5 additions & 5 deletions client/src/components/HistoryViewer/HistoryViewerVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class HistoryViewerVersion extends Component {
* @returns {string}
*/
getAuthor() {
const { version: { Author } } = this.props;
const { version: { author } } = this.props;

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

/**
Expand Down Expand Up @@ -88,7 +88,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 @@ -204,7 +204,7 @@ class HistoryViewerVersion extends Component {
<span
className="history-viewer__version-link"
role="button"
title={i18n.inject(rowTitle, { version: version.Version })}
title={i18n.inject(rowTitle, { version: version.version })}
onClick={this.handleClick}
onKeyUp={this.handleKeyUp}
tabIndex={0}
Expand Down Expand Up @@ -283,7 +283,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 @@ -108,12 +108,12 @@ class HistoryViewerVersionDetail extends PureComponent {
itemLinks={{
preview: {
Stage: {
href: `${version.AbsoluteLink}&archiveDate=${version.LastEdited}`,
href: `${version.AbsoluteLink}&archiveDate=${version.lastEdited}`,
type: 'text/html',
},
},
}}
itemId={version.Version}
itemId={version.version}
/>
</div>
);
Expand All @@ -138,13 +138,13 @@ class HistoryViewerVersionDetail extends PureComponent {

return (
<ToolbarComponent
identifier="HistoryViewer.VersionDetail.Toolbar"
identifier="HistoryViewer.versionDetail.Toolbar"
isLatestVersion={isLatestVersion}
recordId={recordId}
typeName={typeName}
versionId={version.Version}
versionId={version.version}
isPreviewable={this.isPreviewable()}
canRollback={version.IsFullVersion}
canRollback={version.isFullVersion}
rollbackMessage={rollbackMessage}
/>
);
Expand Down Expand Up @@ -198,7 +198,7 @@ class HistoryViewerVersionDetail extends PureComponent {

<div className={classnames(formClasses)}>
<FormBuilderLoader
identifier={`HistoryViewer.VersionDetail.${version.ID}`}
identifier={`HistoryViewer.versionDetail.${version.id}`}
schemaUrl={schemaUrl}
refetchSchemaOnMount={false}
/>
Expand Down Expand Up @@ -261,5 +261,5 @@ export default inject(
PreviewComponent,
CompareWarningComponent,
}),
({ version }, context) => `${context}.HistoryViewerVersionDetail.${version.Version}`
({ version }, context) => `${context}.HistoryViewerVersionDetail.${version.version}`
)(HistoryViewerVersionDetail);
Loading

0 comments on commit 990fde3

Please sign in to comment.