Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendeksilverstripe committed Feb 12, 2024
1 parent 1988388 commit d360818
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 124 deletions.
1 change: 0 additions & 1 deletion client/src/boot/registerComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ export default () => {
SnapshotHistoryViewerCompareWarning: HistoryViewerCompareWarning,
}, { force: true });
};

1 change: 0 additions & 1 deletion client/src/components/HistoryViewer/HistoryViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ HistoryViewer.defaultProps = {
},
};


function mapStateToProps(state) {
const {
currentPage,
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/HistoryViewer/HistoryViewerSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,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,6 @@
import { Component as VersionedState } from './HistoryViewerVersionState';
import { inject } from 'lib/Injector';
import React from 'react';
import { Component as VersionedState } from './HistoryViewerVersionState';

class HistoryViewerSnapshotState extends VersionedState {
translateType(type) {
Expand Down
19 changes: 9 additions & 10 deletions client/src/components/HistoryViewer/HistoryViewerToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,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 +91,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 +123,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
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,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
10 changes: 5 additions & 5 deletions client/src/components/HistoryViewer/HistoryViewerVersionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,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 @@ -32,7 +32,6 @@ class HistoryViewerVersionState extends Component {
return i18n._t('HistoryViewer.Saved', 'Saved');
}


/**
* Return any status badges for the record
*
Expand Down
12 changes: 6 additions & 6 deletions client/src/components/HistoryViewer/RollbackMutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ 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;
106 changes: 53 additions & 53 deletions client/src/components/HistoryViewer/SnapshotViewerContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,59 +16,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 +82,9 @@ SnapshotViewerContainer.propTypes = {
};

export default inject(
['SnapshotViewer'],
(SnapshotViewerComponent) => ({
SnapshotViewerComponent,
}),
({ contextKey }) => `VersionedAdmin.HistoryViewer.${contextKey}`
['SnapshotViewer'],
(SnapshotViewerComponent) => ({
SnapshotViewerComponent,
}),
({ contextKey }) => `VersionedAdmin.HistoryViewer.${contextKey}`
)(SnapshotViewerContainer);
56 changes: 28 additions & 28 deletions client/src/components/HistoryViewer/tests/HistoryViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/* global jest, describe, it, expect */

import React from 'react';
import { Component as HistoryViewer } from '../HistoryViewer';
import Enzyme, { shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16/build/index';
import { Component as HistoryViewer } from '../HistoryViewer';

Enzyme.configure({ adapter: new Adapter() });

Expand Down Expand Up @@ -105,9 +105,9 @@ describe('HistoryViewer', () => {
page={1}
compare={false}
currentVersion={{
version: 123,
latestDraftVersion: true
}}
version: 123,
latestDraftVersion: true
}}
/>);

expect(wrapper.instance().getLatestVersion().version).toEqual(123);
Expand Down Expand Up @@ -202,8 +202,8 @@ describe('HistoryViewer', () => {
page={2}
versions={versions}
currentVersion={{
ID: 1,
}}
ID: 1,
}}
compare={false}
/>);

Expand All @@ -222,13 +222,13 @@ describe('HistoryViewer', () => {
page={2}
versions={versions}
currentVersion={{
ID: 1,
}}
ID: 1,
}}
compare={{
versionFrom: {
ID: 1,
},
}}
versionFrom: {
ID: 1,
},
}}
/>);

expect(wrapper.instance().isListView()).toBe(true);
Expand All @@ -246,16 +246,16 @@ describe('HistoryViewer', () => {
page={2}
versions={versions}
currentVersion={{
ID: 1
}}
ID: 1
}}
compare={{
versionFrom: {
ID: 1,
},
versionTo: {
ID: 2,
},
}}
versionFrom: {
ID: 1,
},
versionTo: {
ID: 2,
},
}}
/>);

expect(wrapper.instance().isListView()).toBe(false);
Expand Down Expand Up @@ -290,13 +290,13 @@ describe('HistoryViewer', () => {
limit={1}
page={2}
versions={{
Versions: {
pageInfo: { totalCount: 1 },
edges: [
{ node: { Version: 14 } },
],
}
}}
Versions: {
pageInfo: { totalCount: 1 },
edges: [
{ node: { Version: 14 } },
],
}
}}
/>);

expect(wrapper.instance().compareModeAvailable()).toBe(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/* global jest, describe, it, expect */

import React from 'react';
import { Component as HistoryViewerHeading } from '../HistoryViewerHeading';
import Enzyme, { shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16/build/index';
import { Component as HistoryViewerHeading } from '../HistoryViewerHeading';

Enzyme.configure({ adapter: new Adapter() });

Expand Down Expand Up @@ -37,4 +37,3 @@ describe('HistoryViewerHeading', () => {
});
});
});

Loading

0 comments on commit d360818

Please sign in to comment.