Skip to content

Commit c2e57af

Browse files
authored
[Uptime] Add Settings Page (#53550)
Adds a settings page to the Uptime UI. The settings page values are per-space. The only current setting is heartbeatIndices. To test this against alternate indices try changing setup.ilm.rollover_alias in heartbeat.yml to something like alt-prefix. See the ilm docs for more details. This should be tested with read-only and write only roles. To test this in kibana try creating two users with two different roles in kibana. One roll should have read access to the Uptime space in kibana. The other should have all access. Both should have read permissions for the heartbeat-* index pattern. This patch also splits API perms from just heartbeat to uptime-read and uptime-write. This patch also refactors some of the header component functionality, using hooks for breadcrumbs, and making the top links optional. Fixes elastic/uptime#43
1 parent d3a9531 commit c2e57af

File tree

89 files changed

+1462
-346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1462
-346
lines changed

x-pack/legacy/plugins/uptime/common/constants/ui.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export const MONITOR_ROUTE = '/monitor/:monitorId?';
88

99
export const OVERVIEW_ROUTE = '/';
1010

11+
export const SETTINGS_ROUTE = '/settings';
12+
1113
export enum STATUS {
1214
UP = 'up',
1315
DOWN = 'down',
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import * as t from 'io-ts';
8+
9+
export const DynamicSettingsType = t.type({
10+
heartbeatIndices: t.string,
11+
});
12+
13+
export const DynamicSettingsSaveType = t.intersection([
14+
t.type({
15+
success: t.boolean,
16+
}),
17+
t.partial({
18+
error: t.string,
19+
}),
20+
]);
21+
22+
export type DynamicSettings = t.TypeOf<typeof DynamicSettingsType>;
23+
export type DynamicSettingsSaveResponse = t.TypeOf<typeof DynamicSettingsSaveType>;
24+
25+
export const defaultDynamicSettings: DynamicSettings = {
26+
heartbeatIndices: 'heartbeat-8*',
27+
};

x-pack/legacy/plugins/uptime/common/runtime_types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export * from './common';
99
export * from './monitor';
1010
export * from './overview_filters';
1111
export * from './snapshot';
12+
export * from './dynamic_settings';

x-pack/legacy/plugins/uptime/public/components/functional/empty_state/__tests__/__snapshots__/data_missing.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/legacy/plugins/uptime/public/components/functional/empty_state/__tests__/__snapshots__/empty_state.test.tsx.snap

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/legacy/plugins/uptime/public/components/functional/empty_state/data_missing.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface DataMissingProps {
2424
export const DataMissing = ({ headingMessage }: DataMissingProps) => {
2525
const { basePath } = useContext(UptimeSettingsContext);
2626
return (
27-
<EuiFlexGroup justifyContent="center">
27+
<EuiFlexGroup justifyContent="center" data-test-subj="data-missing">
2828
<EuiFlexItem grow={false}>
2929
<EuiSpacer size="xs" />
3030
<EuiPanel>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { ChromeBreadcrumb } from 'kibana/public';
8+
import React from 'react';
9+
import { Route } from 'react-router-dom';
10+
import { mountWithRouter } from '../../lib';
11+
import { OVERVIEW_ROUTE } from '../../../common/constants';
12+
import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public';
13+
import { UptimeUrlParams, getSupportedUrlParams } from '../../lib/helper';
14+
import { makeBaseBreadcrumb, useBreadcrumbs } from '../../hooks/use_breadcrumbs';
15+
16+
describe('useBreadcrumbs', () => {
17+
it('sets the given breadcrumbs', () => {
18+
const [getBreadcrumbs, core] = mockCore();
19+
20+
const expectedCrumbs: ChromeBreadcrumb[] = [
21+
{
22+
text: 'Crumb: ',
23+
href: 'http://href.example.net',
24+
},
25+
{
26+
text: 'Crumb II: Son of Crumb',
27+
href: 'http://href2.example.net',
28+
},
29+
];
30+
31+
const Component = () => {
32+
useBreadcrumbs(expectedCrumbs);
33+
return <>Hello</>;
34+
};
35+
36+
mountWithRouter(
37+
<KibanaContextProvider services={{ ...core }}>
38+
<Route path={OVERVIEW_ROUTE}>
39+
<Component />
40+
</Route>
41+
</KibanaContextProvider>
42+
);
43+
44+
const urlParams: UptimeUrlParams = getSupportedUrlParams({});
45+
expect(getBreadcrumbs()).toStrictEqual([makeBaseBreadcrumb(urlParams)].concat(expectedCrumbs));
46+
});
47+
});
48+
49+
const mockCore: () => [() => ChromeBreadcrumb[], any] = () => {
50+
let breadcrumbObj: ChromeBreadcrumb[] = [];
51+
const get = () => {
52+
return breadcrumbObj;
53+
};
54+
const core = {
55+
chrome: {
56+
setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => {
57+
breadcrumbObj = newBreadcrumbs;
58+
},
59+
},
60+
};
61+
62+
return [get, core];
63+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { ChromeBreadcrumb } from 'kibana/public';
8+
import { i18n } from '@kbn/i18n';
9+
import { useEffect } from 'react';
10+
import { UptimeUrlParams } from '../lib/helper';
11+
import { stringifyUrlParams } from '../lib/helper/stringify_url_params';
12+
import { useKibana } from '../../../../../../src/plugins/kibana_react/public';
13+
import { useUrlParams } from '.';
14+
15+
export const makeBaseBreadcrumb = (params?: UptimeUrlParams): ChromeBreadcrumb => {
16+
let href = '#/';
17+
if (params) {
18+
const crumbParams: Partial<UptimeUrlParams> = { ...params };
19+
// We don't want to encode this values because they are often set to Date.now(), the relative
20+
// values in dateRangeStart are better for a URL.
21+
delete crumbParams.absoluteDateRangeStart;
22+
delete crumbParams.absoluteDateRangeEnd;
23+
href += stringifyUrlParams(crumbParams, true);
24+
}
25+
return {
26+
text: i18n.translate('xpack.uptime.breadcrumbs.overviewBreadcrumbText', {
27+
defaultMessage: 'Uptime',
28+
}),
29+
href,
30+
};
31+
};
32+
33+
export const useBreadcrumbs = (extraCrumbs: ChromeBreadcrumb[]) => {
34+
const params = useUrlParams()[0]();
35+
const setBreadcrumbs = useKibana().services.chrome?.setBreadcrumbs;
36+
useEffect(() => {
37+
if (setBreadcrumbs) {
38+
setBreadcrumbs([makeBaseBreadcrumb(params)].concat(extraCrumbs));
39+
}
40+
}, [extraCrumbs, params, setBreadcrumbs]);
41+
};

0 commit comments

Comments
 (0)