mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
Merge pull request #56 from ascribe/destructure-fetch-params
Destructure params for piece and edition fetching
This commit is contained in:
commit
5a794fea11
@ -17,14 +17,14 @@ class EditionListActions {
|
||||
);
|
||||
}
|
||||
|
||||
fetchEditionList(pieceId, page, pageSize, orderBy, orderAsc, filterBy, maxEdition) {
|
||||
fetchEditionList({ pieceId, page, pageSize, orderBy, orderAsc, filterBy, maxEdition }) {
|
||||
if ((!orderBy && typeof orderAsc === 'undefined') || !orderAsc) {
|
||||
orderBy = 'edition_number';
|
||||
orderAsc = true;
|
||||
}
|
||||
|
||||
// Taken from: http://stackoverflow.com/a/519157/1263876
|
||||
if((typeof page === 'undefined' || !page) && (typeof pageSize === 'undefined' || !pageSize)) {
|
||||
if ((typeof page === 'undefined' || !page) && (typeof pageSize === 'undefined' || !pageSize)) {
|
||||
page = 1;
|
||||
pageSize = 10;
|
||||
}
|
||||
@ -39,7 +39,7 @@ class EditionListActions {
|
||||
|
||||
return Q.Promise((resolve, reject) => {
|
||||
EditionListFetcher
|
||||
.fetch(pieceId, page, itemsToFetch, orderBy, orderAsc, filterBy)
|
||||
.fetch({ pieceId, page, itemsToFetch, orderBy, orderAsc, filterBy })
|
||||
.then((res) => {
|
||||
if (res && !res.editions) {
|
||||
throw new Error('Piece has no editions to fetch.');
|
||||
|
@ -15,7 +15,7 @@ class PieceListActions {
|
||||
);
|
||||
}
|
||||
|
||||
fetchPieceList(page, pageSize, search, orderBy, orderAsc, filterBy) {
|
||||
fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy }) {
|
||||
// To prevent flickering on a pagination request,
|
||||
// we overwrite the piecelist with an empty list before
|
||||
// pieceListCount === -1 defines the loading state
|
||||
@ -34,7 +34,7 @@ class PieceListActions {
|
||||
// afterwards, we can load the list
|
||||
return Q.Promise((resolve, reject) => {
|
||||
PieceListFetcher
|
||||
.fetch(page, pageSize, search, orderBy, orderAsc, filterBy)
|
||||
.fetch({ page, pageSize, search, orderBy, orderAsc, filterBy })
|
||||
.then((res) => {
|
||||
this.actions.updatePieceList({
|
||||
page,
|
||||
|
@ -19,9 +19,10 @@ import { getLangText } from '../../utils/lang_utils';
|
||||
|
||||
let AccordionListItemEditionWidget = React.createClass({
|
||||
propTypes: {
|
||||
className: React.PropTypes.string,
|
||||
piece: React.PropTypes.object.isRequired,
|
||||
toggleCreateEditionsDialog: React.PropTypes.func.isRequired,
|
||||
|
||||
className: React.PropTypes.string,
|
||||
onPollingSuccess: React.PropTypes.func
|
||||
},
|
||||
|
||||
@ -50,14 +51,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) {
|
||||
if (isEditionListOpen) {
|
||||
EditionListActions.toggleEditionList(pieceId);
|
||||
} else {
|
||||
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() {
|
||||
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,
|
||||
pageSize,
|
||||
orderBy,
|
||||
orderAsc,
|
||||
filterBy,
|
||||
page: page + 1
|
||||
});
|
||||
},
|
||||
render() {
|
||||
const { className, parentId } = this.props;
|
||||
|
@ -88,11 +88,12 @@ let AccordionListItemWallet = React.createClass({
|
||||
},
|
||||
|
||||
onPollingSuccess(pieceId) {
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
EditionListActions.toggleEditionList(pieceId);
|
||||
|
||||
let notification = new GlobalNotificationModel('Editions successfully created', 'success', 10000);
|
||||
const notification = new GlobalNotificationModel('Editions successfully created', 'success', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
},
|
||||
|
||||
|
@ -28,6 +28,12 @@ let CreateEditionsButton = React.createClass({
|
||||
EditionListStore.listen(this.onChange);
|
||||
},
|
||||
|
||||
componentDidUpdate() {
|
||||
if(this.props.piece.num_editions === 0 && typeof this.state.pollingIntervalIndex === 'undefined') {
|
||||
this.startPolling();
|
||||
}
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
EditionListStore.unlisten(this.onChange);
|
||||
clearInterval(this.state.pollingIntervalIndex);
|
||||
@ -37,28 +43,24 @@ let CreateEditionsButton = React.createClass({
|
||||
this.setState(state);
|
||||
},
|
||||
|
||||
componentDidUpdate() {
|
||||
if(this.props.piece.num_editions === 0 && typeof this.state.pollingIntervalIndex === 'undefined') {
|
||||
this.startPolling();
|
||||
}
|
||||
},
|
||||
|
||||
startPolling() {
|
||||
// start polling until editions are defined
|
||||
let pollingIntervalIndex = setInterval(() => {
|
||||
|
||||
// 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({
|
||||
|
@ -79,9 +79,10 @@ let EditionActionPanel = React.createClass({
|
||||
},
|
||||
|
||||
refreshCollection() {
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
EditionListActions.refreshEditionList({pieceId: this.props.edition.parent});
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
EditionListActions.refreshEditionList({ pieceId: this.props.edition.parent });
|
||||
},
|
||||
|
||||
handleSuccess(response) {
|
||||
|
@ -141,15 +141,17 @@ let PieceContainer = React.createClass({
|
||||
},
|
||||
|
||||
handleEditionCreationSuccess() {
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
PieceActions.updateProperty({key: 'num_editions', value: 0});
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
this.toggleCreateEditionsDialog();
|
||||
},
|
||||
|
||||
handleDeleteSuccess(response) {
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
|
||||
// since we're deleting a piece, we just need to close
|
||||
// all editions dialogs and not reload them
|
||||
@ -178,6 +180,7 @@ let PieceContainer = React.createClass({
|
||||
},
|
||||
|
||||
handlePollingSuccess(pieceId, numEditions) {
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
// we need to refresh the num_editions property of the actual piece we're looking at
|
||||
PieceActions.updateProperty({
|
||||
@ -189,8 +192,7 @@ let PieceContainer = React.createClass({
|
||||
// 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, this.state.filterBy);
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
|
||||
let notification = new GlobalNotificationModel('Editions successfully created', 'success', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
|
@ -213,15 +213,15 @@ let PieceList = React.createClass({
|
||||
},
|
||||
|
||||
applyOrderBy(orderBy) {
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
const { filterBy, orderAsc, page, pageSize, search } = this.state;
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
},
|
||||
|
||||
loadPieceList({ page, filterBy = this.state.filterBy, search = this.state.search }) {
|
||||
const { orderAsc, pageSize } = this.state;
|
||||
const orderBy = this.state.orderBy || this.props.orderBy;
|
||||
|
||||
return PieceListActions.fetchPieceList(page, this.state.pageSize, search,
|
||||
orderBy, this.state.orderAsc, filterBy);
|
||||
return PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
},
|
||||
|
||||
fetchSelectedPieceEditionList() {
|
||||
@ -247,8 +247,9 @@ let PieceList = React.createClass({
|
||||
},
|
||||
|
||||
handleAclSuccess() {
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
const { filterBy, orderBy, orderAsc, page, pageSize, search } = this.state;
|
||||
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
|
||||
this.fetchSelectedPieceEditionList()
|
||||
.forEach((pieceId) => {
|
||||
|
@ -65,26 +65,21 @@ let RegisterPiece = React.createClass( {
|
||||
this.setState(state);
|
||||
},
|
||||
|
||||
handleSuccess(response){
|
||||
handleSuccess(response) {
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
const notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
|
||||
// once the user was able to register a piece successfully, we need to make sure to keep
|
||||
// the piece list up to date
|
||||
PieceListActions.fetchPieceList(
|
||||
this.state.page,
|
||||
this.state.pageSize,
|
||||
this.state.searchTerm,
|
||||
this.state.orderBy,
|
||||
this.state.orderAsc,
|
||||
this.state.filterBy
|
||||
);
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
|
||||
this.history.push(`/pieces/${response.piece.id}`);
|
||||
},
|
||||
|
||||
getSpecifyEditions() {
|
||||
if(this.state.whitelabel && this.state.whitelabel.acl_create_editions || Object.keys(this.state.whitelabel).length === 0) {
|
||||
if (this.state.whitelabel && this.state.whitelabel.acl_create_editions || Object.keys(this.state.whitelabel).length === 0) {
|
||||
return (
|
||||
<Property
|
||||
name="num_editions"
|
||||
|
@ -58,8 +58,9 @@ let AccordionListItemPrize = React.createClass({
|
||||
},
|
||||
|
||||
handleSubmitPrizeSuccess(response) {
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
|
||||
let notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
@ -138,8 +139,9 @@ let AccordionListItemPrize = React.createClass({
|
||||
},
|
||||
|
||||
refreshPieceData() {
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
},
|
||||
|
||||
onSelectChange(){
|
||||
|
@ -303,9 +303,10 @@ let PrizePieceRatings = React.createClass({
|
||||
},
|
||||
|
||||
refreshPieceData() {
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
this.props.loadPiece();
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
},
|
||||
|
||||
onSelectChange() {
|
||||
|
@ -52,8 +52,9 @@ let CylandAccordionListItem = React.createClass({
|
||||
},
|
||||
|
||||
handleSubmitSuccess(response) {
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
|
||||
let notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
|
@ -74,8 +74,9 @@ let CylandPieceContainer = React.createClass({
|
||||
},
|
||||
|
||||
handleDeleteSuccess(response) {
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
|
||||
// since we're deleting a piece, we just need to close
|
||||
// all editions dialogs and not reload them
|
||||
|
@ -142,14 +142,9 @@ let CylandRegisterPiece = React.createClass({
|
||||
},
|
||||
|
||||
refreshPieceList() {
|
||||
PieceListActions.fetchPieceList(
|
||||
this.state.page,
|
||||
this.state.pageSize,
|
||||
this.state.searchTerm,
|
||||
this.state.orderBy,
|
||||
this.state.orderAsc,
|
||||
this.state.filterBy
|
||||
);
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
},
|
||||
|
||||
render() {
|
||||
|
@ -53,8 +53,9 @@ let IkonotvAccordionListItem = React.createClass({
|
||||
},
|
||||
|
||||
handleSubmitSuccess(response) {
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
|
||||
let notification = new GlobalNotificationModel(response.notification, 'success', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
|
@ -83,8 +83,9 @@ let IkonotvPieceContainer = React.createClass({
|
||||
},
|
||||
|
||||
handleDeleteSuccess(response) {
|
||||
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, this.state.search,
|
||||
this.state.orderBy, this.state.orderAsc, this.state.filterBy);
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
|
||||
// since we're deleting a piece, we just need to close
|
||||
// all editions dialogs and not reload them
|
||||
|
@ -147,14 +147,9 @@ let IkonotvRegisterPiece = React.createClass({
|
||||
},
|
||||
|
||||
refreshPieceList() {
|
||||
PieceListActions.fetchPieceList(
|
||||
this.state.page,
|
||||
this.state.pageSize,
|
||||
this.state.searchTerm,
|
||||
this.state.orderBy,
|
||||
this.state.orderAsc,
|
||||
this.state.filterBy
|
||||
);
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
},
|
||||
|
||||
canSubmit() {
|
||||
|
@ -103,14 +103,9 @@ let MarketRegisterPiece = React.createClass({
|
||||
},
|
||||
|
||||
refreshPieceList() {
|
||||
PieceListActions.fetchPieceList(
|
||||
this.state.page,
|
||||
this.state.pageSize,
|
||||
this.state.searchTerm,
|
||||
this.state.orderBy,
|
||||
this.state.orderAsc,
|
||||
this.state.filterBy
|
||||
);
|
||||
const { filterBy, orderAsc, orderBy, page, pageSize, search } = this.state;
|
||||
|
||||
PieceListActions.fetchPieceList({ page, pageSize, search, orderBy, orderAsc, filterBy });
|
||||
},
|
||||
|
||||
render() {
|
||||
|
@ -9,10 +9,10 @@ let EditionListFetcher = {
|
||||
/**
|
||||
* Fetches a list of editions from the API.
|
||||
*/
|
||||
fetch(pieceId, page, pageSize, orderBy, orderAsc, filterBy) {
|
||||
let ordering = generateOrderingQueryParams(orderBy, orderAsc);
|
||||
fetch({ pieceId, page, pageSize, orderBy, orderAsc, filterBy }) {
|
||||
const ordering = generateOrderingQueryParams(orderBy, orderAsc);
|
||||
|
||||
let queryParams = mergeOptions(
|
||||
const queryParams = mergeOptions(
|
||||
{
|
||||
page,
|
||||
pageSize,
|
||||
|
@ -10,12 +10,12 @@ let PieceListFetcher = {
|
||||
* Fetches a list of pieces from the API.
|
||||
* Can be called with all supplied queryparams the API.
|
||||
*/
|
||||
fetch(page, pageSize, search, orderBy, orderAsc, filterBy) {
|
||||
let ordering = generateOrderingQueryParams(orderBy, orderAsc);
|
||||
fetch({ page, pageSize, search, orderBy, orderAsc, filterBy }) {
|
||||
const ordering = generateOrderingQueryParams(orderBy, orderAsc);
|
||||
|
||||
// filterBy is an object of acl key-value pairs.
|
||||
// The values are booleans
|
||||
let queryParams = mergeOptions(
|
||||
const queryParams = mergeOptions(
|
||||
{
|
||||
page,
|
||||
pageSize,
|
||||
|
@ -108,7 +108,15 @@ class EditionListStore {
|
||||
pieceEditionList.length = 0;
|
||||
|
||||
EditionsListActions
|
||||
.fetchEditionList(pieceId, 1, pageSize, orderBy, orderAsc, filterBy, maxSeen)
|
||||
.fetchEditionList({
|
||||
pieceId,
|
||||
pageSize,
|
||||
orderBy,
|
||||
orderAsc,
|
||||
filterBy,
|
||||
maxSeen,
|
||||
page: 1
|
||||
})
|
||||
.catch(console.logGlobal);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user