From 9cc70dc4c929e050f15fff7f87ce271b4f9bbc3b Mon Sep 17 00:00:00 2001 From: root Date: Fri, 12 Jun 2015 17:18:40 +0200 Subject: [PATCH] refactor open state of edition table first cut --- js/actions/edition_list_actions.js | 32 +++++++++++-------- js/actions/piece_list_actions.js | 4 +-- .../accordion_list_item_table.js | 1 - .../accordion_list_item_table_editions.js | 15 +++++---- js/components/piece_list.js | 3 +- js/stores/edition_list_store.js | 6 ++++ js/stores/piece_list_store.js | 8 ++--- 7 files changed, 40 insertions(+), 29 deletions(-) diff --git a/js/actions/edition_list_actions.js b/js/actions/edition_list_actions.js index ca653323..e36ae1b0 100644 --- a/js/actions/edition_list_actions.js +++ b/js/actions/edition_list_actions.js @@ -9,7 +9,8 @@ class EditionListActions { this.generateActions( 'updateEditionList', 'selectEdition', - 'clearAllEditionSelections' + 'clearAllEditionSelections', + 'toggleEditionList' ); } @@ -19,19 +20,24 @@ class EditionListActions { orderAsc = true; } - EditionListFetcher - .fetch(pieceId, orderBy, orderAsc) - .then((res) => { - this.actions.updateEditionList({ - 'editionListOfPiece': res.editions, - pieceId, - orderBy, - orderAsc + return new Promise((resolve, reject) => { + EditionListFetcher + .fetch(pieceId, orderBy, orderAsc) + .then((res) => { + this.actions.updateEditionList({ + 'editionListOfPiece': res.editions, + pieceId, + orderBy, + orderAsc + }); + resolve(res); + }) + .catch((err) => { + reject(err); + console.log(err); }); - }) - .catch((err) => { - console.log(err); - }); + }); + } } diff --git a/js/actions/piece_list_actions.js b/js/actions/piece_list_actions.js index 938cb195..a4ab626c 100644 --- a/js/actions/piece_list_actions.js +++ b/js/actions/piece_list_actions.js @@ -8,9 +8,7 @@ import PieceListFetcher from '../fetchers/piece_list_fetcher'; class PieceListActions { constructor() { this.generateActions( - 'updatePieceList', - 'showEditionList', - 'closeAllEditionLists' + 'updatePieceList' ); } diff --git a/js/components/ascribe_accordion_list/accordion_list_item_table.js b/js/components/ascribe_accordion_list/accordion_list_item_table.js index 4ead1eeb..a162823d 100644 --- a/js/components/ascribe_accordion_list/accordion_list_item_table.js +++ b/js/components/ascribe_accordion_list/accordion_list_item_table.js @@ -13,7 +13,6 @@ let AccordionListItemTable = React.createClass({ parentId: React.PropTypes.number, itemList: React.PropTypes.array, columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(ColumnModel)), - numOfTableItems: React.PropTypes.number, show: React.PropTypes.bool, changeOrder: React.PropTypes.func, orderBy: React.PropTypes.string, diff --git a/js/components/ascribe_accordion_list/accordion_list_item_table_editions.js b/js/components/ascribe_accordion_list/accordion_list_item_table_editions.js index 67bec486..ea5d9d94 100644 --- a/js/components/ascribe_accordion_list/accordion_list_item_table_editions.js +++ b/js/components/ascribe_accordion_list/accordion_list_item_table_editions.js @@ -22,8 +22,7 @@ let AccordionListItemTableEditions = React.createClass({ propTypes: { className: React.PropTypes.string, - parentId: React.PropTypes.number, - show: React.PropTypes.bool + parentId: React.PropTypes.number }, getInitialState() { @@ -60,7 +59,7 @@ let AccordionListItemTableEditions = React.createClass({ }, toggleTable() { - PieceListActions.showEditionList(this.props.parentId); + // This is triggered everytime show all editions is clicked, which is wrong EditionListActions.fetchEditionList(this.props.parentId); }, @@ -73,6 +72,7 @@ let AccordionListItemTableEditions = React.createClass({ let allEditionsCount = 0; let orderBy; let orderAsc; + let show; // here we need to check if all editions of a specific // piece are already defined. Otherwise .length will throw an error and we'll not @@ -84,6 +84,10 @@ let AccordionListItemTableEditions = React.createClass({ orderAsc = this.state.editionList[this.props.parentId].orderAsc; } + if(this.props.parentId in this.state.editionOpenList) { + show = this.state.editionOpenList[this.props.parentId].show; + } + let transition = new TransitionModel('edition', 'editionId', 'bitcoin_id'); let columnList = [ @@ -149,15 +153,14 @@ let AccordionListItemTableEditions = React.createClass({ parentId={this.props.parentId} itemList={this.state.editionList[this.props.parentId]} columnList={columnList} - numOfTableItems={this.props.numOfEditions} - show={this.props.show} + show={show} orderBy={orderBy} orderAsc={orderAsc} changeOrder={this.changeEditionListOrder}> + show={show} /> diff --git a/js/components/piece_list.js b/js/components/piece_list.js index 642cff3f..fd9cd183 100644 --- a/js/components/piece_list.js +++ b/js/components/piece_list.js @@ -77,8 +77,7 @@ let PieceList = React.createClass({ key={i}> + parentId={item.id} /> ); })} diff --git a/js/stores/edition_list_store.js b/js/stores/edition_list_store.js index f3c30ee1..c5ee36fe 100644 --- a/js/stores/edition_list_store.js +++ b/js/stores/edition_list_store.js @@ -8,6 +8,7 @@ import EditionsListActions from '../actions/edition_list_actions'; class EditionListStore { constructor() { this.editionList = {}; + this.editionOpenList = {}; this.bindActions(EditionsListActions); } @@ -24,6 +25,11 @@ class EditionListStore { this.editionList[pieceId] = editionListOfPiece; + // ToDo: Do merging later + this.editionOpenList[pieceId] = { + show: this.editionOpenList[pieceId] ? !this.editionOpenList[pieceId].show : true + }; + /** * orderBy and orderAsc are specific to a single list of editons * therefore they need to be saved in relation to their parent-piece. diff --git a/js/stores/piece_list_store.js b/js/stores/piece_list_store.js index 754f2d4a..3789b313 100644 --- a/js/stores/piece_list_store.js +++ b/js/stores/piece_list_store.js @@ -28,7 +28,7 @@ class PieceListStore { this.bindActions(PieceListActions); } - onShowEditionList(pieceId) { + /*onShowEditionList(pieceId) { this.pieceList .forEach((piece) => { if(piece.id === pieceId) { @@ -39,14 +39,14 @@ class PieceListStore { } } }); - } + }*/ - onCloseAllEditionLists() { + /*onCloseAllEditionLists() { this.pieceList .forEach((piece) => { piece.show = false; }); - } + }*/ onUpdatePieceList({ page, pageSize, search, pieceList, orderBy, orderAsc, pieceListCount }) { this.page = page;