Skip to content

Commit

Permalink
Merge branch 'master' into drilldowns
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Mar 22, 2020
2 parents e14cf4a + 33af1c1 commit 03b2b37
Show file tree
Hide file tree
Showing 105 changed files with 3,397 additions and 366 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import theme from '@elastic/eui/dist/eui_theme_light.json';
import React from 'react';
import { isValidPlatinumLicense } from '../../../../../../../plugins/apm/common/service_map';
import { useDeepObjectIdentity } from '../../../hooks/useDeepObjectIdentity';
import { useFetcher } from '../../../hooks/useFetcher';
import { useLicense } from '../../../hooks/useLicense';
import { useUrlParams } from '../../../hooks/useUrlParams';
Expand All @@ -28,33 +27,27 @@ interface ServiceMapProps {
export function ServiceMap({ serviceName }: ServiceMapProps) {
const license = useLicense();
const { urlParams, uiFilters } = useUrlParams();
const params = useDeepObjectIdentity({
start: urlParams.start,
end: urlParams.end,
environment: urlParams.environment,
serviceName,
uiFilters: {
...uiFilters,
environment: undefined
}
});

const { data } = useFetcher(() => {
const { start, end } = params;
const { start, end, environment } = urlParams;
if (start && end) {
return callApmApi({
pathname: '/api/apm/service-map',
params: {
query: {
...params,
start,
end,
uiFilters: JSON.stringify(params.uiFilters)
environment,
serviceName,
uiFilters: JSON.stringify({
...uiFilters,
environment: undefined
})
}
}
});
}
}, [params]);
}, [serviceName, uiFilters, urlParams]);

const { ref, height, width } = useRefDimensions();

Expand Down
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/uptime/common/constants/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const MONITOR_ROUTE = '/monitor/:monitorId?';

export const OVERVIEW_ROUTE = '/';

export const SETTINGS_ROUTE = '/settings';

export enum STATUS {
UP = 'up',
DOWN = 'down',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import * as t from 'io-ts';

export const DynamicSettingsType = t.type({
heartbeatIndices: t.string,
});

export const DynamicSettingsSaveType = t.intersection([
t.type({
success: t.boolean,
}),
t.partial({
error: t.string,
}),
]);

export type DynamicSettings = t.TypeOf<typeof DynamicSettingsType>;
export type DynamicSettingsSaveResponse = t.TypeOf<typeof DynamicSettingsSaveType>;

export const defaultDynamicSettings: DynamicSettings = {
heartbeatIndices: 'heartbeat-8*',
};
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/uptime/common/runtime_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './common';
export * from './monitor';
export * from './overview_filters';
export * from './snapshot';
export * from './dynamic_settings';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface DataMissingProps {
export const DataMissing = ({ headingMessage }: DataMissingProps) => {
const { basePath } = useContext(UptimeSettingsContext);
return (
<EuiFlexGroup justifyContent="center">
<EuiFlexGroup justifyContent="center" data-test-subj="data-missing">
<EuiFlexItem grow={false}>
<EuiSpacer size="xs" />
<EuiPanel>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { ChromeBreadcrumb } from 'kibana/public';
import React from 'react';
import { Route } from 'react-router-dom';
import { mountWithRouter } from '../../lib';
import { OVERVIEW_ROUTE } from '../../../common/constants';
import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public';
import { UptimeUrlParams, getSupportedUrlParams } from '../../lib/helper';
import { makeBaseBreadcrumb, useBreadcrumbs } from '../../hooks/use_breadcrumbs';

describe('useBreadcrumbs', () => {
it('sets the given breadcrumbs', () => {
const [getBreadcrumbs, core] = mockCore();

const expectedCrumbs: ChromeBreadcrumb[] = [
{
text: 'Crumb: ',
href: 'http://href.example.net',
},
{
text: 'Crumb II: Son of Crumb',
href: 'http://href2.example.net',
},
];

const Component = () => {
useBreadcrumbs(expectedCrumbs);
return <>Hello</>;
};

mountWithRouter(
<KibanaContextProvider services={{ ...core }}>
<Route path={OVERVIEW_ROUTE}>
<Component />
</Route>
</KibanaContextProvider>
);

const urlParams: UptimeUrlParams = getSupportedUrlParams({});
expect(getBreadcrumbs()).toStrictEqual([makeBaseBreadcrumb(urlParams)].concat(expectedCrumbs));
});
});

const mockCore: () => [() => ChromeBreadcrumb[], any] = () => {
let breadcrumbObj: ChromeBreadcrumb[] = [];
const get = () => {
return breadcrumbObj;
};
const core = {
chrome: {
setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => {
breadcrumbObj = newBreadcrumbs;
},
},
};

return [get, core];
};
41 changes: 41 additions & 0 deletions x-pack/legacy/plugins/uptime/public/hooks/use_breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { ChromeBreadcrumb } from 'kibana/public';
import { i18n } from '@kbn/i18n';
import { useEffect } from 'react';
import { UptimeUrlParams } from '../lib/helper';
import { stringifyUrlParams } from '../lib/helper/stringify_url_params';
import { useKibana } from '../../../../../../src/plugins/kibana_react/public';
import { useUrlParams } from '.';

export const makeBaseBreadcrumb = (params?: UptimeUrlParams): ChromeBreadcrumb => {
let href = '#/';
if (params) {
const crumbParams: Partial<UptimeUrlParams> = { ...params };
// We don't want to encode this values because they are often set to Date.now(), the relative
// values in dateRangeStart are better for a URL.
delete crumbParams.absoluteDateRangeStart;
delete crumbParams.absoluteDateRangeEnd;
href += stringifyUrlParams(crumbParams, true);
}
return {
text: i18n.translate('xpack.uptime.breadcrumbs.overviewBreadcrumbText', {
defaultMessage: 'Uptime',
}),
href,
};
};

export const useBreadcrumbs = (extraCrumbs: ChromeBreadcrumb[]) => {
const params = useUrlParams()[0]();
const setBreadcrumbs = useKibana().services.chrome?.setBreadcrumbs;
useEffect(() => {
if (setBreadcrumbs) {
setBreadcrumbs([makeBaseBreadcrumb(params)].concat(extraCrumbs));
}
}, [extraCrumbs, params, setBreadcrumbs]);
};
Loading

0 comments on commit 03b2b37

Please sign in to comment.