Skip to content

Commit a716540

Browse files
rizzomichaelgsteven-supersolid
authored andcommitted
Data browser updates object count when table is filtered (#652)
* Data browser updates object count when table is filtered * requested changes for changelog
1 parent 06ef96f commit a716540

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
* _Contributing to this repo? Add info about your change here to be included in next release_
66

7+
* Improvement: Data browser updates object count when table is filtered (#652), thanks to [Mike Rizzo](https://github.com/rizzomichaelg)
8+
79
### 1.0.23
810
* Improvement: Enabling web hooks (#584), thanks to [Antonio Davi Macedo Coelho de Castro](https://github.com/davimacedo)
911
* Improvement: Set autofocus on the username input field (#644), thanks to [Herman Liang](https://github.com/hermanliang)

src/dashboard/Data/Browser/Browser.react.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export default class Browser extends DashboardView {
5151

5252
relation: null,
5353
counts: {},
54+
filteredCounts: {},
5455
clp: {},
5556
filters: new List(),
5657
ordering: '-createdAt',
@@ -320,9 +321,21 @@ export default class Browser extends DashboardView {
320321
return data;
321322
}
322323

324+
async fetchParseDataCount(source, filters) {
325+
const query = queryFromFilters(source, filters);
326+
const count = await query.count({ useMasterKey: true });
327+
return count;
328+
}
329+
323330
async fetchData(source, filters = new List(), last) {
324331
const data = await this.fetchParseData(source, filters);
325-
this.setState({ data: data, filters, lastMax: 200 });
332+
var filteredCounts = { ...this.state.filteredCounts };
333+
if (filters.length > 0) {
334+
filteredCounts[source] = await this.fetchParseDataCount(source,filters);
335+
} else {
336+
delete filteredCounts[source];
337+
}
338+
this.setState({ data: data, filters, lastMax: 200 , filteredCounts: filteredCounts});
326339
}
327340

328341
async fetchRelation(relation, filters = new List()) {
@@ -781,9 +794,19 @@ export default class Browser extends DashboardView {
781794
columns[name] = info;
782795
});
783796

797+
var count;
798+
if (this.state.relation) {
799+
count = this.state.relationCount;
800+
} else {
801+
if (className in this.state.filteredCounts) {
802+
count = this.state.filteredCounts[className];
803+
} else {
804+
count = this.state.counts[className];
805+
}
806+
}
784807
browser = (
785808
<DataBrowser
786-
count={this.state.relation ? this.state.relationCount : this.state.counts[className]}
809+
count={count}
787810
perms={this.state.clp[className]}
788811
schema={schema}
789812
userPointers={userPointers}

0 commit comments

Comments
 (0)