Skip to content

Commit b377452

Browse files
douglasmuraokadavimacedo
authored andcommitted
feat(Database Browser): Select all objects (#1219)
* feat(Database Browser): Select all objects Allows users to select all objects. This is only enabled when the lazy loading has loaded all possible objects, since we don't have a way to select all objects based on a query. * fix: Select all checkbox title when disabled * fix: Select all visible objects * feat: Fetch more objects when deleting
1 parent e0f09d0 commit b377452

File tree

4 files changed

+34
-26
lines changed

4 files changed

+34
-26
lines changed

src/components/DataBrowserHeaderBar/DataBrowserHeaderBar.react.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ import { DndProvider } from 'react-dnd'
1414

1515
export default class DataBrowserHeaderBar extends React.Component {
1616
render() {
17-
let { headers, onResize, selectAll, onAddColumn, updateOrdering, readonly, preventSchemaEdits } = this.props;
17+
let { headers, onResize, selectAll, onAddColumn, updateOrdering, readonly, preventSchemaEdits, selected } = this.props;
1818
let elements = [
19-
// Note: bulk checkbox is disabled as all rows are selected (not just visible ones due to current lazy loading implementation)
20-
// TODO: add bulk checking only visible rows
2119
<div key='check' className={[styles.wrap, styles.check].join(' ')}>
22-
{readonly ? null : <input className={styles.disabled} type='checkbox' disabled={true} checked={false} onChange={(e) => selectAll(e.target.checked)} />}
20+
{readonly
21+
? null
22+
: <input
23+
type='checkbox'
24+
checked={selected}
25+
onChange={(e) => selectAll(e.target.checked)} />
26+
}
2327
</div>
2428
];
2529

src/components/DataBrowserHeaderBar/DataBrowserHeaderBar.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,3 @@
6464
margin: 0 -4px;
6565
cursor: ew-resize;
6666
}
67-
68-
.disabled {
69-
cursor: not-allowed;
70-
}

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ import { Helmet } from 'react-helmet';
3737
import PropTypes from 'lib/PropTypes';
3838
import ParseApp from 'lib/ParseApp';
3939

40+
// The initial and max amount of rows fetched by lazy loading
41+
const MAX_ROWS_FETCHED = 200;
42+
4043
export default
4144
@subscribeTo('Schema', 'schema')
4245
class Browser extends DashboardView {
@@ -337,7 +340,7 @@ class Browser extends DashboardView {
337340
query.ascending(field)
338341
}
339342

340-
query.limit(200);
343+
query.limit(MAX_ROWS_FETCHED);
341344

342345
let promise = query.find({ useMasterKey: true });
343346
let isUnique = false;
@@ -374,7 +377,7 @@ class Browser extends DashboardView {
374377
} else {
375378
delete filteredCounts[source];
376379
}
377-
this.setState({ data: data, filters, lastMax: 200 , filteredCounts: filteredCounts});
380+
this.setState({ data: data, filters, lastMax: MAX_ROWS_FETCHED , filteredCounts: filteredCounts});
378381
}
379382

380383
async fetchRelation(relation, filters = new List()) {
@@ -386,7 +389,7 @@ class Browser extends DashboardView {
386389
selection: {},
387390
data,
388391
filters,
389-
lastMax: 200,
392+
lastMax: MAX_ROWS_FETCHED,
390393
});
391394
}
392395

@@ -429,14 +432,16 @@ class Browser extends DashboardView {
429432
query.lessThan('createdAt', this.state.data[this.state.data.length - 1].get('createdAt'));
430433
}
431434
query.addDescending('createdAt');
432-
query.limit(200);
435+
query.limit(MAX_ROWS_FETCHED);
433436

434437
query.find({ useMasterKey: true }).then((nextPage) => {
435438
if (className === this.props.params.className) {
436-
this.setState((state) => ({ data: state.data.concat(nextPage)}));
439+
this.setState((state) => ({
440+
data: state.data.concat(nextPage)
441+
}));
437442
}
438443
});
439-
this.setState({ lastMax: this.state.lastMax + 200 });
444+
this.setState({ lastMax: this.state.lastMax + MAX_ROWS_FETCHED });
440445
}
441446

442447
updateFilters(filters) {
@@ -587,7 +592,7 @@ class Browser extends DashboardView {
587592
this.state.counts[className] = 0;
588593
this.setState({
589594
data: [],
590-
lastMax: 200,
595+
lastMax: MAX_ROWS_FETCHED,
591596
selection: {},
592597
});
593598
}
@@ -640,7 +645,14 @@ class Browser extends DashboardView {
640645
this.state.data.splice(indexes[i] - i, 1);
641646
}
642647
this.state.counts[className] -= indexes.length;
643-
this.forceUpdate();
648+
649+
// If after deletion, the remaining elements on the table is lesser than the maximum allowed elements
650+
// we fetch more data to fill the table
651+
if (this.state.data.length < MAX_ROWS_FETCHED) {
652+
this.prefetchData(this.props, this.context);
653+
} else {
654+
this.forceUpdate();
655+
}
644656
}
645657
}, (error) => {
646658
let errorDeletingNote = null;
@@ -669,9 +681,6 @@ class Browser extends DashboardView {
669681

670682
selectRow(id, checked) {
671683
this.setState(({ selection }) => {
672-
if (id === '*') {
673-
return { selection: checked ? { '*': true } : {} };
674-
}
675684
if (checked) {
676685
selection[id] = true;
677686
} else {

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ const ROW_HEIGHT = 31;
2323

2424
const READ_ONLY = [ 'objectId', 'createdAt', 'updatedAt' ];
2525

26-
let scrolling = false;
27-
2826
export default class BrowserTable extends React.Component {
2927
constructor() {
3028
super();
@@ -59,9 +57,6 @@ export default class BrowserTable extends React.Component {
5957
}
6058

6159
handleScroll() {
62-
if (scrolling) {
63-
return;
64-
}
6560
if (!this.props.data || this.props.data.length === 0) {
6661
return;
6762
}
@@ -329,8 +324,12 @@ export default class BrowserTable extends React.Component {
329324
<div className={[styles.browser, browserUtils.isSafari() ? styles.safari : ''].join(' ')}>
330325
{table}
331326
<DataBrowserHeaderBar
332-
selected={this.props.selection['*']}
333-
selectAll={this.props.selectRow.bind(null, '*')}
327+
selected={
328+
this.props.selection &&
329+
this.props.data &&
330+
Object.values(this.props.selection).filter(checked => checked).length === this.props.data.length
331+
}
332+
selectAll={checked => this.props.data.forEach(({ id }) => this.props.selectRow(id, checked))}
334333
headers={headers}
335334
updateOrdering={this.props.updateOrdering}
336335
readonly={!!this.props.relation || !!this.props.isUnique}

0 commit comments

Comments
 (0)