diff --git a/opentech/static_src/src/app/src/SubmissionsByRoundApp.js b/opentech/static_src/src/app/src/SubmissionsByRoundApp.js index f7fb16d38115ccc2035b55ea6935d88adb982faf..22b073181177ee5fcad623cd2f2b3704edb6fd06 100644 --- a/opentech/static_src/src/app/src/SubmissionsByRoundApp.js +++ b/opentech/static_src/src/app/src/SubmissionsByRoundApp.js @@ -2,18 +2,16 @@ import React from 'react'; import PropTypes from 'prop-types'; import { hot } from 'react-hot-loader' import Switcher from '@components/Switcher' -import DetailView from '@components/DetailView'; -import DisplayPanel from '@components/DisplayPanel'; -import SubmissionsByRoundContainer from '@containers/SubmissionsByRoundContainer'; +import GroupByStatusDetailView from '@containers/GroupByStatusDetailView'; class SubmissionsByRoundApp extends React.Component { + state = { + detailOpen: false, + }; + constructor(props) { super(props); - - this.state = { - detailOpen: false - } } detailOpen = (state) => { @@ -34,10 +32,7 @@ class SubmissionsByRoundApp extends React.Component { <div style={this.state.style} ref={this.setOriginalContentRef} dangerouslySetInnerHTML={{ __html: this.props.pageContent }} /> {this.state.detailOpen && - <DetailView> - <SubmissionsByRoundContainer roundId={this.props.roundId} /> - <DisplayPanel /> - </DetailView> + <GroupByStatusDetailView roundId={this.props.roundId} /> } </> ) @@ -46,7 +41,7 @@ class SubmissionsByRoundApp extends React.Component { SubmissionsByRoundApp.propTypes = { roundId: PropTypes.number, -} +}; -export default hot(module)(SubmissionsByRoundApp) +export default hot(module)(SubmissionsByRoundApp); diff --git a/opentech/static_src/src/app/src/components/DetailView/index.js b/opentech/static_src/src/app/src/components/DetailView/index.js index cd23b42658b17de56dde74f15b6b488867507b61..e735e079b9acb55802ccd028e530a17314ffffc8 100644 --- a/opentech/static_src/src/app/src/components/DetailView/index.js +++ b/opentech/static_src/src/app/src/components/DetailView/index.js @@ -2,14 +2,16 @@ import React from 'react'; import PropTypes from 'prop-types'; import './style.scss'; -const DetailView = ({ children }) => ( +const DetailView = ({ listing, display }) => ( <div className="detail-view"> - {children} + {listing} + {display} </div> ); DetailView.propTypes = { - children: PropTypes.node.isRequired, + listing: PropTypes.node.isRequired, + display: PropTypes.node.isRequired, }; export default DetailView; diff --git a/opentech/static_src/src/app/src/components/SubmissionsByRoundList.js b/opentech/static_src/src/app/src/components/Listing/index.js similarity index 61% rename from opentech/static_src/src/app/src/components/SubmissionsByRoundList.js rename to opentech/static_src/src/app/src/components/Listing/index.js index f564e03c23857e80d989272bc46e8d7dab0857a1..1f993fbd5ecd565a9f8d333546eb117304628149 100644 --- a/opentech/static_src/src/app/src/components/SubmissionsByRoundList.js +++ b/opentech/static_src/src/app/src/components/Listing/index.js @@ -1,27 +1,26 @@ import React from 'react'; -import SubmissionsByRoundListHeading from '@components/SubmissionsByRoundListHeading'; -import SubmissionsByRoundListItem from '@components/SubmissionsByRoundListItem'; +import ListingHeading from '@components/ListingHeading'; +import ListingItem from '@components/ListingItem'; -import './SubmissionsByRoundList.scss'; +import './style.scss'; -export default class SubmissionsByRoundList extends React.Component { +export default class Listing extends React.Component { renderListItems() { const listItems = []; for (const item of this.props.items) { listItems.push( - <SubmissionsByRoundListHeading key={`status-${item.id}`} title={item.title} count={item.submissions.length} /> + <ListingHeading key={`item-${item.id}`} title={item.title} count={item.subitems.length} /> ); const submissions = []; - for (const submission of item.submissions) { + for (const subitem of item.subitems) { submissions.push( - <SubmissionsByRoundListItem key={`submission-${submission.id}`} title={submission.title} /> + <ListingItem key={`subitem-${subitem.id}`} title={subitem.title} /> ); } - listItems.push( - <ul key={`submissions-list-${item.id}`}> + <ul key={`subitems-listing-${item.id}`}> {submissions} </ul> ); diff --git a/opentech/static_src/src/app/src/components/SubmissionsByRoundList.scss b/opentech/static_src/src/app/src/components/Listing/style.scss similarity index 100% rename from opentech/static_src/src/app/src/components/SubmissionsByRoundList.scss rename to opentech/static_src/src/app/src/components/Listing/style.scss diff --git a/opentech/static_src/src/app/src/components/SubmissionsByRoundListHeading.js b/opentech/static_src/src/app/src/components/ListingHeading.js similarity index 79% rename from opentech/static_src/src/app/src/components/SubmissionsByRoundListHeading.js rename to opentech/static_src/src/app/src/components/ListingHeading.js index bc97b2f7aac1ecad63f2bf60535e53b665e9ba29..996f7a933e214c8ae0aad300df9f4d1d8fda27ff 100644 --- a/opentech/static_src/src/app/src/components/SubmissionsByRoundListHeading.js +++ b/opentech/static_src/src/app/src/components/ListingHeading.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -export default class SubmissionsByRoundListHeading extends React.Component { +export default class ListingHeading extends React.Component { render() { return ( <li className="listing__item listing__item--heading"> @@ -12,7 +12,7 @@ export default class SubmissionsByRoundListHeading extends React.Component { } } -SubmissionsByRoundListHeading.propTypes = { +ListingHeading.propTypes = { title: PropTypes.string, count: PropTypes.oneOfType([ PropTypes.string, diff --git a/opentech/static_src/src/app/src/components/SubmissionsByRoundListItem.js b/opentech/static_src/src/app/src/components/ListingItem.js similarity index 70% rename from opentech/static_src/src/app/src/components/SubmissionsByRoundListItem.js rename to opentech/static_src/src/app/src/components/ListingItem.js index 7f2e41122fca121cd710039fbec743fe89a72a5c..3e6e1326c8d7921f4a3ef7caabd0603a4158bcec 100644 --- a/opentech/static_src/src/app/src/components/SubmissionsByRoundListItem.js +++ b/opentech/static_src/src/app/src/components/ListingItem.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -export default class SubmissionsByRoundListItem extends React.Component { +export default class ListingItem extends React.Component { render() { return ( <li className="listing__item"> @@ -12,6 +12,6 @@ export default class SubmissionsByRoundListItem extends React.Component { } } -SubmissionsByRoundListItem.propTypes = { +ListingItem.propTypes = { title: PropTypes.string, }; diff --git a/opentech/static_src/src/app/src/containers/ByStatusListing.js b/opentech/static_src/src/app/src/containers/ByStatusListing.js new file mode 100644 index 0000000000000000000000000000000000000000..27cba75db259263bc50017baa13c7404e6d44a34 --- /dev/null +++ b/opentech/static_src/src/app/src/containers/ByStatusListing.js @@ -0,0 +1,60 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { connect } from 'react-redux' + +import Listing from '@components/Listing'; +import { getCurrentRound, getCurrentRoundSubmissionsByStatus } from '@selectors/submissions'; +import { setCurrentSubmissionRound, fetchSubmissionsByRound } from '@actions/submissions'; + + +class ByStatusListing extends React.Component { + componentDidMount() { + const { roundId } = this.props; + // Update items if round ID is defined. + if (roundId !== null && roundId !== undefined) { + this.props.loadSubmissions(roundId); + } + } + + componentDidUpdate(prevProps) { + const { roundId } = this.props; + // Update entries if round ID is changed or is not null. + if (roundId !== null && roundId !== undefined && prevProps.roundId !== roundId) { + this.props.loadSubmissions(roundId); + } + } + + render() { + return <Listing items={this.getListingItems()} />; + } + + getListingItems() { + return this.props.items.map(v => ({ + id: v.id, + title: v.title, + subitems: [ + ...v.submissions + ] + })); + } +} + +const mapStateToProps = state => ({ + items: getCurrentRoundSubmissionsByStatus(state), + roundId: getCurrentRound(state), +}); + +const mapDispatchToProps = dispatch => ({ + loadSubmissions: id => dispatch(fetchSubmissionsByRound(id)), +}); + +ByStatusListing.propTypes = { + loadSubmissions: PropTypes.func, + roundId: PropTypes.number, +}; + + +export default connect( + mapStateToProps, + mapDispatchToProps +)(ByStatusListing); diff --git a/opentech/static_src/src/app/src/containers/GroupByStatusDetailView.js b/opentech/static_src/src/app/src/containers/GroupByStatusDetailView.js new file mode 100644 index 0000000000000000000000000000000000000000..c790f32b10540b522e6e3995bb43383586397e46 --- /dev/null +++ b/opentech/static_src/src/app/src/containers/GroupByStatusDetailView.js @@ -0,0 +1,38 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { connect } from 'react-redux' + +import DisplayPanel from '@components/DisplayPanel'; +import DetailView from '@components/DetailView'; +import ByStatusListing from '@containers/ByStatusListing'; +import { setCurrentSubmissionRound } from '@actions/submissions'; + +class GroupByStatusDetailView extends React.Component { + componentWillMount() { + this.props.setSubmissionRound(this.props.roundId); + } + + render() { + const passProps = { + listing: <ByStatusListing />, + display: <DisplayPanel />, + }; + return ( + <DetailView {...passProps} /> + ); + } +} + +GroupByStatusDetailView.propTypes = { + roundId: PropTypes.number, +}; + +const mapDispatchToProps = dispatch => { + return { + setSubmissionRound: id => { + dispatch(setCurrentSubmissionRound(id)); + }, + } +}; + +export default connect(null, mapDispatchToProps)(GroupByStatusDetailView); diff --git a/opentech/static_src/src/app/src/containers/SubmissionsByRoundContainer.js b/opentech/static_src/src/app/src/containers/SubmissionsByRoundContainer.js deleted file mode 100644 index 1d5f23de94c8d07b2d3abb352ac91bb702dcd5c2..0000000000000000000000000000000000000000 --- a/opentech/static_src/src/app/src/containers/SubmissionsByRoundContainer.js +++ /dev/null @@ -1,54 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux' - -import SubmissionsByRoundList from '@components/SubmissionsByRoundList'; -import { getCurrentRoundSubmissionsByStatus } from '@selectors/submissions'; -import { setCurrentSubmissionRound, fetchSubmissionsByRound } from '@actions/submissions'; - - -class SubmissionsByRoundContainer extends React.Component { - constructor(props) { - super(props); - } - - componentDidMount() { - this.props.setSubmissionRound(this.props.roundId); - this.props.loadSubmissions(this.props.roundId); - } - - render() { - return ( - <> - <SubmissionsByRoundList items={this.props.items} /> - </> - ); - } -} - - -const mapStateToProps = state => { - return { - items: getCurrentRoundSubmissionsByStatus(state), - }; -}; - -const mapDispatchToProps = dispatch => { - return { - loadSubmissions: id => { - dispatch(fetchSubmissionsByRound(id)); - }, - setSubmissionRound: id => { - dispatch(setCurrentSubmissionRound(id)); - }, - } -}; - -SubmissionsByRoundContainer.propTypes = { - roundId: PropTypes.number, - loadSubmissions: PropTypes.func, -}; - - - -export default connect(mapStateToProps, mapDispatchToProps)(SubmissionsByRoundContainer); diff --git a/opentech/static_src/src/app/src/index.js b/opentech/static_src/src/app/src/index.js index a3359dcd20e16a996c34286a795cb5879963e59e..ce8b1d05f83bbd7b4f75b574a8387aafe54db289 100644 --- a/opentech/static_src/src/app/src/index.js +++ b/opentech/static_src/src/app/src/index.js @@ -1,8 +1,8 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import { Provider } from 'react-redux' +import { Provider } from 'react-redux'; -import SubmissionsByRoundApp from './SubmissionsByRoundApp' +import SubmissionsByRoundApp from './SubmissionsByRoundApp'; import createStore from '@redux/store'; diff --git a/opentech/static_src/src/app/src/redux/selectors/submissions.js b/opentech/static_src/src/app/src/redux/selectors/submissions.js index 75a76bf06c9fbec6ccfab4645a4d52b61fc280f3..b5f45db34eca041a6f23f5053970c70675da2216 100644 --- a/opentech/static_src/src/app/src/redux/selectors/submissions.js +++ b/opentech/static_src/src/app/src/redux/selectors/submissions.js @@ -1,8 +1,8 @@ import { createSelector } from 'reselect'; -const getSubmissionsByRound = (state) => state.submissions.itemsByRound; +const getSubmissionsByRound = state => state.submissions.itemsByRound; -const getCurrentRound = (state) => state.submissions.currentRound; +const getCurrentRound = state => state.submissions.currentRound; const getCurrentRoundSubmissions = createSelector( [ getSubmissionsByRound, getCurrentRound ], @@ -32,6 +32,7 @@ const getCurrentRoundSubmissionsByStatus = createSelector( ); export { + getCurrentRound, getCurrentRoundSubmissions, getCurrentRoundSubmissionsByStatus, };