forked from silverstripe/silverstripe-elemental
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request silverstripe#277 from creative-commoners/pulls/4.0…
…/attach-graphql NEW Query for reading blocks is now bound to ElementEditor component
- Loading branch information
Showing
14 changed files
with
151 additions
and
1,533 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import Injector from 'lib/Injector'; | ||
import ElementEditor from 'components/ElementEditor/containers/ElementEditor'; | ||
import Element from 'components/ElementEditor/Element'; | ||
import ElementEditor from 'components/ElementEditor/ElementEditor'; | ||
import ElementList from 'components/ElementEditor/ElementList'; | ||
import Toolbar from 'components/ElementEditor/Toolbar'; | ||
|
||
export default () => { | ||
Injector.component.registerMany({ | ||
ElementEditor | ||
ElementEditor, | ||
ElementToolbar: Toolbar, | ||
ElementList, | ||
Element, | ||
}); | ||
}; |
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,14 +1,33 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
import React, { PureComponent } from 'react'; | ||
import { elementType } from 'types/elementType'; | ||
|
||
class Element extends Component { | ||
/** | ||
* The Element component used in the context of an ElementEditor shows the summary | ||
* of an element's details when used in the CMS, including ID, Title and Summary. | ||
*/ | ||
class Element extends PureComponent { | ||
render() { | ||
const { element: { ID, Title, Summary } } = this.props; | ||
|
||
if (!ID) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div /> | ||
<div className="element-editor__element"> | ||
<p>#{ID}: {Title}</p> | ||
<p>{Summary}</p> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
Element.defaultProps = {}; | ||
Element.propTypes = {}; | ||
Element.propTypes = { | ||
element: elementType, | ||
}; | ||
|
||
Element.defaultProps = { | ||
element: null, | ||
}; | ||
|
||
export default Element; |
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,14 +1,34 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
import React, { PureComponent, PropTypes } from 'react'; | ||
import { inject } from 'lib/Injector'; | ||
|
||
class ElementEditor extends Component { | ||
/** | ||
* The ElementEditor is used in the CMS to manage a list or nested lists of | ||
* elements for a page or other DataObject. | ||
*/ | ||
class ElementEditor extends PureComponent { | ||
render() { | ||
const { ToolbarComponent, ListComponent, pageId } = this.props; | ||
|
||
return ( | ||
<div /> | ||
<div className="element-editor"> | ||
<ToolbarComponent /> | ||
<ListComponent pageId={pageId} /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
ElementEditor.propTypes = { | ||
pageId: PropTypes.number.isRequired, | ||
}; | ||
|
||
ElementEditor.defaultProps = {}; | ||
ElementEditor.propTypes = {}; | ||
|
||
export default ElementEditor; | ||
export default inject( | ||
['ElementToolbar', 'ElementList'], | ||
(ToolbarComponent, ListComponent) => ({ | ||
ToolbarComponent, | ||
ListComponent, | ||
}), | ||
() => 'ElementEditor' | ||
)(ElementEditor); |
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,14 +1,50 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
import { elementType } from 'types/elementType'; | ||
import { inject } from 'lib/Injector'; | ||
|
||
class ElementList extends Component { | ||
/** | ||
* Renders a list of Element components, each with an elementType object | ||
* of data mapped into it. The data is provided by a GraphQL HOC registered | ||
* in registerTransforms.js. | ||
*/ | ||
renderBlocks() { | ||
const { ElementComponent, blocks } = this.props; | ||
|
||
if (!blocks) { | ||
return null; | ||
} | ||
|
||
return blocks.map((element) => ( | ||
<ElementComponent | ||
key={element.ID} | ||
element={element} | ||
/> | ||
)); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div /> | ||
<div className="elemental-editor__list"> | ||
{this.renderBlocks()} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
ElementList.defaultProps = {}; | ||
ElementList.propTypes = {}; | ||
ElementList.propTypes = { | ||
// @todo support either ElementList or Element children in an array (or both) | ||
blocks: PropTypes.arrayOf(elementType), | ||
}; | ||
|
||
ElementList.defaultProps = { | ||
blocks: [], | ||
}; | ||
|
||
export default ElementList; | ||
export default inject( | ||
['Element'], | ||
(ElementComponent) => ({ | ||
ElementComponent, | ||
}), | ||
() => 'ElementEditor.ElementList' | ||
)(ElementList); |
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { PropTypes } from 'react'; | ||
|
||
// Describes the structure of an element coming in via GraphQL | ||
const elementType = { | ||
ID: PropTypes.number.isRequired, | ||
Title: PropTypes.string, | ||
Summary: PropTypes.string, | ||
}; | ||
|
||
export { elementType }; |
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 was deleted.
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,3 @@ | ||
<div $AttributesHTML data-schema="$SchemaData.JSON"> | ||
<%-- Field is rendered by React components --%> | ||
</div> |