Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: class count mismatch on sidebar #568

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/dashboard/Data/Browser/Browser.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class Browser extends DashboardView {
if (this.props.params.appId !== nextProps.params.appId || !this.props.params.className) {
this.setState({ counts: {} });
Parse.Object._clearAllState();
nextProps.schema.dispatch(ActionTypes.FETCH).then(() => this.handleFetchedSchema());
}

// check if the changes are in currentApp serverInfo status
Expand All @@ -266,8 +267,6 @@ class Browser extends DashboardView {
}

this.prefetchData(nextProps, nextContext);
nextProps.schema.dispatch(ActionTypes.FETCH)
.then(() => this.handleFetchedSchema());
}
if (!nextProps.params.className && nextProps.schema.data.get('classes')) {
this.redirectToFirstClass(nextProps.schema.data.get('classes'));
Expand Down Expand Up @@ -875,7 +874,10 @@ class Browser extends DashboardView {
if (this.props.params.className === obj.className) {
this.state.data.unshift(obj);
}
this.state.counts[obj.className] += 1;
let newCount = this.state.counts[obj.className] + 1;
this.state.counts[obj.className] = newCount;
// update class count in currentApp context so that cache will have updated count
this.context.currentApp.setClassCountForClass(obj.className, newCount);
}

this.setState(state);
Expand Down Expand Up @@ -1455,6 +1457,8 @@ class Browser extends DashboardView {
lastMax: MAX_ROWS_FETCHED,
selection: {},
});
// update class count in currentApp context
this.context.currentApp.setClassCountForClass(className, 0);
}
});
} else {
Expand Down Expand Up @@ -1499,6 +1503,9 @@ class Browser extends DashboardView {
deletedNote = toDeleteObjectIds.length + ' ' + className + ' objects deleted';
}

// update class count in context currentApp so that cached values are updated
this.context.currentApp.setClassCountForClass(className, this.state.counts[className] - toDeleteObjectIds.length);

this.showNote(deletedNote, false);

if (this.props.params.className === className) {
Expand Down
4 changes: 4 additions & 0 deletions src/lib/ParseApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,10 @@ export default class ParseApp {
return promise;
}

setClassCountForClass(className, count) {
return this.classCounts.counts[className] = count;
}

setAppStoreURL(type, url) {
let path = '/apps/' + this.slug;
let promise = AJAX.put(path, {['parse_app[parse_app_metadata][url][' + type + ']']: url});
Expand Down