@@ -5,21 +5,36 @@ import MiqFormRenderer from '@@ddf';
55import createSchema from './visual-settings-form.schema' ;
66
77const VisualSettingsForm = ( { recordId } ) => {
8- const [ { initialValues, timezoneOptions, isLoading } , setState ] = useState ( { isLoading : true } ) ;
8+ const [ {
9+ initialValues, shortcuts, timezoneOptions, isLoading,
10+ } , setState ] = useState ( { isLoading : true } ) ;
911
1012 useEffect ( ( ) => {
11- API . get ( '/api' ) . then ( ( { timezones } ) => {
12- const timezoneOptions = [ ] ;
13- timezones . forEach ( ( timezone ) => {
14- timezoneOptions . push ( { value : timezone . name , label : timezone . description } ) ;
13+ API . get ( '/api/shortcuts?expand=resources&attributes=description,url' ) . then ( ( { resources } ) => {
14+ const shortcuts = [ ] ;
15+
16+ resources . forEach ( ( shortcut ) => {
17+ shortcuts . push ( { value : shortcut . url , label : shortcut . description } ) ;
18+ } ) ;
19+
20+ return shortcuts ;
21+ } ) . then ( ( shortcuts ) => {
22+ API . get ( '/api' ) . then ( ( { timezones } ) => {
23+ const timezoneOptions = [ ] ;
24+
25+ timezones . forEach ( ( timezone ) => {
26+ timezoneOptions . push ( { value : timezone . name , label : timezone . description } ) ;
27+ } ) ;
28+
29+ return timezoneOptions ;
30+ } ) . then ( ( timezoneOptions ) => {
31+ API . get ( `/api/users/${ recordId } ?attributes=settings` ) . then ( ( { settings } ) => setState ( {
32+ initialValues : settings ,
33+ shortcuts,
34+ timezoneOptions,
35+ isLoading : false ,
36+ } ) ) ;
1537 } ) ;
16- return timezoneOptions ;
17- } ) . then ( ( timezoneOptions ) => {
18- API . get ( `/api/users/${ recordId } ?attributes=settings` ) . then ( ( { settings } ) => setState ( {
19- initialValues : settings ,
20- timezoneOptions,
21- isLoading : false ,
22- } ) ) ;
2338 } ) ;
2439 } , [ recordId ] ) ;
2540
@@ -42,7 +57,7 @@ const VisualSettingsForm = ({ recordId }) => {
4257 }
4358 return (
4459 < MiqFormRenderer
45- schema = { createSchema ( timezoneOptions ) }
60+ schema = { createSchema ( shortcuts , timezoneOptions ) }
4661 initialValues = { initialValues }
4762 onSubmit = { onSubmit }
4863 canReset
0 commit comments