1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-28 16:48:04 +02:00

Destructure params for fetchEditionList

This commit is contained in:
Brett Sun 2015-12-08 14:55:04 +01:00
parent f82797bea3
commit 349ea8518f
6 changed files with 46 additions and 31 deletions

View File

@ -17,7 +17,7 @@ class EditionListActions {
); );
} }
fetchEditionList(pieceId, page, pageSize, orderBy, orderAsc, filterBy) { fetchEditionList({pieceId, page, pageSize, orderBy, orderAsc, filterBy}) {
if((!orderBy && typeof orderAsc === 'undefined') || !orderAsc) { if((!orderBy && typeof orderAsc === 'undefined') || !orderAsc) {
orderBy = 'edition_number'; orderBy = 'edition_number';
orderAsc = true; orderAsc = true;
@ -31,7 +31,7 @@ class EditionListActions {
return Q.Promise((resolve, reject) => { return Q.Promise((resolve, reject) => {
EditionListFetcher EditionListFetcher
.fetch(pieceId, page, pageSize, orderBy, orderAsc, filterBy) .fetch({pieceId, page, pageSize, orderBy, orderAsc, filterBy})
.then((res) => { .then((res) => {
if(res && !res.editions) { if(res && !res.editions) {
throw new Error('Piece has no editions to fetch.'); throw new Error('Piece has no editions to fetch.');
@ -54,7 +54,6 @@ class EditionListActions {
reject(err); reject(err);
}); });
}); });
} }
} }

View File

@ -50,14 +50,15 @@ let AccordionListItemEditionWidget = React.createClass({
* Calls the store to either show or hide the editionListTable * Calls the store to either show or hide the editionListTable
*/ */
toggleTable() { toggleTable() {
let pieceId = this.props.piece.id; const { piece: { id: pieceId } } = this.props;
let isEditionListOpen = this.state.isEditionListOpenForPieceId[pieceId] ? this.state.isEditionListOpenForPieceId[pieceId].show : false; const { filterBy, isEditionListOpenForPieceId } = this.state;
const isEditionListOpen = isEditionListOpenForPieceId[pieceId] ? isEditionListOpenForPieceId[pieceId].show : false;
if(isEditionListOpen) { if(isEditionListOpen) {
EditionListActions.toggleEditionList(pieceId); EditionListActions.toggleEditionList(pieceId);
} else { } else {
EditionListActions.toggleEditionList(pieceId); EditionListActions.toggleEditionList(pieceId);
EditionListActions.fetchEditionList(pieceId, null, null, null, null, this.state.filterBy); EditionListActions.fetchEditionList({pieceId, filterBy});
} }
}, },
@ -68,7 +69,7 @@ let AccordionListItemEditionWidget = React.createClass({
getGlyphicon() { getGlyphicon() {
let pieceId = this.props.piece.id; let pieceId = this.props.piece.id;
let isEditionListOpen = this.state.isEditionListOpenForPieceId[pieceId] ? this.state.isEditionListOpenForPieceId[pieceId].show : false; let isEditionListOpen = this.state.isEditionListOpenForPieceId[pieceId] ? this.state.isEditionListOpenForPieceId[pieceId].show : false;
if(isEditionListOpen) { if(isEditionListOpen) {
// this is the loading feedback for the editions // this is the loading feedback for the editions
// button. // button.

View File

@ -66,20 +66,28 @@ let AccordionListItemTableEditions = React.createClass({
}, },
filterSelectedEditions() { filterSelectedEditions() {
let selectedEditions = this.state.editionList[this.props.parentId] return this.state
.filter((edition) => edition.selected); .editionList[this.props.parentId]
return selectedEditions; .filter((edition) => edition.selected);
}, },
loadFurtherEditions() { loadFurtherEditions() {
const { parentId: pieceId } = this.props;
const { page, pageSize, orderBy, orderAsc, filterBy } = this.state.editionList[pieceId];
// trigger loading animation // trigger loading animation
this.setState({ this.setState({
showMoreLoading: true showMoreLoading: true
}); });
let editionList = this.state.editionList[this.props.parentId]; EditionListActions.fetchEditionList({
EditionListActions.fetchEditionList(this.props.parentId, editionList.page + 1, editionList.pageSize, pieceId,
editionList.orderBy, editionList.orderAsc, editionList.filterBy); page: page + 1,
pageSize,
orderBy,
orderAsc,
filterBy
});
}, },
render() { render() {
let selectedEditionsCount = 0; let selectedEditionsCount = 0;

View File

@ -49,16 +49,18 @@ let CreateEditionsButton = React.createClass({
// requests, will try to merge the filterBy parameter with other parameters (mergeOptions). // requests, will try to merge the filterBy parameter with other parameters (mergeOptions).
// Therefore it can't but null but instead has to be an empty object // Therefore it can't but null but instead has to be an empty object
EditionListActions.fetchEditionList(this.props.piece.id, null, null, null, null, {}) EditionListActions
.then((res) => { .fetchEditionList({
pieceId: this.props.piece.id,
clearInterval(this.state.pollingIntervalIndex); filterBy: {}
this.props.onPollingSuccess(this.props.piece.id, res.editions[0].num_editions); })
.then((res) => {
}) clearInterval(this.state.pollingIntervalIndex);
.catch((err) => { this.props.onPollingSuccess(this.props.piece.id, res.editions[0].num_editions);
/* Ignore and keep going */ })
}); .catch((err) => {
/* Ignore and keep going */
});
}, 5000); }, 5000);
this.setState({ this.setState({

View File

@ -9,7 +9,7 @@ let EditionListFetcher = {
/** /**
* Fetches a list of editions from the API. * Fetches a list of editions from the API.
*/ */
fetch(pieceId, page, pageSize, orderBy, orderAsc, filterBy) { fetch({pieceId, page, pageSize, orderBy, orderAsc, filterBy}) {
let ordering = generateOrderingQueryParams(orderBy, orderAsc); let ordering = generateOrderingQueryParams(orderBy, orderAsc);
let queryParams = mergeOptions( let queryParams = mergeOptions(

View File

@ -32,7 +32,7 @@ class EditionListStore {
// page // page
let storeEditionIndex = (page - 1) * pageSize + i; let storeEditionIndex = (page - 1) * pageSize + i;
let editionsForPieces = this.editionList[pieceId]; let editionsForPieces = this.editionList[pieceId];
// if edition already exists, just merge // if edition already exists, just merge
if(editionsForPieces[storeEditionIndex]) { if(editionsForPieces[storeEditionIndex]) {
editionsForPieces[storeEditionIndex] = React.addons.update(editionsForPieces[storeEditionIndex], {$merge: editionListOfPiece[i]}); editionsForPieces[storeEditionIndex] = React.addons.update(editionsForPieces[storeEditionIndex], {$merge: editionListOfPiece[i]});
@ -88,10 +88,15 @@ class EditionListStore {
this.editionList[pieceId].length = 0; this.editionList[pieceId].length = 0;
// refetch editions with adjusted page size // refetch editions with adjusted page size
EditionsListActions.fetchEditionList(pieceId, 1, prevEditionListLength, EditionsListActions
this.editionList[pieceId].orderBy, .fetchEditionList({
this.editionList[pieceId].orderAsc, pieceId,
filterBy) page: 1,
pageSize: prevEditionListLength,
orderBy: this.editionList[pieceId].orderBy,
orderAsc: this.editionList[pieceId].orderAsc,
filterBy
})
.then(() => { .then(() => {
// reset back to the normal pageSize and page // reset back to the normal pageSize and page
this.editionList[pieceId].page = prevEditionListPage; this.editionList[pieceId].page = prevEditionListPage;
@ -144,7 +149,7 @@ class EditionListStore {
if(!this.isEditionListOpenForPieceId[pieceId].show) { if(!this.isEditionListOpenForPieceId[pieceId].show) {
// to clear an array, david walsh recommends to just set it's length to zero // to clear an array, david walsh recommends to just set it's length to zero
// http://davidwalsh.name/empty-array // http://davidwalsh.name/empty-array
this.editionList[pieceId].length = 0; this.editionList[pieceId].length = 0;
} }
} }