-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW Implement React history viewer if available (SS 4.2 onwards)
- Loading branch information
1 parent
a70fbd6
commit 7c1a649
Showing
10 changed files
with
269 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
Name: elementalgraphqlconfig | ||
--- | ||
SilverStripe\GraphQL\Controller: | ||
schema: | ||
scaffolding: | ||
types: | ||
DNADesign\Elemental\Models\BaseElement: | ||
fields: '*' | ||
operations: | ||
readOne: true | ||
SilverStripe\Security\Member: | ||
fields: [ID, FirstName, Surname] | ||
operations: | ||
readOne: true |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* global window */ | ||
|
||
import registerComponents from 'boot/registerComponents'; | ||
|
||
window.document.addEventListener('DOMContentLoaded', () => { | ||
registerComponents(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Injector from 'lib/Injector'; | ||
import readOneBlockQuery from 'state/history/readOneBlockQuery'; | ||
|
||
export default () => { | ||
Injector.transform( | ||
'elements-history', | ||
(updater) => { | ||
// Add content block history to the HistoryViewer | ||
updater.component( | ||
'HistoryViewer.Form_ItemEditForm', | ||
readOneBlockQuery, | ||
'ElementHistoryViewer' | ||
); | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
require('./BlockHistory.js'); | ||
|
||
require('boot'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { graphql } from 'react-apollo'; | ||
import gql from 'graphql-tag'; | ||
|
||
// GraphQL query for retrieving the version history of a specific block. The results of | ||
// the query must be set to the "versions" prop on the component that this HOC is | ||
// applied to for binding implementation. | ||
const query = gql` | ||
query ReadHistoryViewerBlock ($block_id: ID!, $limit: Int!, $offset: Int!) { | ||
readOneBlock( | ||
Versioning: { | ||
Mode: LATEST | ||
}, | ||
ID: $block_id | ||
) { | ||
ID | ||
Versions (limit: $limit, offset: $offset) { | ||
pageInfo { | ||
totalCount | ||
} | ||
edges { | ||
node { | ||
Version | ||
Author { | ||
FirstName | ||
Surname | ||
} | ||
Publisher { | ||
FirstName | ||
Surname | ||
} | ||
Published | ||
LiveVersion | ||
LastEdited | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const config = { | ||
options({ recordId, limit, page }) { | ||
return { | ||
variables: { | ||
limit, | ||
offset: ((page || 1) - 1) * limit, | ||
block_id: recordId, | ||
} | ||
}; | ||
}, | ||
props( | ||
{ | ||
data: { | ||
error, | ||
refetch, | ||
readOneBlock, | ||
loading: networkLoading, | ||
}, | ||
ownProps: { | ||
actions = { | ||
versions: {} | ||
}, | ||
limit, | ||
recordId, | ||
}, | ||
} | ||
) { | ||
const versions = readOneBlock || null; | ||
|
||
const errors = error && error.graphQLErrors && | ||
error.graphQLErrors.map((graphQLError) => graphQLError.message); | ||
|
||
return { | ||
loading: networkLoading || !versions, | ||
versions, | ||
graphQLErrors: errors, | ||
actions: { | ||
...actions, | ||
versions: { | ||
...versions, | ||
goToPage(page) { | ||
refetch({ | ||
offset: ((page || 1) - 1) * limit, | ||
limit, | ||
block_id: recordId, | ||
}); | ||
} | ||
}, | ||
}, | ||
}; | ||
}, | ||
}; | ||
|
||
export { query, config }; | ||
|
||
export default graphql(query, config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.