[Stack Monitoring] Migrate indices view to React (#113338)

* [Stack Monitoring] Migrate indices view to React

* Fix lint
This commit is contained in:
Zacqary Adam Xeper 2021-09-29 16:40:49 -05:00 committed by GitHub
parent 3eb93a84f5
commit 8a63be0acc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 108 additions and 0 deletions

View file

@ -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}

View file

@ -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>
);
};

View file

@ -7,4 +7,5 @@
export const ElasticsearchOverview: FunctionComponent<Props>;
export const ElasticsearchNodes: FunctionComponent<Props>;
export const ElasticsearchIndices: FunctionComponent<Props>;
export const NodeReact: FunctionComponent<Props>;