Skip to content

Commit 3e912b5

Browse files
Fix start page not being honoured
1 parent aa78d86 commit 3e912b5

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

app/javascript/components/visual-settings-form/index.jsx

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,36 @@ import MiqFormRenderer from '@@ddf';
55
import createSchema from './visual-settings-form.schema';
66

77
const 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

app/javascript/components/visual-settings-form/visual-settings-form.schema.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { componentTypes } from '@@ddf';
22

3-
const createSchema = (timezoneOptions) => ({
3+
const createSchema = (shortcuts, timezoneOptions) => ({
44
fields: [
55
{
66
component: componentTypes.SUB_FORM,
@@ -98,8 +98,8 @@ const createSchema = (timezoneOptions) => ({
9898
id: 'display.startpage',
9999
label: __('Start Page'),
100100
isSearchable: true,
101-
loadOptions: () => API.get('/api/shortcuts?expand=resources&attributes=description,url')
102-
.then(({ resources }) => resources.map(({ url, description }) => ({ value: url, label: description }))),
101+
simpleValue: true,
102+
options: shortcuts,
103103
},
104104
{
105105
component: componentTypes.SELECT,

0 commit comments

Comments
 (0)