silverstripe-cms/client/src/state/history/revertToPageVersionMutation.js
Robbie Averill e3237f9638 NEW Add revert mutation and refactor injector transformations (#2158)
* NEW Add revert mutation and refactor injector transformations

Removing the existing HOC component and just using Injector transformations to apply the GraphQL query and mutation

* Refetch versions after performing the revert mutation

* WIP Provide additional context
2018-05-17 15:36:46 +12:00

45 lines
903 B
JavaScript

import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
const mutation = gql`
mutation revertPageToVersion($id:ID!, $fromStage:VersionedStage!, $toStage:VersionedStage!, $fromVersion:Int!) {
copySilverStripeSiteTreeToStage(Input: {
ID: $id
FromVersion: $fromVersion
FromStage: $fromStage
ToStage: $toStage
}) {
ID
}
}
`;
const config = {
props: ({ mutate, ownProps: { actions } }) => {
const revertToVersion = (id, fromVersion, fromStage, toStage) => mutate({
variables: {
id,
fromVersion,
fromStage,
toStage,
},
});
return {
actions: {
...actions,
revertToVersion,
},
};
},
options: {
// Refetch versions after mutation is completed
refetchQueries: ['ReadHistoryViewerPage']
}
};
export { mutation, config };
export default graphql(mutation, config);