From 318a0bf4b2c0f2e8b383342de5a54d4ad117b158 Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Fri, 6 Nov 2015 14:10:54 +0100 Subject: [PATCH] Filter the collection to only show the consignable items by default --- .../piece_list_bulk_modal.js | 31 ------------------- .../piece_list_toolbar_filter_widget.js | 10 +++--- js/components/piece_list.js | 23 +++++++++++++- .../components/lumenus/lumenus_piece_list.js | 3 +- 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js b/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js index 1380f21d..bb8d4ccc 100644 --- a/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js +++ b/js/components/ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js @@ -6,12 +6,6 @@ import { mergeOptions } from '../../utils/general_utils'; import EditionListActions from '../../actions/edition_list_actions'; -import UserStore from '../../stores/user_store'; -import UserActions from '../../actions/user_actions'; - -import PieceListStore from '../../stores/piece_list_store'; -import PieceListActions from '../../actions/piece_list_actions'; - import PieceListBulkModalSelectedEditionsWidget from './piece_list_bulk_modal_selected_editions_widget'; import { getLangText } from '../../utils/lang_utils.js'; @@ -30,31 +24,6 @@ let PieceListBulkModal = React.createClass({ ]) }, - getInitialState() { - return mergeOptions( - UserStore.getState(), - PieceListStore.getState() - ); - }, - - componentDidMount() { - UserStore.listen(this.onChange); - PieceListStore.listen(this.onChange); - - UserActions.fetchCurrentUser(); - PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search, - this.state.orderBy, this.state.orderAsc, this.state.filterBy); - }, - - componentWillUnmount() { - PieceListStore.unlisten(this.onChange); - UserStore.unlisten(this.onChange); - }, - - onChange(state) { - this.setState(state); - }, - clearAllSelections() { EditionListActions.clearAllEditionSelections(); EditionListActions.closeAllEditionLists(); diff --git a/js/components/ascribe_piece_list_toolbar/piece_list_toolbar_filter_widget.js b/js/components/ascribe_piece_list_toolbar/piece_list_toolbar_filter_widget.js index 38de2af6..cea41e3b 100644 --- a/js/components/ascribe_piece_list_toolbar/piece_list_toolbar_filter_widget.js +++ b/js/components/ascribe_piece_list_toolbar/piece_list_toolbar_filter_widget.js @@ -28,7 +28,7 @@ let PieceListToolbarFilterWidget = React.createClass({ }, generateFilterByStatement(param) { - let filterBy = this.props.filterBy; + const { filterBy } = this.props; if(filterBy) { // we need hasOwnProperty since the values are all booleans @@ -56,13 +56,13 @@ let PieceListToolbarFilterWidget = React.createClass({ */ filterBy(param) { return () => { - let filterBy = this.generateFilterByStatement(param); + const filterBy = this.generateFilterByStatement(param); this.props.applyFilterBy(filterBy); }; }, isFilterActive() { - let trueValuesOnly = Object.keys(this.props.filterBy).filter((acl) => acl); + const trueValuesOnly = Object.keys(this.props.filterBy).filter((acl) => acl); // We're hiding the star in that complicated matter so that, // the surrounding button is not resized up on appearance @@ -74,7 +74,7 @@ let PieceListToolbarFilterWidget = React.createClass({ }, render() { - let filterIcon = ( + const filterIcon = ( * @@ -140,4 +140,4 @@ let PieceListToolbarFilterWidget = React.createClass({ } }); -export default PieceListToolbarFilterWidget; \ No newline at end of file +export default PieceListToolbarFilterWidget; diff --git a/js/components/piece_list.js b/js/components/piece_list.js index 69f5b23f..1ea64ff6 100644 --- a/js/components/piece_list.js +++ b/js/components/piece_list.js @@ -60,11 +60,17 @@ let PieceList = React.createClass({ }] }; }, + getInitialState() { - return mergeOptions( + const stores = mergeOptions( PieceListStore.getState(), EditionListStore.getState() ); + + // Use the default filters but use the stores' settings if they're available + stores.filterBy = Object.assign(this.getDefaultFilterBy(), stores.filterBy); + + return stores; }, componentDidMount() { @@ -96,6 +102,21 @@ let PieceList = React.createClass({ this.setState(state); }, + getDefaultFilterBy() { + const { filterParams } = this.props; + const defaultFilterBy = {}; + + filterParams.forEach(({ label, items }) => { + items.forEach((item) => { + if (typeof item === 'object' && item.defaultValue) { + defaultFilterBy[item.key] = true; + } + }); + }); + + return defaultFilterBy; + }, + paginationGoToPage(page) { return () => { // if the users clicks a pager of the pagination, diff --git a/js/components/whitelabel/wallet/components/lumenus/lumenus_piece_list.js b/js/components/whitelabel/wallet/components/lumenus/lumenus_piece_list.js index ccfb7e1c..58ad7813 100644 --- a/js/components/whitelabel/wallet/components/lumenus/lumenus_piece_list.js +++ b/js/components/whitelabel/wallet/components/lumenus/lumenus_piece_list.js @@ -25,7 +25,8 @@ let LumenusPieceList = React.createClass({ label: getLangText('Show works I can'), items: [{ key: 'acl_consign', - label: getLangText('consign to Lumenus') + label: getLangText('consign to Lumenus'), + defaultValue: true }] }]} location={this.props.location}/>