mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Stack Monitoring] Migrate indices view to React (#113338)
* [Stack Monitoring] Migrate indices view to React * Fix lint
This commit is contained in:
parent
3eb93a84f5
commit
8a63be0acc
3 changed files with 108 additions and 0 deletions
|
@ -24,6 +24,7 @@ import { BeatsOverviewPage } from './pages/beats/overview';
|
|||
import { BeatsInstancesPage } from './pages/beats/instances';
|
||||
import { CODE_PATH_ELASTICSEARCH, CODE_PATH_BEATS } from '../../common/constants';
|
||||
import { ElasticsearchNodesPage } from './pages/elasticsearch/nodes_page';
|
||||
import { ElasticsearchIndicesPage } from './pages/elasticsearch/indices_page';
|
||||
import { ElasticsearchNodePage } from './pages/elasticsearch/node_page';
|
||||
import { MonitoringTimeContainer } from './hooks/use_monitoring_time';
|
||||
import { BreadcrumbContainer } from './hooks/use_breadcrumbs';
|
||||
|
@ -81,6 +82,13 @@ const MonitoringApp: React.FC<{
|
|||
/>
|
||||
|
||||
{/* ElasticSearch Views */}
|
||||
<RouteInit
|
||||
path="/elasticsearch/indices"
|
||||
component={ElasticsearchIndicesPage}
|
||||
codePaths={[CODE_PATH_ELASTICSEARCH]}
|
||||
fetchAllClusters={false}
|
||||
/>
|
||||
|
||||
<RouteInit
|
||||
path="/elasticsearch/nodes/:node"
|
||||
component={ElasticsearchNodePage}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* 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 } from 'react';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { find } from 'lodash';
|
||||
import { ElasticsearchTemplate } from './elasticsearch_template';
|
||||
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
|
||||
import { GlobalStateContext } from '../../global_state_context';
|
||||
import { ElasticsearchIndices } from '../../../components/elasticsearch';
|
||||
import { ComponentProps } from '../../route_init';
|
||||
import { SetupModeRenderer } from '../../setup_mode/setup_mode_renderer';
|
||||
import { SetupModeContext } from '../../../components/setup_mode/setup_mode_context';
|
||||
import { useTable } from '../../hooks/use_table';
|
||||
import { useLocalStorage } from '../../hooks/use_local_storage';
|
||||
|
||||
interface SetupModeProps {
|
||||
setupMode: any;
|
||||
flyoutComponent: any;
|
||||
bottomBarComponent: any;
|
||||
}
|
||||
|
||||
export const ElasticsearchIndicesPage: React.FC<ComponentProps> = ({ clusters }) => {
|
||||
const globalState = useContext(GlobalStateContext);
|
||||
const { services } = useKibana<{ data: any }>();
|
||||
const { getPaginationTableProps } = useTable('elasticsearch.indices');
|
||||
const clusterUuid = globalState.cluster_uuid;
|
||||
const cluster = find(clusters, {
|
||||
cluster_uuid: clusterUuid,
|
||||
});
|
||||
const [data, setData] = useState({} as any);
|
||||
const [showSystemIndices, setShowSystemIndices] = useLocalStorage<boolean>(
|
||||
'showSystemIndices',
|
||||
false
|
||||
);
|
||||
|
||||
const title = i18n.translate('xpack.monitoring.elasticsearch.indices.routeTitle', {
|
||||
defaultMessage: 'Elasticsearch - Indices',
|
||||
});
|
||||
|
||||
const pageTitle = i18n.translate('xpack.monitoring.elasticsearch.indices.pageTitle', {
|
||||
defaultMessage: 'Elasticsearch indices',
|
||||
});
|
||||
|
||||
const toggleShowSystemIndices = useCallback(
|
||||
() => setShowSystemIndices(!showSystemIndices),
|
||||
[showSystemIndices, setShowSystemIndices]
|
||||
);
|
||||
|
||||
const getPageData = useCallback(async () => {
|
||||
const bounds = services.data?.query.timefilter.timefilter.getBounds();
|
||||
const url = `../api/monitoring/v1/clusters/${clusterUuid}/elasticsearch/indices`;
|
||||
const response = await services.http?.fetch(url, {
|
||||
method: 'POST',
|
||||
query: {
|
||||
show_system_indices: showSystemIndices,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
timeRange: {
|
||||
min: bounds.min.toISOString(),
|
||||
max: bounds.max.toISOString(),
|
||||
},
|
||||
}),
|
||||
});
|
||||
setData(response);
|
||||
}, [showSystemIndices, clusterUuid, services.data?.query.timefilter.timefilter, services.http]);
|
||||
|
||||
return (
|
||||
<ElasticsearchTemplate
|
||||
title={title}
|
||||
pageTitle={pageTitle}
|
||||
getPageData={getPageData}
|
||||
data-test-subj="elasticsearchOverviewPage"
|
||||
cluster={cluster}
|
||||
>
|
||||
<div data-test-subj="elasticsearchNodesListingPage">
|
||||
<SetupModeRenderer
|
||||
render={({ flyoutComponent, bottomBarComponent }: SetupModeProps) => (
|
||||
<SetupModeContext.Provider value={{ setupModeSupported: true }}>
|
||||
{flyoutComponent}
|
||||
<ElasticsearchIndices
|
||||
clusterStatus={data.clusterStatus}
|
||||
indices={data.indices}
|
||||
alerts={{}}
|
||||
showSystemIndices={showSystemIndices}
|
||||
toggleShowSystemIndices={toggleShowSystemIndices}
|
||||
{...getPaginationTableProps()}
|
||||
/>
|
||||
{bottomBarComponent}
|
||||
</SetupModeContext.Provider>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</ElasticsearchTemplate>
|
||||
);
|
||||
};
|
|
@ -7,4 +7,5 @@
|
|||
|
||||
export const ElasticsearchOverview: FunctionComponent<Props>;
|
||||
export const ElasticsearchNodes: FunctionComponent<Props>;
|
||||
export const ElasticsearchIndices: FunctionComponent<Props>;
|
||||
export const NodeReact: FunctionComponent<Props>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue