@@ -5,6 +5,7 @@ import TableView from 'dashboard/TableView.react';
5
5
import Toolbar from 'components/Toolbar/Toolbar.react' ;
6
6
import Parse from 'parse' ;
7
7
import React from 'react' ;
8
+ import Notification from 'dashboard/Data/Browser/Notification.react' ;
8
9
import CreateViewDialog from './CreateViewDialog.react' ;
9
10
import * as ViewPreferences from 'lib/ViewPreferences' ;
10
11
import { withRouter } from 'lib/withRouter' ;
@@ -24,8 +25,12 @@ class Views extends TableView {
24
25
counts : { } ,
25
26
data : [ ] ,
26
27
order : [ ] ,
28
+ columns : { } ,
27
29
showCreate : false ,
30
+ lastError : null ,
31
+ lastNote : null ,
28
32
} ;
33
+ this . noteTimeout = null ;
29
34
this . action = new SidebarAction ( 'Create a view' , ( ) =>
30
35
this . setState ( { showCreate : true } )
31
36
) ;
@@ -59,6 +64,12 @@ class Views extends TableView {
59
64
this . setState ( ( { counts } ) => ( {
60
65
counts : { ...counts , [ view . name ] : res . length } ,
61
66
} ) ) ;
67
+ } )
68
+ . catch ( error => {
69
+ this . showNote (
70
+ `Request failed: ${ error . message || 'Unknown error occurred' } ` ,
71
+ true
72
+ ) ;
62
73
} ) ;
63
74
}
64
75
} ) ;
@@ -68,12 +79,12 @@ class Views extends TableView {
68
79
69
80
loadData ( name ) {
70
81
if ( ! name ) {
71
- this . setState ( { data : [ ] , order : [ ] } ) ;
82
+ this . setState ( { data : [ ] , order : [ ] , columns : { } } ) ;
72
83
return ;
73
84
}
74
85
const view = ( this . state . views || [ ] ) . find ( v => v . name === name ) ;
75
86
if ( ! view ) {
76
- this . setState ( { data : [ ] , order : [ ] } ) ;
87
+ this . setState ( { data : [ ] , order : [ ] , columns : { } } ) ;
77
88
return ;
78
89
}
79
90
new Parse . Query ( view . className )
@@ -104,11 +115,18 @@ class Views extends TableView {
104
115
type = 'Object' ;
105
116
}
106
117
}
107
- columns [ key ] = { type } ;
108
- } ) ;
118
+ columns [ key ] = { type } ;
109
119
} ) ;
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 : { } } ) ;
112
130
} ) ;
113
131
}
114
132
@@ -160,6 +178,7 @@ class Views extends TableView {
160
178
}
161
179
162
180
renderExtras ( ) {
181
+ let extras = null ;
163
182
if ( this . state . showCreate ) {
164
183
let classNames = [ ] ;
165
184
if ( this . props . schema ?. data ) {
@@ -168,7 +187,7 @@ class Views extends TableView {
168
187
classNames = Object . keys ( classes . toObject ( ) ) ;
169
188
}
170
189
}
171
- return (
190
+ extras = (
172
191
< CreateViewDialog
173
192
classes = { classNames }
174
193
onCancel = { ( ) => this . setState ( { showCreate : false } ) }
@@ -187,6 +206,32 @@ class Views extends TableView {
187
206
/>
188
207
) ;
189
208
}
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 ) ;
191
236
}
192
237
}
0 commit comments