Skip to content
Closed
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
49 changes: 11 additions & 38 deletions src/dashboard/Data/Browser/Browser.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
lastMax: -1,
newObject: null,
editCloneRows: null,
fetchingNextPage: false,

lastError: null,
lastNote: null,
Expand Down Expand Up @@ -975,60 +976,32 @@
}

async fetchNextPage() {
if (!this.state.data || this.state.isUnique) {
if (!this.state.data || this.state.isUnique || this.state.fetchingNextPage) {
return null;
}
this.setState({ fetchingNextPage: true });
const className = this.props.params.className;
const source = this.state.relation || className;
let query = await queryFromFilters(source, this.state.filters);

Check failure on line 985 in src/dashboard/Data/Browser/Browser.react.js

View workflow job for this annotation

GitHub Actions / Lint

'query' is never reassigned. Use 'const' instead
if (this.state.ordering !== '-createdAt') {
// Construct complex pagination query
const equalityQuery = queryFromFilters(source, this.state.filters);
let field = this.state.ordering;
let ascending = true;
let comp = this.state.data[this.state.data.length - 1].get(field);
if (field === 'objectId' || field === '-objectId') {
comp = this.state.data[this.state.data.length - 1].id;
}
if (field[0] === '-') {
field = field.substr(1);
query.lessThan(field, comp);
ascending = false;
} else {
query.greaterThan(field, comp);
}
if (field === 'createdAt') {
equalityQuery.greaterThan(
'createdAt',
this.state.data[this.state.data.length - 1].get('createdAt')
);
} else {
equalityQuery.lessThan(
'createdAt',
this.state.data[this.state.data.length - 1].get('createdAt')
);
equalityQuery.equalTo(field, comp);
}
query = Parse.Query.or(query, equalityQuery);
if (ascending) {
query.ascending(this.state.ordering);
} else {
query.descending(this.state.ordering.substr(1));
}
if (this.state.ordering[0] === '-') {
query.descending(this.state.ordering.substr(1));
} else {
query.lessThan('createdAt', this.state.data[this.state.data.length - 1].get('createdAt'));
query.addDescending('createdAt');
query.ascending(this.state.ordering);
}
query.skip(this.state.lastMax);
query.limit(MAX_ROWS_FETCHED);
this.excludeFields(query, source);

const { useMasterKey } = this.state;
query.find({ useMasterKey }).then(nextPage => {
if (className === this.props.params.className) {
this.setState(state => ({
data: state.data.concat(nextPage),
}));
}
}).catch(() => {
this.setState({ lastMax: this.state.lastMax - MAX_ROWS_FETCHED });
}).finally(() => {
this.setState({ fetchingNextPage: false });
});
this.setState({ lastMax: this.state.lastMax + MAX_ROWS_FETCHED });
}
Expand Down
25 changes: 13 additions & 12 deletions src/dashboard/Data/Browser/BrowserTable.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class BrowserTable extends React.Component {
maxWidth: window.innerWidth - 300,
};
this.handleScroll = this.handleScroll.bind(this);
this.tableRef = React.createRef();
this.scrollRef = React.createRef();
this.handleResize = this.handleResize.bind(this);
this.updateMaxWidth = this.updateMaxWidth.bind(this);
}
Expand All @@ -45,27 +45,27 @@ export default class BrowserTable extends React.Component {
this.setState({
offset: 0,
});
this.tableRef.current.scrollTop = 0;
this.scrollRef.current.scrollTop = 0;
} else if (this.props.newObject !== props.newObject) {
this.setState({ offset: 0 });
this.tableRef.current.scrollTop = 0;
this.scrollRef.current.scrollTop = 0;
} else if (this.props.ordering !== props.ordering) {
this.setState({ offset: 0 });
this.tableRef.current.scrollTop = 0;
this.scrollRef.current.scrollTop = 0;
} else if (this.props.filters.size !== props.filters.size) {
this.setState({ offset: 0 }, () => {
this.tableRef.current.scrollTop = 0;
this.scrollRef.current.scrollTop = 0;
});
}
}

componentDidMount() {
this.tableRef.current.addEventListener('scroll', this.handleScroll);
this.scrollRef.current.addEventListener('scroll', this.handleScroll);
window.addEventListener('resize', this.updateMaxWidth);
}

componentWillUnmount() {
this.tableRef.current.removeEventListener('scroll', this.handleScroll);
this.scrollRef.current.removeEventListener('scroll', this.handleScroll);
window.removeEventListener('resize', this.updateMaxWidth);
}

Expand Down Expand Up @@ -98,7 +98,7 @@ export default class BrowserTable extends React.Component {
return;
}
requestAnimationFrame(() => {
const currentScrollTop = this.tableRef.current.scrollTop;
const currentScrollTop = this.scrollRef.current.scrollTop;
let rowsAbove = Math.floor(currentScrollTop / ROW_HEIGHT);
let offset = this.state.offset;
const currentRow = rowsAbove - this.state.offset;
Expand All @@ -116,7 +116,7 @@ export default class BrowserTable extends React.Component {
}
if (this.state.offset !== offset) {
this.setState({ offset });
this.tableRef.current.scrollTop = currentScrollTop;
this.scrollRef.current.scrollTop = currentScrollTop;
}
if (this.props.maxFetched - offset <= ROWS_OFFSET * 1.4) {
this.props.fetchNextPage();
Expand Down Expand Up @@ -154,7 +154,7 @@ export default class BrowserTable extends React.Component {
required,
}));
let editor = null;
let table = <div ref={this.tableRef} />;
let table = <div/>;
if (this.props.data) {
const rowWidth = this.props.order.reduce(
(rowWidth, { visible, width }) => (visible ? rowWidth + width : rowWidth),
Expand Down Expand Up @@ -518,7 +518,7 @@ export default class BrowserTable extends React.Component {

if (this.props.newObject || this.props.data.length > 0) {
table = (
<div className={styles.table} ref={this.tableRef}>
<div className={styles.table}>
<div style={{ height: Math.max(0, this.state.offset * ROW_HEIGHT) }} />
{editCloneRows}
{newRow}
Expand All @@ -537,7 +537,7 @@ export default class BrowserTable extends React.Component {
);
} else {
table = (
<div className={styles.table} ref={this.tableRef}>
<div className={styles.table}>
<div className={styles.empty}>
{this.props.relation ? (
<EmptyState
Expand Down Expand Up @@ -568,6 +568,7 @@ export default class BrowserTable extends React.Component {

return (
<div
ref={this.scrollRef}
className={styles.browser}
style={{
right: rightValue,
Expand Down
Loading