@@ -87,50 +87,55 @@ type ThemeDetailPageProps = {
87
87
themeList ?: ThemeType [ ] ;
88
88
orgId : string ;
89
89
location : Location & { state : LocationProp } ;
90
+ match : any ;
90
91
} ;
91
92
92
93
type ThemeDetailPageState = {
93
- name : string ;
94
- theme : ThemeDetail ;
94
+ name ? : string ;
95
+ theme ? : ThemeDetail ;
95
96
canLeave : boolean ;
96
97
compDsl ?: JSONObject ;
97
98
} ;
98
99
99
100
class ThemeDetailPage extends React . Component < ThemeDetailPageProps , ThemeDetailPageState > {
100
- themeDefault : ThemeDetail ;
101
+ themeDefault ? : ThemeDetail ;
101
102
readonly id : string ;
102
- readonly type : string ;
103
+ // readonly type: string;
103
104
readonly inputRef : React . RefObject < InputRef > ;
104
105
footerRef = React . createRef < HTMLDivElement > ( ) ;
105
106
106
107
constructor ( props : ThemeDetailPageProps ) {
107
108
super ( props ) ;
108
- const { name, id, theme, type } = props . location . state || { } ;
109
- if ( ! name || ! id || ! theme || ! type ) {
110
- history . replace ( BASE_URL ) ;
111
- window . location . reload ( ) ;
112
- }
113
-
114
- if ( theme . chart ) {
115
- this . themeDefault = theme ;
116
- } else {
117
- this . themeDefault = {
118
- ...theme ,
119
- chart : undefined ,
120
- } ;
121
- }
109
+ this . id = this . props . match . params . themeId ;
122
110
123
- this . id = id ;
124
- this . type = type ;
125
111
this . state = {
126
- theme,
127
- name,
128
112
canLeave : false ,
129
113
compDsl : undefined ,
130
114
} ;
131
115
this . inputRef = React . createRef ( ) ;
132
116
}
133
117
118
+ findCurrentTheme ( ) {
119
+ const themeDetail = this . props . themeList ?. find ( item => item . id === this . id ) ;
120
+ this . setState ( {
121
+ name : themeDetail ?. name ,
122
+ theme : themeDetail ?. theme ,
123
+ } ) ;
124
+ this . themeDefault = themeDetail ?. theme ;
125
+ }
126
+
127
+ componentDidMount ( ) {
128
+ if ( this . props . themeList ?. length ) {
129
+ this . findCurrentTheme ( ) ;
130
+ }
131
+ }
132
+
133
+ componentDidUpdate ( prevProps : ThemeDetailPageProps , prevState : ThemeDetailPageState ) {
134
+ if ( prevProps . themeList ?. length !== this . props . themeList ?. length ) {
135
+ this . findCurrentTheme ( ) ;
136
+ }
137
+ }
138
+
134
139
handleReset ( ) {
135
140
this . setState ( { theme : this . themeDefault } ) ;
136
141
}
@@ -164,6 +169,8 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
164
169
}
165
170
166
171
configChange ( params : configChangeParams ) {
172
+ if ( ! this . state . theme ) return ;
173
+
167
174
this . setState ( {
168
175
theme : {
169
176
...this . state . theme ,
@@ -194,25 +201,25 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
194
201
settingsKey : 'primary' ,
195
202
name : trans ( 'themeDetail.primary' ) ,
196
203
desc : trans ( 'themeDetail.primaryDesc' ) ,
197
- color : this . state . theme . primary ,
204
+ color : this . state . theme ? .primary ,
198
205
} ,
199
206
{
200
207
settingsKey : 'canvas' ,
201
208
name : trans ( 'themeDetail.canvas' ) ,
202
209
desc : trans ( 'themeDetail.canvasDesc' ) ,
203
- color : this . state . theme . canvas ,
210
+ color : this . state . theme ? .canvas ,
204
211
} ,
205
212
{
206
213
settingsKey : 'primarySurface' ,
207
214
name : trans ( 'themeDetail.primarySurface' ) ,
208
215
desc : trans ( 'themeDetail.primarySurfaceDesc' ) ,
209
- color : this . state . theme . primarySurface ,
216
+ color : this . state . theme ? .primarySurface ,
210
217
} ,
211
218
{
212
219
settingsKey : 'border' ,
213
220
name : trans ( 'themeDetail.borderColor' ) ,
214
221
desc : trans ( 'themeDetail.borderColorDesc' ) ,
215
- color : this . state . theme . border || this . state . theme . borderColor ,
222
+ color : this . state . theme ? .border || this . state . theme ? .borderColor ,
216
223
}
217
224
]
218
225
} ,
@@ -224,13 +231,13 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
224
231
settingsKey : 'textLight' ,
225
232
name : trans ( 'themeDetail.textLight' ) ,
226
233
desc : trans ( 'themeDetail.textLightDesc' ) ,
227
- color : this . state . theme . textLight ,
234
+ color : this . state . theme ? .textLight ,
228
235
} ,
229
236
{
230
237
settingsKey : 'textDark' ,
231
238
name : trans ( 'themeDetail.textDark' ) ,
232
239
desc : trans ( 'themeDetail.textDarkDesc' ) ,
233
- color : this . state . theme . textDark ,
240
+ color : this . state . theme ? .textDark ,
234
241
}
235
242
]
236
243
}
@@ -245,7 +252,7 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
245
252
name : trans ( 'themeDetail.fontFamily' ) ,
246
253
desc : trans ( 'themeDetail.fontFamilyDesc' ) ,
247
254
type : "fontFamily" ,
248
- value : this . state . theme . fontFamily ,
255
+ value : this . state . theme ? .fontFamily ,
249
256
}
250
257
]
251
258
} ,
@@ -260,21 +267,21 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
260
267
name : trans ( 'themeDetail.borderRadius' ) ,
261
268
desc : trans ( 'themeDetail.borderRadiusDesc' ) ,
262
269
type : "radius" ,
263
- value : this . state . theme . radius || this . state . theme . borderRadius ,
270
+ value : this . state . theme ? .radius || this . state . theme ? .borderRadius ,
264
271
} ,
265
272
{
266
273
settingsKey : 'borderWidth' ,
267
274
name : trans ( 'themeDetail.borderWidth' ) ,
268
275
desc : trans ( 'themeDetail.borderWidthDesc' ) ,
269
276
type : "borderWidth" ,
270
- value : this . state . theme . borderWidth ,
277
+ value : this . state . theme ? .borderWidth ,
271
278
} ,
272
279
{
273
280
settingsKey : 'borderStyle' ,
274
281
name : trans ( 'themeDetail.borderStyle' ) ,
275
282
desc : trans ( 'themeDetail.borderStyleDesc' ) ,
276
283
type : "borderStyle" ,
277
- value : this . state . theme . borderStyle ,
284
+ value : this . state . theme ? .borderStyle ,
278
285
}
279
286
]
280
287
} ,
@@ -286,26 +293,39 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
286
293
name : trans ( 'themeDetail.margin' ) ,
287
294
desc : trans ( 'themeDetail.marginDesc' ) ,
288
295
type : "margin" ,
289
- value : this . state . theme . margin ,
296
+ value : this . state . theme ? .margin ,
290
297
} ,
291
298
{
292
299
settingsKey : 'padding' ,
293
300
name : trans ( 'themeDetail.padding' ) ,
294
301
desc : trans ( 'themeDetail.paddingDesc' ) ,
295
302
type : "padding" ,
296
- value : this . state . theme . padding ,
303
+ value : this . state . theme ? .padding ,
297
304
} ,
298
305
{
299
306
settingsKey : 'gridColumns' ,
300
307
name : trans ( 'themeDetail.gridColumns' ) ,
301
308
desc : trans ( 'themeDetail.gridColumnsDesc' ) ,
302
309
type : "gridColumns" ,
303
- value : this . state . theme . gridColumns ,
310
+ value : this . state . theme ? .gridColumns ,
304
311
}
305
312
]
306
313
} ,
307
314
] ;
308
315
316
+ if ( ! this . themeDefault ) {
317
+ return (
318
+ < Flex align = "center" justify = "center" vertical style = { {
319
+ height : '300px' ,
320
+ width : '400px' ,
321
+ margin : '0 auto' ,
322
+ } } >
323
+ < h4 > Oops! Theme not found.</ h4 >
324
+ < button onClick = { ( ) => history . push ( THEME_SETTING ) } style = { { background : '#4965f2' , border : '1px solid #4965f2' , color : '#ffffff' , borderRadius :'6px' } } > Back to Themes</ button >
325
+ </ Flex >
326
+ )
327
+ }
328
+
309
329
return (
310
330
< >
311
331
< Prompt
@@ -363,7 +383,7 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
363
383
</ List . Item >
364
384
) }
365
385
{ item . items . map ( ( colorItem ) => (
366
- < Tooltip title = { colorItem . desc } placement = "right" >
386
+ < Tooltip key = { colorItem . settingsKey } title = { colorItem . desc } placement = "right" >
367
387
< List . Item key = { colorItem . settingsKey } >
368
388
< ThemeSettingsSelector
369
389
themeSettingKey = { colorItem . settingsKey }
@@ -381,7 +401,7 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
381
401
) }
382
402
/>
383
403
< Divider type = "vertical" style = { { height : "610px" } } />
384
- < PreviewApp style = { { marginTop : '3px' , height : "620px" , width : "100%" } } theme = { this . state . theme } dsl = { dsl } />
404
+ < PreviewApp style = { { marginTop : '3px' , height : "620px" , width : "100%" } } theme = { this . state . theme ! } dsl = { dsl } />
385
405
</ Flex >
386
406
</ Card >
387
407
</ ThemeSettingsView >
@@ -403,7 +423,7 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
403
423
</ List . Item >
404
424
) }
405
425
{ item . items . map ( ( layoutSettingsItem ) => (
406
- < Tooltip title = { layoutSettingsItem . desc } placement = "right" >
426
+ < Tooltip key = { layoutSettingsItem . settingsKey } title = { layoutSettingsItem . desc } placement = "right" >
407
427
< List . Item key = { layoutSettingsItem . settingsKey } >
408
428
{ layoutSettingsItem . type == "fontFamily" &&
409
429
< ThemeSettingsSelector
@@ -425,7 +445,7 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
425
445
) }
426
446
/>
427
447
< Divider type = "vertical" style = { { height : "610px" } } />
428
- < PreviewApp style = { { marginTop : '3px' , height : "620px" , width : "100%" } } theme = { this . state . theme } dsl = { dsl } />
448
+ < PreviewApp style = { { marginTop : '3px' , height : "620px" , width : "100%" } } theme = { this . state . theme ! } dsl = { dsl } />
429
449
</ Flex >
430
450
</ Card >
431
451
</ ThemeSettingsView >
@@ -447,7 +467,7 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
447
467
</ List . Item >
448
468
) }
449
469
{ item . items . map ( ( layoutSettingsItem ) => (
450
- < Tooltip title = { layoutSettingsItem . desc } placement = "right" >
470
+ < Tooltip key = { layoutSettingsItem . settingsKey } title = { layoutSettingsItem . desc } placement = "right" >
451
471
< List . Item key = { layoutSettingsItem . settingsKey } >
452
472
{ layoutSettingsItem . type == "radius" &&
453
473
< ThemeSettingsSelector
@@ -516,7 +536,7 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
516
536
) }
517
537
/>
518
538
< Divider type = "vertical" style = { { height : "610px" } } />
519
- < PreviewApp style = { { marginTop : '3px' , height : "620px" , width : "100%" } } theme = { this . state . theme } dsl = { dsl } />
539
+ < PreviewApp style = { { marginTop : '3px' , height : "620px" , width : "100%" } } theme = { this . state . theme ! } dsl = { dsl } />
520
540
</ Flex >
521
541
</ Card >
522
542
</ ThemeSettingsView >
@@ -534,18 +554,20 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
534
554
styleKey : string ,
535
555
compStyle : Record < string , string >
536
556
) => {
537
- this . setState ( {
538
- theme : {
539
- ...this . state . theme ,
540
- components : {
541
- ...this . state . theme . components ,
542
- [ compName ] : {
543
- ...this . state . theme . components ?. [ compName ] ,
544
- [ styleKey ] : compStyle ,
557
+ if ( this . state . theme ) {
558
+ this . setState ( {
559
+ theme : {
560
+ ...this . state . theme ,
561
+ components : {
562
+ ...this . state . theme . components ,
563
+ [ compName ] : {
564
+ ...this . state . theme . components ?. [ compName ] ,
565
+ [ styleKey ] : compStyle ,
566
+ }
545
567
}
546
- }
547
- } ,
548
- } ) ;
568
+ } ,
569
+ } ) ;
570
+ }
549
571
} }
550
572
/>
551
573
</ Card >
@@ -571,7 +593,7 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
571
593
</ List . Item >
572
594
< List . Item style = { { width : "260px" , height : "370px" , padding :"10px" } } >
573
595
< CodeEditor
574
- value = { this . state . theme . chart || "" }
596
+ value = { this . state . theme ? .chart || "" }
575
597
onChange = { ( value ) => this . configChange ( {
576
598
themeSettingKey : "chart" ,
577
599
chart : value . doc . toString ( ) ? value . doc . toString ( ) : undefined ,
@@ -585,7 +607,7 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
585
607
</ List >
586
608
</ ChartInput >
587
609
< Divider type = "vertical" style = { { height : "370px" } } />
588
- < PreviewApp style = { { height : "380px" , width : "100%" , margin : "0" } } theme = { this . state . theme } dsl = { chartDsl } />
610
+ < PreviewApp style = { { height : "380px" , width : "100%" , margin : "0" } } theme = { this . state . theme ! } dsl = { chartDsl } />
589
611
</ Flex >
590
612
</ Card >
591
613
</ ThemeSettingsView >
0 commit comments