Skip to content

Commit 168239c

Browse files
[Uptime] Index Status API to Rest (#59657)
* gql to rest * update snap * fix api Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 746e236 commit 168239c

File tree

74 files changed

+590
-911
lines changed

Some content is hidden

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

74 files changed

+590
-911
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export * from './capabilities';
1212
export { PLUGIN } from './plugin';
1313
export { QUERY, STATES } from './query';
1414
export * from './ui';
15+
export * from './rest_api';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
export enum REST_API_URLS {
8+
INDEX_STATUS = '/api/uptime/index_status',
9+
}

x-pack/legacy/plugins/uptime/common/graphql/types.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ export interface Query {
2121

2222
/** Fetches the current state of Uptime monitors for the given parameters. */
2323
getMonitorStates?: MonitorSummaryResult | null;
24-
/** Fetches details about the uptime index. */
25-
getStatesIndexStatus: StatesIndexStatus;
2624
}
2725

2826
export interface PingResults {
@@ -392,7 +390,7 @@ export interface MonitorSummaryResult {
392390
/** The objects representing the state of a series of heartbeat monitors. */
393391
summaries?: MonitorSummary[] | null;
394392
/** The number of summaries. */
395-
totalSummaryCount: DocCount;
393+
totalSummaryCount: number;
396394
}
397395
/** Represents the current state and associated data for an Uptime monitor. */
398396
export interface MonitorSummary {
@@ -525,13 +523,7 @@ export interface SummaryHistogramPoint {
525523
/** The number of _down_ documents. */
526524
down: number;
527525
}
528-
/** Represents the current status of the uptime index. */
529-
export interface StatesIndexStatus {
530-
/** Flag denoting whether the index exists. */
531-
indexExists: boolean;
532-
/** The number of documents in the index. */
533-
docCount?: DocCount | null;
534-
}
526+
535527

536528
export interface AllPingsQueryArgs {
537529
/** Optional: the direction to sort by. Accepts 'asc' and 'desc'. Defaults to 'desc'. */

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export const SummaryType = t.partial({
2222
geo: CheckGeoType,
2323
});
2424

25+
export const StatesIndexStatusType = t.type({
26+
indexExists: t.boolean,
27+
docCount: t.number,
28+
});
29+
2530
export type Summary = t.TypeOf<typeof SummaryType>;
2631
export type CheckGeo = t.TypeOf<typeof CheckGeoType>;
2732
export type Location = t.TypeOf<typeof LocationType>;
33+
export type StatesIndexStatus = t.TypeOf<typeof StatesIndexStatusType>;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 React, { useEffect } from 'react';
8+
import { useDispatch, useSelector } from 'react-redux';
9+
import { indexStatusAction } from '../../../state/actions';
10+
import { indexStatusSelector } from '../../../state/selectors';
11+
import { EmptyStateComponent } from '../../functional/empty_state/empty_state';
12+
13+
export const EmptyState: React.FC = ({ children }) => {
14+
const { data, loading, errors } = useSelector(indexStatusSelector);
15+
16+
const dispatch = useDispatch();
17+
18+
useEffect(() => {
19+
dispatch(indexStatusAction.get());
20+
}, [dispatch]);
21+
22+
return (
23+
<EmptyStateComponent
24+
statesIndexStatus={data}
25+
loading={loading}
26+
errors={errors}
27+
children={children as React.ReactElement}
28+
/>
29+
);
30+
};

x-pack/legacy/plugins/uptime/public/components/connected/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export { MonitorStatusBar } from './monitor/status_bar_container';
1313
export { MonitorListDrawer } from './monitor/list_drawer_container';
1414
export { MonitorListActionsPopover } from './monitor/drawer_popover_container';
1515
export { DurationChart } from './charts/monitor_duration';
16+
export { EmptyState } from './empty_state/empty_state';

x-pack/legacy/plugins/uptime/public/components/connected/kuerybar/kuery_bar_container.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { selectIndexPattern } from '../../../state/selectors';
1010
import { getIndexPattern } from '../../../state/actions';
1111
import { KueryBarComponent } from '../../functional';
1212

13-
const mapStateToProps = (state: AppState) => ({ indexPattern: selectIndexPattern(state) });
13+
const mapStateToProps = (state: AppState) => ({ ...selectIndexPattern(state) });
1414

1515
const mapDispatchToProps = (dispatch: any) => ({
1616
loadIndexPattern: () => {

x-pack/legacy/plugins/uptime/public/components/connected/pages/overview_container.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ const mapDispatchToProps = (dispatch: any): DispatchProps => ({
1818
setEsKueryFilters: (esFilters: string) => dispatch(setEsKueryString(esFilters)),
1919
});
2020

21-
const mapStateToProps = (state: AppState) => ({ indexPattern: selectIndexPattern(state) });
21+
const mapStateToProps = (state: AppState) => ({ ...selectIndexPattern(state) });
2222

2323
export const OverviewPage = connect(mapStateToProps, mapDispatchToProps)(OverviewPageComponent);

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

Lines changed: 16 additions & 21 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__/empty_state.test.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,21 @@ import React from 'react';
88
import { mountWithIntl, shallowWithIntl } from 'test_utils/enzyme_helpers';
99
import { EmptyStateComponent } from '../empty_state';
1010
import { GraphQLError } from 'graphql';
11-
import { StatesIndexStatus } from '../../../../../common/graphql/types';
11+
import { StatesIndexStatus } from '../../../../../common/runtime_types';
1212

1313
describe('EmptyState component', () => {
1414
let statesIndexStatus: StatesIndexStatus;
1515

1616
beforeEach(() => {
1717
statesIndexStatus = {
1818
indexExists: true,
19-
docCount: {
20-
count: 1,
21-
},
19+
docCount: 1,
2220
};
2321
});
2422

2523
it('renders child components when count is truthy', () => {
2624
const component = shallowWithIntl(
27-
<EmptyStateComponent data={{ statesIndexStatus }} loading={false}>
25+
<EmptyStateComponent statesIndexStatus={statesIndexStatus} loading={false}>
2826
<div>Foo</div>
2927
<div>Bar</div>
3028
<div>Baz</div>
@@ -33,9 +31,9 @@ describe('EmptyState component', () => {
3331
expect(component).toMatchSnapshot();
3432
});
3533

36-
it(`doesn't render child components when count is falsey`, () => {
34+
it(`doesn't render child components when count is falsy`, () => {
3735
const component = mountWithIntl(
38-
<EmptyStateComponent data={undefined} loading={false}>
36+
<EmptyStateComponent statesIndexStatus={null} loading={false}>
3937
<div>Shouldn&apos;t be rendered</div>
4038
</EmptyStateComponent>
4139
);
@@ -57,7 +55,7 @@ describe('EmptyState component', () => {
5755
},
5856
];
5957
const component = mountWithIntl(
60-
<EmptyStateComponent data={undefined} errors={errors} loading={false}>
58+
<EmptyStateComponent statesIndexStatus={null} errors={errors} loading={false}>
6159
<div>Shouldn&apos;t appear...</div>
6260
</EmptyStateComponent>
6361
);
@@ -66,7 +64,7 @@ describe('EmptyState component', () => {
6664

6765
it('renders loading state if no errors or doc count', () => {
6866
const component = mountWithIntl(
69-
<EmptyStateComponent loading={true}>
67+
<EmptyStateComponent loading={true} statesIndexStatus={null}>
7068
<div>Should appear even while loading...</div>
7169
</EmptyStateComponent>
7270
);
@@ -75,13 +73,11 @@ describe('EmptyState component', () => {
7573

7674
it('does not render empty state with appropriate base path and no docs', () => {
7775
statesIndexStatus = {
78-
docCount: {
79-
count: 0,
80-
},
76+
docCount: 0,
8177
indexExists: true,
8278
};
8379
const component = mountWithIntl(
84-
<EmptyStateComponent data={{ statesIndexStatus }} loading={false}>
80+
<EmptyStateComponent statesIndexStatus={statesIndexStatus} loading={false}>
8581
<div>If this is in the snapshot the test should fail</div>
8682
</EmptyStateComponent>
8783
);
@@ -91,7 +87,7 @@ describe('EmptyState component', () => {
9187
it('notifies when index does not exist', () => {
9288
statesIndexStatus.indexExists = false;
9389
const component = mountWithIntl(
94-
<EmptyStateComponent data={{ statesIndexStatus }} loading={false}>
90+
<EmptyStateComponent statesIndexStatus={statesIndexStatus} loading={false}>
9591
<div>This text should not render</div>
9692
</EmptyStateComponent>
9793
);

0 commit comments

Comments
 (0)