From a3656410b133d87be50447de175eff6ecd03ee68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Tue, 29 Sep 2015 14:25:30 +0200 Subject: [PATCH 1/4] Update component no PieceListStore changes --- .../piece_list_bulk_modal.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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 452a9bd8..06fd98a0 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 @@ -33,21 +33,25 @@ let PieceListBulkModal = React.createClass({ ); }, - onChange(state) { - this.setState(state); - }, + componentDidMount() { EditionListStore.listen(this.onChange); UserStore.listen(this.onChange); + PieceListStore.listen(this.onChange); UserActions.fetchCurrentUser(); }, componentWillUnmount() { EditionListStore.unlisten(this.onChange); + PieceListStore.unlisten(this.onChange); UserStore.unlisten(this.onChange); }, + onChange(state) { + this.setState(state); + }, + fetchSelectedPieceEditionList() { let filteredPieceIdList = Object.keys(this.state.editionList) .filter((pieceId) => { From 550eb2dc0bfafd39e6be1fabd4fa5d3303f10e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Tue, 29 Sep 2015 15:23:57 +0200 Subject: [PATCH 2/4] Add fetchPieceList to PieceListBulkModal --- .../ascribe_piece_list_bulk_modal/piece_list_bulk_modal.js | 3 +++ 1 file changed, 3 insertions(+) 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 06fd98a0..3e5b6495 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 @@ -39,7 +39,10 @@ let PieceListBulkModal = React.createClass({ EditionListStore.listen(this.onChange); 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() { From 40095f7fbf06c388b571bf246cc9eec687b2dfc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Tue, 29 Sep 2015 15:38:06 +0200 Subject: [PATCH 3/4] throw javascript errors on >= 400 HTTP errors --- js/stores/edition_list_store.js | 1 - js/utils/requests.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/js/stores/edition_list_store.js b/js/stores/edition_list_store.js index 87b4df76..b3b152d3 100644 --- a/js/stores/edition_list_store.js +++ b/js/stores/edition_list_store.js @@ -13,7 +13,6 @@ class EditionListStore { } onUpdateEditionList({pieceId, editionListOfPiece, page, pageSize, orderBy, orderAsc, count, filterBy}) { - /* Basically there are two modes an edition list can be updated. diff --git a/js/utils/requests.js b/js/utils/requests.js index fd676896..3761a7a0 100644 --- a/js/utils/requests.js +++ b/js/utils/requests.js @@ -21,7 +21,7 @@ class Requests { } unpackResponse(response) { - if (response.status >= 500) { + if (response.status >= 400) { throw new Error(response.status + ' - ' + response.statusText + ' - on URL:' + response.url); } From 7283ae7574ce94cd5c1c904e1226c86a46656c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Wed, 30 Sep 2015 11:22:20 +0200 Subject: [PATCH 4/4] PR Feedback: Change API error handling to saver approach --- js/actions/edition_list_actions.js | 5 +++++ js/utils/requests.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/js/actions/edition_list_actions.js b/js/actions/edition_list_actions.js index d13882cd..fb0a2249 100644 --- a/js/actions/edition_list_actions.js +++ b/js/actions/edition_list_actions.js @@ -33,6 +33,10 @@ class EditionListActions { EditionListFetcher .fetch(pieceId, page, pageSize, orderBy, orderAsc, filterBy) .then((res) => { + if(res && !res.editions) { + throw new Error('Piece has no editions to fetch.'); + } + this.actions.updateEditionList({ pieceId, page, @@ -46,6 +50,7 @@ class EditionListActions { resolve(res); }) .catch((err) => { + console.logGlobal(err); reject(err); }); }); diff --git a/js/utils/requests.js b/js/utils/requests.js index 3761a7a0..fd676896 100644 --- a/js/utils/requests.js +++ b/js/utils/requests.js @@ -21,7 +21,7 @@ class Requests { } unpackResponse(response) { - if (response.status >= 400) { + if (response.status >= 500) { throw new Error(response.status + ' - ' + response.statusText + ' - on URL:' + response.url); }