Skip to content

Commit d485379

Browse files
committed
fix: handle view query errors
1 parent eab8cf3 commit d485379

File tree

1 file changed

+53
-8
lines changed

1 file changed

+53
-8
lines changed

src/dashboard/Data/Views/Views.react.js

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import TableView from 'dashboard/TableView.react';
55
import Toolbar from 'components/Toolbar/Toolbar.react';
66
import Parse from 'parse';
77
import React from 'react';
8+
import Notification from 'dashboard/Data/Browser/Notification.react';
89
import CreateViewDialog from './CreateViewDialog.react';
910
import * as ViewPreferences from 'lib/ViewPreferences';
1011
import { withRouter } from 'lib/withRouter';
@@ -24,8 +25,12 @@ class Views extends TableView {
2425
counts: {},
2526
data: [],
2627
order: [],
28+
columns: {},
2729
showCreate: false,
30+
lastError: null,
31+
lastNote: null,
2832
};
33+
this.noteTimeout = null;
2934
this.action = new SidebarAction('Create a view', () =>
3035
this.setState({ showCreate: true })
3136
);
@@ -59,6 +64,12 @@ class Views extends TableView {
5964
this.setState(({ counts }) => ({
6065
counts: { ...counts, [view.name]: res.length },
6166
}));
67+
})
68+
.catch(error => {
69+
this.showNote(
70+
`Request failed: ${error.message || 'Unknown error occurred'}`,
71+
true
72+
);
6273
});
6374
}
6475
});
@@ -68,12 +79,12 @@ class Views extends TableView {
6879

6980
loadData(name) {
7081
if (!name) {
71-
this.setState({ data: [], order: [] });
82+
this.setState({ data: [], order: [], columns: {} });
7283
return;
7384
}
7485
const view = (this.state.views || []).find(v => v.name === name);
7586
if (!view) {
76-
this.setState({ data: [], order: [] });
87+
this.setState({ data: [], order: [], columns: {} });
7788
return;
7889
}
7990
new Parse.Query(view.className)
@@ -104,11 +115,18 @@ class Views extends TableView {
104115
type = 'Object';
105116
}
106117
}
107-
columns[key] = { type };
108-
});
118+
columns[key] = { type };
109119
});
110-
const order = Object.keys(columns).map(name => ({ name, width: 150 }));
111-
this.setState({ data: results, order, columns });
120+
});
121+
const order = Object.keys(columns).map(name => ({ name, width: 150 }));
122+
this.setState({ data: results, order, columns });
123+
})
124+
.catch(error => {
125+
this.showNote(
126+
`Request failed: ${error.message || 'Unknown error occurred'}`,
127+
true
128+
);
129+
this.setState({ data: [], order: [], columns: {} });
112130
});
113131
}
114132

@@ -160,6 +178,7 @@ class Views extends TableView {
160178
}
161179

162180
renderExtras() {
181+
let extras = null;
163182
if (this.state.showCreate) {
164183
let classNames = [];
165184
if (this.props.schema?.data) {
@@ -168,7 +187,7 @@ class Views extends TableView {
168187
classNames = Object.keys(classes.toObject());
169188
}
170189
}
171-
return (
190+
extras = (
172191
<CreateViewDialog
173192
classes={classNames}
174193
onCancel={() => this.setState({ showCreate: false })}
@@ -187,6 +206,32 @@ class Views extends TableView {
187206
/>
188207
);
189208
}
190-
return null;
209+
let notification = null;
210+
if (this.state.lastError) {
211+
notification = <Notification note={this.state.lastError} isErrorNote={true} />;
212+
} else if (this.state.lastNote) {
213+
notification = <Notification note={this.state.lastNote} isErrorNote={false} />;
214+
}
215+
return (
216+
<>
217+
{extras}
218+
{notification}
219+
</>
220+
);
221+
}
222+
223+
showNote(message, isError) {
224+
if (!message) {
225+
return;
226+
}
227+
clearTimeout(this.noteTimeout);
228+
if (isError) {
229+
this.setState({ lastError: message, lastNote: null });
230+
} else {
231+
this.setState({ lastNote: message, lastError: null });
232+
}
233+
this.noteTimeout = setTimeout(() => {
234+
this.setState({ lastError: null, lastNote: null });
235+
}, 3500);
191236
}
192237
}

0 commit comments

Comments
 (0)