From 31ac3d21b0e46ccbea727812cb80a46ff01e80d4 Mon Sep 17 00:00:00 2001 From: Or Ouziel Date: Mon, 3 Jan 2022 13:03:15 +0200 Subject: [PATCH] FE general polish (#75) --- .../cloud_security_posture/.i18nrc.json | 7 ---- .../common/constants.ts | 5 +-- .../cloud_security_posture/common/index.ts | 7 ++++ .../common/api/use_cloud_posture_stats_api.ts | 3 +- .../public/components/page_template.tsx | 2 +- .../public/components/section_container.tsx | 41 ------------------- .../public/pages/findings/findings.test.tsx | 4 +- .../public/pages/findings/utils.tsx | 6 +-- .../cloud_security_posture/public/plugin.ts | 2 +- .../index_template/create_index_template.ts | 6 +-- .../server/routes/findings/findings.ts | 4 +- .../server/routes/stats/stats_queries.ts | 10 ++--- 12 files changed, 28 insertions(+), 69 deletions(-) delete mode 100755 x-pack/plugins/cloud_security_posture/.i18nrc.json delete mode 100644 x-pack/plugins/cloud_security_posture/public/components/section_container.tsx diff --git a/x-pack/plugins/cloud_security_posture/.i18nrc.json b/x-pack/plugins/cloud_security_posture/.i18nrc.json deleted file mode 100755 index 066f79790abb0..0000000000000 --- a/x-pack/plugins/cloud_security_posture/.i18nrc.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "prefix": "csp", - "paths": { - "csp": "." - }, - "translations": ["translations/ja-JP.json"] -} diff --git a/x-pack/plugins/cloud_security_posture/common/constants.ts b/x-pack/plugins/cloud_security_posture/common/constants.ts index 999dd4752e690..04198ebce0469 100644 --- a/x-pack/plugins/cloud_security_posture/common/constants.ts +++ b/x-pack/plugins/cloud_security_posture/common/constants.ts @@ -4,9 +4,8 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - -export const CSP_KUBEBEAT_INDEX_PATTERN = 'kubebeat*'; -export const CSP_KUBEBEAT_INDEX_NAME = 'findings'; +export const CSP_KUBEBEAT_INDEX_NAME = 'kubebeat*'; +export const CSP_FINDINGS_INDEX_NAME = 'findings'; export const STATS_ROUTH_PATH = '/api/csp/stats'; export const FINDINGS_ROUTH_PATH = '/api/csp/finding'; export const AGENT_LOGS_INDEX = 'kubebeat*'; diff --git a/x-pack/plugins/cloud_security_posture/common/index.ts b/x-pack/plugins/cloud_security_posture/common/index.ts index 50d2413e80c94..cca8125c8499d 100755 --- a/x-pack/plugins/cloud_security_posture/common/index.ts +++ b/x-pack/plugins/cloud_security_posture/common/index.ts @@ -1,2 +1,9 @@ +/* + * 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. + */ + export const PLUGIN_ID = 'csp'; export const PLUGIN_NAME = 'csp'; diff --git a/x-pack/plugins/cloud_security_posture/public/common/api/use_cloud_posture_stats_api.ts b/x-pack/plugins/cloud_security_posture/public/common/api/use_cloud_posture_stats_api.ts index 989aa1d550957..6b1035c635384 100644 --- a/x-pack/plugins/cloud_security_posture/public/common/api/use_cloud_posture_stats_api.ts +++ b/x-pack/plugins/cloud_security_posture/public/common/api/use_cloud_posture_stats_api.ts @@ -8,8 +8,9 @@ import { useQuery } from 'react-query'; import { useKibana } from '../../../../../../src/plugins/kibana_react/public'; import { CloudPostureStats } from '../../../common/types'; +import { STATS_ROUTH_PATH } from '../../../common/constants'; export const useCloudPostureStatsApi = () => { const { http } = useKibana().services; - return useQuery(['csp_dashboard_stats'], () => http!.get('/api/csp/stats')); + return useQuery(['csp_dashboard_stats'], () => http!.get(STATS_ROUTH_PATH)); }; diff --git a/x-pack/plugins/cloud_security_posture/public/components/page_template.tsx b/x-pack/plugins/cloud_security_posture/public/components/page_template.tsx index f303059f39411..99fa91c6df10f 100644 --- a/x-pack/plugins/cloud_security_posture/public/components/page_template.tsx +++ b/x-pack/plugins/cloud_security_posture/public/components/page_template.tsx @@ -21,7 +21,7 @@ const navItems: NonNullable['items'] = n id: route.name, ...route, renderItem: () => ( - + {route.name} ), diff --git a/x-pack/plugins/cloud_security_posture/public/components/section_container.tsx b/x-pack/plugins/cloud_security_posture/public/components/section_container.tsx deleted file mode 100644 index f3790c8769e74..0000000000000 --- a/x-pack/plugins/cloud_security_posture/public/components/section_container.tsx +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 { EuiAccordion, EuiPanel, EuiSpacer, EuiTitle } from '@elastic/eui'; - -interface SectionContainerProps { - title: string; - children: React.ReactNode; - hasBorder?: boolean; - initialIsOpen?: boolean; -} - -export const SectionContainer = ({ - title, - children, - hasBorder = true, - initialIsOpen = false, -}: SectionContainerProps) => ( - - -
{title}
- - } - > - - - {children} - -
-
-); diff --git a/x-pack/plugins/cloud_security_posture/public/pages/findings/findings.test.tsx b/x-pack/plugins/cloud_security_posture/public/pages/findings/findings.test.tsx index aaaa4bbbb486a..a52ca63d48ee1 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/findings/findings.test.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/findings/findings.test.tsx @@ -12,7 +12,7 @@ import { dataPluginMock } from '../../../../../../src/plugins/data/public/mocks' import { coreMock } from '../../../../../../src/core/public/mocks'; import { createStubDataView } from '../../../../../../src/plugins/data_views/public/data_views/data_view.stub'; import * as utils from './utils'; -import { CSP_KUBEBEAT_INDEX_PATTERN } from '../../../common/constants'; +import { CSP_KUBEBEAT_INDEX_NAME } from '../../../common/constants'; import { TEST_SUBJECTS } from './constants'; import type { UseQueryResult } from 'react-query'; import type { DataView } from '../../../../../../src/plugins/data/common'; @@ -59,7 +59,7 @@ describe('', () => { status: 'success', data: createStubDataView({ spec: { - id: CSP_KUBEBEAT_INDEX_PATTERN, + id: CSP_KUBEBEAT_INDEX_NAME, }, }), } as UseQueryResult) diff --git a/x-pack/plugins/cloud_security_posture/public/pages/findings/utils.tsx b/x-pack/plugins/cloud_security_posture/public/pages/findings/utils.tsx index ed00c6657ef0e..2cd365760ab83 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/findings/utils.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/findings/utils.tsx @@ -16,7 +16,7 @@ import type { TimeRange, } from '../../../../../../src/plugins/data/common'; import type { CspPluginSetup } from '../../types'; -import { CSP_KUBEBEAT_INDEX_PATTERN } from '../../../common/constants'; +import { CSP_KUBEBEAT_INDEX_NAME } from '../../../common/constants'; import { useKibana } from '../../../../../../src/plugins/kibana_react/public'; export const extractErrorMessage = (e: unknown): string => @@ -37,7 +37,7 @@ export const useKubebeatDataView = () => { const createDataView = () => dataViews.createAndSave({ - title: CSP_KUBEBEAT_INDEX_PATTERN, + title: CSP_KUBEBEAT_INDEX_NAME, allowNoIndex: false, }); @@ -45,7 +45,7 @@ export const useKubebeatDataView = () => { // if not, no point in creating a data view // const check = () => http?.get(`/kubebeat`); - const findDataView = async () => (await dataViews.find(CSP_KUBEBEAT_INDEX_PATTERN))?.[0]; + const findDataView = async () => (await dataViews.find(CSP_KUBEBEAT_INDEX_NAME))?.[0]; const getKubebeatDataView = () => findDataView().then((v) => (v ? v : createDataView())); diff --git a/x-pack/plugins/cloud_security_posture/public/plugin.ts b/x-pack/plugins/cloud_security_posture/public/plugin.ts index 542661ac69312..347a982e63ef1 100755 --- a/x-pack/plugins/cloud_security_posture/public/plugin.ts +++ b/x-pack/plugins/cloud_security_posture/public/plugin.ts @@ -15,7 +15,7 @@ export class CspPlugin implements Plugin => { try { - const isExisting = await doesIndexTemplateExist(esClient, CSP_KUBEBEAT_INDEX_NAME); + const isExisting = await doesIndexTemplateExist(esClient, CSP_FINDINGS_INDEX_NAME); if (isExisting) return true; return await createIndexTemplate( esClient, + CSP_FINDINGS_INDEX_NAME, CSP_KUBEBEAT_INDEX_NAME, - CSP_KUBEBEAT_INDEX_PATTERN, // TODO: check why this cast is required findingsIndexMapping as Record ); diff --git a/x-pack/plugins/cloud_security_posture/server/routes/findings/findings.ts b/x-pack/plugins/cloud_security_posture/server/routes/findings/findings.ts index bfa4faaa6f8a9..b29102a133f28 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/findings/findings.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/findings/findings.ts @@ -11,7 +11,7 @@ import { schema as rt, TypeOf } from '@kbn/config-schema'; import type { ElasticsearchClient } from 'src/core/server'; import type { IRouter } from 'src/core/server'; import { getLatestCycleIds } from './get_latest_cycle_ids'; -import { CSP_KUBEBEAT_INDEX_PATTERN, FINDINGS_ROUTH_PATH } from '../../../common/constants'; +import { CSP_KUBEBEAT_INDEX_NAME, FINDINGS_ROUTH_PATH } from '../../../common/constants'; export const DEFAULT_FINDINGS_PER_PAGE = 20; type FindingsQuerySchema = TypeOf; @@ -42,7 +42,7 @@ const getFindingsEsQuery = async ( ): Promise => { const query = await buildQueryFilter(esClient, queryParams); return { - index: CSP_KUBEBEAT_INDEX_PATTERN, + index: CSP_KUBEBEAT_INDEX_NAME, query, size: queryParams.per_page, from: diff --git a/x-pack/plugins/cloud_security_posture/server/routes/stats/stats_queries.ts b/x-pack/plugins/cloud_security_posture/server/routes/stats/stats_queries.ts index f592e84568863..6e545f6327334 100644 --- a/x-pack/plugins/cloud_security_posture/server/routes/stats/stats_queries.ts +++ b/x-pack/plugins/cloud_security_posture/server/routes/stats/stats_queries.ts @@ -10,7 +10,7 @@ import { QueryDslQueryContainer, } from '@elastic/elasticsearch/lib/api/types'; -import { CSP_KUBEBEAT_INDEX_PATTERN } from '../../../common/constants'; +import { CSP_KUBEBEAT_INDEX_NAME } from '../../../common/constants'; export const getFindingsEsQuery = ( cycleId: string, @@ -28,7 +28,7 @@ export const getFindingsEsQuery = ( } return { - index: CSP_KUBEBEAT_INDEX_PATTERN, + index: CSP_KUBEBEAT_INDEX_NAME, query: { bool: { filter }, }, @@ -53,7 +53,7 @@ export const getResourcesEvaluationEsQuery = ( query.bool!.must = { terms: { 'resource.filename.keyword': resources } }; } return { - index: CSP_KUBEBEAT_INDEX_PATTERN, + index: CSP_KUBEBEAT_INDEX_NAME, size, query, aggs: { @@ -66,7 +66,7 @@ export const getResourcesEvaluationEsQuery = ( }; export const getBenchmarksQuery = (): SearchRequest => ({ - index: CSP_KUBEBEAT_INDEX_PATTERN, + index: CSP_KUBEBEAT_INDEX_NAME, size: 0, aggs: { benchmarks: { @@ -76,7 +76,7 @@ export const getBenchmarksQuery = (): SearchRequest => ({ }); export const getLatestFindingQuery = (): SearchRequest => ({ - index: CSP_KUBEBEAT_INDEX_PATTERN, + index: CSP_KUBEBEAT_INDEX_NAME, size: 1, /* @ts-expect-error TS2322 - missing SearchSortContainer */ sort: { '@timestamp': 'desc' },