1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-25 02:36:28 +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) {
orderBy = 'edition_number';
orderAsc = true;
@ -31,7 +31,7 @@ class EditionListActions {
return Q.Promise((resolve, reject) => {
EditionListFetcher
.fetch(pieceId, page, pageSize, orderBy, orderAsc, filterBy)
.fetch({pieceId, page, pageSize, orderBy, orderAsc, filterBy})
.then((res) => {
if(res && !res.editions) {
throw new Error('Piece has no editions to fetch.');
@ -54,7 +54,6 @@ class EditionListActions {
reject(err);
});
});
}
}

View File

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

View File

@ -66,20 +66,28 @@ let AccordionListItemTableEditions = React.createClass({
},
filterSelectedEditions() {
let selectedEditions = this.state.editionList[this.props.parentId]
.filter((edition) => edition.selected);
return selectedEditions;
return this.state
.editionList[this.props.parentId]
.filter((edition) => edition.selected);
},
loadFurtherEditions() {
const { parentId: pieceId } = this.props;
const { page, pageSize, orderBy, orderAsc, filterBy } = this.state.editionList[pieceId];
// trigger loading animation
this.setState({
showMoreLoading: true
});
let editionList = this.state.editionList[this.props.parentId];
EditionListActions.fetchEditionList(this.props.parentId, editionList.page + 1, editionList.pageSize,
editionList.orderBy, editionList.orderAsc, editionList.filterBy);
EditionListActions.fetchEditionList({
pieceId,
page: page + 1,
pageSize,
orderBy,
orderAsc,
filterBy
});
},
render() {
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).
// Therefore it can't but null but instead has to be an empty object
EditionListActions.fetchEditionList(this.props.piece.id, null, null, null, null, {})
.then((res) => {
clearInterval(this.state.pollingIntervalIndex);
this.props.onPollingSuccess(this.props.piece.id, res.editions[0].num_editions);
})
.catch((err) => {
/* Ignore and keep going */
});
EditionListActions
.fetchEditionList({
pieceId: this.props.piece.id,
filterBy: {}
})
.then((res) => {
clearInterval(this.state.pollingIntervalIndex);
this.props.onPollingSuccess(this.props.piece.id, res.editions[0].num_editions);
})
.catch((err) => {
/* Ignore and keep going */
});
}, 5000);
this.setState({

View File

@ -9,7 +9,7 @@ let EditionListFetcher = {
/**
* 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 queryParams = mergeOptions(

View File

@ -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]});
@ -88,10 +88,15 @@ class EditionListStore {
this.editionList[pieceId].length = 0;
// refetch editions with adjusted page size
EditionsListActions.fetchEditionList(pieceId, 1, prevEditionListLength,
this.editionList[pieceId].orderBy,
this.editionList[pieceId].orderAsc,
filterBy)
EditionsListActions
.fetchEditionList({
pieceId,
page: 1,
pageSize: prevEditionListLength,
orderBy: this.editionList[pieceId].orderBy,
orderAsc: this.editionList[pieceId].orderAsc,
filterBy
})
.then(() => {
// reset back to the normal pageSize and page
this.editionList[pieceId].page = prevEditionListPage;
@ -144,7 +149,7 @@ class EditionListStore {
if(!this.isEditionListOpenForPieceId[pieceId].show) {
// to clear an array, david walsh recommends to just set it's length to zero
// http://davidwalsh.name/empty-array
this.editionList[pieceId].length = 0;
}
}