From 8da71d02297ebaf77ecd7014175a57daf13ae604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Wed, 29 Jul 2015 14:46:33 +0200 Subject: [PATCH 1/3] make term components unique in loan form --- js/components/ascribe_forms/form_loan.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/js/components/ascribe_forms/form_loan.js b/js/components/ascribe_forms/form_loan.js index da5ad6f0..89394766 100644 --- a/js/components/ascribe_forms/form_loan.js +++ b/js/components/ascribe_forms/form_loan.js @@ -53,12 +53,16 @@ let LoanForm = React.createClass({ getContractCheckbox() { if(this.state.contractKey && this.state.contractUrl) { + // we need to define a key on the InputCheckboxes as otherwise + // react is not rerendering them on a store switch and is keeping + // the default value of the component (which is in that case true) return ( {getLangText('I agree to the')}  @@ -76,6 +80,7 @@ let LoanForm = React.createClass({ style={{paddingBottom: 0}} hidden={true}> ); From b0d321381698819c847597d3b64bad2d9f37d718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Wed, 29 Jul 2015 15:03:15 +0200 Subject: [PATCH 2/3] add flushLoanContract logic --- js/actions/loan_contract_actions.js | 3 ++- js/components/ascribe_forms/form_loan.js | 1 + js/stores/loan_contract_store.js | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/js/actions/loan_contract_actions.js b/js/actions/loan_contract_actions.js index 07ce0966..cc7e5a5b 100644 --- a/js/actions/loan_contract_actions.js +++ b/js/actions/loan_contract_actions.js @@ -7,7 +7,8 @@ import OwnershipFetcher from '../fetchers/ownership_fetcher'; class LoanContractActions { constructor() { this.generateActions( - 'updateLoanContract' + 'updateLoanContract', + 'flushLoanContract' ); } diff --git a/js/components/ascribe_forms/form_loan.js b/js/components/ascribe_forms/form_loan.js index 89394766..b261d749 100644 --- a/js/components/ascribe_forms/form_loan.js +++ b/js/components/ascribe_forms/form_loan.js @@ -36,6 +36,7 @@ let LoanForm = React.createClass({ }, componentWillUnmount() { + LoanContractActions.flushLoanContract(); LoanContractStore.unlisten(this.onChange); }, diff --git a/js/stores/loan_contract_store.js b/js/stores/loan_contract_store.js index 107b34bb..3d0c0592 100644 --- a/js/stores/loan_contract_store.js +++ b/js/stores/loan_contract_store.js @@ -17,6 +17,12 @@ class LoanContractStore { this.contractUrl = contractUrl; this.contractEmail = contractEmail; } + + onFlushLoanContract() { + this.contractKey = null; + this.contractUrl = null; + this.contractEmail = null; + } } export default alt.createStore(LoanContractStore, 'LoanContractStore'); From 9ebc489c78adcf6d1a50da0b7fb70185cc6c7f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Wed, 29 Jul 2015 15:24:30 +0200 Subject: [PATCH 3/3] refresh piece list correctly after piece with edition creation --- .../accordion_list_item_edition_widget.js | 2 -- js/components/ascribe_detail/piece.js | 8 ++++++++ js/stores/piece_list_store.js | 1 - 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/js/components/ascribe_accordion_list/accordion_list_item_edition_widget.js b/js/components/ascribe_accordion_list/accordion_list_item_edition_widget.js index 1616f183..9fb72b06 100644 --- a/js/components/ascribe_accordion_list/accordion_list_item_edition_widget.js +++ b/js/components/ascribe_accordion_list/accordion_list_item_edition_widget.js @@ -6,8 +6,6 @@ import classNames from 'classnames'; import EditionListActions from '../../actions/edition_list_actions'; import EditionListStore from '../../stores/edition_list_store'; -import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger'; -import Tooltip from 'react-bootstrap/lib/Tooltip'; import Button from 'react-bootstrap/lib/Button'; import CreateEditionsButton from '../ascribe_buttons/create_editions_button'; diff --git a/js/components/ascribe_detail/piece.js b/js/components/ascribe_detail/piece.js index 94ac82a4..fd80e66f 100644 --- a/js/components/ascribe_detail/piece.js +++ b/js/components/ascribe_detail/piece.js @@ -113,11 +113,19 @@ let Piece = React.createClass({ }, handlePollingSuccess(pieceId, numEditions) { + + // we need to refresh the num_editions property of the actual piece we're looking at PieceActions.updateProperty({ key: 'num_editions', value: numEditions }); + // as well as its representation in the collection + // btw.: It's not sufficient to just set num_editions to numEditions, since a single accordion + // list item also uses the firstEdition property which we can only get from the server in that case. + // Therefore we need to at least refetch the changed piece from the server or on our case simply all + PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc); + let notification = new GlobalNotificationModel('Editions successfully created', 'success', 10000); GlobalNotificationActions.appendGlobalNotification(notification); }, diff --git a/js/stores/piece_list_store.js b/js/stores/piece_list_store.js index 22d8d5d6..a8b73e44 100644 --- a/js/stores/piece_list_store.js +++ b/js/stores/piece_list_store.js @@ -80,7 +80,6 @@ class PieceListStore { let piece = filteredPieceList[0]; piece[key] = value; - } else { throw new Error('Could not find a matching piece in piece list since its either not there or piecelist contains duplicates.'); }