-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Stack Monitoring] Beats Overview view migration (#112377)
* Wire up a stub beats overview page * Filling in some bits * Figured out this todo already * Fix importa and product name * Wire up BeatsOverview component * Set breadcrumbs * Add "beats" part to breadcrumbs * Remove unused vars copied from ES overview * Use passed data rather than outer scope * Fixing basic type checks * Fix breadcrumb type issues Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
d27c723
commit 970394b
Showing
3 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/monitoring/public/application/pages/beats/beats_template.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import React from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { PageTemplate } from '../page_template'; | ||
import { TabMenuItem, PageTemplateProps } from '../page_template'; | ||
|
||
interface BeatsTemplateProps extends PageTemplateProps { | ||
cluster: any; | ||
} | ||
|
||
export const BeatsTemplate: React.FC<BeatsTemplateProps> = ({ cluster, ...props }) => { | ||
const tabs: TabMenuItem[] = [ | ||
{ | ||
id: 'overview', | ||
label: i18n.translate('xpack.monitoring.beatsNavigation.overviewLinkText', { | ||
defaultMessage: 'Overview', | ||
}), | ||
route: '/beats', | ||
}, | ||
{ | ||
id: 'instances', | ||
label: i18n.translate('xpack.monitoring.beatsNavigation.instancesLinkText', { | ||
defaultMessage: 'Instances', | ||
}), | ||
route: '/beats/beats', | ||
}, | ||
]; | ||
|
||
return <PageTemplate {...props} tabs={tabs} product="beats" />; | ||
}; |
85 changes: 85 additions & 0 deletions
85
x-pack/plugins/monitoring/public/application/pages/beats/overview.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useContext, useState, useCallback, useEffect } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { find } from 'lodash'; | ||
import { ComponentProps } from '../../route_init'; | ||
import { BeatsTemplate } from './beats_template'; | ||
import { GlobalStateContext } from '../../global_state_context'; | ||
import { useCharts } from '../../hooks/use_charts'; | ||
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public'; | ||
// @ts-ignore | ||
import { BeatsOverview } from '../../../components/beats/overview'; | ||
import { BreadcrumbContainer } from '../../hooks/use_breadcrumbs'; | ||
|
||
export const BeatsOverviewPage: React.FC<ComponentProps> = ({ clusters }) => { | ||
const globalState = useContext(GlobalStateContext); | ||
const { zoomInfo, onBrush } = useCharts(); | ||
const { services } = useKibana<{ data: any }>(); | ||
const clusterUuid = globalState.cluster_uuid; | ||
const ccs = globalState.ccs; | ||
const { generate: generateBreadcrumbs } = useContext(BreadcrumbContainer.Context); | ||
const cluster = find(clusters, { | ||
cluster_uuid: clusterUuid, | ||
}) as any; | ||
|
||
const [data, setData] = useState(null); | ||
|
||
const title = i18n.translate('xpack.monitoring.beats.overview.routeTitle', { | ||
defaultMessage: 'Beats - Overview', | ||
}); | ||
|
||
const pageTitle = i18n.translate('xpack.monitoring.beats.overview.pageTitle', { | ||
defaultMessage: 'Beats overview', | ||
}); | ||
|
||
useEffect(() => { | ||
if (cluster) { | ||
generateBreadcrumbs(cluster.cluster_name, { | ||
inBeats: true, | ||
}); | ||
} | ||
}, [cluster, generateBreadcrumbs]); | ||
|
||
const getPageData = useCallback(async () => { | ||
const bounds = services.data?.query.timefilter.timefilter.getBounds(); | ||
const url = `../api/monitoring/v1/clusters/${clusterUuid}/beats`; | ||
|
||
const response = await services.http?.fetch(url, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
ccs, | ||
timeRange: { | ||
min: bounds.min.toISOString(), | ||
max: bounds.max.toISOString(), | ||
}, | ||
}), | ||
}); | ||
|
||
setData(response); | ||
}, [ccs, clusterUuid, services.data?.query.timefilter.timefilter, services.http]); | ||
|
||
const renderOverview = (overviewData: any) => { | ||
if (overviewData === null) { | ||
return null; | ||
} | ||
return <BeatsOverview {...overviewData} onBrush={onBrush} zoomInfo={zoomInfo} />; | ||
}; | ||
|
||
return ( | ||
<BeatsTemplate | ||
title={title} | ||
pageTitle={pageTitle} | ||
getPageData={getPageData} | ||
data-test-subj="beatsOverviewPage" | ||
cluster={cluster} | ||
> | ||
<div data-test-subj="beatsOverviewPage">{renderOverview(data)}</div> | ||
</BeatsTemplate> | ||
); | ||
}; |