Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] GraphQL v4 compat #60

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions client/dist/js/bundle.js

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.

44 changes: 21 additions & 23 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 edges = (versions && versions.snapshotHistory && versions.snapshotHistory.edges)
? versions.snapshotHistory.edges
: [];
return edges.map(({ node }) => {
return {
return edges.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 @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ class HistoryViewerVersionList extends PureComponent {
{this.renderHeader()}
{
versions.map((version, index) => (
version.IsFullVersion ?
version.isFullVersion ?
<VersionComponent
key={`${version.ID}--${version.LastEdited}`}
key={`${version.ID}--${version.lastEdited}`}
isActive={this.isVersionActive(version)}
version={version}
compare={compare}
compareModeAvailable={compareModeAvailable}
/> :
<SnapshotComponent
isComparing={!!compare}
key={`${version.ID}--${version.LastEdited}`}
key={`${version.ID}--${version.lastEdited}`}
isActive={this.isVersionActive(version)}
version={version}
initial={index < 1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ export { HistoryViewerVersionState as Component };
export default inject(
['Badge'],
(BadgeComponent) => ({ BadgeComponent }),
({ version }) => `HistoryViewer.HistoryViewerVersionState.${version.Version}`
({ version }) => `HistoryViewer.HistoryViewerVersionState.${version.version}`
)(HistoryViewerVersionState);
10 changes: 5 additions & 5 deletions client/src/components/HistoryViewer/RollbackMutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import createRollbackMutation from '../../graphql/createRollbackMutation';
const RollbackMutation = ({ typeName, children }) => {
const ROLLBACK = useMemo(() => createRollbackMutation(typeName), [typeName]);
return (
<Mutation mutation={ROLLBACK} refetchQueries={[`ReadSnapshots${typeName}`]}>
{children}
</Mutation>
)
<Mutation mutation={ROLLBACK} refetchQueries={[`ReadSnapshots${typeName}`]}>
{children}
</Mutation>
);
};

export default RollbackMutation;
export default RollbackMutation;
Loading