From 07834414c75ac2ff0b451b0031d241eb0b5c4bc9 Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Wed, 2 Dec 2015 14:26:15 +0100 Subject: [PATCH 1/5] Set default name for marketplace wallets to be 'Market' until the white label name loads --- .../market_buttons/market_submit_button.js | 8 +++---- .../components/market/market_piece_list.js | 12 ++++++---- .../market/market_register_piece.js | 23 +++++++++++++++---- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/js/components/whitelabel/wallet/components/market/market_buttons/market_submit_button.js b/js/components/whitelabel/wallet/components/market/market_buttons/market_submit_button.js index d75282af..a4b1b7c3 100644 --- a/js/components/whitelabel/wallet/components/market/market_buttons/market_submit_button.js +++ b/js/components/whitelabel/wallet/components/market/market_buttons/market_submit_button.js @@ -91,7 +91,7 @@ let MarketSubmitButton = React.createClass({ render() { const { availableAcls, currentUser, className, editions, handleSuccess } = this.props; - const { whitelabel } = this.state; + const { whitelabel: { name: whitelabelName = 'Market', user: whitelabelAdminEmail } } = this.state; const { solePieceId, canSubmit } = this.getAggregateEditionDetails(); const message = getAclFormMessage({ aclName: 'acl_consign', @@ -103,14 +103,14 @@ let MarketSubmitButton = React.createClass({ const triggerButton = ( ); const consignForm = ( + title={getLangText('Consign artwork to %s', whitelabelName)}> {consignForm} diff --git a/js/components/whitelabel/wallet/components/market/market_piece_list.js b/js/components/whitelabel/wallet/components/market/market_piece_list.js index 8ffab5a5..e45da164 100644 --- a/js/components/whitelabel/wallet/components/market/market_piece_list.js +++ b/js/components/whitelabel/wallet/components/market/market_piece_list.js @@ -49,19 +49,23 @@ let MarketPieceList = React.createClass({ }, render() { - const { currentUser, whitelabel } = this.state; + const { + currentUser: { email: userEmail }, + whitelabel: { name: whitelabelName = 'Market', user: whitelabelAdminEmail } + } = this.state; + let filterParams = null; let canLoadPieceList = false; - if (currentUser.email && whitelabel.user) { + if (userEmail && whitelabelAdminEmail) { canLoadPieceList = true; - const isUserAdmin = currentUser.email === whitelabel.user; + const isUserAdmin = userEmail === whitelabelAdminEmail; filterParams = [{ label: getLangText('Show works I can'), items: [{ key: isUserAdmin ? 'acl_transfer' : 'acl_consign', - label: getLangText(isUserAdmin ? 'transfer' : 'consign to %s', whitelabel.name), + label: getLangText(isUserAdmin ? 'transfer' : 'consign to %s', whitelabelName), defaultValue: true }] }]; diff --git a/js/components/whitelabel/wallet/components/market/market_register_piece.js b/js/components/whitelabel/wallet/components/market/market_register_piece.js index 3572fd6d..d68be85d 100644 --- a/js/components/whitelabel/wallet/components/market/market_register_piece.js +++ b/js/components/whitelabel/wallet/components/market/market_register_piece.js @@ -11,11 +11,13 @@ import MarketAdditionalDataForm from './market_forms/market_additional_data_form import Property from '../../../../ascribe_forms/property'; import RegisterPieceForm from '../../../../ascribe_forms/form_register_piece'; -import UserStore from '../../../../../stores/user_store'; -import UserActions from '../../../../../actions/user_actions'; import PieceActions from '../../../../../actions/piece_actions'; import PieceListStore from '../../../../../stores/piece_list_store'; import PieceListActions from '../../../../../actions/piece_list_actions'; +import UserStore from '../../../../../stores/user_store'; +import UserActions from '../../../../../actions/user_actions'; +import WhitelabelActions from '../../../../../actions/whitelabel_actions'; +import WhitelabelStore from '../../../../../stores/whitelabel_store'; import SlidesContainer from '../../../../ascribe_slides_container/slides_container'; @@ -32,8 +34,9 @@ let MarketRegisterPiece = React.createClass({ getInitialState(){ return mergeOptions( - UserStore.getState(), PieceListStore.getState(), + UserStore.getState(), + WhitelabelStore.getState(), { step: 0 }); @@ -42,7 +45,10 @@ let MarketRegisterPiece = React.createClass({ componentDidMount() { PieceListStore.listen(this.onChange); UserStore.listen(this.onChange); + WhitelabelStore.listen(this.onChange); + UserActions.fetchCurrentUser(); + WhitelabelActions.fetchWhitelabel(); // Reset the piece store to make sure that we don't display old data // if the user repeatedly registers works @@ -52,6 +58,7 @@ let MarketRegisterPiece = React.createClass({ componentWillUnmount() { PieceListStore.unlisten(this.onChange); UserStore.unlisten(this.onChange); + WhitelabelStore.unlisten(this.onChange); }, onChange(state) { @@ -107,6 +114,12 @@ let MarketRegisterPiece = React.createClass({ }, render() { + const { + isFineUploaderActive, + step, + whitelabel: { name: whitelabelName = 'Market' } + } = this.state; + setDocumentTitle(getLangText('Register a new piece')); return ( @@ -122,9 +135,9 @@ let MarketRegisterPiece = React.createClass({ 0} + disabled={step > 0} enableLocalHashing={false} - headerMessage={getLangText('Consign to Market')} + headerMessage={getLangText('Consign to %s', whitelabelName)} submitMessage={getLangText('Proceed to additional details')} isFineUploaderActive={true} handleSuccess={this.handleRegisterSuccess} From 2381bd22ac1cc1181fed2356b6599664f60479de Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Wed, 2 Dec 2015 16:05:21 +0100 Subject: [PATCH 2/5] Change nested destructuring formatting --- .../wallet/components/market/market_piece_list.js | 6 ++++-- .../wallet/components/market/market_register_piece.js | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/js/components/whitelabel/wallet/components/market/market_piece_list.js b/js/components/whitelabel/wallet/components/market/market_piece_list.js index e45da164..647a84be 100644 --- a/js/components/whitelabel/wallet/components/market/market_piece_list.js +++ b/js/components/whitelabel/wallet/components/market/market_piece_list.js @@ -51,8 +51,10 @@ let MarketPieceList = React.createClass({ render() { const { currentUser: { email: userEmail }, - whitelabel: { name: whitelabelName = 'Market', user: whitelabelAdminEmail } - } = this.state; + whitelabel: { + name: whitelabelName = 'Market', + user: whitelabelAdminEmail + } } = this.state; let filterParams = null; let canLoadPieceList = false; diff --git a/js/components/whitelabel/wallet/components/market/market_register_piece.js b/js/components/whitelabel/wallet/components/market/market_register_piece.js index d68be85d..e02df80c 100644 --- a/js/components/whitelabel/wallet/components/market/market_register_piece.js +++ b/js/components/whitelabel/wallet/components/market/market_register_piece.js @@ -117,8 +117,9 @@ let MarketRegisterPiece = React.createClass({ const { isFineUploaderActive, step, - whitelabel: { name: whitelabelName = 'Market' } - } = this.state; + whitelabel: { + name: whitelabelName = 'Market' + } } = this.state; setDocumentTitle(getLangText('Register a new piece')); From 743c11df5b16a47f8fcad7a39c024c1fe1443a2f Mon Sep 17 00:00:00 2001 From: diminator Date: Wed, 2 Dec 2015 18:56:48 +0100 Subject: [PATCH 3/5] fixed cyland/ikono serializers --- js/components/register_piece.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/components/register_piece.js b/js/components/register_piece.js index bc0639e3..9cd1779c 100644 --- a/js/components/register_piece.js +++ b/js/components/register_piece.js @@ -44,7 +44,7 @@ let RegisterPiece = React.createClass( { return mergeOptions( UserStore.getState(), WhitelabelStore.getState(), - PieceListStore.getState(), + PieceListStore.getState() ); }, From 565bf308aedee0fc845a8fb1c1b8de93961f0232 Mon Sep 17 00:00:00 2001 From: diminator Date: Wed, 2 Dec 2015 21:42:35 +0100 Subject: [PATCH 4/5] tested and fixed ikonotv --- .../components/ikonotv/ikonotv_register_piece.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/js/components/whitelabel/wallet/components/ikonotv/ikonotv_register_piece.js b/js/components/whitelabel/wallet/components/ikonotv/ikonotv_register_piece.js index 16d893b7..c6f59a53 100644 --- a/js/components/whitelabel/wallet/components/ikonotv/ikonotv_register_piece.js +++ b/js/components/whitelabel/wallet/components/ikonotv/ikonotv_register_piece.js @@ -16,6 +16,9 @@ import UserActions from '../../../../../actions/user_actions'; import PieceStore from '../../../../../stores/piece_store'; import PieceActions from '../../../../../actions/piece_actions'; +import WhitelabelActions from '../../../../../actions/whitelabel_actions'; +import WhitelabelStore from '../../../../../stores/whitelabel_store'; + import GlobalNotificationModel from '../../../../../models/global_notification_model'; import GlobalNotificationActions from '../../../../../actions/global_notification_actions'; @@ -47,6 +50,7 @@ let IkonotvRegisterPiece = React.createClass({ UserStore.getState(), PieceListStore.getState(), PieceStore.getState(), + WhitelabelStore.getState(), { step: 0, pageExitWarning: getLangText("If you leave this form now, your work will not be loaned to Ikono TV.") @@ -57,7 +61,9 @@ let IkonotvRegisterPiece = React.createClass({ PieceListStore.listen(this.onChange); UserStore.listen(this.onChange); PieceStore.listen(this.onChange); + WhitelabelStore.listen(this.onChange); UserActions.fetchCurrentUser(); + WhitelabelActions.fetchWhitelabel(); // Before we load the new piece, we reset the piece store to delete old data that we do // not want to display to the user. @@ -81,6 +87,7 @@ let IkonotvRegisterPiece = React.createClass({ PieceListStore.unlisten(this.onChange); UserStore.unlisten(this.onChange); PieceStore.unlisten(this.onChange); + WhitelabelStore.listen(this.onChange); }, onChange(state) { @@ -152,7 +159,8 @@ let IkonotvRegisterPiece = React.createClass({ canSubmit() { let currentUser = this.state.currentUser; - return currentUser && currentUser.acl && currentUser.acl.acl_wallet_submit; + let whitelabel = this.state.whitelabel; + return currentUser && currentUser.acl && currentUser.acl.acl_wallet_submit && whitelabel && whitelabel.user; }, getSlideArtistDetails() { @@ -194,15 +202,16 @@ let IkonotvRegisterPiece = React.createClass({ let today = new Moment(); let enddate = new Moment(); enddate.add(2, 'years'); + const {piece, whitelabel} = this.state; return (
Date: Thu, 3 Dec 2015 17:43:15 +0100 Subject: [PATCH 5/5] Revert "Merge with AD-1443" Revert https://github.com/ascribe/onion/pull/40, as that needs more work. --- js/components/piece_list.js | 5 ++-- js/stores/edition_list_store.js | 43 +++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/js/components/piece_list.js b/js/components/piece_list.js index 9208df92..4a96cbd8 100644 --- a/js/components/piece_list.js +++ b/js/components/piece_list.js @@ -189,14 +189,13 @@ let PieceList = React.createClass({ this.state.pieceList .forEach((piece) => { // but only if they're actually open - const isEditionListOpenForPiece = this.state.isEditionListOpenForPieceId[piece.id]; - - if (isEditionListOpenForPiece && isEditionListOpenForPiece.show) { + if(this.state.isEditionListOpenForPieceId[piece.id].show) { EditionListActions.refreshEditionList({ pieceId: piece.id, filterBy }); } + }); }); diff --git a/js/stores/edition_list_store.js b/js/stores/edition_list_store.js index 6b4d64f9..107f9af4 100644 --- a/js/stores/edition_list_store.js +++ b/js/stores/edition_list_store.js @@ -32,7 +32,7 @@ class EditionListStore { // page let storeEditionIndex = (page - 1) * pageSize + i; let editionsForPieces = this.editionList[pieceId]; - + // if edition already exists, just merge if(editionsForPieces[storeEditionIndex]) { editionsForPieces[storeEditionIndex] = React.addons.update(editionsForPieces[storeEditionIndex], {$merge: editionListOfPiece[i]}); @@ -60,29 +60,46 @@ class EditionListStore { * We often just have to refresh the edition list for a certain pieceId, * this method provides exactly that functionality without any side effects */ - onRefreshEditionList({pieceId, filterBy = this.editionList[pieceId].filterBy}) { - const pieceEditionList = this.editionList[pieceId]; - + onRefreshEditionList({pieceId, filterBy = {}}) { // It may happen that the user enters the site logged in already // through /editions // If he then tries to delete a piece/edition and this method is called, // we'll not be able to refresh his edition list since its not yet there. // Therefore we can just return, since there is no data to be refreshed - if (!pieceEditionList) { + if(!this.editionList[pieceId]) { return; } + let prevEditionListLength = this.editionList[pieceId].length; + let prevEditionListPage = this.editionList[pieceId].page; + let prevEditionListPageSize = this.editionList[pieceId].pageSize; + + // we can also refresh the edition list using filterBy, + // if we decide not to do that then the old filter will just be applied. + if(filterBy && Object.keys(filterBy).length <= 0) { + filterBy = this.editionList[pieceId].filterBy; + prevEditionListLength = 10; + prevEditionListPage = 1; + prevEditionListPageSize = 10; + } + // to clear an array, david walsh recommends to just set it's length to zero // http://davidwalsh.name/empty-array - pieceEditionList.length = 0; + this.editionList[pieceId].length = 0; - // refetch editions from the beginning with the previous settings - EditionsListActions - .fetchEditionList(pieceId, 1, pieceEditionList.pageSize, - pieceEditionList.orderBy, - pieceEditionList.orderAsc, - filterBy) - .catch(console.logGlobal); + // refetch editions with adjusted page size + EditionsListActions.fetchEditionList(pieceId, 1, prevEditionListLength, + this.editionList[pieceId].orderBy, + this.editionList[pieceId].orderAsc, + filterBy) + .then(() => { + // reset back to the normal pageSize and page + this.editionList[pieceId].page = prevEditionListPage; + this.editionList[pieceId].pageSize = prevEditionListPageSize; + }) + .catch((err) => { + console.logGlobal(err); + }); } onSelectEdition({pieceId, editionId, toValue}) {