mirror of
https://github.com/ascribe/onion.git
synced 2025-02-14 21:10:27 +01:00
Destructure params for fetchEditionList
This commit is contained in:
parent
f82797bea3
commit
349ea8518f
@ -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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -66,20 +66,28 @@ let AccordionListItemTableEditions = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
filterSelectedEditions() {
|
filterSelectedEditions() {
|
||||||
let selectedEditions = this.state.editionList[this.props.parentId]
|
return this.state
|
||||||
|
.editionList[this.props.parentId]
|
||||||
.filter((edition) => edition.selected);
|
.filter((edition) => edition.selected);
|
||||||
return selectedEditions;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
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;
|
||||||
|
@ -49,12 +49,14 @@ 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
|
||||||
|
.fetchEditionList({
|
||||||
|
pieceId: this.props.piece.id,
|
||||||
|
filterBy: {}
|
||||||
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
|
||||||
clearInterval(this.state.pollingIntervalIndex);
|
clearInterval(this.state.pollingIntervalIndex);
|
||||||
this.props.onPollingSuccess(this.props.piece.id, res.editions[0].num_editions);
|
this.props.onPollingSuccess(this.props.piece.id, res.editions[0].num_editions);
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
/* Ignore and keep going */
|
/* Ignore and keep going */
|
||||||
|
@ -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(
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user