Skip to content

Commit

Permalink
NEW: CMS 5 upgrade.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendeksilverstripe committed Feb 14, 2024
1 parent 4a85b4a commit 9ab8d14
Show file tree
Hide file tree
Showing 33 changed files with 5,471 additions and 8,337 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10
18
2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion client/src/boot/registerComponents.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/no-unresolved */

import Injector from 'lib/Injector';
import HistoryViewer from 'components/HistoryViewer/HistoryViewer';
import SnapshotViewerContainer from 'components/HistoryViewer/SnapshotViewerContainer';
Expand Down Expand Up @@ -38,4 +40,3 @@ export default () => {
SnapshotHistoryViewerCompareWarning: HistoryViewerCompareWarning,
}, { force: true });
};

2 changes: 2 additions & 0 deletions client/src/boot/registerReducers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/no-unresolved */

import Injector from 'lib/Injector';
import { combineReducers } from 'redux';
import historyViewerReducer from 'state/historyviewer/HistoryViewerReducer';
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/HistoryViewer/HistoryViewer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-unresolved */
/* global window */

import React, { Component } from 'react';
Expand Down Expand Up @@ -458,7 +459,6 @@ HistoryViewer.defaultProps = {
},
};


function mapStateToProps(state) {
const {
currentPage,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/no-unresolved */

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/HistoryViewer/HistoryViewerHeading.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/no-unresolved */

import i18n from 'i18n';
import React, { Component } from 'react';
import { Dropdown, DropdownToggle, DropdownMenu } from 'reactstrap';
Expand Down
8 changes: 5 additions & 3 deletions client/src/components/HistoryViewer/HistoryViewerSnapshot.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/no-unresolved */

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { inject } from 'lib/Injector';
Expand Down Expand Up @@ -128,8 +130,8 @@ export default compose(
inject(
['FormAction', 'SnapshotHistoryViewerSnapshotState'],
(FormAction, HistoryViewerSnapshotState) => ({
FormActionComponent: FormAction,
StateComponent: HistoryViewerSnapshotState,
})
FormActionComponent: FormAction,
StateComponent: HistoryViewerSnapshotState,
})
)
)(HistoryViewerSnapshot);
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component as VersionedState } from './HistoryViewerVersionState';
/* eslint-disable import/no-unresolved */

import { inject } from 'lib/Injector';
import React from 'react';
import { Component as VersionedState } from './HistoryViewerVersionState';

class HistoryViewerSnapshotState extends VersionedState {
translateType(type) {
Expand Down
21 changes: 11 additions & 10 deletions client/src/components/HistoryViewer/HistoryViewerToolbar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/no-unresolved, react/no-unused-state */

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { compose } from 'redux';
Expand Down Expand Up @@ -72,11 +74,11 @@ class HistoryViewerToolbar extends Component {
icon="back-in-time"
name="revert"
attributes={{
title: revertButtonTitle,
}}
title: revertButtonTitle,
}}
data={{
buttonStyle: 'warning'
}}
buttonStyle: 'warning'
}}
disabled={isLatestVersion || isReverting || !canRollback}
loading={isReverting}
title={i18n._t('HistoryViewerToolbar.REVERT_TO_VERSION', 'Revert to this version')}
Expand All @@ -91,11 +93,11 @@ class HistoryViewerToolbar extends Component {
>
{rollbackMessage}
</Tooltip>
)}
)}
{ isPreviewable && <ViewModeComponent id="history-viewer-edit-mode" area="edit" /> }
</div>
</div>
)}
)}
</RollbackMutation>
);
}
Expand Down Expand Up @@ -123,14 +125,13 @@ HistoryViewerToolbar.defaultProps = {
canRollback: true,
};


function mapDispatchToProps(dispatch) {
return {
onAfterRevert(versionId) {
dispatch(addMessage(i18n.sprintf(
i18n._t('HistoryViewerToolbar.REVERTED_MESSAGE', 'Successfully reverted to version %s'),
versionId
)));
i18n._t('HistoryViewerToolbar.REVERTED_MESSAGE', 'Successfully reverted to version %s'),
versionId
)));
dispatch(showList());
},
};
Expand Down
3 changes: 3 additions & 0 deletions client/src/components/HistoryViewer/HistoryViewerVersion.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/no-unresolved */

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { compose } from 'redux';
Expand Down Expand Up @@ -195,6 +197,7 @@ class HistoryViewerVersion extends Component {
</span>
);
}

render() {
const { version, isActive, StateComponent } = this.props;
const rowTitle = i18n._t('HistoryViewerVersion.GO_TO_VERSION', 'Go to version {version}');
Expand Down
6 changes: 4 additions & 2 deletions client/src/components/HistoryViewer/HistoryViewerVersion.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
$snapshot-top-padding: $table-cell-padding * 2 + $line-height-base;

.history-viewer__row--current {
.history-viewer__version-link {
cursor: default;
Expand Down Expand Up @@ -80,7 +82,7 @@

&--initial {
&:before {
top: ($table-cell-padding * 2 + $line-height-base) / 2;
top: calc($snapshot-top-padding / 2);
}
}
&--muted {
Expand All @@ -94,4 +96,4 @@
display:none;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-unresolved, react/no-deprecated */
/* global document */

import React, { PureComponent } from 'react';
Expand Down
12 changes: 7 additions & 5 deletions client/src/components/HistoryViewer/HistoryViewerVersionList.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/no-unresolved */

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
Expand Down Expand Up @@ -43,12 +45,12 @@ class HistoryViewerVersionList extends PureComponent {
* @returns {boolean}
*/
isVersionActive(version) {
const { currentVersion, compare, compare: { versionFrom, versionTo } } = this.props;
const isCurrent = currentVersion && currentVersion.id === version.id;
const isCompareFrom = versionFrom && versionFrom.id === version.id;
const isCompareTo = versionTo && versionTo.id === version.id;
const { currentVersion, compare, compare: { versionFrom, versionTo } } = this.props;
const isCurrent = currentVersion && currentVersion.id === version.id;
const isCompareFrom = versionFrom && versionFrom.id === version.id;
const isCompareTo = versionTo && versionTo.id === version.id;

return (!compare && isCurrent) || isCompareFrom || isCompareTo;
return (!compare && isCurrent) || isCompareFrom || isCompareTo;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

// In detail views, pulls the content (and content tabs) closer to the selected version table
.history-viewer__table--current {
margin-bottom: $panel-padding-y / 2;
margin-bottom: calc($panel-padding-y / 2);
}

.history-viewer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/no-unresolved */

import React, { Component } from 'react';
import classnames from 'classnames';
import i18n from 'i18n';
Expand Down Expand Up @@ -32,7 +34,6 @@ class HistoryViewerVersionState extends Component {
return i18n._t('HistoryViewer.Saved', 'Saved');
}


/**
* Return any status badges for the record
*
Expand Down
14 changes: 8 additions & 6 deletions client/src/components/HistoryViewer/RollbackMutation.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/* eslint-disable import/no-unresolved */

import React, { useMemo } from 'react';
import { Mutation } from 'react-apollo';
import createRollbackMutation from '../../graphql/createRollbackMutation';

const RollbackMutation = ({ typeName, children }) => {
const ROLLBACK = useMemo(() => createRollbackMutation(typeName), [typeName]);
return (
<Mutation mutation={ROLLBACK} refetchQueries={[`ReadSnapshots${typeName}`]}>
{children}
</Mutation>
);
const ROLLBACK = useMemo(() => createRollbackMutation(typeName), [typeName]);
return (
<Mutation mutation={ROLLBACK} refetchQueries={[`ReadSnapshots${typeName}`]}>
{children}
</Mutation>
);
};

export default RollbackMutation;
108 changes: 55 additions & 53 deletions client/src/components/HistoryViewer/SnapshotViewerContainer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/no-unresolved */

import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import { Query } from 'react-apollo';
Expand All @@ -16,59 +18,59 @@ const SnapshotViewerContainer = ({
},
SnapshotViewerComponent,
}) => {
const QUERY = useMemo(
() => createSnapshotsQuery(typeName, isPreviewable),
[typeName, isPreviewable]
);
const QUERY = useMemo(
() => createSnapshotsQuery(typeName, isPreviewable),
[typeName, isPreviewable]
);

const variables = {
limit,
offset: ((page || 1) - 1) * limit,
page_id: recordId,
};
return (
<Query query={QUERY} variables={variables} fetchPolicy="network-only">
{({ loading, error, data, refetch }) => {
let readOne = null;
if (data) {
readOne = data[`readOne${typeName}`];
}
const versions = readOne || {};
const variables = {
limit,
offset: ((page || 1) - 1) * limit,
page_id: recordId,
};
return (
<Query query={QUERY} variables={variables} fetchPolicy="network-only">
{({ loading, error, data, refetch }) => {
let readOne = null;
if (data) {
readOne = data[`readOne${typeName}`];
}
const versions = readOne || {};

const errors = error && error.graphQLErrors &&
const errors = error && error.graphQLErrors &&
error.graphQLErrors.map((graphQLError) => graphQLError.message);

const props = {
loading,
versions,
graphQLErrors: errors,
actions: {
...actions,
versions: {
...versions,
// eslint-disable-next-line no-shadow
goToPage(page) {
refetch({
offset: ((page || 1) - 1) * limit,
limit,
page_id: recordId,
});
}
},
},
recordId,
recordClass,
typeName,
limit,
page,
};
const props = {
loading,
versions,
graphQLErrors: errors,
actions: {
...actions,
versions: {
...versions,
// eslint-disable-next-line no-shadow
goToPage(page) {
refetch({
offset: ((page || 1) - 1) * limit,
limit,
page_id: recordId,
});
}
},
},
recordId,
recordClass,
typeName,
limit,
page,
};

return (
<SnapshotViewerComponent {...props} />
);
}}
</Query>
);
return (
<SnapshotViewerComponent {...props} />
);
}}
</Query>
);
};

SnapshotViewerContainer.propTypes = {
Expand All @@ -82,9 +84,9 @@ SnapshotViewerContainer.propTypes = {
};

export default inject(
['SnapshotViewer'],
(SnapshotViewerComponent) => ({
SnapshotViewerComponent,
}),
({ contextKey }) => `VersionedAdmin.HistoryViewer.${contextKey}`
['SnapshotViewer'],
(SnapshotViewerComponent) => ({
SnapshotViewerComponent,
}),
({ contextKey }) => `VersionedAdmin.HistoryViewer.${contextKey}`
)(SnapshotViewerContainer);
Loading

0 comments on commit 9ab8d14

Please sign in to comment.