@@ -20,19 +20,23 @@ import {
20
20
EuiFlexGrid ,
21
21
EuiFlexGroup ,
22
22
EuiImage ,
23
- EuiAccordion ,
24
23
EuiCheckbox ,
25
24
EuiCheckboxGroup ,
26
25
EuiCheckableCardProps ,
27
26
EuiCheckboxGroupProps ,
28
27
EuiCheckboxProps ,
29
28
EuiFieldTextProps ,
29
+ EuiColorPicker ,
30
+ EuiColorPickerProps ,
31
+ EuiComboBox ,
32
+ EuiComboBoxProps ,
30
33
} from '@elastic/eui' ;
31
34
32
35
import { WorkspaceTemplate } from '../../../../../core/types' ;
33
36
import { AppNavLinkStatus , ApplicationStart } from '../../../../../core/public' ;
34
37
import { useApplications , useWorkspaceTemplate } from '../../hooks' ;
35
38
import { WORKSPACE_OP_TYPE_CREATE , WORKSPACE_OP_TYPE_UPDATE } from '../../../common/constants' ;
39
+ import { WorkspaceIconSelector } from './workspace_icon_selector' ;
36
40
37
41
interface WorkspaceFeature {
38
42
id : string ;
@@ -49,6 +53,9 @@ export interface WorkspaceFormData {
49
53
name : string ;
50
54
description ?: string ;
51
55
features : string [ ] ;
56
+ color ?: string ;
57
+ icon ?: string ;
58
+ defaultVISTheme ?: string ;
52
59
}
53
60
54
61
type WorkspaceFormErrors = { [ key in keyof WorkspaceFormData ] ?: string } ;
@@ -59,6 +66,8 @@ const isWorkspaceFeatureGroup = (
59
66
60
67
const workspaceHtmlIdGenerator = htmlIdGenerator ( ) ;
61
68
69
+ const defaultVISThemeOptions = [ { label : 'Categorical' , value : 'categorical' } ] ;
70
+
62
71
interface WorkspaceFormProps {
63
72
application : ApplicationStart ;
64
73
onSubmit ?: ( formData : WorkspaceFormData ) => void ;
@@ -76,6 +85,10 @@ export const WorkspaceForm = ({
76
85
77
86
const [ name , setName ] = useState ( defaultValues ?. name ) ;
78
87
const [ description , setDescription ] = useState ( defaultValues ?. description ) ;
88
+ const [ color , setColor ] = useState ( defaultValues ?. color ) ;
89
+ const [ icon , setIcon ] = useState ( defaultValues ?. icon ) ;
90
+ const [ defaultVISTheme , setDefaultVISTheme ] = useState ( defaultValues ?. defaultVISTheme ) ;
91
+
79
92
const [ selectedTemplateId , setSelectedTemplateId ] = useState < string > ( ) ;
80
93
const [ selectedFeatureIds , setSelectedFeatureIds ] = useState ( defaultValues ?. features || [ ] ) ;
81
94
const selectedTemplate = workspaceTemplates . find (
@@ -87,6 +100,9 @@ export const WorkspaceForm = ({
87
100
name,
88
101
description,
89
102
features : selectedFeatureIds ,
103
+ color,
104
+ icon,
105
+ defaultVISTheme,
90
106
} ) ;
91
107
const getFormDataRef = useRef ( getFormData ) ;
92
108
getFormDataRef . current = getFormData ;
@@ -120,6 +136,11 @@ export const WorkspaceForm = ({
120
136
} , [ ] ) ;
121
137
} , [ applications ] ) ;
122
138
139
+ const selectedDefaultVISThemeOptions = useMemo (
140
+ ( ) => defaultVISThemeOptions . filter ( ( item ) => item . value === defaultVISTheme ) ,
141
+ [ defaultVISTheme ]
142
+ ) ;
143
+
123
144
if ( ! formIdRef . current ) {
124
145
formIdRef . current = workspaceHtmlIdGenerator ( ) ;
125
146
}
@@ -198,6 +219,20 @@ export const WorkspaceForm = ({
198
219
setDescription ( e . target . value ) ;
199
220
} , [ ] ) ;
200
221
222
+ const handleColorChange = useCallback < Required < EuiColorPickerProps > [ 'onChange' ] > ( ( text ) => {
223
+ setColor ( text ) ;
224
+ } , [ ] ) ;
225
+
226
+ const handleIconChange = useCallback ( ( newIcon : string ) => {
227
+ setIcon ( newIcon ) ;
228
+ } , [ ] ) ;
229
+
230
+ const handleDefaultVISThemeInputChange = useCallback <
231
+ Required < EuiComboBoxProps < string > > [ 'onChange' ]
232
+ > ( ( options ) => {
233
+ setDefaultVISTheme ( options [ 0 ] ?. value ) ;
234
+ } , [ ] ) ;
235
+
201
236
return (
202
237
< EuiForm id = { formIdRef . current } onSubmit = { handleFormSubmit } component = "form" >
203
238
< EuiPanel >
@@ -217,6 +252,25 @@ export const WorkspaceForm = ({
217
252
>
218
253
< EuiFieldText value = { description } onChange = { handleDescriptionInputChange } />
219
254
</ EuiFormRow >
255
+ < EuiFormRow label = "Color" isInvalid = { ! ! formErrors . color } error = { formErrors . color } >
256
+ < EuiColorPicker color = { color } onChange = { handleColorChange } />
257
+ </ EuiFormRow >
258
+ < EuiFormRow label = "Icon" isInvalid = { ! ! formErrors . icon } error = { formErrors . icon } >
259
+ < WorkspaceIconSelector value = { icon } onChange = { handleIconChange } color = { color } />
260
+ </ EuiFormRow >
261
+ < EuiFormRow
262
+ label = "Default VIS Theme"
263
+ isInvalid = { ! ! formErrors . defaultVISTheme }
264
+ error = { formErrors . defaultVISTheme }
265
+ >
266
+ < EuiComboBox
267
+ options = { defaultVISThemeOptions }
268
+ singleSelection
269
+ onChange = { handleDefaultVISThemeInputChange }
270
+ selectedOptions = { selectedDefaultVISThemeOptions }
271
+ isClearable = { false }
272
+ />
273
+ </ EuiFormRow >
220
274
</ EuiPanel >
221
275
< EuiSpacer />
222
276
< EuiPanel >
@@ -267,74 +321,65 @@ export const WorkspaceForm = ({
267
321
< EuiSpacer />
268
322
</ >
269
323
) }
270
- < EuiAccordion
271
- id = { workspaceHtmlIdGenerator ( ) }
272
- buttonContent = {
273
- < >
274
- < EuiTitle size = "xs" >
275
- < h3 > Advanced Options</ h3 >
276
- </ EuiTitle >
277
- </ >
278
- }
279
- >
280
- < EuiFlexGrid style = { { paddingLeft : 20 , paddingTop : 20 } } columns = { 2 } >
281
- { featureOrGroups . map ( ( featureOrGroup ) => {
282
- const features = isWorkspaceFeatureGroup ( featureOrGroup )
324
+ </ EuiPanel >
325
+ < EuiSpacer />
326
+ < EuiPanel >
327
+ < EuiTitle size = "s" >
328
+ < h2 > Workspace features</ h2 >
329
+ </ EuiTitle >
330
+ < EuiFlexGrid style = { { paddingLeft : 20 , paddingTop : 20 } } columns = { 2 } >
331
+ { featureOrGroups . map ( ( featureOrGroup ) => {
332
+ const features = isWorkspaceFeatureGroup ( featureOrGroup ) ? featureOrGroup . features : [ ] ;
333
+ const selectedIds = selectedFeatureIds . filter ( ( id ) =>
334
+ ( isWorkspaceFeatureGroup ( featureOrGroup )
283
335
? featureOrGroup . features
284
- : [ ] ;
285
- const selectedIds = selectedFeatureIds . filter ( ( id ) =>
286
- ( isWorkspaceFeatureGroup ( featureOrGroup )
287
- ? featureOrGroup . features
288
- : [ featureOrGroup ]
289
- ) . find ( ( item ) => item . id === id )
290
- ) ;
291
- return (
292
- < EuiFlexItem key = { featureOrGroup . name } >
293
- < EuiCheckbox
294
- id = {
295
- isWorkspaceFeatureGroup ( featureOrGroup )
296
- ? featureOrGroup . name
297
- : featureOrGroup . id
298
- }
299
- onChange = {
300
- isWorkspaceFeatureGroup ( featureOrGroup )
301
- ? handleFeatureGroupChange
302
- : handleFeatureCheckboxChange
303
- }
304
- label = { `${
305
- featureOrGroup . name === 'OpenSearch Plugins'
306
- ? 'OpenSearch Features'
307
- : featureOrGroup . name
308
- } ${ features . length > 0 ? `(${ selectedIds . length } /${ features . length } )` : '' } `}
309
- checked = { selectedIds . length > 0 }
310
- indeterminate = {
311
- isWorkspaceFeatureGroup ( featureOrGroup ) &&
312
- selectedIds . length > 0 &&
313
- selectedIds . length < features . length
314
- }
336
+ : [ featureOrGroup ]
337
+ ) . find ( ( item ) => item . id === id )
338
+ ) ;
339
+ return (
340
+ < EuiFlexItem key = { featureOrGroup . name } >
341
+ < EuiCheckbox
342
+ id = {
343
+ isWorkspaceFeatureGroup ( featureOrGroup )
344
+ ? featureOrGroup . name
345
+ : featureOrGroup . id
346
+ }
347
+ onChange = {
348
+ isWorkspaceFeatureGroup ( featureOrGroup )
349
+ ? handleFeatureGroupChange
350
+ : handleFeatureCheckboxChange
351
+ }
352
+ label = { `${ featureOrGroup . name } ${
353
+ features . length > 0 ? `(${ selectedIds . length } /${ features . length } )` : ''
354
+ } `}
355
+ checked = { selectedIds . length > 0 }
356
+ indeterminate = {
357
+ isWorkspaceFeatureGroup ( featureOrGroup ) &&
358
+ selectedIds . length > 0 &&
359
+ selectedIds . length < features . length
360
+ }
361
+ />
362
+ { isWorkspaceFeatureGroup ( featureOrGroup ) && (
363
+ < EuiCheckboxGroup
364
+ options = { featureOrGroup . features . map ( ( item ) => ( {
365
+ id : item . id ,
366
+ label : item . name ,
367
+ } ) ) }
368
+ idToSelectedMap = { selectedIds . reduce (
369
+ ( previousValue , currentValue ) => ( {
370
+ ...previousValue ,
371
+ [ currentValue ] : true ,
372
+ } ) ,
373
+ { }
374
+ ) }
375
+ onChange = { handleFeatureChange }
376
+ style = { { marginLeft : 40 } }
315
377
/>
316
- { isWorkspaceFeatureGroup ( featureOrGroup ) && (
317
- < EuiCheckboxGroup
318
- options = { featureOrGroup . features . map ( ( item ) => ( {
319
- id : item . id ,
320
- label : item . name ,
321
- } ) ) }
322
- idToSelectedMap = { selectedIds . reduce (
323
- ( previousValue , currentValue ) => ( {
324
- ...previousValue ,
325
- [ currentValue ] : true ,
326
- } ) ,
327
- { }
328
- ) }
329
- onChange = { handleFeatureChange }
330
- style = { { marginLeft : 40 } }
331
- />
332
- ) }
333
- </ EuiFlexItem >
334
- ) ;
335
- } ) }
336
- </ EuiFlexGrid >
337
- </ EuiAccordion >
378
+ ) }
379
+ </ EuiFlexItem >
380
+ ) ;
381
+ } ) }
382
+ </ EuiFlexGrid >
338
383
</ EuiPanel >
339
384
< EuiSpacer />
340
385
< EuiText textAlign = "right" >
0 commit comments