From ae6f5afe8d4e1d8f8ee5af7712295d78ec4850be Mon Sep 17 00:00:00 2001 From: Lee Drengenberg Date: Mon, 9 Nov 2020 15:58:16 -0600 Subject: [PATCH 01/80] load empty_kibana in test to have clean starting point (#82772) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- test/functional/apps/management/_mgmt_import_saved_objects.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/functional/apps/management/_mgmt_import_saved_objects.js b/test/functional/apps/management/_mgmt_import_saved_objects.js index 3a9f8665fd33b..d479a7006d0f8 100644 --- a/test/functional/apps/management/_mgmt_import_saved_objects.js +++ b/test/functional/apps/management/_mgmt_import_saved_objects.js @@ -29,6 +29,7 @@ export default function ({ getService, getPageObjects }) { describe('mgmt saved objects', function describeIndexTests() { beforeEach(async function () { + await esArchiver.load('empty_kibana'); await esArchiver.load('discover'); await PageObjects.settings.navigateTo(); }); From 04c583e2b0ccef54bd25803b021b8e580fee6c90 Mon Sep 17 00:00:00 2001 From: Constance Date: Mon, 9 Nov 2020 14:10:22 -0800 Subject: [PATCH 02/80] [App Search] Misc naming tech debt (#82770) * Rename `engine_overview` folder to `engines` - To better match ent-search folder structure - Also rename/clarify pluralization of "Engines" where possible, to distinguish between individual Engine Overview pages * DRY out Engines and Meta Engines titles * DRY out Credentials title * DRY out Settings title * DRY out Role Mappings title * Update localization keys to match changes Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../components/credentials/constants.ts | 6 ++++ .../components/credentials/credentials.tsx | 15 ++------- .../components/credentials/index.ts | 1 + .../app_search/components/engine/constants.ts | 4 --- .../components/engine/engine_nav.tsx | 2 +- .../assets/engine_icon.tsx | 0 .../assets/meta_engine_icon.tsx | 0 .../components/empty_state.scss | 0 .../components/empty_state.test.tsx | 0 .../components/empty_state.tsx | 4 +-- .../components/header.test.tsx | 8 ++--- .../components/header.tsx | 4 +-- .../components/index.ts | 2 +- .../components/loading_state.test.tsx | 0 .../components/loading_state.tsx | 4 +-- .../components/engines/constants.ts | 16 +++++++++ .../engines_overview.scss} | 2 +- .../engines_overview.test.tsx} | 24 +++++++------- .../engines_overview.tsx} | 29 +++++++--------- .../engines_table.test.tsx} | 11 ++++--- .../engines_table.tsx} | 16 ++++----- .../app_search/components/engines/index.ts | 8 +++++ .../components/role_mappings/constants.ts | 12 +++++++ .../index.ts | 2 +- .../components/settings/constants.ts | 11 +++++++ .../app_search/components/settings/index.ts | 1 + .../components/settings/settings.tsx | 17 +++------- .../applications/app_search/index.test.tsx | 4 +-- .../public/applications/app_search/index.tsx | 33 +++++-------------- .../translations/translations/ja-JP.json | 11 +++---- .../translations/translations/zh-CN.json | 11 +++---- 31 files changed, 135 insertions(+), 123 deletions(-) rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview => engines}/assets/engine_icon.tsx (100%) rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview => engines}/assets/meta_engine_icon.tsx (100%) rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview => engines}/components/empty_state.scss (100%) rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview => engines}/components/empty_state.test.tsx (100%) rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview => engines}/components/empty_state.tsx (96%) rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview => engines}/components/header.test.tsx (82%) rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview => engines}/components/header.tsx (93%) rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview => engines}/components/index.ts (87%) rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview => engines}/components/loading_state.test.tsx (100%) rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview => engines}/components/loading_state.tsx (89%) create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/constants.ts rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview/engine_overview.scss => engines/engines_overview.scss} (96%) rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview/engine_overview.test.tsx => engines/engines_overview.test.tsx} (80%) rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview/engine_overview.tsx => engines/engines_overview.tsx} (83%) rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview/engine_table.test.tsx => engines/engines_table.test.tsx} (91%) rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview/engine_table.tsx => engines/engines_table.tsx} (92%) create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/index.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/role_mappings/constants.ts rename x-pack/plugins/enterprise_search/public/applications/app_search/components/{engine_overview => role_mappings}/index.ts (82%) create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/constants.ts diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/constants.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/constants.ts index decf1e2158744..ea4906ec08946 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/constants.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/constants.ts @@ -3,8 +3,14 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ + import { i18n } from '@kbn/i18n'; +export const CREDENTIALS_TITLE = i18n.translate( + 'xpack.enterpriseSearch.appSearch.credentials.title', + { defaultMessage: 'Credentials' } +); + export enum ApiTokenTypes { Admin = 'admin', Private = 'private', diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials.tsx index c8eae8cc13f5f..72b02dfdc1f61 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials.tsx @@ -28,6 +28,7 @@ import { FlashMessages } from '../../../shared/flash_messages'; import { CredentialsLogic } from './credentials_logic'; import { externalUrl } from '../../../shared/enterprise_search_url/external_url'; +import { CREDENTIALS_TITLE } from './constants'; import { CredentialsList } from './credentials_list'; import { CredentialsFlyout } from './credentials_flyout'; @@ -47,21 +48,11 @@ export const Credentials: React.FC = () => { return ( <> - + -

- {i18n.translate('xpack.enterpriseSearch.appSearch.credentials.title', { - defaultMessage: 'Credentials', - })} -

+

{CREDENTIALS_TITLE}

diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/index.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/index.ts index bceda234175a7..0fc64a43ffa85 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/index.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/index.ts @@ -5,3 +5,4 @@ */ export { Credentials } from './credentials'; +export { CREDENTIALS_TITLE } from './constants'; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/constants.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/constants.ts index ee5b47eda490e..3c963e415f33b 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/constants.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/constants.ts @@ -9,10 +9,6 @@ import { i18n } from '@kbn/i18n'; // TODO: It's very likely that we'll move these i18n constants to their respective component // folders once those are migrated over. This is a temporary way of DRYing them out for now. -export const ENGINES_TITLE = i18n.translate('xpack.enterpriseSearch.appSearch.engines.title', { - defaultMessage: 'Engines', -}); - export const OVERVIEW_TITLE = i18n.translate( 'xpack.enterpriseSearch.appSearch.engine.overview.title', { defaultMessage: 'Overview' } diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/engine_nav.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/engine_nav.tsx index e5ee392b34c01..f92fefc7124b8 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/engine_nav.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/engine_nav.tsx @@ -30,8 +30,8 @@ import { ENGINE_API_LOGS_PATH, } from '../../routes'; import { getAppSearchUrl } from '../../../shared/enterprise_search_url'; +import { ENGINES_TITLE } from '../engines'; import { - ENGINES_TITLE, OVERVIEW_TITLE, ANALYTICS_TITLE, DOCUMENTS_TITLE, diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/assets/engine_icon.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/assets/engine_icon.tsx similarity index 100% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/assets/engine_icon.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/assets/engine_icon.tsx diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/assets/meta_engine_icon.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/assets/meta_engine_icon.tsx similarity index 100% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/assets/meta_engine_icon.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/assets/meta_engine_icon.tsx diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.scss b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/empty_state.scss similarity index 100% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.scss rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/empty_state.scss diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/empty_state.test.tsx similarity index 100% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.test.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/empty_state.test.tsx diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/empty_state.tsx similarity index 96% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/empty_state.tsx index b7ed1cc895097..95142782d2272 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/empty_state.tsx @@ -14,7 +14,7 @@ import { getAppSearchUrl } from '../../../../shared/enterprise_search_url'; import { SetAppSearchChrome as SetPageChrome } from '../../../../shared/kibana_chrome'; import { CREATE_ENGINES_PATH } from '../../../routes'; -import { EngineOverviewHeader } from './header'; +import { EnginesOverviewHeader } from './header'; import './empty_state.scss'; @@ -34,7 +34,7 @@ export const EmptyState: React.FC = () => { return ( <> - + { +describe('EnginesOverviewHeader', () => { it('renders', () => { - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper.find('h1')).toHaveLength(1); }); it('renders a launch app search button that sends telemetry on click', () => { - const wrapper = shallow(); + const wrapper = shallow(); const button = wrapper.find('[data-test-subj="launchButton"]'); expect(button.prop('href')).toBe('http://localhost:3002/as'); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/header.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/header.tsx similarity index 93% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/header.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/header.tsx index 4bb69bafa0996..3faa74be11e98 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/header.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/header.tsx @@ -19,7 +19,7 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { TelemetryLogic } from '../../../../shared/telemetry'; import { getAppSearchUrl } from '../../../../shared/enterprise_search_url'; -export const EngineOverviewHeader: React.FC = () => { +export const EnginesOverviewHeader: React.FC = () => { const { sendAppSearchTelemetry } = useActions(TelemetryLogic); const buttonProps = { @@ -42,7 +42,7 @@ export const EngineOverviewHeader: React.FC = () => {

diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/index.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/index.ts similarity index 87% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/index.ts rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/index.ts index 794053f184f8c..cb2e0f825d455 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/index.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/index.ts @@ -4,6 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -export { EngineOverviewHeader } from './header'; +export { EnginesOverviewHeader } from './header'; export { LoadingState } from './loading_state'; export { EmptyState } from './empty_state'; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/loading_state.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/loading_state.test.tsx similarity index 100% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/loading_state.test.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/loading_state.test.tsx diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/loading_state.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/loading_state.tsx similarity index 89% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/loading_state.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/loading_state.tsx index 832a133ed43c7..8e2166d2ef105 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/loading_state.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/loading_state.tsx @@ -8,13 +8,13 @@ import React from 'react'; import { EuiPageContent, EuiSpacer, EuiLoadingContent } from '@elastic/eui'; import { SetAppSearchChrome as SetPageChrome } from '../../../../shared/kibana_chrome'; -import { EngineOverviewHeader } from './header'; +import { EnginesOverviewHeader } from './header'; export const LoadingState: React.FC = () => { return ( <> - + diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/constants.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/constants.ts new file mode 100644 index 0000000000000..12545c59b40a0 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/constants.ts @@ -0,0 +1,16 @@ +/* + * 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 { i18n } from '@kbn/i18n'; + +export const ENGINES_TITLE = i18n.translate('xpack.enterpriseSearch.appSearch.engines.title', { + defaultMessage: 'Engines', +}); + +export const META_ENGINES_TITLE = i18n.translate( + 'xpack.enterpriseSearch.appSearch.metaEngines.title', + { defaultMessage: 'Meta Engines' } +); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.scss b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_overview.scss similarity index 96% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.scss rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_overview.scss index 5e8a20ba425ad..c956f3da562f6 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.scss +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_overview.scss @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -.engineOverview { +.enginesOverview { padding: $euiSize; @include euiBreakpoint('m', 'l', 'xl') { diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_overview.test.tsx similarity index 80% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_overview.test.tsx index f87ea2d422780..61f783a8b6c2e 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_overview.test.tsx @@ -14,14 +14,14 @@ import { shallow, ReactWrapper } from 'enzyme'; import { mountAsync, mockHttpValues, setMockValues } from '../../../__mocks__'; import { LoadingState, EmptyState } from './components'; -import { EngineTable } from './engine_table'; +import { EnginesTable } from './engines_table'; -import { EngineOverview } from './'; +import { EnginesOverview } from './'; -describe('EngineOverview', () => { +describe('EnginesOverview', () => { describe('non-happy-path states', () => { it('isLoading', () => { - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper.find(LoadingState)).toHaveLength(1); }); @@ -36,7 +36,7 @@ describe('EngineOverview', () => { }), }, }); - const wrapper = await mountAsync(, { i18n: true }); + const wrapper = await mountAsync(, { i18n: true }); expect(wrapper.find(EmptyState)).toHaveLength(1); }); @@ -69,9 +69,9 @@ describe('EngineOverview', () => { }); it('renders and calls the engines API', async () => { - const wrapper = await mountAsync(, { i18n: true }); + const wrapper = await mountAsync(, { i18n: true }); - expect(wrapper.find(EngineTable)).toHaveLength(1); + expect(wrapper.find(EnginesTable)).toHaveLength(1); expect(mockApi).toHaveBeenNthCalledWith(1, '/api/app_search/engines', { query: { type: 'indexed', @@ -86,9 +86,9 @@ describe('EngineOverview', () => { hasPlatinumLicense: true, http: { ...mockHttpValues.http, get: mockApi }, }); - const wrapper = await mountAsync(, { i18n: true }); + const wrapper = await mountAsync(, { i18n: true }); - expect(wrapper.find(EngineTable)).toHaveLength(2); + expect(wrapper.find(EnginesTable)).toHaveLength(2); expect(mockApi).toHaveBeenNthCalledWith(2, '/api/app_search/engines', { query: { type: 'meta', @@ -100,10 +100,10 @@ describe('EngineOverview', () => { describe('pagination', () => { const getTablePagination = (wrapper: ReactWrapper) => - wrapper.find(EngineTable).prop('pagination'); + wrapper.find(EnginesTable).prop('pagination'); it('passes down page data from the API', async () => { - const wrapper = await mountAsync(, { i18n: true }); + const wrapper = await mountAsync(, { i18n: true }); const pagination = getTablePagination(wrapper); expect(pagination.totalEngines).toEqual(100); @@ -111,7 +111,7 @@ describe('EngineOverview', () => { }); it('re-polls the API on page change', async () => { - const wrapper = await mountAsync(, { i18n: true }); + const wrapper = await mountAsync(, { i18n: true }); await act(async () => getTablePagination(wrapper).onPaginate(5)); wrapper.update(); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_overview.tsx similarity index 83% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_overview.tsx index c0fd254567910..559fef695d63b 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_overview.tsx @@ -13,7 +13,6 @@ import { EuiTitle, EuiSpacer, } from '@elastic/eui'; -import { i18n } from '@kbn/i18n'; import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome'; import { SendAppSearchTelemetry as SendTelemetry } from '../../../shared/telemetry'; @@ -23,11 +22,11 @@ import { LicensingLogic } from '../../../shared/licensing'; import { EngineIcon } from './assets/engine_icon'; import { MetaEngineIcon } from './assets/meta_engine_icon'; +import { ENGINES_TITLE, META_ENGINES_TITLE } from './constants'; +import { EnginesOverviewHeader, LoadingState, EmptyState } from './components'; +import { EnginesTable } from './engines_table'; -import { EngineOverviewHeader, LoadingState, EmptyState } from './components'; -import { EngineTable } from './engine_table'; - -import './engine_overview.scss'; +import './engines_overview.scss'; interface IGetEnginesParams { type: string; @@ -38,7 +37,7 @@ interface ISetEnginesCallbacks { setResultsTotal: React.Dispatch>; } -export const EngineOverview: React.FC = () => { +export const EnginesOverview: React.FC = () => { const { http } = useValues(HttpLogic); const { hasPlatinumLicense } = useValues(LicensingLogic); @@ -88,21 +87,18 @@ export const EngineOverview: React.FC = () => { - - + +

- - {i18n.translate('xpack.enterpriseSearch.appSearch.enginesOverview.engines', { - defaultMessage: 'Engines', - })} + {ENGINES_TITLE}

- {

- - {i18n.translate('xpack.enterpriseSearch.appSearch.enginesOverview.metaEngines', { - defaultMessage: 'Meta Engines', - })} + {META_ENGINES_TITLE}

- { +describe('EnginesTable', () => { const onPaginate = jest.fn(); // onPaginate updates the engines API call upstream const wrapper = mountWithIntl( - { it('handles empty data', () => { const emptyWrapper = mountWithIntl( - {} }} /> + {} }} + /> ); const emptyTable = emptyWrapper.find(EuiBasicTable); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_table.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_table.tsx similarity index 92% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_table.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_table.tsx index abeaf45e6aee8..a9cf64b3dffda 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_table.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_table.tsx @@ -16,28 +16,28 @@ import { getEngineRoute } from '../../routes'; import { ENGINES_PAGE_SIZE } from '../../../../../common/constants'; -export interface IEngineTableData { +interface IEnginesTableData { name: string; created_at: string; document_count: number; field_count: number; } -export interface IEngineTablePagination { +interface IEnginesTablePagination { totalEngines: number; pageIndex: number; onPaginate(pageIndex: number): void; } -export interface IEngineTableProps { - data: IEngineTableData[]; - pagination: IEngineTablePagination; +interface IEnginesTableProps { + data: IEnginesTableData[]; + pagination: IEnginesTablePagination; } -export interface IOnChange { +interface IOnChange { page: { index: number; }; } -export const EngineTable: React.FC = ({ +export const EnginesTable: React.FC = ({ data, pagination: { totalEngines, pageIndex, onPaginate }, }) => { @@ -52,7 +52,7 @@ export const EngineTable: React.FC = ({ }), }); - const columns: Array> = [ + const columns: Array> = [ { field: 'name', name: i18n.translate('xpack.enterpriseSearch.appSearch.enginesOverview.table.column.name', { diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/index.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/index.ts new file mode 100644 index 0000000000000..76ca9239a3c7e --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/index.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export { EnginesOverview } from './engines_overview'; +export { ENGINES_TITLE, META_ENGINES_TITLE } from './constants'; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/role_mappings/constants.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/role_mappings/constants.ts new file mode 100644 index 0000000000000..133d8b604381b --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/role_mappings/constants.ts @@ -0,0 +1,12 @@ +/* + * 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 { i18n } from '@kbn/i18n'; + +export const ROLE_MAPPINGS_TITLE = i18n.translate( + 'xpack.enterpriseSearch.appSearch.roleMappings.title', + { defaultMessage: 'Role Mappings' } +); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/index.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/role_mappings/index.ts similarity index 82% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/index.ts rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/role_mappings/index.ts index 48b7645dc39e8..662b91bb3e925 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/index.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/role_mappings/index.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export { EngineOverview } from './engine_overview'; +export { ROLE_MAPPINGS_TITLE } from './constants'; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/constants.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/constants.ts new file mode 100644 index 0000000000000..c7b22d740341c --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/constants.ts @@ -0,0 +1,11 @@ +/* + * 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 { i18n } from '@kbn/i18n'; + +export const SETTINGS_TITLE = i18n.translate('xpack.enterpriseSearch.appSearch.settings.title', { + defaultMessage: 'Settings', +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/index.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/index.ts index db74dcb1a1846..3e162a4a2a1bc 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/index.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/index.ts @@ -5,3 +5,4 @@ */ export { Settings } from './settings'; +export { SETTINGS_TITLE } from './constants'; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/settings.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/settings.tsx index e5e86f3e39734..13079bb380f13 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/settings.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/settings.tsx @@ -6,30 +6,21 @@ import React from 'react'; -import { i18n } from '@kbn/i18n'; import { EuiPageHeader, EuiPageHeaderSection, EuiPageContentBody, EuiTitle } from '@elastic/eui'; import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome'; import { FlashMessages } from '../../../shared/flash_messages'; +import { SETTINGS_TITLE } from './'; + export const Settings: React.FC = () => { return ( <> - + -

- {i18n.translate('xpack.enterpriseSearch.appSearch.settings.title', { - defaultMessage: 'Settings', - })} -

+

{SETTINGS_TITLE}

diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/index.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/index.test.tsx index 700b903efe59b..11387734e9f9e 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/index.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/index.test.tsx @@ -16,7 +16,7 @@ import { shallow } from 'enzyme'; import { Layout, SideNav, SideNavLink } from '../shared/layout'; import { SetupGuide } from './components/setup_guide'; import { ErrorConnecting } from './components/error_connecting'; -import { EngineOverview } from './components/engine_overview'; +import { EnginesOverview } from './components/engines'; import { EngineRouter } from './components/engine'; import { AppSearch, AppSearchUnconfigured, AppSearchConfigured, AppSearchNav } from './'; @@ -57,7 +57,7 @@ describe('AppSearchConfigured', () => { expect(wrapper.find(Layout)).toHaveLength(2); expect(wrapper.find(Layout).last().prop('readOnlyMode')).toBeFalsy(); - expect(wrapper.find(EngineOverview)).toHaveLength(1); + expect(wrapper.find(EnginesOverview)).toHaveLength(1); expect(wrapper.find(EngineRouter)).toHaveLength(1); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx index f32b0b256b898..4571ef10286e4 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx @@ -8,8 +8,6 @@ import React, { useEffect } from 'react'; import { Route, Redirect, Switch } from 'react-router-dom'; import { useActions, useValues } from 'kea'; -import { i18n } from '@kbn/i18n'; - import { getAppSearchUrl } from '../shared/enterprise_search_url'; import { KibanaLogic } from '../shared/kibana'; import { HttpLogic } from '../shared/http'; @@ -33,9 +31,10 @@ import { import { SetupGuide } from './components/setup_guide'; import { ErrorConnecting } from './components/error_connecting'; import { NotFound } from '../shared/not_found'; -import { EngineOverview } from './components/engine_overview'; -import { Settings } from './components/settings'; -import { Credentials } from './components/credentials'; +import { EnginesOverview, ENGINES_TITLE } from './components/engines'; +import { Settings, SETTINGS_TITLE } from './components/settings'; +import { Credentials, CREDENTIALS_TITLE } from './components/credentials'; +import { ROLE_MAPPINGS_TITLE } from './components/role_mappings'; export const AppSearch: React.FC = (props) => { const { config } = useValues(KibanaLogic); @@ -82,7 +81,7 @@ export const AppSearchConfigured: React.FC = (props) => { - + @@ -113,29 +112,15 @@ export const AppSearchNav: React.FC = ({ subNav }) => { return ( - {i18n.translate('xpack.enterpriseSearch.appSearch.nav.engines', { - defaultMessage: 'Engines', - })} + {ENGINES_TITLE} - {canViewSettings && ( - - {i18n.translate('xpack.enterpriseSearch.appSearch.nav.settings', { - defaultMessage: 'Settings', - })} - - )} + {canViewSettings && {SETTINGS_TITLE}} {canViewAccountCredentials && ( - - {i18n.translate('xpack.enterpriseSearch.appSearch.nav.credentials', { - defaultMessage: 'Credentials', - })} - + {CREDENTIALS_TITLE} )} {canViewRoleMappings && ( - {i18n.translate('xpack.enterpriseSearch.appSearch.nav.roleMappings', { - defaultMessage: 'Role Mappings', - })} + {ROLE_MAPPINGS_TITLE} )} diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index e270996d62093..d8e136567564e 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -6930,8 +6930,8 @@ "xpack.enterpriseSearch.appSearch.emptyState.createFirstEngineCta": "エンジンを作成", "xpack.enterpriseSearch.appSearch.emptyState.description1": "App Searchエンジンは、検索エクスペリエンスのために、ドキュメントを格納します。", "xpack.enterpriseSearch.appSearch.emptyState.title": "初めてのエンジンの作成", - "xpack.enterpriseSearch.appSearch.enginesOverview.engines": "エンジン", - "xpack.enterpriseSearch.appSearch.enginesOverview.metaEngines": "メタエンジン", + "xpack.enterpriseSearch.appSearch.engines.title": "エンジン", + "xpack.enterpriseSearch.appSearch.metaEngines.title": "メタエンジン", "xpack.enterpriseSearch.appSearch.enginesOverview.table.action.manage": "管理", "xpack.enterpriseSearch.appSearch.enginesOverview.table.column.actions": "アクション", "xpack.enterpriseSearch.appSearch.enginesOverview.table.column.createdAt": "作成日時", @@ -6939,10 +6939,9 @@ "xpack.enterpriseSearch.appSearch.enginesOverview.table.column.fieldCount": "フィールドカウント", "xpack.enterpriseSearch.appSearch.enginesOverview.table.column.name": "名前", "xpack.enterpriseSearch.appSearch.enginesOverview.title": "エンジン概要", - "xpack.enterpriseSearch.appSearch.nav.credentials": "資格情報", - "xpack.enterpriseSearch.appSearch.nav.engines": "エンジン", - "xpack.enterpriseSearch.appSearch.nav.roleMappings": "ロールマッピング", - "xpack.enterpriseSearch.appSearch.nav.settings": "アカウント設定", + "xpack.enterpriseSearch.appSearch.credentials.title": "資格情報", + "xpack.enterpriseSearch.appSearch.roleMappings.title": "ロールマッピング", + "xpack.enterpriseSearch.appSearch.settings.title": "アカウント設定", "xpack.enterpriseSearch.appSearch.productCardDescription": "Elastic App Searchには、強力な検索を設計し、WebサイトやWeb/モバイルアプリケーションにデプロイするための使いやすいツールがあります。", "xpack.enterpriseSearch.appSearch.productCta": "App Searchの起動", "xpack.enterpriseSearch.appSearch.productDescription": "ダッシュボード、分析、APIを活用し、高度なアプリケーション検索をシンプルにします。", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 7bf0a22a4dce7..84cc3510ce487 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -6936,8 +6936,8 @@ "xpack.enterpriseSearch.appSearch.emptyState.createFirstEngineCta": "创建引擎", "xpack.enterpriseSearch.appSearch.emptyState.description1": "App Search 引擎存储文档以提升您的搜索体验。", "xpack.enterpriseSearch.appSearch.emptyState.title": "创建您的首个引擎", - "xpack.enterpriseSearch.appSearch.enginesOverview.engines": "引擎", - "xpack.enterpriseSearch.appSearch.enginesOverview.metaEngines": "元引擎", + "xpack.enterpriseSearch.appSearch.engines.title": "引擎", + "xpack.enterpriseSearch.appSearch.metaEngines.title": "元引擎", "xpack.enterpriseSearch.appSearch.enginesOverview.table.action.manage": "管理", "xpack.enterpriseSearch.appSearch.enginesOverview.table.column.actions": "操作", "xpack.enterpriseSearch.appSearch.enginesOverview.table.column.createdAt": "创建于", @@ -6945,10 +6945,9 @@ "xpack.enterpriseSearch.appSearch.enginesOverview.table.column.fieldCount": "字段计数", "xpack.enterpriseSearch.appSearch.enginesOverview.table.column.name": "名称", "xpack.enterpriseSearch.appSearch.enginesOverview.title": "引擎概览", - "xpack.enterpriseSearch.appSearch.nav.credentials": "凭据", - "xpack.enterpriseSearch.appSearch.nav.engines": "引擎", - "xpack.enterpriseSearch.appSearch.nav.roleMappings": "角色映射", - "xpack.enterpriseSearch.appSearch.nav.settings": "帐户设置", + "xpack.enterpriseSearch.appSearch.credentials.title": "凭据", + "xpack.enterpriseSearch.appSearch.roleMappings.title": "角色映射", + "xpack.enterpriseSearch.appSearch.settings.title": "帐户设置", "xpack.enterpriseSearch.appSearch.productCardDescription": "Elastic App Search 提供用户友好的工具,用于设计强大的搜索功能,并将其部署到您的网站或 Web/移动应用程序。", "xpack.enterpriseSearch.appSearch.productCta": "启动 App Search", "xpack.enterpriseSearch.appSearch.productDescription": "利用仪表板、分析和 API 执行高级应用程序搜索简单易行。", From bf758312cdba1986a4cd99cc6c011185f66ec15e Mon Sep 17 00:00:00 2001 From: IgorG <56408662+IgorGuz2000@users.noreply.github.com> Date: Mon, 9 Nov 2020 14:35:16 -0800 Subject: [PATCH 03/80] New events resolver (#82170) * Added Test for event.library * renamed data directry and gzip data file * rename expectedData file * Changes per Charlie request * Changes for the enable_APM-ci branch * Update resolver.ts * Added comment per Charlie request * Update resolver.ts * Added Alert Test for Resolver and fix for the APM enabled Run fail * Added Alert Test for Resolver and fix for the APM enabled Run fail * removed commented out code * Fixing CI fail * Fixing CI fail * Removed Alert Resolver test * aAdding Alert test back * Adding Alert test back * Adding Alert test back * Adding info log for debuging * Adding info log for debuging * Adding info log for debuging * Adding info log for debuging * Adding info log for debuging * Adding info log for debuging * adding one more verification for Data * stripedd Data file Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../resolver_tree/alert_events/data.json.gz | Bin 0 -> 108120 bytes .../apps/endpoint/resolver.ts | 23 ++++++++++++++++++ .../test/security_solution_endpoint/config.ts | 1 - .../page_objects/hosts_page.ts | 2 ++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 x-pack/test/functional/es_archives/endpoint/resolver_tree/alert_events/data.json.gz diff --git a/x-pack/test/functional/es_archives/endpoint/resolver_tree/alert_events/data.json.gz b/x-pack/test/functional/es_archives/endpoint/resolver_tree/alert_events/data.json.gz new file mode 100644 index 0000000000000000000000000000000000000000..997a7a5322a11545a2fb1cf33f051d964e35391c GIT binary patch literal 108120 zcmagFbyQnH`!yQe9g4dQ3fz~@%yjMNTpI= z4V=+f@btD+dS1uX{50|aMB1Ah=+o8JA=Km^UPGOpS+@$b2HqWyMVd|6FWb6{Ek}kj z>wl?eo>)toF|-qT%D9!?G1@SAF}&X;g?OL;Iko}SQQ z#vDBt8yt-Lwd|rN`^FpG7K*c#8Ao&=V61A+IBP}mXPo860k1}2ZNU;BV~Bu^wOl|p ze_NGFLWWS0Q<3+3aTs0Krgkv@5pZywygu+^1&@qkH1gAC=p5?U+lhUh!}EjbO&4e! za6P`0F{(fqvqn-y7W=`}R!|M&h?7BPJwyIx_Nd9eg=^$s&?)Q~dsqa+yIPh`jMm)*l(!r%aJRz;h0zHgR%SAx_=8ig?Z(N*zIlam=@nS?rOg}TgfWj-v;Z;rAH9uJYG z^ToAgen;Txd-LnSH1Ub@DfjdQ(&h#Axvi>(d3 zCB>&CqtfN3!M5qWYIa`7Zc5f-1IArQL|OFmdJSvzauP{XD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ik?jlOVX-l>to=T=XB(VzARIG?+H2%oqDjz+w=4wta~ zV_n?je+PDcHo@7)>Xm#pDkSdwIT8130p~s;?BDESVUwSdchC8!@v#&LIeMd5m1yg? zRYBOOLZyw*S!Ceq+p#>Y{Ry~7{Y&zSgO$bgbluU1PM61n)ig3;?@nLw$L?5JxrN))$e+1aOtNU-@;c?%g)?rTChmoZ#Qgq0C@VhotQ9xj@8`< z;j7Fqeob6^EoX~TU3{j=<9&Z3zBFg9-S_CmRJD+mvf))pdcm1-UsH=4*JUqUZ6&#V z-iud;w>PUS>)>7Y1$cH$671}l@YWZB~*@K0Xyc`uE{N`o8Nh`}*j0z!Ur&8|Qy` zBYA&kZ+PCtitK%TQzNW4o0~pZc4M{Qy|tRvvd=twYxZ95-`i0Gzi`67Vek7LLf$Jo z8h3tacTcSfnd=heFK4;s;))pl*21uoX&Ml zyS1vX&cf9~8-AdA-^W=z57(^ElnW@;4Jp04c-7;`ZD$Iu)o)px#f)^Yl~c&y14|g! zrAC0e_{(KtH5a!%^;nV}ZoO-pN4Ea5?3Klbqk13eJzOmHVwFnl%D-nj^s|+Axe5a_ z&UT0Ez|rhos{**Lp^S~iN|3Vp#apJX@_y&Ktnj_RzV-h;WglLDecR{ecZZ!{hRt}o zFZyMP|GKQN^XKkg+hu6*di&XT_s{;fToHEpN9@Pu5p)Ak^a9Ob&ZU> zan0OV { + await esArchiver.load('empty_kibana'); + await esArchiver.load('endpoint/resolver_tree/alert_events', { useCreate: true }); + await queryBar.setQuery(''); + await queryBar.submitQuery(); + const expectedAlertData = [ + '1 library', + '157 file', + '520 registry', + '3 file', + '5 library', + '5 library', + ]; + await pageObjects.hosts.navigateToEventsPanel(); + await pageObjects.hosts.executeQueryAndOpenResolver('event.dataset : endpoint.alerts'); + await (await testSubjects.find('resolver:graph-controls:zoom-out')).click(); + await browser.setWindowSize(2100, 1500); + for (let i = 0; i < 2; i++) { + await (await testSubjects.find('resolver:graph-controls:east-button')).click(); + } + await pageObjects.hosts.runNodeEvents(expectedAlertData); + }); }); }); } diff --git a/x-pack/test/security_solution_endpoint/config.ts b/x-pack/test/security_solution_endpoint/config.ts index 9ee9e061edf4c..9499c235a5f0d 100644 --- a/x-pack/test/security_solution_endpoint/config.ts +++ b/x-pack/test/security_solution_endpoint/config.ts @@ -30,7 +30,6 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { ['securitySolutionManagement']: { pathname: '/app/security/administration', }, - ...xpackFunctionalConfig.get('apps'), ['security']: { pathname: '/app/security', }, diff --git a/x-pack/test/security_solution_endpoint/page_objects/hosts_page.ts b/x-pack/test/security_solution_endpoint/page_objects/hosts_page.ts index 988fadbbdfe33..c76a5a7c22f60 100644 --- a/x-pack/test/security_solution_endpoint/page_objects/hosts_page.ts +++ b/x-pack/test/security_solution_endpoint/page_objects/hosts_page.ts @@ -121,6 +121,8 @@ export function SecurityHostsPageProvider({ getService, getPageObjects }: FtrPro for (let i = 0; i < NodeSubmenuItems.length; i++) { await (await testSubjects.findAll('resolver:map:node-submenu-item'))[i].click(); const Events = await testSubjects.findAll('resolver:map:node-submenu-item'); + // this sleep is for the AMP enabled run + await pageObjects.common.sleep(300); const EventName = await Events[i]._webElement.getText(); const LinkText = await testSubjects.find('resolver:breadcrumbs:last'); const linkText = await LinkText._webElement.getText(); From 7a67cffe37a7d922b8d74024c150a902c1a28539 Mon Sep 17 00:00:00 2001 From: Matthew Kime Date: Mon, 9 Nov 2020 17:11:21 -0600 Subject: [PATCH 04/80] Index patterns api - load field list on server (#82629) The server side index patterns api can now load the field list. Previously it would error if a field list refresh was required. The regular and rollup index pattern field list loading methods were merged. Rollup index patterns require additional functionality over regular index patterns when it comes to loading the field list, but this won't be necessary once rollups v2 is released. --- ...atternsservice.getfieldsforindexpattern.md | 2 +- ...dexpatternsservice.getfieldsforwildcard.md | 2 +- ...lugins-data-public.indexpatternsservice.md | 4 +- ...-server.getcapabilitiesforrollupindices.md | 28 ++++ ...dexpatternsfetcher.getfieldsforwildcard.md | 4 +- ...-data-server.indexpatternsservice.start.md | 4 +- .../kibana-plugin-plugins-data-server.md | 2 + ...data-server.mergecapabilitieswithfields.md | 15 ++ ...plugin-plugins-data-server.plugin.start.md | 4 +- .../index_patterns/index_patterns.ts | 19 +-- .../data/common/index_patterns/types.ts | 13 +- .../index_patterns_api_client.test.ts | 17 +-- .../index_patterns_api_client.ts | 37 ++--- src/plugins/data/public/public.api.md | 4 +- src/plugins/data/server/index.ts | 2 + .../server/index_patterns/fetcher/index.ts | 6 +- .../fetcher/index_patterns_fetcher.ts | 50 +++++- .../fetcher/lib/__tests__/fixtures/index.js | 20 +++ .../fetcher}/lib/__tests__/fixtures/jobs.js | 19 ++- .../lib/__tests__/jobs_compatibility.js | 20 ++- .../index_patterns/fetcher/lib/index.ts | 2 + .../fetcher}/lib/jobs_compatibility.ts | 19 ++- .../fetcher/lib/map_capabilities.ts | 37 +++++ .../lib/merge_capabilities_with_fields.ts | 26 +++- .../data/server/index_patterns/index.ts | 8 +- .../index_patterns_api_client.ts | 27 +++- .../index_patterns/index_patterns_service.ts | 19 ++- .../data/server/index_patterns/routes.ts | 6 +- .../server/search/aggs/aggs_service.test.ts | 20 ++- .../data/server/search/aggs/aggs_service.ts | 16 +- src/plugins/data/server/search/aggs/types.ts | 7 +- .../data/server/search/search_service.ts | 9 +- src/plugins/data/server/server.api.md | 61 +++++--- .../server/lib/get_fields.ts | 6 +- .../plugins/data_search/server/plugin.ts | 6 +- .../plugins/index_patterns/server/plugin.ts | 49 ++++-- .../test_suites/data_plugin/index_patterns.ts | 25 ++- .../rollup_index_pattern_creation_config.js | 4 +- .../server/lib/__tests__/fixtures/index.js | 7 - .../rollup/server/lib/map_capabilities.ts | 24 --- .../rollup_search_strategy.ts | 7 +- x-pack/plugins/rollup/server/plugin.ts | 4 +- .../server/routes/api/index_patterns/index.ts | 12 -- .../register_fields_for_wildcard_route.ts | 142 ------------------ x-pack/plugins/rollup/server/routes/index.ts | 2 - x-pack/plugins/rollup/server/types.ts | 4 +- .../apis/management/rollup/constants.js | 2 +- .../rollup/index_patterns_extensions.js | 55 +------ 48 files changed, 484 insertions(+), 394 deletions(-) create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.getcapabilitiesforrollupindices.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.mergecapabilitieswithfields.md create mode 100644 src/plugins/data/server/index_patterns/fetcher/lib/__tests__/fixtures/index.js rename {x-pack/plugins/rollup/server => src/plugins/data/server/index_patterns/fetcher}/lib/__tests__/fixtures/jobs.js (65%) rename {x-pack/plugins/rollup/server => src/plugins/data/server/index_patterns/fetcher}/lib/__tests__/jobs_compatibility.js (81%) rename {x-pack/plugins/rollup/server => src/plugins/data/server/index_patterns/fetcher}/lib/jobs_compatibility.ts (79%) create mode 100644 src/plugins/data/server/index_patterns/fetcher/lib/map_capabilities.ts rename {x-pack/plugins/rollup/server => src/plugins/data/server/index_patterns/fetcher}/lib/merge_capabilities_with_fields.ts (70%) delete mode 100644 x-pack/plugins/rollup/server/lib/__tests__/fixtures/index.js delete mode 100644 x-pack/plugins/rollup/server/lib/map_capabilities.ts delete mode 100644 x-pack/plugins/rollup/server/routes/api/index_patterns/index.ts delete mode 100644 x-pack/plugins/rollup/server/routes/api/index_patterns/register_fields_for_wildcard_route.ts diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforindexpattern.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforindexpattern.md index c06c3c6f68492..f288573cd7abb 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforindexpattern.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforindexpattern.md @@ -9,5 +9,5 @@ Get field list by providing an index patttern (or spec) Signature: ```typescript -getFieldsForIndexPattern: (indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions) => Promise; +getFieldsForIndexPattern: (indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions | undefined) => Promise; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforwildcard.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforwildcard.md index aec84866b9e58..32bf6fc13b02c 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforwildcard.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforwildcard.md @@ -9,5 +9,5 @@ Get field list by providing { pattern } Signature: ```typescript -getFieldsForWildcard: (options?: GetFieldsOptions) => Promise; +getFieldsForWildcard: (options: GetFieldsOptions) => Promise; ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.md index 34df8656e9175..57bb98de09ebd 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.indexpatternsservice.md @@ -26,8 +26,8 @@ export declare class IndexPatternsService | [get](./kibana-plugin-plugins-data-public.indexpatternsservice.get.md) | | (id: string) => Promise<IndexPattern> | Get an index pattern by id. Cache optimized | | [getCache](./kibana-plugin-plugins-data-public.indexpatternsservice.getcache.md) | | () => Promise<SavedObject<IndexPatternSavedObjectAttrs>[] | null | undefined> | | | [getDefault](./kibana-plugin-plugins-data-public.indexpatternsservice.getdefault.md) | | () => Promise<IndexPattern | null> | Get default index pattern | -| [getFieldsForIndexPattern](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforindexpattern.md) | | (indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions) => Promise<any> | Get field list by providing an index patttern (or spec) | -| [getFieldsForWildcard](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforwildcard.md) | | (options?: GetFieldsOptions) => Promise<any> | Get field list by providing { pattern } | +| [getFieldsForIndexPattern](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforindexpattern.md) | | (indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions | undefined) => Promise<any> | Get field list by providing an index patttern (or spec) | +| [getFieldsForWildcard](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforwildcard.md) | | (options: GetFieldsOptions) => Promise<any> | Get field list by providing { pattern } | | [getIds](./kibana-plugin-plugins-data-public.indexpatternsservice.getids.md) | | (refresh?: boolean) => Promise<string[]> | Get list of index pattern ids | | [getIdsWithTitle](./kibana-plugin-plugins-data-public.indexpatternsservice.getidswithtitle.md) | | (refresh?: boolean) => Promise<Array<{
id: string;
title: string;
}>> | Get list of index pattern ids with titles | | [getTitles](./kibana-plugin-plugins-data-public.indexpatternsservice.gettitles.md) | | (refresh?: boolean) => Promise<string[]> | Get list of index pattern titles | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.getcapabilitiesforrollupindices.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.getcapabilitiesforrollupindices.md new file mode 100644 index 0000000000000..ba2efcc9b75ca --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.getcapabilitiesforrollupindices.md @@ -0,0 +1,28 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [getCapabilitiesForRollupIndices](./kibana-plugin-plugins-data-server.getcapabilitiesforrollupindices.md) + +## getCapabilitiesForRollupIndices() function + +Signature: + +```typescript +export declare function getCapabilitiesForRollupIndices(indices: { + [key: string]: any; +}): { + [key: string]: any; +}; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| indices | {
[key: string]: any;
} | | + +Returns: + +`{ + [key: string]: any; +}` + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsfetcher.getfieldsforwildcard.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsfetcher.getfieldsforwildcard.md index addd29916d81d..f0989097a727d 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsfetcher.getfieldsforwildcard.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsfetcher.getfieldsforwildcard.md @@ -15,6 +15,8 @@ getFieldsForWildcard(options: { fieldCapsOptions?: { allow_no_indices: boolean; }; + type?: string; + rollupIndex?: string; }): Promise; ``` @@ -22,7 +24,7 @@ getFieldsForWildcard(options: { | Parameter | Type | Description | | --- | --- | --- | -| options | {
pattern: string | string[];
metaFields?: string[];
fieldCapsOptions?: {
allow_no_indices: boolean;
};
} | | +| options | {
pattern: string | string[];
metaFields?: string[];
fieldCapsOptions?: {
allow_no_indices: boolean;
};
type?: string;
rollupIndex?: string;
} | | Returns: diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.start.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.start.md index e7c331bad64e8..6528b1c213cca 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.start.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.indexpatternsservice.start.md @@ -8,7 +8,7 @@ ```typescript start(core: CoreStart, { fieldFormats, logger }: IndexPatternsServiceStartDeps): { - indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract) => Promise; + indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract, elasticsearchClient: ElasticsearchClient) => Promise; }; ``` @@ -22,6 +22,6 @@ start(core: CoreStart, { fieldFormats, logger }: IndexPatternsServiceStartDeps): Returns: `{ - indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract) => Promise; + indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract, elasticsearchClient: ElasticsearchClient) => Promise; }` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md index 49cf12486cbb8..8957f6d0f06b4 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md @@ -28,6 +28,7 @@ | Function | Description | | --- | --- | +| [getCapabilitiesForRollupIndices(indices)](./kibana-plugin-plugins-data-server.getcapabilitiesforrollupindices.md) | | | [getDefaultSearchParams(uiSettingsClient)](./kibana-plugin-plugins-data-server.getdefaultsearchparams.md) | | | [getShardTimeout(config)](./kibana-plugin-plugins-data-server.getshardtimeout.md) | | | [getTime(indexPattern, timeRange, options)](./kibana-plugin-plugins-data-server.gettime.md) | | @@ -77,6 +78,7 @@ | [esQuery](./kibana-plugin-plugins-data-server.esquery.md) | | | [fieldFormats](./kibana-plugin-plugins-data-server.fieldformats.md) | | | [indexPatterns](./kibana-plugin-plugins-data-server.indexpatterns.md) | | +| [mergeCapabilitiesWithFields](./kibana-plugin-plugins-data-server.mergecapabilitieswithfields.md) | | | [search](./kibana-plugin-plugins-data-server.search.md) | | | [UI\_SETTINGS](./kibana-plugin-plugins-data-server.ui_settings.md) | | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.mergecapabilitieswithfields.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.mergecapabilitieswithfields.md new file mode 100644 index 0000000000000..2880e2d0d8f2c --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.mergecapabilitieswithfields.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [mergeCapabilitiesWithFields](./kibana-plugin-plugins-data-server.mergecapabilitieswithfields.md) + +## mergeCapabilitiesWithFields variable + +Signature: + +```typescript +mergeCapabilitiesWithFields: (rollupIndexCapabilities: { + [key: string]: any; +}, fieldsFromFieldCapsApi: { + [key: string]: any; +}, previousFields?: FieldDescriptor[]) => FieldDescriptor[] +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.start.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.start.md index 555a5c2374da7..8a3dbe5a6350c 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.start.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.start.md @@ -12,7 +12,7 @@ start(core: CoreStart): { fieldFormatServiceFactory: (uiSettings: import("src/core/server").IUiSettingsClient) => Promise; }; indexPatterns: { - indexPatternsServiceFactory: (savedObjectsClient: Pick) => Promise; + indexPatternsServiceFactory: (savedObjectsClient: Pick, elasticsearchClient: import("src/core/server").ElasticsearchClient) => Promise; }; search: ISearchStart>; }; @@ -31,7 +31,7 @@ start(core: CoreStart): { fieldFormatServiceFactory: (uiSettings: import("src/core/server").IUiSettingsClient) => Promise; }; indexPatterns: { - indexPatternsServiceFactory: (savedObjectsClient: Pick) => Promise; + indexPatternsServiceFactory: (savedObjectsClient: Pick, elasticsearchClient: import("src/core/server").ElasticsearchClient) => Promise; }; search: ISearchStart>; }` diff --git a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts index aae9b89cdc61f..19c6e9c7b8a7a 100644 --- a/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/common/index_patterns/index_patterns/index_patterns.ts @@ -98,11 +98,12 @@ export class IndexPatternsService { * Refresh cache of index pattern ids and titles */ private async refreshSavedObjectsCache() { - this.savedObjectsCache = await this.savedObjectsClient.find({ + const so = await this.savedObjectsClient.find({ type: 'index-pattern', fields: ['title'], perPage: 10000, }); + this.savedObjectsCache = so; } /** @@ -215,13 +216,13 @@ export class IndexPatternsService { * Get field list by providing { pattern } * @param options */ - getFieldsForWildcard = async (options: GetFieldsOptions = {}) => { + getFieldsForWildcard = async (options: GetFieldsOptions) => { const metaFields = await this.config.get(UI_SETTINGS.META_FIELDS); return this.apiClient.getFieldsForWildcard({ pattern: options.pattern, metaFields, type: options.type, - params: options.params || {}, + rollupIndex: options.rollupIndex, }); }; @@ -231,13 +232,13 @@ export class IndexPatternsService { */ getFieldsForIndexPattern = async ( indexPattern: IndexPattern | IndexPatternSpec, - options: GetFieldsOptions = {} + options?: GetFieldsOptions ) => this.getFieldsForWildcard({ - pattern: indexPattern.title as string, - ...options, type: indexPattern.type, - params: indexPattern.typeMeta && indexPattern.typeMeta.params, + rollupIndex: indexPattern?.typeMeta?.params?.rollup_index, + ...options, + pattern: indexPattern.title as string, }); /** @@ -374,10 +375,10 @@ export class IndexPatternsService { try { spec.fields = isFieldRefreshRequired ? await this.refreshFieldSpecMap(spec.fields || {}, id, spec.title as string, { - pattern: title, + pattern: title as string, metaFields: await this.config.get(UI_SETTINGS.META_FIELDS), type, - params: typeMeta && typeMeta.params, + rollupIndex: typeMeta?.params?.rollupIndex, }) : spec.fields; } catch (err) { diff --git a/src/plugins/data/common/index_patterns/types.ts b/src/plugins/data/common/index_patterns/types.ts index 3387bc3b3c19e..b381cc0963333 100644 --- a/src/plugins/data/common/index_patterns/types.ts +++ b/src/plugins/data/common/index_patterns/types.ts @@ -86,15 +86,22 @@ export interface SavedObjectsClientCommon { } export interface GetFieldsOptions { - pattern?: string; + pattern: string; type?: string; - params?: any; lookBack?: boolean; metaFields?: string[]; + rollupIndex?: string; +} + +export interface GetFieldsOptionsTimePattern { + pattern: string; + metaFields: string[]; + lookBack: number; + interval: string; } export interface IIndexPatternsApiClient { - getFieldsForTimePattern: (options: GetFieldsOptions) => Promise; + getFieldsForTimePattern: (options: GetFieldsOptionsTimePattern) => Promise; getFieldsForWildcard: (options: GetFieldsOptions) => Promise; } diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts index 37ee80c2c29e4..8c48ee44fba9c 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.test.ts @@ -32,7 +32,12 @@ describe('IndexPatternsApiClient', () => { test('uses the right URI to fetch fields for time patterns', async function () { const expectedPath = '/api/index_patterns/_fields_for_time_pattern'; - await indexPatternsApiClient.getFieldsForTimePattern(); + await indexPatternsApiClient.getFieldsForTimePattern({ + pattern: 'blah', + metaFields: [], + lookBack: 5, + interval: '', + }); expect(fetchSpy).toHaveBeenCalledWith(expectedPath, expect.any(Object)); }); @@ -40,15 +45,7 @@ describe('IndexPatternsApiClient', () => { test('uses the right URI to fetch fields for wildcard', async function () { const expectedPath = '/api/index_patterns/_fields_for_wildcard'; - await indexPatternsApiClient.getFieldsForWildcard(); - - expect(fetchSpy).toHaveBeenCalledWith(expectedPath, expect.any(Object)); - }); - - test('uses the right URI to fetch fields for wildcard given a type', async function () { - const expectedPath = '/api/index_patterns/rollup/_fields_for_wildcard'; - - await indexPatternsApiClient.getFieldsForWildcard({ type: 'rollup' }); + await indexPatternsApiClient.getFieldsForWildcard({ pattern: 'blah' }); expect(fetchSpy).toHaveBeenCalledWith(expectedPath, expect.any(Object)); }); diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts index 377a3f7f91a50..ca0f35d6612b2 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/index_patterns_api_client.ts @@ -19,7 +19,11 @@ import { HttpSetup } from 'src/core/public'; import { IndexPatternMissingIndices } from '../../../common/index_patterns/lib'; -import { GetFieldsOptions, IIndexPatternsApiClient } from '../../../common/index_patterns/types'; +import { + GetFieldsOptions, + IIndexPatternsApiClient, + GetFieldsOptionsTimePattern, +} from '../../../common/index_patterns/types'; const API_BASE_URL: string = `/api/index_patterns/`; @@ -48,7 +52,7 @@ export class IndexPatternsApiClient implements IIndexPatternsApiClient { return API_BASE_URL + path.filter(Boolean).map(encodeURIComponent).join('/'); } - getFieldsForTimePattern(options: GetFieldsOptions = {}) { + getFieldsForTimePattern(options: GetFieldsOptionsTimePattern) { const { pattern, lookBack, metaFields } = options; const url = this._getUrl(['_fields_for_time_pattern']); @@ -60,27 +64,12 @@ export class IndexPatternsApiClient implements IIndexPatternsApiClient { }).then((resp: any) => resp.fields); } - getFieldsForWildcard(options: GetFieldsOptions = {}) { - const { pattern, metaFields, type, params } = options; - - let url; - let query; - - if (type) { - url = this._getUrl([type, '_fields_for_wildcard']); - query = { - pattern, - meta_fields: metaFields, - params: JSON.stringify(params), - }; - } else { - url = this._getUrl(['_fields_for_wildcard']); - query = { - pattern, - meta_fields: metaFields, - }; - } - - return this._request(url, query).then((resp: any) => resp.fields); + getFieldsForWildcard({ pattern, metaFields, type, rollupIndex }: GetFieldsOptions) { + return this._request(this._getUrl(['_fields_for_wildcard']), { + pattern, + meta_fields: metaFields, + type, + rollup_index: rollupIndex, + }).then((resp: any) => resp.fields); } } diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index bc2bb2663f163..31b05bd4763a2 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -1367,9 +1367,9 @@ export class IndexPatternsService { // (undocumented) getCache: () => Promise[] | null | undefined>; getDefault: () => Promise; - getFieldsForIndexPattern: (indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions) => Promise; + getFieldsForIndexPattern: (indexPattern: IndexPattern | IndexPatternSpec, options?: GetFieldsOptions | undefined) => Promise; // Warning: (ae-forgotten-export) The symbol "GetFieldsOptions" needs to be exported by the entry point index.d.ts - getFieldsForWildcard: (options?: GetFieldsOptions) => Promise; + getFieldsForWildcard: (options: GetFieldsOptions) => Promise; getIds: (refresh?: boolean) => Promise; getIdsWithTitle: (refresh?: boolean) => Promise { - const { pattern, metaFields, fieldCapsOptions } = options; - return await getFieldCapabilities(this.elasticsearchClient, pattern, metaFields, { - allow_no_indices: fieldCapsOptions ? fieldCapsOptions.allow_no_indices : this.allowNoIndices, - }); + const { pattern, metaFields, fieldCapsOptions, type, rollupIndex } = options; + const fieldCapsResponse = await getFieldCapabilities( + this.elasticsearchClient, + pattern, + metaFields, + { + allow_no_indices: fieldCapsOptions + ? fieldCapsOptions.allow_no_indices + : this.allowNoIndices, + } + ); + if (type === 'rollup' && rollupIndex) { + const rollupFields: FieldDescriptor[] = []; + const rollupIndexCapabilities = getCapabilitiesForRollupIndices( + ( + await this.elasticsearchClient.rollup.getRollupIndexCaps({ + index: rollupIndex, + }) + ).body + )[rollupIndex].aggs; + const fieldCapsResponseObj = keyBy(fieldCapsResponse, 'name'); + + // Keep meta fields + metaFields!.forEach( + (field: string) => + fieldCapsResponseObj[field] && rollupFields.push(fieldCapsResponseObj[field]) + ); + + return mergeCapabilitiesWithFields( + rollupIndexCapabilities, + fieldCapsResponseObj, + rollupFields + ); + } + return fieldCapsResponse; } /** diff --git a/src/plugins/data/server/index_patterns/fetcher/lib/__tests__/fixtures/index.js b/src/plugins/data/server/index_patterns/fetcher/lib/__tests__/fixtures/index.js new file mode 100644 index 0000000000000..d675702ae54e9 --- /dev/null +++ b/src/plugins/data/server/index_patterns/fetcher/lib/__tests__/fixtures/index.js @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { jobs } from './jobs'; diff --git a/x-pack/plugins/rollup/server/lib/__tests__/fixtures/jobs.js b/src/plugins/data/server/index_patterns/fetcher/lib/__tests__/fixtures/jobs.js similarity index 65% rename from x-pack/plugins/rollup/server/lib/__tests__/fixtures/jobs.js rename to src/plugins/data/server/index_patterns/fetcher/lib/__tests__/fixtures/jobs.js index c03b7c33abe0a..39ebd9595eeaf 100644 --- a/x-pack/plugins/rollup/server/lib/__tests__/fixtures/jobs.js +++ b/src/plugins/data/server/index_patterns/fetcher/lib/__tests__/fixtures/jobs.js @@ -1,7 +1,20 @@ /* - * 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. + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ export const jobs = [ diff --git a/x-pack/plugins/rollup/server/lib/__tests__/jobs_compatibility.js b/src/plugins/data/server/index_patterns/fetcher/lib/__tests__/jobs_compatibility.js similarity index 81% rename from x-pack/plugins/rollup/server/lib/__tests__/jobs_compatibility.js rename to src/plugins/data/server/index_patterns/fetcher/lib/__tests__/jobs_compatibility.js index a67f67de859f5..e3c93ac1f8616 100644 --- a/x-pack/plugins/rollup/server/lib/__tests__/jobs_compatibility.js +++ b/src/plugins/data/server/index_patterns/fetcher/lib/__tests__/jobs_compatibility.js @@ -1,8 +1,22 @@ /* - * 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. + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ + import expect from '@kbn/expect'; import { areJobsCompatible, mergeJobConfigurations } from '../jobs_compatibility'; import { jobs } from './fixtures'; diff --git a/src/plugins/data/server/index_patterns/fetcher/lib/index.ts b/src/plugins/data/server/index_patterns/fetcher/lib/index.ts index 20e74d2b1a579..b2fd3a1a09a25 100644 --- a/src/plugins/data/server/index_patterns/fetcher/lib/index.ts +++ b/src/plugins/data/server/index_patterns/fetcher/lib/index.ts @@ -20,3 +20,5 @@ export { getFieldCapabilities, shouldReadFieldFromDocValues } from './field_capabilities'; export { resolveTimePattern } from './resolve_time_pattern'; export { createNoMatchingIndicesError } from './errors'; +export * from './merge_capabilities_with_fields'; +export * from './map_capabilities'; diff --git a/x-pack/plugins/rollup/server/lib/jobs_compatibility.ts b/src/plugins/data/server/index_patterns/fetcher/lib/jobs_compatibility.ts similarity index 79% rename from x-pack/plugins/rollup/server/lib/jobs_compatibility.ts rename to src/plugins/data/server/index_patterns/fetcher/lib/jobs_compatibility.ts index f5f54cf9a54e8..f21de8907ee24 100644 --- a/x-pack/plugins/rollup/server/lib/jobs_compatibility.ts +++ b/src/plugins/data/server/index_patterns/fetcher/lib/jobs_compatibility.ts @@ -1,7 +1,20 @@ /* - * 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. + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ import { isEqual } from 'lodash'; diff --git a/src/plugins/data/server/index_patterns/fetcher/lib/map_capabilities.ts b/src/plugins/data/server/index_patterns/fetcher/lib/map_capabilities.ts new file mode 100644 index 0000000000000..6187174834012 --- /dev/null +++ b/src/plugins/data/server/index_patterns/fetcher/lib/map_capabilities.ts @@ -0,0 +1,37 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { mergeJobConfigurations } from './jobs_compatibility'; + +export function getCapabilitiesForRollupIndices(indices: { [key: string]: any }) { + const indexNames = Object.keys(indices); + const capabilities = {} as { [key: string]: any }; + + indexNames.forEach((index) => { + try { + capabilities[index] = mergeJobConfigurations(indices[index].rollup_jobs); + } catch (e) { + capabilities[index] = { + error: e.message, + }; + } + }); + + return capabilities; +} diff --git a/x-pack/plugins/rollup/server/lib/merge_capabilities_with_fields.ts b/src/plugins/data/server/index_patterns/fetcher/lib/merge_capabilities_with_fields.ts similarity index 70% rename from x-pack/plugins/rollup/server/lib/merge_capabilities_with_fields.ts rename to src/plugins/data/server/index_patterns/fetcher/lib/merge_capabilities_with_fields.ts index 51111e9e45d0a..dd69f4b7ff007 100644 --- a/x-pack/plugins/rollup/server/lib/merge_capabilities_with_fields.ts +++ b/src/plugins/data/server/index_patterns/fetcher/lib/merge_capabilities_with_fields.ts @@ -1,20 +1,30 @@ /* - * 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. + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ // Merge rollup capabilities information with field information -export interface Field { - name?: string; - [key: string]: any; -} +import { FieldDescriptor } from '../index_patterns_fetcher'; export const mergeCapabilitiesWithFields = ( rollupIndexCapabilities: { [key: string]: any }, fieldsFromFieldCapsApi: { [key: string]: any }, - previousFields: Field[] = [] + previousFields: FieldDescriptor[] = [] ) => { const rollupFields = [...previousFields]; const rollupFieldNames: string[] = []; diff --git a/src/plugins/data/server/index_patterns/index.ts b/src/plugins/data/server/index_patterns/index.ts index 683d1c445fd72..3305b1bb9a92f 100644 --- a/src/plugins/data/server/index_patterns/index.ts +++ b/src/plugins/data/server/index_patterns/index.ts @@ -17,5 +17,11 @@ * under the License. */ export * from './utils'; -export { IndexPatternsFetcher, FieldDescriptor, shouldReadFieldFromDocValues } from './fetcher'; +export { + IndexPatternsFetcher, + FieldDescriptor, + shouldReadFieldFromDocValues, + mergeCapabilitiesWithFields, + getCapabilitiesForRollupIndices, +} from './fetcher'; export { IndexPatternsService, IndexPatternsServiceStart } from './index_patterns_service'; diff --git a/src/plugins/data/server/index_patterns/index_patterns_api_client.ts b/src/plugins/data/server/index_patterns/index_patterns_api_client.ts index 2dc6f40c5a6f1..21a3bf6e73e61 100644 --- a/src/plugins/data/server/index_patterns/index_patterns_api_client.ts +++ b/src/plugins/data/server/index_patterns/index_patterns_api_client.ts @@ -17,13 +17,30 @@ * under the License. */ -import { GetFieldsOptions, IIndexPatternsApiClient } from '../../common/index_patterns/types'; +import { ElasticsearchClient } from 'kibana/server'; +import { + GetFieldsOptions, + IIndexPatternsApiClient, + GetFieldsOptionsTimePattern, +} from '../../common/index_patterns/types'; +import { IndexPatternsFetcher } from './fetcher'; export class IndexPatternsApiServer implements IIndexPatternsApiClient { - async getFieldsForTimePattern(options: GetFieldsOptions = {}) { - throw new Error('IndexPatternsApiServer - getFieldsForTimePattern not defined'); + esClient: ElasticsearchClient; + constructor(elasticsearchClient: ElasticsearchClient) { + this.esClient = elasticsearchClient; } - async getFieldsForWildcard(options: GetFieldsOptions = {}) { - throw new Error('IndexPatternsApiServer - getFieldsForWildcard not defined'); + async getFieldsForWildcard({ pattern, metaFields, type, rollupIndex }: GetFieldsOptions) { + const indexPatterns = new IndexPatternsFetcher(this.esClient); + return await indexPatterns.getFieldsForWildcard({ + pattern, + metaFields, + type, + rollupIndex, + }); + } + async getFieldsForTimePattern(options: GetFieldsOptionsTimePattern) { + const indexPatterns = new IndexPatternsFetcher(this.esClient); + return await indexPatterns.getFieldsForTimePattern(options); } } diff --git a/src/plugins/data/server/index_patterns/index_patterns_service.ts b/src/plugins/data/server/index_patterns/index_patterns_service.ts index d665e3715fa72..af2d4d6a73e0f 100644 --- a/src/plugins/data/server/index_patterns/index_patterns_service.ts +++ b/src/plugins/data/server/index_patterns/index_patterns_service.ts @@ -17,7 +17,14 @@ * under the License. */ -import { CoreSetup, CoreStart, Plugin, Logger, SavedObjectsClientContract } from 'kibana/server'; +import { + CoreSetup, + CoreStart, + Plugin, + Logger, + SavedObjectsClientContract, + ElasticsearchClient, +} from 'kibana/server'; import { registerRoutes } from './routes'; import { indexPatternSavedObjectType } from '../saved_objects'; import { capabilitiesProvider } from './capabilities_provider'; @@ -29,7 +36,8 @@ import { SavedObjectsClientServerToCommon } from './saved_objects_client_wrapper export interface IndexPatternsServiceStart { indexPatternsServiceFactory: ( - savedObjectsClient: SavedObjectsClientContract + savedObjectsClient: SavedObjectsClientContract, + elasticsearchClient: ElasticsearchClient ) => Promise; } @@ -50,14 +58,17 @@ export class IndexPatternsService implements Plugin { + indexPatternsServiceFactory: async ( + savedObjectsClient: SavedObjectsClientContract, + elasticsearchClient: ElasticsearchClient + ) => { const uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient); const formats = await fieldFormats.fieldFormatServiceFactory(uiSettingsClient); return new IndexPatternsCommonService({ uiSettings: new UiSettingsServerToCommon(uiSettingsClient), savedObjectsClient: new SavedObjectsClientServerToCommon(savedObjectsClient), - apiClient: new IndexPatternsApiServer(), + apiClient: new IndexPatternsApiServer(elasticsearchClient), fieldFormats: formats, onError: (error) => { logger.error(error); diff --git a/src/plugins/data/server/index_patterns/routes.ts b/src/plugins/data/server/index_patterns/routes.ts index 041eb235d01e0..f8af52954fc61 100644 --- a/src/plugins/data/server/index_patterns/routes.ts +++ b/src/plugins/data/server/index_patterns/routes.ts @@ -42,13 +42,15 @@ export function registerRoutes(http: HttpServiceSetup) { meta_fields: schema.oneOf([schema.string(), schema.arrayOf(schema.string())], { defaultValue: [], }), + type: schema.maybe(schema.string()), + rollup_index: schema.maybe(schema.string()), }), }, }, async (context, request, response) => { const { asCurrentUser } = context.core.elasticsearch.client; const indexPatterns = new IndexPatternsFetcher(asCurrentUser); - const { pattern, meta_fields: metaFields } = request.query; + const { pattern, meta_fields: metaFields, type, rollup_index: rollupIndex } = request.query; let parsedFields: string[] = []; try { @@ -61,6 +63,8 @@ export function registerRoutes(http: HttpServiceSetup) { const fields = await indexPatterns.getFieldsForWildcard({ pattern, metaFields: parsedFields, + type, + rollupIndex, }); return response.ok({ diff --git a/src/plugins/data/server/search/aggs/aggs_service.test.ts b/src/plugins/data/server/search/aggs/aggs_service.test.ts index cb4239cc339c4..e58420f6c2f07 100644 --- a/src/plugins/data/server/search/aggs/aggs_service.test.ts +++ b/src/plugins/data/server/search/aggs/aggs_service.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { KibanaRequest } from 'src/core/server'; +import { KibanaRequest, ElasticsearchClient } from 'src/core/server'; import { coreMock } from '../../../../../core/server/mocks'; import { expressionsPluginMock } from '../../../../../plugins/expressions/server/mocks'; @@ -63,7 +63,8 @@ describe('AggsService - server', () => { expect(start).toHaveProperty('asScopedToClient'); const contract = await start.asScopedToClient( - savedObjects.getScopedClient({} as KibanaRequest) + savedObjects.getScopedClient({} as KibanaRequest), + {} as ElasticsearchClient ); expect(contract).toHaveProperty('calculateAutoTimeExpression'); expect(contract).toHaveProperty('createAggConfigs'); @@ -74,7 +75,10 @@ describe('AggsService - server', () => { service.setup(setupDeps); const start = await service .start(startDeps) - .asScopedToClient(savedObjects.getScopedClient({} as KibanaRequest)); + .asScopedToClient( + savedObjects.getScopedClient({} as KibanaRequest), + {} as ElasticsearchClient + ); expect(start.types.get('terms').name).toBe('terms'); }); @@ -83,7 +87,10 @@ describe('AggsService - server', () => { service.setup(setupDeps); const start = await service .start(startDeps) - .asScopedToClient(savedObjects.getScopedClient({} as KibanaRequest)); + .asScopedToClient( + savedObjects.getScopedClient({} as KibanaRequest), + {} as ElasticsearchClient + ); const aggTypes = getAggTypes(); expect(start.types.getAll().buckets.length).toBe(aggTypes.buckets.length); @@ -103,7 +110,10 @@ describe('AggsService - server', () => { const start = await service .start(startDeps) - .asScopedToClient(savedObjects.getScopedClient({} as KibanaRequest)); + .asScopedToClient( + savedObjects.getScopedClient({} as KibanaRequest), + {} as ElasticsearchClient + ); const aggTypes = getAggTypes(); expect(start.types.getAll().buckets.length).toBe(aggTypes.buckets.length + 1); diff --git a/src/plugins/data/server/search/aggs/aggs_service.ts b/src/plugins/data/server/search/aggs/aggs_service.ts index c805c8af6694c..c23f748b1eeb5 100644 --- a/src/plugins/data/server/search/aggs/aggs_service.ts +++ b/src/plugins/data/server/search/aggs/aggs_service.ts @@ -19,7 +19,11 @@ import { pick } from 'lodash'; -import { UiSettingsServiceStart, SavedObjectsClientContract } from 'src/core/server'; +import { + UiSettingsServiceStart, + SavedObjectsClientContract, + ElasticsearchClient, +} from 'src/core/server'; import { ExpressionsServiceSetup } from 'src/plugins/expressions/common'; import { AggsCommonService, @@ -65,7 +69,10 @@ export class AggsService { public start({ fieldFormats, uiSettings, indexPatterns }: AggsStartDependencies): AggsStart { return { - asScopedToClient: async (savedObjectsClient: SavedObjectsClientContract) => { + asScopedToClient: async ( + savedObjectsClient: SavedObjectsClientContract, + elasticsearchClient: ElasticsearchClient + ) => { const uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient); const formats = await fieldFormats.fieldFormatServiceFactory(uiSettingsClient); @@ -82,8 +89,9 @@ export class AggsService { types, } = this.aggsCommonService.start({ getConfig, - getIndexPattern: (await indexPatterns.indexPatternsServiceFactory(savedObjectsClient)) - .get, + getIndexPattern: ( + await indexPatterns.indexPatternsServiceFactory(savedObjectsClient, elasticsearchClient) + ).get, isDefaultTimezone, }); diff --git a/src/plugins/data/server/search/aggs/types.ts b/src/plugins/data/server/search/aggs/types.ts index 1b21d948b25d9..2c28c970cbb84 100644 --- a/src/plugins/data/server/search/aggs/types.ts +++ b/src/plugins/data/server/search/aggs/types.ts @@ -17,11 +17,14 @@ * under the License. */ -import { SavedObjectsClientContract } from 'src/core/server'; +import { SavedObjectsClientContract, ElasticsearchClient } from 'src/core/server'; import { AggsCommonSetup, AggsStart as Start } from '../../../common'; export type AggsSetup = AggsCommonSetup; export interface AggsStart { - asScopedToClient: (savedObjectsClient: SavedObjectsClientContract) => Promise; + asScopedToClient: ( + savedObjectsClient: SavedObjectsClientContract, + elasticsearchClient: ElasticsearchClient + ) => Promise; } diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts index c5a60c42a41c9..d8aa588719e3e 100644 --- a/src/plugins/data/server/search/search_service.ts +++ b/src/plugins/data/server/search/search_service.ts @@ -177,7 +177,11 @@ export class SearchService implements Plugin { const { elasticsearch, savedObjects, uiSettings } = core; const asScoped = this.asScopedProvider(core); return { - aggs: this.aggsService.start({ fieldFormats, uiSettings, indexPatterns }), + aggs: this.aggsService.start({ + fieldFormats, + uiSettings, + indexPatterns, + }), getSearchStrategy: this.getSearchStrategy, asScoped, searchSource: { @@ -185,7 +189,8 @@ export class SearchService implements Plugin { const esClient = elasticsearch.client.asScoped(request); const savedObjectsClient = savedObjects.getScopedClient(request); const scopedIndexPatterns = await indexPatterns.indexPatternsServiceFactory( - savedObjectsClient + savedObjectsClient, + esClient.asCurrentUser ); const uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient); diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index 5b0e0499e29bf..131b3e4c39c6b 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -17,7 +17,8 @@ import { CoreStart as CoreStart_2 } from 'kibana/server'; import { Datatable } from 'src/plugins/expressions/common'; import { DatatableColumn } from 'src/plugins/expressions'; import { Duration } from 'moment'; -import { ElasticsearchClient } from 'kibana/server'; +import { ElasticsearchClient } from 'src/core/server'; +import { ElasticsearchClient as ElasticsearchClient_2 } from 'kibana/server'; import { Ensure } from '@kbn/utility-types'; import { EnvironmentMode } from '@kbn/config'; import { ErrorToastOptions } from 'src/core/public/notifications'; @@ -389,6 +390,15 @@ export type Filter = { query?: any; }; +// Warning: (ae-missing-release-tag) "getCapabilitiesForRollupIndices" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export function getCapabilitiesForRollupIndices(indices: { + [key: string]: any; +}): { + [key: string]: any; +}; + // Warning: (ae-forgotten-export) The symbol "IUiSettingsClient" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "getDefaultSearchParams" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -688,7 +698,7 @@ export const indexPatterns: { // // @public (undocumented) export class IndexPatternsFetcher { - constructor(elasticsearchClient: ElasticsearchClient, allowNoIndices?: boolean); + constructor(elasticsearchClient: ElasticsearchClient_2, allowNoIndices?: boolean); getFieldsForTimePattern(options: { pattern: string; metaFields: string[]; @@ -701,6 +711,8 @@ export class IndexPatternsFetcher { fieldCapsOptions?: { allow_no_indices: boolean; }; + type?: string; + rollupIndex?: string; }): Promise; } @@ -715,7 +727,7 @@ export class IndexPatternsService implements Plugin_3 Promise; + indexPatternsServiceFactory: (savedObjectsClient: SavedObjectsClientContract_2, elasticsearchClient: ElasticsearchClient_2) => Promise; }; } @@ -824,6 +836,15 @@ export interface KueryNode { type: keyof NodeTypes; } +// Warning: (ae-missing-release-tag) "mergeCapabilitiesWithFields" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export const mergeCapabilitiesWithFields: (rollupIndexCapabilities: { + [key: string]: any; +}, fieldsFromFieldCapsApi: { + [key: string]: any; +}, previousFields?: FieldDescriptor[]) => FieldDescriptor[]; + // Warning: (ae-missing-release-tag) "METRIC_TYPES" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -927,7 +948,7 @@ export class Plugin implements Plugin_2 Promise; }; indexPatterns: { - indexPatternsServiceFactory: (savedObjectsClient: Pick) => Promise; + indexPatternsServiceFactory: (savedObjectsClient: Pick, elasticsearchClient: import("src/core/server").ElasticsearchClient) => Promise; }; search: ISearchStart>; }; @@ -1195,22 +1216,22 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:127:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:127:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:241:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:241:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:241:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:241:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:256:5 - (ae-forgotten-export) The symbol "getTotalLoaded" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:257:5 - (ae-forgotten-export) The symbol "toSnakeCase" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:261:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:262:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:271:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:272:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:273:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:277:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:278:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:282:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:285:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index_patterns/index_patterns_service.ts:50:14 - (ae-forgotten-export) The symbol "IndexPatternsService" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:258:5 - (ae-forgotten-export) The symbol "getTotalLoaded" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:259:5 - (ae-forgotten-export) The symbol "toSnakeCase" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:263:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:264:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:273:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:274:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:275:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:279:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:280:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:284:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:287:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index_patterns/index_patterns_service.ts:58:14 - (ae-forgotten-export) The symbol "IndexPatternsService" needs to be exported by the entry point index.d.ts // src/plugins/data/server/plugin.ts:88:66 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts // src/plugins/data/server/search/types.ts:104:5 - (ae-forgotten-export) The symbol "ISearchStartSearchSource" needs to be exported by the entry point index.d.ts diff --git a/src/plugins/vis_type_timeseries/server/lib/get_fields.ts b/src/plugins/vis_type_timeseries/server/lib/get_fields.ts index b52188129f77f..dc49e280a2bb7 100644 --- a/src/plugins/vis_type_timeseries/server/lib/get_fields.ts +++ b/src/plugins/vis_type_timeseries/server/lib/get_fields.ts @@ -62,10 +62,12 @@ export async function getFields( let indexPatternString = indexPattern; if (!indexPatternString) { - const [{ savedObjects }, { data }] = await framework.core.getStartServices(); + const [{ savedObjects, elasticsearch }, { data }] = await framework.core.getStartServices(); const savedObjectsClient = savedObjects.getScopedClient(request); + const clusterClient = elasticsearch.client.asScoped(request).asCurrentUser; const indexPatternsService = await data.indexPatterns.indexPatternsServiceFactory( - savedObjectsClient + savedObjectsClient, + clusterClient ); const defaultIndexPattern = await indexPatternsService.getDefault(); indexPatternString = get(defaultIndexPattern, 'title', ''); diff --git a/test/plugin_functional/plugins/data_search/server/plugin.ts b/test/plugin_functional/plugins/data_search/server/plugin.ts index e016ef56802f3..ca22e82188403 100644 --- a/test/plugin_functional/plugins/data_search/server/plugin.ts +++ b/test/plugin_functional/plugins/data_search/server/plugin.ts @@ -58,14 +58,16 @@ export class DataSearchTestPlugin }, }, async (context, req, res) => { - const [{ savedObjects }, { data }] = await core.getStartServices(); + const [{ savedObjects, elasticsearch }, { data }] = await core.getStartServices(); const service = await data.search.searchSource.asScoped(req); + const clusterClient = elasticsearch.client.asScoped(req).asCurrentUser; const savedObjectsClient = savedObjects.getScopedClient(req); // Since the index pattern ID can change on each test run, we need // to look it up on the fly and insert it into the request. const indexPatterns = await data.indexPatterns.indexPatternsServiceFactory( - savedObjectsClient + savedObjectsClient, + clusterClient ); const ids = await indexPatterns.getIds(); // @ts-expect-error Force overwriting the request diff --git a/test/plugin_functional/plugins/index_patterns/server/plugin.ts b/test/plugin_functional/plugins/index_patterns/server/plugin.ts index a54502b740211..c05b71b834c70 100644 --- a/test/plugin_functional/plugins/index_patterns/server/plugin.ts +++ b/test/plugin_functional/plugins/index_patterns/server/plugin.ts @@ -36,13 +36,35 @@ export class IndexPatternsTestPlugin public setup(core: CoreSetup) { const router = core.http.createRouter(); + router.post( + { + path: '/api/index-patterns-plugin/create', + validate: { + body: schema.object({}, { unknowns: 'allow' }), + }, + }, + async (context, req, res) => { + const [{ savedObjects, elasticsearch }, { data }] = await core.getStartServices(); + const savedObjectsClient = savedObjects.getScopedClient(req); + const service = await data.indexPatterns.indexPatternsServiceFactory( + savedObjectsClient, + elasticsearch.client.asScoped(req).asCurrentUser + ); + const ids = await service.createAndSave(req.body); + return res.ok({ body: ids }); + } + ); + router.get( { path: '/api/index-patterns-plugin/get-all', validate: false }, async (context, req, res) => { - const [{ savedObjects }, { data }] = await core.getStartServices(); + const [{ savedObjects, elasticsearch }, { data }] = await core.getStartServices(); const savedObjectsClient = savedObjects.getScopedClient(req); - const service = await data.indexPatterns.indexPatternsServiceFactory(savedObjectsClient); - const ids = await service.getIds(); + const service = await data.indexPatterns.indexPatternsServiceFactory( + savedObjectsClient, + elasticsearch.client.asScoped(req).asCurrentUser + ); + const ids = await service.getIds(true); return res.ok({ body: ids }); } ); @@ -58,9 +80,12 @@ export class IndexPatternsTestPlugin }, async (context, req, res) => { const id = (req.params as Record).id; - const [{ savedObjects }, { data }] = await core.getStartServices(); + const [{ savedObjects, elasticsearch }, { data }] = await core.getStartServices(); const savedObjectsClient = savedObjects.getScopedClient(req); - const service = await data.indexPatterns.indexPatternsServiceFactory(savedObjectsClient); + const service = await data.indexPatterns.indexPatternsServiceFactory( + savedObjectsClient, + elasticsearch.client.asScoped(req).asCurrentUser + ); const ip = await service.get(id); return res.ok({ body: ip.toSpec() }); } @@ -76,10 +101,13 @@ export class IndexPatternsTestPlugin }, }, async (context, req, res) => { - const [{ savedObjects }, { data }] = await core.getStartServices(); + const [{ savedObjects, elasticsearch }, { data }] = await core.getStartServices(); const id = (req.params as Record).id; const savedObjectsClient = savedObjects.getScopedClient(req); - const service = await data.indexPatterns.indexPatternsServiceFactory(savedObjectsClient); + const service = await data.indexPatterns.indexPatternsServiceFactory( + savedObjectsClient, + elasticsearch.client.asScoped(req).asCurrentUser + ); const ip = await service.get(id); await service.updateSavedObject(ip); return res.ok(); @@ -96,10 +124,13 @@ export class IndexPatternsTestPlugin }, }, async (context, req, res) => { - const [{ savedObjects }, { data }] = await core.getStartServices(); + const [{ savedObjects, elasticsearch }, { data }] = await core.getStartServices(); const id = (req.params as Record).id; const savedObjectsClient = savedObjects.getScopedClient(req); - const service = await data.indexPatterns.indexPatternsServiceFactory(savedObjectsClient); + const service = await data.indexPatterns.indexPatternsServiceFactory( + savedObjectsClient, + elasticsearch.client.asScoped(req).asCurrentUser + ); await service.delete(id); return res.ok(); } diff --git a/test/plugin_functional/test_suites/data_plugin/index_patterns.ts b/test/plugin_functional/test_suites/data_plugin/index_patterns.ts index 2c846dc780311..2e94f61c7ded8 100644 --- a/test/plugin_functional/test_suites/data_plugin/index_patterns.ts +++ b/test/plugin_functional/test_suites/data_plugin/index_patterns.ts @@ -23,16 +23,25 @@ import '../../plugins/core_provider_plugin/types'; export default function ({ getService }: PluginFunctionalProviderContext) { const supertest = getService('supertest'); - // skipping the tests as it deletes index patterns created by other test causing unexpected failures - // https://github.com/elastic/kibana/issues/79886 - describe.skip('index patterns', function () { + describe('index patterns', function () { let indexPatternId = ''; - it('can get all ids', async () => { - const body = await (await supertest.get('/api/index-patterns-plugin/get-all').expect(200)) - .body; - indexPatternId = body[0]; - expect(body.length > 0).to.equal(true); + it('can create an index pattern', async () => { + const title = 'shakes*'; + const fieldFormats = { bytes: { id: 'bytes' } }; + const body = await ( + await supertest + .post('/api/index-patterns-plugin/create') + .set('kbn-xsrf', 'anything') + .send({ title, fieldFormats }) + .expect(200) + ).body; + + indexPatternId = body.id; + expect(body.id).not.empty(); + expect(body.title).to.equal(title); + expect(body.fields.length).to.equal(15); + expect(body.fieldFormatMap).to.eql(fieldFormats); }); it('can get index pattern by id', async () => { diff --git a/x-pack/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js b/x-pack/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js index 643cc3efb0136..e021831d2f438 100644 --- a/x-pack/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js +++ b/x-pack/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js @@ -161,9 +161,7 @@ export class RollupIndexPatternCreationConfig extends IndexPatternCreationConfig getFetchForWildcardOptions = () => { return { type: this.type, - params: { - rollup_index: this.rollupIndex, - }, + rollupIndex: this.rollupIndex, }; }; } diff --git a/x-pack/plugins/rollup/server/lib/__tests__/fixtures/index.js b/x-pack/plugins/rollup/server/lib/__tests__/fixtures/index.js deleted file mode 100644 index e97606c1fadfb..0000000000000 --- a/x-pack/plugins/rollup/server/lib/__tests__/fixtures/index.js +++ /dev/null @@ -1,7 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -export { jobs } from './jobs'; diff --git a/x-pack/plugins/rollup/server/lib/map_capabilities.ts b/x-pack/plugins/rollup/server/lib/map_capabilities.ts deleted file mode 100644 index 233c6d1dd4b4b..0000000000000 --- a/x-pack/plugins/rollup/server/lib/map_capabilities.ts +++ /dev/null @@ -1,24 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -import { mergeJobConfigurations } from './jobs_compatibility'; - -export function getCapabilitiesForRollupIndices(indices: { [key: string]: any }) { - const indexNames = Object.keys(indices); - const capabilities = {} as { [key: string]: any }; - - indexNames.forEach((index) => { - try { - capabilities[index] = mergeJobConfigurations(indices[index].rollup_jobs); - } catch (e) { - capabilities[index] = { - error: e.message, - }; - } - }); - - return capabilities; -} diff --git a/x-pack/plugins/rollup/server/lib/search_strategies/rollup_search_strategy.ts b/x-pack/plugins/rollup/server/lib/search_strategies/rollup_search_strategy.ts index f439ac555aed9..dcf6629d35397 100644 --- a/x-pack/plugins/rollup/server/lib/search_strategies/rollup_search_strategy.ts +++ b/x-pack/plugins/rollup/server/lib/search_strategies/rollup_search_strategy.ts @@ -6,8 +6,11 @@ import { keyBy, isString } from 'lodash'; import { ILegacyScopedClusterClient } from 'src/core/server'; import { ReqFacade } from '../../../../../../src/plugins/vis_type_timeseries/server'; -import { mergeCapabilitiesWithFields } from '../merge_capabilities_with_fields'; -import { getCapabilitiesForRollupIndices } from '../map_capabilities'; + +import { + mergeCapabilitiesWithFields, + getCapabilitiesForRollupIndices, +} from '../../../../../../src/plugins/data/server'; const getRollupIndices = (rollupData: { [key: string]: any }) => Object.keys(rollupData); diff --git a/x-pack/plugins/rollup/server/plugin.ts b/x-pack/plugins/rollup/server/plugin.ts index fe193150fc1ca..51920af7c8cbc 100644 --- a/x-pack/plugins/rollup/server/plugin.ts +++ b/x-pack/plugins/rollup/server/plugin.ts @@ -36,8 +36,7 @@ import { registerRollupSearchStrategy } from './lib/search_strategies'; import { elasticsearchJsPlugin } from './client/elasticsearch_rollup'; import { isEsError } from './shared_imports'; import { formatEsError } from './lib/format_es_error'; -import { getCapabilitiesForRollupIndices } from './lib/map_capabilities'; -import { mergeCapabilitiesWithFields } from './lib/merge_capabilities_with_fields'; +import { getCapabilitiesForRollupIndices } from '../../../../src/plugins/data/server'; interface RollupContext { client: ILegacyScopedClusterClient; @@ -107,7 +106,6 @@ export class RollupPlugin implements Plugin { isEsError, formatEsError, getCapabilitiesForRollupIndices, - mergeCapabilitiesWithFields, }, sharedImports: { IndexPatternsFetcher, diff --git a/x-pack/plugins/rollup/server/routes/api/index_patterns/index.ts b/x-pack/plugins/rollup/server/routes/api/index_patterns/index.ts deleted file mode 100644 index 7bf525ca4aa98..0000000000000 --- a/x-pack/plugins/rollup/server/routes/api/index_patterns/index.ts +++ /dev/null @@ -1,12 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -import { RouteDependencies } from '../../../types'; -import { registerFieldsForWildcardRoute } from './register_fields_for_wildcard_route'; - -export function registerIndexPatternsRoutes(dependencies: RouteDependencies) { - registerFieldsForWildcardRoute(dependencies); -} diff --git a/x-pack/plugins/rollup/server/routes/api/index_patterns/register_fields_for_wildcard_route.ts b/x-pack/plugins/rollup/server/routes/api/index_patterns/register_fields_for_wildcard_route.ts deleted file mode 100644 index df9907fbf731a..0000000000000 --- a/x-pack/plugins/rollup/server/routes/api/index_patterns/register_fields_for_wildcard_route.ts +++ /dev/null @@ -1,142 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -import { keyBy } from 'lodash'; -import { schema } from '@kbn/config-schema'; -import { Field } from '../../../lib/merge_capabilities_with_fields'; -import { RouteDependencies } from '../../../types'; -import type { IndexPatternsFetcher as IndexPatternsFetcherType } from '../../../../../../../src/plugins/data/server'; - -const parseMetaFields = (metaFields: string | string[]) => { - let parsedFields: string[] = []; - if (typeof metaFields === 'string') { - parsedFields = JSON.parse(metaFields); - } else { - parsedFields = metaFields; - } - return parsedFields; -}; - -const getFieldsForWildcardRequest = async ( - context: any, - request: any, - response: any, - IndexPatternsFetcher: typeof IndexPatternsFetcherType -) => { - const { asCurrentUser } = context.core.elasticsearch.client; - const indexPatterns = new IndexPatternsFetcher(asCurrentUser); - const { pattern, meta_fields: metaFields } = request.query; - - let parsedFields: string[] = []; - try { - parsedFields = parseMetaFields(metaFields); - } catch (error) { - return response.badRequest({ - body: error, - }); - } - - try { - const fields = await indexPatterns.getFieldsForWildcard({ - pattern, - metaFields: parsedFields, - }); - - return response.ok({ - body: { fields }, - headers: { - 'content-type': 'application/json', - }, - }); - } catch (error) { - return response.notFound(); - } -}; - -/** - * Get list of fields for rollup index pattern, in the format of regular index pattern fields - */ -export const registerFieldsForWildcardRoute = ({ - router, - license, - lib: { isEsError, formatEsError, getCapabilitiesForRollupIndices, mergeCapabilitiesWithFields }, - sharedImports: { IndexPatternsFetcher }, -}: RouteDependencies) => { - const querySchema = schema.object({ - pattern: schema.string(), - meta_fields: schema.arrayOf(schema.string(), { - defaultValue: [], - }), - params: schema.string({ - validate(value) { - try { - const params = JSON.parse(value); - const keys = Object.keys(params); - const { rollup_index: rollupIndex } = params; - - if (!rollupIndex) { - return '[request query.params]: "rollup_index" is required'; - } else if (keys.length > 1) { - const invalidParams = keys.filter((key) => key !== 'rollup_index'); - return `[request query.params]: ${invalidParams.join(', ')} is not allowed`; - } - } catch (err) { - return '[request query.params]: expected JSON string'; - } - }, - }), - }); - - router.get( - { - path: '/api/index_patterns/rollup/_fields_for_wildcard', - validate: { - query: querySchema, - }, - }, - license.guardApiRoute(async (context, request, response) => { - const { params, meta_fields: metaFields } = request.query; - - try { - // Make call and use field information from response - const { payload } = await getFieldsForWildcardRequest( - context, - request, - response, - IndexPatternsFetcher - ); - const fields = payload.fields; - const parsedParams = JSON.parse(params); - const rollupIndex = parsedParams.rollup_index; - const rollupFields: Field[] = []; - const fieldsFromFieldCapsApi: { [key: string]: any } = keyBy(fields, 'name'); - const rollupIndexCapabilities = getCapabilitiesForRollupIndices( - await context.rollup!.client.callAsCurrentUser('rollup.rollupIndexCapabilities', { - indexPattern: rollupIndex, - }) - )[rollupIndex].aggs; - - // Keep meta fields - metaFields.forEach( - (field: string) => - fieldsFromFieldCapsApi[field] && rollupFields.push(fieldsFromFieldCapsApi[field]) - ); - - const mergedRollupFields = mergeCapabilitiesWithFields( - rollupIndexCapabilities, - fieldsFromFieldCapsApi, - rollupFields - ); - return response.ok({ body: { fields: mergedRollupFields } }); - } catch (err) { - if (isEsError(err)) { - return response.customError({ statusCode: err.statusCode, body: err }); - } - return response.internalError({ body: err }); - } - }) - ); -}; diff --git a/x-pack/plugins/rollup/server/routes/index.ts b/x-pack/plugins/rollup/server/routes/index.ts index b25480855b4a2..322003c0ee325 100644 --- a/x-pack/plugins/rollup/server/routes/index.ts +++ b/x-pack/plugins/rollup/server/routes/index.ts @@ -6,13 +6,11 @@ import { RouteDependencies } from '../types'; -import { registerIndexPatternsRoutes } from './api/index_patterns'; import { registerIndicesRoutes } from './api/indices'; import { registerJobsRoutes } from './api/jobs'; import { registerSearchRoutes } from './api/search'; export function registerApiRoutes(dependencies: RouteDependencies) { - registerIndexPatternsRoutes(dependencies); registerIndicesRoutes(dependencies); registerJobsRoutes(dependencies); registerSearchRoutes(dependencies); diff --git a/x-pack/plugins/rollup/server/types.ts b/x-pack/plugins/rollup/server/types.ts index b167806cf8d5d..89e13e69c4da2 100644 --- a/x-pack/plugins/rollup/server/types.ts +++ b/x-pack/plugins/rollup/server/types.ts @@ -8,6 +8,7 @@ import { IRouter } from 'src/core/server'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; import { VisTypeTimeseriesSetup } from 'src/plugins/vis_type_timeseries/server'; +import { getCapabilitiesForRollupIndices } from 'src/plugins/data/server'; import { IndexManagementPluginSetup } from '../../index_management/server'; import { PluginSetupContract as FeaturesPluginSetup } from '../../features/server'; import { LicensingPluginSetup } from '../../licensing/server'; @@ -15,8 +16,6 @@ import { License } from './services'; import { IndexPatternsFetcher } from './shared_imports'; import { isEsError } from './shared_imports'; import { formatEsError } from './lib/format_es_error'; -import { getCapabilitiesForRollupIndices } from './lib/map_capabilities'; -import { mergeCapabilitiesWithFields } from './lib/merge_capabilities_with_fields'; export interface Dependencies { indexManagement?: IndexManagementPluginSetup; @@ -33,7 +32,6 @@ export interface RouteDependencies { isEsError: typeof isEsError; formatEsError: typeof formatEsError; getCapabilitiesForRollupIndices: typeof getCapabilitiesForRollupIndices; - mergeCapabilitiesWithFields: typeof mergeCapabilitiesWithFields; }; sharedImports: { IndexPatternsFetcher: typeof IndexPatternsFetcher; diff --git a/x-pack/test/api_integration/apis/management/rollup/constants.js b/x-pack/test/api_integration/apis/management/rollup/constants.js index fe899c4c10c88..0313434cf716c 100644 --- a/x-pack/test/api_integration/apis/management/rollup/constants.js +++ b/x-pack/test/api_integration/apis/management/rollup/constants.js @@ -5,7 +5,7 @@ */ export const API_BASE_PATH = '/api/rollup'; -export const INDEX_PATTERNS_EXTENSION_BASE_PATH = '/api/index_patterns/rollup'; +export const INDEX_PATTERNS_EXTENSION_BASE_PATH = '/api/index_patterns'; export const ROLLUP_INDEX_NAME = 'rollup_index'; export const INDEX_TO_ROLLUP_MAPPINGS = { properties: { diff --git a/x-pack/test/api_integration/apis/management/rollup/index_patterns_extensions.js b/x-pack/test/api_integration/apis/management/rollup/index_patterns_extensions.js index 357b952e7e66d..0a93e8b8bd1e3 100644 --- a/x-pack/test/api_integration/apis/management/rollup/index_patterns_extensions.js +++ b/x-pack/test/api_integration/apis/management/rollup/index_patterns_extensions.js @@ -26,7 +26,6 @@ export default function ({ getService }) { describe('query params validation', () => { let uri; let body; - let params; it('"pattern" is required', async () => { uri = `${BASE_URI}`; @@ -36,62 +35,17 @@ export default function ({ getService }) { ); }); - it('"params" is required', async () => { - params = { pattern: 'foo' }; - uri = `${BASE_URI}?${stringify(params, { sort: false })}`; - ({ body } = await supertest.get(uri).expect(400)); - expect(body.message).to.contain( - '[request query.params]: expected value of type [string]' - ); - }); - - it('"params" must be a valid JSON string', async () => { - params = { pattern: 'foo', params: 'foobarbaz' }; - uri = `${BASE_URI}?${stringify(params, { sort: false })}`; - ({ body } = await supertest.get(uri).expect(400)); - expect(body.message).to.contain('[request query.params]: expected JSON string'); - }); - - it('"params" requires a "rollup_index" property', async () => { - params = { pattern: 'foo', params: JSON.stringify({}) }; - uri = `${BASE_URI}?${stringify(params, { sort: false })}`; - ({ body } = await supertest.get(uri).expect(400)); - expect(body.message).to.contain('[request query.params]: "rollup_index" is required'); - }); - - it('"params" only accepts a "rollup_index" property', async () => { - params = { - pattern: 'foo', - params: JSON.stringify({ rollup_index: 'my_index', someProp: 'bar' }), - }; - uri = `${BASE_URI}?${stringify(params, { sort: false })}`; - ({ body } = await supertest.get(uri).expect(400)); - expect(body.message).to.contain('[request query.params]: someProp is not allowed'); - }); - - it('"meta_fields" must be an Array', async () => { - params = { - pattern: 'foo', - params: JSON.stringify({ rollup_index: 'bar' }), - meta_fields: 'stringValue', - }; - uri = `${BASE_URI}?${stringify(params, { sort: false })}`; - ({ body } = await supertest.get(uri).expect(400)); - expect(body.message).to.contain( - '[request query.meta_fields]: could not parse array value from json input' - ); - }); - it('should return 404 the rollup index to query does not exist', async () => { uri = `${BASE_URI}?${stringify( { pattern: 'foo', - params: JSON.stringify({ rollup_index: 'bar' }), + type: 'rollup', + rollup_index: 'bar', }, { sort: false } )}`; ({ body } = await supertest.get(uri).expect(404)); - expect(body.message).to.contain('[index_not_found_exception] no such index [bar]'); + expect(body.message).to.contain('No indices match pattern "foo"'); }); }); @@ -105,7 +59,8 @@ export default function ({ getService }) { // Query for wildcard const params = { pattern: indexName, - params: JSON.stringify({ rollup_index: rollupIndex }), + type: 'rollup', + rollup_index: rollupIndex, }; const uri = `${BASE_URI}?${stringify(params, { sort: false })}`; const { body } = await supertest.get(uri).expect(200); From f193d9c96271d0ad7c1b3c721a9f82690e4751b6 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Mon, 9 Nov 2020 17:33:13 -0700 Subject: [PATCH 05/80] [data.search.aggs] Throw an error when trying to create an agg type that doesn't exist. (#81509) --- .../common/search/aggs/agg_config.test.ts | 10 --------- .../common/search/aggs/agg_configs.test.ts | 21 +++++++++++++++++++ .../data/common/search/aggs/agg_configs.ts | 19 +++++++++++++++-- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/plugins/data/common/search/aggs/agg_config.test.ts b/src/plugins/data/common/search/aggs/agg_config.test.ts index f6fcc29805dc4..9bb47f5cb3575 100644 --- a/src/plugins/data/common/search/aggs/agg_config.test.ts +++ b/src/plugins/data/common/search/aggs/agg_config.test.ts @@ -680,16 +680,6 @@ describe('AggConfig', () => { const json = aggConfig.toExpressionAst()?.arguments.json; expect(json).toEqual([JSON.stringify(configStates.params.json)]); }); - - it(`returns undefined if an expressionName doesn't exist on the agg type`, () => { - const ac = new AggConfigs(indexPattern, [], { typesRegistry }); - const configStates = { - type: 'unknown type', - params: {}, - }; - const aggConfig = ac.createAggConfig(configStates); - expect(aggConfig.toExpressionAst()).toBe(undefined); - }); }); describe('#makeLabel', () => { diff --git a/src/plugins/data/common/search/aggs/agg_configs.test.ts b/src/plugins/data/common/search/aggs/agg_configs.test.ts index 803ccc70b98a7..d1c8e29a03cc7 100644 --- a/src/plugins/data/common/search/aggs/agg_configs.test.ts +++ b/src/plugins/data/common/search/aggs/agg_configs.test.ts @@ -150,6 +150,27 @@ describe('AggConfigs', () => { ); expect(ac.aggs).toHaveLength(1); }); + + it(`throws if trying to add an agg which doesn't have a type in the registry`, () => { + const configStates = [ + { + enabled: true, + type: 'histogram', + params: {}, + }, + ]; + + const ac = new AggConfigs(indexPattern, configStates, { typesRegistry }); + expect(() => + ac.createAggConfig({ + enabled: true, + type: 'oops', + params: {}, + }) + ).toThrowErrorMatchingInlineSnapshot( + `"Unable to find a registered agg type for \\"oops\\"."` + ); + }); }); describe('#getRequestAggs', () => { diff --git a/src/plugins/data/common/search/aggs/agg_configs.ts b/src/plugins/data/common/search/aggs/agg_configs.ts index 282e6f3b538a4..368f44f161132 100644 --- a/src/plugins/data/common/search/aggs/agg_configs.ts +++ b/src/plugins/data/common/search/aggs/agg_configs.ts @@ -18,6 +18,7 @@ */ import _ from 'lodash'; +import { i18n } from '@kbn/i18n'; import { Assign } from '@kbn/utility-types'; import { ISearchOptions, ISearchSource } from 'src/plugins/data/public'; @@ -122,15 +123,29 @@ export class AggConfigs { { addToAggConfigs = true } = {} ) => { const { type } = params; - let aggConfig; + const getType = (t: string) => { + const typeFromRegistry = this.typesRegistry.get(t); + + if (!typeFromRegistry) { + throw new Error( + i18n.translate('data.search.aggs.error.aggNotFound', { + defaultMessage: 'Unable to find a registered agg type for "{type}".', + values: { type: type as string }, + }) + ); + } + return typeFromRegistry; + }; + + let aggConfig; if (params instanceof AggConfig) { aggConfig = params; params.parent = this; } else { aggConfig = new AggConfig(this, { ...params, - type: typeof type === 'string' ? this.typesRegistry.get(type) : type, + type: typeof type === 'string' ? getType(type) : type, }); } From bafe9dfea1ca7c44b0e1283860659b08467bc3ef Mon Sep 17 00:00:00 2001 From: Marco Liberati Date: Tue, 10 Nov 2020 10:05:32 +0100 Subject: [PATCH 06/80] [Lens] Distinct icons for XY and pie chart value labels toolbar (#82927) --- x-pack/plugins/lens/public/pie_visualization/toolbar.tsx | 2 +- .../plugins/lens/public/shared_components/toolbar_popover.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx b/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx index ab7422c3eeb63..d69164de8a6aa 100644 --- a/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx +++ b/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx @@ -125,7 +125,7 @@ export function PieToolbar(props: VisualizationToolbarProps diff --git a/x-pack/plugins/lens/public/shared_components/toolbar_popover.tsx b/x-pack/plugins/lens/public/shared_components/toolbar_popover.tsx index 20837424dc7b5..cf2268c6eadf2 100644 --- a/x-pack/plugins/lens/public/shared_components/toolbar_popover.tsx +++ b/x-pack/plugins/lens/public/shared_components/toolbar_popover.tsx @@ -11,6 +11,7 @@ import { EuiIconLegend } from '../assets/legend'; const typeToIconMap: { [type: string]: string | IconType } = { legend: EuiIconLegend as IconType, + labels: 'visText', values: 'number', }; From 1de3a02a4620ba02151985a622647e6d8c95c3bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yulia=20=C4=8Cech?= <6585477+yuliacech@users.noreply.github.com> Date: Tue, 10 Nov 2020 11:09:37 +0100 Subject: [PATCH 07/80] Fix ilm navigation (#81664) * Fix edit policy page navigation * Fix edit policy page navigation * Add links to PR for explanation * Added more tests and linked to a github issue about navigation issues * Fix decoding function for undefined values * Fix type check issues * Renamed dollar sign to percent sign, added a method for (double) encoded paths and better description in test names * Deleted Index Management from required bundles in ILM * Fixed merge conflicts * Revert "Deleted Index Management from required bundles in ILM" This reverts commit 5a735dfe Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../public/url/attempt_to_uri_decode.test.ts | 49 +++- .../public/url/attempt_to_uri_decode.ts | 8 +- .../client_integration/app/app.helpers.tsx | 74 +++++ .../client_integration/app/app.test.ts | 252 ++++++++++++++++++ .../edit_policy/constants.ts | 20 ++ .../edit_policy/edit_policy.test.ts | 3 +- .../client_integration/helpers/index.ts | 3 + .../public/application/app.tsx | 40 +-- .../public/application/index.tsx | 8 +- .../edit_policy/edit_policy.container.tsx | 6 +- .../sections/edit_policy/edit_policy.tsx | 2 +- .../public/shared_imports.ts | 2 + .../component_template_details.tsx | 2 +- .../component_template_list.tsx | 6 +- .../component_template_clone.tsx | 2 +- .../component_template_edit.tsx | 2 +- .../data_stream_list/data_stream_list.tsx | 2 +- .../home/template_list/template_list.tsx | 2 +- .../template_clone/template_clone.tsx | 2 +- .../sections/template_edit/template_edit.tsx | 2 +- .../pipelines_clone/pipelines_clone.tsx | 2 +- .../pipelines_edit/pipelines_edit.tsx | 2 +- 22 files changed, 448 insertions(+), 43 deletions(-) create mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.helpers.tsx create mode 100644 x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.test.ts diff --git a/src/plugins/es_ui_shared/public/url/attempt_to_uri_decode.test.ts b/src/plugins/es_ui_shared/public/url/attempt_to_uri_decode.test.ts index 15750c7667800..6654611faa18b 100644 --- a/src/plugins/es_ui_shared/public/url/attempt_to_uri_decode.test.ts +++ b/src/plugins/es_ui_shared/public/url/attempt_to_uri_decode.test.ts @@ -19,14 +19,51 @@ import { attemptToURIDecode } from './attempt_to_uri_decode'; +// this function doesn't work for % with other special chars or sequence %25 +// known issue https://github.com/elastic/kibana/issues/82440 test('decodes an encoded string', () => { - const encodedString = 'test%3F'; - expect(attemptToURIDecode(encodedString)).toBe('test?'); + const originalName = 'test;,/?:@&=+$#'; + const encodedName = encodeURIComponent(originalName); + // react router v5 automatically decodes route match params + const reactRouterDecoded = decodeURI(encodedName); + + expect(attemptToURIDecode(encodedName)).toBe(originalName); + expect(attemptToURIDecode(reactRouterDecoded)).toBe(originalName); }); -// react router partially decodes %25 sequence to % in match params -// https://github.com/elastic/kibana/pull/81664 test('ignores the error if a string is already decoded', () => { - const decodedString = 'test%'; - expect(attemptToURIDecode(decodedString)).toBe(decodedString); + const originalName = 'test%'; + + const encodedName = encodeURIComponent(originalName); + // react router v5 automatically decodes route match params + const reactRouterDecoded = decodeURI(encodedName); + + expect(attemptToURIDecode(encodedName)).toBe(originalName); + expect(attemptToURIDecode(reactRouterDecoded)).toBe(originalName); +}); + +test('returns wrong decoded value for %25 sequence', () => { + const originalName = 'test%25'; + + const encodedName = encodeURIComponent(originalName); + // react router v5 automatically decodes route match params + const reactRouterDecoded = decodeURI(encodedName); + + expect(attemptToURIDecode(encodedName)).toBe(originalName); + expect(attemptToURIDecode(reactRouterDecoded)).not.toBe(originalName); +}); + +test('returns wrong decoded value for % with other escaped characters', () => { + const originalName = 'test%?#'; + + const encodedName = encodeURIComponent(originalName); + // react router v5 automatically decodes route match params + const reactRouterDecoded = decodeURI(encodedName); + + expect(attemptToURIDecode(encodedName)).toBe(originalName); + expect(attemptToURIDecode(reactRouterDecoded)).not.toBe(originalName); +}); + +test("doesn't convert undefined to a string", () => { + expect(attemptToURIDecode(undefined)).toBeUndefined(); }); diff --git a/src/plugins/es_ui_shared/public/url/attempt_to_uri_decode.ts b/src/plugins/es_ui_shared/public/url/attempt_to_uri_decode.ts index 65444b83f77bb..37e4761106e44 100644 --- a/src/plugins/es_ui_shared/public/url/attempt_to_uri_decode.ts +++ b/src/plugins/es_ui_shared/public/url/attempt_to_uri_decode.ts @@ -19,12 +19,14 @@ /* * Use this function with any match params coming from react router to safely decode values. - * https://github.com/elastic/kibana/pull/81664 + * After an update to react router v6, this functions should be deprecated. + * Known issue for navigation with special characters in paths + * https://github.com/elastic/kibana/issues/82440 */ -export const attemptToURIDecode = (value: string) => { +export const attemptToURIDecode = (value?: string): string | undefined => { let result = value; try { - result = decodeURIComponent(value); + result = value ? decodeURIComponent(value) : value; } catch (e) { // do nothing } diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.helpers.tsx b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.helpers.tsx new file mode 100644 index 0000000000000..de7242a6c5ddf --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.helpers.tsx @@ -0,0 +1,74 @@ +/* + * 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 React from 'react'; +import { act } from 'react-dom/test-utils'; +import { registerTestBed, TestBed, TestBedConfig } from '../../../../../test_utils'; +import { App } from '../../../public/application/app'; +import { TestSubjects } from '../helpers'; +import { createBreadcrumbsMock } from '../../../public/application/services/breadcrumbs.mock'; +import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public/context'; + +const breadcrumbService = createBreadcrumbsMock(); + +const AppWithContext = (props: any) => { + return ( + + + + ); +}; + +const getTestBedConfig = (initialEntries: string[]): TestBedConfig => ({ + memoryRouter: { + initialEntries, + }, + defaultProps: { + getUrlForApp: () => {}, + navigateToApp: () => {}, + }, +}); + +const initTestBed = (initialEntries: string[]) => + registerTestBed(AppWithContext, getTestBedConfig(initialEntries))(); + +export interface AppTestBed extends TestBed { + actions: { + clickPolicyNameLink: () => void; + clickCreatePolicyButton: () => void; + }; +} + +export const setup = async (initialEntries: string[]): Promise => { + const testBed = await initTestBed(initialEntries); + + const clickPolicyNameLink = async () => { + const { component, find } = testBed; + await act(async () => { + find('policyTablePolicyNameLink').simulate('click', { button: 0 }); + }); + component.update(); + }; + + const clickCreatePolicyButton = async () => { + const { component, find } = testBed; + await act(async () => { + find('createPolicyButton').simulate('click', { button: 0 }); + }); + component.update(); + }; + + return { + ...testBed, + actions: { clickPolicyNameLink, clickCreatePolicyButton }, + }; +}; + +export const getEncodedPolicyEditPath = (policyName: string): string => + `/policies/edit/${encodeURIComponent(policyName)}`; + +export const getDoubleEncodedPolicyEditPath = (policyName: string): string => + encodeURI(getEncodedPolicyEditPath(policyName)); diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.test.ts new file mode 100644 index 0000000000000..9052cf2847baa --- /dev/null +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/app/app.test.ts @@ -0,0 +1,252 @@ +/* + * 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 { + AppTestBed, + getDoubleEncodedPolicyEditPath, + getEncodedPolicyEditPath, + setup, +} from './app.helpers'; +import { setupEnvironment } from '../helpers/setup_environment'; +import { getDefaultHotPhasePolicy, POLICY_NAME } from '../edit_policy/constants'; +import { act } from 'react-dom/test-utils'; + +const SPECIAL_CHARS_NAME = 'test?#$+=&@:'; +const PERCENT_SIGN_NAME = 'test%'; +// navigation doesn't work for % with other special chars or sequence %25 +// known issue https://github.com/elastic/kibana/issues/82440 +const PERCENT_SIGN_WITH_OTHER_CHARS_NAME = 'test%#'; +const PERCENT_SIGN_25_SEQUENCE = 'test%25'; + +window.scrollTo = jest.fn(); + +describe('', () => { + let testBed: AppTestBed; + const { server, httpRequestsMockHelpers } = setupEnvironment(); + afterAll(() => { + server.restore(); + }); + + describe('new policy creation', () => { + test('when there are no policies', async () => { + httpRequestsMockHelpers.setLoadPolicies([]); + await act(async () => { + testBed = await setup(['/']); + }); + + const { component, actions } = testBed; + component.update(); + + await actions.clickCreatePolicyButton(); + component.update(); + + expect(testBed.find('policyTitle').text()).toBe(`Create an index lifecycle policy`); + expect(testBed.find('policyNameField').props().value).toBe(''); + }); + + test('when there are policies', async () => { + httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy(POLICY_NAME)]); + await act(async () => { + testBed = await setup(['/']); + }); + + const { component, actions } = testBed; + component.update(); + + await actions.clickCreatePolicyButton(); + component.update(); + + expect(testBed.find('policyTitle').text()).toBe(`Create an index lifecycle policy`); + expect(testBed.find('policyNameField').props().value).toBe(''); + }); + }); + + describe('navigation with special characters', () => { + beforeAll(async () => { + httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy(SPECIAL_CHARS_NAME)]); + }); + + test('clicking policy name in the table works', async () => { + await act(async () => { + testBed = await setup(['/']); + }); + + const { component, actions } = testBed; + component.update(); + + await actions.clickPolicyNameLink(); + component.update(); + + expect(testBed.find('policyTitle').text()).toBe( + `Edit index lifecycle policy ${SPECIAL_CHARS_NAME}` + ); + }); + + test('loading edit policy page url works', async () => { + await act(async () => { + testBed = await setup([getEncodedPolicyEditPath(SPECIAL_CHARS_NAME)]); + }); + + const { component } = testBed; + component.update(); + + expect(testBed.find('policyTitle').text()).toBe( + `Edit index lifecycle policy ${SPECIAL_CHARS_NAME}` + ); + }); + + // using double encoding to counteract react-router's v5 internal decodeURI call + // when those links are open in a new tab, address bar contains double encoded url + test('loading edit policy page url with double encoding works', async () => { + await act(async () => { + testBed = await setup([getDoubleEncodedPolicyEditPath(SPECIAL_CHARS_NAME)]); + }); + + const { component } = testBed; + component.update(); + + expect(testBed.find('policyTitle').text()).toBe( + `Edit index lifecycle policy ${SPECIAL_CHARS_NAME}` + ); + }); + }); + + describe('navigation with percent sign', () => { + beforeAll(async () => { + httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy(PERCENT_SIGN_NAME)]); + }); + + test('loading edit policy page url works', async () => { + await act(async () => { + testBed = await setup([getEncodedPolicyEditPath(PERCENT_SIGN_NAME)]); + }); + + const { component } = testBed; + component.update(); + + expect(testBed.find('policyTitle').text()).toBe( + `Edit index lifecycle policy ${PERCENT_SIGN_NAME}` + ); + }); + + test('loading edit policy page url with double encoding works', async () => { + await act(async () => { + testBed = await setup([getDoubleEncodedPolicyEditPath(PERCENT_SIGN_NAME)]); + }); + + const { component } = testBed; + component.update(); + + expect(testBed.find('policyTitle').text()).toBe( + `Edit index lifecycle policy ${PERCENT_SIGN_NAME}` + ); + }); + }); + + describe('navigation with percent sign with other special characters', () => { + beforeAll(async () => { + httpRequestsMockHelpers.setLoadPolicies([ + getDefaultHotPhasePolicy(PERCENT_SIGN_WITH_OTHER_CHARS_NAME), + ]); + }); + + test('clicking policy name in the table works', async () => { + await act(async () => { + testBed = await setup(['/']); + }); + + const { component, actions } = testBed; + component.update(); + + await actions.clickPolicyNameLink(); + component.update(); + + expect(testBed.find('policyTitle').text()).toBe( + `Edit index lifecycle policy ${PERCENT_SIGN_WITH_OTHER_CHARS_NAME}` + ); + }); + + test("loading edit policy page url doesn't work", async () => { + await act(async () => { + testBed = await setup([getEncodedPolicyEditPath(PERCENT_SIGN_WITH_OTHER_CHARS_NAME)]); + }); + + const { component } = testBed; + component.update(); + + // known issue https://github.com/elastic/kibana/issues/82440 + expect(testBed.find('policyTitle').text()).not.toBe( + `Edit index lifecycle policy ${PERCENT_SIGN_WITH_OTHER_CHARS_NAME}` + ); + }); + + // using double encoding to counteract react-router's v5 internal decodeURI call + // when those links are open in a new tab, address bar contains double encoded url + test('loading edit policy page url with double encoding works', async () => { + await act(async () => { + testBed = await setup([getDoubleEncodedPolicyEditPath(PERCENT_SIGN_WITH_OTHER_CHARS_NAME)]); + }); + + const { component } = testBed; + component.update(); + + expect(testBed.find('policyTitle').text()).toBe( + `Edit index lifecycle policy ${PERCENT_SIGN_WITH_OTHER_CHARS_NAME}` + ); + }); + }); + + describe('navigation with %25 sequence', () => { + beforeAll(async () => { + httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy(PERCENT_SIGN_25_SEQUENCE)]); + }); + + test('clicking policy name in the table works correctly', async () => { + await act(async () => { + testBed = await setup(['/']); + }); + + const { component, actions } = testBed; + component.update(); + + await actions.clickPolicyNameLink(); + component.update(); + + expect(testBed.find('policyTitle').text()).toBe( + `Edit index lifecycle policy ${PERCENT_SIGN_25_SEQUENCE}` + ); + }); + + test("loading edit policy page url doesn't work", async () => { + await act(async () => { + testBed = await setup([getEncodedPolicyEditPath(PERCENT_SIGN_25_SEQUENCE)]); + }); + + const { component } = testBed; + component.update(); + + // known issue https://github.com/elastic/kibana/issues/82440 + expect(testBed.find('policyTitle').text()).not.toBe( + `Edit index lifecycle policy ${PERCENT_SIGN_25_SEQUENCE}` + ); + }); + + // using double encoding to counteract react-router's v5 internal decodeURI call + // when those links are open in a new tab, address bar contains double encoded url + test('loading edit policy page url with double encoding works', async () => { + await act(async () => { + testBed = await setup([getDoubleEncodedPolicyEditPath(PERCENT_SIGN_25_SEQUENCE)]); + }); + + const { component } = testBed; + component.update(); + + expect(testBed.find('policyTitle').text()).toBe( + `Edit index lifecycle policy ${PERCENT_SIGN_25_SEQUENCE}` + ); + }); + }); +}); diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/constants.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/constants.ts index 3d430cf31621e..00c7d705c1f44 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/constants.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/constants.ts @@ -121,6 +121,26 @@ export const DELETE_PHASE_POLICY: PolicyFromES = { name: POLICY_NAME, }; +export const getDefaultHotPhasePolicy = (policyName: string): PolicyFromES => ({ + version: 1, + modified_date: Date.now().toString(), + policy: { + name: policyName, + phases: { + hot: { + min_age: '0ms', + actions: { + rollover: { + max_age: '30d', + max_size: '50gb', + }, + }, + }, + }, + }, + name: policyName, +}); + export const POLICY_WITH_NODE_ATTR_AND_OFF_ALLOCATION: PolicyFromES = { version: 1, modified_date: Date.now().toString(), diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.test.ts index 4ee67d1ed8a19..c91ee3e2a1c06 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.test.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.test.ts @@ -19,6 +19,7 @@ import { POLICY_WITH_INCLUDE_EXCLUDE, POLICY_WITH_NODE_ATTR_AND_OFF_ALLOCATION, POLICY_WITH_NODE_ROLE_ALLOCATION, + getDefaultHotPhasePolicy, } from './constants'; window.scrollTo = jest.fn(); @@ -33,7 +34,7 @@ describe('', () => { describe('hot phase', () => { describe('serialization', () => { beforeEach(async () => { - httpRequestsMockHelpers.setLoadPolicies([DEFAULT_POLICY]); + httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy('my_policy')]); httpRequestsMockHelpers.setLoadSnapshotPolicies([]); await act(async () => { diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/index.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/index.ts index e8ebc2963d16a..aff9151da61f9 100644 --- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/index.ts +++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/helpers/index.ts @@ -17,5 +17,8 @@ export type TestSubjects = | 'hot-selectedMaxDocuments' | 'hot-selectedMaxAge' | 'hot-selectedMaxAgeUnits' + | 'policyTablePolicyNameLink' + | 'policyTitle' + | 'createPolicyButton' | 'freezeSwitch' | string; diff --git a/x-pack/plugins/index_lifecycle_management/public/application/app.tsx b/x-pack/plugins/index_lifecycle_management/public/application/app.tsx index 856981fe5c4f9..20185b02064bc 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/app.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/app.tsx @@ -15,7 +15,7 @@ import { PolicyTable } from './sections/policy_table'; import { trackUiMetric } from './services/ui_metric'; import { ROUTES } from './services/navigation'; -export const App = ({ +export const AppWithRouter = ({ history, navigateToApp, getUrlForApp, @@ -23,23 +23,33 @@ export const App = ({ history: ScopedHistory; navigateToApp: ApplicationStart['navigateToApp']; getUrlForApp: ApplicationStart['getUrlForApp']; +}) => ( + + + +); + +export const App = ({ + navigateToApp, + getUrlForApp, +}: { + navigateToApp: ApplicationStart['navigateToApp']; + getUrlForApp: ApplicationStart['getUrlForApp']; }) => { useEffect(() => trackUiMetric(METRIC_TYPE.LOADED, UIM_APP_LOAD), []); return ( - - - - } - /> - } - /> - - + + + } + /> + } + /> + ); }; diff --git a/x-pack/plugins/index_lifecycle_management/public/application/index.tsx b/x-pack/plugins/index_lifecycle_management/public/application/index.tsx index 3d4cc7dbbd1d4..bb1a4810ba2d2 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/index.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/index.tsx @@ -12,7 +12,7 @@ import { CloudSetup } from '../../../cloud/public'; import { KibanaContextProvider } from '../shared_imports'; -import { App } from './app'; +import { AppWithRouter } from './app'; import { BreadcrumbService } from './services/breadcrumbs'; @@ -28,7 +28,11 @@ export const renderApp = ( render( - + , element diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/edit_policy.container.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/edit_policy.container.tsx index ebef80871b83d..4c0cc2c8957e1 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/edit_policy.container.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/edit_policy.container.tsx @@ -9,7 +9,7 @@ import { RouteComponentProps } from 'react-router-dom'; import { EuiButton, EuiEmptyPrompt, EuiLoadingSpinner } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import { useKibana } from '../../../shared_imports'; +import { useKibana, attemptToURIDecode } from '../../../shared_imports'; import { useLoadPoliciesList } from '../../services/api'; import { getPolicyByName } from '../../lib/policies'; @@ -90,13 +90,13 @@ export const EditPolicy: React.FunctionComponent = ({ history }) => { verticalPosition="center" horizontalPosition="center" > - +

{isNewPolicy ? i18n.translate('xpack.indexLifecycleMgmt.editPolicy.createPolicyMessage', { diff --git a/x-pack/plugins/index_lifecycle_management/public/shared_imports.ts b/x-pack/plugins/index_lifecycle_management/public/shared_imports.ts index a127574d5bad0..a5844af0bf6dd 100644 --- a/x-pack/plugins/index_lifecycle_management/public/shared_imports.ts +++ b/x-pack/plugins/index_lifecycle_management/public/shared_imports.ts @@ -32,6 +32,8 @@ export { TextField, } from '../../../../src/plugins/es_ui_shared/static/forms/components'; +export { attemptToURIDecode } from '../../../../src/plugins/es_ui_shared/public'; + export { KibanaContextProvider } from '../../../../src/plugins/kibana_react/public'; export const useKibana = () => _useKibana(); diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_details/component_template_details.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_details/component_template_details.tsx index 6d9aa58d6c86b..2fb16874cf943 100644 --- a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_details/component_template_details.tsx +++ b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_details/component_template_details.tsx @@ -52,7 +52,7 @@ export const ComponentTemplateDetailsFlyoutContent: React.FunctionComponent { const { api } = useComponentTemplatesContext(); - const decodedComponentTemplateName = attemptToURIDecode(componentTemplateName); + const decodedComponentTemplateName = attemptToURIDecode(componentTemplateName)!; const { data: componentTemplateDetails, isLoading, error } = api.useLoadComponentTemplate( decodedComponentTemplateName diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_list/component_template_list.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_list/component_template_list.tsx index 00ea3ebf794ee..e8424ae46c6d2 100644 --- a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_list/component_template_list.tsx +++ b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_list/component_template_list.tsx @@ -84,7 +84,7 @@ export const ComponentTemplateList: React.FunctionComponent = ({ }), icon: 'pencil', handleActionClick: () => - goToEditComponentTemplate(attemptToURIDecode(componentTemplateName)), + goToEditComponentTemplate(attemptToURIDecode(componentTemplateName)!), }, { name: i18n.translate('xpack.idxMgmt.componentTemplateDetails.cloneActionLabel', { @@ -92,7 +92,7 @@ export const ComponentTemplateList: React.FunctionComponent = ({ }), icon: 'copy', handleActionClick: () => - goToCloneComponentTemplate(attemptToURIDecode(componentTemplateName)), + goToCloneComponentTemplate(attemptToURIDecode(componentTemplateName)!), }, { name: i18n.translate('xpack.idxMgmt.componentTemplateDetails.deleteButtonLabel', { @@ -103,7 +103,7 @@ export const ComponentTemplateList: React.FunctionComponent = ({ details._kbnMeta.usedBy.length > 0, closePopoverOnClick: true, handleActionClick: () => { - setComponentTemplatesToDelete([attemptToURIDecode(componentTemplateName)]); + setComponentTemplatesToDelete([attemptToURIDecode(componentTemplateName)!]); }, }, ]; diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_clone/component_template_clone.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_clone/component_template_clone.tsx index 6c03fcf5d9972..e6b403543f4b0 100644 --- a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_clone/component_template_clone.tsx +++ b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_clone/component_template_clone.tsx @@ -19,7 +19,7 @@ export interface Params { export const ComponentTemplateClone: FunctionComponent> = (props) => { const { sourceComponentTemplateName } = props.match.params; - const decodedSourceName = attemptToURIDecode(sourceComponentTemplateName); + const decodedSourceName = attemptToURIDecode(sourceComponentTemplateName)!; const { toasts, api } = useComponentTemplatesContext(); diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_edit/component_template_edit.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_edit/component_template_edit.tsx index 934f86f7d7590..500c84a97d222 100644 --- a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_edit/component_template_edit.tsx +++ b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_edit/component_template_edit.tsx @@ -31,7 +31,7 @@ export const ComponentTemplateEdit: React.FunctionComponent(false); const [saveError, setSaveError] = useState(null); - const decodedName = attemptToURIDecode(name); + const decodedName = attemptToURIDecode(name)!; const { error, data: componentTemplate, isLoading } = api.useLoadComponentTemplate(decodedName); diff --git a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_list.tsx b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_list.tsx index ba79319b566bf..20b93d9d71d04 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_list.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_list.tsx @@ -231,7 +231,7 @@ export const DataStreamList: React.FunctionComponent { history.push(`/${Section.DataStreams}`); diff --git a/x-pack/plugins/index_management/public/application/sections/home/template_list/template_list.tsx b/x-pack/plugins/index_management/public/application/sections/home/template_list/template_list.tsx index f3e82223c30e6..3689a875e28b2 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/template_list/template_list.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/template_list/template_list.tsx @@ -101,7 +101,7 @@ export const TemplateList: React.FunctionComponent { - const decodedTemplateName = attemptToURIDecode(name); + const decodedTemplateName = attemptToURIDecode(name)!; const isLegacy = getIsLegacyFromQueryParams(location); const [isSaving, setIsSaving] = useState(false); diff --git a/x-pack/plugins/index_management/public/application/sections/template_edit/template_edit.tsx b/x-pack/plugins/index_management/public/application/sections/template_edit/template_edit.tsx index 3e62f7f880f74..e3cb40b3a36e1 100644 --- a/x-pack/plugins/index_management/public/application/sections/template_edit/template_edit.tsx +++ b/x-pack/plugins/index_management/public/application/sections/template_edit/template_edit.tsx @@ -27,7 +27,7 @@ export const TemplateEdit: React.FunctionComponent { - const decodedTemplateName = attemptToURIDecode(name); + const decodedTemplateName = attemptToURIDecode(name)!; const isLegacy = getIsLegacyFromQueryParams(location); const [isSaving, setIsSaving] = useState(false); diff --git a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_clone/pipelines_clone.tsx b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_clone/pipelines_clone.tsx index 9465117b6b589..df60907973156 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_clone/pipelines_clone.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_clone/pipelines_clone.tsx @@ -25,7 +25,7 @@ export const PipelinesClone: FunctionComponent> const { sourceName } = props.match.params; const { services } = useKibana(); - const decodedSourceName = attemptToURIDecode(sourceName); + const decodedSourceName = attemptToURIDecode(sourceName)!; const { error, data: pipeline, isLoading, isInitialRequest } = services.api.useLoadPipeline( decodedSourceName ); diff --git a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_edit/pipelines_edit.tsx b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_edit/pipelines_edit.tsx index 7e2e85ab23fb3..2b53fdb6a6375 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_edit/pipelines_edit.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_edit/pipelines_edit.tsx @@ -38,7 +38,7 @@ export const PipelinesEdit: React.FunctionComponent(false); const [saveError, setSaveError] = useState(null); - const decodedPipelineName = attemptToURIDecode(name); + const decodedPipelineName = attemptToURIDecode(name)!; const { error, data: pipeline, isLoading } = services.api.useLoadPipeline(decodedPipelineName); From 0503f873f8de1790e82f7adfc3bdd758c91f97bd Mon Sep 17 00:00:00 2001 From: Denis Maximov Date: Tue, 10 Nov 2020 12:25:28 +0200 Subject: [PATCH 08/80] [Lens] Do not reset formatting when switching between custom ranges and auto histogram (#82694) --- .../definitions/ranges/ranges.test.tsx | 30 +++++++++++++++++++ .../operations/definitions/ranges/ranges.tsx | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx index c8a8ffa7b128f..d43a905434c02 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx @@ -744,6 +744,36 @@ describe('ranges', () => { /^Bytes format:/ ); }); + + it('should not reset formatters when switching between custom ranges and auto histogram', () => { + const setStateSpy = jest.fn(); + // now set a format on the range operation + (state.layers.first.columns.col1 as RangeIndexPatternColumn).params.format = { + id: 'custom', + params: { decimals: 3 }, + }; + + const instance = mount( + + ); + + // This series of act closures are made to make it work properly the update flush + act(() => { + instance.find(EuiLink).first().prop('onClick')!({} as ReactMouseEvent); + }); + + expect(setStateSpy.mock.calls[1][0].layers.first.columns.col1.params.format).toEqual({ + id: 'custom', + params: { decimals: 3 }, + }); + }); }); }); }); diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx index 1050eef45a71c..46d9e4e6c22de 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx @@ -225,7 +225,7 @@ export const rangeOperation: OperationDefinition Date: Tue, 10 Nov 2020 13:24:07 +0200 Subject: [PATCH 09/80] [Visualizations] Make the icon buttons labels more descriptive (#82585) * [Visualizations] Make the icon buttons labels more descriptive on the Vis Editor * Fix jest test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../__snapshots__/agg.test.tsx.snap | 4 ++-- .../public/components/agg.tsx | 19 +++++++++++++------ .../public/components/agg_add.tsx | 14 +++++++++----- .../translations/translations/ja-JP.json | 5 ----- .../translations/translations/zh-CN.json | 5 ----- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/plugins/vis_default_editor/public/components/__snapshots__/agg.test.tsx.snap b/src/plugins/vis_default_editor/public/components/__snapshots__/agg.test.tsx.snap index 2a521bc01219c..26173cddb3716 100644 --- a/src/plugins/vis_default_editor/public/components/__snapshots__/agg.test.tsx.snap +++ b/src/plugins/vis_default_editor/public/components/__snapshots__/agg.test.tsx.snap @@ -17,12 +17,12 @@ exports[`DefaultEditorAgg component should init with the default set of props 1` extraAction={
{ const actionIcons = []; + const aggTitle = agg.type?.title?.toLowerCase(); if (showError) { actionIcons.push({ @@ -170,7 +172,8 @@ function DefaultEditorAgg({ color: 'danger', type: 'alert', tooltip: i18n.translate('visDefaultEditor.agg.errorsAriaLabel', { - defaultMessage: 'Aggregation has errors', + defaultMessage: '{schemaTitle} {aggTitle} aggregation has errors', + values: { aggTitle, schemaTitle }, }), dataTestSubj: 'hasErrorsAggregationIcon', }); @@ -184,7 +187,8 @@ function DefaultEditorAgg({ type: 'eye', onClick: () => onToggleEnableAgg(agg.id, false), tooltip: i18n.translate('visDefaultEditor.agg.disableAggButtonTooltip', { - defaultMessage: 'Disable aggregation', + defaultMessage: 'Disable {schemaTitle} {aggTitle} aggregation', + values: { aggTitle, schemaTitle }, }), dataTestSubj: 'toggleDisableAggregationBtn disable', }); @@ -196,7 +200,8 @@ function DefaultEditorAgg({ type: 'eyeClosed', onClick: () => onToggleEnableAgg(agg.id, true), tooltip: i18n.translate('visDefaultEditor.agg.enableAggButtonTooltip', { - defaultMessage: 'Enable aggregation', + defaultMessage: 'Enable {schemaTitle} {aggTitle} aggregation', + values: { aggTitle, schemaTitle }, }), dataTestSubj: 'toggleDisableAggregationBtn enable', }); @@ -206,7 +211,8 @@ function DefaultEditorAgg({ id: 'dragHandle', type: 'grab', tooltip: i18n.translate('visDefaultEditor.agg.modifyPriorityButtonTooltip', { - defaultMessage: 'Modify priority by dragging', + defaultMessage: 'Modify priority of {schemaTitle} {aggTitle} by dragging', + values: { aggTitle, schemaTitle }, }), dataTestSubj: 'dragHandleBtn', }); @@ -218,7 +224,8 @@ function DefaultEditorAgg({ type: 'cross', onClick: () => removeAgg(agg.id), tooltip: i18n.translate('visDefaultEditor.agg.removeDimensionButtonTooltip', { - defaultMessage: 'Remove dimension', + defaultMessage: 'Remove {schemaTitle} {aggTitle} aggregation', + values: { aggTitle, schemaTitle }, }), dataTestSubj: 'removeDimensionBtn', }); @@ -257,7 +264,7 @@ function DefaultEditorAgg({
); }; - const schemaTitle = getSchemaByName(schemas, agg.schema).title; + const buttonContent = ( <> {schemaTitle || agg.schema} {showDescription && {aggDescription}} diff --git a/src/plugins/vis_default_editor/public/components/agg_add.tsx b/src/plugins/vis_default_editor/public/components/agg_add.tsx index 46d5af8cec680..e78f2fcc4453c 100644 --- a/src/plugins/vis_default_editor/public/components/agg_add.tsx +++ b/src/plugins/vis_default_editor/public/components/agg_add.tsx @@ -56,22 +56,26 @@ function DefaultEditorAggAdd({ addSchema(schema); }; + const groupNameLabel = + groupName === AggGroupNames.Buckets + ? i18n.translate('visDefaultEditor.aggAdd.bucketLabel', { defaultMessage: 'bucket' }) + : i18n.translate('visDefaultEditor.aggAdd.metricLabel', { defaultMessage: 'metric' }); + const addButton = ( setIsPopoverOpen(!isPopoverOpen)} + aria-label={i18n.translate('visDefaultEditor.aggAdd.addGroupButtonLabel', { + defaultMessage: 'Add {groupNameLabel}', + values: { groupNameLabel }, + })} > ); - const groupNameLabel = - groupName === AggGroupNames.Buckets - ? i18n.translate('visDefaultEditor.aggAdd.bucketLabel', { defaultMessage: 'bucket' }) - : i18n.translate('visDefaultEditor.aggAdd.metricLabel', { defaultMessage: 'metric' }); - const isSchemaDisabled = (schema: Schema): boolean => { const count = group.filter((agg) => agg.schema === schema.name).length; return count >= schema.max; diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index d8e136567564e..d9a113b69b473 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -3542,11 +3542,6 @@ "uiActions.triggers.valueClickTitle": "シングルクリック", "usageCollection.stats.notReadyMessage": "まだ統計が準備できていません。しばらくたってから再試行してください。", "visDefaultEditor.advancedToggle.advancedLinkLabel": "高度な設定", - "visDefaultEditor.agg.disableAggButtonTooltip": "集約を無効にする", - "visDefaultEditor.agg.enableAggButtonTooltip": "集約を有効にする", - "visDefaultEditor.agg.errorsAriaLabel": "集約にエラーがあります", - "visDefaultEditor.agg.modifyPriorityButtonTooltip": "ドラッグして優先順位を変更します", - "visDefaultEditor.agg.removeDimensionButtonTooltip": "次元を削除", "visDefaultEditor.agg.toggleEditorButtonAriaLabel": "{schema} エディターを切り替える", "visDefaultEditor.aggAdd.addButtonLabel": "追加", "visDefaultEditor.aggAdd.addGroupButtonLabel": "{groupNameLabel} を追加", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 84cc3510ce487..4a393f8a7a223 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -3543,11 +3543,6 @@ "uiActions.triggers.valueClickTitle": "单击", "usageCollection.stats.notReadyMessage": "统计信息尚未准备就绪。请稍后重试。", "visDefaultEditor.advancedToggle.advancedLinkLabel": "高级", - "visDefaultEditor.agg.disableAggButtonTooltip": "禁用聚合", - "visDefaultEditor.agg.enableAggButtonTooltip": "启用聚合", - "visDefaultEditor.agg.errorsAriaLabel": "聚合有错误", - "visDefaultEditor.agg.modifyPriorityButtonTooltip": "通过拖动来修改优先级", - "visDefaultEditor.agg.removeDimensionButtonTooltip": "移除维度", "visDefaultEditor.agg.toggleEditorButtonAriaLabel": "切换 {schema} 编辑器", "visDefaultEditor.aggAdd.addButtonLabel": "添加", "visDefaultEditor.aggAdd.addGroupButtonLabel": "添加{groupNameLabel}", From 471c281fa2572860380d06b26420d694445d1e75 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Tue, 10 Nov 2020 13:34:05 +0200 Subject: [PATCH 10/80] [Visualizations] Remove kui usage (#82810) * [Visualize] Remove kui usage * Use EuiPromptButton istead of EuiCallout * Add a link to advanced settings for visualizations docs * Changes requested on code review Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../public/doc_links/doc_links_service.ts | 1 + .../public/embeddable/_index.scss | 1 - .../embeddable/_visualize_lab_disabled.scss | 13 ----- .../embeddable/disabled_lab_visualization.tsx | 51 ++++++++++++------- 4 files changed, 33 insertions(+), 33 deletions(-) delete mode 100644 src/plugins/visualizations/public/embeddable/_visualize_lab_disabled.scss diff --git a/src/core/public/doc_links/doc_links_service.ts b/src/core/public/doc_links/doc_links_service.ts index 48187fe465392..0815df4b9b0c7 100644 --- a/src/core/public/doc_links/doc_links_service.ts +++ b/src/core/public/doc_links/doc_links_service.ts @@ -131,6 +131,7 @@ export class DocLinksService { management: { kibanaSearchSettings: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/advanced-options.html#kibana-search-settings`, dashboardSettings: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/advanced-options.html#kibana-dashboard-settings`, + visualizationSettings: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/advanced-options.html#kibana-visualization-settings`, }, visualize: { guide: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/visualize.html`, diff --git a/src/plugins/visualizations/public/embeddable/_index.scss b/src/plugins/visualizations/public/embeddable/_index.scss index c1e3809657bfa..9703e90159f48 100644 --- a/src/plugins/visualizations/public/embeddable/_index.scss +++ b/src/plugins/visualizations/public/embeddable/_index.scss @@ -1,2 +1 @@ -@import 'visualize_lab_disabled'; @import 'embeddables'; diff --git a/src/plugins/visualizations/public/embeddable/_visualize_lab_disabled.scss b/src/plugins/visualizations/public/embeddable/_visualize_lab_disabled.scss deleted file mode 100644 index 914480ff8c777..0000000000000 --- a/src/plugins/visualizations/public/embeddable/_visualize_lab_disabled.scss +++ /dev/null @@ -1,13 +0,0 @@ -.visDisabledLabVisualization { - width: 100%; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - text-align: center; -} - -.visDisabledLabVisualization__icon { - font-size: $euiFontSizeXL; -} - diff --git a/src/plugins/visualizations/public/embeddable/disabled_lab_visualization.tsx b/src/plugins/visualizations/public/embeddable/disabled_lab_visualization.tsx index 3d2af2c591a3c..ea7760f31d54c 100644 --- a/src/plugins/visualizations/public/embeddable/disabled_lab_visualization.tsx +++ b/src/plugins/visualizations/public/embeddable/disabled_lab_visualization.tsx @@ -17,29 +17,42 @@ * under the License. */ -import { FormattedMessage } from '@kbn/i18n/react'; +import { FormattedMessage, I18nProvider } from '@kbn/i18n/react'; +import { EuiEmptyPrompt, EuiLink } from '@elastic/eui'; import React from 'react'; +import { getDocLinks } from '../services'; export function DisabledLabVisualization({ title }: { title: string }) { + const advancedSettingsLink = getDocLinks().links.management.visualizationSettings; return ( -
-

+ } + iconType="beaker" + body={ + + } + actions={ + + + + } /> -
- {title} }} - /> -
-
- -
- + ); } From a7a83fd4215803d8b835bd4a97a8db4559ef3703 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Tue, 10 Nov 2020 13:42:12 +0200 Subject: [PATCH 11/80] [TSVB] Disable using top_hits in pipeline aggregations (#82278) * [TSVB] Disable using top_hits in bucket script aggregations * remove console message * Correct schema for metrics size * Chanhe hardcoded agg with the exported for the METRIC_TYPES var * Exclude top_hit agg from all Sibling Pipeline Aggregations and all Parent Pipeline Aggregations Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- src/plugins/vis_type_timeseries/common/vis_schema.ts | 2 +- .../public/application/components/aggs/calculation.js | 2 ++ .../public/application/components/aggs/cumulative_sum.js | 2 ++ .../public/application/components/aggs/derivative.js | 2 ++ .../public/application/components/aggs/moving_average.js | 2 ++ .../public/application/components/aggs/positive_only.js | 2 ++ .../public/application/components/aggs/serial_diff.js | 2 ++ .../public/application/components/aggs/std_sibling.js | 5 ++++- .../public/application/components/aggs/vars.js | 1 + 9 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/plugins/vis_type_timeseries/common/vis_schema.ts b/src/plugins/vis_type_timeseries/common/vis_schema.ts index 27f09fb574b0f..9ec5ae1424ae3 100644 --- a/src/plugins/vis_type_timeseries/common/vis_schema.ts +++ b/src/plugins/vis_type_timeseries/common/vis_schema.ts @@ -120,7 +120,7 @@ export const metricsItems = schema.object({ type: stringRequired, value: stringOptionalNullable, values: schema.maybe(schema.nullable(schema.arrayOf(schema.nullable(schema.string())))), - size: stringOptionalNullable, + size: stringOrNumberOptionalNullable, agg_with: stringOptionalNullable, order: stringOptionalNullable, order_by: stringOptionalNullable, diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/calculation.js b/src/plugins/vis_type_timeseries/public/application/components/aggs/calculation.js index bb3d39797656f..5bf4fb55ee5e5 100644 --- a/src/plugins/vis_type_timeseries/public/application/components/aggs/calculation.js +++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/calculation.js @@ -26,6 +26,7 @@ import { createChangeHandler } from '../lib/create_change_handler'; import { createSelectHandler } from '../lib/create_select_handler'; import { createTextHandler } from '../lib/create_text_handler'; import { CalculationVars, newVariable } from './vars'; +import { METRIC_TYPES } from '../../../../common/metric_types'; import { FormattedMessage } from '@kbn/i18n/react'; import { @@ -99,6 +100,7 @@ export function CalculationAgg(props) { onChange={handleChange} name="variables" model={model} + exclude={[METRIC_TYPES.TOP_HIT]} /> diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/cumulative_sum.js b/src/plugins/vis_type_timeseries/public/application/components/aggs/cumulative_sum.js index 11b3e303e7e00..0b879adbd37ae 100644 --- a/src/plugins/vis_type_timeseries/public/application/components/aggs/cumulative_sum.js +++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/cumulative_sum.js @@ -24,6 +24,7 @@ import { AggSelect } from './agg_select'; import { MetricSelect } from './metric_select'; import { createChangeHandler } from '../lib/create_change_handler'; import { createSelectHandler } from '../lib/create_select_handler'; +import { METRIC_TYPES } from '../../../../common/metric_types'; import { FormattedMessage } from '@kbn/i18n/react'; import { htmlIdGenerator, @@ -80,6 +81,7 @@ export function CumulativeSumAgg(props) { metrics={siblings} metric={model} value={model.field} + exclude={[METRIC_TYPES.TOP_HIT]} /> diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/derivative.js b/src/plugins/vis_type_timeseries/public/application/components/aggs/derivative.js index faf1a59adc4aa..fa1289dc74c72 100644 --- a/src/plugins/vis_type_timeseries/public/application/components/aggs/derivative.js +++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/derivative.js @@ -25,6 +25,7 @@ import { AggRow } from './agg_row'; import { createChangeHandler } from '../lib/create_change_handler'; import { createSelectHandler } from '../lib/create_select_handler'; import { createTextHandler } from '../lib/create_text_handler'; +import { METRIC_TYPES } from '../../../../common/metric_types'; import { htmlIdGenerator, EuiFlexGroup, @@ -91,6 +92,7 @@ export const DerivativeAgg = (props) => { metrics={siblings} metric={model} value={model.field} + exclude={[METRIC_TYPES.TOP_HIT]} fullWidth /> diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/moving_average.js b/src/plugins/vis_type_timeseries/public/application/components/aggs/moving_average.js index 316e0f9af43bd..fb945d2606bc8 100644 --- a/src/plugins/vis_type_timeseries/public/application/components/aggs/moving_average.js +++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/moving_average.js @@ -25,6 +25,7 @@ import { MetricSelect } from './metric_select'; import { createChangeHandler } from '../lib/create_change_handler'; import { createSelectHandler } from '../lib/create_select_handler'; import { createNumberHandler } from '../lib/create_number_handler'; +import { METRIC_TYPES } from '../../../../common/metric_types'; import { htmlIdGenerator, EuiFlexGroup, @@ -153,6 +154,7 @@ export const MovingAverageAgg = (props) => { metrics={siblings} metric={model} value={model.field} + exclude={[METRIC_TYPES.TOP_HIT]} /> diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/positive_only.js b/src/plugins/vis_type_timeseries/public/application/components/aggs/positive_only.js index 1999862f7aa0e..6ca5fa8e7447f 100644 --- a/src/plugins/vis_type_timeseries/public/application/components/aggs/positive_only.js +++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/positive_only.js @@ -24,6 +24,7 @@ import { MetricSelect } from './metric_select'; import { AggRow } from './agg_row'; import { createChangeHandler } from '../lib/create_change_handler'; import { createSelectHandler } from '../lib/create_select_handler'; +import { METRIC_TYPES } from '../../../../common/metric_types'; import { htmlIdGenerator, EuiFlexGroup, @@ -85,6 +86,7 @@ export const PositiveOnlyAgg = (props) => { metrics={siblings} metric={model} value={model.field} + exclude={[METRIC_TYPES.TOP_HIT]} /> diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/serial_diff.js b/src/plugins/vis_type_timeseries/public/application/components/aggs/serial_diff.js index 10b3d551bb89f..e3a0c74273539 100644 --- a/src/plugins/vis_type_timeseries/public/application/components/aggs/serial_diff.js +++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/serial_diff.js @@ -25,6 +25,7 @@ import { AggRow } from './agg_row'; import { createChangeHandler } from '../lib/create_change_handler'; import { createSelectHandler } from '../lib/create_select_handler'; import { createNumberHandler } from '../lib/create_number_handler'; +import { METRIC_TYPES } from '../../../../common/metric_types'; import { htmlIdGenerator, EuiFlexGroup, @@ -87,6 +88,7 @@ export const SerialDiffAgg = (props) => { metrics={siblings} metric={model} value={model.field} + exclude={[METRIC_TYPES.TOP_HIT]} /> diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/std_sibling.js b/src/plugins/vis_type_timeseries/public/application/components/aggs/std_sibling.js index 30e5c57ac90ba..bed5e9caa9f87 100644 --- a/src/plugins/vis_type_timeseries/public/application/components/aggs/std_sibling.js +++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/std_sibling.js @@ -25,6 +25,8 @@ import { AggSelect } from './agg_select'; import { createChangeHandler } from '../lib/create_change_handler'; import { createSelectHandler } from '../lib/create_select_handler'; import { createTextHandler } from '../lib/create_text_handler'; +import { METRIC_TYPES } from '../../../../common/metric_types'; + import { htmlIdGenerator, EuiFlexGroup, @@ -154,7 +156,7 @@ const StandardSiblingAggUi = (props) => { > From 446cffeccf9a19baee96aaf4b146547a3f7f721a Mon Sep 17 00:00:00 2001 From: Bill McConaghy Date: Tue, 10 Nov 2020 07:21:52 -0500 Subject: [PATCH 12/80] renaming built-in alerts to Stack Alerts (#82873) * renaming built-in alerts to Stack Alerts * responding to PR feedback and adding glossary definition for stack alerts * Update docs/glossary.asciidoc Co-authored-by: gchaps <33642766+gchaps@users.noreply.github.com> Co-authored-by: gchaps <33642766+gchaps@users.noreply.github.com> --- docs/glossary.asciidoc | 5 +++++ docs/user/alerting/alert-types.asciidoc | 8 +++++--- docs/user/alerting/alerting-getting-started.asciidoc | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/glossary.asciidoc b/docs/glossary.asciidoc index be24402170bbe..ff03a60173961 100644 --- a/docs/glossary.asciidoc +++ b/docs/glossary.asciidoc @@ -330,6 +330,11 @@ See {kibana-ref}/xpack-spaces.html[Spaces]. // end::space-def[] +[[glossary-stack-alerts]] stack alerts :: +// tag::stack-alert-def[] +The general purpose alert types {kib} provides out of the box. Index threshold and geo alerts are currently the two stack alert types. +// end::stack-alert-def[] + [float] [[t_glos]] diff --git a/docs/user/alerting/alert-types.asciidoc b/docs/user/alerting/alert-types.asciidoc index f71e43c5defc7..7de5ff56228cc 100644 --- a/docs/user/alerting/alert-types.asciidoc +++ b/docs/user/alerting/alert-types.asciidoc @@ -2,11 +2,13 @@ [[alert-types]] == Alert types -{kib} supplies alerts types in two ways: some are built into {kib}, while domain-specific alert types are registered by {kib} apps such as <>, <>, and <>. +{kib} supplies alert types in two ways: some are built into {kib} (these are known as stack alerts), while domain-specific alert types are registered by {kib} apps such as <>, <>, and <>. -This section covers built-in alert types. For domain-specific alert types, refer to the documentation for that app. +This section covers stack alerts. For domain-specific alert types, refer to the documentation for that app. +Users will need `all` access to the *Stack Alerts* feature to be able to create and edit any of the alerts listed below. +See <> for more information on configuring roles that provide access to this feature. -Currently {kib} provides one built-in alert type: the <> type. +Currently {kib} provides one stack alert: the <> type. [float] [[alert-type-index-threshold]] diff --git a/docs/user/alerting/alerting-getting-started.asciidoc b/docs/user/alerting/alerting-getting-started.asciidoc index 2b22b49375676..53aef4aaa062e 100644 --- a/docs/user/alerting/alerting-getting-started.asciidoc +++ b/docs/user/alerting/alerting-getting-started.asciidoc @@ -6,7 +6,7 @@ beta[] -- -Alerting allows you to detect complex conditions within different {kib} apps and trigger actions when those conditions are met. Alerting is integrated with <>, <>, <>, <>, can be centrally managed from the <> UI, and provides a set of built-in <> and <> for you to use. +Alerting allows you to detect complex conditions within different {kib} apps and trigger actions when those conditions are met. Alerting is integrated with <>, <>, <>, <>, can be centrally managed from the <> UI, and provides a set of built-in <> and <> (known as stack alerts) for you to use. image::images/alerting-overview.png[Alerts and actions UI] From 451e387f40d211d1eb36589c7d8de95d4e6e94b6 Mon Sep 17 00:00:00 2001 From: Larry Gregory Date: Tue, 10 Nov 2020 07:37:44 -0500 Subject: [PATCH 13/80] Fix SO query for searching across spaces (#83025) --- .../service/lib/search_dsl/query_params.test.ts | 5 ++--- .../service/lib/search_dsl/query_params.ts | 14 ++++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/core/server/saved_objects/service/lib/search_dsl/query_params.test.ts b/src/core/server/saved_objects/service/lib/search_dsl/query_params.test.ts index c35ec809fcf8d..e78b944183df9 100644 --- a/src/core/server/saved_objects/service/lib/search_dsl/query_params.test.ts +++ b/src/core/server/saved_objects/service/lib/search_dsl/query_params.test.ts @@ -103,12 +103,11 @@ describe('#getQueryParams', () => { if (registry.isMultiNamespace(type)) { const array = [...(namespaces ?? [DEFAULT_NAMESPACE_STRING]), ALL_NAMESPACES_STRING]; - const namespacesClause = { terms: { namespaces: array } }; return { bool: { must: namespaces?.includes(ALL_NAMESPACES_STRING) - ? expect.not.arrayContaining([namespacesClause]) - : expect.arrayContaining([namespacesClause]), + ? [{ term: { type } }] + : [{ term: { type } }, { terms: { namespaces: array } }], must_not: [{ exists: { field: 'namespace' } }], }, }; diff --git a/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts b/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts index 2ecba42e408e7..cb58db171681a 100644 --- a/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts +++ b/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts @@ -78,13 +78,19 @@ function getClauseForType( const searchAcrossAllNamespaces = namespaces.includes(ALL_NAMESPACES_STRING); if (registry.isMultiNamespace(type)) { - const namespacesFilterClause = searchAcrossAllNamespaces - ? {} - : { terms: { namespaces: [...namespaces, ALL_NAMESPACES_STRING] } }; + const typeFilterClause = { term: { type } }; + + const namespacesFilterClause = { + terms: { namespaces: [...namespaces, ALL_NAMESPACES_STRING] }, + }; + + const must = searchAcrossAllNamespaces + ? [typeFilterClause] + : [typeFilterClause, namespacesFilterClause]; return { bool: { - must: [{ term: { type } }, namespacesFilterClause], + must, must_not: [{ exists: { field: 'namespace' } }], }, }; From 6003cadce4abfa19dfec1d08b037d45ba11367d7 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 10 Nov 2020 12:43:39 +0000 Subject: [PATCH 14/80] skip flaky suite (#82804) --- .../security_and_spaces/tests/alerting/update.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts index 0ad2ca226ed5d..8836bc2e4db2f 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts @@ -31,7 +31,8 @@ export default function createUpdateTests({ getService }: FtrProviderContext) { .then((response: SupertestResponse) => response.body); } - describe('update', () => { + // FLAKY: https://github.com/elastic/kibana/issues/82804 + describe.skip('update', () => { const objectRemover = new ObjectRemover(supertest); after(() => objectRemover.removeAll()); From 0b99841310b804901827040aaf025468941710a3 Mon Sep 17 00:00:00 2001 From: Marco Liberati Date: Tue, 10 Nov 2020 14:31:04 +0100 Subject: [PATCH 15/80] [Lens] Performance refactoring for indexpattern fast lookup and Operation support matrix computation (#82829) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../datapanel.test.tsx | 254 +++++++------- .../indexpattern_datasource/datapanel.tsx | 5 +- .../bucket_nesting_editor.test.tsx | 22 +- .../dimension_panel/bucket_nesting_editor.tsx | 15 +- .../dimension_panel/dimension_editor.tsx | 45 ++- .../dimension_panel/dimension_panel.test.tsx | 74 ++-- .../dimension_panel/droppable.test.ts | 91 +++-- .../dimension_panel/droppable.ts | 6 +- .../dimension_panel/field_select.tsx | 25 +- .../dimension_panel/operation_support.ts | 38 +- .../indexpattern.test.ts | 205 +++++------ .../indexpattern_suggestions.test.tsx | 326 ++++++++++-------- .../indexpattern_suggestions.ts | 32 +- .../layerpanel.test.tsx | 232 +++++++------ .../indexpattern_datasource/loader.test.ts | 13 +- .../public/indexpattern_datasource/loader.ts | 2 + .../public/indexpattern_datasource/mocks.ts | 117 ++++--- .../operations/definitions/cardinality.tsx | 2 +- .../definitions/date_histogram.test.tsx | 79 ++++- .../operations/definitions/date_histogram.tsx | 19 +- .../operations/definitions/metrics.tsx | 2 +- .../definitions/ranges/ranges.test.tsx | 4 + .../operations/definitions/ranges/ranges.tsx | 6 +- .../operations/definitions/terms/index.tsx | 2 +- .../definitions/terms/terms.test.tsx | 2 +- .../operations/operations.test.ts | 50 +-- .../indexpattern_datasource/pure_helpers.ts | 8 +- .../state_helpers.test.ts | 101 +++--- .../public/indexpattern_datasource/types.ts | 1 + .../public/indexpattern_datasource/utils.ts | 10 +- 30 files changed, 996 insertions(+), 792 deletions(-) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx index c48bc3dc52404..d2ec1c81bbeec 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.test.tsx @@ -18,6 +18,131 @@ import { ChangeIndexPattern } from './change_indexpattern'; import { EuiProgress, EuiLoadingSpinner } from '@elastic/eui'; import { documentField } from './document_field'; import { chartPluginMock } from '../../../../../src/plugins/charts/public/mocks'; +import { getFieldByNameFactory } from './pure_helpers'; + +const fieldsOne = [ + { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + aggregatable: true, + searchable: true, + }, + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'memory', + displayName: 'amemory', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'unsupported', + displayName: 'unsupported', + type: 'geo', + aggregatable: true, + searchable: true, + }, + { + name: 'source', + displayName: 'source', + type: 'string', + aggregatable: true, + searchable: true, + }, + { + name: 'client', + displayName: 'client', + type: 'ip', + aggregatable: true, + searchable: true, + }, + documentField, +]; + +const fieldsTwo = [ + { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + aggregatable: true, + searchable: true, + aggregationRestrictions: { + date_histogram: { + agg: 'date_histogram', + fixed_interval: '1d', + delay: '7d', + time_zone: 'UTC', + }, + }, + }, + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + aggregationRestrictions: { + histogram: { + agg: 'histogram', + interval: 1000, + }, + max: { + agg: 'max', + }, + min: { + agg: 'min', + }, + sum: { + agg: 'sum', + }, + }, + }, + { + name: 'source', + displayName: 'source', + type: 'string', + aggregatable: true, + searchable: true, + aggregationRestrictions: { + terms: { + agg: 'terms', + }, + }, + }, + documentField, +]; + +const fieldsThree = [ + { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + aggregatable: true, + searchable: true, + }, + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'source', + displayName: 'source', + type: 'string', + aggregatable: true, + searchable: true, + }, + documentField, +]; const initialState: IndexPatternPrivateState = { indexPatternRefs: [], @@ -85,139 +210,24 @@ const initialState: IndexPatternPrivateState = { title: 'idx1', timeFieldName: 'timestamp', hasRestrictions: false, - fields: [ - { - name: 'timestamp', - displayName: 'timestampLabel', - type: 'date', - aggregatable: true, - searchable: true, - }, - { - name: 'bytes', - displayName: 'bytes', - type: 'number', - aggregatable: true, - searchable: true, - }, - { - name: 'memory', - displayName: 'amemory', - type: 'number', - aggregatable: true, - searchable: true, - }, - { - name: 'unsupported', - displayName: 'unsupported', - type: 'geo', - aggregatable: true, - searchable: true, - }, - { - name: 'source', - displayName: 'source', - type: 'string', - aggregatable: true, - searchable: true, - }, - { - name: 'client', - displayName: 'client', - type: 'ip', - aggregatable: true, - searchable: true, - }, - documentField, - ], + fields: fieldsOne, + getFieldByName: getFieldByNameFactory(fieldsOne), }, '2': { id: '2', title: 'idx2', timeFieldName: 'timestamp', hasRestrictions: true, - fields: [ - { - name: 'timestamp', - displayName: 'timestampLabel', - type: 'date', - aggregatable: true, - searchable: true, - aggregationRestrictions: { - date_histogram: { - agg: 'date_histogram', - fixed_interval: '1d', - delay: '7d', - time_zone: 'UTC', - }, - }, - }, - { - name: 'bytes', - displayName: 'bytes', - type: 'number', - aggregatable: true, - searchable: true, - aggregationRestrictions: { - histogram: { - agg: 'histogram', - interval: 1000, - }, - max: { - agg: 'max', - }, - min: { - agg: 'min', - }, - sum: { - agg: 'sum', - }, - }, - }, - { - name: 'source', - displayName: 'source', - type: 'string', - aggregatable: true, - searchable: true, - aggregationRestrictions: { - terms: { - agg: 'terms', - }, - }, - }, - documentField, - ], + fields: fieldsTwo, + getFieldByName: getFieldByNameFactory(fieldsTwo), }, '3': { id: '3', title: 'idx3', timeFieldName: 'timestamp', hasRestrictions: false, - fields: [ - { - name: 'timestamp', - displayName: 'timestampLabel', - type: 'date', - aggregatable: true, - searchable: true, - }, - { - name: 'bytes', - displayName: 'bytes', - type: 'number', - aggregatable: true, - searchable: true, - }, - { - name: 'source', - displayName: 'source', - type: 'string', - aggregatable: true, - searchable: true, - }, - documentField, - ], + fields: fieldsThree, + getFieldByName: getFieldByNameFactory(fieldsThree), }, }, isFirstExistenceFetch: false, @@ -330,6 +340,7 @@ describe('IndexPattern Data Panel', () => { title: 'aaa', timeFieldName: 'atime', fields: [], + getFieldByName: getFieldByNameFactory([]), hasRestrictions: false, }, b: { @@ -337,6 +348,7 @@ describe('IndexPattern Data Panel', () => { title: 'bbb', timeFieldName: 'btime', fields: [], + getFieldByName: getFieldByNameFactory([]), hasRestrictions: false, }, }, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.tsx index 28c5605f3bfc5..f2c7d7fc20926 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/datapanel.tsx @@ -5,7 +5,7 @@ */ import './datapanel.scss'; -import { uniq, keyBy, groupBy } from 'lodash'; +import { uniq, groupBy } from 'lodash'; import React, { useState, memo, useCallback, useMemo } from 'react'; import { EuiFlexGroup, @@ -266,9 +266,8 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({ const fieldInfoUnavailable = existenceFetchFailed || currentIndexPattern.hasRestrictions; const unfilteredFieldGroups: FieldGroups = useMemo(() => { - const fieldByName = keyBy(allFields, 'name'); const containsData = (field: IndexPatternField) => { - const overallField = fieldByName[field.name]; + const overallField = currentIndexPattern.getFieldByName(field.name); return ( overallField && fieldExists(existingFields, currentIndexPattern.title, overallField.name) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/bucket_nesting_editor.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/bucket_nesting_editor.test.tsx index 3696f3ad7b102..ee6a86072236c 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/bucket_nesting_editor.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/bucket_nesting_editor.test.tsx @@ -10,12 +10,14 @@ import { BucketNestingEditor } from './bucket_nesting_editor'; import { IndexPatternColumn } from '../indexpattern'; import { IndexPatternField } from '../types'; -const fieldMap = { +const fieldMap: Record = { a: { displayName: 'a' } as IndexPatternField, b: { displayName: 'b' } as IndexPatternField, c: { displayName: 'c' } as IndexPatternField, }; +const getFieldByName = (name: string): IndexPatternField | undefined => fieldMap[name]; + describe('BucketNestingEditor', () => { function mockCol(col: Partial = {}): IndexPatternColumn { const result = { @@ -39,7 +41,7 @@ describe('BucketNestingEditor', () => { it('should display the top level grouping when at the root', () => { const component = mount( { const component = mount( { const component = mount( { const component = mount( { const component = mount( { const component = mount( { const component = mount( { const component = mount( { const setColumns = jest.fn(); const component = mount( , column: IndexPatternColumn) { - return hasField(column) ? fieldMap[column.sourceField]?.displayName || column.sourceField : ''; +function getFieldName( + column: IndexPatternColumn, + getFieldByName: (name: string) => IndexPatternField | undefined +) { + return hasField(column) + ? getFieldByName(column.sourceField)?.displayName || column.sourceField + : ''; } export function BucketNestingEditor({ columnId, layer, setColumns, - fieldMap, + getFieldByName, }: { columnId: string; layer: IndexPatternLayer; setColumns: (columns: string[]) => void; - fieldMap: Record; + getFieldByName: (name: string) => IndexPatternField | undefined; }) { const column = layer.columns[columnId]; const columns = Object.entries(layer.columns); @@ -42,7 +47,7 @@ export function BucketNestingEditor({ .map(([value, c]) => ({ value, text: c.label, - fieldName: getFieldName(fieldMap, c), + fieldName: getFieldName(c, getFieldByName), operationType: c.operationType, })); diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_editor.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_editor.tsx index a18cb69db74cb..7cbfbc1749382 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_editor.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_editor.tsx @@ -29,7 +29,7 @@ import { deleteColumn, changeColumn, updateColumnParam, mergeLayer } from '../st import { FieldSelect } from './field_select'; import { hasField, fieldIsInvalid } from '../utils'; import { BucketNestingEditor } from './bucket_nesting_editor'; -import { IndexPattern, IndexPatternField } from '../types'; +import { IndexPattern } from '../types'; import { trackUiEvent } from '../../lens_ui_telemetry'; import { FormatSelector } from './format_selector'; @@ -97,23 +97,13 @@ export function DimensionEditor(props: DimensionEditorProps) { const ParamEditor = selectedOperationDefinition?.paramEditor; - const fieldMap: Record = useMemo(() => { - const fields: Record = {}; - currentIndexPattern.fields.forEach((field) => { - fields[field.name] = field; - }); - return fields; - }, [currentIndexPattern]); - const possibleOperations = useMemo(() => { return Object.values(operationDefinitionMap) .sort((op1, op2) => { return op1.displayName.localeCompare(op2.displayName); }) .map((def) => def.type) - .filter( - (type) => fieldByOperation[type]?.length || operationWithoutField.indexOf(type) !== -1 - ); + .filter((type) => fieldByOperation[type]?.size || operationWithoutField.has(type)); }, [fieldByOperation, operationWithoutField]); // Operations are compatible if they match inputs. They are always compatible in @@ -128,7 +118,7 @@ export function DimensionEditor(props: DimensionEditorProps) { (selectedColumn && hasField(selectedColumn) && definition.input === 'field' && - fieldByOperation[operationType]?.indexOf(selectedColumn.sourceField) !== -1) || + fieldByOperation[operationType]?.has(selectedColumn.sourceField)) || (selectedColumn && !hasField(selectedColumn) && definition.input !== 'field'), }; }); @@ -198,9 +188,9 @@ export function DimensionEditor(props: DimensionEditorProps) { trackUiEvent(`indexpattern_dimension_operation_${operationType}`); return; } else if (!selectedColumn || !compatibleWithCurrentField) { - const possibleFields = fieldByOperation[operationType] || []; + const possibleFields = fieldByOperation[operationType] || new Set(); - if (possibleFields.length === 1) { + if (possibleFields.size === 1) { setState( changeColumn({ state, @@ -212,7 +202,7 @@ export function DimensionEditor(props: DimensionEditorProps) { layerId: props.layerId, op: operationType, indexPattern: currentIndexPattern, - field: fieldMap[possibleFields[0]], + field: currentIndexPattern.getFieldByName(possibleFields.values().next().value), previousColumn: selectedColumn, }), }) @@ -236,7 +226,9 @@ export function DimensionEditor(props: DimensionEditorProps) { layerId: props.layerId, op: operationType, indexPattern: currentIndexPattern, - field: hasField(selectedColumn) ? fieldMap[selectedColumn.sourceField] : undefined, + field: hasField(selectedColumn) + ? currentIndexPattern.getFieldByName(selectedColumn.sourceField) + : undefined, previousColumn: selectedColumn, }); @@ -297,7 +289,6 @@ export function DimensionEditor(props: DimensionEditorProps) { fieldIsInvalid={currentFieldIsInvalid} currentIndexPattern={currentIndexPattern} existingFields={state.existingFields} - fieldMap={fieldMap} operationSupportMatrix={operationSupportMatrix} selectedColumnOperationType={selectedColumn && selectedColumn.operationType} selectedColumnSourceField={ @@ -323,25 +314,29 @@ export function DimensionEditor(props: DimensionEditorProps) { ) { // If we just changed the field are not in an error state and the operation didn't change, // we use the operations onFieldChange method to calculate the new column. - column = changeField(selectedColumn, currentIndexPattern, fieldMap[choice.field]); + column = changeField( + selectedColumn, + currentIndexPattern, + currentIndexPattern.getFieldByName(choice.field)! + ); } else { // Otherwise we'll use the buildColumn method to calculate a new column const compatibleOperations = ('field' in choice && operationSupportMatrix.operationByField[choice.field]) || - []; + new Set(); let operation; - if (compatibleOperations.length > 0) { + if (compatibleOperations.size > 0) { operation = incompatibleSelectedOperationType && - compatibleOperations.includes(incompatibleSelectedOperationType) + compatibleOperations.has(incompatibleSelectedOperationType) ? incompatibleSelectedOperationType - : compatibleOperations[0]; + : compatibleOperations.values().next().value; } else if ('field' in choice) { operation = choice.operationType; } column = buildColumn({ columns: props.state.layers[props.layerId].columns, - field: fieldMap[choice.field], + field: currentIndexPattern.getFieldByName(choice.field), indexPattern: currentIndexPattern, layerId: props.layerId, suggestedPriority: props.suggestedPriority, @@ -417,12 +412,12 @@ export function DimensionEditor(props: DimensionEditorProps) { {!incompatibleSelectedOperationType && !hideGrouping && ( setState(mergeLayer({ state, layerId, newLayer: { columnOrder } })) } + getFieldByName={currentIndexPattern.getFieldByName} /> )} diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx index 92a4dad14dd25..3ed04b08df58f 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx @@ -22,6 +22,7 @@ import { IndexPatternColumn } from '../operations'; import { documentField } from '../document_field'; import { OperationMetadata } from '../../types'; import { DateHistogramIndexPatternColumn } from '../operations/definitions/date_histogram'; +import { getFieldByNameFactory } from '../pure_helpers'; jest.mock('../loader'); jest.mock('../state_helpers'); @@ -34,6 +35,42 @@ jest.mock('lodash', () => { }; }); +const fields = [ + { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + aggregatable: true, + searchable: true, + exists: true, + }, + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + exists: true, + }, + { + name: 'memory', + displayName: 'memory', + type: 'number', + aggregatable: true, + searchable: true, + exists: true, + }, + { + name: 'source', + displayName: 'source', + type: 'string', + aggregatable: true, + searchable: true, + exists: true, + }, + documentField, +]; + const expectedIndexPatterns = { 1: { id: '1', @@ -41,41 +78,8 @@ const expectedIndexPatterns = { timeFieldName: 'timestamp', hasExistence: true, hasRestrictions: false, - fields: [ - { - name: 'timestamp', - displayName: 'timestampLabel', - type: 'date', - aggregatable: true, - searchable: true, - exists: true, - }, - { - name: 'bytes', - displayName: 'bytes', - type: 'number', - aggregatable: true, - searchable: true, - exists: true, - }, - { - name: 'memory', - displayName: 'memory', - type: 'number', - aggregatable: true, - searchable: true, - exists: true, - }, - { - name: 'source', - displayName: 'source', - type: 'string', - aggregatable: true, - searchable: true, - exists: true, - }, - documentField, - ], + fields, + getFieldByName: getFieldByNameFactory(fields), }, }; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.test.ts index dd696f8be357f..1d85c1f8f78ca 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.test.ts @@ -15,9 +15,46 @@ import { IndexPatternPrivateState } from '../types'; import { documentField } from '../document_field'; import { OperationMetadata } from '../../types'; import { IndexPatternColumn } from '../operations'; +import { getFieldByNameFactory } from '../pure_helpers'; jest.mock('../state_helpers'); +const fields = [ + { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + aggregatable: true, + searchable: true, + exists: true, + }, + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + exists: true, + }, + { + name: 'memory', + displayName: 'memory', + type: 'number', + aggregatable: true, + searchable: true, + exists: true, + }, + { + name: 'source', + displayName: 'source', + type: 'string', + aggregatable: true, + searchable: true, + exists: true, + }, + documentField, +]; + const expectedIndexPatterns = { 1: { id: '1', @@ -25,41 +62,8 @@ const expectedIndexPatterns = { timeFieldName: 'timestamp', hasExistence: true, hasRestrictions: false, - fields: [ - { - name: 'timestamp', - displayName: 'timestampLabel', - type: 'date', - aggregatable: true, - searchable: true, - exists: true, - }, - { - name: 'bytes', - displayName: 'bytes', - type: 'number', - aggregatable: true, - searchable: true, - exists: true, - }, - { - name: 'memory', - displayName: 'memory', - type: 'number', - aggregatable: true, - searchable: true, - exists: true, - }, - { - name: 'source', - displayName: 'source', - type: 'string', - aggregatable: true, - searchable: true, - exists: true, - }, - documentField, - ], + fields, + getFieldByName: getFieldByNameFactory(fields), }, }; @@ -177,6 +181,23 @@ describe('IndexPatternDimensionEditorPanel', () => { type: 'string', }, ], + + getFieldByName: getFieldByNameFactory([ + { + aggregatable: true, + name: 'bar', + displayName: 'bar', + searchable: true, + type: 'number', + }, + { + aggregatable: true, + name: 'mystring', + displayName: 'mystring', + searchable: true, + type: 'string', + }, + ]), }, }, currentIndexPatternId: '1', diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.ts b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.ts index 7f509cd0244f0..a6ff550af96e9 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.ts @@ -137,9 +137,9 @@ export function onDrop(props: DatasourceDimensionDropHandlerProps { currentIndexPattern: IndexPattern; - fieldMap: Record; incompatibleSelectedOperationType: OperationType | null; selectedColumnOperationType?: OperationType; selectedColumnSourceField?: string; @@ -46,7 +45,6 @@ export interface FieldSelectProps extends EuiComboBoxProps<{}> { export function FieldSelect({ currentIndexPattern, - fieldMap, incompatibleSelectedOperationType, selectedColumnOperationType, selectedColumnSourceField, @@ -63,31 +61,32 @@ export function FieldSelect({ function isCompatibleWithCurrentOperation(fieldName: string) { if (incompatibleSelectedOperationType) { - return operationByField[fieldName]!.includes(incompatibleSelectedOperationType); + return operationByField[fieldName]!.has(incompatibleSelectedOperationType); } return ( !selectedColumnOperationType || - operationByField[fieldName]!.includes(selectedColumnOperationType) + operationByField[fieldName]!.has(selectedColumnOperationType) ); } const [specialFields, normalFields] = _.partition( fields, - (field) => fieldMap[field].type === 'document' + (field) => currentIndexPattern.getFieldByName(field)?.type === 'document' ); const containsData = (field: string) => - fieldMap[field].type === 'document' || + currentIndexPattern.getFieldByName(field)?.type === 'document' || fieldExists(existingFields, currentIndexPattern.title, field); function fieldNamesToOptions(items: string[]) { return items + .filter((field) => currentIndexPattern.getFieldByName(field)?.displayName) .map((field) => ({ - label: fieldMap[field].displayName, + label: currentIndexPattern.getFieldByName(field)?.displayName, value: { type: 'field', field, - dataType: fieldMap[field].type, + dataType: currentIndexPattern.getFieldByName(field)?.type, operationType: selectedColumnOperationType && isCompatibleWithCurrentOperation(field) ? selectedColumnOperationType @@ -118,7 +117,10 @@ export function FieldSelect({ })); } - const [metaFields, nonMetaFields] = _.partition(normalFields, (field) => fieldMap[field].meta); + const [metaFields, nonMetaFields] = _.partition( + normalFields, + (field) => currentIndexPattern.getFieldByName(field)?.meta + ); const [availableFields, emptyFields] = _.partition(nonMetaFields, containsData); const constructFieldsOptions = (fieldsArr: string[], label: string) => @@ -158,7 +160,6 @@ export function FieldSelect({ incompatibleSelectedOperationType, selectedColumnOperationType, currentIndexPattern, - fieldMap, operationByField, existingFields, ]); @@ -180,7 +181,7 @@ export function FieldSelect({ { label: fieldIsInvalid ? selectedColumnSourceField - : fieldMap[selectedColumnSourceField]?.displayName, + : currentIndexPattern.getFieldByName(selectedColumnSourceField)?.displayName, value: { type: 'field', field: selectedColumnSourceField }, }, ] diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/operation_support.ts b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/operation_support.ts index 2ea28da201556..31fb5277d53ec 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/operation_support.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/operation_support.ts @@ -11,9 +11,9 @@ import { getAvailableOperationsByMetadata } from '../operations'; import { IndexPatternPrivateState } from '../types'; export interface OperationSupportMatrix { - operationByField: Partial>; - operationWithoutField: OperationType[]; - fieldByOperation: Partial>; + operationByField: Partial>>; + operationWithoutField: Set; + fieldByOperation: Partial>>; } type Props = Pick< @@ -31,30 +31,30 @@ export const getOperationSupportMatrix = (props: Props): OperationSupportMatrix currentIndexPattern ).filter((operation) => props.filterOperations(operation.operationMetaData)); - const supportedOperationsByField: Partial> = {}; - const supportedOperationsWithoutField: OperationType[] = []; - const supportedFieldsByOperation: Partial> = {}; + const supportedOperationsByField: Partial>> = {}; + const supportedOperationsWithoutField: Set = new Set(); + const supportedFieldsByOperation: Partial>> = {}; filteredOperationsByMetadata.forEach(({ operations }) => { operations.forEach((operation) => { if (operation.type === 'field') { - supportedOperationsByField[operation.field] = [ - ...(supportedOperationsByField[operation.field] ?? []), - operation.operationType, - ]; - - supportedFieldsByOperation[operation.operationType] = [ - ...(supportedFieldsByOperation[operation.operationType] ?? []), - operation.field, - ]; + if (!supportedOperationsByField[operation.field]) { + supportedOperationsByField[operation.field] = new Set(); + } + supportedOperationsByField[operation.field]?.add(operation.operationType); + + if (!supportedFieldsByOperation[operation.operationType]) { + supportedFieldsByOperation[operation.operationType] = new Set(); + } + supportedFieldsByOperation[operation.operationType]?.add(operation.field); } else if (operation.type === 'none') { - supportedOperationsWithoutField.push(operation.operationType); + supportedOperationsWithoutField.add(operation.operationType); } }); }); return { - operationByField: _.mapValues(supportedOperationsByField, _.uniq), - operationWithoutField: _.uniq(supportedOperationsWithoutField), - fieldByOperation: _.mapValues(supportedFieldsByOperation, _.uniq), + operationByField: supportedOperationsByField, + operationWithoutField: supportedOperationsWithoutField, + fieldByOperation: supportedFieldsByOperation, }; }; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts index a3f48b162475a..51d95245adb25 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.test.ts @@ -12,121 +12,128 @@ import { IndexPatternPersistedState, IndexPatternPrivateState } from './types'; import { dataPluginMock } from '../../../../../src/plugins/data/public/mocks'; import { Ast } from '@kbn/interpreter/common'; import { chartPluginMock } from '../../../../../src/plugins/charts/public/mocks'; +import { getFieldByNameFactory } from './pure_helpers'; jest.mock('./loader'); jest.mock('../id_generator'); -const expectedIndexPatterns = { - 1: { - id: '1', - title: 'my-fake-index-pattern', - timeFieldName: 'timestamp', - hasRestrictions: false, - fields: [ - { - name: 'timestamp', - displayName: 'timestampLabel', - type: 'date', - aggregatable: true, - searchable: true, +const fieldsOne = [ + { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + aggregatable: true, + searchable: true, + }, + { + name: 'start_date', + displayName: 'start_date', + type: 'date', + aggregatable: true, + searchable: true, + }, + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'memory', + displayName: 'memory', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'source', + displayName: 'source', + type: 'string', + aggregatable: true, + searchable: true, + }, + { + name: 'dest', + displayName: 'dest', + type: 'string', + aggregatable: true, + searchable: true, + }, +]; + +const fieldsTwo = [ + { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + aggregatable: true, + searchable: true, + aggregationRestrictions: { + date_histogram: { + agg: 'date_histogram', + fixed_interval: '1d', + delay: '7d', + time_zone: 'UTC', }, - { - name: 'start_date', - displayName: 'start_date', - type: 'date', - aggregatable: true, - searchable: true, + }, + }, + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + aggregationRestrictions: { + // Ignored in the UI + histogram: { + agg: 'histogram', + interval: 1000, }, - { - name: 'bytes', - displayName: 'bytes', - type: 'number', - aggregatable: true, - searchable: true, + avg: { + agg: 'avg', }, - { - name: 'memory', - displayName: 'memory', - type: 'number', - aggregatable: true, - searchable: true, + max: { + agg: 'max', }, - { - name: 'source', - displayName: 'source', - type: 'string', - aggregatable: true, - searchable: true, + min: { + agg: 'min', }, - { - name: 'dest', - displayName: 'dest', - type: 'string', - aggregatable: true, - searchable: true, + sum: { + agg: 'sum', }, - ], + }, + }, + { + name: 'source', + displayName: 'source', + type: 'string', + aggregatable: true, + searchable: true, + aggregationRestrictions: { + terms: { + agg: 'terms', + }, + }, + }, +]; + +const expectedIndexPatterns = { + 1: { + id: '1', + title: 'my-fake-index-pattern', + timeFieldName: 'timestamp', + hasRestrictions: false, + fields: fieldsOne, + getFieldByName: getFieldByNameFactory(fieldsOne), }, 2: { id: '2', title: 'my-fake-restricted-pattern', timeFieldName: 'timestamp', hasRestrictions: true, - fields: [ - { - name: 'timestamp', - displayName: 'timestampLabel', - type: 'date', - aggregatable: true, - searchable: true, - aggregationRestrictions: { - date_histogram: { - agg: 'date_histogram', - fixed_interval: '1d', - delay: '7d', - time_zone: 'UTC', - }, - }, - }, - { - name: 'bytes', - displayName: 'bytes', - type: 'number', - aggregatable: true, - searchable: true, - aggregationRestrictions: { - // Ignored in the UI - histogram: { - agg: 'histogram', - interval: 1000, - }, - avg: { - agg: 'avg', - }, - max: { - agg: 'max', - }, - min: { - agg: 'min', - }, - sum: { - agg: 'sum', - }, - }, - }, - { - name: 'source', - displayName: 'source', - type: 'string', - aggregatable: true, - searchable: true, - aggregationRestrictions: { - terms: { - agg: 'terms', - }, - }, - }, - ], + fields: fieldsTwo, + getFieldByName: getFieldByNameFactory(fieldsTwo), }, }; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx index c8cb9fcb33ba9..523a1be34ba3d 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx @@ -12,121 +12,128 @@ import { getDatasourceSuggestionsFromCurrentState, getDatasourceSuggestionsForVisualizeField, } from './indexpattern_suggestions'; +import { getFieldByNameFactory } from './pure_helpers'; jest.mock('./loader'); jest.mock('../id_generator'); -const expectedIndexPatterns = { - 1: { - id: '1', - title: 'my-fake-index-pattern', - timeFieldName: 'timestamp', - hasRestrictions: false, - fields: [ - { - name: 'timestamp', - displayName: 'timestampLabel', - type: 'date', - aggregatable: true, - searchable: true, +const fieldsOne = [ + { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + aggregatable: true, + searchable: true, + }, + { + name: 'start_date', + displayName: 'start_date', + type: 'date', + aggregatable: true, + searchable: true, + }, + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'memory', + displayName: 'memory', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'source', + displayName: 'source', + type: 'string', + aggregatable: true, + searchable: true, + }, + { + name: 'dest', + displayName: 'dest', + type: 'string', + aggregatable: true, + searchable: true, + }, +]; + +const fieldsTwo = [ + { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + aggregatable: true, + searchable: true, + aggregationRestrictions: { + date_histogram: { + agg: 'date_histogram', + fixed_interval: '1d', + delay: '7d', + time_zone: 'UTC', }, - { - name: 'start_date', - displayName: 'start_date', - type: 'date', - aggregatable: true, - searchable: true, + }, + }, + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + aggregationRestrictions: { + // Ignored in the UI + histogram: { + agg: 'histogram', + interval: 1000, }, - { - name: 'bytes', - displayName: 'bytes', - type: 'number', - aggregatable: true, - searchable: true, + avg: { + agg: 'avg', }, - { - name: 'memory', - displayName: 'memory', - type: 'number', - aggregatable: true, - searchable: true, + max: { + agg: 'max', }, - { - name: 'source', - displayName: 'source', - type: 'string', - aggregatable: true, - searchable: true, + min: { + agg: 'min', }, - { - name: 'dest', - displayName: 'dest', - type: 'string', - aggregatable: true, - searchable: true, + sum: { + agg: 'sum', + }, + }, + }, + { + name: 'source', + displayName: 'source', + type: 'string', + aggregatable: true, + searchable: true, + aggregationRestrictions: { + terms: { + agg: 'terms', }, - ], + }, + }, +]; + +const expectedIndexPatterns = { + 1: { + id: '1', + title: 'my-fake-index-pattern', + timeFieldName: 'timestamp', + hasRestrictions: false, + fields: fieldsOne, + getFieldByName: getFieldByNameFactory(fieldsOne), }, 2: { id: '2', title: 'my-fake-restricted-pattern', hasRestrictions: true, timeFieldName: 'timestamp', - fields: [ - { - name: 'timestamp', - displayName: 'timestampLabel', - type: 'date', - aggregatable: true, - searchable: true, - aggregationRestrictions: { - date_histogram: { - agg: 'date_histogram', - fixed_interval: '1d', - delay: '7d', - time_zone: 'UTC', - }, - }, - }, - { - name: 'bytes', - displayName: 'bytes', - type: 'number', - aggregatable: true, - searchable: true, - aggregationRestrictions: { - // Ignored in the UI - histogram: { - agg: 'histogram', - interval: 1000, - }, - avg: { - agg: 'avg', - }, - max: { - agg: 'max', - }, - min: { - agg: 'min', - }, - sum: { - agg: 'sum', - }, - }, - }, - { - name: 'source', - displayName: 'source', - type: 'string', - aggregatable: true, - searchable: true, - aggregationRestrictions: { - terms: { - agg: 'terms', - }, - }, - }, - ], + fields: fieldsTwo, + getFieldByName: getFieldByNameFactory(fieldsTwo), }, }; @@ -335,6 +342,15 @@ describe('IndexPattern Data Source suggestions', () => { searchable: true, }, ], + getFieldByName: getFieldByNameFactory([ + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + }, + ]), }, }, layers: { @@ -546,6 +562,16 @@ describe('IndexPattern Data Source suggestions', () => { searchable: true, }, ], + + getFieldByName: getFieldByNameFactory([ + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + }, + ]), }, }, layers: { @@ -1531,6 +1557,43 @@ describe('IndexPattern Data Source suggestions', () => { it('returns simplified versions of table with more than 2 columns', () => { const initialState = testInitialState(); + const fields = [ + { + name: 'field1', + displayName: 'field1', + type: 'string', + aggregatable: true, + searchable: true, + }, + { + name: 'field2', + displayName: 'field2', + type: 'string', + aggregatable: true, + searchable: true, + }, + { + name: 'field3', + displayName: 'field3Label', + type: 'string', + aggregatable: true, + searchable: true, + }, + { + name: 'field4', + displayName: 'field4', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'field5', + displayName: 'field5', + type: 'number', + aggregatable: true, + searchable: true, + }, + ]; const state: IndexPatternPrivateState = { indexPatternRefs: [], existingFields: {}, @@ -1540,43 +1603,8 @@ describe('IndexPattern Data Source suggestions', () => { id: '1', title: 'my-fake-index-pattern', hasRestrictions: false, - fields: [ - { - name: 'field1', - displayName: 'field1', - type: 'string', - aggregatable: true, - searchable: true, - }, - { - name: 'field2', - displayName: 'field2', - type: 'string', - aggregatable: true, - searchable: true, - }, - { - name: 'field3', - displayName: 'field3Label', - type: 'string', - aggregatable: true, - searchable: true, - }, - { - name: 'field4', - displayName: 'field4', - type: 'number', - aggregatable: true, - searchable: true, - }, - { - name: 'field5', - displayName: 'field5', - type: 'number', - aggregatable: true, - searchable: true, - }, - ], + fields, + getFieldByName: getFieldByNameFactory(fields), }, }, isFirstExistenceFetch: false, @@ -1700,6 +1728,23 @@ describe('IndexPattern Data Source suggestions', () => { searchable: true, }, ], + + getFieldByName: getFieldByNameFactory([ + { + name: 'field1', + displayName: 'field1', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'field2', + displayName: 'field2', + type: 'date', + aggregatable: true, + searchable: true, + }, + ]), }, }, isFirstExistenceFetch: false, @@ -1756,6 +1801,15 @@ describe('IndexPattern Data Source suggestions', () => { searchable: true, }, ], + getFieldByName: getFieldByNameFactory([ + { + name: 'field1', + displayName: 'field1', + type: 'number', + aggregatable: true, + searchable: true, + }, + ]), }, }, isFirstExistenceFetch: false, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.ts b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.ts index 098569d1f460a..c12d7d4be226b 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.ts @@ -128,7 +128,7 @@ export function getDatasourceSuggestionsForVisualizeField( const layerIds = layers.filter((id) => state.layers[id].indexPatternId === indexPatternId); // Identify the field by the indexPatternId and the fieldName const indexPattern = state.indexPatterns[indexPatternId]; - const field = indexPattern.fields.find((fld) => fld.name === fieldName); + const field = indexPattern.getFieldByName(fieldName); if (layerIds.length !== 0 || !field) return []; const newId = generateId(); @@ -371,7 +371,7 @@ function createNewLayerWithMetricAggregation( indexPattern: IndexPattern, field: IndexPatternField ): IndexPatternLayer { - const dateField = indexPattern.fields.find((f) => f.name === indexPattern.timeFieldName)!; + const dateField = indexPattern.getFieldByName(indexPattern.timeFieldName!); const column = getMetricColumn(indexPattern, layerId, field); @@ -451,9 +451,8 @@ export function getDatasourceSuggestionsFromCurrentState( (columnId) => layer.columns[columnId].isBucketed && layer.columns[columnId].dataType === 'date' ); - const timeField = indexPattern.fields.find( - ({ name }) => name === indexPattern.timeFieldName - ); + const timeField = + indexPattern.timeFieldName && indexPattern.getFieldByName(indexPattern.timeFieldName); const hasNumericDimension = buckets.length === 1 && @@ -507,17 +506,17 @@ function createChangedNestingSuggestion(state: IndexPatternPrivateState, layerId const layer = state.layers[layerId]; const [firstBucket, secondBucket, ...rest] = layer.columnOrder; const updatedLayer = { ...layer, columnOrder: [secondBucket, firstBucket, ...rest] }; - const currentFields = state.indexPatterns[state.currentIndexPatternId].fields; + const indexPattern = state.indexPatterns[state.currentIndexPatternId]; + const firstBucketColumn = layer.columns[firstBucket]; const firstBucketLabel = - currentFields.find((field) => { - const column = layer.columns[firstBucket]; - return hasField(column) && column.sourceField === field.name; - })?.displayName || ''; + (hasField(firstBucketColumn) && + indexPattern.getFieldByName(firstBucketColumn.sourceField)?.displayName) || + ''; + const secondBucketColumn = layer.columns[secondBucket]; const secondBucketLabel = - currentFields.find((field) => { - const column = layer.columns[secondBucket]; - return hasField(column) && column.sourceField === field.name; - })?.displayName || ''; + (hasField(secondBucketColumn) && + indexPattern.getFieldByName(secondBucketColumn.sourceField)?.displayName) || + ''; return buildSuggestion({ state, @@ -604,7 +603,10 @@ function createAlternativeMetricSuggestions( if (!hasField(column)) { return; } - const field = indexPattern.fields.find(({ name }) => column.sourceField === name)!; + const field = indexPattern.getFieldByName(column.sourceField); + if (!field) { + return; + } const alternativeMetricOperations = getOperationTypesForField(field) .map((op) => buildColumn({ diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/layerpanel.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/layerpanel.test.tsx index 92e35b257f24a..40eb52fe67c6d 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/layerpanel.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/layerpanel.test.tsx @@ -11,6 +11,7 @@ import { shallowWithIntl as shallow } from 'test_utils/enzyme_helpers'; import { ShallowWrapper } from 'enzyme'; import { EuiSelectable } from '@elastic/eui'; import { ChangeIndexPattern } from './change_indexpattern'; +import { getFieldByNameFactory } from './pure_helpers'; jest.mock('./state_helpers'); @@ -19,6 +20,120 @@ interface IndexPatternPickerOption { checked?: 'on' | 'off'; } +const fieldsOne = [ + { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + aggregatable: true, + searchable: true, + }, + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'memory', + displayName: 'memory', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'unsupported', + displayName: 'unsupported', + type: 'geo', + aggregatable: true, + searchable: true, + }, + { + name: 'source', + displayName: 'source', + type: 'string', + aggregatable: true, + searchable: true, + }, +]; + +const fieldsTwo = [ + { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + aggregatable: true, + searchable: true, + aggregationRestrictions: { + date_histogram: { + agg: 'date_histogram', + fixed_interval: '1d', + delay: '7d', + time_zone: 'UTC', + }, + }, + }, + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + aggregationRestrictions: { + histogram: { + agg: 'histogram', + interval: 1000, + }, + max: { + agg: 'max', + }, + min: { + agg: 'min', + }, + sum: { + agg: 'sum', + }, + }, + }, + { + name: 'source', + displayName: 'source', + type: 'string', + aggregatable: true, + searchable: true, + aggregationRestrictions: { + terms: { + agg: 'terms', + }, + }, + }, +]; + +const fieldsThree = [ + { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + aggregatable: true, + searchable: true, + }, + { + name: 'memory', + displayName: 'memory', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'source', + displayName: 'source', + type: 'string', + aggregatable: true, + searchable: true, + }, +]; + const initialState: IndexPatternPrivateState = { indexPatternRefs: [ { id: '1', title: 'my-fake-index-pattern' }, @@ -63,129 +178,24 @@ const initialState: IndexPatternPrivateState = { title: 'my-fake-index-pattern', timeFieldName: 'timestamp', hasRestrictions: false, - fields: [ - { - name: 'timestamp', - displayName: 'timestampLabel', - type: 'date', - aggregatable: true, - searchable: true, - }, - { - name: 'bytes', - displayName: 'bytes', - type: 'number', - aggregatable: true, - searchable: true, - }, - { - name: 'memory', - displayName: 'memory', - type: 'number', - aggregatable: true, - searchable: true, - }, - { - name: 'unsupported', - displayName: 'unsupported', - type: 'geo', - aggregatable: true, - searchable: true, - }, - { - name: 'source', - displayName: 'source', - type: 'string', - aggregatable: true, - searchable: true, - }, - ], + fields: fieldsOne, + getFieldByName: getFieldByNameFactory(fieldsOne), }, '2': { id: '2', title: 'my-fake-restricted-pattern', hasRestrictions: true, timeFieldName: 'timestamp', - fields: [ - { - name: 'timestamp', - displayName: 'timestampLabel', - type: 'date', - aggregatable: true, - searchable: true, - aggregationRestrictions: { - date_histogram: { - agg: 'date_histogram', - fixed_interval: '1d', - delay: '7d', - time_zone: 'UTC', - }, - }, - }, - { - name: 'bytes', - displayName: 'bytes', - type: 'number', - aggregatable: true, - searchable: true, - aggregationRestrictions: { - histogram: { - agg: 'histogram', - interval: 1000, - }, - max: { - agg: 'max', - }, - min: { - agg: 'min', - }, - sum: { - agg: 'sum', - }, - }, - }, - { - name: 'source', - displayName: 'source', - type: 'string', - aggregatable: true, - searchable: true, - aggregationRestrictions: { - terms: { - agg: 'terms', - }, - }, - }, - ], + fields: fieldsTwo, + getFieldByName: getFieldByNameFactory(fieldsTwo), }, '3': { id: '3', title: 'my-compatible-pattern', timeFieldName: 'timestamp', hasRestrictions: false, - fields: [ - { - name: 'timestamp', - displayName: 'timestampLabel', - type: 'date', - aggregatable: true, - searchable: true, - }, - { - name: 'memory', - displayName: 'memory', - type: 'number', - aggregatable: true, - searchable: true, - }, - { - name: 'source', - displayName: 'source', - type: 'string', - aggregatable: true, - searchable: true, - }, - ], + fields: fieldsThree, + getFieldByName: getFieldByNameFactory(fieldsThree), }, }, }; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/loader.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/loader.test.ts index 4222c02388433..adb86253ab28c 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/loader.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/loader.test.ts @@ -285,15 +285,10 @@ describe('loader', () => { } as unknown) as Pick, }); - expect( - cache.foo.fields.find((f: IndexPatternField) => f.name === 'bytes')!.aggregationRestrictions - ).toEqual({ + expect(cache.foo.getFieldByName('bytes')!.aggregationRestrictions).toEqual({ sum: { agg: 'sum' }, }); - expect( - cache.foo.fields.find((f: IndexPatternField) => f.name === 'timestamp')! - .aggregationRestrictions - ).toEqual({ + expect(cache.foo.getFieldByName('timestamp')!.aggregationRestrictions).toEqual({ date_histogram: { agg: 'date_histogram', fixed_interval: 'm' }, }); }); @@ -342,9 +337,7 @@ describe('loader', () => { } as unknown) as Pick, }); - expect(cache.foo.fields.find((f: IndexPatternField) => f.name === 'timestamp')!.meta).toEqual( - true - ); + expect(cache.foo.getFieldByName('timestamp')!.meta).toEqual(true); }); }); diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/loader.ts b/x-pack/plugins/lens/public/indexpattern_datasource/loader.ts index 70079cce6cc46..fac5d7350e45e 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/loader.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/loader.ts @@ -26,6 +26,7 @@ import { import { VisualizeFieldContext } from '../../../../../src/plugins/ui_actions/public'; import { documentField } from './document_field'; import { readFromStorage, writeToStorage } from '../settings_storage'; +import { getFieldByNameFactory } from './pure_helpers'; type SetState = StateSetter; type SavedObjectsClient = Pick; @@ -112,6 +113,7 @@ export async function loadIndexPatterns({ ]) ), fields: newFields, + getFieldByName: getFieldByNameFactory(newFields), hasRestrictions: !!typeMeta?.aggs, }; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/mocks.ts b/x-pack/plugins/lens/public/indexpattern_datasource/mocks.ts index 744a9f6743d09..2c6f42668d863 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/mocks.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/mocks.ts @@ -5,14 +5,11 @@ */ import { DragContextState } from '../drag_drop'; +import { getFieldByNameFactory } from './pure_helpers'; import { IndexPattern } from './types'; -export const createMockedIndexPattern = (): IndexPattern => ({ - id: '1', - title: 'my-fake-index-pattern', - timeFieldName: 'timestamp', - hasRestrictions: false, - fields: [ +export const createMockedIndexPattern = (): IndexPattern => { + const fields = [ { name: 'timestamp', displayName: 'timestampLabel', @@ -74,16 +71,19 @@ export const createMockedIndexPattern = (): IndexPattern => ({ lang: 'painless', script: '1234', }, - ], -}); + ]; + return { + id: '1', + title: 'my-fake-index-pattern', + timeFieldName: 'timestamp', + hasRestrictions: false, + fields, + getFieldByName: getFieldByNameFactory(fields), + }; +}; -export const createMockedRestrictedIndexPattern = () => ({ - id: '2', - title: 'my-fake-restricted-pattern', - timeFieldName: 'timestamp', - hasRestrictions: true, - fieldFormatMap: { bytes: { id: 'bytes', params: { pattern: '0.0' } } }, - fields: [ +export const createMockedRestrictedIndexPattern = () => { + const fields = [ { name: 'timestamp', displayName: 'timestampLabel', @@ -109,54 +109,63 @@ export const createMockedRestrictedIndexPattern = () => ({ lang: 'painless', script: '1234', }, - ], - typeMeta: { - params: { - rollup_index: 'my-fake-index-pattern', - }, - aggs: { - terms: { - source: { - agg: 'terms', - }, + ]; + return { + id: '2', + title: 'my-fake-restricted-pattern', + timeFieldName: 'timestamp', + hasRestrictions: true, + fieldFormatMap: { bytes: { id: 'bytes', params: { pattern: '0.0' } } }, + fields, + getFieldByName: getFieldByNameFactory(fields), + typeMeta: { + params: { + rollup_index: 'my-fake-index-pattern', }, - date_histogram: { - timestamp: { - agg: 'date_histogram', - fixed_interval: '1d', - delay: '7d', - time_zone: 'UTC', + aggs: { + terms: { + source: { + agg: 'terms', + }, }, - }, - histogram: { - bytes: { - agg: 'histogram', - interval: 1000, + date_histogram: { + timestamp: { + agg: 'date_histogram', + fixed_interval: '1d', + delay: '7d', + time_zone: 'UTC', + }, }, - }, - avg: { - bytes: { - agg: 'avg', + histogram: { + bytes: { + agg: 'histogram', + interval: 1000, + }, }, - }, - max: { - bytes: { - agg: 'max', + avg: { + bytes: { + agg: 'avg', + }, }, - }, - min: { - bytes: { - agg: 'min', + max: { + bytes: { + agg: 'max', + }, }, - }, - sum: { - bytes: { - agg: 'sum', + min: { + bytes: { + agg: 'min', + }, + }, + sum: { + bytes: { + agg: 'sum', + }, }, }, }, - }, -}); + }; +}; export function createMockedDragDropContext(): jest.Mocked { return { diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/cardinality.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/cardinality.tsx index 65119d3978ee6..1cfa63511a45c 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/cardinality.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/cardinality.tsx @@ -43,7 +43,7 @@ export const cardinalityOperation: OperationDefinition { - const newField = newIndexPattern.fields.find((field) => field.name === column.sourceField); + const newField = newIndexPattern.getFieldByName(column.sourceField); return Boolean( newField && diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.test.tsx index ac6bf63c37110..fc33b64ca508f 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.test.tsx @@ -18,6 +18,7 @@ import { } from '../../../../../../../src/plugins/data/public/mocks'; import { createMockedIndexPattern } from '../../mocks'; import { IndexPatternPrivateState } from '../../types'; +import { getFieldByNameFactory } from '../../pure_helpers'; const dataStart = dataPluginMock.createStartContract(); dataStart.search.aggs.calculateAutoTimeExpression = getCalculateAutoTimeExpression( @@ -66,6 +67,17 @@ describe('date_histogram', () => { searchable: true, }, ], + + getFieldByName: getFieldByNameFactory([ + { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + esTypes: ['date'], + aggregatable: true, + searchable: true, + }, + ]), }, 2: { id: '2', @@ -81,6 +93,16 @@ describe('date_histogram', () => { searchable: true, }, ], + getFieldByName: getFieldByNameFactory([ + { + name: 'other_timestamp', + displayName: 'other_timestamp', + type: 'date', + esTypes: ['date'], + aggregatable: true, + searchable: true, + }, + ]), }, }, layers: { @@ -267,6 +289,22 @@ describe('date_histogram', () => { }, }, ], + getFieldByName: getFieldByNameFactory([ + { + name: 'timestamp', + displayName: 'timestamp', + aggregatable: true, + searchable: true, + type: 'date', + aggregationRestrictions: { + date_histogram: { + agg: 'date_histogram', + time_zone: 'UTC', + calendar_interval: '42w', + }, + }, + }, + ]), } ); expect(esAggsConfig).toEqual( @@ -294,7 +332,7 @@ describe('date_histogram', () => { }, }; const indexPattern = createMockedIndexPattern(); - const newDateField = indexPattern.fields.find((i) => i.name === 'start_date')!; + const newDateField = indexPattern.getFieldByName('start_date')!; const column = dateHistogramOperation.onFieldChange(oldColumn, indexPattern, newDateField); expect(column).toHaveProperty('sourceField', 'start_date'); @@ -314,7 +352,7 @@ describe('date_histogram', () => { }, }; const indexPattern = createMockedIndexPattern(); - const newDateField = indexPattern.fields.find((i) => i.name === 'start_date')!; + const newDateField = indexPattern.getFieldByName('start_date')!; const column = dateHistogramOperation.onFieldChange(oldColumn, indexPattern, newDateField); expect(column).toHaveProperty('sourceField', 'start_date'); @@ -356,6 +394,22 @@ describe('date_histogram', () => { }, }, ], + getFieldByName: getFieldByNameFactory([ + { + name: 'dateField', + displayName: 'dateField', + type: 'date', + aggregatable: true, + searchable: true, + aggregationRestrictions: { + date_histogram: { + agg: 'date_histogram', + time_zone: 'CET', + calendar_interval: 'w', + }, + }, + }, + ]), } ); expect(transferedColumn).toEqual( @@ -393,6 +447,15 @@ describe('date_histogram', () => { searchable: true, }, ], + getFieldByName: getFieldByNameFactory([ + { + name: 'dateField', + displayName: 'dateField', + type: 'date', + aggregatable: true, + searchable: true, + }, + ]), } ); expect(transferedColumn).toEqual( @@ -609,6 +672,18 @@ describe('date_histogram', () => { }, }, ], + getFieldByName: getFieldByNameFactory([ + { + ...state.indexPatterns[1].fields[0], + aggregationRestrictions: { + date_histogram: { + agg: 'date_histogram', + time_zone: 'UTC', + calendar_interval: '1h', + }, + }, + }, + ]), }, }, }} diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.tsx index 185f44405bb4b..19043c03e5a61 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.tsx @@ -81,7 +81,7 @@ export const dateHistogramOperation: OperationDefinition< }; }, isTransferable: (column, newIndexPattern) => { - const newField = newIndexPattern.fields.find((field) => field.name === column.sourceField); + const newField = newIndexPattern.getFieldByName(column.sourceField); return Boolean( newField && @@ -91,12 +91,9 @@ export const dateHistogramOperation: OperationDefinition< ); }, transfer: (column, newIndexPattern) => { - const newField = newIndexPattern.fields.find((field) => field.name === column.sourceField); - if ( - newField && - newField.aggregationRestrictions && - newField.aggregationRestrictions.date_histogram - ) { + const newField = newIndexPattern.getFieldByName(column.sourceField); + + if (newField?.aggregationRestrictions?.date_histogram) { const restrictions = newField.aggregationRestrictions.date_histogram; return { @@ -123,7 +120,7 @@ export const dateHistogramOperation: OperationDefinition< }; }, toEsAggsConfig: (column, columnId, indexPattern) => { - const usedField = indexPattern.fields.find((field) => field.name === column.sourceField); + const usedField = indexPattern.getFieldByName(column.sourceField); return { id: columnId, enabled: true, @@ -132,7 +129,7 @@ export const dateHistogramOperation: OperationDefinition< params: { field: column.sourceField, time_zone: column.params.timeZone, - useNormalizedEsInterval: !usedField || !usedField.aggregationRestrictions?.date_histogram, + useNormalizedEsInterval: !usedField?.aggregationRestrictions?.date_histogram, interval: column.params.interval, drop_partials: false, min_doc_count: 0, @@ -143,8 +140,8 @@ export const dateHistogramOperation: OperationDefinition< paramEditor: ({ state, setState, currentColumn, layerId, dateRange, data }) => { const field = currentColumn && - state.indexPatterns[state.layers[layerId].indexPatternId].fields.find( - (currentField) => currentField.name === currentColumn.sourceField + state.indexPatterns[state.layers[layerId].indexPatternId].getFieldByName( + currentColumn.sourceField ); const intervalIsRestricted = field!.aggregationRestrictions && field!.aggregationRestrictions.date_histogram; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/metrics.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/metrics.tsx index 1d3ecc165ce74..fef575c61475c 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/metrics.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/metrics.tsx @@ -43,7 +43,7 @@ function buildMetricOperation>({ } }, isTransferable: (column, newIndexPattern) => { - const newField = newIndexPattern.fields.find((field) => field.name === column.sourceField); + const newField = newIndexPattern.getFieldByName(column.sourceField); return Boolean( newField && diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx index d43a905434c02..ce015284e544b 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.test.tsx @@ -30,6 +30,7 @@ import { } from './constants'; import { RangePopover } from './advanced_editor'; import { DragDropBuckets } from '../shared_components'; +import { getFieldByNameFactory } from '../../../pure_helpers'; const dataPluginMockValue = dataPluginMock.createStartContract(); // need to overwrite the formatter field first @@ -96,6 +97,9 @@ describe('ranges', () => { title: 'my_index_pattern', hasRestrictions: false, fields: [{ name: sourceField, type: 'number', displayName: sourceField }], + getFieldByName: getFieldByNameFactory([ + { name: sourceField, type: 'number', displayName: sourceField }, + ]), }, }, existingFields: {}, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx index 46d9e4e6c22de..c6cc6ae13f178 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx @@ -140,7 +140,7 @@ export const rangeOperation: OperationDefinition { - const newField = newIndexPattern.fields.find((field) => field.name === column.sourceField); + const newField = newIndexPattern.getFieldByName(column.sourceField); return Boolean( newField && @@ -168,9 +168,7 @@ export const rangeOperation: OperationDefinition { const indexPattern = state.indexPatterns[state.layers[layerId].indexPatternId]; - const currentField = indexPattern.fields.find( - (field) => field.name === currentColumn.sourceField - ); + const currentField = indexPattern.getFieldByName(currentColumn.sourceField); const numberFormat = currentColumn.params.format; const numberFormatterPattern = numberFormat && diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/index.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/index.tsx index dcb4646816e13..421068a5ad47f 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/index.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/index.tsx @@ -61,7 +61,7 @@ export const termsOperation: OperationDefinition { - const newField = newIndexPattern.fields.find((field) => field.name === column.sourceField); + const newField = newIndexPattern.getFieldByName(column.sourceField); return Boolean( newField && diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/terms.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/terms.test.tsx index 1341ca0587c75..bb1b13ba74cc5 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/terms.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/terms.test.tsx @@ -103,7 +103,7 @@ describe('terms', () => { }, }; const indexPattern = createMockedIndexPattern(); - const newNumberField = indexPattern.fields.find((i) => i.name === 'bytes')!; + const newNumberField = indexPattern.getFieldByName('bytes')!; const column = termsOperation.onFieldChange(oldColumn, indexPattern, newNumberField); expect(column).toHaveProperty('dataType', 'number'); diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/operations.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/operations.test.ts index 6808bc724f26b..9767d4bdca688 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/operations.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/operations.test.ts @@ -8,38 +8,42 @@ import { getOperationTypesForField, getAvailableOperationsByMetadata, buildColum import { AvgIndexPatternColumn } from './definitions/metrics'; import { IndexPatternPrivateState } from '../types'; import { documentField } from '../document_field'; +import { getFieldByNameFactory } from '../pure_helpers'; jest.mock('../loader'); +const fields = [ + { + name: 'timestamp', + displayName: 'timestamp', + type: 'date', + aggregatable: true, + searchable: true, + }, + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'source', + displayName: 'source', + type: 'string', + aggregatable: true, + searchable: true, + }, +]; + const expectedIndexPatterns = { 1: { id: '1', title: 'my-fake-index-pattern', timeFieldName: 'timestamp', hasRestrictions: false, - fields: [ - { - name: 'timestamp', - displayName: 'timestamp', - type: 'date', - aggregatable: true, - searchable: true, - }, - { - name: 'bytes', - displayName: 'bytes', - type: 'number', - aggregatable: true, - searchable: true, - }, - { - name: 'source', - displayName: 'source', - type: 'string', - aggregatable: true, - searchable: true, - }, - ], + fields, + getFieldByName: getFieldByNameFactory(fields), }, }; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/pure_helpers.ts b/x-pack/plugins/lens/public/indexpattern_datasource/pure_helpers.ts index 9e81b5e0c5bf9..c5da3d0c5dcde 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/pure_helpers.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/pure_helpers.ts @@ -4,7 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { IndexPatternPrivateState } from './types'; +import { keyBy } from 'lodash'; +import { IndexPatternField, IndexPatternPrivateState } from './types'; export function fieldExists( existingFields: IndexPatternPrivateState['existingFields'], @@ -13,3 +14,8 @@ export function fieldExists( ) { return existingFields[indexPatternTitle] && existingFields[indexPatternTitle][fieldName]; } + +export function getFieldByNameFactory(newFields: IndexPatternField[]) { + const fieldsLookup = keyBy(newFields, 'name'); + return (name: string) => fieldsLookup[name]; +} diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/state_helpers.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/state_helpers.test.ts index da90a2ce5fcec..45008b2d9439a 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/state_helpers.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/state_helpers.test.ts @@ -16,6 +16,7 @@ import { TermsIndexPatternColumn } from './operations/definitions/terms'; import { DateHistogramIndexPatternColumn } from './operations/definitions/date_histogram'; import { AvgIndexPatternColumn } from './operations/definitions/metrics'; import { IndexPattern, IndexPatternPrivateState, IndexPatternLayer } from './types'; +import { getFieldByNameFactory } from './pure_helpers'; jest.mock('./operations'); @@ -585,59 +586,61 @@ describe('state_helpers', () => { }); describe('updateLayerIndexPattern', () => { - const indexPattern: IndexPattern = { - id: 'test', - title: '', - hasRestrictions: true, - fields: [ - { - name: 'fieldA', - displayName: 'fieldA', - aggregatable: true, - searchable: true, - type: 'string', - }, - { - name: 'fieldB', - displayName: 'fieldB', - aggregatable: true, - searchable: true, - type: 'number', - aggregationRestrictions: { - avg: { - agg: 'avg', - }, + const fields = [ + { + name: 'fieldA', + displayName: 'fieldA', + aggregatable: true, + searchable: true, + type: 'string', + }, + { + name: 'fieldB', + displayName: 'fieldB', + aggregatable: true, + searchable: true, + type: 'number', + aggregationRestrictions: { + avg: { + agg: 'avg', }, }, - { - name: 'fieldC', - displayName: 'fieldC', - aggregatable: false, - searchable: true, - type: 'date', - }, - { - name: 'fieldD', - displayName: 'fieldD', - aggregatable: true, - searchable: true, - type: 'date', - aggregationRestrictions: { - date_histogram: { - agg: 'date_histogram', - time_zone: 'CET', - calendar_interval: 'w', - }, + }, + { + name: 'fieldC', + displayName: 'fieldC', + aggregatable: false, + searchable: true, + type: 'date', + }, + { + name: 'fieldD', + displayName: 'fieldD', + aggregatable: true, + searchable: true, + type: 'date', + aggregationRestrictions: { + date_histogram: { + agg: 'date_histogram', + time_zone: 'CET', + calendar_interval: 'w', }, }, - { - name: 'fieldE', - displayName: 'fieldE', - aggregatable: true, - searchable: true, - type: 'date', - }, - ], + }, + { + name: 'fieldE', + displayName: 'fieldE', + aggregatable: true, + searchable: true, + type: 'date', + }, + ]; + const indexPattern: IndexPattern = { + id: 'test', + title: '', + hasRestrictions: true, + getFieldByName: getFieldByNameFactory(fields), + fields, }; it('should switch index pattern id in layer', () => { diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/types.ts b/x-pack/plugins/lens/public/indexpattern_datasource/types.ts index a3c0e8aed7421..1e6fc5a5806b5 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/types.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/types.ts @@ -11,6 +11,7 @@ import { IndexPatternAggRestrictions } from '../../../../../src/plugins/data/pub export interface IndexPattern { id: string; fields: IndexPatternField[]; + getFieldByName(name: string): IndexPatternField | undefined; title: string; timeFieldName?: string; fieldFormatMap?: Record< diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/utils.ts b/x-pack/plugins/lens/public/indexpattern_datasource/utils.ts index d3d65617f2253..d0ea81d135156 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/utils.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/utils.ts @@ -87,15 +87,15 @@ export function fieldIsInvalid( indexPattern: IndexPattern ) { const operationDefinition = operationType && operationDefinitionMap[operationType]; + const field = sourceField ? indexPattern.getFieldByName(sourceField) : undefined; return Boolean( sourceField && operationDefinition && - !indexPattern.fields.some( - (field) => - field.name === sourceField && - operationDefinition?.input === 'field' && - operationDefinition.getPossibleOperationForField(field) !== undefined + !( + field && + operationDefinition?.input === 'field' && + operationDefinition.getPossibleOperationForField(field) !== undefined ) ); } From dc489e48a4942a43a860f44d8a21f54aad210fc4 Mon Sep 17 00:00:00 2001 From: Maja Grubic Date: Tue, 10 Nov 2020 14:14:25 +0000 Subject: [PATCH 16/80] [Discover] Add metric on adding filter (#82961) --- src/plugins/discover/public/application/angular/discover.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/plugins/discover/public/application/angular/discover.js b/src/plugins/discover/public/application/angular/discover.js index 389eda90e00a1..af763240bccfd 100644 --- a/src/plugins/discover/public/application/angular/discover.js +++ b/src/plugins/discover/public/application/angular/discover.js @@ -65,6 +65,7 @@ const { timefilter, toastNotifications, uiSettings: config, + trackUiMetric, } = getServices(); import { getRootBreadcrumbs, getSavedSearchBreadcrumbs } from '../helpers/breadcrumbs'; @@ -81,6 +82,7 @@ import { DOC_HIDE_TIME_COLUMN_SETTING, MODIFY_COLUMNS_ON_SWITCH, } from '../../../common'; +import { METRIC_TYPE } from '@kbn/analytics'; const fetchStatuses = { UNINITIALIZED: 'uninitialized', @@ -990,6 +992,9 @@ function discoverController($element, $route, $scope, $timeout, $window, Promise operation, $scope.indexPattern.id ); + if (trackUiMetric) { + trackUiMetric(METRIC_TYPE.CLICK, 'filter_added'); + } return filterManager.addFilters(newFilters); }; From b2d6b66fe505b5af504073d448ed4b84785fdb39 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Tue, 10 Nov 2020 17:15:26 +0300 Subject: [PATCH 17/80] [bundle optimization] fix imports of react-use lib (#82847) * [bundle optimization] fix imports of react-use lib * add 2 more files * add rule into eslintrc.js Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .eslintrc.js | 4 ++++ .../home/public/application/components/home_app.js | 2 +- .../public/components/controls/date_ranges.tsx | 2 +- .../public/components/controls/field.tsx | 2 +- .../public/components/controls/filters.tsx | 2 +- .../public/components/controls/order_by.tsx | 2 +- .../public/components/controls/radius_ratio_option.tsx | 2 +- .../public/components/controls/sub_metric.tsx | 2 +- .../public/components/sidebar/controls.tsx | 2 +- .../application/components/visualize_listing.tsx | 4 +++- .../URLFilter/URLSearch/SelectableUrlList.tsx | 2 +- .../components/app/ServiceMap/useRefDimensions.ts | 2 +- .../plugins/fleet/public/applications/fleet/index.tsx | 2 +- .../expression_editor/criterion_preview_chart.tsx | 2 +- .../components/expression_editor/editor.tsx | 2 +- .../infra/public/components/log_stream/index.tsx | 2 +- .../setup_flyout/log_entry_categories_setup_view.tsx | 2 +- .../logs/log_analysis/log_analysis_setup_state.ts | 2 +- .../use_log_entry_categories_quality.ts | 2 +- .../infra/public/containers/logs/log_entries/index.ts | 2 +- .../containers/logs/log_highlights/log_highlights.tsx | 2 +- .../containers/logs/log_position/log_position_state.ts | 2 +- .../public/containers/logs/log_source/log_source.ts | 2 +- .../public/containers/logs/log_summary/with_summary.ts | 2 +- x-pack/plugins/infra/public/hooks/use_kibana_space.ts | 2 +- .../infra/public/hooks/use_kibana_timefilter_time.tsx | 5 ++++- .../public/pages/link_to/redirect_to_node_logs.tsx | 2 +- .../sections/top_categories/top_categories_table.tsx | 2 +- .../log_entry_rate/sections/anomalies/expanded_row.tsx | 2 +- .../logs/log_entry_rate/sections/anomalies/table.tsx | 2 +- .../log_entry_rate/use_log_entry_anomalies_results.ts | 2 +- .../plugins/infra/public/pages/logs/page_content.tsx | 2 +- .../pages/metrics/inventory_view/components/layout.tsx | 2 +- .../plugins/infra/public/utils/use_tracked_promise.ts | 2 +- .../operations/definitions/filters/filter_popover.tsx | 2 +- .../operations/definitions/ranges/advanced_editor.tsx | 2 +- .../operations/definitions/ranges/range_editor.tsx | 2 +- .../definitions/shared_components/label_input.tsx | 2 +- .../definitions/terms/values_range_input.test.tsx | 4 +--- .../definitions/terms/values_range_input.tsx | 2 +- .../plugins/lens/public/pie_visualization/toolbar.tsx | 2 +- .../logstash/public/application/pipeline_edit_view.tsx | 2 +- .../public/common/mock/endpoint/app_root_provider.tsx | 2 +- .../components/aggregation_list/popover_form.tsx | 2 +- .../common/filter_agg/components/filter_agg_form.tsx | 2 +- .../common/filter_agg/components/filter_term_form.tsx | 2 +- .../__tests__/step_screenshot_display.test.tsx | 10 ++++------ .../monitor/synthetics/step_screenshot_display.tsx | 2 +- 48 files changed, 59 insertions(+), 54 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 5c2a2817eae53..561e9bc55bf9d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -640,6 +640,10 @@ module.exports = { name: 'lodash/fp/assocPath', message: 'Please use @elastic/safer-lodash-set instead', }, + { + name: 'react-use', + message: 'Please use react-use/lib/{method} instead.', + }, ], }, ], diff --git a/src/plugins/home/public/application/components/home_app.js b/src/plugins/home/public/application/components/home_app.js index 7fe4f4351c35b..734100fe584ab 100644 --- a/src/plugins/home/public/application/components/home_app.js +++ b/src/plugins/home/public/application/components/home_app.js @@ -28,7 +28,7 @@ import { HashRouter as Router, Switch, Route } from 'react-router-dom'; import { getTutorial } from '../load_tutorials'; import { replaceTemplateStrings } from './tutorial/replace_template_strings'; import { getServices } from '../kibana_services'; -import { useMount } from 'react-use'; +import useMount from 'react-use/lib/useMount'; const RedirectToDefaultApp = () => { useMount(() => { diff --git a/src/plugins/vis_default_editor/public/components/controls/date_ranges.tsx b/src/plugins/vis_default_editor/public/components/controls/date_ranges.tsx index 785ef1b83a23d..90ee1dd4f02ae 100644 --- a/src/plugins/vis_default_editor/public/components/controls/date_ranges.tsx +++ b/src/plugins/vis_default_editor/public/components/controls/date_ranges.tsx @@ -36,7 +36,7 @@ import dateMath from '@elastic/datemath'; import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; import { isEqual, omit } from 'lodash'; -import { useMount } from 'react-use'; +import useMount from 'react-use/lib/useMount'; import { DocLinksStart } from 'src/core/public'; import { useKibana } from '../../../../kibana_react/public'; diff --git a/src/plugins/vis_default_editor/public/components/controls/field.tsx b/src/plugins/vis_default_editor/public/components/controls/field.tsx index 9529adfe12720..cb6e9d9aa7ba8 100644 --- a/src/plugins/vis_default_editor/public/components/controls/field.tsx +++ b/src/plugins/vis_default_editor/public/components/controls/field.tsx @@ -19,7 +19,7 @@ import { get } from 'lodash'; import React, { useState, useCallback } from 'react'; -import { useMount } from 'react-use'; +import useMount from 'react-use/lib/useMount'; import { EuiComboBox, EuiComboBoxOptionOption, EuiFormRow } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; diff --git a/src/plugins/vis_default_editor/public/components/controls/filters.tsx b/src/plugins/vis_default_editor/public/components/controls/filters.tsx index b2e6373edfc10..4c5181ab316d1 100644 --- a/src/plugins/vis_default_editor/public/components/controls/filters.tsx +++ b/src/plugins/vis_default_editor/public/components/controls/filters.tsx @@ -21,7 +21,7 @@ import React, { useState, useEffect } from 'react'; import { omit, isEqual } from 'lodash'; import { htmlIdGenerator, EuiButton, EuiSpacer } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import { useMount } from 'react-use'; +import useMount from 'react-use/lib/useMount'; import { Query, DataPublicPluginStart } from '../../../../data/public'; import { IUiSettingsClient } from '../../../../../core/public'; diff --git a/src/plugins/vis_default_editor/public/components/controls/order_by.tsx b/src/plugins/vis_default_editor/public/components/controls/order_by.tsx index 16aeafaab253b..000719318f107 100644 --- a/src/plugins/vis_default_editor/public/components/controls/order_by.tsx +++ b/src/plugins/vis_default_editor/public/components/controls/order_by.tsx @@ -20,7 +20,7 @@ import React from 'react'; import { EuiFormRow, EuiSelect } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { useMount } from 'react-use'; +import useMount from 'react-use/lib/useMount'; import { isCompatibleAggregation, diff --git a/src/plugins/vis_default_editor/public/components/controls/radius_ratio_option.tsx b/src/plugins/vis_default_editor/public/components/controls/radius_ratio_option.tsx index c2c21e7c1a058..00e6b6da88b05 100644 --- a/src/plugins/vis_default_editor/public/components/controls/radius_ratio_option.tsx +++ b/src/plugins/vis_default_editor/public/components/controls/radius_ratio_option.tsx @@ -21,7 +21,7 @@ import React, { useCallback } from 'react'; import { EuiFormRow, EuiIconTip, EuiRange, EuiSpacer } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { useMount } from 'react-use'; +import useMount from 'react-use/lib/useMount'; import { AggControlProps } from './agg_control_props'; diff --git a/src/plugins/vis_default_editor/public/components/controls/sub_metric.tsx b/src/plugins/vis_default_editor/public/components/controls/sub_metric.tsx index fc79ba703c2b4..4b0637edf4055 100644 --- a/src/plugins/vis_default_editor/public/components/controls/sub_metric.tsx +++ b/src/plugins/vis_default_editor/public/components/controls/sub_metric.tsx @@ -20,7 +20,7 @@ import React from 'react'; import { EuiFormLabel, EuiSpacer } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { useMount } from 'react-use'; +import useMount from 'react-use/lib/useMount'; import { AggParamType, IAggConfig, AggGroupNames } from '../../../../data/public'; import { useSubAggParamsHandlers } from './utils'; diff --git a/src/plugins/vis_default_editor/public/components/sidebar/controls.tsx b/src/plugins/vis_default_editor/public/components/sidebar/controls.tsx index df9818b237962..388ac39f06475 100644 --- a/src/plugins/vis_default_editor/public/components/sidebar/controls.tsx +++ b/src/plugins/vis_default_editor/public/components/sidebar/controls.tsx @@ -21,7 +21,7 @@ import React, { useCallback, useState } from 'react'; import { EuiFlexGroup, EuiFlexItem, EuiButton, EuiButtonEmpty, EuiToolTip } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; -import { useDebounce } from 'react-use'; +import useDebounce from 'react-use/lib/useDebounce'; import { Vis } from 'src/plugins/visualizations/public'; import { discardChanges, EditorAction } from './state'; diff --git a/src/plugins/visualize/public/application/components/visualize_listing.tsx b/src/plugins/visualize/public/application/components/visualize_listing.tsx index 2edabbf46f9d8..718bd2ed343ce 100644 --- a/src/plugins/visualize/public/application/components/visualize_listing.tsx +++ b/src/plugins/visualize/public/application/components/visualize_listing.tsx @@ -21,7 +21,9 @@ import './visualize_listing.scss'; import React, { useCallback, useRef, useMemo, useEffect } from 'react'; import { i18n } from '@kbn/i18n'; -import { useUnmount, useMount } from 'react-use'; +import useUnmount from 'react-use/lib/useUnmount'; +import useMount from 'react-use/lib/useMount'; + import { useLocation } from 'react-router-dom'; import { SavedObjectsFindOptionsReference } from '../../../../../core/public'; diff --git a/x-pack/plugins/apm/public/components/app/RumDashboard/URLFilter/URLSearch/SelectableUrlList.tsx b/x-pack/plugins/apm/public/components/app/RumDashboard/URLFilter/URLSearch/SelectableUrlList.tsx index 7bd9b2c87814b..1d314e3a0e0d3 100644 --- a/x-pack/plugins/apm/public/components/app/RumDashboard/URLFilter/URLSearch/SelectableUrlList.tsx +++ b/x-pack/plugins/apm/public/components/app/RumDashboard/URLFilter/URLSearch/SelectableUrlList.tsx @@ -31,7 +31,7 @@ import { i18n } from '@kbn/i18n'; import styled from 'styled-components'; import euiLightVars from '@elastic/eui/dist/eui_theme_light.json'; import euiDarkVars from '@elastic/eui/dist/eui_theme_dark.json'; -import { useEvent } from 'react-use'; +import useEvent from 'react-use/lib/useEvent'; import { formatOptions, selectableRenderOptions, diff --git a/x-pack/plugins/apm/public/components/app/ServiceMap/useRefDimensions.ts b/x-pack/plugins/apm/public/components/app/ServiceMap/useRefDimensions.ts index c8639b334f66a..fc478e27ccac3 100644 --- a/x-pack/plugins/apm/public/components/app/ServiceMap/useRefDimensions.ts +++ b/x-pack/plugins/apm/public/components/app/ServiceMap/useRefDimensions.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ import { useRef } from 'react'; -import { useWindowSize } from 'react-use'; +import useWindowSize from 'react-use/lib/useWindowSize'; export function useRefDimensions() { const ref = useRef(null); diff --git a/x-pack/plugins/fleet/public/applications/fleet/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/index.tsx index 03cc4a8b7aff7..a49306f8e8d55 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/index.tsx @@ -5,7 +5,7 @@ */ import React, { memo, useEffect, useState } from 'react'; import ReactDOM from 'react-dom'; -import { useObservable } from 'react-use'; +import useObservable from 'react-use/lib/useObservable'; import { HashRouter as Router, Redirect, Switch, Route, RouteProps } from 'react-router-dom'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; diff --git a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/criterion_preview_chart.tsx b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/criterion_preview_chart.tsx index 478d4b879a7e1..1d23b4d4778ca 100644 --- a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/criterion_preview_chart.tsx +++ b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/criterion_preview_chart.tsx @@ -5,7 +5,7 @@ */ import React, { useMemo } from 'react'; -import { useDebounce } from 'react-use'; +import useDebounce from 'react-use/lib/useDebounce'; import { ScaleType, AnnotationDomainTypes, diff --git a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx index c5b0ed5844852..48639f3095d3d 100644 --- a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx +++ b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx @@ -7,7 +7,7 @@ import React, { useCallback, useMemo, useState } from 'react'; import { i18n } from '@kbn/i18n'; import { EuiLoadingSpinner, EuiSpacer, EuiButton, EuiCallOut } from '@elastic/eui'; -import { useMount } from 'react-use'; +import useMount from 'react-use/lib/useMount'; import { GroupByExpression } from '../../../common/group_by_expression/group_by_expression'; import { ForLastExpression, diff --git a/x-pack/plugins/infra/public/components/log_stream/index.tsx b/x-pack/plugins/infra/public/components/log_stream/index.tsx index f9bfbf9564798..6698018e8cc19 100644 --- a/x-pack/plugins/infra/public/components/log_stream/index.tsx +++ b/x-pack/plugins/infra/public/components/log_stream/index.tsx @@ -6,7 +6,7 @@ import React, { useMemo } from 'react'; import { noop } from 'lodash'; -import { useMount } from 'react-use'; +import useMount from 'react-use/lib/useMount'; import { euiStyled } from '../../../../observability/public'; import { LogEntriesCursor } from '../../../common/http_api'; diff --git a/x-pack/plugins/infra/public/components/logging/log_analysis_setup/setup_flyout/log_entry_categories_setup_view.tsx b/x-pack/plugins/infra/public/components/logging/log_analysis_setup/setup_flyout/log_entry_categories_setup_view.tsx index e7961a11a4d52..5ff15012ad245 100644 --- a/x-pack/plugins/infra/public/components/logging/log_analysis_setup/setup_flyout/log_entry_categories_setup_view.tsx +++ b/x-pack/plugins/infra/public/components/logging/log_analysis_setup/setup_flyout/log_entry_categories_setup_view.tsx @@ -6,7 +6,7 @@ import { EuiSpacer, EuiSteps, EuiText, EuiTitle } from '@elastic/eui'; import React, { useCallback, useMemo } from 'react'; -import { useMount } from 'react-use'; +import useMount from 'react-use/lib/useMount'; import { useLogEntryCategoriesSetup } from '../../../../containers/logs/log_analysis/modules/log_entry_categories'; import { createInitialConfigurationStep } from '../initial_configuration_step'; import { createProcessStep } from '../process_step'; diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_setup_state.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_setup_state.ts index 750a7104a3a98..821d0373d316a 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_setup_state.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_setup_state.ts @@ -6,7 +6,7 @@ import { isEqual } from 'lodash'; import { useCallback, useEffect, useMemo, useState } from 'react'; -import { usePrevious } from 'react-use'; +import usePrevious from 'react-use/lib/usePrevious'; import { combineDatasetFilters, DatasetFilter, diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_quality.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_quality.ts index 6bad94ec49f87..c490f7d74fc9d 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_quality.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/modules/log_entry_categories/use_log_entry_categories_quality.ts @@ -5,7 +5,7 @@ */ import { useMemo, useState } from 'react'; -import { useDeepCompareEffect } from 'react-use'; +import useDeepCompareEffect from 'react-use/lib/useDeepCompareEffect'; import { CategoryQualityWarningReason, QualityWarning, diff --git a/x-pack/plugins/infra/public/containers/logs/log_entries/index.ts b/x-pack/plugins/infra/public/containers/logs/log_entries/index.ts index 214bb16b24283..146746af980c9 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_entries/index.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_entries/index.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ import { useEffect, useState, useReducer, useCallback } from 'react'; -import { useMountedState } from 'react-use'; +import useMountedState from 'react-use/lib/useMountedState'; import createContainer from 'constate'; import { pick, throttle } from 'lodash'; import { TimeKey, timeKeyIsBetween } from '../../../../common/time'; diff --git a/x-pack/plugins/infra/public/containers/logs/log_highlights/log_highlights.tsx b/x-pack/plugins/infra/public/containers/logs/log_highlights/log_highlights.tsx index 941e89848131b..3081e37da1d37 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_highlights/log_highlights.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_highlights/log_highlights.tsx @@ -6,7 +6,7 @@ import createContainer from 'constate'; import { useState, useContext } from 'react'; -import { useThrottle } from 'react-use'; +import useThrottle from 'react-use/lib/useThrottle'; import { useLogEntryHighlights } from './log_entry_highlights'; import { useLogSummaryHighlights } from './log_summary_highlights'; import { useNextAndPrevious } from './next_and_previous'; diff --git a/x-pack/plugins/infra/public/containers/logs/log_position/log_position_state.ts b/x-pack/plugins/infra/public/containers/logs/log_position/log_position_state.ts index 4b110fbc4e51e..f1aed0fa75165 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_position/log_position_state.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_position/log_position_state.ts @@ -6,7 +6,7 @@ import { useState, useMemo, useEffect, useCallback } from 'react'; import createContainer from 'constate'; -import { useSetState } from 'react-use'; +import useSetState from 'react-use/lib/useSetState'; import { TimeKey } from '../../../../common/time'; import { datemathToEpochMillis, isValidDatemath } from '../../../utils/datemath'; import { useKibanaTimefilterTime } from '../../../hooks/use_kibana_timefilter_time'; diff --git a/x-pack/plugins/infra/public/containers/logs/log_source/log_source.ts b/x-pack/plugins/infra/public/containers/logs/log_source/log_source.ts index e2dd4c523c03f..75c328b829397 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_source/log_source.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_source/log_source.ts @@ -6,7 +6,7 @@ import createContainer from 'constate'; import { useCallback, useMemo, useState } from 'react'; -import { useMountedState } from 'react-use'; +import useMountedState from 'react-use/lib/useMountedState'; import type { HttpHandler } from 'src/core/public'; import { LogSourceConfiguration, diff --git a/x-pack/plugins/infra/public/containers/logs/log_summary/with_summary.ts b/x-pack/plugins/infra/public/containers/logs/log_summary/with_summary.ts index 625a1ead4d930..1a420d7dddf91 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_summary/with_summary.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_summary/with_summary.ts @@ -5,7 +5,7 @@ */ import { useContext } from 'react'; -import { useThrottle } from 'react-use'; +import useThrottle from 'react-use/lib/useThrottle'; import { RendererFunction } from '../../../utils/typed_react'; import { LogSummaryBuckets, useLogSummary } from './log_summary'; diff --git a/x-pack/plugins/infra/public/hooks/use_kibana_space.ts b/x-pack/plugins/infra/public/hooks/use_kibana_space.ts index 1c06263008961..39caa4f063cd5 100644 --- a/x-pack/plugins/infra/public/hooks/use_kibana_space.ts +++ b/x-pack/plugins/infra/public/hooks/use_kibana_space.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { useAsync } from 'react-use'; +import useAsync from 'react-use/lib/useAsync'; import { useKibanaContextForPlugin } from '../hooks/use_kibana'; import type { Space } from '../../../spaces/public'; diff --git a/x-pack/plugins/infra/public/hooks/use_kibana_timefilter_time.tsx b/x-pack/plugins/infra/public/hooks/use_kibana_timefilter_time.tsx index e9537370f12cd..193a285c6b882 100644 --- a/x-pack/plugins/infra/public/hooks/use_kibana_timefilter_time.tsx +++ b/x-pack/plugins/infra/public/hooks/use_kibana_timefilter_time.tsx @@ -5,7 +5,10 @@ */ import { useCallback } from 'react'; -import { useUpdateEffect, useMount } from 'react-use'; + +import useUpdateEffect from 'react-use/lib/useUpdateEffect'; +import useMount from 'react-use/lib/useMount'; + import { useKibanaContextForPlugin } from './use_kibana'; import { TimeRange, TimefilterContract } from '../../../../../src/plugins/data/public'; diff --git a/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.tsx b/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.tsx index 0541b811508ee..6205d9883e535 100644 --- a/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.tsx +++ b/x-pack/plugins/infra/public/pages/link_to/redirect_to_node_logs.tsx @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n'; import flowRight from 'lodash/flowRight'; import React from 'react'; import { Redirect, RouteComponentProps } from 'react-router-dom'; -import { useMount } from 'react-use'; +import useMount from 'react-use/lib/useMount'; import { HttpStart } from 'src/core/public'; import { useKibana } from '../../../../../../src/plugins/kibana_react/public'; import { findInventoryFields } from '../../../common/inventory_models'; diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/sections/top_categories/top_categories_table.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/sections/top_categories/top_categories_table.tsx index 4fd8aa3cdc1dd..ab4195492a706 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/sections/top_categories/top_categories_table.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/sections/top_categories/top_categories_table.tsx @@ -8,7 +8,7 @@ import { EuiBasicTable, EuiBasicTableColumn } from '@elastic/eui'; import numeral from '@elastic/numeral'; import { i18n } from '@kbn/i18n'; import React, { useMemo } from 'react'; -import { useSet } from 'react-use'; +import useSet from 'react-use/lib/useSet'; import { euiStyled } from '../../../../../../../observability/public'; import { diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/expanded_row.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/expanded_row.tsx index 84ef13cc70706..9c78c421af752 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/expanded_row.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/expanded_row.tsx @@ -8,7 +8,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiStat, EuiTitle } from '@elastic/eui'; import numeral from '@elastic/numeral'; import { i18n } from '@kbn/i18n'; import React from 'react'; -import { useMount } from 'react-use'; +import useMount from 'react-use/lib/useMount'; import { euiStyled } from '../../../../../../../observability/public'; import { LogEntryAnomaly } from '../../../../../../common/http_api'; import { TimeRange } from '../../../../../../common/http_api/shared/time_range'; diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/table.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/table.tsx index e0a3b6fb91db0..855113d66f510 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/table.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/table.tsx @@ -17,7 +17,7 @@ import { RIGHT_ALIGNMENT } from '@elastic/eui/lib/services'; import moment from 'moment'; import { i18n } from '@kbn/i18n'; import React, { useCallback, useMemo } from 'react'; -import { useSet } from 'react-use'; +import useSet from 'react-use/lib/useSet'; import { TimeRange } from '../../../../../../common/http_api/shared/time_range'; import { formatAnomalyScore, diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_anomalies_results.ts b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_anomalies_results.ts index 37c99272f0872..e626e7477f2c0 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_anomalies_results.ts +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_anomalies_results.ts @@ -5,7 +5,7 @@ */ import { useMemo, useState, useCallback, useEffect, useReducer } from 'react'; -import { useMount } from 'react-use'; +import useMount from 'react-use/lib/useMount'; import { useTrackedPromise, CanceledPromiseError } from '../../../utils/use_tracked_promise'; import { callGetLogEntryAnomaliesAPI } from './service_calls/get_log_entry_anomalies'; import { callGetLogEntryAnomaliesDatasetsAPI } from './service_calls/get_log_entry_anomalies_datasets'; diff --git a/x-pack/plugins/infra/public/pages/logs/page_content.tsx b/x-pack/plugins/infra/public/pages/logs/page_content.tsx index e85f0d9bf446b..10189c0d8076c 100644 --- a/x-pack/plugins/infra/public/pages/logs/page_content.tsx +++ b/x-pack/plugins/infra/public/pages/logs/page_content.tsx @@ -8,7 +8,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiButtonEmpty } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React from 'react'; import { Route, Switch } from 'react-router-dom'; -import { useMount } from 'react-use'; +import useMount from 'react-use/lib/useMount'; import { AlertDropdown } from '../../alerting/log_threshold'; import { useKibana } from '../../../../../../src/plugins/kibana_react/public'; diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/layout.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/layout.tsx index b9caef704d071..f6e9d45c4d225 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/layout.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/layout.tsx @@ -5,7 +5,7 @@ */ import React, { useCallback, useEffect } from 'react'; -import { useInterval } from 'react-use'; +import useInterval from 'react-use/lib/useInterval'; import { EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui'; import { AutoSizer } from '../../../../components/auto_sizer'; diff --git a/x-pack/plugins/infra/public/utils/use_tracked_promise.ts b/x-pack/plugins/infra/public/utils/use_tracked_promise.ts index 42518127f68bf..75c9d1bacc675 100644 --- a/x-pack/plugins/infra/public/utils/use_tracked_promise.ts +++ b/x-pack/plugins/infra/public/utils/use_tracked_promise.ts @@ -7,7 +7,7 @@ /* eslint-disable max-classes-per-file */ import { DependencyList, useEffect, useMemo, useRef, useState, useCallback } from 'react'; -import { useMountedState } from 'react-use'; +import useMountedState from 'react-use/lib/useMountedState'; interface UseTrackedPromiseArgs { createPromise: (...args: Arguments) => Promise; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filter_popover.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filter_popover.tsx index 077e07a89f788..b023a9a5a3ec5 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filter_popover.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filter_popover.tsx @@ -6,7 +6,7 @@ import './filter_popover.scss'; import React, { MouseEventHandler, useState } from 'react'; -import { useDebounce } from 'react-use'; +import useDebounce from 'react-use/lib/useDebounce'; import { EuiPopover, EuiSpacer } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FilterValue, defaultLabel, isQueryValid } from '.'; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/advanced_editor.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/advanced_editor.tsx index c6773e806aef8..2eb971aa03c55 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/advanced_editor.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/advanced_editor.tsx @@ -8,7 +8,7 @@ import './advanced_editor.scss'; import React, { useState, MouseEventHandler } from 'react'; import { i18n } from '@kbn/i18n'; -import { useDebounce } from 'react-use'; +import useDebounce from 'react-use/lib/useDebounce'; import { EuiFlexGroup, EuiFlexItem, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/range_editor.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/range_editor.tsx index 8ed17a813e7fd..a18c47f9dedd1 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/range_editor.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/range_editor.tsx @@ -6,7 +6,7 @@ import React, { useEffect, useState } from 'react'; import { i18n } from '@kbn/i18n'; -import { useDebounce } from 'react-use'; +import useDebounce from 'react-use/lib/useDebounce'; import { EuiButtonEmpty, EuiFormRow, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/shared_components/label_input.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/shared_components/label_input.tsx index 09a98d9e48ef7..f0ee30bb4331b 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/shared_components/label_input.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/shared_components/label_input.tsx @@ -5,7 +5,7 @@ */ import React, { useState, useEffect } from 'react'; -import { useDebounce } from 'react-use'; +import useDebounce from 'react-use/lib/useDebounce'; import { EuiFieldText, keys } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/values_range_input.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/values_range_input.test.tsx index c1620dd316a60..18b9b5b1e8b98 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/values_range_input.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/values_range_input.test.tsx @@ -10,9 +10,7 @@ import { shallow } from 'enzyme'; import { EuiRange } from '@elastic/eui'; import { ValuesRangeInput } from './values_range_input'; -jest.mock('react-use', () => ({ - useDebounce: (fn: () => void) => fn(), -})); +jest.mock('react-use/lib/useDebounce', () => (fn: () => void) => fn()); describe('ValuesRangeInput', () => { it('should render EuiRange correctly', () => { diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/values_range_input.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/values_range_input.tsx index 6bfde4b652571..ef42f2d4a7175 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/values_range_input.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/values_range_input.tsx @@ -5,7 +5,7 @@ */ import React, { useState } from 'react'; -import { useDebounce } from 'react-use'; +import useDebounce from 'react-use/lib/useDebounce'; import { i18n } from '@kbn/i18n'; import { EuiRange } from '@elastic/eui'; diff --git a/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx b/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx index d69164de8a6aa..f1eb4ccdd9cf7 100644 --- a/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx +++ b/x-pack/plugins/lens/public/pie_visualization/toolbar.tsx @@ -6,7 +6,7 @@ import './toolbar.scss'; import React, { useState } from 'react'; -import { useDebounce } from 'react-use'; +import useDebounce from 'react-use/lib/useDebounce'; import { i18n } from '@kbn/i18n'; import { EuiFlexGroup, diff --git a/x-pack/plugins/logstash/public/application/pipeline_edit_view.tsx b/x-pack/plugins/logstash/public/application/pipeline_edit_view.tsx index 9b291e5261033..a36ef394f3327 100644 --- a/x-pack/plugins/logstash/public/application/pipeline_edit_view.tsx +++ b/x-pack/plugins/logstash/public/application/pipeline_edit_view.tsx @@ -5,7 +5,7 @@ */ import React, { useState, useLayoutEffect, useCallback } from 'react'; -import { usePromise } from 'react-use'; +import usePromise from 'react-use/lib/usePromise'; import { History } from 'history'; import { i18n } from '@kbn/i18n'; diff --git a/x-pack/plugins/security_solution/public/common/mock/endpoint/app_root_provider.tsx b/x-pack/plugins/security_solution/public/common/mock/endpoint/app_root_provider.tsx index 3b7262e8a8d7e..fd6a483e538b8 100644 --- a/x-pack/plugins/security_solution/public/common/mock/endpoint/app_root_provider.tsx +++ b/x-pack/plugins/security_solution/public/common/mock/endpoint/app_root_provider.tsx @@ -9,7 +9,7 @@ import { Provider } from 'react-redux'; import { I18nProvider } from '@kbn/i18n/react'; import { Router } from 'react-router-dom'; import { History } from 'history'; -import { useObservable } from 'react-use'; +import useObservable from 'react-use/lib/useObservable'; import { Store } from 'redux'; import { EuiThemeProvider } from '../../../../../xpack_legacy/common'; import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public'; diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/popover_form.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/popover_form.tsx index 30e8c2b594db7..dbdff6c6b311e 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/popover_form.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/aggregation_list/popover_form.tsx @@ -19,7 +19,7 @@ import { } from '@elastic/eui'; import { cloneDeep } from 'lodash'; -import { useUpdateEffect } from 'react-use'; +import useUpdateEffect from 'react-use/lib/useUpdateEffect'; import { AggName } from '../../../../../../common/types/aggregations'; import { dictionaryToArray } from '../../../../../../common/types/common'; import { diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/common/filter_agg/components/filter_agg_form.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/common/filter_agg/components/filter_agg_form.tsx index ac6e93d3ed5eb..4e45ec7689235 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/common/filter_agg/components/filter_agg_form.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/common/filter_agg/components/filter_agg_form.tsx @@ -7,7 +7,7 @@ import React, { useContext, useMemo } from 'react'; import { EuiFormRow, EuiSelect } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import { useUpdateEffect } from 'react-use'; +import useUpdateEffect from 'react-use/lib/useUpdateEffect'; import { CreateTransformWizardContext } from '../../../../wizard/wizard'; import { commonFilterAggs, filterAggsFieldSupport } from '../constants'; import { IndexPattern } from '../../../../../../../../../../../../src/plugins/data/public'; diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/common/filter_agg/components/filter_term_form.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/common/filter_agg/components/filter_term_form.tsx index d59f99192621c..f9f345610e1eb 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/common/filter_agg/components/filter_term_form.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/common/filter_agg/components/filter_term_form.tsx @@ -8,7 +8,7 @@ import React, { useCallback, useContext, useEffect, useState } from 'react'; import { EuiComboBox, EuiFormRow } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { debounce } from 'lodash'; -import { useUpdateEffect } from 'react-use'; +import useUpdateEffect from 'react-use/lib/useUpdateEffect'; import { i18n } from '@kbn/i18n'; import { isEsSearchResponse } from '../../../../../../../../../common/api_schemas/type_guards'; import { useApi } from '../../../../../../../hooks'; diff --git a/x-pack/plugins/uptime/public/components/monitor/synthetics/__tests__/step_screenshot_display.test.tsx b/x-pack/plugins/uptime/public/components/monitor/synthetics/__tests__/step_screenshot_display.test.tsx index 16db430dbd73a..9d94514aa48c5 100644 --- a/x-pack/plugins/uptime/public/components/monitor/synthetics/__tests__/step_screenshot_display.test.tsx +++ b/x-pack/plugins/uptime/public/components/monitor/synthetics/__tests__/step_screenshot_display.test.tsx @@ -6,15 +6,13 @@ import { shallowWithIntl, mountWithIntl } from 'test_utils/enzyme_helpers'; import React from 'react'; -import * as reactUse from 'react-use'; import { StepScreenshotDisplay } from '../step_screenshot_display'; -describe('StepScreenshotDisplayProps', () => { - // @ts-ignore missing fields don't matter in this test, the component in question only relies on `isIntersecting` - jest.spyOn(reactUse, 'useIntersection').mockImplementation(() => ({ - isIntersecting: true, - })); +jest.mock('react-use/lib/useIntersection', () => () => ({ + isIntersecting: true, +})); +describe('StepScreenshotDisplayProps', () => { it('displays screenshot thumbnail when present', () => { const wrapper = mountWithIntl( Date: Tue, 10 Nov 2020 15:16:58 +0100 Subject: [PATCH 18/80] migrate i18n mixin to KP (#81799) * migrate i18n mixin to KP * directly load the config from i18n service * add base tests * update telemetry schema * update legacy telemetry schema * fix server tests * use paths from config service instead of manually loading the plugin config * add tests for get_translation_paths * add tests for i18n service * add plugin service test * update generated doc * improve tsdoc --- ...ibana-plugin-core-server.coresetup.i18n.md | 13 +++ .../kibana-plugin-core-server.coresetup.md | 1 + ...-core-server.i18nservicesetup.getlocale.md | 17 ++++ ...er.i18nservicesetup.gettranslationfiles.md | 17 ++++ ...ana-plugin-core-server.i18nservicesetup.md | 20 +++++ .../core/server/kibana-plugin-core-server.md | 1 + .../environment/environment_service.mock.ts | 3 +- .../constants.ts => core/server/i18n/fs.ts} | 5 +- .../i18n/get_kibana_translation_files.test.ts | 81 +++++++++++++++++ .../i18n/get_kibana_translation_files.ts} | 29 +++--- .../i18n/get_translation_paths.test.mocks.ts | 26 ++++++ .../server/i18n/get_translation_paths.test.ts | 90 +++++++++++++++++++ .../server/i18n/get_translation_paths.ts | 12 +-- src/core/server/i18n/i18n_config.ts | 29 ++++++ src/core/server/i18n/i18n_service.mock.ts | 50 +++++++++++ .../server/i18n/i18n_service.test.mocks.ts | 28 ++++++ src/core/server/i18n/i18n_service.test.ts | 84 +++++++++++++++++ src/core/server/i18n/i18n_service.ts | 75 ++++++++++++++++ src/{legacy => core}/server/i18n/index.ts | 3 +- src/core/server/i18n/init_translations.ts | 31 +++++++ src/core/server/index.ts | 5 ++ src/core/server/internal_types.ts | 2 + src/core/server/legacy/legacy_service.test.ts | 2 + src/core/server/legacy/legacy_service.ts | 1 + .../server/metrics/metrics_service.mock.ts | 2 +- src/core/server/mocks.ts | 4 + src/core/server/plugins/plugin_context.ts | 1 + .../server/plugins/plugins_service.mock.ts | 2 +- .../server/plugins/plugins_service.test.ts | 18 ++++ src/core/server/plugins/plugins_service.ts | 1 + .../server/plugins/plugins_system.test.ts | 9 ++ src/core/server/plugins/plugins_system.ts | 4 + .../rendering/__mocks__/rendering_service.ts | 4 +- .../saved_objects_service.mock.ts | 3 +- src/core/server/server.api.md | 8 ++ src/core/server/server.test.mocks.ts | 6 ++ src/core/server/server.test.ts | 7 ++ src/core/server/server.ts | 15 +++- src/core/server/status/status_service.mock.ts | 2 +- .../ui_settings/ui_settings_service.mock.ts | 2 +- src/legacy/server/config/schema.js | 13 +-- .../i18n/get_kibana_translation_paths.test.ts | 58 ------------ src/legacy/server/i18n/i18n_mixin.ts | 63 ------------- src/legacy/server/kbn_server.js | 4 - .../server/__snapshots__/index.test.ts.snap | 2 + .../server/collectors/index.ts | 1 + .../localization/file_integrity.test.mocks.ts | 0 .../localization/file_integrity.test.ts | 0 .../localization/file_integrity.ts | 0 .../server/collectors}/localization/index.ts | 0 .../telemetry_localization_collector.test.ts | 0 .../telemetry_localization_collector.ts | 18 ++-- .../kibana_usage_collection/server/plugin.ts | 2 + .../telemetry/schema/legacy_plugins.json | 20 +---- src/plugins/telemetry/schema/oss_plugins.json | 17 ++++ 55 files changed, 709 insertions(+), 202 deletions(-) create mode 100644 docs/development/core/server/kibana-plugin-core-server.coresetup.i18n.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.i18nservicesetup.getlocale.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.i18nservicesetup.gettranslationfiles.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.i18nservicesetup.md rename src/{legacy/server/i18n/constants.ts => core/server/i18n/fs.ts} (88%) create mode 100644 src/core/server/i18n/get_kibana_translation_files.test.ts rename src/{legacy/server/i18n/get_kibana_translation_paths.ts => core/server/i18n/get_kibana_translation_files.ts} (64%) create mode 100644 src/core/server/i18n/get_translation_paths.test.mocks.ts create mode 100644 src/core/server/i18n/get_translation_paths.test.ts rename src/{legacy => core}/server/i18n/get_translation_paths.ts (85%) create mode 100644 src/core/server/i18n/i18n_config.ts create mode 100644 src/core/server/i18n/i18n_service.mock.ts create mode 100644 src/core/server/i18n/i18n_service.test.mocks.ts create mode 100644 src/core/server/i18n/i18n_service.test.ts create mode 100644 src/core/server/i18n/i18n_service.ts rename src/{legacy => core}/server/i18n/index.ts (86%) create mode 100644 src/core/server/i18n/init_translations.ts delete mode 100644 src/legacy/server/i18n/get_kibana_translation_paths.test.ts delete mode 100644 src/legacy/server/i18n/i18n_mixin.ts rename src/{legacy/server/i18n => plugins/kibana_usage_collection/server/collectors}/localization/file_integrity.test.mocks.ts (100%) rename src/{legacy/server/i18n => plugins/kibana_usage_collection/server/collectors}/localization/file_integrity.test.ts (100%) rename src/{legacy/server/i18n => plugins/kibana_usage_collection/server/collectors}/localization/file_integrity.ts (100%) rename src/{legacy/server/i18n => plugins/kibana_usage_collection/server/collectors}/localization/index.ts (100%) rename src/{legacy/server/i18n => plugins/kibana_usage_collection/server/collectors}/localization/telemetry_localization_collector.test.ts (100%) rename src/{legacy/server/i18n => plugins/kibana_usage_collection/server/collectors}/localization/telemetry_localization_collector.ts (82%) diff --git a/docs/development/core/server/kibana-plugin-core-server.coresetup.i18n.md b/docs/development/core/server/kibana-plugin-core-server.coresetup.i18n.md new file mode 100644 index 0000000000000..cac878c1e4449 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coresetup.i18n.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreSetup](./kibana-plugin-core-server.coresetup.md) > [i18n](./kibana-plugin-core-server.coresetup.i18n.md) + +## CoreSetup.i18n property + +[I18nServiceSetup](./kibana-plugin-core-server.i18nservicesetup.md) + +Signature: + +```typescript +i18n: I18nServiceSetup; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coresetup.md b/docs/development/core/server/kibana-plugin-core-server.coresetup.md index 7a733cc34dace..1171dbad570ce 100644 --- a/docs/development/core/server/kibana-plugin-core-server.coresetup.md +++ b/docs/development/core/server/kibana-plugin-core-server.coresetup.md @@ -21,6 +21,7 @@ export interface CoreSetupElasticsearchServiceSetup | [ElasticsearchServiceSetup](./kibana-plugin-core-server.elasticsearchservicesetup.md) | | [getStartServices](./kibana-plugin-core-server.coresetup.getstartservices.md) | StartServicesAccessor<TPluginsStart, TStart> | [StartServicesAccessor](./kibana-plugin-core-server.startservicesaccessor.md) | | [http](./kibana-plugin-core-server.coresetup.http.md) | HttpServiceSetup & {
resources: HttpResources;
} | [HttpServiceSetup](./kibana-plugin-core-server.httpservicesetup.md) | +| [i18n](./kibana-plugin-core-server.coresetup.i18n.md) | I18nServiceSetup | [I18nServiceSetup](./kibana-plugin-core-server.i18nservicesetup.md) | | [logging](./kibana-plugin-core-server.coresetup.logging.md) | LoggingServiceSetup | [LoggingServiceSetup](./kibana-plugin-core-server.loggingservicesetup.md) | | [metrics](./kibana-plugin-core-server.coresetup.metrics.md) | MetricsServiceSetup | [MetricsServiceSetup](./kibana-plugin-core-server.metricsservicesetup.md) | | [savedObjects](./kibana-plugin-core-server.coresetup.savedobjects.md) | SavedObjectsServiceSetup | [SavedObjectsServiceSetup](./kibana-plugin-core-server.savedobjectsservicesetup.md) | diff --git a/docs/development/core/server/kibana-plugin-core-server.i18nservicesetup.getlocale.md b/docs/development/core/server/kibana-plugin-core-server.i18nservicesetup.getlocale.md new file mode 100644 index 0000000000000..2fe8e564e7ce5 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.i18nservicesetup.getlocale.md @@ -0,0 +1,17 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [I18nServiceSetup](./kibana-plugin-core-server.i18nservicesetup.md) > [getLocale](./kibana-plugin-core-server.i18nservicesetup.getlocale.md) + +## I18nServiceSetup.getLocale() method + +Return the locale currently in use. + +Signature: + +```typescript +getLocale(): string; +``` +Returns: + +`string` + diff --git a/docs/development/core/server/kibana-plugin-core-server.i18nservicesetup.gettranslationfiles.md b/docs/development/core/server/kibana-plugin-core-server.i18nservicesetup.gettranslationfiles.md new file mode 100644 index 0000000000000..81caed287454e --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.i18nservicesetup.gettranslationfiles.md @@ -0,0 +1,17 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [I18nServiceSetup](./kibana-plugin-core-server.i18nservicesetup.md) > [getTranslationFiles](./kibana-plugin-core-server.i18nservicesetup.gettranslationfiles.md) + +## I18nServiceSetup.getTranslationFiles() method + +Return the absolute paths to translation files currently in use. + +Signature: + +```typescript +getTranslationFiles(): string[]; +``` +Returns: + +`string[]` + diff --git a/docs/development/core/server/kibana-plugin-core-server.i18nservicesetup.md b/docs/development/core/server/kibana-plugin-core-server.i18nservicesetup.md new file mode 100644 index 0000000000000..f68b7877953e7 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.i18nservicesetup.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [I18nServiceSetup](./kibana-plugin-core-server.i18nservicesetup.md) + +## I18nServiceSetup interface + + +Signature: + +```typescript +export interface I18nServiceSetup +``` + +## Methods + +| Method | Description | +| --- | --- | +| [getLocale()](./kibana-plugin-core-server.i18nservicesetup.getlocale.md) | Return the locale currently in use. | +| [getTranslationFiles()](./kibana-plugin-core-server.i18nservicesetup.gettranslationfiles.md) | Return the absolute paths to translation files currently in use. | + diff --git a/docs/development/core/server/kibana-plugin-core-server.md b/docs/development/core/server/kibana-plugin-core-server.md index 68f5e72915556..adbb2460dc80a 100644 --- a/docs/development/core/server/kibana-plugin-core-server.md +++ b/docs/development/core/server/kibana-plugin-core-server.md @@ -89,6 +89,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [HttpServerInfo](./kibana-plugin-core-server.httpserverinfo.md) | | | [HttpServiceSetup](./kibana-plugin-core-server.httpservicesetup.md) | Kibana HTTP Service provides own abstraction for work with HTTP stack. Plugins don't have direct access to hapi server and its primitives anymore. Moreover, plugins shouldn't rely on the fact that HTTP Service uses one or another library under the hood. This gives the platform flexibility to upgrade or changing our internal HTTP stack without breaking plugins. If the HTTP Service lacks functionality you need, we are happy to discuss and support your needs. | | [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) | | +| [I18nServiceSetup](./kibana-plugin-core-server.i18nservicesetup.md) | | | [IClusterClient](./kibana-plugin-core-server.iclusterclient.md) | Represents an Elasticsearch cluster API client created by the platform. It allows to call API on behalf of the internal Kibana user and the actual user that is derived from the request headers (via asScoped(...)). | | [IContextContainer](./kibana-plugin-core-server.icontextcontainer.md) | An object that handles registration of context providers and configuring handlers with context. | | [ICspConfig](./kibana-plugin-core-server.icspconfig.md) | CSP configuration for use in Kibana. | diff --git a/src/core/server/environment/environment_service.mock.ts b/src/core/server/environment/environment_service.mock.ts index a956e369ba4a7..3c579b0f68b00 100644 --- a/src/core/server/environment/environment_service.mock.ts +++ b/src/core/server/environment/environment_service.mock.ts @@ -17,8 +17,7 @@ * under the License. */ import type { PublicMethodsOf } from '@kbn/utility-types'; - -import { EnvironmentService, InternalEnvironmentServiceSetup } from './environment_service'; +import type { EnvironmentService, InternalEnvironmentServiceSetup } from './environment_service'; const createSetupContractMock = () => { const setupContract: jest.Mocked = { diff --git a/src/legacy/server/i18n/constants.ts b/src/core/server/i18n/fs.ts similarity index 88% rename from src/legacy/server/i18n/constants.ts rename to src/core/server/i18n/fs.ts index a7a410dbcb5b3..23d729504f81c 100644 --- a/src/legacy/server/i18n/constants.ts +++ b/src/core/server/i18n/fs.ts @@ -17,4 +17,7 @@ * under the License. */ -export const I18N_RC = '.i18nrc.json'; +import Fs from 'fs'; +import { promisify } from 'util'; + +export const readFile = promisify(Fs.readFile); diff --git a/src/core/server/i18n/get_kibana_translation_files.test.ts b/src/core/server/i18n/get_kibana_translation_files.test.ts new file mode 100644 index 0000000000000..737d8ed8bc4e2 --- /dev/null +++ b/src/core/server/i18n/get_kibana_translation_files.test.ts @@ -0,0 +1,81 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { getKibanaTranslationFiles } from './get_kibana_translation_files'; +import { getTranslationPaths } from './get_translation_paths'; + +const mockGetTranslationPaths = getTranslationPaths as jest.Mock; + +jest.mock('./get_translation_paths', () => ({ + getTranslationPaths: jest.fn().mockResolvedValue([]), +})); +jest.mock('../utils', () => ({ + fromRoot: jest.fn().mockImplementation((path: string) => path), +})); + +const locale = 'en'; + +describe('getKibanaTranslationPaths', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('calls getTranslationPaths against kibana root and kibana-extra', async () => { + await getKibanaTranslationFiles(locale, []); + + expect(mockGetTranslationPaths).toHaveBeenCalledTimes(2); + + expect(mockGetTranslationPaths).toHaveBeenCalledWith({ + cwd: '.', + nested: true, + }); + + expect(mockGetTranslationPaths).toHaveBeenCalledWith({ + cwd: '../kibana-extra', + nested: true, + }); + }); + + it('calls getTranslationPaths for each config returned in plugin.paths and plugins.scanDirs', async () => { + const pluginPaths = ['/path/to/pluginA', '/path/to/pluginB']; + + await getKibanaTranslationFiles(locale, pluginPaths); + + expect(mockGetTranslationPaths).toHaveBeenCalledTimes(2 + pluginPaths.length); + + pluginPaths.forEach((pluginPath) => { + expect(mockGetTranslationPaths).toHaveBeenCalledWith({ + cwd: pluginPath, + nested: false, + }); + }); + }); + + it('only return files for specified locale', async () => { + mockGetTranslationPaths.mockResolvedValueOnce(['/root/en.json', '/root/fr.json']); + mockGetTranslationPaths.mockResolvedValueOnce([ + '/kibana-extra/en.json', + '/kibana-extra/fr.json', + ]); + + const translationFiles = await getKibanaTranslationFiles('en', []); + + expect(translationFiles).toEqual(['/root/en.json', '/kibana-extra/en.json']); + }); +}); diff --git a/src/legacy/server/i18n/get_kibana_translation_paths.ts b/src/core/server/i18n/get_kibana_translation_files.ts similarity index 64% rename from src/legacy/server/i18n/get_kibana_translation_paths.ts rename to src/core/server/i18n/get_kibana_translation_files.ts index d7f77d3185ba4..dacb6a1e16a5c 100644 --- a/src/legacy/server/i18n/get_kibana_translation_paths.ts +++ b/src/core/server/i18n/get_kibana_translation_files.ts @@ -17,26 +17,27 @@ * under the License. */ -import { KibanaConfig } from '../kbn_server'; -import { fromRoot } from '../../../core/server/utils'; -import { I18N_RC } from './constants'; +import { basename } from 'path'; +import { fromRoot } from '../utils'; import { getTranslationPaths } from './get_translation_paths'; -export async function getKibanaTranslationPaths(config: Pick) { - return await Promise.all([ +export const getKibanaTranslationFiles = async ( + locale: string, + pluginPaths: string[] +): Promise => { + const translationPaths = await Promise.all([ getTranslationPaths({ cwd: fromRoot('.'), - glob: `*/${I18N_RC}`, + nested: true, }), - ...(config.get('plugins.paths') as string[]).map((cwd) => - getTranslationPaths({ cwd, glob: I18N_RC }) - ), - ...(config.get('plugins.scanDirs') as string[]).map((cwd) => - getTranslationPaths({ cwd, glob: `*/${I18N_RC}` }) - ), + ...pluginPaths.map((pluginPath) => getTranslationPaths({ cwd: pluginPath, nested: false })), getTranslationPaths({ cwd: fromRoot('../kibana-extra'), - glob: `*/${I18N_RC}`, + nested: true, }), ]); -} + + return ([] as string[]) + .concat(...translationPaths) + .filter((translationPath) => basename(translationPath, '.json') === locale); +}; diff --git a/src/core/server/i18n/get_translation_paths.test.mocks.ts b/src/core/server/i18n/get_translation_paths.test.mocks.ts new file mode 100644 index 0000000000000..f3b688062523c --- /dev/null +++ b/src/core/server/i18n/get_translation_paths.test.mocks.ts @@ -0,0 +1,26 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export const globbyMock = jest.fn(); +jest.doMock('globby', () => globbyMock); + +export const readFileMock = jest.fn(); +jest.doMock('./fs', () => ({ + readFile: readFileMock, +})); diff --git a/src/core/server/i18n/get_translation_paths.test.ts b/src/core/server/i18n/get_translation_paths.test.ts new file mode 100644 index 0000000000000..c6af59da07fb5 --- /dev/null +++ b/src/core/server/i18n/get_translation_paths.test.ts @@ -0,0 +1,90 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { resolve, join } from 'path'; +import { globbyMock, readFileMock } from './get_translation_paths.test.mocks'; +import { getTranslationPaths } from './get_translation_paths'; + +describe('getTranslationPaths', () => { + beforeEach(() => { + globbyMock.mockReset(); + readFileMock.mockReset(); + + globbyMock.mockResolvedValue([]); + readFileMock.mockResolvedValue('{}'); + }); + + it('calls `globby` with the correct parameters', async () => { + getTranslationPaths({ cwd: '/some/cwd', nested: false }); + + expect(globbyMock).toHaveBeenCalledTimes(1); + expect(globbyMock).toHaveBeenCalledWith('.i18nrc.json', { cwd: '/some/cwd' }); + + globbyMock.mockClear(); + + await getTranslationPaths({ cwd: '/other/cwd', nested: true }); + + expect(globbyMock).toHaveBeenCalledTimes(1); + expect(globbyMock).toHaveBeenCalledWith('*/.i18nrc.json', { cwd: '/other/cwd' }); + }); + + it('calls `readFile` for each entry returned by `globby`', async () => { + const entries = [join('pathA', '.i18nrc.json'), join('pathB', '.i18nrc.json')]; + globbyMock.mockResolvedValue(entries); + + const cwd = '/kibana-extra'; + + await getTranslationPaths({ cwd, nested: true }); + + expect(readFileMock).toHaveBeenCalledTimes(2); + + expect(readFileMock).toHaveBeenNthCalledWith(1, resolve(cwd, entries[0]), 'utf8'); + expect(readFileMock).toHaveBeenNthCalledWith(2, resolve(cwd, entries[1]), 'utf8'); + }); + + it('returns the absolute path to the translation files', async () => { + const entries = ['.i18nrc.json']; + globbyMock.mockResolvedValue(entries); + + const i18nFileContent = { + translations: ['translations/en.json', 'translations/fr.json'], + }; + readFileMock.mockResolvedValue(JSON.stringify(i18nFileContent)); + + const cwd = '/cwd'; + + const translationPaths = await getTranslationPaths({ cwd, nested: true }); + + expect(translationPaths).toEqual([ + resolve(cwd, 'translations/en.json'), + resolve(cwd, 'translations/fr.json'), + ]); + }); + + it('throws if i18nrc parsing fails', async () => { + globbyMock.mockResolvedValue(['.i18nrc.json']); + readFileMock.mockRejectedValue(new Error('error parsing file')); + + await expect( + getTranslationPaths({ cwd: '/cwd', nested: true }) + ).rejects.toThrowErrorMatchingInlineSnapshot( + `"Failed to parse .i18nrc.json file at /cwd/.i18nrc.json"` + ); + }); +}); diff --git a/src/legacy/server/i18n/get_translation_paths.ts b/src/core/server/i18n/get_translation_paths.ts similarity index 85% rename from src/legacy/server/i18n/get_translation_paths.ts rename to src/core/server/i18n/get_translation_paths.ts index a2a292e2278be..41d9dc4722e37 100644 --- a/src/legacy/server/i18n/get_translation_paths.ts +++ b/src/core/server/i18n/get_translation_paths.ts @@ -17,18 +17,18 @@ * under the License. */ -import { promisify } from 'util'; -import { readFile } from 'fs'; import { resolve, dirname } from 'path'; import globby from 'globby'; - -const readFileAsync = promisify(readFile); +import { readFile } from './fs'; interface I18NRCFileStructure { translations?: string[]; } -export async function getTranslationPaths({ cwd, glob }: { cwd: string; glob: string }) { +const I18N_RC = '.i18nrc.json'; + +export async function getTranslationPaths({ cwd, nested }: { cwd: string; nested: boolean }) { + const glob = nested ? `*/${I18N_RC}` : I18N_RC; const entries = await globby(glob, { cwd }); const translationPaths: string[] = []; @@ -36,7 +36,7 @@ export async function getTranslationPaths({ cwd, glob }: { cwd: string; glob: st const entryFullPath = resolve(cwd, entry); const pluginBasePath = dirname(entryFullPath); try { - const content = await readFileAsync(entryFullPath, 'utf8'); + const content = await readFile(entryFullPath, 'utf8'); const { translations } = JSON.parse(content) as I18NRCFileStructure; if (translations && translations.length) { translations.forEach((translation) => { diff --git a/src/core/server/i18n/i18n_config.ts b/src/core/server/i18n/i18n_config.ts new file mode 100644 index 0000000000000..f181c52dc4b06 --- /dev/null +++ b/src/core/server/i18n/i18n_config.ts @@ -0,0 +1,29 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema, TypeOf } from '@kbn/config-schema'; + +export const config = { + path: 'i18n', + schema: schema.object({ + locale: schema.string({ defaultValue: 'en' }), + }), +}; + +export type I18nConfigType = TypeOf; diff --git a/src/core/server/i18n/i18n_service.mock.ts b/src/core/server/i18n/i18n_service.mock.ts new file mode 100644 index 0000000000000..679751aefbf27 --- /dev/null +++ b/src/core/server/i18n/i18n_service.mock.ts @@ -0,0 +1,50 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { PublicMethodsOf } from '@kbn/utility-types'; +import type { I18nServiceSetup, I18nService } from './i18n_service'; + +const createSetupContractMock = () => { + const mock: jest.Mocked = { + getLocale: jest.fn(), + getTranslationFiles: jest.fn(), + }; + + mock.getLocale.mockReturnValue('en'); + mock.getTranslationFiles.mockReturnValue([]); + + return mock; +}; + +type I18nServiceContract = PublicMethodsOf; + +const createMock = () => { + const mock: jest.Mocked = { + setup: jest.fn(), + }; + + mock.setup.mockResolvedValue(createSetupContractMock()); + + return mock; +}; + +export const i18nServiceMock = { + create: createMock, + createSetupContract: createSetupContractMock, +}; diff --git a/src/core/server/i18n/i18n_service.test.mocks.ts b/src/core/server/i18n/i18n_service.test.mocks.ts new file mode 100644 index 0000000000000..23f97a1404fff --- /dev/null +++ b/src/core/server/i18n/i18n_service.test.mocks.ts @@ -0,0 +1,28 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export const getKibanaTranslationFilesMock = jest.fn(); +jest.doMock('./get_kibana_translation_files', () => ({ + getKibanaTranslationFiles: getKibanaTranslationFilesMock, +})); + +export const initTranslationsMock = jest.fn(); +jest.doMock('./init_translations', () => ({ + initTranslations: initTranslationsMock, +})); diff --git a/src/core/server/i18n/i18n_service.test.ts b/src/core/server/i18n/i18n_service.test.ts new file mode 100644 index 0000000000000..87de39a92ab26 --- /dev/null +++ b/src/core/server/i18n/i18n_service.test.ts @@ -0,0 +1,84 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { getKibanaTranslationFilesMock, initTranslationsMock } from './i18n_service.test.mocks'; + +import { BehaviorSubject } from 'rxjs'; +import { I18nService } from './i18n_service'; + +import { configServiceMock } from '../config/mocks'; +import { mockCoreContext } from '../core_context.mock'; + +const getConfigService = (locale = 'en') => { + const configService = configServiceMock.create(); + configService.atPath.mockImplementation((path) => { + if (path === 'i18n') { + return new BehaviorSubject({ + locale, + }); + } + return new BehaviorSubject({}); + }); + return configService; +}; + +describe('I18nService', () => { + let service: I18nService; + let configService: ReturnType; + + beforeEach(() => { + jest.clearAllMocks(); + configService = getConfigService(); + + const coreContext = mockCoreContext.create({ configService }); + service = new I18nService(coreContext); + }); + + describe('#setup', () => { + it('calls `getKibanaTranslationFiles` with the correct parameters', async () => { + getKibanaTranslationFilesMock.mockResolvedValue([]); + + const pluginPaths = ['/pathA', '/pathB']; + await service.setup({ pluginPaths }); + + expect(getKibanaTranslationFilesMock).toHaveBeenCalledTimes(1); + expect(getKibanaTranslationFilesMock).toHaveBeenCalledWith('en', pluginPaths); + }); + + it('calls `initTranslations` with the correct parameters', async () => { + const translationFiles = ['/path/to/file', 'path/to/another/file']; + getKibanaTranslationFilesMock.mockResolvedValue(translationFiles); + + await service.setup({ pluginPaths: [] }); + + expect(initTranslationsMock).toHaveBeenCalledTimes(1); + expect(initTranslationsMock).toHaveBeenCalledWith('en', translationFiles); + }); + + it('returns accessors for locale and translation files', async () => { + const translationFiles = ['/path/to/file', 'path/to/another/file']; + getKibanaTranslationFilesMock.mockResolvedValue(translationFiles); + + const { getLocale, getTranslationFiles } = await service.setup({ pluginPaths: [] }); + + expect(getLocale()).toEqual('en'); + expect(getTranslationFiles()).toEqual(translationFiles); + }); + }); +}); diff --git a/src/core/server/i18n/i18n_service.ts b/src/core/server/i18n/i18n_service.ts new file mode 100644 index 0000000000000..fd32dd7fdd6ef --- /dev/null +++ b/src/core/server/i18n/i18n_service.ts @@ -0,0 +1,75 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { take } from 'rxjs/operators'; +import { Logger } from '../logging'; +import { IConfigService } from '../config'; +import { CoreContext } from '../core_context'; +import { config as i18nConfigDef, I18nConfigType } from './i18n_config'; +import { getKibanaTranslationFiles } from './get_kibana_translation_files'; +import { initTranslations } from './init_translations'; + +interface SetupDeps { + pluginPaths: string[]; +} + +/** + * @public + */ +export interface I18nServiceSetup { + /** + * Return the locale currently in use. + */ + getLocale(): string; + + /** + * Return the absolute paths to translation files currently in use. + */ + getTranslationFiles(): string[]; +} + +export class I18nService { + private readonly log: Logger; + private readonly configService: IConfigService; + + constructor(coreContext: CoreContext) { + this.log = coreContext.logger.get('i18n'); + this.configService = coreContext.configService; + } + + public async setup({ pluginPaths }: SetupDeps): Promise { + const i18nConfig = await this.configService + .atPath(i18nConfigDef.path) + .pipe(take(1)) + .toPromise(); + + const locale = i18nConfig.locale; + this.log.debug(`Using locale: ${locale}`); + + const translationFiles = await getKibanaTranslationFiles(locale, pluginPaths); + + this.log.debug(`Using translation files: [${translationFiles.join(', ')}]`); + await initTranslations(locale, translationFiles); + + return { + getLocale: () => locale, + getTranslationFiles: () => translationFiles, + }; + } +} diff --git a/src/legacy/server/i18n/index.ts b/src/core/server/i18n/index.ts similarity index 86% rename from src/legacy/server/i18n/index.ts rename to src/core/server/i18n/index.ts index a7ef49f44532c..2db3fdeb405d9 100644 --- a/src/legacy/server/i18n/index.ts +++ b/src/core/server/i18n/index.ts @@ -17,4 +17,5 @@ * under the License. */ -export { i18nMixin } from './i18n_mixin'; +export { config, I18nConfigType } from './i18n_config'; +export { I18nService, I18nServiceSetup } from './i18n_service'; diff --git a/src/core/server/i18n/init_translations.ts b/src/core/server/i18n/init_translations.ts new file mode 100644 index 0000000000000..94e6d41019ad2 --- /dev/null +++ b/src/core/server/i18n/init_translations.ts @@ -0,0 +1,31 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { i18n, i18nLoader } from '@kbn/i18n'; + +export const initTranslations = async (locale: string, translationFiles: string[]) => { + i18nLoader.registerTranslationFiles(translationFiles); + const translations = await i18nLoader.getTranslationsByLocale(locale); + i18n.init( + Object.freeze({ + locale, + ...translations, + }) + ); +}; diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 0adda4770639d..7b19c3a686757 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -64,6 +64,7 @@ import { MetricsServiceSetup, MetricsServiceStart } from './metrics'; import { StatusServiceSetup } from './status'; import { AppenderConfigType, appendersSchema, LoggingServiceSetup } from './logging'; import { CoreUsageDataStart } from './core_usage_data'; +import { I18nServiceSetup } from './i18n'; // Because of #79265 we need to explicity import, then export these types for // scripts/telemetry_check.js to work as expected @@ -336,6 +337,8 @@ export { MetricsServiceStart, } from './metrics'; +export { I18nServiceSetup } from './i18n'; + export { AppCategory } from '../types'; export { DEFAULT_APP_CATEGORIES } from '../utils'; @@ -421,6 +424,8 @@ export interface CoreSetup = KbnServer as any; @@ -75,6 +76,7 @@ beforeEach(() => { capabilities: capabilitiesServiceMock.createSetupContract(), context: contextServiceMock.createSetupContract(), elasticsearch: { legacy: {} } as any, + i18n: i18nServiceMock.createSetupContract(), uiSettings: uiSettingsServiceMock.createSetupContract(), http: { ...httpServiceMock.createInternalSetupContract(), diff --git a/src/core/server/legacy/legacy_service.ts b/src/core/server/legacy/legacy_service.ts index c42771179aba2..3111c8daf7981 100644 --- a/src/core/server/legacy/legacy_service.ts +++ b/src/core/server/legacy/legacy_service.ts @@ -251,6 +251,7 @@ export class LegacyService implements CoreService { csp: setupDeps.core.http.csp, getServerInfo: setupDeps.core.http.getServerInfo, }, + i18n: setupDeps.core.i18n, logging: { configure: (config$) => setupDeps.core.logging.configure([], config$), }, diff --git a/src/core/server/metrics/metrics_service.mock.ts b/src/core/server/metrics/metrics_service.mock.ts index 0d9e9af39317c..6faccc9c9da56 100644 --- a/src/core/server/metrics/metrics_service.mock.ts +++ b/src/core/server/metrics/metrics_service.mock.ts @@ -19,7 +19,7 @@ import { BehaviorSubject } from 'rxjs'; import type { PublicMethodsOf } from '@kbn/utility-types'; -import { MetricsService } from './metrics_service'; +import type { MetricsService } from './metrics_service'; import { InternalMetricsServiceSetup, InternalMetricsServiceStart, diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index 8ca0c82219ed4..03a0ae2d6443a 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -38,6 +38,7 @@ import { metricsServiceMock } from './metrics/metrics_service.mock'; import { environmentServiceMock } from './environment/environment_service.mock'; import { statusServiceMock } from './status/status_service.mock'; import { coreUsageDataServiceMock } from './core_usage_data/core_usage_data_service.mock'; +import { i18nServiceMock } from './i18n/i18n_service.mock'; export { configServiceMock } from './config/mocks'; export { httpServerMock } from './http/http_server.mocks'; @@ -57,6 +58,7 @@ export { statusServiceMock } from './status/status_service.mock'; export { contextServiceMock } from './context/context_service.mock'; export { capabilitiesServiceMock } from './capabilities/capabilities_service.mock'; export { coreUsageDataServiceMock } from './core_usage_data/core_usage_data_service.mock'; +export { i18nServiceMock } from './i18n/i18n_service.mock'; export function pluginInitializerContextConfigMock(config: T) { const globalConfig: SharedGlobalConfig = { @@ -136,6 +138,7 @@ function createCoreSetupMock({ context: contextServiceMock.createSetupContract(), elasticsearch: elasticsearchServiceMock.createSetup(), http: httpMock, + i18n: i18nServiceMock.createSetupContract(), savedObjects: savedObjectsServiceMock.createInternalSetupContract(), status: statusServiceMock.createSetupContract(), uiSettings: uiSettingsMock, @@ -172,6 +175,7 @@ function createInternalCoreSetupMock() { savedObjects: savedObjectsServiceMock.createInternalSetupContract(), status: statusServiceMock.createInternalSetupContract(), environment: environmentServiceMock.createSetupContract(), + i18n: i18nServiceMock.createSetupContract(), httpResources: httpResourcesMock.createSetupContract(), rendering: renderingMock.createSetupContract(), uiSettings: uiSettingsServiceMock.createSetupContract(), diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index 22e79741e854c..3b2634ddbe315 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -176,6 +176,7 @@ export function createPluginSetupContext( csp: deps.http.csp, getServerInfo: deps.http.getServerInfo, }, + i18n: deps.i18n, logging: { configure: (config$) => deps.logging.configure(['plugins', plugin.name], config$), }, diff --git a/src/core/server/plugins/plugins_service.mock.ts b/src/core/server/plugins/plugins_service.mock.ts index 14d6de889dd42..3ea8badb0f450 100644 --- a/src/core/server/plugins/plugins_service.mock.ts +++ b/src/core/server/plugins/plugins_service.mock.ts @@ -17,7 +17,7 @@ * under the License. */ import type { PublicMethodsOf } from '@kbn/utility-types'; -import { PluginsService, PluginsServiceSetup } from './plugins_service'; +import type { PluginsService, PluginsServiceSetup } from './plugins_service'; type PluginsServiceMock = jest.Mocked>; diff --git a/src/core/server/plugins/plugins_service.test.ts b/src/core/server/plugins/plugins_service.test.ts index 64a382e539fb0..02b82c17ed4fc 100644 --- a/src/core/server/plugins/plugins_service.test.ts +++ b/src/core/server/plugins/plugins_service.test.ts @@ -127,6 +127,7 @@ async function testSetup(options: { isDevClusterMaster?: boolean } = {}) { [mockPluginSystem] = MockPluginsSystem.mock.instances as any; mockPluginSystem.uiPlugins.mockReturnValue(new Map()); + mockPluginSystem.getPlugins.mockReturnValue([]); environmentSetup = environmentServiceMock.createSetupContract(); } @@ -469,6 +470,22 @@ describe('PluginsService', () => { deprecationProvider ); }); + + it('returns the paths of the plugins', async () => { + const pluginA = createPlugin('A', { path: '/plugin-A-path', configPath: 'pathA' }); + const pluginB = createPlugin('B', { path: '/plugin-B-path', configPath: 'pathB' }); + + mockDiscover.mockReturnValue({ + error$: from([]), + plugin$: from([]), + }); + + mockPluginSystem.getPlugins.mockReturnValue([pluginA, pluginB]); + + const { pluginPaths } = await pluginsService.discover({ environment: environmentSetup }); + + expect(pluginPaths).toEqual(['/plugin-A-path', '/plugin-B-path']); + }); }); describe('#generateUiPluginsConfigs()', () => { @@ -633,6 +650,7 @@ describe('PluginService when isDevClusterMaster is true', () => { await expect(pluginsService.discover({ environment: environmentSetup })).resolves .toMatchInlineSnapshot(` Object { + "pluginPaths": Array [], "pluginTree": undefined, "uiPlugins": Object { "browserConfigs": Map {}, diff --git a/src/core/server/plugins/plugins_service.ts b/src/core/server/plugins/plugins_service.ts index a1062bde7765f..5967e6d5358de 100644 --- a/src/core/server/plugins/plugins_service.ts +++ b/src/core/server/plugins/plugins_service.ts @@ -118,6 +118,7 @@ export class PluginsService implements CoreService plugin.path), uiPlugins: { internal: this.uiPluginInternalInfo, public: uiPlugins, diff --git a/src/core/server/plugins/plugins_system.test.ts b/src/core/server/plugins/plugins_system.test.ts index ae9267ca5cf60..89a3697ebe9cd 100644 --- a/src/core/server/plugins/plugins_system.test.ts +++ b/src/core/server/plugins/plugins_system.test.ts @@ -92,6 +92,15 @@ test('can be setup even without plugins', async () => { expect(pluginsSetup.size).toBe(0); }); +test('getPlugins returns the list of plugins', () => { + const pluginA = createPlugin('plugin-a'); + const pluginB = createPlugin('plugin-b'); + pluginsSystem.addPlugin(pluginA); + pluginsSystem.addPlugin(pluginB); + + expect(pluginsSystem.getPlugins()).toEqual([pluginA, pluginB]); +}); + test('getPluginDependencies returns dependency tree of symbols', () => { pluginsSystem.addPlugin(createPlugin('plugin-a', { required: ['no-dep'] })); pluginsSystem.addPlugin( diff --git a/src/core/server/plugins/plugins_system.ts b/src/core/server/plugins/plugins_system.ts index 72d2cfe158b37..23dc77b7bf673 100644 --- a/src/core/server/plugins/plugins_system.ts +++ b/src/core/server/plugins/plugins_system.ts @@ -42,6 +42,10 @@ export class PluginsSystem { this.plugins.set(plugin.name, plugin); } + public getPlugins() { + return [...this.plugins.values()]; + } + /** * @returns a ReadonlyMap of each plugin and an Array of its available dependencies * @internal diff --git a/src/core/server/rendering/__mocks__/rendering_service.ts b/src/core/server/rendering/__mocks__/rendering_service.ts index 01d084f9ae53c..00e617de82542 100644 --- a/src/core/server/rendering/__mocks__/rendering_service.ts +++ b/src/core/server/rendering/__mocks__/rendering_service.ts @@ -17,8 +17,8 @@ * under the License. */ import type { PublicMethodsOf } from '@kbn/utility-types'; -import { RenderingService as Service } from '../rendering_service'; -import { InternalRenderingServiceSetup } from '../types'; +import type { RenderingService as Service } from '../rendering_service'; +import type { InternalRenderingServiceSetup } from '../types'; import { mockRenderingServiceParams } from './params'; type IRenderingService = PublicMethodsOf; diff --git a/src/core/server/saved_objects/saved_objects_service.mock.ts b/src/core/server/saved_objects/saved_objects_service.mock.ts index c56cdabf6e4cd..85dbf4b5e8c6a 100644 --- a/src/core/server/saved_objects/saved_objects_service.mock.ts +++ b/src/core/server/saved_objects/saved_objects_service.mock.ts @@ -19,8 +19,7 @@ import { BehaviorSubject } from 'rxjs'; import type { PublicMethodsOf } from '@kbn/utility-types'; - -import { +import type { SavedObjectsService, InternalSavedObjectsServiceSetup, InternalSavedObjectsServiceStart, diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 52500673f7f31..88d7fecbcf502 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -480,6 +480,8 @@ export interface CoreSetup HttpServerInfo; } +// @public (undocumented) +export interface I18nServiceSetup { + getLocale(): string; + getTranslationFiles(): string[]; +} + // @public export type IBasePath = Pick; diff --git a/src/core/server/server.test.mocks.ts b/src/core/server/server.test.mocks.ts index fe299c6d11675..d2d6990dc5451 100644 --- a/src/core/server/server.test.mocks.ts +++ b/src/core/server/server.test.mocks.ts @@ -100,3 +100,9 @@ export const mockLoggingService = loggingServiceMock.create(); jest.doMock('./logging/logging_service', () => ({ LoggingService: jest.fn(() => mockLoggingService), })); + +import { i18nServiceMock } from './i18n/i18n_service.mock'; +export const mockI18nService = i18nServiceMock.create(); +jest.doMock('./i18n/i18n_service', () => ({ + I18nService: jest.fn(() => mockI18nService), +})); diff --git a/src/core/server/server.test.ts b/src/core/server/server.test.ts index 78703ceeec7ae..0c7ebbcb527ec 100644 --- a/src/core/server/server.test.ts +++ b/src/core/server/server.test.ts @@ -31,6 +31,7 @@ import { mockMetricsService, mockStatusService, mockLoggingService, + mockI18nService, } from './server.test.mocks'; import { BehaviorSubject } from 'rxjs'; @@ -49,6 +50,7 @@ beforeEach(() => { mockConfigService.atPath.mockReturnValue(new BehaviorSubject({ autoListen: true })); mockPluginsService.discover.mockResolvedValue({ pluginTree: { asOpaqueIds: new Map(), asNames: new Map() }, + pluginPaths: [], uiPlugins: { internal: new Map(), public: new Map(), browserConfigs: new Map() }, }); }); @@ -70,6 +72,7 @@ test('sets up services on "setup"', async () => { expect(mockMetricsService.setup).not.toHaveBeenCalled(); expect(mockStatusService.setup).not.toHaveBeenCalled(); expect(mockLoggingService.setup).not.toHaveBeenCalled(); + expect(mockI18nService.setup).not.toHaveBeenCalled(); await server.setup(); @@ -83,6 +86,7 @@ test('sets up services on "setup"', async () => { expect(mockMetricsService.setup).toHaveBeenCalledTimes(1); expect(mockStatusService.setup).toHaveBeenCalledTimes(1); expect(mockLoggingService.setup).toHaveBeenCalledTimes(1); + expect(mockI18nService.setup).toHaveBeenCalledTimes(1); }); test('injects legacy dependency to context#setup()', async () => { @@ -96,6 +100,7 @@ test('injects legacy dependency to context#setup()', async () => { ]); mockPluginsService.discover.mockResolvedValue({ pluginTree: { asOpaqueIds: pluginDependencies, asNames: new Map() }, + pluginPaths: [], uiPlugins: { internal: new Map(), public: new Map(), browserConfigs: new Map() }, }); @@ -185,6 +190,7 @@ test(`doesn't setup core services if config validation fails`, async () => { expect(mockMetricsService.setup).not.toHaveBeenCalled(); expect(mockStatusService.setup).not.toHaveBeenCalled(); expect(mockLoggingService.setup).not.toHaveBeenCalled(); + expect(mockI18nService.setup).not.toHaveBeenCalled(); }); test(`doesn't setup core services if legacy config validation fails`, async () => { @@ -207,6 +213,7 @@ test(`doesn't setup core services if legacy config validation fails`, async () = expect(mockMetricsService.setup).not.toHaveBeenCalled(); expect(mockStatusService.setup).not.toHaveBeenCalled(); expect(mockLoggingService.setup).not.toHaveBeenCalled(); + expect(mockI18nService.setup).not.toHaveBeenCalled(); }); test(`doesn't validate config if env.isDevClusterMaster is true`, async () => { diff --git a/src/core/server/server.ts b/src/core/server/server.ts index eaa03d11cab98..55ed88e55a9f5 100644 --- a/src/core/server/server.ts +++ b/src/core/server/server.ts @@ -16,11 +16,13 @@ * specific language governing permissions and limitations * under the License. */ + import apm from 'elastic-apm-node'; import { config as pathConfig } from '@kbn/utils'; import { mapToObject } from '@kbn/std'; import { ConfigService, Env, RawConfigurationProvider, coreDeprecationProvider } from './config'; import { CoreApp } from './core_app'; +import { I18nService } from './i18n'; import { ElasticsearchService } from './elasticsearch'; import { HttpService } from './http'; import { HttpResourcesService } from './http_resources'; @@ -29,10 +31,11 @@ import { LegacyService, ensureValidConfiguration } from './legacy'; import { Logger, LoggerFactory, LoggingService, ILoggingSystem } from './logging'; import { UiSettingsService } from './ui_settings'; import { PluginsService, config as pluginsConfig } from './plugins'; -import { SavedObjectsService } from '../server/saved_objects'; +import { SavedObjectsService } from './saved_objects'; import { MetricsService, opsConfig } from './metrics'; import { CapabilitiesService } from './capabilities'; import { EnvironmentService, config as pidConfig } from './environment'; +// do not try to shorten the import to `./status`, it will break server test mocking import { StatusService } from './status/status_service'; import { config as cspConfig } from './csp'; @@ -44,6 +47,7 @@ import { config as kibanaConfig } from './kibana_config'; import { savedObjectsConfig, savedObjectsMigrationConfig } from './saved_objects'; import { config as uiSettingsConfig } from './ui_settings'; import { config as statusConfig } from './status'; +import { config as i18nConfig } from './i18n'; import { ContextService } from './context'; import { RequestHandlerContext } from '.'; import { InternalCoreSetup, InternalCoreStart, ServiceConfigDescriptor } from './internal_types'; @@ -72,6 +76,7 @@ export class Server { private readonly logging: LoggingService; private readonly coreApp: CoreApp; private readonly coreUsageData: CoreUsageDataService; + private readonly i18n: I18nService; #pluginsInitialized?: boolean; private coreStart?: InternalCoreStart; @@ -103,6 +108,7 @@ export class Server { this.httpResources = new HttpResourcesService(core); this.logging = new LoggingService(core); this.coreUsageData = new CoreUsageDataService(core); + this.i18n = new I18nService(core); } public async setup() { @@ -112,7 +118,7 @@ export class Server { const environmentSetup = await this.environment.setup(); // Discover any plugins before continuing. This allows other systems to utilize the plugin dependency graph. - const { pluginTree, uiPlugins } = await this.plugins.discover({ + const { pluginTree, pluginPaths, uiPlugins } = await this.plugins.discover({ environment: environmentSetup, }); const legacyConfigSetup = await this.legacy.setupLegacyConfig(); @@ -125,6 +131,9 @@ export class Server { await ensureValidConfiguration(this.configService, legacyConfigSetup); } + // setup i18n prior to any other service, to have translations ready + const i18nServiceSetup = await this.i18n.setup({ pluginPaths }); + const contextServiceSetup = this.context.setup({ // We inject a fake "legacy plugin" with dependencies on every plugin so that legacy plugins: // 1) Can access context from any KP plugin @@ -190,6 +199,7 @@ export class Server { elasticsearch: elasticsearchServiceSetup, environment: environmentSetup, http: httpSetup, + i18n: i18nServiceSetup, savedObjects: savedObjectsSetup, status: statusSetup, uiSettings: uiSettingsSetup, @@ -302,6 +312,7 @@ export class Server { opsConfig, statusConfig, pidConfig, + i18nConfig, ]; this.configService.addDeprecationProvider(rootConfigPath, coreDeprecationProvider); diff --git a/src/core/server/status/status_service.mock.ts b/src/core/server/status/status_service.mock.ts index 0ee2d03229a78..42892ddbb490c 100644 --- a/src/core/server/status/status_service.mock.ts +++ b/src/core/server/status/status_service.mock.ts @@ -17,7 +17,7 @@ * under the License. */ import type { PublicMethodsOf } from '@kbn/utility-types'; -import { StatusService } from './status_service'; +import type { StatusService } from './status_service'; import { InternalStatusServiceSetup, StatusServiceSetup, diff --git a/src/core/server/ui_settings/ui_settings_service.mock.ts b/src/core/server/ui_settings/ui_settings_service.mock.ts index b1ed0dd188cde..818e9b43889e3 100644 --- a/src/core/server/ui_settings/ui_settings_service.mock.ts +++ b/src/core/server/ui_settings/ui_settings_service.mock.ts @@ -22,7 +22,7 @@ import { InternalUiSettingsServiceSetup, InternalUiSettingsServiceStart, } from './types'; -import { UiSettingsService } from './ui_settings_service'; +import type { UiSettingsService } from './ui_settings_service'; const createClientMock = () => { const mocked: jest.Mocked = { diff --git a/src/legacy/server/config/schema.js b/src/legacy/server/config/schema.js index e1f03b8a08847..39df3990ff2ff 100644 --- a/src/legacy/server/config/schema.js +++ b/src/legacy/server/config/schema.js @@ -128,21 +128,12 @@ export default () => cGroupOverrides: HANDLED_IN_NEW_PLATFORM, }).default(), - // still used by the legacy i18n mixin - plugins: Joi.object({ - paths: Joi.array().items(Joi.string()).default([]), - scanDirs: Joi.array().items(Joi.string()).default([]), - initialize: Joi.boolean().default(true), - }).default(), - + plugins: HANDLED_IN_NEW_PLATFORM, path: HANDLED_IN_NEW_PLATFORM, stats: HANDLED_IN_NEW_PLATFORM, status: HANDLED_IN_NEW_PLATFORM, map: HANDLED_IN_NEW_PLATFORM, - - i18n: Joi.object({ - locale: Joi.string().default('en'), - }).default(), + i18n: HANDLED_IN_NEW_PLATFORM, // temporarily moved here from the (now deleted) kibana legacy plugin kibana: Joi.object({ diff --git a/src/legacy/server/i18n/get_kibana_translation_paths.test.ts b/src/legacy/server/i18n/get_kibana_translation_paths.test.ts deleted file mode 100644 index 0f202c4d433c0..0000000000000 --- a/src/legacy/server/i18n/get_kibana_translation_paths.test.ts +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { I18N_RC } from './constants'; -import { fromRoot } from '../../../core/server/utils'; - -jest.mock('./get_translation_paths', () => ({ getTranslationPaths: jest.fn() })); -import { getKibanaTranslationPaths } from './get_kibana_translation_paths'; -import { getTranslationPaths as mockGetTranslationPaths } from './get_translation_paths'; - -describe('getKibanaTranslationPaths', () => { - const mockConfig = { get: jest.fn() }; - - beforeEach(() => { - jest.resetAllMocks(); - }); - - it('calls getTranslationPaths against kibana root and kibana-extra', async () => { - mockConfig.get.mockReturnValue([]); - await getKibanaTranslationPaths(mockConfig); - expect(mockGetTranslationPaths).toHaveBeenNthCalledWith(1, { - cwd: fromRoot('.'), - glob: `*/${I18N_RC}`, - }); - - expect(mockGetTranslationPaths).toHaveBeenNthCalledWith(2, { - cwd: fromRoot('../kibana-extra'), - glob: `*/${I18N_RC}`, - }); - }); - - it('calls getTranslationPaths for each config returned in plugin.paths and plugins.scanDirs', async () => { - mockConfig.get.mockReturnValueOnce(['a', 'b']).mockReturnValueOnce(['c']); - await getKibanaTranslationPaths(mockConfig); - expect(mockConfig.get).toHaveBeenNthCalledWith(1, 'plugins.paths'); - expect(mockConfig.get).toHaveBeenNthCalledWith(2, 'plugins.scanDirs'); - - expect(mockGetTranslationPaths).toHaveBeenNthCalledWith(2, { cwd: 'a', glob: I18N_RC }); - expect(mockGetTranslationPaths).toHaveBeenNthCalledWith(3, { cwd: 'b', glob: I18N_RC }); - expect(mockGetTranslationPaths).toHaveBeenNthCalledWith(4, { cwd: 'c', glob: `*/${I18N_RC}` }); - }); -}); diff --git a/src/legacy/server/i18n/i18n_mixin.ts b/src/legacy/server/i18n/i18n_mixin.ts deleted file mode 100644 index 0b3879073c164..0000000000000 --- a/src/legacy/server/i18n/i18n_mixin.ts +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { i18n, i18nLoader } from '@kbn/i18n'; -import { basename } from 'path'; -import { Server } from '@hapi/hapi'; -import type { UsageCollectionSetup } from '../../../plugins/usage_collection/server'; -import { getKibanaTranslationPaths } from './get_kibana_translation_paths'; -import KbnServer, { KibanaConfig } from '../kbn_server'; -import { registerLocalizationUsageCollector } from './localization'; - -export async function i18nMixin( - kbnServer: KbnServer, - server: Server, - config: Pick -) { - const locale = config.get('i18n.locale') as string; - - const translationPaths = await getKibanaTranslationPaths(config); - - const currentTranslationPaths = ([] as string[]) - .concat(...translationPaths) - .filter((translationPath) => basename(translationPath, '.json') === locale); - i18nLoader.registerTranslationFiles(currentTranslationPaths); - - const translations = await i18nLoader.getTranslationsByLocale(locale); - i18n.init( - Object.freeze({ - locale, - ...translations, - }) - ); - - const getTranslationsFilePaths = () => currentTranslationPaths; - - server.decorate('server', 'getTranslationsFilePaths', getTranslationsFilePaths); - - if (kbnServer.newPlatform.setup.plugins.usageCollection) { - const { usageCollection } = kbnServer.newPlatform.setup.plugins as { - usageCollection: UsageCollectionSetup; - }; - registerLocalizationUsageCollector(usageCollection, { - getLocale: () => config.get('i18n.locale') as string, - getTranslationsFilePaths, - }); - } -} diff --git a/src/legacy/server/kbn_server.js b/src/legacy/server/kbn_server.js index e29563a7c6266..013da35d2acb7 100644 --- a/src/legacy/server/kbn_server.js +++ b/src/legacy/server/kbn_server.js @@ -31,7 +31,6 @@ import warningsMixin from './warnings'; import configCompleteMixin from './config/complete'; import { optimizeMixin } from '../../optimize'; import { uiMixin } from '../ui'; -import { i18nMixin } from './i18n'; /** * @typedef {import('./kbn_server').KibanaConfig} KibanaConfig @@ -82,9 +81,6 @@ export default class KbnServer { loggingMixin, warningsMixin, - // scan translations dirs, register locale files and initialize i18n engine. - i18nMixin, - // tell the config we are done loading plugins configCompleteMixin, diff --git a/src/plugins/kibana_usage_collection/server/__snapshots__/index.test.ts.snap b/src/plugins/kibana_usage_collection/server/__snapshots__/index.test.ts.snap index c479562795512..c782ce9c8cc84 100644 --- a/src/plugins/kibana_usage_collection/server/__snapshots__/index.test.ts.snap +++ b/src/plugins/kibana_usage_collection/server/__snapshots__/index.test.ts.snap @@ -13,3 +13,5 @@ exports[`kibana_usage_collection Runs the setup method without issues 5`] = `fal exports[`kibana_usage_collection Runs the setup method without issues 6`] = `true`; exports[`kibana_usage_collection Runs the setup method without issues 7`] = `false`; + +exports[`kibana_usage_collection Runs the setup method without issues 8`] = `true`; diff --git a/src/plugins/kibana_usage_collection/server/collectors/index.ts b/src/plugins/kibana_usage_collection/server/collectors/index.ts index 2408dc84c2e56..f3b7d8ca5eea0 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/index.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/index.ts @@ -24,3 +24,4 @@ export { registerKibanaUsageCollector } from './kibana'; export { registerOpsStatsCollector } from './ops_stats'; export { registerCspCollector } from './csp'; export { registerCoreUsageCollector } from './core'; +export { registerLocalizationUsageCollector } from './localization'; diff --git a/src/legacy/server/i18n/localization/file_integrity.test.mocks.ts b/src/plugins/kibana_usage_collection/server/collectors/localization/file_integrity.test.mocks.ts similarity index 100% rename from src/legacy/server/i18n/localization/file_integrity.test.mocks.ts rename to src/plugins/kibana_usage_collection/server/collectors/localization/file_integrity.test.mocks.ts diff --git a/src/legacy/server/i18n/localization/file_integrity.test.ts b/src/plugins/kibana_usage_collection/server/collectors/localization/file_integrity.test.ts similarity index 100% rename from src/legacy/server/i18n/localization/file_integrity.test.ts rename to src/plugins/kibana_usage_collection/server/collectors/localization/file_integrity.test.ts diff --git a/src/legacy/server/i18n/localization/file_integrity.ts b/src/plugins/kibana_usage_collection/server/collectors/localization/file_integrity.ts similarity index 100% rename from src/legacy/server/i18n/localization/file_integrity.ts rename to src/plugins/kibana_usage_collection/server/collectors/localization/file_integrity.ts diff --git a/src/legacy/server/i18n/localization/index.ts b/src/plugins/kibana_usage_collection/server/collectors/localization/index.ts similarity index 100% rename from src/legacy/server/i18n/localization/index.ts rename to src/plugins/kibana_usage_collection/server/collectors/localization/index.ts diff --git a/src/legacy/server/i18n/localization/telemetry_localization_collector.test.ts b/src/plugins/kibana_usage_collection/server/collectors/localization/telemetry_localization_collector.test.ts similarity index 100% rename from src/legacy/server/i18n/localization/telemetry_localization_collector.test.ts rename to src/plugins/kibana_usage_collection/server/collectors/localization/telemetry_localization_collector.test.ts diff --git a/src/legacy/server/i18n/localization/telemetry_localization_collector.ts b/src/plugins/kibana_usage_collection/server/collectors/localization/telemetry_localization_collector.ts similarity index 82% rename from src/legacy/server/i18n/localization/telemetry_localization_collector.ts rename to src/plugins/kibana_usage_collection/server/collectors/localization/telemetry_localization_collector.ts index fb837f5ae28df..f2b00bd629a07 100644 --- a/src/legacy/server/i18n/localization/telemetry_localization_collector.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/localization/telemetry_localization_collector.ts @@ -20,6 +20,7 @@ import { i18nLoader } from '@kbn/i18n'; import { size } from 'lodash'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; +import { I18nServiceSetup } from '../../../../../core/server'; import { getIntegrityHashes, Integrities } from './file_integrity'; export interface UsageStats { @@ -28,11 +29,6 @@ export interface UsageStats { labelsCount?: number; } -export interface LocalizationUsageCollectorHelpers { - getLocale: () => string; - getTranslationsFilePaths: () => string[]; -} - export async function getTranslationCount( loader: typeof i18nLoader, locale: string @@ -41,13 +37,10 @@ export async function getTranslationCount( return size(translations.messages); } -export function createCollectorFetch({ - getLocale, - getTranslationsFilePaths, -}: LocalizationUsageCollectorHelpers) { +export function createCollectorFetch({ getLocale, getTranslationFiles }: I18nServiceSetup) { return async function fetchUsageStats(): Promise { const locale = getLocale(); - const translationFilePaths: string[] = getTranslationsFilePaths(); + const translationFilePaths: string[] = getTranslationFiles(); const [labelsCount, integrities] = await Promise.all([ getTranslationCount(i18nLoader, locale), @@ -62,15 +55,14 @@ export function createCollectorFetch({ }; } -// TODO: Migrate out of the Legacy dir export function registerLocalizationUsageCollector( usageCollection: UsageCollectionSetup, - helpers: LocalizationUsageCollectorHelpers + i18n: I18nServiceSetup ) { const collector = usageCollection.makeUsageCollector({ type: 'localization', isReady: () => true, - fetch: createCollectorFetch(helpers), + fetch: createCollectorFetch(i18n), schema: { locale: { type: 'keyword' }, integrities: { DYNAMIC_KEY: { type: 'text' } }, diff --git a/src/plugins/kibana_usage_collection/server/plugin.ts b/src/plugins/kibana_usage_collection/server/plugin.ts index 198fdbb7a8703..16cb620351aaa 100644 --- a/src/plugins/kibana_usage_collection/server/plugin.ts +++ b/src/plugins/kibana_usage_collection/server/plugin.ts @@ -41,6 +41,7 @@ import { registerUiMetricUsageCollector, registerCspCollector, registerCoreUsageCollector, + registerLocalizationUsageCollector, } from './collectors'; interface KibanaUsageCollectionPluginsDepsSetup { @@ -104,5 +105,6 @@ export class KibanaUsageCollectionPlugin implements Plugin { ); registerCspCollector(usageCollection, coreSetup.http); registerCoreUsageCollector(usageCollection, getCoreUsageDataService); + registerLocalizationUsageCollector(usageCollection, coreSetup.i18n); } } diff --git a/src/plugins/telemetry/schema/legacy_plugins.json b/src/plugins/telemetry/schema/legacy_plugins.json index 1a7c0ccb15082..d5b0514b64918 100644 --- a/src/plugins/telemetry/schema/legacy_plugins.json +++ b/src/plugins/telemetry/schema/legacy_plugins.json @@ -1,21 +1,3 @@ { - "properties": { - "localization": { - "properties": { - "locale": { - "type": "keyword" - }, - "integrities": { - "properties": { - "DYNAMIC_KEY": { - "type": "text" - } - } - }, - "labelsCount": { - "type": "long" - } - } - } - } + "properties": {} } diff --git a/src/plugins/telemetry/schema/oss_plugins.json b/src/plugins/telemetry/schema/oss_plugins.json index c840cbe8fc94d..a1eae69ffaed0 100644 --- a/src/plugins/telemetry/schema/oss_plugins.json +++ b/src/plugins/telemetry/schema/oss_plugins.json @@ -1581,6 +1581,23 @@ } } }, + "localization": { + "properties": { + "locale": { + "type": "keyword" + }, + "integrities": { + "properties": { + "DYNAMIC_KEY": { + "type": "text" + } + } + }, + "labelsCount": { + "type": "long" + } + } + }, "stack_management": { "properties": { "visualize:enableLabs": { From e909cee7f1a9206dbd3822fe92b36890b29dec6c Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 10 Nov 2020 09:49:20 -0500 Subject: [PATCH 19/80] [Maps] add on-prem EMS config (#82525) Adds.a new `map.emsUrl` setting. User can configure this to the location of a local on-prem installation of EMS. For this setting to take effect, the cluster must be configured with an enterprise license. --- .../maps_legacy/common/ems_defaults.ts | 25 ++ src/plugins/maps_legacy/common/index.ts | 20 ++ src/plugins/maps_legacy/config.ts | 19 +- src/plugins/maps_legacy/kibana.json | 1 + src/plugins/maps_legacy/public/index.ts | 1 + .../public/map/service_settings.js | 2 +- src/plugins/maps_legacy/server/index.ts | 1 + .../plugins/maps/common/ems_settings.test.ts | 221 ++++++++++++++++++ x-pack/plugins/maps/common/ems_settings.ts | 91 ++++++++ .../ems_boundaries_layer_wizard.tsx | 5 +- .../ems_base_map_layer_wizard.tsx | 5 +- .../components/ems_unavailable_message.tsx | 7 +- x-pack/plugins/maps/public/kibana_services.ts | 17 +- .../plugins/maps/public/licensed_features.ts | 8 + x-pack/plugins/maps/public/meta.test.js | 42 +++- x-pack/plugins/maps/public/meta.ts | 31 ++- x-pack/plugins/maps/public/plugin.ts | 11 +- .../bootstrap/get_initial_layers.test.js | 18 +- .../routing/bootstrap/get_initial_layers.ts | 4 +- x-pack/plugins/maps/server/plugin.ts | 20 +- x-pack/plugins/maps/server/routes.js | 80 ++++--- 21 files changed, 532 insertions(+), 97 deletions(-) create mode 100644 src/plugins/maps_legacy/common/ems_defaults.ts create mode 100644 src/plugins/maps_legacy/common/index.ts create mode 100644 x-pack/plugins/maps/common/ems_settings.test.ts create mode 100644 x-pack/plugins/maps/common/ems_settings.ts diff --git a/src/plugins/maps_legacy/common/ems_defaults.ts b/src/plugins/maps_legacy/common/ems_defaults.ts new file mode 100644 index 0000000000000..583dca1dbf036 --- /dev/null +++ b/src/plugins/maps_legacy/common/ems_defaults.ts @@ -0,0 +1,25 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// Default config for the elastic hosted EMS endpoints +export const DEFAULT_EMS_FILE_API_URL = 'https://vector.maps.elastic.co'; +export const DEFAULT_EMS_TILE_API_URL = 'https://tiles.maps.elastic.co'; +export const DEFAULT_EMS_LANDING_PAGE_URL = 'https://maps.elastic.co/v7.10'; +export const DEFAULT_EMS_FONT_LIBRARY_URL = + 'https://tiles.maps.elastic.co/fonts/{fontstack}/{range}.pbf'; diff --git a/src/plugins/maps_legacy/common/index.ts b/src/plugins/maps_legacy/common/index.ts new file mode 100644 index 0000000000000..12148ec1ec6b8 --- /dev/null +++ b/src/plugins/maps_legacy/common/index.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export * from './ems_defaults'; diff --git a/src/plugins/maps_legacy/config.ts b/src/plugins/maps_legacy/config.ts index f49d56dedd45f..68595944e68b3 100644 --- a/src/plugins/maps_legacy/config.ts +++ b/src/plugins/maps_legacy/config.ts @@ -21,18 +21,29 @@ import { schema, TypeOf } from '@kbn/config-schema'; import { configSchema as tilemapSchema } from '../tile_map/config'; import { configSchema as regionmapSchema } from '../region_map/config'; +import { + DEFAULT_EMS_FONT_LIBRARY_URL, + DEFAULT_EMS_LANDING_PAGE_URL, + DEFAULT_EMS_TILE_API_URL, + DEFAULT_EMS_FILE_API_URL, +} from './common/ems_defaults'; + export const configSchema = schema.object({ includeElasticMapsService: schema.boolean({ defaultValue: true }), proxyElasticMapsServiceInMaps: schema.boolean({ defaultValue: false }), tilemap: tilemapSchema, regionmap: regionmapSchema, manifestServiceUrl: schema.string({ defaultValue: '' }), - emsFileApiUrl: schema.string({ defaultValue: 'https://vector.maps.elastic.co' }), - emsTileApiUrl: schema.string({ defaultValue: 'https://tiles.maps.elastic.co' }), - emsLandingPageUrl: schema.string({ defaultValue: 'https://maps.elastic.co/v7.10' }), + + emsUrl: schema.string({ defaultValue: '' }), + + emsFileApiUrl: schema.string({ defaultValue: DEFAULT_EMS_FILE_API_URL }), + emsTileApiUrl: schema.string({ defaultValue: DEFAULT_EMS_TILE_API_URL }), + emsLandingPageUrl: schema.string({ defaultValue: DEFAULT_EMS_LANDING_PAGE_URL }), emsFontLibraryUrl: schema.string({ - defaultValue: 'https://tiles.maps.elastic.co/fonts/{fontstack}/{range}.pbf', + defaultValue: DEFAULT_EMS_FONT_LIBRARY_URL, }), + emsTileLayerId: schema.object({ bright: schema.string({ defaultValue: 'road_map' }), desaturated: schema.string({ defaultValue: 'road_map_desaturated' }), diff --git a/src/plugins/maps_legacy/kibana.json b/src/plugins/maps_legacy/kibana.json index d9bf33e661368..1499b3de446b5 100644 --- a/src/plugins/maps_legacy/kibana.json +++ b/src/plugins/maps_legacy/kibana.json @@ -5,5 +5,6 @@ "configPath": ["map"], "ui": true, "server": true, + "extraPublicDirs": ["common"], "requiredBundles": ["kibanaReact", "charts"] } diff --git a/src/plugins/maps_legacy/public/index.ts b/src/plugins/maps_legacy/public/index.ts index fe5338b890ec8..2654ded907cce 100644 --- a/src/plugins/maps_legacy/public/index.ts +++ b/src/plugins/maps_legacy/public/index.ts @@ -59,6 +59,7 @@ export { mapTooltipProvider, }; +export * from '../common'; export * from './common/types'; export { ORIGIN } from './common/constants/origin'; diff --git a/src/plugins/maps_legacy/public/map/service_settings.js b/src/plugins/maps_legacy/public/map/service_settings.js index 833304378402a..7a00456b89a92 100644 --- a/src/plugins/maps_legacy/public/map/service_settings.js +++ b/src/plugins/maps_legacy/public/map/service_settings.js @@ -128,7 +128,7 @@ export class ServiceSettings { allServices.push(tmsService); } - if (this._mapConfig.includeElasticMapsService) { + if (this._mapConfig.includeElasticMapsService && !this._mapConfig.emsUrl) { const servicesFromManifest = await this._emsClient.getTMSServices(); const strippedServiceFromManifest = await Promise.all( servicesFromManifest diff --git a/src/plugins/maps_legacy/server/index.ts b/src/plugins/maps_legacy/server/index.ts index 665b3b8986ef0..ba37df60f9357 100644 --- a/src/plugins/maps_legacy/server/index.ts +++ b/src/plugins/maps_legacy/server/index.ts @@ -30,6 +30,7 @@ export const config: PluginConfigDescriptor = { tilemap: true, regionmap: true, manifestServiceUrl: true, + emsUrl: true, emsFileApiUrl: true, emsTileApiUrl: true, emsLandingPageUrl: true, diff --git a/x-pack/plugins/maps/common/ems_settings.test.ts b/x-pack/plugins/maps/common/ems_settings.test.ts new file mode 100644 index 0000000000000..69ae7069129cb --- /dev/null +++ b/x-pack/plugins/maps/common/ems_settings.test.ts @@ -0,0 +1,221 @@ +/* + * 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 { EMSSettings, IEMSConfig } from './ems_settings'; +import { + DEFAULT_EMS_FILE_API_URL, + DEFAULT_EMS_FONT_LIBRARY_URL, + DEFAULT_EMS_LANDING_PAGE_URL, + DEFAULT_EMS_TILE_API_URL, +} from '../../../../src/plugins/maps_legacy/common'; + +const IS_ENTERPRISE_PLUS = () => true; + +describe('EMSSettings', () => { + const mockConfig: IEMSConfig = { + includeElasticMapsService: true, + proxyElasticMapsServiceInMaps: false, + emsUrl: '', + emsFileApiUrl: DEFAULT_EMS_FILE_API_URL, + emsTileApiUrl: DEFAULT_EMS_TILE_API_URL, + emsLandingPageUrl: DEFAULT_EMS_LANDING_PAGE_URL, + emsFontLibraryUrl: DEFAULT_EMS_FONT_LIBRARY_URL, + isEMSEnabled: true, + }; + + describe('isEMSEnabled/isOnPrem', () => { + test('should validate defaults', () => { + const emsSettings = new EMSSettings(mockConfig, IS_ENTERPRISE_PLUS); + expect(emsSettings.isEMSEnabled()).toBe(true); + expect(emsSettings.isOnPrem()).toBe(false); + }); + + test('should validate if on-prem is turned on', () => { + const emsSettings = new EMSSettings( + { + ...mockConfig, + ...{ + emsUrl: 'https://localhost:8080', + }, + }, + IS_ENTERPRISE_PLUS + ); + expect(emsSettings.isEMSEnabled()).toBe(true); + expect(emsSettings.isOnPrem()).toBe(true); + }); + + test('should not validate if ems turned off', () => { + const emsSettings = new EMSSettings( + { + ...mockConfig, + ...{ + includeElasticMapsService: false, + }, + }, + IS_ENTERPRISE_PLUS + ); + expect(emsSettings.isEMSEnabled()).toBe(false); + expect(emsSettings.isOnPrem()).toBe(false); + }); + + test('should work if ems is turned off, but on-prem is turned on', () => { + const emsSettings = new EMSSettings( + { + ...mockConfig, + ...{ + emsUrl: 'https://localhost:8080', + includeElasticMapsService: false, + }, + }, + IS_ENTERPRISE_PLUS + ); + expect(emsSettings.isEMSEnabled()).toBe(true); + expect(emsSettings.isOnPrem()).toBe(true); + }); + + describe('when license is turned off', () => { + test('should not be enabled', () => { + const emsSettings = new EMSSettings( + { + ...mockConfig, + ...{ + emsUrl: 'https://localhost:8080', + }, + }, + () => false + ); + expect(emsSettings.isEMSEnabled()).toBe(false); + expect(emsSettings.isOnPrem()).toBe(true); + }); + }); + }); + + describe('emsUrl setting', () => { + describe('when emsUrl is not set', () => { + test('should respect defaults', () => { + const emsSettings = new EMSSettings(mockConfig, IS_ENTERPRISE_PLUS); + expect(emsSettings.getEMSFileApiUrl()).toBe(DEFAULT_EMS_FILE_API_URL); + expect(emsSettings.getEMSTileApiUrl()).toBe(DEFAULT_EMS_TILE_API_URL); + expect(emsSettings.getEMSFontLibraryUrl()).toBe(DEFAULT_EMS_FONT_LIBRARY_URL); + expect(emsSettings.getEMSLandingPageUrl()).toBe(DEFAULT_EMS_LANDING_PAGE_URL); + }); + test('should apply overrides', () => { + const emsSettings = new EMSSettings( + { + ...mockConfig, + ...{ + emsFileApiUrl: 'https://file.foobar', + emsTileApiUrl: 'https://tile.foobar', + emsFontLibraryUrl: 'https://tile.foobar/font', + emsLandingPageUrl: 'https://maps.foobar/v7.666', + }, + }, + IS_ENTERPRISE_PLUS + ); + expect(emsSettings.getEMSFileApiUrl()).toBe('https://file.foobar'); + expect(emsSettings.getEMSTileApiUrl()).toBe('https://tile.foobar'); + expect(emsSettings.getEMSFontLibraryUrl()).toBe('https://tile.foobar/font'); + expect(emsSettings.getEMSLandingPageUrl()).toBe('https://maps.foobar/v7.666'); + }); + }); + + describe('when emsUrl is set', () => { + test('should override defaults', () => { + const emsSettings = new EMSSettings( + { + ...mockConfig, + ...{ + emsUrl: 'https://localhost:8080', + }, + }, + IS_ENTERPRISE_PLUS + ); + expect(emsSettings.getEMSFileApiUrl()).toBe('https://localhost:8080/file'); + expect(emsSettings.getEMSTileApiUrl()).toBe('https://localhost:8080/tile'); + expect(emsSettings.getEMSFontLibraryUrl()).toBe( + 'https://localhost:8080/tile/fonts/{fontstack}/{range}.pbf' + ); + expect(emsSettings.getEMSLandingPageUrl()).toBe('https://localhost:8080/maps'); + }); + + describe('internal settings overrides (the below behavior is not publically supported, but aids internal debugging use-cases)', () => { + test(`should override internal emsFileApiUrl`, () => { + const emsSettings = new EMSSettings( + { + ...mockConfig, + ...{ + emsUrl: 'https://localhost:8080', + emsFileApiUrl: 'https://file.foobar', + }, + }, + IS_ENTERPRISE_PLUS + ); + expect(emsSettings.getEMSFileApiUrl()).toBe('https://file.foobar'); + expect(emsSettings.getEMSTileApiUrl()).toBe('https://localhost:8080/tile'); + expect(emsSettings.getEMSFontLibraryUrl()).toBe( + 'https://localhost:8080/tile/fonts/{fontstack}/{range}.pbf' + ); + expect(emsSettings.getEMSLandingPageUrl()).toBe('https://localhost:8080/maps'); + }); + + test(`should override internal emsTileApiUrl`, () => { + const emsSettings = new EMSSettings( + { + ...mockConfig, + ...{ + emsUrl: 'https://localhost:8080', + emsTileApiUrl: 'https://tile.foobar', + }, + }, + IS_ENTERPRISE_PLUS + ); + expect(emsSettings.getEMSFileApiUrl()).toBe('https://localhost:8080/file'); + expect(emsSettings.getEMSTileApiUrl()).toBe('https://tile.foobar'); + expect(emsSettings.getEMSFontLibraryUrl()).toBe( + 'https://localhost:8080/tile/fonts/{fontstack}/{range}.pbf' + ); + expect(emsSettings.getEMSLandingPageUrl()).toBe('https://localhost:8080/maps'); + }); + + test('should override internal emsFontLibraryUrl', () => { + const emsSettings = new EMSSettings( + { + ...mockConfig, + ...{ + emsUrl: 'https://localhost:8080', + emsFontLibraryUrl: 'https://maps.foobar/fonts', + }, + }, + IS_ENTERPRISE_PLUS + ); + expect(emsSettings.getEMSFileApiUrl()).toBe('https://localhost:8080/file'); + expect(emsSettings.getEMSTileApiUrl()).toBe('https://localhost:8080/tile'); + expect(emsSettings.getEMSFontLibraryUrl()).toBe('https://maps.foobar/fonts'); + expect(emsSettings.getEMSLandingPageUrl()).toBe('https://localhost:8080/maps'); + }); + + test('should override internal emsLandingPageUrl', () => { + const emsSettings = new EMSSettings( + { + ...mockConfig, + ...{ + emsUrl: 'https://localhost:8080', + emsLandingPageUrl: 'https://maps.foobar', + }, + }, + IS_ENTERPRISE_PLUS + ); + expect(emsSettings.getEMSFileApiUrl()).toBe('https://localhost:8080/file'); + expect(emsSettings.getEMSTileApiUrl()).toBe('https://localhost:8080/tile'); + expect(emsSettings.getEMSFontLibraryUrl()).toBe( + 'https://localhost:8080/tile/fonts/{fontstack}/{range}.pbf' + ); + expect(emsSettings.getEMSLandingPageUrl()).toBe('https://maps.foobar'); + }); + }); + }); + }); +}); diff --git a/x-pack/plugins/maps/common/ems_settings.ts b/x-pack/plugins/maps/common/ems_settings.ts new file mode 100644 index 0000000000000..0f4d211f0e963 --- /dev/null +++ b/x-pack/plugins/maps/common/ems_settings.ts @@ -0,0 +1,91 @@ +/* + * 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 { + DEFAULT_EMS_FILE_API_URL, + DEFAULT_EMS_FONT_LIBRARY_URL, + DEFAULT_EMS_LANDING_PAGE_URL, + DEFAULT_EMS_TILE_API_URL, +} from '../../../../src/plugins/maps_legacy/common'; + +export interface IEMSConfig { + emsUrl?: string; + includeElasticMapsService?: boolean; + proxyElasticMapsServiceInMaps?: boolean; + emsFileApiUrl?: string; + emsTileApiUrl?: string; + emsLandingPageUrl?: string; + emsFontLibraryUrl?: string; + isEMSEnabled?: boolean; +} + +export class EMSSettings { + private readonly _config: IEMSConfig; + private readonly _getIsEnterprisePlus: () => boolean; + + constructor(config: IEMSConfig, getIsEnterPrisePlus: () => boolean) { + this._config = config; + this._getIsEnterprisePlus = getIsEnterPrisePlus; + } + + _isEMSUrlSet() { + return !!this._config.emsUrl; + } + + _getEMSRoot() { + return this._config.emsUrl!.replace(/\/$/, ''); + } + + isOnPrem(): boolean { + return this._isEMSUrlSet(); + } + + isIncludeElasticMapsService() { + return !!this._config.includeElasticMapsService; + } + + isEMSEnabled(): boolean { + if (this._isEMSUrlSet()) { + return this._getIsEnterprisePlus(); + } + return this.isIncludeElasticMapsService(); + } + + getEMSFileApiUrl(): string { + if (this._config.emsFileApiUrl !== DEFAULT_EMS_FILE_API_URL || !this._isEMSUrlSet()) { + return this._config.emsFileApiUrl!; + } else { + return `${this._getEMSRoot()}/file`; + } + } + + isProxyElasticMapsServiceInMaps(): boolean { + return !!this._config.proxyElasticMapsServiceInMaps; + } + + getEMSTileApiUrl(): string { + if (this._config.emsTileApiUrl !== DEFAULT_EMS_TILE_API_URL || !this._isEMSUrlSet()) { + return this._config.emsTileApiUrl!; + } else { + return `${this._getEMSRoot()}/tile`; + } + } + getEMSLandingPageUrl(): string { + if (this._config.emsLandingPageUrl !== DEFAULT_EMS_LANDING_PAGE_URL || !this._isEMSUrlSet()) { + return this._config.emsLandingPageUrl!; + } else { + return `${this._getEMSRoot()}/maps`; + } + } + + getEMSFontLibraryUrl(): string { + if (this._config.emsFontLibraryUrl !== DEFAULT_EMS_FONT_LIBRARY_URL || !this._isEMSUrlSet()) { + return this._config.emsFontLibraryUrl!; + } else { + return `${this._getEMSRoot()}/tile/fonts/{fontstack}/{range}.pbf`; + } + } +} diff --git a/x-pack/plugins/maps/public/classes/sources/ems_file_source/ems_boundaries_layer_wizard.tsx b/x-pack/plugins/maps/public/classes/sources/ems_file_source/ems_boundaries_layer_wizard.tsx index 8d4d57e524276..768bbd1d94700 100644 --- a/x-pack/plugins/maps/public/classes/sources/ems_file_source/ems_boundaries_layer_wizard.tsx +++ b/x-pack/plugins/maps/public/classes/sources/ems_file_source/ems_boundaries_layer_wizard.tsx @@ -11,14 +11,15 @@ import { LayerWizard, RenderWizardArguments } from '../../layers/layer_wizard_re import { EMSFileCreateSourceEditor } from './create_source_editor'; import { EMSFileSource, sourceTitle } from './ems_file_source'; // @ts-ignore -import { getIsEmsEnabled } from '../../../kibana_services'; +import { getEMSSettings } from '../../../kibana_services'; import { EMSFileSourceDescriptor } from '../../../../common/descriptor_types'; import { LAYER_WIZARD_CATEGORY } from '../../../../common/constants'; export const emsBoundariesLayerWizardConfig: LayerWizard = { categories: [LAYER_WIZARD_CATEGORY.REFERENCE], checkVisibility: async () => { - return getIsEmsEnabled(); + const emsSettings = getEMSSettings(); + return emsSettings!.isEMSEnabled(); }, description: i18n.translate('xpack.maps.source.emsFileDescription', { defaultMessage: 'Administrative boundaries from Elastic Maps Service', diff --git a/x-pack/plugins/maps/public/classes/sources/ems_tms_source/ems_base_map_layer_wizard.tsx b/x-pack/plugins/maps/public/classes/sources/ems_tms_source/ems_base_map_layer_wizard.tsx index 315759a2eba29..bfa46574f007a 100644 --- a/x-pack/plugins/maps/public/classes/sources/ems_tms_source/ems_base_map_layer_wizard.tsx +++ b/x-pack/plugins/maps/public/classes/sources/ems_tms_source/ems_base_map_layer_wizard.tsx @@ -13,13 +13,14 @@ import { EMSTMSSource, sourceTitle } from './ems_tms_source'; import { VectorTileLayer } from '../../layers/vector_tile_layer/vector_tile_layer'; // @ts-ignore import { TileServiceSelect } from './tile_service_select'; -import { getIsEmsEnabled } from '../../../kibana_services'; +import { getEMSSettings } from '../../../kibana_services'; import { LAYER_WIZARD_CATEGORY } from '../../../../common/constants'; export const emsBaseMapLayerWizardConfig: LayerWizard = { categories: [LAYER_WIZARD_CATEGORY.REFERENCE], checkVisibility: async () => { - return getIsEmsEnabled(); + const emsSettings = getEMSSettings(); + return emsSettings!.isEMSEnabled(); }, description: i18n.translate('xpack.maps.source.emsTileDescription', { defaultMessage: 'Tile map service from Elastic Maps Service', diff --git a/x-pack/plugins/maps/public/components/ems_unavailable_message.tsx b/x-pack/plugins/maps/public/components/ems_unavailable_message.tsx index dea161fafd609..ba897b7d9da0c 100644 --- a/x-pack/plugins/maps/public/components/ems_unavailable_message.tsx +++ b/x-pack/plugins/maps/public/components/ems_unavailable_message.tsx @@ -5,15 +5,14 @@ */ import { i18n } from '@kbn/i18n'; -// @ts-ignore -import { getIsEmsEnabled } from '../kibana_services'; +import { getEMSSettings } from '../kibana_services'; export function getEmsUnavailableMessage(): string { - const isEmsEnabled = getIsEmsEnabled(); + const isEmsEnabled = getEMSSettings().isEMSEnabled(); if (isEmsEnabled) { return i18n.translate('xpack.maps.source.ems.noAccessDescription', { defaultMessage: - 'Kibana is unable to access Elastic Maps Service. Contact your system administrator', + 'Kibana is unable to access Elastic Maps Service. Contact your system administrator.', }); } diff --git a/x-pack/plugins/maps/public/kibana_services.ts b/x-pack/plugins/maps/public/kibana_services.ts index 08ee4b6628dd1..782c37a72d99b 100644 --- a/x-pack/plugins/maps/public/kibana_services.ts +++ b/x-pack/plugins/maps/public/kibana_services.ts @@ -9,6 +9,7 @@ import { CoreStart } from 'kibana/public'; import { MapsLegacyConfig } from '../../../../src/plugins/maps_legacy/config'; import { MapsConfigType } from '../config'; import { MapsPluginStartDependencies } from './plugin'; +import { EMSSettings } from '../common/ems_settings'; let kibanaVersion: string; export const setKibanaVersion = (version: string) => (kibanaVersion = version); @@ -62,14 +63,16 @@ let kibanaCommonConfig: MapsLegacyConfig; export const setKibanaCommonConfig = (config: MapsLegacyConfig) => (kibanaCommonConfig = config); export const getKibanaCommonConfig = () => kibanaCommonConfig; -export const getIsEmsEnabled = () => getKibanaCommonConfig().includeElasticMapsService; -export const getEmsFontLibraryUrl = () => getKibanaCommonConfig().emsFontLibraryUrl; +let emsSettings: EMSSettings; +export const setEMSSettings = (value: EMSSettings) => { + emsSettings = value; +}; +export const getEMSSettings = () => { + return emsSettings; +}; + export const getEmsTileLayerId = () => getKibanaCommonConfig().emsTileLayerId; -export const getEmsFileApiUrl = () => getKibanaCommonConfig().emsFileApiUrl; -export const getEmsTileApiUrl = () => getKibanaCommonConfig().emsTileApiUrl; -export const getEmsLandingPageUrl = () => getKibanaCommonConfig().emsLandingPageUrl; -export const getProxyElasticMapsServiceInMaps = () => - getKibanaCommonConfig().proxyElasticMapsServiceInMaps; + export const getRegionmapLayers = () => _.get(getKibanaCommonConfig(), 'regionmap.layers', []); export const getTilemap = () => _.get(getKibanaCommonConfig(), 'tilemap', []); diff --git a/x-pack/plugins/maps/public/licensed_features.ts b/x-pack/plugins/maps/public/licensed_features.ts index 67fa526da0cbd..13809f2b26a8c 100644 --- a/x-pack/plugins/maps/public/licensed_features.ts +++ b/x-pack/plugins/maps/public/licensed_features.ts @@ -27,9 +27,13 @@ export const LICENCED_FEATURES_DETAILS: Record licenseId; export const getIsGoldPlus = () => isGoldPlus; +export const getIsEnterprisePlus = () => isEnterprisePlus; + export function registerLicensedFeatures(licensingPlugin: LicensingPluginSetup) { for (const licensedFeature of Object.values(LICENSED_FEATURES)) { licensingPlugin.featureUsage.register( @@ -45,6 +49,10 @@ export function setLicensingPluginStart(licensingPlugin: LicensingPluginStart) { licensingPluginStart.license$.subscribe((license: ILicense) => { const gold = license.check(APP_ID, 'gold'); isGoldPlus = gold.state === 'valid'; + + const enterprise = license.check(APP_ID, 'enterprise'); + isEnterprisePlus = enterprise.state === 'valid'; + licenseId = license.uid; }); } diff --git a/x-pack/plugins/maps/public/meta.test.js b/x-pack/plugins/maps/public/meta.test.js index c414c8a2d400e..d4f9885830b54 100644 --- a/x-pack/plugins/maps/public/meta.test.js +++ b/x-pack/plugins/maps/public/meta.test.js @@ -9,14 +9,22 @@ import { getEMSClient, getGlyphUrl } from './meta'; jest.mock('@elastic/ems-client'); +const EMS_FONTS_URL_MOCK = 'ems/fonts'; +const MOCK_EMS_SETTINGS = { + isEMSEnabled: () => true, + getEMSFileApiUrl: () => 'https://file-api', + getEMSTileApiUrl: () => 'https://tile-api', + getEMSLandingPageUrl: () => 'http://test.com', + getEMSFontLibraryUrl: () => EMS_FONTS_URL_MOCK, + isProxyElasticMapsServiceInMaps: () => false, +}; + describe('default use without proxy', () => { beforeEach(() => { - require('./kibana_services').getProxyElasticMapsServiceInMaps = () => false; - require('./kibana_services').getIsEmsEnabled = () => true; require('./kibana_services').getEmsTileLayerId = () => '123'; - require('./kibana_services').getEmsFileApiUrl = () => 'https://file-api'; - require('./kibana_services').getEmsTileApiUrl = () => 'https://tile-api'; - require('./kibana_services').getEmsLandingPageUrl = () => 'http://test.com'; + require('./kibana_services').getEMSSettings = () => { + return MOCK_EMS_SETTINGS; + }; require('./licensed_features').getLicenseId = () => { return 'foobarlicenseid'; }; @@ -32,10 +40,7 @@ describe('default use without proxy', () => { describe('getGlyphUrl', () => { describe('EMS enabled', () => { - const EMS_FONTS_URL_MOCK = 'ems/fonts'; beforeAll(() => { - require('./kibana_services').getIsEmsEnabled = () => true; - require('./kibana_services').getEmsFontLibraryUrl = () => EMS_FONTS_URL_MOCK; require('./kibana_services').getHttp = () => ({ basePath: { prepend: (url) => url, // No need to actually prepend a dev basepath for test @@ -45,7 +50,12 @@ describe('getGlyphUrl', () => { describe('EMS proxy enabled', () => { beforeAll(() => { - require('./kibana_services').getProxyElasticMapsServiceInMaps = () => true; + require('./kibana_services').getEMSSettings = () => { + return { + ...MOCK_EMS_SETTINGS, + isProxyElasticMapsServiceInMaps: () => true, + }; + }; }); test('should return proxied EMS fonts URL', async () => { @@ -55,7 +65,12 @@ describe('getGlyphUrl', () => { describe('EMS proxy disabled', () => { beforeAll(() => { - require('./kibana_services').getProxyElasticMapsServiceInMaps = () => false; + require('./kibana_services').getEMSSettings = () => { + return { + ...MOCK_EMS_SETTINGS, + isProxyElasticMapsServiceInMaps: () => false, + }; + }; }); test('should return EMS fonts URL', async () => { @@ -72,7 +87,12 @@ describe('getGlyphUrl', () => { }, }; require('./kibana_services').getHttp = () => mockHttp; - require('./kibana_services').getIsEmsEnabled = () => false; + require('./kibana_services').getEMSSettings = () => { + return { + ...MOCK_EMS_SETTINGS, + isEMSEnabled: () => false, + }; + }; }); test('should return kibana fonts URL', async () => { diff --git a/x-pack/plugins/maps/public/meta.ts b/x-pack/plugins/maps/public/meta.ts index 929050338de72..5632e226478a7 100644 --- a/x-pack/plugins/maps/public/meta.ts +++ b/x-pack/plugins/maps/public/meta.ts @@ -18,15 +18,10 @@ import { } from '../common/constants'; import { getHttp, - getIsEmsEnabled, getRegionmapLayers, getTilemap, - getEmsFileApiUrl, - getEmsTileApiUrl, - getEmsLandingPageUrl, - getEmsFontLibraryUrl, - getProxyElasticMapsServiceInMaps, getKibanaVersion, + getEMSSettings, } from './kibana_services'; import { getLicenseId } from './licensed_features'; import { LayerConfig } from '../../../../src/plugins/region_map/config'; @@ -40,7 +35,7 @@ export function getKibanaTileMap(): unknown { } export async function getEmsFileLayers(): Promise { - if (!getIsEmsEnabled()) { + if (!getEMSSettings().isEMSEnabled()) { return []; } @@ -48,7 +43,7 @@ export async function getEmsFileLayers(): Promise { } export async function getEmsTmsServices(): Promise { - if (!getIsEmsEnabled()) { + if (!getEMSSettings().isEMSEnabled()) { return []; } @@ -65,18 +60,18 @@ let emsClient: EMSClient | null = null; let latestLicenseId: string | undefined; export function getEMSClient(): EMSClient { if (!emsClient) { - const proxyElasticMapsServiceInMaps = getProxyElasticMapsServiceInMaps(); + const emsSettings = getEMSSettings(); const proxyPath = ''; - const tileApiUrl = proxyElasticMapsServiceInMaps + const tileApiUrl = emsSettings!.isProxyElasticMapsServiceInMaps() ? relativeToAbsolute( getHttp().basePath.prepend(`/${GIS_API_PATH}/${EMS_TILES_CATALOGUE_PATH}`) ) - : getEmsTileApiUrl(); - const fileApiUrl = proxyElasticMapsServiceInMaps + : emsSettings!.getEMSTileApiUrl(); + const fileApiUrl = emsSettings!.isProxyElasticMapsServiceInMaps() ? relativeToAbsolute( getHttp().basePath.prepend(`/${GIS_API_PATH}/${EMS_FILES_CATALOGUE_PATH}`) ) - : getEmsFileApiUrl(); + : emsSettings!.getEMSFileApiUrl(); emsClient = new EMSClient({ language: i18n.getLocale(), @@ -84,7 +79,7 @@ export function getEMSClient(): EMSClient { appName: EMS_APP_NAME, tileApiUrl, fileApiUrl, - landingPageUrl: getEmsLandingPageUrl(), + landingPageUrl: emsSettings!.getEMSLandingPageUrl(), fetchFunction(url: string) { return fetch(url); }, @@ -100,16 +95,18 @@ export function getEMSClient(): EMSClient { } export function getGlyphUrl(): string { - if (!getIsEmsEnabled()) { + const emsSettings = getEMSSettings(); + if (!emsSettings!.isEMSEnabled()) { return getHttp().basePath.prepend(`/${FONTS_API_PATH}/{fontstack}/{range}`); } - return getProxyElasticMapsServiceInMaps() + + return emsSettings!.isProxyElasticMapsServiceInMaps() ? relativeToAbsolute( getHttp().basePath.prepend( `/${GIS_API_PATH}/${EMS_TILES_CATALOGUE_PATH}/${EMS_GLYPHS_PATH}` ) ) + `/{fontstack}/{range}` - : getEmsFontLibraryUrl(); + : emsSettings!.getEMSFontLibraryUrl(); } export function isRetina(): boolean { diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index 75a3f8ef5ede8..b79a2b06b9b37 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -19,6 +19,7 @@ import { // @ts-ignore import { MapView } from './inspector/views/map_view'; import { + setEMSSettings, setKibanaCommonConfig, setKibanaVersion, setMapAppConfig, @@ -55,7 +56,12 @@ import { DataPublicPluginStart } from '../../../../src/plugins/data/public'; import { LicensingPluginSetup, LicensingPluginStart } from '../../licensing/public'; import { StartContract as FileUploadStartContract } from '../../file_upload/public'; import { SavedObjectsStart } from '../../../../src/plugins/saved_objects/public'; -import { registerLicensedFeatures, setLicensingPluginStart } from './licensed_features'; +import { + getIsEnterprisePlus, + registerLicensedFeatures, + setLicensingPluginStart, +} from './licensed_features'; +import { EMSSettings } from '../common/ems_settings'; export interface MapsPluginSetupDependencies { inspector: InspectorSetupContract; @@ -111,6 +117,9 @@ export class MapsPlugin setMapAppConfig(config); setKibanaVersion(this._initializerContext.env.packageInfo.version); + const emsSettings = new EMSSettings(plugins.mapsLegacy.config, getIsEnterprisePlus); + setEMSSettings(emsSettings); + // register url generators const getStartServices = async () => { const [coreStart] = await core.getStartServices(); diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.test.js b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.test.js index 4de29e6f028e1..66adb1da6900e 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.test.js +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.test.js @@ -15,7 +15,11 @@ const layerListNotProvided = undefined; describe('Saved object has layer list', () => { beforeEach(() => { - require('../../kibana_services').getIsEmsEnabled = () => true; + require('../../kibana_services').getEMSSettings = () => { + return { + isEMSEnabled: () => true, + }; + }; }); it('Should get initial layers from saved object', () => { @@ -65,7 +69,11 @@ describe('EMS is enabled', () => { require('../../meta').getKibanaTileMap = () => { return null; }; - require('../../kibana_services').getIsEmsEnabled = () => true; + require('../../kibana_services').getEMSSettings = () => { + return { + isEMSEnabled: () => true, + }; + }; require('../../kibana_services').getEmsTileLayerId = () => ({ bright: 'road_map', desaturated: 'road_map_desaturated', @@ -101,7 +109,11 @@ describe('EMS is not enabled', () => { require('../../meta').getKibanaTileMap = () => { return null; }; - require('../../kibana_services').getIsEmsEnabled = () => false; + require('../../kibana_services').getEMSSettings = () => { + return { + isEMSEnabled: () => false, + }; + }; }); it('Should return empty layer list since there are no configured tile layers', () => { diff --git a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts index e828dc88409cb..c887320873995 100644 --- a/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts +++ b/x-pack/plugins/maps/public/routing/bootstrap/get_initial_layers.ts @@ -23,7 +23,7 @@ import { TileLayer } from '../../classes/layers/tile_layer/tile_layer'; import { EMSTMSSource } from '../../classes/sources/ems_tms_source'; // @ts-expect-error import { VectorTileLayer } from '../../classes/layers/vector_tile_layer/vector_tile_layer'; -import { getIsEmsEnabled, getToasts } from '../../kibana_services'; +import { getEMSSettings, getToasts } from '../../kibana_services'; import { INITIAL_LAYERS_KEY } from '../../../common/constants'; import { getKibanaTileMap } from '../../meta'; @@ -39,7 +39,7 @@ export function getInitialLayers(layerListJSON?: string, initialLayers: LayerDes return [layerDescriptor, ...initialLayers]; } - const isEmsEnabled = getIsEmsEnabled(); + const isEmsEnabled = getEMSSettings()!.isEMSEnabled(); if (isEmsEnabled) { const layerDescriptor = VectorTileLayer.createDescriptor({ sourceDescriptor: EMSTMSSource.createDescriptor({ isAutoSelect: true }), diff --git a/x-pack/plugins/maps/server/plugin.ts b/x-pack/plugins/maps/server/plugin.ts index 00950e96047a0..65d79272494f0 100644 --- a/x-pack/plugins/maps/server/plugin.ts +++ b/x-pack/plugins/maps/server/plugin.ts @@ -28,7 +28,7 @@ import { ILicense } from '../../licensing/common/types'; import { LicensingPluginSetup } from '../../licensing/server'; import { HomeServerPluginSetup } from '../../../../src/plugins/home/server'; import { MapsLegacyPluginSetup } from '../../../../src/plugins/maps_legacy/server'; -import { MapsLegacyConfig } from '../../../../src/plugins/maps_legacy/config'; +import { EMSSettings } from '../common/ems_settings'; interface SetupDeps { features: FeaturesPluginSetupContract; @@ -52,7 +52,7 @@ export class MapsPlugin implements Plugin { _initHomeData( home: HomeServerPluginSetup, prependBasePath: (path: string) => string, - mapsLegacyConfig: MapsLegacyConfig + emsSettings: EMSSettings ) { const sampleDataLinkLabel = i18n.translate('xpack.maps.sampleDataLinkLabel', { defaultMessage: 'Map', @@ -125,7 +125,7 @@ export class MapsPlugin implements Plugin { home.tutorials.registerTutorial( emsBoundariesSpecProvider({ prependBasePath, - emsLandingPageUrl: mapsLegacyConfig.emsLandingPageUrl, + emsLandingPageUrl: emsSettings.getEMSLandingPageUrl(), }) ); } @@ -148,21 +148,27 @@ export class MapsPlugin implements Plugin { } let routesInitialized = false; + let isEnterprisePlus = false; + const emsSettings = new EMSSettings(mapsLegacyConfig, () => isEnterprisePlus); licensing.license$.subscribe((license: ILicense) => { - const { state } = license.check('maps', 'basic'); - if (state === 'valid' && !routesInitialized) { + const basic = license.check(APP_ID, 'basic'); + + const enterprise = license.check(APP_ID, 'enterprise'); + isEnterprisePlus = enterprise.state === 'valid'; + + if (basic.state === 'valid' && !routesInitialized) { routesInitialized = true; initRoutes( core.http.createRouter(), license.uid, - mapsLegacyConfig, + emsSettings, this.kibanaVersion, this._logger ); } }); - this._initHomeData(home, core.http.basePath.prepend, mapsLegacyConfig); + this._initHomeData(home, core.http.basePath.prepend, emsSettings); features.registerKibanaFeature({ id: APP_ID, diff --git a/x-pack/plugins/maps/server/routes.js b/x-pack/plugins/maps/server/routes.js index 5feacfee4d4d2..49d646f9a4e6d 100644 --- a/x-pack/plugins/maps/server/routes.js +++ b/x-pack/plugins/maps/server/routes.js @@ -33,38 +33,45 @@ import fs from 'fs'; import path from 'path'; import { initMVTRoutes } from './mvt/mvt_routes'; -export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) { +const EMPTY_EMS_CLIENT = { + async getFileLayers() { + return []; + }, + async getTMSServices() { + return []; + }, + async getMainManifest() { + return null; + }, + async getDefaultFileManifest() { + return null; + }, + async getDefaultTMSManifest() { + return null; + }, + addQueryParams() {}, +}; + +export function initRoutes(router, licenseUid, emsSettings, kbnVersion, logger) { let emsClient; - if (mapConfig.includeElasticMapsService) { + + if (emsSettings.isIncludeElasticMapsService()) { emsClient = new EMSClient({ language: i18n.getLocale(), appVersion: kbnVersion, appName: EMS_APP_NAME, - fileApiUrl: mapConfig.emsFileApiUrl, - tileApiUrl: mapConfig.emsTileApiUrl, - landingPageUrl: mapConfig.emsLandingPageUrl, + fileApiUrl: emsSettings.getEMSFileApiUrl(), + tileApiUrl: emsSettings.getEMSTileApiUrl(), + landingPageUrl: emsSettings.getEMSLandingPageUrl(), fetchFunction: fetch, }); emsClient.addQueryParams({ license: licenseUid }); } else { - emsClient = { - async getFileLayers() { - return []; - }, - async getTMSServices() { - return []; - }, - async getMainManifest() { - return null; - }, - async getDefaultFileManifest() { - return null; - }, - async getDefaultTMSManifest() { - return null; - }, - addQueryParams() {}, - }; + emsClient = EMPTY_EMS_CLIENT; + } + + function getEMSClient() { + return emsSettings.isEMSEnabled() ? emsClient : EMPTY_EMS_CLIENT; } router.get( @@ -90,7 +97,7 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) { return null; } - const fileLayers = await emsClient.getFileLayers(); + const fileLayers = await getEMSClient().getFileLayers(); const layer = fileLayers.find((layer) => layer.getId() === request.query.id); if (!layer) { return null; @@ -127,7 +134,7 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) { return null; } - const tmsServices = await emsClient.getTMSServices(); + const tmsServices = await getEMSClient().getTMSServices(); const tmsService = tmsServices.find((layer) => layer.getId() === request.query.id); if (!tmsService) { return null; @@ -153,7 +160,7 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) { return badRequest('map.proxyElasticMapsServiceInMaps disabled'); } - const main = await emsClient.getMainManifest(); + const main = await getEMSClient().getMainManifest(); const proxiedManifest = { services: [], }; @@ -189,8 +196,8 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) { return badRequest('map.proxyElasticMapsServiceInMaps disabled'); } - const file = await emsClient.getDefaultFileManifest(); //need raw manifest - const fileLayers = await emsClient.getFileLayers(); + const file = await getEMSClient().getDefaultFileManifest(); //need raw manifest + const fileLayers = await getEMSClient().getFileLayers(); const layers = file.layers.map((layerJson) => { const newLayerJson = { ...layerJson }; @@ -231,7 +238,7 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) { return badRequest('map.proxyElasticMapsServiceInMaps disabled'); } - const tilesManifest = await emsClient.getDefaultTMSManifest(); + const tilesManifest = await getEMSClient().getDefaultTMSManifest(); const newServices = tilesManifest.services.map((service) => { const newService = { ...service, @@ -284,7 +291,7 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) { return null; } - const tmsServices = await emsClient.getTMSServices(); + const tmsServices = await getEMSClient().getTMSServices(); const tmsService = tmsServices.find((layer) => layer.getId() === request.query.id); if (!tmsService) { return null; @@ -319,7 +326,7 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) { return badRequest('map.proxyElasticMapsServiceInMaps disabled'); } - const tmsServices = await emsClient.getTMSServices(); + const tmsServices = await getEMSClient().getTMSServices(); const tmsService = tmsServices.find((layer) => layer.getId() === request.query.id); if (!tmsService) { return null; @@ -368,7 +375,7 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) { return badRequest('map.proxyElasticMapsServiceInMaps disabled'); } - const tmsServices = await emsClient.getTMSServices(); + const tmsServices = await getEMSClient().getTMSServices(); const tmsService = tmsServices.find((layer) => layer.getId() === request.query.id); if (!tmsService) { return null; @@ -409,7 +416,7 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) { return response.badRequest('map.proxyElasticMapsServiceInMaps disabled'); } - const tmsServices = await emsClient.getTMSServices(); + const tmsServices = await getEMSClient().getTMSServices(); const tmsService = tmsServices.find((layer) => layer.getId() === request.query.id); if (!tmsService) { return null; @@ -439,7 +446,8 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) { if (!checkEMSProxyEnabled()) { return response.badRequest('map.proxyElasticMapsServiceInMaps disabled'); } - const url = mapConfig.emsFontLibraryUrl + const url = emsSettings + .getEMSFontLibraryUrl() .replace('{fontstack}', request.params.fontstack) .replace('{range}', request.params.range); @@ -469,7 +477,7 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) { return response.badRequest('map.proxyElasticMapsServiceInMaps disabled'); } - const tmsServices = await emsClient.getTMSServices(); + const tmsServices = await getEMSClient().getTMSServices(); const tmsService = tmsServices.find((layer) => layer.getId() === request.params.id); if (!tmsService) { return null; @@ -573,7 +581,7 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) { ); function checkEMSProxyEnabled() { - const proxyEMSInMaps = mapConfig.proxyElasticMapsServiceInMaps; + const proxyEMSInMaps = emsSettings.isProxyElasticMapsServiceInMaps(); if (!proxyEMSInMaps) { logger.warn( `Cannot load content from EMS when map.proxyElasticMapsServiceInMaps is turned off` From 1b86d79319efa8c5b153a90099d20babde208b92 Mon Sep 17 00:00:00 2001 From: Kaarina Tungseth Date: Tue, 10 Nov 2020 09:11:21 -0600 Subject: [PATCH 20/80] [DOCS] Consolidates drilldown pages (#82081) * [DOCS] Consolidated drilldowns * Review comments pt 1 * Update docs/user/dashboard/drilldowns.asciidoc Co-authored-by: Anton Dosov * Fixes supported drilldowns link * Update src/core/public/doc_links/doc_links_service.ts Co-authored-by: Anton Dosov * Fixes rogue disable section and fixes intro formatting * Fixes URL drilldown link Co-authored-by: Anton Dosov Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../dashboard/dashboard-drilldown.asciidoc | 96 ------- docs/user/dashboard/drilldowns.asciidoc | 269 ++++++++++++++++-- docs/user/dashboard/url-drilldown.asciidoc | 115 +------- .../public/doc_links/doc_links_service.ts | 6 +- 4 files changed, 249 insertions(+), 237 deletions(-) delete mode 100644 docs/user/dashboard/dashboard-drilldown.asciidoc diff --git a/docs/user/dashboard/dashboard-drilldown.asciidoc b/docs/user/dashboard/dashboard-drilldown.asciidoc deleted file mode 100644 index bdff7355d7467..0000000000000 --- a/docs/user/dashboard/dashboard-drilldown.asciidoc +++ /dev/null @@ -1,96 +0,0 @@ -[[dashboard-drilldown]] -=== Dashboard drilldown - -The dashboard drilldown allows you to navigate from one dashboard to another dashboard. -For example, you might have a dashboard that shows the overall status of multiple data centers. -You can create a drilldown that navigates from this dashboard to a dashboard -that shows a single data center or server. - -This example shows a dashboard panel that contains a pie chart with a configured dashboard drilldown: - -[role="screenshot"] -image::images/drilldown_on_piechart.gif[Drilldown on pie chart that navigates to another dashboard] - -[float] -[[dashboard-drilldown-supported-panels]] -==== Supported panels - -The following panels support dashboard drilldowns: - -* Lens -* Area -* Data table -* Heat map -* Horizontal bar -* Line -* Maps -* Pie -* TSVB -* Tag cloud -* Timelion -* Vega -* Vertical bar - -[float] -[[drilldowns-example]] -==== Try it: Create a dashboard drilldown - -Create the *Host Overview* drilldown shown above. - -*Set up the dashboards* - -. Add the sample web logs data set. - -. Create a new dashboard, called `Host Overview`, and include these visualizations -from the sample data set: -+ -[%hardbreaks] -*[Logs] Heatmap* -*[Logs] Visitors by OS* -*[Logs] Host, Visits, and Bytes Table* -*[Logs] Total Requests and Bytes* -+ -TIP: If you don’t see data for a panel, try changing the time range. - -. Open the *[Logs] Web traffic* dashboard. - -. Set a search and filter. -+ -[%hardbreaks] -Search: `extension.keyword: ("gz" or "css" or "deb")` -Filter: `geo.src: CN` - - -*Create the drilldown* - - -. In the dashboard menu bar, click *Edit*. - -. In *[Logs] Visitors by OS*, open the panel menu, and then select *Create drilldown*. - -. Pick *Go to dashboard* action. - -. Give the drilldown a name. - -. Select *Host Overview* as the destination dashboard. - -. Keep both filters enabled so that the drilldown carries over the global filters and date range. -+ -Your input should look similar to this: -+ -[role="screenshot"] -image::images/drilldown_create.png[Create drilldown with entries for drilldown name and destination] - -. Click *Create drilldown.* - -. Save the dashboard. -+ -If you don’t save the drilldown, and then navigate away, the drilldown is lost. - -. In *[Logs] Visitors by OS*, click the `win 8` slice of the pie, and then select the name of your drilldown. -+ -[role="screenshot"] -image::images/drilldown_on_panel.png[Drilldown on pie chart that navigates to another dashboard] -+ -You are navigated to your destination dashboard. Verify that the search query, filters, -and time range are carried over. diff --git a/docs/user/dashboard/drilldowns.asciidoc b/docs/user/dashboard/drilldowns.asciidoc index e3d0e16630c5c..ca788020d9286 100644 --- a/docs/user/dashboard/drilldowns.asciidoc +++ b/docs/user/dashboard/drilldowns.asciidoc @@ -1,52 +1,259 @@ [role="xpack"] [[drilldowns]] -== Use drilldowns for dashboard actions +== Create custom dashboard actions -Drilldowns, also known as custom actions, allow you to configure a -workflow for analyzing and troubleshooting your data. -For example, using a drilldown, you can navigate from one dashboard to another, -taking the current time range, filters, and other parameters with you, -so the context remains the same. You can continue your analysis from a new perspective. +Custom dashboard actions, also known as drilldowns, allow you to create +workflows for analyzing and troubleshooting your data. Drilldowns apply only to the panel that you created the drilldown from, and are not shared across all of the panels. Each panel can have multiple drilldowns. -[role="screenshot"] -image::images/drilldown_on_piechart.gif[Drilldown on pie chart that navigates to another dashboard] +Third-party developers can create drilldowns. To learn how to code drilldowns, refer to {kib-repo}blob/{branch}/x-pack/examples/ui_actions_enhanced_examples[this example plugin]. + +[float] +[[supported-drilldowns]] +=== Supported drilldowns + +{kib} supports two types of drilldowns. + +[NOTE] +============================================== +Some drilldowns are paid subscription features, while others are free. +For a comparison of the Elastic subscription levels, +refer https://www.elastic.co/subscriptions[the subscription page]. +============================================== + +[float] +[[dashboard-drilldown]] +==== Dashboard drilldowns + +Dashboard drilldowns enable you to open a dashboard from another dashboard, +taking the time range, filters, and other parameters with you, +so the context remains the same. Dashboard drilldowns help you to continue your analysis from a new perspective. + +For example, if you have a dashboard that shows the overall status of multiple data center, +you can create a drilldown that navigates from the overall status dashboard to a dashboard +that shows a single data center or server. + +[float] +[[url-drilldown]] +==== URL drilldowns + +beta[] URL drilldowns enable you to navigate from a dashboard to internal or external URLs. +Destination URLs can be dynamic, depending on the dashboard context or user interaction with a panel. +For example, if you have a dashboard that shows data from a Github repository, you can create a URL drilldown +that opens Github from the dashboard. + +Some panels support multiple interactions, also known as triggers. +The <> you use to create a <> depends on the trigger you choose. URL drilldowns support these types of triggers: + +* *Single click* — A single data point in the visualization. + +* *Range selection* — A range of values in a visualization. + +For example, *Single click* has `{{event.value}}` and *Range selection* has `{{event.from}}` and `{{event.to}}`. + +To disable URL drilldowns on your {kib} instance, disable the plugin: -Drilldowns are specific to the dashboard panel for which you create them—they are not shared across panels. A panel can have multiple drilldowns. +["source","yml"] +----------- +url_drilldown.enabled: false +----------- [float] -[[actions]] -=== Drilldown actions +[[dashboard-drilldown-supported-panels]] +=== Supported panels -Drilldowns are user-configurable {kib} actions that are stored with the dashboard metadata. -Kibana provides the following types of actions: +The following panels support dashboard and URL drilldowns. -[cols="2"] +[options="header"] |=== -a| <> +| Panel | Dashboard drilldown | URL drilldown -| Navigate to a dashboard. +| Lens +^| X +^| X -a| <> +| Area +^| X +^| X -| Navigate to external or internal URL. +| Controls +^| +^| + +| Data Table +^| X +^| X + +| Gauge +^| +^| + +| Goal +^| +^| + +| Heat map +^| X +^| X + +| Horizontal Bar +^| X +^| X + +| Line +^| X +^| X + +| Maps +^| X +^| + +| Markdown +^| +^| + +| Metric +^| +^| + +| Pie +^| X +^| X + +| TSVB +^| X +^| + +| Tag Cloud +^| X +^| X + +| Timelion +^| X +^| + +| Vega +^| X +^| + +| Vertical Bar +^| X +^| X |=== -[NOTE] -============================================== -Some action types are paid commercial features, while others are free. -For a comparison of the Elastic subscription levels, -see https://www.elastic.co/subscriptions[the subscription page]. -============================================== +[float] +[[drilldowns-example]] +=== Try it: Create a dashboard drilldown + +To create dashboard drilldowns, you create or locate the dashboards you want to connect, then configure the drilldown that allows you to easily open one dashboard from the other dashboard. + +image:images/drilldown_on_piechart.gif[Drilldown on pie chart that navigates to another dashboard] [float] -[[code-drilldowns]] -=== Code drilldowns -Third-party developers can create drilldowns. -Refer to {kib-repo}blob/{branch}/x-pack/examples/ui_actions_enhanced_examples[this example plugin] -to learn how to code drilldowns. +==== Create the dashboard -include::dashboard-drilldown.asciidoc[] -include::url-drilldown.asciidoc[] +. Add the *Sample web logs* data. + +. Create a new dashboard, then add the following panels: + +* *[Logs] Heatmap* +* *[Logs] Host, Visits, and Bytes Table* +* *[Logs] Total Requests and Bytes* +* *[Logs] Visitors by OS* ++ +If you don’t see data for a panel, try changing the <>. + +. Save the dashboard. In the *Title* field, enter `Host Overview`. + +. Open the *[Logs] Web traffic* dashboard. + +. Set a search and filter. ++ +[%hardbreaks] +Search: `extension.keyword: ("gz" or "css" or "deb")` +Filter: `geo.src: CN` + +[float] +==== Create the drilldown + +. In the toolbar, click *Edit*. + +. Open the *[Logs] Visitors by OS* panel menu, then select *Create drilldown*. + +. Give the drilldown a name, then select *Go to dashboard*. + +. From the *Choose a destination dashboard* dropdown, select *Host Overview*. + +. To carry over the filter, query, and date range, make sure that *Use filters and query from origin dashboard* and *Use date range from origin dashboard* are selected. ++ +[role="screenshot"] +image::images/drilldown_create.png[Create drilldown with entries for drilldown name and destination] + +. Click *Create drilldown*. ++ +The drilldown is stored as dashboard metadata. + +. Save the dashboard. ++ +If you fail to save the dashboard, the drilldown is lost when you navigate away from the dashboard. + +. In the *[Logs] Visitors by OS* panel, click *win 8*, then select the drilldown. ++ +[role="screenshot"] +image::images/drilldown_on_panel.png[Drilldown on pie chart that navigates to another dashboard] +. On the *Host Overview* dashboard, verify that the search query, filters, +and date range are carried over. + +[float] +[[create-a-url-drilldown]] +=== Try it: Create a URL drilldown + +beta[] To create URL drilldowns, you add <> to a URL template, which configures the bahavior of the drilldown. + +image:images/url_drilldown_go_to_github.gif[Drilldown on pie chart that navigates to Github] + +. Add the *Sample web logs* data. + +. Open the *[Logs] Web traffic* dashboard. This isn’t data from Github, but works for demonstration purposes. + +. In the toolbar, click *Edit*. + +. Open the *[Logs] Visitors by OS* panel menu, then select *Create drilldown*. + +.. In the *Name* field, enter `Show on Github`. + +.. Select *Go to URL*. + +.. Enter the URL template: ++ +[source, bash] +---- +https://github.com/elastic/kibana/issues?q=is:issue+is:open+{{event.value}} +---- ++ +The example URL navigates to {kib} issues on Github. `{{event.value}}` is substituted with a value associated with a selected pie slice. In *URL preview*, `{{event.value}}` is substituted with a <> value. ++ +[role="screenshot"] +image:images/url_drilldown_url_template.png[URL template input] + +.. Click *Create drilldown*. ++ +The drilldown is stored as dashboard metadata. + +. Save the dashboard. ++ +If you fail to save the dashboard, the drilldown is lost when you navigate away from the dashboard. + +. On the *[Logs] Visitors by OS* panel, click any chart slice, then select *Show on Github*. ++ +[role="screenshot"] +image:images/url_drilldown_popup.png[URL drilldown popup] + +. On the page that lists the issues in the {kib} repository, verify the slice value appears in Github. ++ +[role="screenshot"] +image:images/url_drilldown_github.png[Github] + +include::url-drilldown.asciidoc[] diff --git a/docs/user/dashboard/url-drilldown.asciidoc b/docs/user/dashboard/url-drilldown.asciidoc index 212e29898bd40..872d83bfd9009 100644 --- a/docs/user/dashboard/url-drilldown.asciidoc +++ b/docs/user/dashboard/url-drilldown.asciidoc @@ -1,96 +1,9 @@ -[[url-drilldown]] -=== URL drilldown +[[url_templating]] +=== URL templating beta[] -The URL drilldown allows you to navigate from a dashboard to an internal or external URL. -The destination URL can be dynamic, depending on the dashboard context or user’s interaction with a visualization. - -For example, you might have a dashboard that shows data from a Github repository. -You can create a drilldown that navigates from this dashboard to Github. - -[role="screenshot"] -image:images/url_drilldown_go_to_github.gif[Drilldown on pie chart that navigates to Github] - -NOTE: URL drilldown is available with the https://www.elastic.co/subscriptions[Gold subscription] and higher. - -[float] -[[url-drilldown-supported-panels]] -==== Supported panels - -The following panels support URL drilldowns: - -* Lens -* Area -* Data table -* Heat map -* Horizontal bar -* Line -* Pie -* Tag cloud -* Vertical bar - -[float] -[[try-it]] -==== Try it: Create a URL drilldown - -This example shows how to create the "Show on Github" drilldown shown above. - -. Add the sample web logs data set. -. Open the *[Logs] Web traffic* dashboard. This isn’t data from Github, but it should work for demonstration purposes. -. In the dashboard menu bar, click *Edit*. -. In *[Logs] Visitors by OS*, open the panel menu, and then select *Create drilldown*. -. Give the drilldown a name: *Show on Github*. -. Select a drilldown action: *Go to URL*. -+ -[role="screenshot"] -image:images/url_drilldown_pick_an_action.png[Action picker] -. Enter a URL template: -+ -[source, bash] ----- -https://github.com/elastic/kibana/issues?q=is:issue+is:open+{{event.value}} ----- -+ -This example URL navigates to {kib} issues on Github. `{{event.value}}` will be substituted with a value associated with a clicked pie slice. In _preview_ `{{event.value}}` is substituted with a <> value. -[role="screenshot"] -image:images/url_drilldown_url_template.png[URL template input] -. Click *Create drilldown*. -. Save the dashboard. -+ -If you don’t save the drilldown, and then navigate away, the drilldown is lost. - -. In *[Logs] Visitors by OS*, click any slice of the pie, and then select the drilldown *Show on Github*. -+ -[role="screenshot"] -image:images/url_drilldown_popup.png[URL drilldown popup] -+ -You are navigated to the issue list in the {kib} repository. Verify that value from a pie slice you’ve clicked on is carried over to Github. -+ -[role="screenshot"] -image:images/url_drilldown_github.png[Github] - -[float] -[[trigger-picker]] -==== Picking a trigger for a URL drilldown - -Some panels support multiple user interactions (called triggers) for which you can configure a URL drilldown. The list of supported variables in the URL template depends on the trigger you selected. -In the preceding example, you configured a URL drilldown on a pie chart. The only trigger that pie chart supports is clicking on a pie slice, so you didn’t have to pick a trigger. - -However, the sample *[Logs] Unique Visitors vs. Average Bytes* chart supports both clicking on a data point and selecting a range. When you create a URL drilldown for this chart, you have the following choices: - -[role="screenshot"] -image:images/url_drilldown_trigger_picker.png[Trigger picker: Single click and Range selection] - -Variables in the URL template differ per trigger. -For example, *Single click* has `{{event.value}}` and *Range selection* has `{{event.from}}` and `{{event.to}}`. -You can create multiple URL drilldowns per panel and attach them to different triggers. - -[float] -[[templating]] -==== URL templating language - -The URL template input uses Handlebars — a simple templating language. Handlebars templates look like regular text with embedded Handlebars expressions. +The URL template input uses https://handlebarsjs.com/guide/expressions.html#expressions[Handlebars] — a simple templating language. Handlebars templates look like regular text with embedded Handlebars expressions. [source, bash] ---- @@ -99,14 +12,13 @@ https://github.com/elastic/kibana/issues?q={{event.value}} A Handlebars expression is a `{{`, some contents, followed by a `}}`. When the drilldown is executed, these expressions are replaced by values from the dashboard and interaction context. -Refer to Handlebars https://ela.st/handlebars-docs#expressions[documentation] to learn about advanced use cases. - [[helpers]] -In addition to https://ela.st/handlebars-helpers[built-in] Handlebars helpers, you can use the following custom helpers: +In addition to https://handlebarsjs.com/guide/builtin-helpers.html[built-in] Handlebars helpers, you can use custom helpers. +Refer to Handlebars https://ela.st/handlebars-docs#expressions[documentation] to learn about advanced use cases. |=== -|Helper |Use case +|Custom helper |Use case |json a|Serialize variables in JSON format. @@ -133,7 +45,7 @@ a|Format dates. Supports relative dates expressions (for example, "now-15d"). R Example: -`{{ date event.from “YYYY MM DD”}}` + +`{{date event.from “YYYY MM DD”}}` + `{{date “now-15”}}` |formatNumber @@ -240,7 +152,7 @@ For example, `{{context.panel.filters}}` are previewed with the current filters *Event* variables are extracted during drilldown execution from a user interaction with a panel (for example, from a pie slice that the user clicked on). Because there is no user interaction with a panel in preview, there is no interaction context to use in a preview. -To work around this, {kib} provides a sample interaction that relies on a picked <>. +To work around this, {kib} provides a sample interaction that relies on a trigger. So in a preview, you might notice that `{{event.value}}` is replaced with `{{event.value}}` instead of with a sample from your data. Such previews can help you make sure that the structure of your URL template is valid. However, to ensure that the configured URL drilldown works as expected with your data, you have to save the dashboard and test in the panel. @@ -340,14 +252,3 @@ Tip: Consider using <> helper for date formatting. | Aggregation field behind the selected range, if available. |=== - -[float] -[[disable]] -==== Disable URL drilldown - -You can disable URL drilldown feature on your {kib} instance by disabling the plugin: - -["source","yml"] ------------ -url_drilldown.enabled: false ------------ diff --git a/src/core/public/doc_links/doc_links_service.ts b/src/core/public/doc_links/doc_links_service.ts index 0815df4b9b0c7..6af14734444d1 100644 --- a/src/core/public/doc_links/doc_links_service.ts +++ b/src/core/public/doc_links/doc_links_service.ts @@ -39,9 +39,9 @@ export class DocLinksService { dashboard: { guide: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/dashboard.html`, drilldowns: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/drilldowns.html`, - drilldownsTriggerPicker: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/url-drilldown.html#trigger-picker`, - urlDrilldownTemplateSyntax: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/url-drilldown.html#templating`, - urlDrilldownVariables: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/url-drilldown.html#variables`, + drilldownsTriggerPicker: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/drilldowns.html#url-drilldown`, + urlDrilldownTemplateSyntax: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/url_templating-language.html`, + urlDrilldownVariables: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/url_templating-language.html#variables`, }, filebeat: { base: `${ELASTIC_WEBSITE_URL}guide/en/beats/filebeat/${DOC_LINK_VERSION}`, From 2332c8b6d8eaae7c2bc96dfb1b2028286604b051 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Tue, 10 Nov 2020 08:25:32 -0700 Subject: [PATCH 21/80] [Maps] show icon when layer is filtered by time and allow layers to ignore global time range (#83006) * [Maps] show icon when layer is filtered by time and allow layers to ignore global time range * show icon if layer is narrowed by time fitler * tslint * apply global time to source check box * apply global time to join check box * tslint and jest expect updates * one more tslint fix * tslint, fix apm jest test, update time filter icon when disabling applyGlobalTime Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../__tests__/__mocks__/regions_layer.mock.ts | 6 +- .../VisitorBreakdownMap/useLayerList.ts | 4 +- .../data_request_descriptor_types.ts | 10 +- .../source_descriptor_types.ts | 3 +- .../create_choropleth_layer_descriptor.ts | 2 + .../create_region_map_layer_descriptor.ts | 2 + .../maps/public/classes/layers/layer.test.ts | 2 + .../maps/public/classes/layers/layer.tsx | 83 +----- .../create_layer_descriptor.test.ts | 4 + .../observability/create_layer_descriptor.ts | 2 + .../security/create_layer_descriptors.test.ts | 6 + .../layers/vector_layer/vector_layer.tsx | 19 ++ .../es_agg_source/es_agg_source.test.ts | 12 +- .../es_geo_grid_source.test.ts | 1 + .../es_search_source/es_search_source.test.ts | 1 + .../classes/sources/es_source/es_source.ts | 22 +- .../sources/es_term_source/es_term_source.ts | 18 +- .../kibana_regionmap_source.ts | 4 - .../mvt_single_layer_vector_source.tsx | 4 - .../maps/public/classes/sources/source.ts | 7 +- .../sources/vector_source/vector_source.tsx | 2 +- .../public/classes/util/can_skip_fetch.ts | 7 +- .../components/global_time_checkbox.tsx | 32 ++ .../filter_editor/filter_editor.js | 29 +- .../layer_panel/join_editor/join_editor.tsx | 1 + .../layer_panel/join_editor/resources/join.js | 71 +++-- .../toc_entry_actions_popover.test.tsx.snap | 281 +++++++----------- .../toc_entry_actions_popover/index.ts | 10 +- .../toc_entry_actions_popover.test.tsx | 15 - .../toc_entry_actions_popover.tsx | 65 +--- .../toc_entry/toc_entry_button/index.ts | 20 ++ .../toc_entry_button/toc_entry_button.tsx | 184 ++++++++++++ 32 files changed, 553 insertions(+), 376 deletions(-) create mode 100644 x-pack/plugins/maps/public/components/global_time_checkbox.tsx create mode 100644 x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_button/index.ts create mode 100644 x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_button/toc_entry_button.tsx diff --git a/x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/__tests__/__mocks__/regions_layer.mock.ts b/x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/__tests__/__mocks__/regions_layer.mock.ts index e564332583375..6d259a5a2e48c 100644 --- a/x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/__tests__/__mocks__/regions_layer.mock.ts +++ b/x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/__tests__/__mocks__/regions_layer.mock.ts @@ -21,6 +21,8 @@ export const mockLayerList = [ { leftField: 'iso2', right: { + applyGlobalQuery: true, + applyGlobalTime: true, type: 'ES_TERM_SOURCE', id: '3657625d-17b0-41ef-99ba-3a2b2938655c', indexPatternTitle: 'apm-*', @@ -38,7 +40,6 @@ export const mockLayerList = [ }, ], indexPatternId: 'apm_static_index_pattern_id', - applyGlobalQuery: true, }, }, ], @@ -46,7 +47,6 @@ export const mockLayerList = [ type: 'EMS_FILE', id: 'world_countries', tooltipProperties: ['name'], - applyGlobalQuery: true, }, style: { type: 'VECTOR', @@ -96,6 +96,8 @@ export const mockLayerList = [ { leftField: 'region_iso_code', right: { + applyGlobalQuery: true, + applyGlobalTime: true, type: 'ES_TERM_SOURCE', id: 'e62a1b9c-d7ff-4fd4-a0f6-0fdc44bb9e41', indexPatternTitle: 'apm-*', diff --git a/x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/useLayerList.ts b/x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/useLayerList.ts index bc45d58329f49..a1cdf7bb646e5 100644 --- a/x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/useLayerList.ts +++ b/x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/useLayerList.ts @@ -43,6 +43,7 @@ const ES_TERM_SOURCE_COUNTRY: ESTermSourceDescriptor = { ], indexPatternId: APM_STATIC_INDEX_PATTERN_ID, applyGlobalQuery: true, + applyGlobalTime: true, }; const ES_TERM_SOURCE_REGION: ESTermSourceDescriptor = { @@ -56,6 +57,8 @@ const ES_TERM_SOURCE_REGION: ESTermSourceDescriptor = { language: 'kuery', }, indexPatternId: APM_STATIC_INDEX_PATTERN_ID, + applyGlobalQuery: true, + applyGlobalTime: true, }; const getWhereQuery = (serviceName: string) => { @@ -158,7 +161,6 @@ export function useLayerList() { type: 'EMS_FILE', id: 'world_countries', tooltipProperties: [COUNTRY_NAME], - applyGlobalQuery: true, }, style: getLayerStyle(TRANSACTION_DURATION_COUNTRY), id: 'e8d1d974-eed8-462f-be2c-f0004b7619b2', diff --git a/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts b/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts index fc691f339f34a..68fc784182a77 100644 --- a/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts +++ b/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts @@ -38,17 +38,17 @@ export type VectorSourceSyncMeta = ESSearchSourceSyncMeta | ESGeoGridSourceSyncM export type VectorSourceRequestMeta = MapFilters & { applyGlobalQuery: boolean; + applyGlobalTime: boolean; fieldNames: string[]; geogridPrecision?: number; sourceQuery?: MapQuery; sourceMeta: VectorSourceSyncMeta; }; -export type VectorJoinSourceRequestMeta = MapFilters & { - applyGlobalQuery: boolean; - fieldNames: string[]; - sourceQuery?: Query; -}; +export type VectorJoinSourceRequestMeta = Omit< + VectorSourceRequestMeta, + 'geogridPrecision' | 'sourceMeta' +> & { sourceQuery?: Query }; export type VectorStyleRequestMeta = MapFilters & { dynamicStyleFields: string[]; diff --git a/x-pack/plugins/maps/common/descriptor_types/source_descriptor_types.ts b/x-pack/plugins/maps/common/descriptor_types/source_descriptor_types.ts index 3dc90a12513fd..a6afbe4d55f9b 100644 --- a/x-pack/plugins/maps/common/descriptor_types/source_descriptor_types.ts +++ b/x-pack/plugins/maps/common/descriptor_types/source_descriptor_types.ts @@ -18,7 +18,6 @@ export type AttributionDescriptor = { export type AbstractSourceDescriptor = { id?: string; type: string; - applyGlobalQuery?: boolean; }; export type EMSTMSSourceDescriptor = AbstractSourceDescriptor & { @@ -37,6 +36,8 @@ export type AbstractESSourceDescriptor = AbstractSourceDescriptor & { id: string; indexPatternId: string; geoField?: string; + applyGlobalQuery: boolean; + applyGlobalTime: boolean; }; export type AggDescriptor = { diff --git a/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/create_choropleth_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/create_choropleth_layer_descriptor.ts index 61fb6ef54c207..43d1d39c170c0 100644 --- a/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/create_choropleth_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/choropleth_layer_wizard/create_choropleth_layer_descriptor.ts @@ -61,6 +61,8 @@ function createChoroplethLayerDescriptor({ indexPatternTitle: rightIndexPatternTitle, term: rightTermField, metrics: [metricsDescriptor], + applyGlobalQuery: true, + applyGlobalTime: true, }, }, ], diff --git a/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts index 8bf078806cfbc..8830831b8b656 100644 --- a/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/create_region_map_layer_descriptor.ts @@ -87,6 +87,8 @@ export function createRegionMapLayerDescriptor({ indexPatternTitle: indexPatternTitle ? indexPatternTitle : indexPatternId, term: termsFieldName, metrics: [metricsDescriptor], + applyGlobalQuery: true, + applyGlobalTime: true, }, }, ], diff --git a/x-pack/plugins/maps/public/classes/layers/layer.test.ts b/x-pack/plugins/maps/public/classes/layers/layer.test.ts index 76df7c2af840a..e669ddf13e5ac 100644 --- a/x-pack/plugins/maps/public/classes/layers/layer.test.ts +++ b/x-pack/plugins/maps/public/classes/layers/layer.test.ts @@ -74,6 +74,8 @@ describe('cloneDescriptor', () => { metrics: [{ type: AGG_TYPE.COUNT }], term: 'myTermField', type: 'joinSource', + applyGlobalQuery: true, + applyGlobalTime: true, }, }, ], diff --git a/x-pack/plugins/maps/public/classes/layers/layer.tsx b/x-pack/plugins/maps/public/classes/layers/layer.tsx index f75dae84b1723..7c76df7f6e877 100644 --- a/x-pack/plugins/maps/public/classes/layers/layer.tsx +++ b/x-pack/plugins/maps/public/classes/layers/layer.tsx @@ -8,9 +8,8 @@ import { Query } from 'src/plugins/data/public'; import _ from 'lodash'; import React, { ReactElement } from 'react'; -import { EuiIcon, EuiLoadingSpinner } from '@elastic/eui'; +import { EuiIcon } from '@elastic/eui'; import uuid from 'uuid/v4'; -import { i18n } from '@kbn/i18n'; import { FeatureCollection } from 'geojson'; import { DataRequest } from '../util/data_request'; import { @@ -49,8 +48,6 @@ export interface ILayer { supportsFitToBounds(): Promise; getAttributions(): Promise; getLabel(): string; - getCustomIconAndTooltipContent(): CustomIconAndTooltipContent; - getIconAndTooltipContent(zoomLevel: number, isUsingSearch: boolean): IconAndTooltipContent; renderLegendDetails(): ReactElement | null; showAtZoomLevel(zoom: number): boolean; getMinZoom(): number; @@ -64,6 +61,7 @@ export interface ILayer { getImmutableSourceProperties(): Promise; renderSourceSettingsEditor({ onChange }: SourceEditorArgs): ReactElement | null; isLayerLoading(): boolean; + isFilteredByGlobalTime(): Promise; hasErrors(): boolean; getErrors(): string; getMbLayerIds(): string[]; @@ -93,16 +91,9 @@ export interface ILayer { getJoinsDisabledReason(): string | null; isFittable(): Promise; getLicensedFeatures(): Promise; + getCustomIconAndTooltipContent(): CustomIconAndTooltipContent; } -export type Footnote = { - icon: ReactElement; - message?: string | null; -}; -export type IconAndTooltipContent = { - icon?: ReactElement | null; - tooltipContent?: string | null; - footnotes: Footnote[]; -}; + export type CustomIconAndTooltipContent = { icon: ReactElement | null; tooltipContent?: string | null; @@ -237,6 +228,10 @@ export class AbstractLayer implements ILayer { return (await this.supportsFitToBounds()) && this.isVisible(); } + async isFilteredByGlobalTime(): Promise { + return false; + } + async getDisplayName(source?: ISource): Promise { if (this._descriptor.label) { return this._descriptor.label; @@ -277,68 +272,6 @@ export class AbstractLayer implements ILayer { }; } - getIconAndTooltipContent(zoomLevel: number, isUsingSearch: boolean): IconAndTooltipContent { - let icon; - let tooltipContent = null; - const footnotes = []; - if (this.hasErrors()) { - icon = ( - - ); - tooltipContent = this.getErrors(); - } else if (this.isLayerLoading()) { - icon = ; - } else if (!this.isVisible()) { - icon = ; - tooltipContent = i18n.translate('xpack.maps.layer.layerHiddenTooltip', { - defaultMessage: `Layer is hidden.`, - }); - } else if (!this.showAtZoomLevel(zoomLevel)) { - const minZoom = this.getMinZoom(); - const maxZoom = this.getMaxZoom(); - icon = ; - tooltipContent = i18n.translate('xpack.maps.layer.zoomFeedbackTooltip', { - defaultMessage: `Layer is visible between zoom levels {minZoom} and {maxZoom}.`, - values: { minZoom, maxZoom }, - }); - } else { - const customIconAndTooltipContent = this.getCustomIconAndTooltipContent(); - if (customIconAndTooltipContent) { - icon = customIconAndTooltipContent.icon; - if (!customIconAndTooltipContent.areResultsTrimmed) { - tooltipContent = customIconAndTooltipContent.tooltipContent; - } else { - footnotes.push({ - icon: , - message: customIconAndTooltipContent.tooltipContent, - }); - } - } - - if (isUsingSearch && this.getQueryableIndexPatternIds().length) { - footnotes.push({ - icon: , - message: i18n.translate('xpack.maps.layer.isUsingSearchMsg', { - defaultMessage: 'Results narrowed by search bar', - }), - }); - } - } - - return { - icon, - tooltipContent, - footnotes, - }; - } - async hasLegendDetails(): Promise { return false; } diff --git a/x-pack/plugins/maps/public/classes/layers/solution_layers/observability/create_layer_descriptor.test.ts b/x-pack/plugins/maps/public/classes/layers/solution_layers/observability/create_layer_descriptor.test.ts index 66eba3a539801..e2678ee218b4b 100644 --- a/x-pack/plugins/maps/public/classes/layers/solution_layers/observability/create_layer_descriptor.test.ts +++ b/x-pack/plugins/maps/public/classes/layers/solution_layers/observability/create_layer_descriptor.test.ts @@ -39,6 +39,8 @@ describe('createLayerDescriptor', () => { { leftField: 'iso2', right: { + applyGlobalQuery: true, + applyGlobalTime: true, id: '12345', indexPatternId: 'apm_static_index_pattern_id', indexPatternTitle: 'apm-*', @@ -176,6 +178,7 @@ describe('createLayerDescriptor', () => { }, sourceDescriptor: { applyGlobalQuery: true, + applyGlobalTime: true, geoField: 'client.geo.location', id: '12345', indexPatternId: 'apm_static_index_pattern_id', @@ -218,6 +221,7 @@ describe('createLayerDescriptor', () => { }, sourceDescriptor: { applyGlobalQuery: true, + applyGlobalTime: true, geoField: 'client.geo.location', id: '12345', indexPatternId: 'apm_static_index_pattern_id', diff --git a/x-pack/plugins/maps/public/classes/layers/solution_layers/observability/create_layer_descriptor.ts b/x-pack/plugins/maps/public/classes/layers/solution_layers/observability/create_layer_descriptor.ts index bdd86d78b5300..5dbf07ed2a535 100644 --- a/x-pack/plugins/maps/public/classes/layers/solution_layers/observability/create_layer_descriptor.ts +++ b/x-pack/plugins/maps/public/classes/layers/solution_layers/observability/create_layer_descriptor.ts @@ -177,6 +177,8 @@ export function createLayerDescriptor({ term: 'client.geo.country_iso_code', metrics: [metricsDescriptor], whereQuery: apmSourceQuery, + applyGlobalQuery: true, + applyGlobalTime: true, }, }, ], diff --git a/x-pack/plugins/maps/public/classes/layers/solution_layers/security/create_layer_descriptors.test.ts b/x-pack/plugins/maps/public/classes/layers/solution_layers/security/create_layer_descriptors.test.ts index 22456527491eb..fe04678deacae 100644 --- a/x-pack/plugins/maps/public/classes/layers/solution_layers/security/create_layer_descriptors.test.ts +++ b/x-pack/plugins/maps/public/classes/layers/solution_layers/security/create_layer_descriptors.test.ts @@ -33,6 +33,7 @@ describe('createLayerDescriptor', () => { minZoom: 0, sourceDescriptor: { applyGlobalQuery: true, + applyGlobalTime: true, filterByMapBounds: true, geoField: 'client.geo.location', id: '12345', @@ -140,6 +141,7 @@ describe('createLayerDescriptor', () => { minZoom: 0, sourceDescriptor: { applyGlobalQuery: true, + applyGlobalTime: true, filterByMapBounds: true, geoField: 'server.geo.location', id: '12345', @@ -247,6 +249,7 @@ describe('createLayerDescriptor', () => { minZoom: 0, sourceDescriptor: { applyGlobalQuery: true, + applyGlobalTime: true, destGeoField: 'server.geo.location', id: '12345', indexPatternId: 'id', @@ -366,6 +369,7 @@ describe('createLayerDescriptor', () => { minZoom: 0, sourceDescriptor: { applyGlobalQuery: true, + applyGlobalTime: true, filterByMapBounds: true, geoField: 'source.geo.location', id: '12345', @@ -473,6 +477,7 @@ describe('createLayerDescriptor', () => { minZoom: 0, sourceDescriptor: { applyGlobalQuery: true, + applyGlobalTime: true, filterByMapBounds: true, geoField: 'destination.geo.location', id: '12345', @@ -580,6 +585,7 @@ describe('createLayerDescriptor', () => { minZoom: 0, sourceDescriptor: { applyGlobalQuery: true, + applyGlobalTime: true, destGeoField: 'destination.geo.location', id: '12345', indexPatternId: 'id', diff --git a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx index b9d7834896245..b4c0098bb1338 100644 --- a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx +++ b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.tsx @@ -254,6 +254,7 @@ export class VectorLayer extends AbstractLayer { timeFilters: searchFilters.timeFilters, filters: searchFilters.filters, applyGlobalQuery: searchFilters.applyGlobalQuery, + applyGlobalTime: searchFilters.applyGlobalTime, }; let bounds = null; @@ -315,6 +316,22 @@ export class VectorLayer extends AbstractLayer { return indexPatternIds; } + async isFilteredByGlobalTime(): Promise { + if (this.getSource().getApplyGlobalTime() && (await this.getSource().isTimeAware())) { + return true; + } + + const joinPromises = this.getValidJoins().map(async (join) => { + return ( + join.getRightJoinSource().getApplyGlobalTime() && + (await join.getRightJoinSource().isTimeAware()) + ); + }); + return (await Promise.all(joinPromises)).some((isJoinTimeAware: boolean) => { + return isJoinTimeAware; + }); + } + async _syncJoin({ join, startLoading, @@ -331,6 +348,7 @@ export class VectorLayer extends AbstractLayer { fieldNames: joinSource.getFieldNames(), sourceQuery: joinSource.getWhereQuery(), applyGlobalQuery: joinSource.getApplyGlobalQuery(), + applyGlobalTime: joinSource.getApplyGlobalTime(), }; const prevDataRequest = this.getDataRequest(sourceDataId); @@ -403,6 +421,7 @@ export class VectorLayer extends AbstractLayer { geogridPrecision: source.getGeoGridPrecision(dataFilters.zoom), sourceQuery: sourceQuery ? sourceQuery : undefined, applyGlobalQuery: source.getApplyGlobalQuery(), + applyGlobalTime: source.getApplyGlobalTime(), sourceMeta: source.getSyncMeta(), }; } diff --git a/x-pack/plugins/maps/public/classes/sources/es_agg_source/es_agg_source.test.ts b/x-pack/plugins/maps/public/classes/sources/es_agg_source/es_agg_source.test.ts index cf0170ab7f1bd..d31e8366e4ef4 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_agg_source/es_agg_source.test.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_agg_source/es_agg_source.test.ts @@ -31,7 +31,17 @@ const metricExamples = [ class TestESAggSource extends AbstractESAggSource { constructor(metrics: AggDescriptor[]) { - super({ type: 'test', id: 'foobar', indexPatternId: 'foobarid', metrics }, []); + super( + { + type: 'test', + id: 'foobar', + indexPatternId: 'foobarid', + metrics, + applyGlobalQuery: true, + applyGlobalTime: true, + }, + [] + ); } } diff --git a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.test.ts b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.test.ts index 3b1cf3293c0d3..8ac014c820ace 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.test.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.test.ts @@ -151,6 +151,7 @@ describe('ESGeoGridSource', () => { }, extent, applyGlobalQuery: true, + applyGlobalTime: true, fieldNames: [], buffer: extent, sourceQuery: { diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.test.ts b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.test.ts index e7099115ffe5e..ec14a80ae761e 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.test.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.test.ts @@ -103,6 +103,7 @@ describe('ESSearchSource', () => { }, sourceMeta: null, applyGlobalQuery: true, + applyGlobalTime: true, }; it('Should only include required props', async () => { diff --git a/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts b/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts index 68b6b131978ea..bef0b8c6ea7af 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_source/es_source.ts @@ -82,8 +82,9 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource type: isValidStringConfig(descriptor.type) ? descriptor.type! : '', indexPatternId: descriptor.indexPatternId!, applyGlobalQuery: - // backfill old _.get usage - typeof descriptor.applyGlobalQuery !== 'undefined' ? !!descriptor.applyGlobalQuery : true, + typeof descriptor.applyGlobalQuery !== 'undefined' ? descriptor.applyGlobalQuery : true, + applyGlobalTime: + typeof descriptor.applyGlobalTime !== 'undefined' ? descriptor.applyGlobalTime : true, }; } @@ -96,6 +97,14 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource return this._descriptor.id; } + getApplyGlobalQuery(): boolean { + return this._descriptor.applyGlobalQuery; + } + + getApplyGlobalTime(): boolean { + return this._descriptor.applyGlobalTime; + } + isFieldAware(): boolean { return true; } @@ -203,10 +212,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource initialSearchContext?: object ): Promise { const indexPattern = await this.getIndexPattern(); - const isTimeAware = await this.isTimeAware(); - const applyGlobalQuery = - typeof searchFilters.applyGlobalQuery === 'boolean' ? searchFilters.applyGlobalQuery : true; - const globalFilters: Filter[] = applyGlobalQuery ? searchFilters.filters : []; + const globalFilters: Filter[] = searchFilters.applyGlobalQuery ? searchFilters.filters : []; const allFilters: Filter[] = [...globalFilters]; if (this.isFilterByMapBounds() && 'buffer' in searchFilters && searchFilters.buffer) { // buffer can be empty @@ -226,7 +232,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource // @ts-expect-error allFilters.push(extentFilter); } - if (isTimeAware) { + if (searchFilters.applyGlobalTime && (await this.isTimeAware())) { const filter = getTimeFilter().createFilter(indexPattern, searchFilters.timeFilters); if (filter) { allFilters.push(filter); @@ -238,7 +244,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource searchSource.setField('index', indexPattern); searchSource.setField('size', limit); searchSource.setField('filter', allFilters); - if (applyGlobalQuery) { + if (searchFilters.applyGlobalQuery) { searchSource.setField('query', searchFilters.query); } diff --git a/x-pack/plugins/maps/public/classes/sources/es_term_source/es_term_source.ts b/x-pack/plugins/maps/public/classes/sources/es_term_source/es_term_source.ts index 3220253436168..8ef50a1cb7a1c 100644 --- a/x-pack/plugins/maps/public/classes/sources/es_term_source/es_term_source.ts +++ b/x-pack/plugins/maps/public/classes/sources/es_term_source/es_term_source.ts @@ -28,6 +28,7 @@ import { } from '../../../../common/descriptor_types'; import { Adapters } from '../../../../../../../src/plugins/inspector/common/adapters'; import { PropertiesMap } from '../../../../common/elasticsearch_util'; +import { isValidStringConfig } from '../../util/valid_string_config'; const TERMS_AGG_NAME = 'join'; const TERMS_BUCKET_KEYS_TO_IGNORE = ['key', 'doc_count']; @@ -48,12 +49,25 @@ export function extractPropertiesMap(rawEsData: any, countPropertyName: string): export class ESTermSource extends AbstractESAggSource { static type = SOURCE_TYPES.ES_TERM_SOURCE; + static createDescriptor(descriptor: Partial): ESTermSourceDescriptor { + const normalizedDescriptor = AbstractESAggSource.createDescriptor(descriptor); + if (!isValidStringConfig(descriptor.term)) { + throw new Error('Cannot create an ESTermSource without a term'); + } + return { + ...normalizedDescriptor, + term: descriptor.term!, + type: SOURCE_TYPES.ES_TERM_SOURCE, + }; + } + private readonly _termField: ESDocField; readonly _descriptor: ESTermSourceDescriptor; constructor(descriptor: ESTermSourceDescriptor, inspectorAdapters: Adapters) { - super(AbstractESAggSource.createDescriptor(descriptor), inspectorAdapters); - this._descriptor = descriptor; + const sourceDescriptor = ESTermSource.createDescriptor(descriptor); + super(sourceDescriptor, inspectorAdapters); + this._descriptor = sourceDescriptor; this._termField = new ESDocField({ fieldName: this._descriptor.term, source: this, diff --git a/x-pack/plugins/maps/public/classes/sources/kibana_regionmap_source/kibana_regionmap_source.ts b/x-pack/plugins/maps/public/classes/sources/kibana_regionmap_source/kibana_regionmap_source.ts index bf39d78a4784f..e6db127e45116 100644 --- a/x-pack/plugins/maps/public/classes/sources/kibana_regionmap_source/kibana_regionmap_source.ts +++ b/x-pack/plugins/maps/public/classes/sources/kibana_regionmap_source/kibana_regionmap_source.ts @@ -102,10 +102,6 @@ export class KibanaRegionmapSource extends AbstractVectorSource { return this._descriptor.name; } - async isTimeAware() { - return false; - } - canFormatFeatureProperties() { return true; } diff --git a/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx index 6390626b006b4..adc478c1f45d3 100644 --- a/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.tsx @@ -189,10 +189,6 @@ export class MVTSingleLayerVectorSource return null; } - getApplyGlobalQuery(): boolean { - return false; - } - isBoundsAware() { return false; } diff --git a/x-pack/plugins/maps/public/classes/sources/source.ts b/x-pack/plugins/maps/public/classes/sources/source.ts index f24ec012836b6..7a52c4e6fde20 100644 --- a/x-pack/plugins/maps/public/classes/sources/source.ts +++ b/x-pack/plugins/maps/public/classes/sources/source.ts @@ -60,6 +60,7 @@ export interface ISource { cloneDescriptor(): AbstractSourceDescriptor; getFieldNames(): string[]; getApplyGlobalQuery(): boolean; + getApplyGlobalTime(): boolean; getIndexPatternIds(): string[]; getQueryableIndexPatternIds(): string[]; getGeoGridPrecision(zoom: number): number; @@ -135,7 +136,11 @@ export class AbstractSource implements ISource { } getApplyGlobalQuery(): boolean { - return !!this._descriptor.applyGlobalQuery; + return false; + } + + getApplyGlobalTime(): boolean { + return false; } getIndexPatternIds(): string[] { diff --git a/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx b/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx index 38ff3b49a87f4..32db97708e397 100644 --- a/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx +++ b/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.tsx @@ -37,6 +37,7 @@ export interface GeoJsonWithMeta { export interface BoundsFilters { applyGlobalQuery: boolean; + applyGlobalTime: boolean; filters: Filter[]; query?: MapQuery; sourceQuery?: MapQuery; @@ -61,7 +62,6 @@ export interface IVectorSource extends ISource { getLeftJoinFields(): Promise; getSyncMeta(): VectorSourceSyncMeta | null; getFieldNames(): string[]; - getApplyGlobalQuery(): boolean; createField({ fieldName }: { fieldName: string }): IField; canFormatFeatureProperties(): boolean; getSupportedShapeTypes(): Promise; diff --git a/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts b/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts index 147870dbef371..a7919ad058e4b 100644 --- a/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts +++ b/x-pack/plugins/maps/public/classes/util/can_skip_fetch.ts @@ -84,9 +84,13 @@ export async function canSkipSourceUpdate({ return false; } + let updateDueToApplyGlobalTime = false; let updateDueToTime = false; if (timeAware) { - updateDueToTime = !_.isEqual(prevMeta.timeFilters, nextMeta.timeFilters); + updateDueToApplyGlobalTime = prevMeta.applyGlobalTime !== nextMeta.applyGlobalTime; + if (nextMeta.applyGlobalTime) { + updateDueToTime = !_.isEqual(prevMeta.timeFilters, nextMeta.timeFilters); + } } let updateDueToRefreshTimer = false; @@ -132,6 +136,7 @@ export async function canSkipSourceUpdate({ const updateDueToSourceMetaChange = !_.isEqual(prevMeta.sourceMeta, nextMeta.sourceMeta); return ( + !updateDueToApplyGlobalTime && !updateDueToTime && !updateDueToRefreshTimer && !updateDueToExtentChange && diff --git a/x-pack/plugins/maps/public/components/global_time_checkbox.tsx b/x-pack/plugins/maps/public/components/global_time_checkbox.tsx new file mode 100644 index 0000000000000..b224ad6474745 --- /dev/null +++ b/x-pack/plugins/maps/public/components/global_time_checkbox.tsx @@ -0,0 +1,32 @@ +/* + * 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 React from 'react'; +import { EuiFormRow, EuiSwitch, EuiSwitchEvent } from '@elastic/eui'; + +interface Props { + applyGlobalTime: boolean; + label: string; + setApplyGlobalTime: (applyGlobalTime: boolean) => void; +} + +export function GlobalTimeCheckbox({ applyGlobalTime, label, setApplyGlobalTime }: Props) { + const onApplyGlobalTimeChange = (event: EuiSwitchEvent) => { + setApplyGlobalTime(event.target.checked); + }; + + return ( + + + + ); +} diff --git a/x-pack/plugins/maps/public/connected_components/layer_panel/filter_editor/filter_editor.js b/x-pack/plugins/maps/public/connected_components/layer_panel/filter_editor/filter_editor.js index d2652fac5bd2c..70a04ec37860d 100644 --- a/x-pack/plugins/maps/public/connected_components/layer_panel/filter_editor/filter_editor.js +++ b/x-pack/plugins/maps/public/connected_components/layer_panel/filter_editor/filter_editor.js @@ -22,23 +22,26 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; import { getIndexPatternService, getData } from '../../../kibana_services'; import { GlobalFilterCheckbox } from '../../../components/global_filter_checkbox'; +import { GlobalTimeCheckbox } from '../../../components/global_time_checkbox'; export class FilterEditor extends Component { state = { isPopoverOpen: false, indexPatterns: [], + isSourceTimeAware: false, }; componentDidMount() { this._isMounted = true; this._loadIndexPatterns(); + this._loadSourceTimeAware(); } componentWillUnmount() { this._isMounted = false; } - _loadIndexPatterns = async () => { + async _loadIndexPatterns() { // Filter only effects source so only load source indices. const indexPatternIds = this.props.layer.getSource().getIndexPatternIds(); const indexPatterns = []; @@ -58,7 +61,14 @@ export class FilterEditor extends Component { } this.setState({ indexPatterns }); - }; + } + + async _loadSourceTimeAware() { + const isSourceTimeAware = await this.props.layer.getSource().isTimeAware(); + if (this._isMounted) { + this.setState({ isSourceTimeAware }); + } + } _toggle = () => { this.setState((prevState) => ({ @@ -79,6 +89,10 @@ export class FilterEditor extends Component { this.props.updateSourceProp(this.props.layer.getId(), 'applyGlobalQuery', applyGlobalQuery); }; + _onApplyGlobalTimeChange = (applyGlobalTime) => { + this.props.updateSourceProp(this.props.layer.getId(), 'applyGlobalTime', applyGlobalTime); + }; + _renderQueryPopover() { const layerQuery = this.props.layer.getQuery(); const { SearchBar } = getData().ui; @@ -165,6 +179,15 @@ export class FilterEditor extends Component { } render() { + const globalTimeCheckbox = this.state.isSourceTimeAware ? ( + + ) : null; return ( @@ -191,6 +214,8 @@ export class FilterEditor extends Component { applyGlobalQuery={this.props.layer.getSource().getApplyGlobalQuery()} setApplyGlobalQuery={this._onApplyGlobalQueryChange} /> + + {globalTimeCheckbox} ); } diff --git a/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/join_editor.tsx b/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/join_editor.tsx index 2065668858e22..2d14ba20047bc 100644 --- a/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/join_editor.tsx +++ b/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/join_editor.tsx @@ -66,6 +66,7 @@ export function JoinEditor({ joins, layer, onChange, leftJoinFields, layerDispla right: { id: uuid(), applyGlobalQuery: true, + applyGlobalTime: true, }, } as JoinDescriptor, ]); diff --git a/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js b/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js index 5b44801eb780d..54c2b908d1536 100644 --- a/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js +++ b/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/resources/join.js @@ -12,6 +12,7 @@ import { JoinExpression } from './join_expression'; import { MetricsExpression } from './metrics_expression'; import { WhereExpression } from './where_expression'; import { GlobalFilterCheckbox } from '../../../../components/global_filter_checkbox'; +import { GlobalTimeCheckbox } from '../../../../components/global_time_checkbox'; import { indexPatterns } from '../../../../../../../../src/plugins/data/public'; @@ -126,6 +127,16 @@ export class Join extends Component { }); }; + _onApplyGlobalTimeChange = (applyGlobalTime) => { + this.props.onChange({ + leftField: this.props.join.leftField, + right: { + ...this.props.join.right, + applyGlobalTime, + }, + }); + }; + render() { const { join, onRemove, leftFields, leftSourceName } = this.props; const { rightFields, indexPattern } = this.state; @@ -137,6 +148,7 @@ export class Join extends Component { let metricsExpression; let globalFilterCheckbox; + let globalTimeCheckbox; if (isJoinConfigComplete) { metricsExpression = ( @@ -148,16 +160,27 @@ export class Join extends Component { ); globalFilterCheckbox = ( - - + ); + if (this.state.indexPattern && this.state.indexPattern.timeFieldName) { + globalTimeCheckbox = ( + - - ); + ); + } } let whereExpression; @@ -194,22 +217,24 @@ export class Join extends Component { {metricsExpression} {whereExpression} - - {globalFilterCheckbox} - - + + {globalFilterCheckbox} + + {globalTimeCheckbox} + + ); } diff --git a/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/__snapshots__/toc_entry_actions_popover.test.tsx.snap b/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/__snapshots__/toc_entry_actions_popover.test.tsx.snap index 456414889c732..ea37e76bc8494 100644 --- a/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/__snapshots__/toc_entry_actions_popover.test.tsx.snap +++ b/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/__snapshots__/toc_entry_actions_popover.test.tsx.snap @@ -5,49 +5,35 @@ exports[`TOCEntryActionsPopover is rendered 1`] = ` anchorClassName="mapLayTocActions__popoverAnchor" anchorPosition="leftUp" button={ - - simulated tooltip content at zoom: 0 -
- - mockFootnoteIcon - - - simulated footnote at isUsingSearch: true -
- + - - - - mockIcon - - - layer 1 - - - - - mockFootnoteIcon - - - -
+ onClick={[Function]} + /> } className="mapLayTocActions" closePopover={[Function]} @@ -132,49 +118,35 @@ exports[`TOCEntryActionsPopover should disable fit to data when supportsFitToBou anchorClassName="mapLayTocActions__popoverAnchor" anchorPosition="leftUp" button={ - - simulated tooltip content at zoom: 0 -
- - mockFootnoteIcon - - - simulated footnote at isUsingSearch: true -
- + - - - - mockIcon - - - layer 1 - - - - - mockFootnoteIcon - - - -
+ onClick={[Function]} + /> } className="mapLayTocActions" closePopover={[Function]} @@ -259,49 +231,36 @@ exports[`TOCEntryActionsPopover should have "show layer" action when layer is no anchorClassName="mapLayTocActions__popoverAnchor" anchorPosition="leftUp" button={ - - simulated tooltip content at zoom: 0 -
- - mockFootnoteIcon - - - simulated footnote at isUsingSearch: true -
- + - - - - mockIcon - - - layer 1 - - - - - mockFootnoteIcon - - - -
+ onClick={[Function]} + /> } className="mapLayTocActions" closePopover={[Function]} @@ -386,49 +345,35 @@ exports[`TOCEntryActionsPopover should not show edit actions in read only mode 1 anchorClassName="mapLayTocActions__popoverAnchor" anchorPosition="leftUp" button={ - - simulated tooltip content at zoom: 0 -
- - mockFootnoteIcon - - - simulated footnote at isUsingSearch: true -
- + - - - - mockIcon - - - layer 1 - - - - - mockFootnoteIcon - - - -
+ onClick={[Function]} + /> } className="mapLayTocActions" closePopover={[Function]} diff --git a/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/index.ts b/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/index.ts index d8d43e1e1b27a..673bebc43582e 100644 --- a/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/index.ts +++ b/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/index.ts @@ -14,15 +14,12 @@ import { cloneLayer, removeLayer, } from '../../../../../../actions'; -import { getMapZoom, isUsingSearch } from '../../../../../../selectors/map_selectors'; import { getIsReadOnly } from '../../../../../../selectors/ui_selectors'; import { TOCEntryActionsPopover } from './toc_entry_actions_popover'; function mapStateToProps(state: MapStoreState) { return { isReadOnly: getIsReadOnly(state), - isUsingSearch: isUsingSearch(state), - zoom: getMapZoom(state), }; } @@ -43,8 +40,5 @@ function mapDispatchToProps(dispatch: ThunkDispatchmockIcon, - tooltipContent: `simulated tooltip content at zoom: ${zoom}`, - footnotes: [ - { - icon: mockFootnoteIcon, - message: `simulated footnote at isUsingSearch: ${isUsingSearch}`, - }, - ], - }; - } } const defaultProps = { @@ -59,11 +46,9 @@ const defaultProps = { fitToBounds: () => {}, isEditButtonDisabled: false, isReadOnly: false, - isUsingSearch: true, layer: new LayerMock(), removeLayer: () => {}, toggleVisible: () => {}, - zoom: 0, }; describe('TOCEntryActionsPopover', () => { diff --git a/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx b/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx index b46de57e6a789..4d669dfbe235e 100644 --- a/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx +++ b/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_actions_popover/toc_entry_actions_popover.tsx @@ -4,11 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { Component, Fragment } from 'react'; +import React, { Component } from 'react'; -import { EuiButtonEmpty, EuiPopover, EuiContextMenu, EuiIcon, EuiToolTip } from '@elastic/eui'; +import { EuiPopover, EuiContextMenu, EuiIcon } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { ILayer } from '../../../../../../classes/layers/layer'; +import { TOCEntryButton } from '../toc_entry_button'; interface Props { cloneLayer: (layerId: string) => void; @@ -18,11 +19,9 @@ interface Props { fitToBounds: (layerId: string) => void; isEditButtonDisabled: boolean; isReadOnly: boolean; - isUsingSearch: boolean; layer: ILayer; removeLayer: (layerId: string) => void; toggleVisible: (layerId: string) => void; - zoom: number; } interface State { @@ -82,55 +81,6 @@ export class TOCEntryActionsPopover extends Component { this.props.toggleVisible(this.props.layer.getId()); } - _renderPopoverToggleButton() { - const { icon, tooltipContent, footnotes } = this.props.layer.getIconAndTooltipContent( - this.props.zoom, - this.props.isUsingSearch - ); - - const footnoteIcons = footnotes.map((footnote, index) => { - return ( - - {''} - {footnote.icon} - - ); - }); - const footnoteTooltipContent = footnotes.map((footnote, index) => { - return ( -
- {footnote.icon} {footnote.message} -
- ); - }); - - return ( - - {tooltipContent} - {footnoteTooltipContent} - - } - > - - {icon} - {this.props.displayName} {footnoteIcons} - - - ); - } - _getActionsPanel() { const actionItems = [ { @@ -222,7 +172,14 @@ export class TOCEntryActionsPopover extends Component { + } isOpen={this.state.isPopoverOpen} closePopover={this._closePopover} panelPaddingSize="none" diff --git a/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_button/index.ts b/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_button/index.ts new file mode 100644 index 0000000000000..d83c158d0385f --- /dev/null +++ b/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_button/index.ts @@ -0,0 +1,20 @@ +/* + * 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 { connect } from 'react-redux'; +import { MapStoreState } from '../../../../../../reducers/store'; +import { getMapZoom, isUsingSearch } from '../../../../../../selectors/map_selectors'; +import { TOCEntryButton, StateProps, OwnProps } from './toc_entry_button'; + +function mapStateToProps(state: MapStoreState, ownProps: OwnProps): StateProps { + return { + isUsingSearch: isUsingSearch(state), + zoom: getMapZoom(state), + }; +} + +const connected = connect(mapStateToProps)(TOCEntryButton); +export { connected as TOCEntryButton }; diff --git a/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_button/toc_entry_button.tsx b/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_button/toc_entry_button.tsx new file mode 100644 index 0000000000000..87c60278b361a --- /dev/null +++ b/x-pack/plugins/maps/public/connected_components/widget_overlay/layer_control/layer_toc/toc_entry/toc_entry_button/toc_entry_button.tsx @@ -0,0 +1,184 @@ +/* + * 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 React, { Component, Fragment, ReactElement } from 'react'; + +import { EuiButtonEmpty, EuiIcon, EuiToolTip, EuiLoadingSpinner } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import { ILayer } from '../../../../../../classes/layers/layer'; + +interface Footnote { + icon: ReactElement; + message?: string | null; +} + +interface IconAndTooltipContent { + icon?: ReactElement | null; + tooltipContent?: string | null; + footnotes: Footnote[]; +} + +export interface StateProps { + isUsingSearch: boolean; + zoom: number; +} + +export interface OwnProps { + displayName: string; + escapedDisplayName: string; + layer: ILayer; + onClick: () => void; +} + +type Props = StateProps & OwnProps; + +interface State { + isFilteredByGlobalTime: boolean; +} + +export class TOCEntryButton extends Component { + private _isMounted: boolean = false; + + state: State = { + isFilteredByGlobalTime: false, + }; + + componentDidMount() { + this._isMounted = true; + this._loadIsFilteredByGlobalTime(); + } + + componentDidUpdate() { + this._loadIsFilteredByGlobalTime(); + } + + componentWillUnmount() { + this._isMounted = false; + } + + async _loadIsFilteredByGlobalTime() { + const isFilteredByGlobalTime = await this.props.layer.isFilteredByGlobalTime(); + if (this._isMounted && isFilteredByGlobalTime !== this.state.isFilteredByGlobalTime) { + this.setState({ isFilteredByGlobalTime }); + } + } + + getIconAndTooltipContent(): IconAndTooltipContent { + let icon; + let tooltipContent = null; + const footnotes = []; + if (this.props.layer.hasErrors()) { + icon = ( + + ); + tooltipContent = this.props.layer.getErrors(); + } else if (this.props.layer.isLayerLoading()) { + icon = ; + } else if (!this.props.layer.isVisible()) { + icon = ; + tooltipContent = i18n.translate('xpack.maps.layer.layerHiddenTooltip', { + defaultMessage: `Layer is hidden.`, + }); + } else if (!this.props.layer.showAtZoomLevel(this.props.zoom)) { + const minZoom = this.props.layer.getMinZoom(); + const maxZoom = this.props.layer.getMaxZoom(); + icon = ; + tooltipContent = i18n.translate('xpack.maps.layer.zoomFeedbackTooltip', { + defaultMessage: `Layer is visible between zoom levels {minZoom} and {maxZoom}.`, + values: { minZoom, maxZoom }, + }); + } else { + const customIconAndTooltipContent = this.props.layer.getCustomIconAndTooltipContent(); + if (customIconAndTooltipContent) { + icon = customIconAndTooltipContent.icon; + if (!customIconAndTooltipContent.areResultsTrimmed) { + tooltipContent = customIconAndTooltipContent.tooltipContent; + } else { + footnotes.push({ + icon: , + message: customIconAndTooltipContent.tooltipContent, + }); + } + } + + if (this.props.isUsingSearch && this.props.layer.getQueryableIndexPatternIds().length) { + footnotes.push({ + icon: , + message: i18n.translate('xpack.maps.layer.isUsingSearchMsg', { + defaultMessage: 'Results narrowed by search bar', + }), + }); + } + if (this.state.isFilteredByGlobalTime) { + footnotes.push({ + icon: , + message: i18n.translate('xpack.maps.layer.isUsingTimeFilter', { + defaultMessage: 'Results narrowed by time filter', + }), + }); + } + } + + return { + icon, + tooltipContent, + footnotes, + }; + } + + render() { + const { icon, tooltipContent, footnotes } = this.getIconAndTooltipContent(); + + const footnoteIcons = footnotes.map((footnote, index) => { + return ( + + {''} + {footnote.icon} + + ); + }); + const footnoteTooltipContent = footnotes.map((footnote, index) => { + return ( +
+ {footnote.icon} {footnote.message} +
+ ); + }); + + return ( + + {tooltipContent} + {footnoteTooltipContent} + + } + > + + {icon} + {this.props.displayName} {footnoteIcons} + + + ); + } +} From 291c34c84c46a08c53143d66f6bbeb797274e80c Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Tue, 10 Nov 2020 10:25:59 -0500 Subject: [PATCH 22/80] [App Search] Added the log retention panel to the Settings page (#82982) * Added LogRententionPanel * i18n * fix axe failure * Update x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/determine_tooltip_content.test.ts Co-authored-by: Constance * Apply suggestions from code review Co-authored-by: Constance * PR Feeback: interpolation * Apply suggestions from code review Co-authored-by: Constance Co-authored-by: Constance --- .../log_retention_panel.test.tsx | 187 ++++++++++++++++++ .../log_retention/log_retention_panel.tsx | 110 +++++++++++ .../log_retention/messaging/constants.ts | 119 +++++++++++ .../determine_tooltip_content.test.ts | 168 ++++++++++++++++ .../messaging/determine_tooltip_content.ts | 46 +++++ .../log_retention/messaging/index.test.tsx | 74 +++++++ .../log_retention/messaging/index.tsx | 46 +++++ .../settings/log_retention/messaging/types.ts | 18 ++ .../components/settings/settings.tsx | 19 +- 9 files changed, 782 insertions(+), 5 deletions(-) create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_panel.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_panel.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/constants.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/determine_tooltip_content.test.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/determine_tooltip_content.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/index.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/index.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/types.ts diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_panel.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_panel.test.tsx new file mode 100644 index 0000000000000..b4f7e92fac8cc --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_panel.test.tsx @@ -0,0 +1,187 @@ +/* + * 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 '../../../../__mocks__/kea.mock'; +import '../../../../__mocks__/shallow_useeffect.mock'; + +import { setMockActions, setMockValues } from '../../../../__mocks__'; + +import React from 'react'; +import { shallow } from 'enzyme'; + +import { LogRetentionPanel } from './log_retention_panel'; +import { ILogRetention } from './types'; + +describe('', () => { + const actions = { + fetchLogRetention: jest.fn(), + toggleLogRetention: jest.fn(), + }; + + beforeEach(() => { + jest.clearAllMocks(); + setMockActions(actions); + }); + + it('renders', () => { + const logRetentionPanel = shallow(); + expect(logRetentionPanel.find('[data-test-subj="LogRetentionPanel"]')).toHaveLength(1); + }); + + it('initializes data on mount', () => { + shallow(); + expect(actions.fetchLogRetention).toHaveBeenCalledTimes(1); + }); + + it('renders Analytics switch off when analytics log retention is false in LogRetentionLogic ', () => { + setMockValues({ + isLogRetentionUpdating: false, + logRetention: mockLogRetention({ + analytics: { + enabled: false, + }, + }), + }); + + const logRetentionPanel = shallow(); + expect( + logRetentionPanel.find('[data-test-subj="LogRetentionPanelAnalyticsSwitch"]').prop('checked') + ).toEqual(false); + }); + + it('renders Analytics switch on when analyticsLogRetention is true in LogRetentionLogic ', () => { + setMockValues({ + isLogRetentionUpdating: false, + logRetention: mockLogRetention({ + analytics: { + enabled: true, + }, + }), + }); + + const logRetentionPanel = shallow(); + expect( + logRetentionPanel.find('[data-test-subj="LogRetentionPanelAnalyticsSwitch"]').prop('checked') + ).toEqual(true); + }); + + it('renders API switch off when apiLogRetention is false in LogRetentionLogic ', () => { + setMockValues({ + isLogRetentionUpdating: false, + logRetention: mockLogRetention({ + api: { + enabled: false, + }, + }), + }); + + const logRetentionPanel = shallow(); + expect( + logRetentionPanel.find('[data-test-subj="LogRetentionPanelAPISwitch"]').prop('checked') + ).toEqual(false); + }); + + it('renders API switch on when apiLogRetention is true in LogRetentionLogic ', () => { + setMockValues({ + isLogRetentionUpdating: false, + logRetention: mockLogRetention({ + api: { + enabled: true, + }, + }), + }); + + const logRetentionPanel = shallow(); + expect( + logRetentionPanel.find('[data-test-subj="LogRetentionPanelAPISwitch"]').prop('checked') + ).toEqual(true); + }); + + it('enables both switches when isLogRetentionUpdating is false', () => { + setMockValues({ + isLogRetentionUpdating: false, + logRetention: mockLogRetention({}), + }); + const logRetentionPanel = shallow(); + expect( + logRetentionPanel.find('[data-test-subj="LogRetentionPanelAnalyticsSwitch"]').prop('disabled') + ).toEqual(false); + expect( + logRetentionPanel.find('[data-test-subj="LogRetentionPanelAPISwitch"]').prop('disabled') + ).toEqual(false); + }); + + it('disables both switches when isLogRetentionUpdating is true', () => { + setMockValues({ + isLogRetentionUpdating: true, + logRetention: mockLogRetention({}), + }); + const logRetentionPanel = shallow(); + + expect( + logRetentionPanel.find('[data-test-subj="LogRetentionPanelAnalyticsSwitch"]').prop('disabled') + ).toEqual(true); + expect( + logRetentionPanel.find('[data-test-subj="LogRetentionPanelAPISwitch"]').prop('disabled') + ).toEqual(true); + }); + + it('calls toggleLogRetention when analytics log retention option is changed', () => { + setMockValues({ + isLogRetentionUpdating: false, + logRetention: mockLogRetention({ + analytics: { + enabled: false, + }, + }), + }); + const logRetentionPanel = shallow(); + logRetentionPanel + .find('[data-test-subj="LogRetentionPanelAnalyticsSwitch"]') + .simulate('change'); + expect(actions.toggleLogRetention).toHaveBeenCalledWith('analytics'); + }); + + it('calls toggleLogRetention when api log retention option is changed', () => { + setMockValues({ + isLogRetentionUpdating: false, + logRetention: mockLogRetention({ + analytics: { + enabled: false, + }, + }), + }); + const logRetentionPanel = shallow(); + logRetentionPanel.find('[data-test-subj="LogRetentionPanelAPISwitch"]').simulate('change'); + expect(actions.toggleLogRetention).toHaveBeenCalledWith('api'); + }); +}); + +const mockLogRetention = (logRetention: Partial) => { + const baseLogRetention = { + analytics: { + disabledAt: null, + enabled: true, + retentionPolicy: { isDefault: true, minAgeDays: 180 }, + }, + api: { + disabledAt: null, + enabled: true, + retentionPolicy: { isDefault: true, minAgeDays: 180 }, + }, + }; + + return { + analytics: { + ...baseLogRetention.analytics, + ...logRetention.analytics, + }, + api: { + ...baseLogRetention.api, + ...logRetention.api, + }, + }; +}; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_panel.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_panel.tsx new file mode 100644 index 0000000000000..7b8eea061d110 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_panel.tsx @@ -0,0 +1,110 @@ +/* + * 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 React, { useEffect } from 'react'; +import { i18n } from '@kbn/i18n'; + +import { EuiLink, EuiSpacer, EuiSwitch, EuiText, EuiTextColor, EuiTitle } from '@elastic/eui'; +import { useActions, useValues } from 'kea'; + +import { LogRetentionLogic } from './log_retention_logic'; +import { AnalyticsLogRetentionMessage, ApiLogRetentionMessage } from './messaging'; +import { ELogRetentionOptions } from './types'; + +export const LogRetentionPanel: React.FC = () => { + const { toggleLogRetention, fetchLogRetention } = useActions(LogRetentionLogic); + + const { logRetention, isLogRetentionUpdating } = useValues(LogRetentionLogic); + + const hasILM = logRetention !== null; + const analyticsLogRetentionSettings = logRetention?.[ELogRetentionOptions.Analytics]; + const apiLogRetentionSettings = logRetention?.[ELogRetentionOptions.API]; + + useEffect(() => { + fetchLogRetention(); + }, []); + + return ( +
+ +

+ {i18n.translate('xpack.enterpriseSearch.appSearch.settings.logRetention.title', { + defaultMessage: 'Log Retention', + })} +

+
+ +

+ {i18n.translate('xpack.enterpriseSearch.appSearch.settings.logRetention.description', { + defaultMessage: 'Manage the default write settings for API Logs and Analytics.', + })}{' '} + + {i18n.translate('xpack.enterpriseSearch.appSearch.settings.logRetention.learnMore', { + defaultMessage: 'Learn more about retention settings.', + })} + +

+
+ + + + + {i18n.translate( + 'xpack.enterpriseSearch.appSearch.settings.logRetention.analytics.label', + { + defaultMessage: 'Analytics Logs', + } + )} + + {': '} + {hasILM && ( + + + + )} + + } + checked={!!analyticsLogRetentionSettings?.enabled} + onChange={() => toggleLogRetention(ELogRetentionOptions.Analytics)} + disabled={isLogRetentionUpdating} + data-test-subj="LogRetentionPanelAnalyticsSwitch" + /> + + + + + + {i18n.translate( + 'xpack.enterpriseSearch.appSearch.settings.logRetention.api.label', + { + defaultMessage: 'API Logs', + } + )} + + {': '} + {hasILM && ( + + + + )} + + } + checked={!!apiLogRetentionSettings?.enabled} + onChange={() => toggleLogRetention(ELogRetentionOptions.API)} + disabled={isLogRetentionUpdating} + data-test-subj="LogRetentionPanelAPISwitch" + /> + +
+ ); +}; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/constants.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/constants.ts new file mode 100644 index 0000000000000..f7f0fbdff1acb --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/constants.ts @@ -0,0 +1,119 @@ +/* + * 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 { i18n } from '@kbn/i18n'; + +import { ILogRetentionMessages } from './types'; +import { renderLogRetentionDate } from '.'; + +const ANALYTICS_NO_LOGGING = i18n.translate( + 'xpack.enterpriseSearch.appSearch.settings.logRetention.analytics.noLogging', + { + defaultMessage: 'Analytics collection has been disabled for all engines.', + } +); + +const ANALYTICS_NO_LOGGING_COLLECTED = (disabledAt: string) => + i18n.translate( + 'xpack.enterpriseSearch.appSearch.settings.logRetention.analytics.noLogging.collected', + { + defaultMessage: 'The last date analytics were collected was {disabledAt}.', + values: { disabledAt }, + } + ); + +const ANALYTICS_NO_LOGGING_NOT_COLLECTED = i18n.translate( + 'xpack.enterpriseSearch.appSearch.settings.logRetention.analytics.noLogging.notCollected', + { + defaultMessage: 'There are no analytics collected.', + } +); + +const ANALYTICS_ILM_DISABLED = i18n.translate( + 'xpack.enterpriseSearch.appSearch.settings.logRetention.analytics.ilmDisabled', + { + defaultMessage: "App Search isn't managing analytics retention.", + } +); + +const ANALYTICS_CUSTOM_POLICY = i18n.translate( + 'xpack.enterpriseSearch.appSearch.settings.logRetention.analytics.customPolicy', + { + defaultMessage: 'You have a custom analytics retention policy.', + } +); + +const ANALYTICS_STORED = (minAgeDays: number | null | undefined) => + i18n.translate('xpack.enterpriseSearch.appSearch.settings.logRetention.analytics.stored', { + defaultMessage: 'Your analytics are being stored for at least {minAgeDays} days.', + values: { minAgeDays }, + }); + +const API_NO_LOGGING = i18n.translate( + 'xpack.enterpriseSearch.appSearch.settings.logRetention.api.noLogging', + { + defaultMessage: 'API logging has been disabled for all engines.', + } +); + +const API_NO_LOGGING_COLLECTED = (disabledAt: string) => + i18n.translate('xpack.enterpriseSearch.appSearch.settings.logRetention.api.noLogging.collected', { + defaultMessage: 'The last date logs were collected was {disabledAt}.', + values: { disabledAt }, + }); + +const API_NO_LOGGING_NOT_COLLECTED = i18n.translate( + 'xpack.enterpriseSearch.appSearch.settings.logRetention.api.noLogging.notCollected', + { + defaultMessage: 'There are no logs collected.', + } +); + +const API_ILM_DISABLED = i18n.translate( + 'xpack.enterpriseSearch.appSearch.settings.logRetention.api.ilmDisabled', + { + defaultMessage: "App Search isn't managing API log retention.", + } +); + +const API_CUSTOM_POLICY = i18n.translate( + 'xpack.enterpriseSearch.appSearch.settings.logRetention.api.customPolicy', + { + defaultMessage: 'You have a custom API log retention policy.', + } +); + +const API_STORED = (minAgeDays: number | null | undefined) => + i18n.translate('xpack.enterpriseSearch.appSearch.settings.logRetention.api.stored', { + defaultMessage: 'Your logs are being stored for at least {minAgeDays} days.', + values: { minAgeDays }, + }); + +export const ANALYTICS_MESSAGES: ILogRetentionMessages = { + noLogging: (_, logRetentionSettings) => + `${ANALYTICS_NO_LOGGING} ${ + logRetentionSettings.disabledAt + ? ANALYTICS_NO_LOGGING_COLLECTED(renderLogRetentionDate(logRetentionSettings.disabledAt)) + : ANALYTICS_NO_LOGGING_NOT_COLLECTED + }`, + ilmDisabled: ANALYTICS_ILM_DISABLED, + customPolicy: ANALYTICS_CUSTOM_POLICY, + defaultPolicy: (_, logRetentionSettings) => + ANALYTICS_STORED(logRetentionSettings.retentionPolicy?.minAgeDays), +}; + +export const API_MESSAGES: ILogRetentionMessages = { + noLogging: (_, logRetentionSettings) => + `${API_NO_LOGGING} ${ + logRetentionSettings.disabledAt + ? API_NO_LOGGING_COLLECTED(renderLogRetentionDate(logRetentionSettings.disabledAt)) + : API_NO_LOGGING_NOT_COLLECTED + }`, + ilmDisabled: API_ILM_DISABLED, + customPolicy: API_CUSTOM_POLICY, + defaultPolicy: (_, logRetentionSettings) => + API_STORED(logRetentionSettings.retentionPolicy?.minAgeDays), +}; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/determine_tooltip_content.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/determine_tooltip_content.test.ts new file mode 100644 index 0000000000000..fbc2ccfbc8a52 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/determine_tooltip_content.test.ts @@ -0,0 +1,168 @@ +/* + * 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 { determineTooltipContent } from './determine_tooltip_content'; +import { ANALYTICS_MESSAGES, API_MESSAGES } from './constants'; + +describe('determineTooltipContent', () => { + const BASE_SETTINGS = { + disabledAt: null, + enabled: true, + retentionPolicy: null, + }; + + it('will return nothing if settings are not provided', () => { + expect(determineTooltipContent(ANALYTICS_MESSAGES, true)).toBeUndefined(); + }); + + describe('analytics messages', () => { + describe('when analytics logs are enabled', () => { + describe("and they're using the default policy", () => { + it('will render a retention policy message', () => { + expect( + determineTooltipContent(ANALYTICS_MESSAGES, true, { + ...BASE_SETTINGS, + enabled: true, + retentionPolicy: { + isDefault: true, + minAgeDays: 7, + }, + }) + ).toEqual('Your analytics are being stored for at least 7 days.'); + }); + }); + + describe('and there is a custom policy', () => { + it('will render a retention policy message', () => { + expect( + determineTooltipContent(ANALYTICS_MESSAGES, true, { + ...BASE_SETTINGS, + enabled: true, + retentionPolicy: { + isDefault: false, + minAgeDays: 7, + }, + }) + ).toEqual('You have a custom analytics retention policy.'); + }); + }); + }); + + describe('when analytics logs are disabled', () => { + describe('and there is no disabledAt date', () => { + it('will render a no logging message', () => { + expect( + determineTooltipContent(ANALYTICS_MESSAGES, true, { + ...BASE_SETTINGS, + enabled: false, + disabledAt: null, + }) + ).toEqual( + 'Analytics collection has been disabled for all engines. There are no analytics collected.' + ); + }); + }); + + describe('and there is a disabledAt date', () => { + it('will render a no logging message', () => { + expect( + determineTooltipContent(ANALYTICS_MESSAGES, true, { + ...BASE_SETTINGS, + enabled: false, + disabledAt: 'Thu, 05 Nov 2020 18:57:28 +0000', + }) + ).toEqual( + 'Analytics collection has been disabled for all engines. The last date analytics were collected was November 5, 2020.' + ); + }); + }); + }); + + describe('when ilm is disabled entirely', () => { + it('will render a no logging message', () => { + expect( + determineTooltipContent(ANALYTICS_MESSAGES, false, { + ...BASE_SETTINGS, + enabled: true, + }) + ).toEqual("App Search isn't managing analytics retention."); + }); + }); + }); + + describe('api messages', () => { + describe('when analytics logs are enabled', () => { + describe("and they're using the default policy", () => { + it('will render a retention policy message', () => { + expect( + determineTooltipContent(API_MESSAGES, true, { + ...BASE_SETTINGS, + enabled: true, + retentionPolicy: { + isDefault: true, + minAgeDays: 7, + }, + }) + ).toEqual('Your logs are being stored for at least 7 days.'); + }); + }); + + describe('and there is a custom policy', () => { + it('will render a retention policy message', () => { + expect( + determineTooltipContent(API_MESSAGES, true, { + ...BASE_SETTINGS, + enabled: true, + retentionPolicy: { + isDefault: false, + minAgeDays: 7, + }, + }) + ).toEqual('You have a custom API log retention policy.'); + }); + }); + }); + + describe('when analytics logs are disabled', () => { + describe('and there is no disabledAt date', () => { + it('will render a no logging message', () => { + expect( + determineTooltipContent(API_MESSAGES, true, { + ...BASE_SETTINGS, + enabled: false, + disabledAt: null, + }) + ).toEqual('API logging has been disabled for all engines. There are no logs collected.'); + }); + }); + + describe('and there is a disabledAt date', () => { + it('will render a no logging message', () => { + expect( + determineTooltipContent(API_MESSAGES, true, { + ...BASE_SETTINGS, + enabled: false, + disabledAt: 'Thu, 05 Nov 2020 18:57:28 +0000', + }) + ).toEqual( + 'API logging has been disabled for all engines. The last date logs were collected was November 5, 2020.' + ); + }); + }); + }); + + describe('when ilm is disabled entirely', () => { + it('will render a no logging message', () => { + expect( + determineTooltipContent(API_MESSAGES, false, { + ...BASE_SETTINGS, + enabled: true, + }) + ).toEqual("App Search isn't managing API log retention."); + }); + }); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/determine_tooltip_content.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/determine_tooltip_content.ts new file mode 100644 index 0000000000000..e361e28490a83 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/determine_tooltip_content.ts @@ -0,0 +1,46 @@ +/* + * 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 { ILogRetentionSettings } from '../types'; +import { TMessageStringOrFunction, ILogRetentionMessages } from './types'; + +export const determineTooltipContent = ( + messages: ILogRetentionMessages, + ilmEnabled: boolean, + logRetentionSettings?: ILogRetentionSettings +) => { + if (typeof logRetentionSettings === 'undefined') { + return; + } + + const renderOrReturnMessage = (message: TMessageStringOrFunction) => { + if (typeof message === 'function') { + return message(ilmEnabled, logRetentionSettings); + } + return message; + }; + + if (!logRetentionSettings.enabled) { + return renderOrReturnMessage(messages.noLogging); + } + if (logRetentionSettings.enabled && !ilmEnabled) { + return renderOrReturnMessage(messages.ilmDisabled); + } + if ( + logRetentionSettings.enabled && + ilmEnabled && + !logRetentionSettings.retentionPolicy?.isDefault + ) { + return renderOrReturnMessage(messages.customPolicy); + } + if ( + logRetentionSettings.enabled && + ilmEnabled && + logRetentionSettings.retentionPolicy?.isDefault + ) { + return renderOrReturnMessage(messages.defaultPolicy); + } +}; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/index.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/index.test.tsx new file mode 100644 index 0000000000000..b65ffc04ad700 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/index.test.tsx @@ -0,0 +1,74 @@ +/* + * 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 '../../../../../__mocks__/kea.mock'; +import { setMockValues } from '../../../../../__mocks__'; + +import React from 'react'; +import { shallow } from 'enzyme'; + +import { AnalyticsLogRetentionMessage, ApiLogRetentionMessage, renderLogRetentionDate } from '.'; + +describe('LogRetentionMessaging', () => { + const LOG_RETENTION = { + analytics: { + disabledAt: null, + enabled: true, + retentionPolicy: { isDefault: true, minAgeDays: 180 }, + }, + api: { + disabledAt: null, + enabled: true, + retentionPolicy: { isDefault: true, minAgeDays: 180 }, + }, + }; + + describe('renderLogRetentionDate', () => { + it('renders a formatted date', () => { + expect(renderLogRetentionDate('Thu, 05 Nov 2020 18:57:28 +0000')).toEqual('November 5, 2020'); + }); + }); + + describe('AnalyticsLogRetentionMessage', () => { + it('renders', () => { + setMockValues({ + ilmEnabled: true, + logRetention: LOG_RETENTION, + }); + const wrapper = shallow(); + expect(wrapper.text()).toEqual('Your analytics are being stored for at least 180 days.'); + }); + + it('renders nothing if logRetention is null', () => { + setMockValues({ + ilmEnabled: true, + logRetention: null, + }); + const wrapper = shallow(); + expect(wrapper.isEmptyRender()).toEqual(true); + }); + }); + + describe('ApiLogRetentionMessage', () => { + it('renders', () => { + setMockValues({ + ilmEnabled: true, + logRetention: LOG_RETENTION, + }); + const wrapper = shallow(); + expect(wrapper.text()).toEqual('Your logs are being stored for at least 180 days.'); + }); + + it('renders nothing if logRetention is null', () => { + setMockValues({ + ilmEnabled: true, + logRetention: null, + }); + const wrapper = shallow(); + expect(wrapper.isEmptyRender()).toEqual(true); + }); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/index.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/index.tsx new file mode 100644 index 0000000000000..9fe2e8dc72ed6 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/index.tsx @@ -0,0 +1,46 @@ +/* + * 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 React from 'react'; + +import { useValues } from 'kea'; +import moment from 'moment'; + +import { AppLogic } from '../../../../app_logic'; +import { LogRetentionLogic } from '../log_retention_logic'; +import { ELogRetentionOptions } from '../types'; + +import { determineTooltipContent } from './determine_tooltip_content'; +import { ANALYTICS_MESSAGES, API_MESSAGES } from './constants'; + +export const renderLogRetentionDate = (dateString: string) => + moment(dateString).format('MMMM D, YYYY'); + +export const AnalyticsLogRetentionMessage: React.FC = () => { + const { ilmEnabled } = useValues(AppLogic); + const { logRetention } = useValues(LogRetentionLogic); + if (!logRetention) return null; + + return ( + <> + {determineTooltipContent( + ANALYTICS_MESSAGES, + ilmEnabled, + logRetention[ELogRetentionOptions.Analytics] + )} + + ); +}; + +export const ApiLogRetentionMessage: React.FC = () => { + const { ilmEnabled } = useValues(AppLogic); + const { logRetention } = useValues(LogRetentionLogic); + if (!logRetention) return null; + + return ( + <>{determineTooltipContent(API_MESSAGES, ilmEnabled, logRetention[ELogRetentionOptions.API])} + ); +}; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/types.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/types.ts new file mode 100644 index 0000000000000..a9546343d9aa7 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/messaging/types.ts @@ -0,0 +1,18 @@ +/* + * 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 { ILogRetentionSettings } from '../types'; + +export type TMessageStringOrFunction = + | string + | ((ilmEnabled: boolean, logRetentionSettings: ILogRetentionSettings) => string); + +export interface ILogRetentionMessages { + noLogging: TMessageStringOrFunction; + ilmDisabled: TMessageStringOrFunction; + customPolicy: TMessageStringOrFunction; + defaultPolicy: TMessageStringOrFunction; +} diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/settings.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/settings.tsx index 13079bb380f13..7bd3683919bc1 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/settings.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/settings.tsx @@ -5,11 +5,17 @@ */ import React from 'react'; - -import { EuiPageHeader, EuiPageHeaderSection, EuiPageContentBody, EuiTitle } from '@elastic/eui'; +import { + EuiPageHeader, + EuiPageHeaderSection, + EuiPageContent, + EuiPageContentBody, + EuiTitle, +} from '@elastic/eui'; import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome'; import { FlashMessages } from '../../../shared/flash_messages'; +import { LogRetentionPanel } from './log_retention/log_retention_panel'; import { SETTINGS_TITLE } from './'; @@ -24,9 +30,12 @@ export const Settings: React.FC = () => {
- - - + + + + + + ); }; From 00ca555cd98b058420898498114666b443b0ccbf Mon Sep 17 00:00:00 2001 From: Yara Tercero Date: Tue, 10 Nov 2020 10:50:31 -0500 Subject: [PATCH 23/80] [Security Solution][Detections] - follow up cleanup on auto refresh rules (#83023) ### Summary This is a follow up cleanup PR to #82062 . There were a few comments I hadn't gotten to and wanted to follow up on. --- .../cypress/tasks/alerts_detection_rules.ts | 1 - .../detection_engine/rules/all/index.tsx | 19 +++++++------------ .../rules/all/utility_bar.test.tsx | 12 +++++++----- .../security_solution/server/ui_settings.ts | 17 +++++++++-------- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/x-pack/plugins/security_solution/cypress/tasks/alerts_detection_rules.ts b/x-pack/plugins/security_solution/cypress/tasks/alerts_detection_rules.ts index d4602dcd16db8..bcee151a6be42 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/alerts_detection_rules.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/alerts_detection_rules.ts @@ -125,7 +125,6 @@ export const waitForRulesToBeLoaded = () => { cy.get(ASYNC_LOADING_PROGRESS).should('not.exist'); }; -// when using, ensure you've called cy.clock prior in test export const checkAutoRefresh = (ms: number, condition: string) => { cy.get(ASYNC_LOADING_PROGRESS).should('not.be.visible'); cy.tick(ms); diff --git a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/index.tsx b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/index.tsx index 663a4bb242c06..dcf9765c0cdd1 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/index.tsx @@ -13,6 +13,7 @@ import { EuiProgress, EuiOverlayMask, EuiConfirmModal, + EuiWindowEvent, } from '@elastic/eui'; import React, { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react'; import { useHistory } from 'react-router-dom'; @@ -406,18 +407,6 @@ export const AllRules = React.memo( [setAutoRefreshOn, handleRefreshData] ); - useEffect(() => { - debounceResetIdleTimer(); - - window.addEventListener('mousemove', debounceResetIdleTimer, { passive: true }); - window.addEventListener('keydown', debounceResetIdleTimer); - - return () => { - window.removeEventListener('mousemove', debounceResetIdleTimer); - window.removeEventListener('keydown', debounceResetIdleTimer); - }; - }, [handleResetIdleTimer, debounceResetIdleTimer]); - const shouldShowRulesTable = useMemo( (): boolean => showRulesTable({ rulesCustomInstalled, rulesInstalled }) && !initLoading, [initLoading, rulesCustomInstalled, rulesInstalled] @@ -470,6 +459,12 @@ export const AllRules = React.memo( return ( <> + + + + + + ({ eui: euiDarkVars, darkMode: true }); + describe('AllRules', () => { it('renders AllRulesUtilityBar total rules and selected rules', () => { const wrapper = mount( - ({ eui: euiDarkVars, darkMode: true })}> + { it('renders utility actions if user has permissions', () => { const wrapper = mount( - ({ eui: euiDarkVars, darkMode: true })}> + { it('renders no utility actions if user has no permissions', () => { const wrapper = mount( - ({ eui: euiDarkVars, darkMode: true })}> + { it('invokes refresh on refresh action click', () => { const mockRefresh = jest.fn(); const wrapper = mount( - ({ eui: euiDarkVars, darkMode: true })}> + { it('invokes onRefreshSwitch when auto refresh switch is clicked', async () => { const mockSwitch = jest.fn(); const wrapper = mount( - ({ eui: euiDarkVars, darkMode: true })}> + { '

Default refresh interval for the Security time filter, in milliseconds.

', } ), - category: ['securitySolution'], + category: [APP_ID], requiresPageReload: true, schema: schema.object({ value: schema.number(), @@ -66,7 +67,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => { description: i18n.translate('xpack.securitySolution.uiSettings.defaultTimeRangeDescription', { defaultMessage: '

Default period of time in the Security time filter.

', }), - category: ['securitySolution'], + category: [APP_ID], requiresPageReload: true, schema: schema.object({ from: schema.string(), @@ -82,7 +83,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => { defaultMessage: '

Comma-delimited list of Elasticsearch indices from which the Security app collects events.

', }), - category: ['securitySolution'], + category: [APP_ID], requiresPageReload: true, schema: schema.arrayOf(schema.string()), }, @@ -99,7 +100,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => { '

Value above which Machine Learning job anomalies are displayed in the Security app.

Valid values: 0 to 100.

', } ), - category: ['securitySolution'], + category: [APP_ID], requiresPageReload: true, schema: schema.number(), }, @@ -112,7 +113,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => { defaultMessage: '

Enables the News feed

', }), type: 'boolean', - category: ['securitySolution'], + category: [APP_ID], requiresPageReload: true, schema: schema.boolean(), }, @@ -133,7 +134,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => { "value": ${DEFAULT_RULE_REFRESH_INTERVAL_VALUE}, "idleTimeout": ${DEFAULT_RULE_REFRESH_IDLE_VALUE} }`, - category: ['securitySolution'], + category: [APP_ID], requiresPageReload: true, schema: schema.object({ idleTimeout: schema.number({ min: 300000 }), @@ -149,7 +150,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => { description: i18n.translate('xpack.securitySolution.uiSettings.newsFeedUrlDescription', { defaultMessage: '

News feed content will be retrieved from this URL

', }), - category: ['securitySolution'], + category: [APP_ID], requiresPageReload: true, schema: schema.string(), }, @@ -166,7 +167,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => { 'Array of URL templates to build the list of reputation URLs to be displayed on the IP Details page.', } ), - category: ['securitySolution'], + category: [APP_ID], requiresPageReload: true, schema: schema.arrayOf( schema.object({ From 4dba10c76a7f5daead0650030d84393d65f65c06 Mon Sep 17 00:00:00 2001 From: Catherine Liu Date: Tue, 10 Nov 2020 09:51:27 -0600 Subject: [PATCH 24/80] Adds cloud links to user menu (#82803) Co-authored-by: Ryan Keairns --- x-pack/plugins/cloud/kibana.json | 2 +- x-pack/plugins/cloud/public/index.ts | 2 +- x-pack/plugins/cloud/public/mocks.ts | 18 +++ x-pack/plugins/cloud/public/plugin.ts | 28 +++- .../plugins/cloud/public/user_menu_links.ts | 38 +++++ x-pack/plugins/cloud/server/config.ts | 2 + x-pack/plugins/security/public/index.ts | 1 + x-pack/plugins/security/public/mocks.ts | 7 + .../security/public/nav_control/index.mock.ts | 14 ++ .../security/public/nav_control/index.ts | 3 +- .../nav_control/nav_control_component.scss | 11 ++ .../nav_control_component.test.tsx | 38 +++++ .../nav_control/nav_control_component.tsx | 139 ++++++++++++------ .../nav_control/nav_control_service.test.ts | 130 ++++++++++++++++ .../nav_control/nav_control_service.tsx | 41 +++++- .../plugins/security/public/plugin.test.tsx | 7 +- x-pack/plugins/security/public/plugin.tsx | 4 +- 17 files changed, 424 insertions(+), 61 deletions(-) create mode 100644 x-pack/plugins/cloud/public/mocks.ts create mode 100644 x-pack/plugins/cloud/public/user_menu_links.ts create mode 100644 x-pack/plugins/security/public/nav_control/index.mock.ts create mode 100644 x-pack/plugins/security/public/nav_control/nav_control_component.scss diff --git a/x-pack/plugins/cloud/kibana.json b/x-pack/plugins/cloud/kibana.json index 27b35bcbdd88b..9bca2f30bd23c 100644 --- a/x-pack/plugins/cloud/kibana.json +++ b/x-pack/plugins/cloud/kibana.json @@ -3,7 +3,7 @@ "version": "8.0.0", "kibanaVersion": "kibana", "configPath": ["xpack", "cloud"], - "optionalPlugins": ["usageCollection", "home"], + "optionalPlugins": ["usageCollection", "home", "security"], "server": true, "ui": true } diff --git a/x-pack/plugins/cloud/public/index.ts b/x-pack/plugins/cloud/public/index.ts index 39ef5f452c18b..680b2f1ad2bd6 100644 --- a/x-pack/plugins/cloud/public/index.ts +++ b/x-pack/plugins/cloud/public/index.ts @@ -7,7 +7,7 @@ import { PluginInitializerContext } from '../../../../src/core/public'; import { CloudPlugin } from './plugin'; -export { CloudSetup } from './plugin'; +export { CloudSetup, CloudConfigType } from './plugin'; export function plugin(initializerContext: PluginInitializerContext) { return new CloudPlugin(initializerContext); } diff --git a/x-pack/plugins/cloud/public/mocks.ts b/x-pack/plugins/cloud/public/mocks.ts new file mode 100644 index 0000000000000..bafebbca4ecdd --- /dev/null +++ b/x-pack/plugins/cloud/public/mocks.ts @@ -0,0 +1,18 @@ +/* + * 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. + */ + +function createSetupMock() { + return { + cloudId: 'mock-cloud-id', + isCloudEnabled: true, + resetPasswordUrl: 'reset-password-url', + accountUrl: 'account-url', + }; +} + +export const cloudMock = { + createSetup: createSetupMock, +}; diff --git a/x-pack/plugins/cloud/public/plugin.ts b/x-pack/plugins/cloud/public/plugin.ts index 45005f3f5e422..bc410b89c30e7 100644 --- a/x-pack/plugins/cloud/public/plugin.ts +++ b/x-pack/plugins/cloud/public/plugin.ts @@ -6,40 +6,51 @@ import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'src/core/public'; import { i18n } from '@kbn/i18n'; +import { SecurityPluginStart } from '../../security/public'; import { getIsCloudEnabled } from '../common/is_cloud_enabled'; import { ELASTIC_SUPPORT_LINK } from '../common/constants'; import { HomePublicPluginSetup } from '../../../../src/plugins/home/public'; +import { createUserMenuLinks } from './user_menu_links'; -interface CloudConfigType { +export interface CloudConfigType { id?: string; resetPasswordUrl?: string; deploymentUrl?: string; + accountUrl?: string; } interface CloudSetupDependencies { home?: HomePublicPluginSetup; } +interface CloudStartDependencies { + security?: SecurityPluginStart; +} + export interface CloudSetup { cloudId?: string; cloudDeploymentUrl?: string; isCloudEnabled: boolean; + resetPasswordUrl?: string; + accountUrl?: string; } export class CloudPlugin implements Plugin { private config!: CloudConfigType; + private isCloudEnabled: boolean; constructor(private readonly initializerContext: PluginInitializerContext) { this.config = this.initializerContext.config.get(); + this.isCloudEnabled = false; } public async setup(core: CoreSetup, { home }: CloudSetupDependencies) { const { id, resetPasswordUrl, deploymentUrl } = this.config; - const isCloudEnabled = getIsCloudEnabled(id); + this.isCloudEnabled = getIsCloudEnabled(id); if (home) { - home.environment.update({ cloud: isCloudEnabled }); - if (isCloudEnabled) { + home.environment.update({ cloud: this.isCloudEnabled }); + if (this.isCloudEnabled) { home.tutorials.setVariable('cloud', { id, resetPasswordUrl }); } } @@ -47,11 +58,11 @@ export class CloudPlugin implements Plugin { return { cloudId: id, cloudDeploymentUrl: deploymentUrl, - isCloudEnabled, + isCloudEnabled: this.isCloudEnabled, }; } - public start(coreStart: CoreStart) { + public start(coreStart: CoreStart, { security }: CloudStartDependencies) { const { deploymentUrl } = this.config; coreStart.chrome.setHelpSupportUrl(ELASTIC_SUPPORT_LINK); if (deploymentUrl) { @@ -63,5 +74,10 @@ export class CloudPlugin implements Plugin { href: deploymentUrl, }); } + + if (security && this.isCloudEnabled) { + const userMenuLinks = createUserMenuLinks(this.config); + security.navControlService.addUserMenuLinks(userMenuLinks); + } } } diff --git a/x-pack/plugins/cloud/public/user_menu_links.ts b/x-pack/plugins/cloud/public/user_menu_links.ts new file mode 100644 index 0000000000000..15e2f14e885ba --- /dev/null +++ b/x-pack/plugins/cloud/public/user_menu_links.ts @@ -0,0 +1,38 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { UserMenuLink } from '../../security/public'; +import { CloudConfigType } from '.'; + +export const createUserMenuLinks = (config: CloudConfigType): UserMenuLink[] => { + const { resetPasswordUrl, accountUrl } = config; + const userMenuLinks = [] as UserMenuLink[]; + + if (resetPasswordUrl) { + userMenuLinks.push({ + label: i18n.translate('xpack.cloud.userMenuLinks.profileLinkText', { + defaultMessage: 'Cloud profile', + }), + iconType: 'logoCloud', + href: resetPasswordUrl, + order: 100, + }); + } + + if (accountUrl) { + userMenuLinks.push({ + label: i18n.translate('xpack.cloud.userMenuLinks.accountLinkText', { + defaultMessage: 'Account & Billing', + }), + iconType: 'gear', + href: accountUrl, + order: 200, + }); + } + + return userMenuLinks; +}; diff --git a/x-pack/plugins/cloud/server/config.ts b/x-pack/plugins/cloud/server/config.ts index ff8a2c5acdf9a..eaa4ab7a482dd 100644 --- a/x-pack/plugins/cloud/server/config.ts +++ b/x-pack/plugins/cloud/server/config.ts @@ -23,6 +23,7 @@ const configSchema = schema.object({ apm: schema.maybe(apmConfigSchema), resetPasswordUrl: schema.maybe(schema.string()), deploymentUrl: schema.maybe(schema.string()), + accountUrl: schema.maybe(schema.string()), }); export type CloudConfigType = TypeOf; @@ -32,6 +33,7 @@ export const config: PluginConfigDescriptor = { id: true, resetPasswordUrl: true, deploymentUrl: true, + accountUrl: true, }, schema: configSchema, }; diff --git a/x-pack/plugins/security/public/index.ts b/x-pack/plugins/security/public/index.ts index 8016c94224060..d0382c22ed3c6 100644 --- a/x-pack/plugins/security/public/index.ts +++ b/x-pack/plugins/security/public/index.ts @@ -16,6 +16,7 @@ import { export { SecurityPluginSetup, SecurityPluginStart }; export { AuthenticatedUser } from '../common/model'; export { SecurityLicense, SecurityLicenseFeatures } from '../common/licensing'; +export { UserMenuLink } from '../public/nav_control'; export const plugin: PluginInitializer< SecurityPluginSetup, diff --git a/x-pack/plugins/security/public/mocks.ts b/x-pack/plugins/security/public/mocks.ts index 33c1d1446afba..26a759ca52267 100644 --- a/x-pack/plugins/security/public/mocks.ts +++ b/x-pack/plugins/security/public/mocks.ts @@ -7,6 +7,7 @@ import { authenticationMock } from './authentication/index.mock'; import { createSessionTimeoutMock } from './session/session_timeout.mock'; import { licenseMock } from '../common/licensing/index.mock'; +import { navControlServiceMock } from './nav_control/index.mock'; function createSetupMock() { return { @@ -15,7 +16,13 @@ function createSetupMock() { license: licenseMock.create(), }; } +function createStartMock() { + return { + navControlService: navControlServiceMock.createStart(), + }; +} export const securityMock = { createSetup: createSetupMock, + createStart: createStartMock, }; diff --git a/x-pack/plugins/security/public/nav_control/index.mock.ts b/x-pack/plugins/security/public/nav_control/index.mock.ts new file mode 100644 index 0000000000000..1cd10810d7c8f --- /dev/null +++ b/x-pack/plugins/security/public/nav_control/index.mock.ts @@ -0,0 +1,14 @@ +/* + * 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 { SecurityNavControlServiceStart } from '.'; + +export const navControlServiceMock = { + createStart: (): jest.Mocked => ({ + getUserMenuLinks$: jest.fn(), + addUserMenuLinks: jest.fn(), + }), +}; diff --git a/x-pack/plugins/security/public/nav_control/index.ts b/x-pack/plugins/security/public/nav_control/index.ts index 2b0af1a45d05a..737ae50054698 100644 --- a/x-pack/plugins/security/public/nav_control/index.ts +++ b/x-pack/plugins/security/public/nav_control/index.ts @@ -4,4 +4,5 @@ * you may not use this file except in compliance with the Elastic License. */ -export { SecurityNavControlService } from './nav_control_service'; +export { SecurityNavControlService, SecurityNavControlServiceStart } from './nav_control_service'; +export { UserMenuLink } from './nav_control_component'; diff --git a/x-pack/plugins/security/public/nav_control/nav_control_component.scss b/x-pack/plugins/security/public/nav_control/nav_control_component.scss new file mode 100644 index 0000000000000..a3e04b08cfac2 --- /dev/null +++ b/x-pack/plugins/security/public/nav_control/nav_control_component.scss @@ -0,0 +1,11 @@ +.chrNavControl__userMenu { + .euiContextMenuPanelTitle { + // Uppercased by default, override to match actual username + text-transform: none; + } + + .euiContextMenuItem { + // Temp fix for EUI issue https://github.com/elastic/eui/issues/3092 + line-height: normal; + } +} \ No newline at end of file diff --git a/x-pack/plugins/security/public/nav_control/nav_control_component.test.tsx b/x-pack/plugins/security/public/nav_control/nav_control_component.test.tsx index c1c6a9f69b6ec..1da91e80d062d 100644 --- a/x-pack/plugins/security/public/nav_control/nav_control_component.test.tsx +++ b/x-pack/plugins/security/public/nav_control/nav_control_component.test.tsx @@ -5,6 +5,7 @@ */ import React from 'react'; +import { BehaviorSubject } from 'rxjs'; import { shallowWithIntl, nextTick, mountWithIntl } from 'test_utils/enzyme_helpers'; import { SecurityNavControl } from './nav_control_component'; import { AuthenticatedUser } from '../../common/model'; @@ -17,6 +18,7 @@ describe('SecurityNavControl', () => { user: new Promise(() => {}) as Promise, editProfileUrl: '', logoutUrl: '', + userMenuLinks$: new BehaviorSubject([]), }; const wrapper = shallowWithIntl(); @@ -42,6 +44,7 @@ describe('SecurityNavControl', () => { user: Promise.resolve({ full_name: 'foo' }) as Promise, editProfileUrl: '', logoutUrl: '', + userMenuLinks$: new BehaviorSubject([]), }; const wrapper = shallowWithIntl(); @@ -70,6 +73,7 @@ describe('SecurityNavControl', () => { user: Promise.resolve({ full_name: 'foo' }) as Promise, editProfileUrl: '', logoutUrl: '', + userMenuLinks$: new BehaviorSubject([]), }; const wrapper = mountWithIntl(); @@ -91,6 +95,7 @@ describe('SecurityNavControl', () => { user: Promise.resolve({ full_name: 'foo' }) as Promise, editProfileUrl: '', logoutUrl: '', + userMenuLinks$: new BehaviorSubject([]), }; const wrapper = mountWithIntl(); @@ -107,4 +112,37 @@ describe('SecurityNavControl', () => { expect(findTestSubject(wrapper, 'profileLink')).toHaveLength(1); expect(findTestSubject(wrapper, 'logoutLink')).toHaveLength(1); }); + + it('renders a popover with additional user menu links registered by other plugins', async () => { + const props = { + user: Promise.resolve({ full_name: 'foo' }) as Promise, + editProfileUrl: '', + logoutUrl: '', + userMenuLinks$: new BehaviorSubject([ + { label: 'link1', href: 'path-to-link-1', iconType: 'empty', order: 1 }, + { label: 'link2', href: 'path-to-link-2', iconType: 'empty', order: 2 }, + { label: 'link3', href: 'path-to-link-3', iconType: 'empty', order: 3 }, + ]), + }; + + const wrapper = mountWithIntl(); + await nextTick(); + wrapper.update(); + + expect(findTestSubject(wrapper, 'userMenu')).toHaveLength(0); + expect(findTestSubject(wrapper, 'profileLink')).toHaveLength(0); + expect(findTestSubject(wrapper, 'userMenuLink__link1')).toHaveLength(0); + expect(findTestSubject(wrapper, 'userMenuLink__link2')).toHaveLength(0); + expect(findTestSubject(wrapper, 'userMenuLink__link3')).toHaveLength(0); + expect(findTestSubject(wrapper, 'logoutLink')).toHaveLength(0); + + wrapper.find(EuiHeaderSectionItemButton).simulate('click'); + + expect(findTestSubject(wrapper, 'userMenu')).toHaveLength(1); + expect(findTestSubject(wrapper, 'profileLink')).toHaveLength(1); + expect(findTestSubject(wrapper, 'userMenuLink__link1')).toHaveLength(1); + expect(findTestSubject(wrapper, 'userMenuLink__link2')).toHaveLength(1); + expect(findTestSubject(wrapper, 'userMenuLink__link3')).toHaveLength(1); + expect(findTestSubject(wrapper, 'logoutLink')).toHaveLength(1); + }); }); diff --git a/x-pack/plugins/security/public/nav_control/nav_control_component.tsx b/x-pack/plugins/security/public/nav_control/nav_control_component.tsx index 3ddabb0dc55f8..c22308fa8a43e 100644 --- a/x-pack/plugins/security/public/nav_control/nav_control_component.tsx +++ b/x-pack/plugins/security/public/nav_control/nav_control_component.tsx @@ -7,38 +7,52 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import React, { Component } from 'react'; - +import { Observable, Subscription } from 'rxjs'; import { EuiAvatar, - EuiFlexGroup, - EuiFlexItem, EuiHeaderSectionItemButton, - EuiLink, - EuiText, - EuiSpacer, EuiPopover, EuiLoadingSpinner, + EuiIcon, + EuiContextMenu, + EuiContextMenuPanelItemDescriptor, + IconType, + EuiText, } from '@elastic/eui'; import { AuthenticatedUser } from '../../common/model'; +import './nav_control_component.scss'; + +export interface UserMenuLink { + label: string; + iconType: IconType; + href: string; + order?: number; +} + interface Props { user: Promise; editProfileUrl: string; logoutUrl: string; + userMenuLinks$: Observable; } interface State { isOpen: boolean; authenticatedUser: AuthenticatedUser | null; + userMenuLinks: UserMenuLink[]; } export class SecurityNavControl extends Component { + private subscription?: Subscription; + constructor(props: Props) { super(props); this.state = { isOpen: false, authenticatedUser: null, + userMenuLinks: [], }; props.user.then((authenticatedUser) => { @@ -48,6 +62,18 @@ export class SecurityNavControl extends Component { }); } + componentDidMount() { + this.subscription = this.props.userMenuLinks$.subscribe(async (userMenuLinks) => { + this.setState({ userMenuLinks }); + }); + } + + componentWillUnmount() { + if (this.subscription) { + this.subscription.unsubscribe(); + } + } + onMenuButtonClick = () => { if (!this.state.authenticatedUser) { return; @@ -66,13 +92,13 @@ export class SecurityNavControl extends Component { render() { const { editProfileUrl, logoutUrl } = this.props; - const { authenticatedUser } = this.state; + const { authenticatedUser, userMenuLinks } = this.state; - const name = + const username = (authenticatedUser && (authenticatedUser.full_name || authenticatedUser.username)) || ''; const buttonContents = authenticatedUser ? ( - + ) : ( ); @@ -92,6 +118,60 @@ export class SecurityNavControl extends Component { ); + const profileMenuItem = { + name: ( + + ), + icon: , + href: editProfileUrl, + 'data-test-subj': 'profileLink', + }; + + const logoutMenuItem = { + name: ( + + ), + icon: , + href: logoutUrl, + 'data-test-subj': 'logoutLink', + }; + + const items: EuiContextMenuPanelItemDescriptor[] = []; + + items.push(profileMenuItem); + + if (userMenuLinks.length) { + const userMenuLinkMenuItems = userMenuLinks + .sort(({ order: orderA = Infinity }, { order: orderB = Infinity }) => orderA - orderB) + .map(({ label, iconType, href }: UserMenuLink) => ({ + name: {label}, + icon: , + href, + 'data-test-subj': `userMenuLink__${label}`, + })); + + items.push(...userMenuLinkMenuItems, { + isSeparator: true, + key: 'securityNavControlComponent__userMenuLinksSeparator', + }); + } + + items.push(logoutMenuItem); + + const panels = [ + { + id: 0, + title: username, + items, + }, + ]; + return ( { repositionOnScroll closePopover={this.closeMenu} panelPaddingSize="none" + buffer={0} > -
- - - - - - - -

{name}

-
- - - - - - - - - - - - - - - - - - - - -
-
+
+
); diff --git a/x-pack/plugins/security/public/nav_control/nav_control_service.test.ts b/x-pack/plugins/security/public/nav_control/nav_control_service.test.ts index acf62f3376b8b..5b9788d67500b 100644 --- a/x-pack/plugins/security/public/nav_control/nav_control_service.test.ts +++ b/x-pack/plugins/security/public/nav_control/nav_control_service.test.ts @@ -173,4 +173,134 @@ describe('SecurityNavControlService', () => { navControlService.start({ core: coreStart }); expect(coreStart.chrome.navControls.registerRight).toHaveBeenCalledTimes(2); }); + + describe(`#start`, () => { + it('should return functions to register and retrieve user menu links', () => { + const license$ = new BehaviorSubject(validLicense); + + const navControlService = new SecurityNavControlService(); + navControlService.setup({ + securityLicense: new SecurityLicenseService().setup({ license$ }).license, + authc: securityMock.createSetup().authc, + logoutUrl: '/some/logout/url', + }); + + const coreStart = coreMock.createStart(); + const navControlServiceStart = navControlService.start({ core: coreStart }); + expect(navControlServiceStart).toHaveProperty('getUserMenuLinks$'); + expect(navControlServiceStart).toHaveProperty('addUserMenuLinks'); + }); + + it('should register custom user menu links to be displayed in the nav controls', (done) => { + const license$ = new BehaviorSubject(validLicense); + + const navControlService = new SecurityNavControlService(); + navControlService.setup({ + securityLicense: new SecurityLicenseService().setup({ license$ }).license, + authc: securityMock.createSetup().authc, + logoutUrl: '/some/logout/url', + }); + + const coreStart = coreMock.createStart(); + const { getUserMenuLinks$, addUserMenuLinks } = navControlService.start({ core: coreStart }); + const userMenuLinks$ = getUserMenuLinks$(); + + addUserMenuLinks([ + { + label: 'link1', + href: 'path-to-link1', + iconType: 'empty', + }, + ]); + + userMenuLinks$.subscribe((links) => { + expect(links).toMatchInlineSnapshot(` + Array [ + Object { + "href": "path-to-link1", + "iconType": "empty", + "label": "link1", + }, + ] + `); + done(); + }); + }); + + it('should retrieve user menu links sorted by order', (done) => { + const license$ = new BehaviorSubject(validLicense); + + const navControlService = new SecurityNavControlService(); + navControlService.setup({ + securityLicense: new SecurityLicenseService().setup({ license$ }).license, + authc: securityMock.createSetup().authc, + logoutUrl: '/some/logout/url', + }); + + const coreStart = coreMock.createStart(); + const { getUserMenuLinks$, addUserMenuLinks } = navControlService.start({ core: coreStart }); + const userMenuLinks$ = getUserMenuLinks$(); + + addUserMenuLinks([ + { + label: 'link3', + href: 'path-to-link3', + iconType: 'empty', + order: 3, + }, + { + label: 'link1', + href: 'path-to-link1', + iconType: 'empty', + order: 1, + }, + { + label: 'link2', + href: 'path-to-link2', + iconType: 'empty', + order: 2, + }, + ]); + addUserMenuLinks([ + { + label: 'link4', + href: 'path-to-link4', + iconType: 'empty', + order: 4, + }, + ]); + + userMenuLinks$.subscribe((links) => { + expect(links).toMatchInlineSnapshot(` + Array [ + Object { + "href": "path-to-link1", + "iconType": "empty", + "label": "link1", + "order": 1, + }, + Object { + "href": "path-to-link2", + "iconType": "empty", + "label": "link2", + "order": 2, + }, + Object { + "href": "path-to-link3", + "iconType": "empty", + "label": "link3", + "order": 3, + }, + Object { + "href": "path-to-link4", + "iconType": "empty", + "label": "link4", + "order": 4, + }, + ] + `); + done(); + }); + }); + }); }); diff --git a/x-pack/plugins/security/public/nav_control/nav_control_service.tsx b/x-pack/plugins/security/public/nav_control/nav_control_service.tsx index aa3ec2e47469d..5d2e7d7dfb733 100644 --- a/x-pack/plugins/security/public/nav_control/nav_control_service.tsx +++ b/x-pack/plugins/security/public/nav_control/nav_control_service.tsx @@ -4,12 +4,16 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Subscription } from 'rxjs'; +import { sortBy } from 'lodash'; +import { Observable, Subscription, BehaviorSubject, ReplaySubject } from 'rxjs'; +import { map, takeUntil } from 'rxjs/operators'; import { CoreStart } from 'src/core/public'; + import ReactDOM from 'react-dom'; import React from 'react'; + import { SecurityLicense } from '../../common/licensing'; -import { SecurityNavControl } from './nav_control_component'; +import { SecurityNavControl, UserMenuLink } from './nav_control_component'; import { AuthenticationServiceSetup } from '../authentication'; interface SetupDeps { @@ -22,6 +26,18 @@ interface StartDeps { core: CoreStart; } +export interface SecurityNavControlServiceStart { + /** + * Returns an Observable of the array of user menu links registered by other plugins + */ + getUserMenuLinks$: () => Observable; + + /** + * Registers the provided user menu links to be displayed in the user menu in the global nav + */ + addUserMenuLinks: (newUserMenuLink: UserMenuLink[]) => void; +} + export class SecurityNavControlService { private securityLicense!: SecurityLicense; private authc!: AuthenticationServiceSetup; @@ -31,13 +47,16 @@ export class SecurityNavControlService { private securityFeaturesSubscription?: Subscription; + private readonly stop$ = new ReplaySubject(1); + private userMenuLinks$ = new BehaviorSubject([]); + public setup({ securityLicense, authc, logoutUrl }: SetupDeps) { this.securityLicense = securityLicense; this.authc = authc; this.logoutUrl = logoutUrl; } - public start({ core }: StartDeps) { + public start({ core }: StartDeps): SecurityNavControlServiceStart { this.securityFeaturesSubscription = this.securityLicense.features$.subscribe( ({ showLinks }) => { const isAnonymousPath = core.http.anonymousPaths.isAnonymous(window.location.pathname); @@ -49,6 +68,16 @@ export class SecurityNavControlService { } } ); + + return { + getUserMenuLinks$: () => + this.userMenuLinks$.pipe(map(this.sortUserMenuLinks), takeUntil(this.stop$)), + addUserMenuLinks: (userMenuLinks: UserMenuLink[]) => { + const currentLinks = this.userMenuLinks$.value; + const newLinks = [...currentLinks, ...userMenuLinks]; + this.userMenuLinks$.next(newLinks); + }, + }; } public stop() { @@ -57,6 +86,7 @@ export class SecurityNavControlService { this.securityFeaturesSubscription = undefined; } this.navControlRegistered = false; + this.stop$.next(); } private registerSecurityNavControl( @@ -72,6 +102,7 @@ export class SecurityNavControlService { user: currentUserPromise, editProfileUrl: core.http.basePath.prepend('/security/account'), logoutUrl: this.logoutUrl, + userMenuLinks$: this.userMenuLinks$, }; ReactDOM.render( @@ -86,4 +117,8 @@ export class SecurityNavControlService { this.navControlRegistered = true; } + + private sortUserMenuLinks(userMenuLinks: UserMenuLink[]) { + return sortBy(userMenuLinks, 'order'); + } } diff --git a/x-pack/plugins/security/public/plugin.test.tsx b/x-pack/plugins/security/public/plugin.test.tsx index d86d4812af5e3..6f5a2a031a7b2 100644 --- a/x-pack/plugins/security/public/plugin.test.tsx +++ b/x-pack/plugins/security/public/plugin.test.tsx @@ -97,7 +97,12 @@ describe('Security Plugin', () => { data: {} as DataPublicPluginStart, features: {} as FeaturesPluginStart, }) - ).toBeUndefined(); + ).toEqual({ + navControlService: { + getUserMenuLinks$: expect.any(Function), + addUserMenuLinks: expect.any(Function), + }, + }); }); it('starts Management Service if `management` plugin is available', () => { diff --git a/x-pack/plugins/security/public/plugin.tsx b/x-pack/plugins/security/public/plugin.tsx index 700653c4cecb8..f94772c43dd89 100644 --- a/x-pack/plugins/security/public/plugin.tsx +++ b/x-pack/plugins/security/public/plugin.tsx @@ -146,11 +146,13 @@ export class SecurityPlugin public start(core: CoreStart, { management, securityOss }: PluginStartDependencies) { this.sessionTimeout.start(); - this.navControlService.start({ core }); this.securityCheckupService.start({ securityOssStart: securityOss, docLinks: core.docLinks }); + if (management) { this.managementService.start({ capabilities: core.application.capabilities }); } + + return { navControlService: this.navControlService.start({ core }) }; } public stop() { From 8ff92f2b4051faa4969a909c858ca6ae0fdace52 Mon Sep 17 00:00:00 2001 From: Scotty Bollinger Date: Tue, 10 Nov 2020 10:30:45 -0600 Subject: [PATCH 25/80] [Workplace Search] Consolidate groups routes (#83015) * [Workplace Search] Consolidate groups routes This PR consolidates all of the groups route resgistration functions into a single export so that the `registerWorkplaceSearchRoutes` function only has to call the top-level routes * Remove redundant test --- .../server/routes/workplace_search/groups.ts | 10 ++++++++++ .../server/routes/workplace_search/index.ts | 18 ++---------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/enterprise_search/server/routes/workplace_search/groups.ts b/x-pack/plugins/enterprise_search/server/routes/workplace_search/groups.ts index 35c585eb9f781..fa01f983bbb89 100644 --- a/x-pack/plugins/enterprise_search/server/routes/workplace_search/groups.ts +++ b/x-pack/plugins/enterprise_search/server/routes/workplace_search/groups.ts @@ -223,3 +223,13 @@ export function registerBoostsGroupRoute({ } ); } + +export const registerGroupsRoutes = (dependencies: IRouteDependencies) => { + registerGroupsRoute(dependencies); + registerSearchGroupsRoute(dependencies); + registerGroupRoute(dependencies); + registerGroupUsersRoute(dependencies); + registerShareGroupRoute(dependencies); + registerAssignGroupRoute(dependencies); + registerBoostsGroupRoute(dependencies); +}; diff --git a/x-pack/plugins/enterprise_search/server/routes/workplace_search/index.ts b/x-pack/plugins/enterprise_search/server/routes/workplace_search/index.ts index a5ebcc0d05298..0edf0b980cf21 100644 --- a/x-pack/plugins/enterprise_search/server/routes/workplace_search/index.ts +++ b/x-pack/plugins/enterprise_search/server/routes/workplace_search/index.ts @@ -7,23 +7,9 @@ import { IRouteDependencies } from '../../plugin'; import { registerOverviewRoute } from './overview'; -import { - registerGroupsRoute, - registerSearchGroupsRoute, - registerGroupRoute, - registerGroupUsersRoute, - registerShareGroupRoute, - registerAssignGroupRoute, - registerBoostsGroupRoute, -} from './groups'; +import { registerGroupsRoutes } from './groups'; export const registerWorkplaceSearchRoutes = (dependencies: IRouteDependencies) => { registerOverviewRoute(dependencies); - registerGroupsRoute(dependencies); - registerSearchGroupsRoute(dependencies); - registerGroupRoute(dependencies); - registerGroupUsersRoute(dependencies); - registerShareGroupRoute(dependencies); - registerAssignGroupRoute(dependencies); - registerBoostsGroupRoute(dependencies); + registerGroupsRoutes(dependencies); }; From 915f718c6ec226421c7ada18f667d7fa721d4271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Kopyci=C5=84ski?= Date: Tue, 10 Nov 2020 17:36:35 +0100 Subject: [PATCH 26/80] [Security Solution] Fix DNS Network table query (#82778) --- .../components/paginated_table/helpers.ts | 5 +-- .../network/containers/network_dns/index.tsx | 4 +-- .../factory/network/dns/__mocks__/index.ts | 34 +++++++++++++++--- .../factory/network/dns/index.ts | 5 ++- .../network/dns/query.dns_network.dsl.ts | 36 +++++++++++-------- .../apis/security_solution/network_dns.ts | 5 ++- 6 files changed, 60 insertions(+), 29 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/components/paginated_table/helpers.ts b/x-pack/plugins/security_solution/public/common/components/paginated_table/helpers.ts index 8fde81adc922a..9685a260d2a1a 100644 --- a/x-pack/plugins/security_solution/public/common/components/paginated_table/helpers.ts +++ b/x-pack/plugins/security_solution/public/common/components/paginated_table/helpers.ts @@ -8,13 +8,14 @@ import { PaginationInputPaginated } from '../../../graphql/types'; export const generateTablePaginationOptions = ( activePage: number, - limit: number + limit: number, + isBucketSort?: boolean ): PaginationInputPaginated => { const cursorStart = activePage * limit; return { activePage, cursorStart, fakePossibleCount: 4 <= activePage && activePage > 0 ? limit * (activePage + 2) : limit * 5, - querySize: limit + cursorStart, + querySize: isBucketSort ? limit : limit + cursorStart, }; }; diff --git a/x-pack/plugins/security_solution/public/network/containers/network_dns/index.tsx b/x-pack/plugins/security_solution/public/network/containers/network_dns/index.tsx index fc00f8866ed2e..108bfa0c9df69 100644 --- a/x-pack/plugins/security_solution/public/network/containers/network_dns/index.tsx +++ b/x-pack/plugins/security_solution/public/network/containers/network_dns/index.tsx @@ -77,7 +77,7 @@ export const useNetworkDns = ({ factoryQueryType: NetworkQueries.dns, filterQuery: createFilter(filterQuery), isPtrIncluded, - pagination: generateTablePaginationOptions(activePage, limit), + pagination: generateTablePaginationOptions(activePage, limit, true), sort, timerange: { interval: '12h', @@ -193,7 +193,7 @@ export const useNetworkDns = ({ isPtrIncluded, factoryQueryType: NetworkQueries.dns, filterQuery: createFilter(filterQuery), - pagination: generateTablePaginationOptions(activePage, limit), + pagination: generateTablePaginationOptions(activePage, limit, true), sort, timerange: { interval: '12h', diff --git a/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/network/dns/__mocks__/index.ts b/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/network/dns/__mocks__/index.ts index d3625a96c6db9..d4cef30f3b320 100644 --- a/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/network/dns/__mocks__/index.ts +++ b/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/network/dns/__mocks__/index.ts @@ -146,10 +146,23 @@ export const formattedSearchStrategyResponse = { dns_name_query_count: { terms: { field: 'dns.question.registered_domain', - size: 10, - order: { unique_domains: 'desc' }, + size: 1000000, }, aggs: { + bucket_sort: { + bucket_sort: { + sort: [ + { + unique_domains: { + order: 'desc', + }, + }, + { _key: { order: 'asc' } }, + ], + from: 0, + size: 10, + }, + }, unique_domains: { cardinality: { field: 'dns.question.name' } }, dns_bytes_in: { sum: { field: 'source.bytes' } }, dns_bytes_out: { sum: { field: 'destination.bytes' } }, @@ -204,10 +217,23 @@ export const expectedDsl = { dns_name_query_count: { terms: { field: 'dns.question.registered_domain', - size: 10, - order: { unique_domains: 'desc' }, + size: 1000000, }, aggs: { + bucket_sort: { + bucket_sort: { + sort: [ + { + unique_domains: { + order: 'desc', + }, + }, + { _key: { order: 'asc' } }, + ], + from: 0, + size: 10, + }, + }, unique_domains: { cardinality: { field: 'dns.question.name' } }, dns_bytes_in: { sum: { field: 'source.bytes' } }, dns_bytes_out: { sum: { field: 'destination.bytes' } }, diff --git a/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/network/dns/index.ts b/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/network/dns/index.ts index ca7743126df4c..758731b674544 100644 --- a/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/network/dns/index.ts +++ b/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/network/dns/index.ts @@ -33,11 +33,10 @@ export const networkDns: SecuritySolutionFactory = { options: NetworkDnsRequestOptions, response: IEsSearchResponse ): Promise => { - const { activePage, cursorStart, fakePossibleCount, querySize } = options.pagination; + const { activePage, fakePossibleCount } = options.pagination; const totalCount = getOr(0, 'aggregations.dns_count.value', response.rawResponse); - const networkDnsEdges: NetworkDnsEdges[] = getDnsEdges(response); + const edges: NetworkDnsEdges[] = getDnsEdges(response); const fakeTotalCount = fakePossibleCount <= totalCount ? fakePossibleCount : totalCount; - const edges = networkDnsEdges.splice(cursorStart, querySize - cursorStart); const inspect = { dsl: [inspectStringifyObject(buildDnsQuery(options))], }; diff --git a/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/network/dns/query.dns_network.dsl.ts b/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/network/dns/query.dns_network.dsl.ts index 85b9051189bfe..7043b15ebb4dd 100644 --- a/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/network/dns/query.dns_network.dsl.ts +++ b/x-pack/plugins/security_solution/server/search_strategy/security_solution/factory/network/dns/query.dns_network.dsl.ts @@ -15,25 +15,27 @@ import { } from '../../../../../../common/search_strategy'; import { createQueryFilterClauses } from '../../../../../utils/build_query'; +const HUGE_QUERY_SIZE = 1000000; + type QueryOrder = - | { _count: Direction } - | { _key: Direction } - | { unique_domains: Direction } - | { dns_bytes_in: Direction } - | { dns_bytes_out: Direction }; + | { _count: { order: Direction } } + | { _key: { order: Direction } } + | { unique_domains: { order: Direction } } + | { dns_bytes_in: { order: Direction } } + | { dns_bytes_out: { order: Direction } }; const getQueryOrder = (sort: SortField): QueryOrder => { switch (sort.field) { case NetworkDnsFields.queryCount: - return { _count: sort.direction }; + return { _count: { order: sort.direction } }; case NetworkDnsFields.dnsName: - return { _key: sort.direction }; + return { _key: { order: sort.direction } }; case NetworkDnsFields.uniqueDomains: - return { unique_domains: sort.direction }; + return { unique_domains: { order: sort.direction } }; case NetworkDnsFields.dnsBytesIn: - return { dns_bytes_in: sort.direction }; + return { dns_bytes_in: { order: sort.direction } }; case NetworkDnsFields.dnsBytesOut: - return { dns_bytes_out: sort.direction }; + return { dns_bytes_out: { order: sort.direction } }; } assertUnreachable(sort.field); }; @@ -67,7 +69,7 @@ export const buildDnsQuery = ({ filterQuery, isPtrIncluded, sort, - pagination: { querySize }, + pagination: { cursorStart, querySize }, stackByField = 'dns.question.registered_domain', timerange: { from, to }, }: NetworkDnsRequestOptions) => { @@ -95,12 +97,16 @@ export const buildDnsQuery = ({ dns_name_query_count: { terms: { field: stackByField, - size: querySize, - order: { - ...getQueryOrder(sort), - }, + size: HUGE_QUERY_SIZE, }, aggs: { + bucket_sort: { + bucket_sort: { + sort: [getQueryOrder(sort), { _key: { order: 'asc' } }], + from: cursorStart, + size: querySize, + }, + }, unique_domains: { cardinality: { field: 'dns.question.name', diff --git a/x-pack/test/api_integration/apis/security_solution/network_dns.ts b/x-pack/test/api_integration/apis/security_solution/network_dns.ts index 966b8184965d1..9b7a39a279773 100644 --- a/x-pack/test/api_integration/apis/security_solution/network_dns.ts +++ b/x-pack/test/api_integration/apis/security_solution/network_dns.ts @@ -18,8 +18,7 @@ export default function ({ getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const supertest = getService('supertest'); - // Failing: See https://github.com/elastic/kibana/issues/82207 - describe.skip('Network DNS', () => { + describe('Network DNS', () => { describe('With packetbeat', () => { before(() => esArchiver.load('packetbeat/dns')); after(() => esArchiver.unload('packetbeat/dns')); @@ -59,7 +58,7 @@ export default function ({ getService }: FtrProviderContext) { expect(networkDns.edges.length).to.be(10); expect(networkDns.totalCount).to.be(44); expect(networkDns.edges.map((i: NetworkDnsEdges) => i.node.dnsName).join(',')).to.be( - 'aaplimg.com,adgrx.com,akadns.net,akamaiedge.net,amazonaws.com,cbsistatic.com,cdn-apple.com,connman.net,crowbird.com,d1oxlq5h9kq8q5.cloudfront.net' + 'aaplimg.com,adgrx.com,akadns.net,akamaiedge.net,amazonaws.com,cbsistatic.com,cdn-apple.com,connman.net,d1oxlq5h9kq8q5.cloudfront.net,d3epxf4t8a32oh.cloudfront.net' ); expect(networkDns.pageInfo.fakeTotalCount).to.equal(30); }); From 28305237a318212715491c4655f2b26e0f3d77bc Mon Sep 17 00:00:00 2001 From: Ryan Keairns Date: Tue, 10 Nov 2020 10:50:54 -0600 Subject: [PATCH 27/80] Remove kibana-core-ui-designers (#82962) The people in `kibana-core-ui-designers` have been rolled into the `kibana-design` team. All `.scss` changes will now ping `kibana-design` since the `kibana-core-ui-designers` entries were overrides (occurring later in this file). --- .github/CODEOWNERS | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6da2d5d602186..78e17de4139bd 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -369,13 +369,6 @@ x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @elastic/kib **/*.scss @elastic/kibana-design #CC# /packages/kbn-ui-framework/ @elastic/kibana-design -# Core UI design -/src/plugins/dashboard/**/*.scss @elastic/kibana-core-ui-designers -/src/plugins/embeddable/**/*.scss @elastic/kibana-core-ui-designers -/x-pack/plugins/canvas/**/*.scss @elastic/kibana-core-ui-designers -/x-pack/plugins/spaces/**/*.scss @elastic/kibana-core-ui-designers -/x-pack/plugins/security/**/*.scss @elastic/kibana-core-ui-designers - # Observability design /x-pack/plugins/apm/**/*.scss @elastic/observability-design /x-pack/plugins/infra/**/*.scss @elastic/observability-design From a63c390ae063db7ab9b4f8f1e1284b7b382d8b3b Mon Sep 17 00:00:00 2001 From: Aleh Zasypkin Date: Tue, 10 Nov 2020 18:12:47 +0100 Subject: [PATCH 28/80] Remove redundant call to `_authenticate` API after access token is created. (#82980) --- .github/CODEOWNERS | 1 - .../server/authentication/providers/base.ts | 19 +++- .../authentication/providers/kerberos.test.ts | 70 +++---------- .../authentication/providers/kerberos.ts | 61 +++++------- .../authentication/providers/oidc.test.ts | 20 +--- .../server/authentication/providers/oidc.ts | 91 +++++++---------- .../authentication/providers/pki.test.ts | 88 ++++------------- .../server/authentication/providers/pki.ts | 40 +++----- .../authentication/providers/saml.test.ts | 33 +++---- .../server/authentication/providers/saml.ts | 91 +++++++---------- .../authentication/providers/token.test.ts | 99 ++----------------- .../server/authentication/providers/token.ts | 63 +++++------- .../server/authentication/tokens.test.ts | 8 +- .../security/server/authentication/tokens.ts | 13 ++- .../security/server/elasticsearch/index.ts | 3 + x-pack/scripts/functional_tests.js | 2 +- .../tests/pki/pki_auth.ts | 2 +- .../tests/token/header.ts} | 6 +- .../tests/token/index.ts} | 6 +- .../tests/token/login.ts} | 5 +- .../tests/token/logout.ts} | 5 +- .../tests/token/session.ts} | 19 ++-- .../token.config.ts} | 8 +- 23 files changed, 258 insertions(+), 495 deletions(-) rename x-pack/test/{token_api_integration/auth/header.js => security_api_integration/tests/token/header.ts} (91%) rename x-pack/test/{token_api_integration/auth/index.js => security_api_integration/tests/token/index.ts} (72%) rename x-pack/test/{token_api_integration/auth/login.js => security_api_integration/tests/token/login.ts} (94%) rename x-pack/test/{token_api_integration/auth/logout.js => security_api_integration/tests/token/logout.ts} (91%) rename x-pack/test/{token_api_integration/auth/session.js => security_api_integration/tests/token/session.ts} (91%) rename x-pack/test/{token_api_integration/config.js => security_api_integration/token.config.ts} (81%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 78e17de4139bd..150e6431ec968 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -257,7 +257,6 @@ /x-pack/test/security_api_integration/ @elastic/kibana-security /x-pack/test/security_functional/ @elastic/kibana-security /x-pack/test/spaces_api_integration/ @elastic/kibana-security -/x-pack/test/token_api_integration/ @elastic/kibana-security #CC# /src/legacy/ui/public/capabilities @elastic/kibana-security #CC# /x-pack/legacy/plugins/encrypted_saved_objects/ @elastic/kibana-security #CC# /x-pack/plugins/security_solution/ @elastic/kibana-security diff --git a/x-pack/plugins/security/server/authentication/providers/base.ts b/x-pack/plugins/security/server/authentication/providers/base.ts index 030b2a6e968af..a5a68f2a49315 100644 --- a/x-pack/plugins/security/server/authentication/providers/base.ts +++ b/x-pack/plugins/security/server/authentication/providers/base.ts @@ -13,7 +13,8 @@ import { ILegacyClusterClient, Headers, } from '../../../../../../src/core/server'; -import { AuthenticatedUser } from '../../../common/model'; +import type { AuthenticatedUser } from '../../../common/model'; +import type { AuthenticationInfo } from '../../elasticsearch'; import { AuthenticationResult } from '../authentication_result'; import { DeauthenticationResult } from '../deauthentication_result'; import { Tokens } from '../tokens'; @@ -109,10 +110,20 @@ export abstract class BaseAuthenticationProvider { * @param [authHeaders] Optional `Headers` dictionary to send with the request. */ protected async getUser(request: KibanaRequest, authHeaders: Headers = {}) { - return deepFreeze({ - ...(await this.options.client + return this.authenticationInfoToAuthenticatedUser( + await this.options.client .asScoped({ headers: { ...request.headers, ...authHeaders } }) - .callAsCurrentUser('shield.authenticate')), + .callAsCurrentUser('shield.authenticate') + ); + } + + /** + * Converts Elasticsearch Authentication result to a Kibana authenticated user. + * @param authenticationInfo Result returned from the `_authenticate` operation. + */ + protected authenticationInfoToAuthenticatedUser(authenticationInfo: AuthenticationInfo) { + return deepFreeze({ + ...authenticationInfo, authentication_provider: { type: this.type, name: this.options.name }, } as AuthenticatedUser); } diff --git a/x-pack/plugins/security/server/authentication/providers/kerberos.test.ts b/x-pack/plugins/security/server/authentication/providers/kerberos.test.ts index af26d1e60414a..eb4ac8f4dcbed 100644 --- a/x-pack/plugins/security/server/authentication/providers/kerberos.test.ts +++ b/x-pack/plugins/security/server/authentication/providers/kerberos.test.ts @@ -118,12 +118,10 @@ describe('KerberosAuthenticationProvider', () => { headers: { authorization: 'negotiate spnego' }, }); - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); - mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'some-token', refresh_token: 'some-refresh-token', + authentication: user, }); await expect(operation(request)).resolves.toEqual( @@ -136,10 +134,7 @@ describe('KerberosAuthenticationProvider', () => { ) ); - expectAuthenticateCall(mockOptions.client, { - headers: { authorization: 'Bearer some-token' }, - }); - + expect(mockOptions.client.asScoped).not.toHaveBeenCalled(); expect(mockOptions.client.callAsInternalUser).toHaveBeenCalledWith('shield.getAccessToken', { body: { grant_type: '_kerberos', kerberos_ticket: 'spnego' }, }); @@ -153,13 +148,11 @@ describe('KerberosAuthenticationProvider', () => { headers: { authorization: 'negotiate spnego' }, }); - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); - mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'some-token', refresh_token: 'some-refresh-token', kerberos_authentication_response_token: 'response-token', + authentication: user, }); await expect(operation(request)).resolves.toEqual( @@ -173,10 +166,7 @@ describe('KerberosAuthenticationProvider', () => { ) ); - expectAuthenticateCall(mockOptions.client, { - headers: { authorization: 'Bearer some-token' }, - }); - + expect(mockOptions.client.asScoped).not.toHaveBeenCalled(); expect(mockOptions.client.callAsInternalUser).toHaveBeenCalledWith('shield.getAccessToken', { body: { grant_type: '_kerberos', kerberos_ticket: 'spnego' }, }); @@ -250,33 +240,6 @@ describe('KerberosAuthenticationProvider', () => { expect(request.headers.authorization).toBe('negotiate spnego'); }); - - it('fails if could not retrieve user using the new access token.', async () => { - const request = httpServerMock.createKibanaRequest({ - headers: { authorization: 'negotiate spnego' }, - }); - - const failureReason = LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()); - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); - mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); - mockOptions.client.callAsInternalUser.mockResolvedValue({ - access_token: 'some-token', - refresh_token: 'some-refresh-token', - }); - - await expect(operation(request)).resolves.toEqual(AuthenticationResult.failed(failureReason)); - - expectAuthenticateCall(mockOptions.client, { - headers: { authorization: 'Bearer some-token' }, - }); - - expect(mockOptions.client.callAsInternalUser).toHaveBeenCalledWith('shield.getAccessToken', { - body: { grant_type: '_kerberos', kerberos_ticket: 'spnego' }, - }); - - expect(request.headers.authorization).toBe('negotiate spnego'); - }); } describe('`login` method', () => { @@ -381,32 +344,21 @@ describe('KerberosAuthenticationProvider', () => { expect(request.headers).not.toHaveProperty('authorization'); }); - it('succeeds with valid session even if requiring a token refresh', async () => { + it('succeeds with a valid session even if requiring a token refresh', async () => { const user = mockAuthenticatedUser(); const request = httpServerMock.createKibanaRequest(); const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; - mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { - if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) { - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( - LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) - ); - return mockScopedClusterClient; - } - - if (scopeableRequest?.headers.authorization === 'Bearer newfoo') { - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); - return mockScopedClusterClient; - } - - throw new Error('Unexpected call'); - }); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); + mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( + LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) + ); + mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.tokens.refresh.mockResolvedValue({ accessToken: 'newfoo', refreshToken: 'newbar', + authenticationInfo: user, }); await expect(provider.authenticate(request, tokenPair)).resolves.toEqual( diff --git a/x-pack/plugins/security/server/authentication/providers/kerberos.ts b/x-pack/plugins/security/server/authentication/providers/kerberos.ts index fa578b9dca45f..2e15893d0845f 100644 --- a/x-pack/plugins/security/server/authentication/providers/kerberos.ts +++ b/x-pack/plugins/security/server/authentication/providers/kerberos.ts @@ -10,11 +10,12 @@ import { LegacyElasticsearchErrorHelpers, KibanaRequest, } from '../../../../../../src/core/server'; +import type { AuthenticationInfo } from '../../elasticsearch'; import { AuthenticationResult } from '../authentication_result'; import { DeauthenticationResult } from '../deauthentication_result'; import { HTTPAuthorizationHeader } from '../http_authentication'; import { canRedirectRequest } from '../can_redirect_request'; -import { Tokens, TokenPair } from '../tokens'; +import { Tokens, TokenPair, RefreshTokenResult } from '../tokens'; import { BaseAuthenticationProvider } from './base'; /** @@ -149,6 +150,7 @@ export class KerberosAuthenticationProvider extends BaseAuthenticationProvider { access_token: string; refresh_token: string; kerberos_authentication_response_token?: string; + authentication: AuthenticationInfo; }; try { tokens = await this.options.client.callAsInternalUser('shield.getAccessToken', { @@ -203,23 +205,16 @@ export class KerberosAuthenticationProvider extends BaseAuthenticationProvider { }; } - try { - // Then attempt to query for the user details using the new token - const authHeaders = { - authorization: new HTTPAuthorizationHeader('Bearer', tokens.access_token).toString(), - }; - const user = await this.getUser(request, authHeaders); - - this.logger.debug('User has been authenticated with new access token'); - return AuthenticationResult.succeeded(user, { - authHeaders, + return AuthenticationResult.succeeded( + this.authenticationInfoToAuthenticatedUser(tokens.authentication), + { + authHeaders: { + authorization: new HTTPAuthorizationHeader('Bearer', tokens.access_token).toString(), + }, authResponseHeaders, state: { accessToken: tokens.access_token, refreshToken: tokens.refresh_token }, - }); - } catch (err) { - this.logger.debug(`Failed to authenticate request via access token: ${err.message}`); - return AuthenticationResult.failed(err); - } + } + ); } /** @@ -260,9 +255,9 @@ export class KerberosAuthenticationProvider extends BaseAuthenticationProvider { private async authenticateViaRefreshToken(request: KibanaRequest, state: ProviderState) { this.logger.debug('Trying to refresh access token.'); - let refreshedTokenPair: TokenPair | null; + let refreshTokenResult: RefreshTokenResult | null; try { - refreshedTokenPair = await this.options.tokens.refresh(state.refreshToken); + refreshTokenResult = await this.options.tokens.refresh(state.refreshToken); } catch (err) { return AuthenticationResult.failed(err); } @@ -270,28 +265,22 @@ export class KerberosAuthenticationProvider extends BaseAuthenticationProvider { // If refresh token is no longer valid, let's try to renegotiate new tokens using SPNEGO. We // allow this because expired underlying token is an implementation detail and Kibana user // facing session is still valid. - if (refreshedTokenPair === null) { + if (refreshTokenResult === null) { this.logger.debug('Both access and refresh tokens are expired. Re-authenticating...'); return this.authenticateViaSPNEGO(request, state); } - try { - const authHeaders = { - authorization: new HTTPAuthorizationHeader( - 'Bearer', - refreshedTokenPair.accessToken - ).toString(), - }; - const user = await this.getUser(request, authHeaders); - - this.logger.debug('Request has been authenticated via refreshed token.'); - return AuthenticationResult.succeeded(user, { authHeaders, state: refreshedTokenPair }); - } catch (err) { - this.logger.debug( - `Failed to authenticate user using newly refreshed access token: ${err.message}` - ); - return AuthenticationResult.failed(err); - } + this.logger.debug('Request has been authenticated via refreshed token.'); + const { accessToken, refreshToken, authenticationInfo } = refreshTokenResult; + return AuthenticationResult.succeeded( + this.authenticationInfoToAuthenticatedUser(authenticationInfo), + { + authHeaders: { + authorization: new HTTPAuthorizationHeader('Bearer', accessToken).toString(), + }, + state: { accessToken, refreshToken }, + } + ); } /** diff --git a/x-pack/plugins/security/server/authentication/providers/oidc.test.ts b/x-pack/plugins/security/server/authentication/providers/oidc.test.ts index dfea7e508b333..126306c885e53 100644 --- a/x-pack/plugins/security/server/authentication/providers/oidc.test.ts +++ b/x-pack/plugins/security/server/authentication/providers/oidc.test.ts @@ -175,6 +175,7 @@ describe('OIDCAuthenticationProvider', () => { const { request, attempt, expectedRedirectURI } = getMocks(); mockOptions.client.callAsInternalUser.mockResolvedValue({ + authentication: mockUser, access_token: 'some-token', refresh_token: 'some-refresh-token', }); @@ -440,25 +441,14 @@ describe('OIDCAuthenticationProvider', () => { const request = httpServerMock.createKibanaRequest(); const tokenPair = { accessToken: 'expired-token', refreshToken: 'valid-refresh-token' }; - mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { - if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) { - const mockScopedClusterClientToFail = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClientToFail.callAsCurrentUser.mockRejectedValue( - LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) - ); - return mockScopedClusterClientToFail; - } - - if (scopeableRequest?.headers.authorization === 'Bearer new-access-token') { - return mockScopedClusterClient; - } - - throw new Error('Unexpected call'); - }); + mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( + LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) + ); mockOptions.tokens.refresh.mockResolvedValue({ accessToken: 'new-access-token', refreshToken: 'new-refresh-token', + authenticationInfo: mockUser, }); await expect( diff --git a/x-pack/plugins/security/server/authentication/providers/oidc.ts b/x-pack/plugins/security/server/authentication/providers/oidc.ts index eede9f334a5a1..250641d1cf174 100644 --- a/x-pack/plugins/security/server/authentication/providers/oidc.ts +++ b/x-pack/plugins/security/server/authentication/providers/oidc.ts @@ -7,12 +7,12 @@ import Boom from '@hapi/boom'; import type from 'type-detect'; import { KibanaRequest } from '../../../../../../src/core/server'; -import { AuthenticatedUser } from '../../../common/model'; +import type { AuthenticationInfo } from '../../elasticsearch'; import { AuthenticationResult } from '../authentication_result'; import { canRedirectRequest } from '../can_redirect_request'; import { DeauthenticationResult } from '../deauthentication_result'; import { HTTPAuthorizationHeader } from '../http_authentication'; -import { Tokens, TokenPair } from '../tokens'; +import { Tokens, TokenPair, RefreshTokenResult } from '../tokens'; import { AuthenticationProviderOptions, BaseAuthenticationProvider, @@ -243,46 +243,31 @@ export class OIDCAuthenticationProvider extends BaseAuthenticationProvider { } // We have all the necessary parameters, so attempt to complete the OpenID Connect Authentication - let accessToken; - let refreshToken; + let result: { access_token: string; refresh_token: string; authentication: AuthenticationInfo }; try { // This operation should be performed on behalf of the user with a privilege that normal // user usually doesn't have `cluster:admin/xpack/security/oidc/authenticate`. - const authenticateResponse = await this.options.client.callAsInternalUser( - 'shield.oidcAuthenticate', - { - body: { - state: stateOIDCState, - nonce: stateNonce, - redirect_uri: authenticationResponseURI, - realm: this.realm, - }, - } - ); - - accessToken = authenticateResponse.access_token; - refreshToken = authenticateResponse.refresh_token; - } catch (err) { - this.logger.debug(`Failed to authenticate request via OpenID Connect: ${err.message}`); - return AuthenticationResult.failed(err); - } - - // Now we need to retrieve full user information. - let user: Readonly; - try { - user = await this.getUser(request, { - authorization: new HTTPAuthorizationHeader('Bearer', accessToken).toString(), + result = await this.options.client.callAsInternalUser('shield.oidcAuthenticate', { + body: { + state: stateOIDCState, + nonce: stateNonce, + redirect_uri: authenticationResponseURI, + realm: this.realm, + }, }); } catch (err) { - this.logger.debug(`Failed to retrieve user using access token: ${err.message}`); + this.logger.debug(`Failed to authenticate request via OpenID Connect: ${err.message}`); return AuthenticationResult.failed(err); } this.logger.debug('Login has been performed with OpenID Connect response.'); - return AuthenticationResult.redirectTo(stateRedirectURL, { - state: { accessToken, refreshToken, realm: this.realm }, - user, + state: { + accessToken: result.access_token, + refreshToken: result.refresh_token, + realm: this.realm, + }, + user: this.authenticationInfoToAuthenticatedUser(result.authentication), }); } @@ -356,20 +341,17 @@ export class OIDCAuthenticationProvider extends BaseAuthenticationProvider { * @param request Request instance. * @param state State value previously stored by the provider. */ - private async authenticateViaRefreshToken( - request: KibanaRequest, - { refreshToken }: ProviderState - ) { + private async authenticateViaRefreshToken(request: KibanaRequest, state: ProviderState) { this.logger.debug('Trying to refresh elasticsearch access token.'); - if (!refreshToken) { + if (!state.refreshToken) { this.logger.debug('Refresh token is not found in state.'); return AuthenticationResult.notHandled(); } - let refreshedTokenPair: TokenPair | null; + let refreshTokenResult: RefreshTokenResult | null; try { - refreshedTokenPair = await this.options.tokens.refresh(refreshToken); + refreshTokenResult = await this.options.tokens.refresh(state.refreshToken); } catch (err) { return AuthenticationResult.failed(err); } @@ -380,7 +362,7 @@ export class OIDCAuthenticationProvider extends BaseAuthenticationProvider { // message. There are two reasons for `400` and not `401`: Elasticsearch search responds with `400` so it // seems logical to do the same on Kibana side and `401` would force user to logout and do full SLO if it's // supported. - if (refreshedTokenPair === null) { + if (refreshTokenResult === null) { if (canStartNewSession(request)) { this.logger.debug( 'Both elasticsearch access and refresh tokens are expired. Re-initiating OpenID Connect authentication.' @@ -393,24 +375,17 @@ export class OIDCAuthenticationProvider extends BaseAuthenticationProvider { ); } - try { - const authHeaders = { - authorization: new HTTPAuthorizationHeader( - 'Bearer', - refreshedTokenPair.accessToken - ).toString(), - }; - const user = await this.getUser(request, authHeaders); - - this.logger.debug('Request has been authenticated via refreshed token.'); - return AuthenticationResult.succeeded(user, { - authHeaders, - state: { ...refreshedTokenPair, realm: this.realm }, - }); - } catch (err) { - this.logger.debug(`Failed to refresh elasticsearch access token: ${err.message}`); - return AuthenticationResult.failed(err); - } + this.logger.debug('Request has been authenticated via refreshed token.'); + const { accessToken, refreshToken, authenticationInfo } = refreshTokenResult; + return AuthenticationResult.succeeded( + this.authenticationInfoToAuthenticatedUser(authenticationInfo), + { + authHeaders: { + authorization: new HTTPAuthorizationHeader('Bearer', accessToken).toString(), + }, + state: { accessToken, refreshToken, realm: this.realm }, + } + ); } /** diff --git a/x-pack/plugins/security/server/authentication/providers/pki.test.ts b/x-pack/plugins/security/server/authentication/providers/pki.test.ts index 94308ab5f2403..aa85b8a43af4d 100644 --- a/x-pack/plugins/security/server/authentication/providers/pki.test.ts +++ b/x-pack/plugins/security/server/authentication/providers/pki.test.ts @@ -120,10 +120,10 @@ describe('PKIAuthenticationProvider', () => { }), }); - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); - mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); - mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'access-token' }); + mockOptions.client.callAsInternalUser.mockResolvedValue({ + authentication: user, + access_token: 'access-token', + }); await expect(operation(request)).resolves.toEqual( AuthenticationResult.succeeded( @@ -144,10 +144,7 @@ describe('PKIAuthenticationProvider', () => { ], }, }); - - expectAuthenticateCall(mockOptions.client, { - headers: { authorization: 'Bearer access-token' }, - }); + expect(mockOptions.client.asScoped).not.toHaveBeenCalled(); expect(request.headers).not.toHaveProperty('authorization'); }); @@ -162,10 +159,10 @@ describe('PKIAuthenticationProvider', () => { }), }); - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); - mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); - mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'access-token' }); + mockOptions.client.callAsInternalUser.mockResolvedValue({ + authentication: user, + access_token: 'access-token', + }); await expect(operation(request)).resolves.toEqual( AuthenticationResult.succeeded( @@ -181,10 +178,7 @@ describe('PKIAuthenticationProvider', () => { expect(mockOptions.client.callAsInternalUser).toHaveBeenCalledWith('shield.delegatePKI', { body: { x509_certificate_chain: ['fingerprint:2A:7A:C2:DD:base64'] }, }); - - expectAuthenticateCall(mockOptions.client, { - headers: { authorization: 'Bearer access-token' }, - }); + expect(mockOptions.client.asScoped).not.toHaveBeenCalled(); expect(request.headers).not.toHaveProperty('authorization'); }); @@ -209,35 +203,6 @@ describe('PKIAuthenticationProvider', () => { expect(request.headers).not.toHaveProperty('authorization'); }); - - it('fails if could not retrieve user using the new access token.', async () => { - const request = httpServerMock.createKibanaRequest({ - headers: {}, - socket: getMockSocket({ - authorized: true, - peerCertificate: getMockPeerCertificate('2A:7A:C2:DD'), - }), - }); - - const failureReason = LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()); - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(failureReason); - mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); - mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'access-token' }); - - await expect(operation(request)).resolves.toEqual(AuthenticationResult.failed(failureReason)); - - expect(mockOptions.client.callAsInternalUser).toHaveBeenCalledTimes(1); - expect(mockOptions.client.callAsInternalUser).toHaveBeenCalledWith('shield.delegatePKI', { - body: { x509_certificate_chain: ['fingerprint:2A:7A:C2:DD:base64'] }, - }); - - expectAuthenticateCall(mockOptions.client, { - headers: { authorization: 'Bearer access-token' }, - }); - - expect(request.headers).not.toHaveProperty('authorization'); - }); } describe('`login` method', () => { @@ -365,10 +330,10 @@ describe('PKIAuthenticationProvider', () => { }); const state = { accessToken: 'existing-token', peerCertificateFingerprint256: '3A:9A:C5:DD' }; - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); - mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); - mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'access-token' }); + mockOptions.client.callAsInternalUser.mockResolvedValue({ + authentication: user, + access_token: 'access-token', + }); await expect(provider.authenticate(request, state)).resolves.toEqual( AuthenticationResult.succeeded( @@ -402,25 +367,14 @@ describe('PKIAuthenticationProvider', () => { const user = mockAuthenticatedUser({ authentication_provider: { type: 'pki', name: 'pki' } }); const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser - // In response to call with an expired token. - .mockRejectedValueOnce( - LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) - ) - // In response to a call with a new token. - .mockResolvedValueOnce(user) // In response to call with an expired token. - .mockRejectedValueOnce( - LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) - ) - // In response to a call with a new token. - .mockResolvedValueOnce(user) // In response to call with an expired token. - .mockRejectedValueOnce( - LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) - ) - // In response to a call with a new token. - .mockResolvedValueOnce(user); + mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( + LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) + ); mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); - mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'access-token' }); + mockOptions.client.callAsInternalUser.mockResolvedValue({ + authentication: user, + access_token: 'access-token', + }); const nonAjaxRequest = httpServerMock.createKibanaRequest({ socket: getMockSocket({ diff --git a/x-pack/plugins/security/server/authentication/providers/pki.ts b/x-pack/plugins/security/server/authentication/providers/pki.ts index 3629a0ac34f02..974a838127e1d 100644 --- a/x-pack/plugins/security/server/authentication/providers/pki.ts +++ b/x-pack/plugins/security/server/authentication/providers/pki.ts @@ -7,6 +7,7 @@ import Boom from '@hapi/boom'; import { DetailedPeerCertificate } from 'tls'; import { KibanaRequest } from '../../../../../../src/core/server'; +import type { AuthenticationInfo } from '../../elasticsearch'; import { AuthenticationResult } from '../authentication_result'; import { DeauthenticationResult } from '../deauthentication_result'; import { HTTPAuthorizationHeader } from '../http_authentication'; @@ -218,13 +219,11 @@ export class PKIAuthenticationProvider extends BaseAuthenticationProvider { // We should collect entire certificate chain as an ordered array of certificates encoded as base64 strings. const certificateChain = this.getCertificateChain(peerCertificate); - let accessToken: string; + let result: { access_token: string; authentication: AuthenticationInfo }; try { - accessToken = ( - await this.options.client.callAsInternalUser('shield.delegatePKI', { - body: { x509_certificate_chain: certificateChain }, - }) - ).access_token; + result = await this.options.client.callAsInternalUser('shield.delegatePKI', { + body: { x509_certificate_chain: certificateChain }, + }); } catch (err) { this.logger.debug( `Failed to exchange peer certificate chain to an access token: ${err.message}` @@ -233,27 +232,18 @@ export class PKIAuthenticationProvider extends BaseAuthenticationProvider { } this.logger.debug('Successfully retrieved access token in exchange to peer certificate chain.'); - - try { - // Then attempt to query for the user details using the new token - const authHeaders = { - authorization: new HTTPAuthorizationHeader('Bearer', accessToken).toString(), - }; - const user = await this.getUser(request, authHeaders); - - this.logger.debug('User has been authenticated with new access token'); - return AuthenticationResult.succeeded(user, { - authHeaders, + return AuthenticationResult.succeeded( + this.authenticationInfoToAuthenticatedUser(result.authentication), + { + authHeaders: { + authorization: new HTTPAuthorizationHeader('Bearer', result.access_token).toString(), + }, state: { - accessToken, - // NodeJS typings don't include `fingerprint256` yet. - peerCertificateFingerprint256: (peerCertificate as any).fingerprint256, + accessToken: result.access_token, + peerCertificateFingerprint256: peerCertificate.fingerprint256, }, - }); - } catch (err) { - this.logger.debug(`Failed to authenticate request via access token: ${err.message}`); - return AuthenticationResult.failed(err); - } + } + ); } /** diff --git a/x-pack/plugins/security/server/authentication/providers/saml.test.ts b/x-pack/plugins/security/server/authentication/providers/saml.test.ts index a1f2e99c13357..03c0b7404da39 100644 --- a/x-pack/plugins/security/server/authentication/providers/saml.test.ts +++ b/x-pack/plugins/security/server/authentication/providers/saml.test.ts @@ -64,6 +64,7 @@ describe('SAMLAuthenticationProvider', () => { mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'some-token', refresh_token: 'some-refresh-token', + authentication: mockUser, }); await expect( @@ -99,6 +100,7 @@ describe('SAMLAuthenticationProvider', () => { mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'some-token', refresh_token: 'some-refresh-token', + authentication: mockUser, }); provider = new SAMLAuthenticationProvider(mockOptions, { @@ -180,6 +182,7 @@ describe('SAMLAuthenticationProvider', () => { mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'user-initiated-login-token', refresh_token: 'user-initiated-login-refresh-token', + authentication: mockUser, }); await expect( @@ -211,6 +214,7 @@ describe('SAMLAuthenticationProvider', () => { mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'user-initiated-login-token', refresh_token: 'user-initiated-login-refresh-token', + authentication: mockUser, }); provider = new SAMLAuthenticationProvider(mockOptions, { @@ -250,6 +254,7 @@ describe('SAMLAuthenticationProvider', () => { mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: 'idp-initiated-login-token', refresh_token: 'idp-initiated-login-refresh-token', + authentication: mockUser, }); await expect( @@ -306,6 +311,7 @@ describe('SAMLAuthenticationProvider', () => { username: 'user', access_token: 'valid-token', refresh_token: 'valid-refresh-token', + authentication: mockUser, }); provider = new SAMLAuthenticationProvider(mockOptions, { @@ -459,6 +465,7 @@ describe('SAMLAuthenticationProvider', () => { username: 'user', access_token: 'new-valid-token', refresh_token: 'new-valid-refresh-token', + authentication: mockUser, }); const failureReason = new Error('Failed to invalidate token!'); @@ -519,6 +526,7 @@ describe('SAMLAuthenticationProvider', () => { username: 'user', access_token: 'new-valid-token', refresh_token: 'new-valid-refresh-token', + authentication: mockUser, }); mockOptions.tokens.invalidate.mockResolvedValue(undefined); @@ -566,15 +574,11 @@ describe('SAMLAuthenticationProvider', () => { // The first call is made using tokens from existing session. mockScopedClusterClient.callAsCurrentUser.mockImplementationOnce(() => response); - // The second call is made using new tokens. - mockScopedClusterClient.callAsCurrentUser.mockImplementationOnce(() => - Promise.resolve(mockUser) - ); - mockOptions.client.callAsInternalUser.mockResolvedValue({ username: 'user', access_token: 'new-valid-token', refresh_token: 'new-valid-refresh-token', + authentication: mockUser, }); mockOptions.tokens.invalidate.mockResolvedValue(undefined); @@ -849,25 +853,14 @@ describe('SAMLAuthenticationProvider', () => { realm: 'test-realm', }; - mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { - if (scopeableRequest?.headers.authorization === `Bearer ${state.accessToken}`) { - const mockScopedClusterClientToFail = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClientToFail.callAsCurrentUser.mockRejectedValue( - LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) - ); - return mockScopedClusterClientToFail; - } - - if (scopeableRequest?.headers.authorization === 'Bearer new-access-token') { - return mockScopedClusterClient; - } - - throw new Error('Unexpected call'); - }); + mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( + LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) + ); mockOptions.tokens.refresh.mockResolvedValue({ accessToken: 'new-access-token', refreshToken: 'new-refresh-token', + authenticationInfo: mockUser, }); await expect(provider.authenticate(request, state)).resolves.toEqual( diff --git a/x-pack/plugins/security/server/authentication/providers/saml.ts b/x-pack/plugins/security/server/authentication/providers/saml.ts index 54619c851470a..8f31968e5f639 100644 --- a/x-pack/plugins/security/server/authentication/providers/saml.ts +++ b/x-pack/plugins/security/server/authentication/providers/saml.ts @@ -6,13 +6,13 @@ import Boom from '@hapi/boom'; import { KibanaRequest } from '../../../../../../src/core/server'; -import { AuthenticatedUser } from '../../../common/model'; import { isInternalURL } from '../../../common/is_internal_url'; +import type { AuthenticationInfo } from '../../elasticsearch'; import { AuthenticationResult } from '../authentication_result'; import { DeauthenticationResult } from '../deauthentication_result'; import { canRedirectRequest } from '../can_redirect_request'; import { HTTPAuthorizationHeader } from '../http_authentication'; -import { Tokens, TokenPair } from '../tokens'; +import { Tokens, TokenPair, RefreshTokenResult } from '../tokens'; import { AuthenticationProviderOptions, BaseAuthenticationProvider } from './base'; /** @@ -338,24 +338,17 @@ export class SAMLAuthenticationProvider extends BaseAuthenticationProvider { : 'Login has been initiated by Identity Provider.' ); - let accessToken; - let refreshToken; + let result: { access_token: string; refresh_token: string; authentication: AuthenticationInfo }; try { // This operation should be performed on behalf of the user with a privilege that normal // user usually doesn't have `cluster:admin/xpack/security/saml/authenticate`. - const authenticateResponse = await this.options.client.callAsInternalUser( - 'shield.samlAuthenticate', - { - body: { - ids: !isIdPInitiatedLogin ? [stateRequestId] : [], - content: samlResponse, - realm: this.realm, - }, - } - ); - - accessToken = authenticateResponse.access_token; - refreshToken = authenticateResponse.refresh_token; + result = await this.options.client.callAsInternalUser('shield.samlAuthenticate', { + body: { + ids: !isIdPInitiatedLogin ? [stateRequestId] : [], + content: samlResponse, + realm: this.realm, + }, + }); } catch (err) { this.logger.debug(`Failed to log in with SAML response: ${err.message}`); @@ -367,17 +360,6 @@ export class SAMLAuthenticationProvider extends BaseAuthenticationProvider { : AuthenticationResult.failed(err); } - // Now we need to retrieve full user information. - let user: Readonly; - try { - user = await this.getUser(request, { - authorization: new HTTPAuthorizationHeader('Bearer', accessToken).toString(), - }); - } catch (err) { - this.logger.debug(`Failed to retrieve user using access token: ${err.message}`); - return AuthenticationResult.failed(err); - } - // IdP can pass `RelayState` with the deep link in Kibana during IdP initiated login and // depending on the configuration we may need to redirect user to this URL. let redirectURLFromRelayState; @@ -401,7 +383,14 @@ export class SAMLAuthenticationProvider extends BaseAuthenticationProvider { this.logger.debug('Login has been performed with SAML response.'); return AuthenticationResult.redirectTo( redirectURLFromRelayState || stateRedirectURL || `${this.options.basePath.get(request)}/`, - { state: { accessToken, refreshToken, realm: this.realm }, user } + { + state: { + accessToken: result.access_token, + refreshToken: result.refresh_token, + realm: this.realm, + }, + user: this.authenticationInfoToAuthenticatedUser(result.authentication), + } ); } @@ -494,20 +483,17 @@ export class SAMLAuthenticationProvider extends BaseAuthenticationProvider { * @param request Request instance. * @param state State value previously stored by the provider. */ - private async authenticateViaRefreshToken( - request: KibanaRequest, - { refreshToken }: ProviderState - ) { + private async authenticateViaRefreshToken(request: KibanaRequest, state: ProviderState) { this.logger.debug('Trying to refresh access token.'); - if (!refreshToken) { + if (!state.refreshToken) { this.logger.debug('Refresh token is not found in state.'); return AuthenticationResult.notHandled(); } - let refreshedTokenPair: TokenPair | null; + let refreshTokenResult: RefreshTokenResult | null; try { - refreshedTokenPair = await this.options.tokens.refresh(refreshToken); + refreshTokenResult = await this.options.tokens.refresh(state.refreshToken); } catch (err) { return AuthenticationResult.failed(err); } @@ -517,7 +503,7 @@ export class SAMLAuthenticationProvider extends BaseAuthenticationProvider { // handshake. Obviously we can't do that for AJAX requests, so we just reply with `400` and clear error message. // There are two reasons for `400` and not `401`: Elasticsearch search responds with `400` so it seems logical // to do the same on Kibana side and `401` would force user to logout and do full SLO if it's supported. - if (refreshedTokenPair === null) { + if (refreshTokenResult === null) { if (canStartNewSession(request)) { this.logger.debug( 'Both access and refresh tokens are expired. Capturing redirect URL and re-initiating SAML handshake.' @@ -530,26 +516,17 @@ export class SAMLAuthenticationProvider extends BaseAuthenticationProvider { ); } - try { - const authHeaders = { - authorization: new HTTPAuthorizationHeader( - 'Bearer', - refreshedTokenPair.accessToken - ).toString(), - }; - const user = await this.getUser(request, authHeaders); - - this.logger.debug('Request has been authenticated via refreshed token.'); - return AuthenticationResult.succeeded(user, { - authHeaders, - state: { realm: this.realm, ...refreshedTokenPair }, - }); - } catch (err) { - this.logger.debug( - `Failed to authenticate user using newly refreshed access token: ${err.message}` - ); - return AuthenticationResult.failed(err); - } + this.logger.debug('Request has been authenticated via refreshed token.'); + const { accessToken, refreshToken, authenticationInfo } = refreshTokenResult; + return AuthenticationResult.succeeded( + this.authenticationInfoToAuthenticatedUser(authenticationInfo), + { + authHeaders: { + authorization: new HTTPAuthorizationHeader('Bearer', accessToken).toString(), + }, + state: { accessToken, refreshToken, realm: this.realm }, + } + ); } /** diff --git a/x-pack/plugins/security/server/authentication/providers/token.test.ts b/x-pack/plugins/security/server/authentication/providers/token.test.ts index 4501004ab69c1..e09400e9bb44a 100644 --- a/x-pack/plugins/security/server/authentication/providers/token.test.ts +++ b/x-pack/plugins/security/server/authentication/providers/token.test.ts @@ -49,13 +49,10 @@ describe('TokenAuthenticationProvider', () => { const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; const authorization = `Bearer ${tokenPair.accessToken}`; - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); - mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); - mockOptions.client.callAsInternalUser.mockResolvedValue({ access_token: tokenPair.accessToken, refresh_token: tokenPair.refreshToken, + authentication: user, }); await expect(provider.login(request, credentials)).resolves.toEqual( @@ -65,8 +62,7 @@ describe('TokenAuthenticationProvider', () => { ) ); - expectAuthenticateCall(mockOptions.client, { headers: { authorization } }); - + expect(mockOptions.client.asScoped).not.toHaveBeenCalled(); expect(mockOptions.client.callAsInternalUser).toHaveBeenCalledTimes(1); expect(mockOptions.client.callAsInternalUser).toHaveBeenCalledWith('shield.getAccessToken', { body: { grant_type: 'password', ...credentials }, @@ -93,36 +89,6 @@ describe('TokenAuthenticationProvider', () => { expect(request.headers).not.toHaveProperty('authorization'); }); - - it('fails if user cannot be retrieved during login attempt', async () => { - const request = httpServerMock.createKibanaRequest({ headers: {} }); - const credentials = { username: 'user', password: 'password' }; - const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; - const authorization = `Bearer ${tokenPair.accessToken}`; - - mockOptions.client.callAsInternalUser.mockResolvedValue({ - access_token: tokenPair.accessToken, - refresh_token: tokenPair.refreshToken, - }); - - const authenticationError = new Error('Some error'); - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError); - mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); - - await expect(provider.login(request, credentials)).resolves.toEqual( - AuthenticationResult.failed(authenticationError) - ); - - expectAuthenticateCall(mockOptions.client, { headers: { authorization } }); - - expect(mockOptions.client.callAsInternalUser).toHaveBeenCalledTimes(1); - expect(mockOptions.client.callAsInternalUser).toHaveBeenCalledWith('shield.getAccessToken', { - body: { grant_type: 'password', ...credentials }, - }); - - expect(request.headers).not.toHaveProperty('authorization'); - }); }); describe('`authenticate` method', () => { @@ -211,27 +177,16 @@ describe('TokenAuthenticationProvider', () => { const request = httpServerMock.createKibanaRequest(); const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; - mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { - if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) { - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( - LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) - ); - return mockScopedClusterClient; - } - - if (scopeableRequest?.headers.authorization === 'Bearer newfoo') { - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockResolvedValue(user); - return mockScopedClusterClient; - } - - throw new Error('Unexpected call'); - }); + const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); + mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( + LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) + ); + mockOptions.client.asScoped.mockReturnValue(mockScopedClusterClient); mockOptions.tokens.refresh.mockResolvedValue({ accessToken: 'newfoo', refreshToken: 'newbar', + authenticationInfo: user, }); await expect(provider.authenticate(request, tokenPair)).resolves.toEqual( @@ -381,44 +336,6 @@ describe('TokenAuthenticationProvider', () => { expect(request.headers).not.toHaveProperty('authorization'); }); - - it('fails if new access token is rejected after successful refresh', async () => { - const request = httpServerMock.createKibanaRequest(); - const tokenPair = { accessToken: 'foo', refreshToken: 'bar' }; - - const authenticationError = new errors.AuthenticationException('Some error'); - mockOptions.client.asScoped.mockImplementation((scopeableRequest) => { - if (scopeableRequest?.headers.authorization === `Bearer ${tokenPair.accessToken}`) { - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockRejectedValue( - LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(new Error()) - ); - return mockScopedClusterClient; - } - - if (scopeableRequest?.headers.authorization === 'Bearer newfoo') { - const mockScopedClusterClient = elasticsearchServiceMock.createLegacyScopedClusterClient(); - mockScopedClusterClient.callAsCurrentUser.mockRejectedValue(authenticationError); - return mockScopedClusterClient; - } - - throw new Error('Unexpected call'); - }); - - mockOptions.tokens.refresh.mockResolvedValue({ - accessToken: 'newfoo', - refreshToken: 'newbar', - }); - - await expect(provider.authenticate(request, tokenPair)).resolves.toEqual( - AuthenticationResult.failed(authenticationError) - ); - - expect(mockOptions.tokens.refresh).toHaveBeenCalledTimes(1); - expect(mockOptions.tokens.refresh).toHaveBeenCalledWith(tokenPair.refreshToken); - - expect(request.headers).not.toHaveProperty('authorization'); - }); }); describe('`logout` method', () => { diff --git a/x-pack/plugins/security/server/authentication/providers/token.ts b/x-pack/plugins/security/server/authentication/providers/token.ts index f919c20c15225..2032db4b0a8f2 100644 --- a/x-pack/plugins/security/server/authentication/providers/token.ts +++ b/x-pack/plugins/security/server/authentication/providers/token.ts @@ -10,7 +10,7 @@ import { AuthenticationResult } from '../authentication_result'; import { DeauthenticationResult } from '../deauthentication_result'; import { canRedirectRequest } from '../can_redirect_request'; import { HTTPAuthorizationHeader } from '../http_authentication'; -import { Tokens, TokenPair } from '../tokens'; +import { Tokens, TokenPair, RefreshTokenResult } from '../tokens'; import { BaseAuthenticationProvider } from './base'; /** @@ -63,23 +63,21 @@ export class TokenAuthenticationProvider extends BaseAuthenticationProvider { const { access_token: accessToken, refresh_token: refreshToken, + authentication: authenticationInfo, } = await this.options.client.callAsInternalUser('shield.getAccessToken', { body: { grant_type: 'password', username, password }, }); this.logger.debug('Get token API request to Elasticsearch successful'); - - // Then attempt to query for the user details using the new token - const authHeaders = { - authorization: new HTTPAuthorizationHeader('Bearer', accessToken).toString(), - }; - const user = await this.getUser(request, authHeaders); - - this.logger.debug('Login has been successfully performed.'); - return AuthenticationResult.succeeded(user, { - authHeaders, - state: { accessToken, refreshToken }, - }); + return AuthenticationResult.succeeded( + this.authenticationInfoToAuthenticatedUser(authenticationInfo), + { + authHeaders: { + authorization: new HTTPAuthorizationHeader('Bearer', accessToken).toString(), + }, + state: { accessToken, refreshToken }, + } + ); } catch (err) { this.logger.debug(`Failed to perform a login: ${err.message}`); return AuthenticationResult.failed(err); @@ -191,22 +189,19 @@ export class TokenAuthenticationProvider extends BaseAuthenticationProvider { * @param request Request instance. * @param state State value previously stored by the provider. */ - private async authenticateViaRefreshToken( - request: KibanaRequest, - { refreshToken }: ProviderState - ) { + private async authenticateViaRefreshToken(request: KibanaRequest, state: ProviderState) { this.logger.debug('Trying to refresh access token.'); - let refreshedTokenPair: TokenPair | null; + let refreshTokenResult: RefreshTokenResult | null; try { - refreshedTokenPair = await this.options.tokens.refresh(refreshToken); + refreshTokenResult = await this.options.tokens.refresh(state.refreshToken); } catch (err) { return AuthenticationResult.failed(err); } // If refresh token is no longer valid, then we should clear session and redirect user to the // login page to re-authenticate, or fail if redirect isn't possible. - if (refreshedTokenPair === null) { + if (refreshTokenResult === null) { if (canStartNewSession(request)) { this.logger.debug('Clearing session since both access and refresh tokens are expired.'); @@ -219,23 +214,17 @@ export class TokenAuthenticationProvider extends BaseAuthenticationProvider { ); } - try { - const authHeaders = { - authorization: new HTTPAuthorizationHeader( - 'Bearer', - refreshedTokenPair.accessToken - ).toString(), - }; - const user = await this.getUser(request, authHeaders); - - this.logger.debug('Request has been authenticated via refreshed token.'); - return AuthenticationResult.succeeded(user, { authHeaders, state: refreshedTokenPair }); - } catch (err) { - this.logger.debug( - `Failed to authenticate user using newly refreshed access token: ${err.message}` - ); - return AuthenticationResult.failed(err); - } + this.logger.debug('Request has been authenticated via refreshed token.'); + const { accessToken, refreshToken, authenticationInfo } = refreshTokenResult; + return AuthenticationResult.succeeded( + this.authenticationInfoToAuthenticatedUser(authenticationInfo), + { + authHeaders: { + authorization: new HTTPAuthorizationHeader('Bearer', accessToken).toString(), + }, + state: { accessToken, refreshToken }, + } + ); } /** diff --git a/x-pack/plugins/security/server/authentication/tokens.test.ts b/x-pack/plugins/security/server/authentication/tokens.test.ts index e8cf37330aff2..18fdcf8608d29 100644 --- a/x-pack/plugins/security/server/authentication/tokens.test.ts +++ b/x-pack/plugins/security/server/authentication/tokens.test.ts @@ -7,6 +7,7 @@ import { errors } from 'elasticsearch'; import { elasticsearchServiceMock, loggingSystemMock } from '../../../../../src/core/server/mocks'; +import { mockAuthenticatedUser } from '../../common/model/authenticated_user.mock'; import { ILegacyClusterClient, @@ -78,13 +79,18 @@ describe('Tokens', () => { }); it('returns token pair if refresh API call succeeds', async () => { + const authenticationInfo = mockAuthenticatedUser(); const tokenPair = { accessToken: 'access-token', refreshToken: 'refresh-token' }; mockClusterClient.callAsInternalUser.mockResolvedValue({ access_token: tokenPair.accessToken, refresh_token: tokenPair.refreshToken, + authentication: authenticationInfo, }); - await expect(tokens.refresh(refreshToken)).resolves.toEqual(tokenPair); + await expect(tokens.refresh(refreshToken)).resolves.toEqual({ + authenticationInfo, + ...tokenPair, + }); expect(mockClusterClient.callAsInternalUser).toHaveBeenCalledTimes(1); expect(mockClusterClient.callAsInternalUser).toHaveBeenCalledWith('shield.getAccessToken', { diff --git a/x-pack/plugins/security/server/authentication/tokens.ts b/x-pack/plugins/security/server/authentication/tokens.ts index 3918b0b190a15..a435452ae112f 100644 --- a/x-pack/plugins/security/server/authentication/tokens.ts +++ b/x-pack/plugins/security/server/authentication/tokens.ts @@ -5,6 +5,7 @@ */ import { ILegacyClusterClient, Logger } from '../../../../../src/core/server'; +import type { AuthenticationInfo } from '../elasticsearch'; import { getErrorStatusCode } from '../errors'; /** @@ -24,6 +25,13 @@ export interface TokenPair { readonly refreshToken: string; } +/** + * Represents the result of the token refresh operation. + */ +export interface RefreshTokenResult extends TokenPair { + authenticationInfo: AuthenticationInfo; +} + /** * Class responsible for managing access and refresh tokens (refresh, invalidate, etc.) used by * various authentication providers. @@ -44,19 +52,20 @@ export class Tokens { * Tries to exchange provided refresh token to a new pair of access and refresh tokens. * @param existingRefreshToken Refresh token to send to the refresh token API. */ - public async refresh(existingRefreshToken: string): Promise { + public async refresh(existingRefreshToken: string): Promise { try { // Token should be refreshed by the same user that obtained that token. const { access_token: accessToken, refresh_token: refreshToken, + authentication: authenticationInfo, } = await this.options.client.callAsInternalUser('shield.getAccessToken', { body: { grant_type: 'refresh_token', refresh_token: existingRefreshToken }, }); this.logger.debug('Access token has been successfully refreshed.'); - return { accessToken, refreshToken }; + return { accessToken, refreshToken, authenticationInfo }; } catch (err) { this.logger.debug(`Failed to refresh access token: ${err.message}`); diff --git a/x-pack/plugins/security/server/elasticsearch/index.ts b/x-pack/plugins/security/server/elasticsearch/index.ts index 793bdc1c6ad26..23e4876904c31 100644 --- a/x-pack/plugins/security/server/elasticsearch/index.ts +++ b/x-pack/plugins/security/server/elasticsearch/index.ts @@ -4,6 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ +import { AuthenticatedUser } from '../../common/model'; + +export type AuthenticationInfo = Omit; export { ElasticsearchService, ElasticsearchServiceSetup, diff --git a/x-pack/scripts/functional_tests.js b/x-pack/scripts/functional_tests.js index 5e877717fd21e..9db102e487116 100644 --- a/x-pack/scripts/functional_tests.js +++ b/x-pack/scripts/functional_tests.js @@ -42,7 +42,7 @@ const onlyNotInCoverageTests = [ require.resolve('../test/security_api_integration/pki.config.ts'), require.resolve('../test/security_api_integration/oidc.config.ts'), require.resolve('../test/security_api_integration/oidc_implicit_flow.config.ts'), - require.resolve('../test/token_api_integration/config.js'), + require.resolve('../test/security_api_integration/token.config.ts'), require.resolve('../test/observability_api_integration/basic/config.ts'), require.resolve('../test/observability_api_integration/trial/config.ts'), require.resolve('../test/encrypted_saved_objects_api_integration/config.ts'), diff --git a/x-pack/test/security_api_integration/tests/pki/pki_auth.ts b/x-pack/test/security_api_integration/tests/pki/pki_auth.ts index 0331f756712ca..93eabe33dc687 100644 --- a/x-pack/test/security_api_integration/tests/pki/pki_auth.ts +++ b/x-pack/test/security_api_integration/tests/pki/pki_auth.ts @@ -179,7 +179,7 @@ export default function ({ getService }: FtrProviderContext) { authentication_realm: { name: 'pki1', type: 'pki' }, lookup_realm: { name: 'pki1', type: 'pki' }, authentication_provider: { name: 'pki', type: 'pki' }, - authentication_type: 'token', + authentication_type: 'realm', }); checkCookieIsSet(request.cookie(response.headers['set-cookie'][0])!); diff --git a/x-pack/test/token_api_integration/auth/header.js b/x-pack/test/security_api_integration/tests/token/header.ts similarity index 91% rename from x-pack/test/token_api_integration/auth/header.js rename to x-pack/test/security_api_integration/tests/token/header.ts index 0cc233b56d984..2150d7a6269b0 100644 --- a/x-pack/test/token_api_integration/auth/header.js +++ b/x-pack/test/security_api_integration/tests/token/header.ts @@ -4,12 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -export default function ({ getService }) { +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertestWithoutAuth'); const es = getService('legacyEs'); async function createToken() { - const { access_token: accessToken } = await es.shield.getAccessToken({ + const { access_token: accessToken } = await (es as any).shield.getAccessToken({ body: { grant_type: 'password', username: 'elastic', diff --git a/x-pack/test/token_api_integration/auth/index.js b/x-pack/test/security_api_integration/tests/token/index.ts similarity index 72% rename from x-pack/test/token_api_integration/auth/index.js rename to x-pack/test/security_api_integration/tests/token/index.ts index e7b5a5b46a503..e9bf6c641fb1f 100644 --- a/x-pack/test/token_api_integration/auth/index.js +++ b/x-pack/test/security_api_integration/tests/token/index.ts @@ -4,8 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -export default function ({ loadTestFile }) { - describe('token-based auth', function () { +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('security APIs - Token', function () { this.tags('ciGroup6'); loadTestFile(require.resolve('./login')); loadTestFile(require.resolve('./logout')); diff --git a/x-pack/test/token_api_integration/auth/login.js b/x-pack/test/security_api_integration/tests/token/login.ts similarity index 94% rename from x-pack/test/token_api_integration/auth/login.js rename to x-pack/test/security_api_integration/tests/token/login.ts index b2dd870e018da..82abb10847e06 100644 --- a/x-pack/test/token_api_integration/auth/login.js +++ b/x-pack/test/security_api_integration/tests/token/login.ts @@ -5,11 +5,12 @@ */ import request from 'request'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertestWithoutAuth'); - function extractSessionCookie(response) { + function extractSessionCookie(response: { headers: Record }) { const cookie = (response.headers['set-cookie'] || []).find((header) => header.startsWith('sid=') ); diff --git a/x-pack/test/token_api_integration/auth/logout.js b/x-pack/test/security_api_integration/tests/token/logout.ts similarity index 91% rename from x-pack/test/token_api_integration/auth/logout.js rename to x-pack/test/security_api_integration/tests/token/logout.ts index fcc0e8182158f..ccd8b4586be2d 100644 --- a/x-pack/test/token_api_integration/auth/logout.js +++ b/x-pack/test/security_api_integration/tests/token/logout.ts @@ -5,11 +5,12 @@ */ import request from 'request'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertestWithoutAuth'); - function extractSessionCookie(response) { + function extractSessionCookie(response: { headers: Record }) { const cookie = (response.headers['set-cookie'] || []).find((header) => header.startsWith('sid=') ); diff --git a/x-pack/test/token_api_integration/auth/session.js b/x-pack/test/security_api_integration/tests/token/session.ts similarity index 91% rename from x-pack/test/token_api_integration/auth/session.js rename to x-pack/test/security_api_integration/tests/token/session.ts index 1f69b06315a80..30e004a0fff3c 100644 --- a/x-pack/test/token_api_integration/auth/session.js +++ b/x-pack/test/security_api_integration/tests/token/session.ts @@ -4,15 +4,16 @@ * you may not use this file except in compliance with the Elastic License. */ -import request from 'request'; +import request, { Cookie } from 'request'; import expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; -const delay = (ms) => new Promise((resolve) => setTimeout(() => resolve(), ms)); +const delay = (ms: number) => new Promise((resolve) => setTimeout(() => resolve(), ms)); -export default function ({ getService }) { +export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertestWithoutAuth'); - function extractSessionCookie(response) { + function extractSessionCookie(response: { headers: Record }) { const cookie = (response.headers['set-cookie'] || []).find((header) => header.startsWith('sid=') ); @@ -68,7 +69,7 @@ export default function ({ getService }) { }); describe('API access with expired access token.', function () { - const expectNewSessionCookie = (originalCookie, newCookie) => { + const expectNewSessionCookie = (originalCookie: Cookie, newCookie: Cookie) => { if (!newCookie) { throw new Error('No session cookie set after token refresh'); } @@ -97,7 +98,7 @@ export default function ({ getService }) { .set('cookie', originalCookie.cookieString()) .expect(200); - const firstNewCookie = extractSessionCookie(firstResponse); + const firstNewCookie = extractSessionCookie(firstResponse)!; expectNewSessionCookie(originalCookie, firstNewCookie); // Request with old cookie should return another valid cookie we can use to authenticate requests @@ -108,7 +109,7 @@ export default function ({ getService }) { .set('Cookie', originalCookie.cookieString()) .expect(200); - const secondNewCookie = extractSessionCookie(secondResponse); + const secondNewCookie = extractSessionCookie(secondResponse)!; expectNewSessionCookie(originalCookie, secondNewCookie); if (secondNewCookie.value === firstNewCookie.value) { @@ -132,7 +133,7 @@ export default function ({ getService }) { }); describe('API access with missing access token document.', () => { - let sessionCookie; + let sessionCookie: Cookie; beforeEach(async () => (sessionCookie = await createSessionCookie())); it('should clear cookie and redirect to login', async function () { @@ -155,7 +156,7 @@ export default function ({ getService }) { const cookies = response.headers['set-cookie']; expect(cookies).to.have.length(1); - const cookie = request.cookie(cookies[0]); + const cookie = request.cookie(cookies[0])!; expect(cookie.key).to.be('sid'); expect(cookie.value).to.be.empty(); expect(cookie.path).to.be('/'); diff --git a/x-pack/test/token_api_integration/config.js b/x-pack/test/security_api_integration/token.config.ts similarity index 81% rename from x-pack/test/token_api_integration/config.js rename to x-pack/test/security_api_integration/token.config.ts index 3e78a98067a8f..c7afa51edba5e 100644 --- a/x-pack/test/token_api_integration/config.js +++ b/x-pack/test/security_api_integration/token.config.ts @@ -4,11 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -export default async function ({ readConfigFile }) { +import { FtrConfigProviderContext } from '@kbn/test/types/ftr'; + +export default async function ({ readConfigFile }: FtrConfigProviderContext) { const xPackAPITestsConfig = await readConfigFile(require.resolve('../api_integration/config.ts')); return { - testFiles: [require.resolve('./auth')], + testFiles: [require.resolve('./tests/token')], servers: xPackAPITestsConfig.get('servers'), security: { disableTestUser: true }, services: { @@ -16,7 +18,7 @@ export default async function ({ readConfigFile }) { supertestWithoutAuth: xPackAPITestsConfig.get('services.supertestWithoutAuth'), }, junit: { - reportName: 'Token-auth API Integration Tests', + reportName: 'X-Pack Security API Integration Tests (Token)', }, esTestCluster: { From ece505b0759fcb5cdfb4acaf19e432e407dda9e2 Mon Sep 17 00:00:00 2001 From: Mikhail Shustov Date: Tue, 10 Nov 2020 21:26:35 +0300 Subject: [PATCH 29/80] require schema for UiSettings (#83037) --- .../ui_settings/ui_settings_service.test.ts | 29 +++++++++++++++++++ .../server/ui_settings/ui_settings_service.ts | 6 ++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/core/server/ui_settings/ui_settings_service.test.ts b/src/core/server/ui_settings/ui_settings_service.test.ts index 0c17a3a614d60..f4e24e3a517c3 100644 --- a/src/core/server/ui_settings/ui_settings_service.test.ts +++ b/src/core/server/ui_settings/ui_settings_service.test.ts @@ -89,6 +89,20 @@ describe('uiSettings', () => { describe('#start', () => { describe('validation', () => { + it('throws if validation schema is not provided', async () => { + const { register } = await service.setup(setupDeps); + register({ + // @ts-expect-error schema is required key + custom: { + value: 42, + }, + }); + + await expect(service.start()).rejects.toMatchInlineSnapshot( + `[Error: Validation schema is not provided for [custom] UI Setting]` + ); + }); + it('validates registered definitions', async () => { const { register } = await service.setup(setupDeps); register({ @@ -125,6 +139,21 @@ describe('uiSettings', () => { `[Error: [ui settings overrides [custom]]: expected value of type [string] but got [number]]` ); }); + + it('do not throw on unknown overrides', async () => { + const coreContext = mockCoreContext.create(); + coreContext.configService.atPath.mockReturnValueOnce( + new BehaviorSubject({ + overrides: { + custom: 42, + }, + }) + ); + const customizedService = new UiSettingsService(coreContext); + await customizedService.setup(setupDeps); + + await customizedService.start(); + }); }); describe('#asScopedToClient', () => { diff --git a/src/core/server/ui_settings/ui_settings_service.ts b/src/core/server/ui_settings/ui_settings_service.ts index 25062490f5b6b..4f757d18ea7da 100644 --- a/src/core/server/ui_settings/ui_settings_service.ts +++ b/src/core/server/ui_settings/ui_settings_service.ts @@ -109,15 +109,17 @@ export class UiSettingsService private validatesDefinitions() { for (const [key, definition] of this.uiSettingsDefaults) { - if (definition.schema) { - definition.schema.validate(definition.value, {}, `ui settings defaults [${key}]`); + if (!definition.schema) { + throw new Error(`Validation schema is not provided for [${key}] UI Setting`); } + definition.schema.validate(definition.value, {}, `ui settings defaults [${key}]`); } } private validatesOverrides() { for (const [key, value] of Object.entries(this.overrides)) { const definition = this.uiSettingsDefaults.get(key); + // overrides might contain UiSettings for a disabled plugin if (definition?.schema) { definition.schema.validate(value, {}, `ui settings overrides [${key}]`); } From ccb0b354525a072c9b637f1147637391fdf8fa0b Mon Sep 17 00:00:00 2001 From: Wylie Conlon Date: Tue, 10 Nov 2020 13:45:46 -0500 Subject: [PATCH 30/80] [Lens] Use entire layers, not specific columns (#82550) * [Lens] Use entire layers, not specific columns * Fix types * Move all of state_helpers over * Fix tests * Fix crash and add tests to prevent future issues * Prevent users from dropping duplicate fields * Respond to review feedback * Fix review feedback Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../config_panel/layer_panel.test.tsx | 37 + .../editor_frame/config_panel/layer_panel.tsx | 19 +- .../__mocks__/state_helpers.ts | 21 - .../bucket_nesting_editor.test.tsx | 61 +- .../dimension_panel/dimension_editor.tsx | 107 +- .../dimension_panel/dimension_panel.test.tsx | 23 +- .../dimension_panel/droppable.test.ts | 280 ++--- .../dimension_panel/droppable.ts | 71 +- .../indexpattern_datasource/indexpattern.tsx | 9 +- .../indexpattern_suggestions.test.tsx | 105 +- .../indexpattern_suggestions.ts | 400 +++---- .../layerpanel.test.tsx | 2 - .../public/indexpattern_datasource/loader.ts | 2 +- .../operations/__mocks__/index.ts | 27 +- .../operations/definitions/cardinality.tsx | 10 +- .../operations/definitions/column_types.ts | 3 +- .../operations/definitions/count.tsx | 10 +- .../definitions/date_histogram.test.tsx | 10 +- .../operations/definitions/date_histogram.tsx | 17 +- .../definitions/filters/filters.tsx | 5 +- .../operations/definitions/index.ts | 15 +- .../operations/definitions/metrics.tsx | 5 +- .../operations/definitions/ranges/ranges.tsx | 37 +- .../operations/definitions/terms/index.tsx | 12 +- .../definitions/terms/terms.test.tsx | 38 +- .../operations/index.ts | 1 + .../layer_helpers.test.ts} | 1008 +++++++++++------ .../operations/layer_helpers.ts | 344 ++++++ .../operations/operations.test.ts | 72 +- .../operations/operations.ts | 97 +- .../indexpattern_datasource/state_helpers.ts | 180 +-- x-pack/plugins/lens/public/types.ts | 8 - .../public/xy_visualization/visualization.tsx | 2 - x-pack/plugins/lens/server/migrations.test.ts | 88 +- x-pack/plugins/lens/server/migrations.ts | 30 +- 35 files changed, 1710 insertions(+), 1446 deletions(-) delete mode 100644 x-pack/plugins/lens/public/indexpattern_datasource/__mocks__/state_helpers.ts rename x-pack/plugins/lens/public/indexpattern_datasource/{state_helpers.test.ts => operations/layer_helpers.test.ts} (52%) create mode 100644 x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.ts diff --git a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.test.tsx b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.test.tsx index 56425326c1ce1..c0cd211a49dd9 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.test.tsx +++ b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.test.tsx @@ -371,6 +371,43 @@ describe('LayerPanel', () => { ); }); + it('should determine if the datasource supports dropping of a field onto a pre-filled dimension', () => { + mockVisualization.getConfiguration.mockReturnValue({ + groups: [ + { + groupLabel: 'A', + groupId: 'a', + accessors: ['a'], + filterOperations: () => true, + supportsMoreColumns: true, + dataTestSubj: 'lnsGroup', + }, + ], + }); + + mockDatasource.canHandleDrop.mockImplementation(({ columnId }) => columnId !== 'a'); + + const draggingField = { field: { name: 'dragged' }, indexPatternId: 'a', id: '1' }; + + const component = mountWithIntl( + + + + ); + + expect(mockDatasource.canHandleDrop).toHaveBeenCalledWith( + expect.objectContaining({ columnId: 'a' }) + ); + + expect( + component.find('DragDrop[data-test-subj="lnsGroup"]').first().prop('droppable') + ).toEqual(false); + + component.find('DragDrop[data-test-subj="lnsGroup"]').first().simulate('drop'); + + expect(mockDatasource.onDrop).not.toHaveBeenCalled(); + }); + it('should allow drag to move between groups', () => { (generateId as jest.Mock).mockReturnValue(`newid`); diff --git a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.tsx b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.tsx index 0332f11aa78b3..f780f9c3f22d7 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.tsx +++ b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.tsx @@ -235,6 +235,17 @@ export function LayerPanel( dragging.groupId === group.groupId && dragging.columnId !== accessor && dragging.groupId !== 'y'; // TODO: remove this line when https://github.com/elastic/elastic-charts/issues/868 is fixed + + const isDroppable = isDraggedOperation(dragging) + ? dragType === 'reorder' + ? isFromTheSameGroup + : isFromCompatibleGroup + : layerDatasource.canHandleDrop({ + ...layerDatasourceDropProps, + columnId: accessor, + filterOperations: group.filterOperations, + }); + return ( { layerDatasource.onDrop({ isReorder: true, @@ -303,7 +310,6 @@ export function LayerPanel( ...layerDatasourceConfigProps, columnId: accessor, filterOperations: group.filterOperations, - suggestedPriority: group.suggestedPriority, onClick: () => { if (activeId) { setActiveDimension(initialActiveDimensionState); @@ -450,7 +456,6 @@ export function LayerPanel( core: props.core, columnId: activeId, filterOperations: activeGroup.filterOperations, - suggestedPriority: activeGroup?.suggestedPriority, dimensionGroups: groups, setState: (newState: unknown) => { props.updateAll( diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/__mocks__/state_helpers.ts b/x-pack/plugins/lens/public/indexpattern_datasource/__mocks__/state_helpers.ts deleted file mode 100644 index 47687ef10f882..0000000000000 --- a/x-pack/plugins/lens/public/indexpattern_datasource/__mocks__/state_helpers.ts +++ /dev/null @@ -1,21 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -const actual = jest.requireActual('../state_helpers'); - -jest.spyOn(actual, 'changeColumn'); -jest.spyOn(actual, 'updateLayerIndexPattern'); - -export const { - getColumnOrder, - changeColumn, - deleteColumn, - updateColumnParam, - sortByField, - hasField, - updateLayerIndexPattern, - mergeLayer, -} = actual; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/bucket_nesting_editor.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/bucket_nesting_editor.test.tsx index ee6a86072236c..ef0b7f1554478 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/bucket_nesting_editor.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/bucket_nesting_editor.test.tsx @@ -31,7 +31,6 @@ describe('BucketNestingEditor', () => { orderDirection: 'asc', }, sourceField: 'a', - suggestedPriority: 0, ...col, }; @@ -46,9 +45,9 @@ describe('BucketNestingEditor', () => { layer={{ columnOrder: ['a', 'b', 'c'], columns: { - a: mockCol({ suggestedPriority: 0 }), - b: mockCol({ suggestedPriority: 1 }), - c: mockCol({ suggestedPriority: 2, operationType: 'min', isBucketed: false }), + a: mockCol(), + b: mockCol(), + c: mockCol({ operationType: 'min', isBucketed: false }), }, indexPatternId: 'foo', }} @@ -67,9 +66,9 @@ describe('BucketNestingEditor', () => { layer={{ columnOrder: ['b', 'a', 'c'], columns: { - a: mockCol({ suggestedPriority: 0 }), - b: mockCol({ suggestedPriority: 1 }), - c: mockCol({ suggestedPriority: 2, operationType: 'min', isBucketed: false }), + a: mockCol(), + b: mockCol(), + c: mockCol({ operationType: 'min', isBucketed: false }), }, indexPatternId: 'foo', }} @@ -89,9 +88,9 @@ describe('BucketNestingEditor', () => { layer={{ columnOrder: ['b', 'a', 'c'], columns: { - a: mockCol({ suggestedPriority: 0 }), - b: mockCol({ suggestedPriority: 1 }), - c: mockCol({ suggestedPriority: 2, operationType: 'min', isBucketed: false }), + a: mockCol(), + b: mockCol(), + c: mockCol({ operationType: 'min', isBucketed: false }), }, indexPatternId: 'foo', }} @@ -109,9 +108,9 @@ describe('BucketNestingEditor', () => { layer: { columnOrder: ['a', 'b', 'c'], columns: { - a: mockCol({ suggestedPriority: 0 }), - b: mockCol({ suggestedPriority: 1 }), - c: mockCol({ suggestedPriority: 2, operationType: 'min', isBucketed: false }), + a: mockCol(), + b: mockCol(), + c: mockCol({ operationType: 'min', isBucketed: false }), }, indexPatternId: 'foo', }, @@ -134,9 +133,9 @@ describe('BucketNestingEditor', () => { layer={{ columnOrder: ['a', 'b', 'c'], columns: { - a: mockCol({ suggestedPriority: 0, operationType: 'avg', isBucketed: false }), - b: mockCol({ suggestedPriority: 1, operationType: 'max', isBucketed: false }), - c: mockCol({ suggestedPriority: 2, operationType: 'min', isBucketed: false }), + a: mockCol({ operationType: 'avg', isBucketed: false }), + b: mockCol({ operationType: 'max', isBucketed: false }), + c: mockCol({ operationType: 'min', isBucketed: false }), }, indexPatternId: 'foo', }} @@ -155,9 +154,9 @@ describe('BucketNestingEditor', () => { layer={{ columnOrder: ['a', 'b', 'c'], columns: { - a: mockCol({ suggestedPriority: 0 }), - b: mockCol({ suggestedPriority: 1, operationType: 'max', isBucketed: false }), - c: mockCol({ suggestedPriority: 2, operationType: 'min', isBucketed: false }), + a: mockCol(), + b: mockCol({ operationType: 'max', isBucketed: false }), + c: mockCol({ operationType: 'min', isBucketed: false }), }, indexPatternId: 'foo', }} @@ -176,9 +175,9 @@ describe('BucketNestingEditor', () => { layer={{ columnOrder: ['c', 'a', 'b'], columns: { - a: mockCol({ suggestedPriority: 0, operationType: 'count', isBucketed: true }), - b: mockCol({ suggestedPriority: 1, operationType: 'max', isBucketed: true }), - c: mockCol({ suggestedPriority: 2, operationType: 'min', isBucketed: true }), + a: mockCol({ operationType: 'count', isBucketed: true }), + b: mockCol({ operationType: 'max', isBucketed: true }), + c: mockCol({ operationType: 'min', isBucketed: true }), }, indexPatternId: 'foo', }} @@ -200,9 +199,9 @@ describe('BucketNestingEditor', () => { layer={{ columnOrder: ['c', 'a', 'b'], columns: { - a: mockCol({ suggestedPriority: 0, operationType: 'count', isBucketed: true }), - b: mockCol({ suggestedPriority: 1, operationType: 'max', isBucketed: true }), - c: mockCol({ suggestedPriority: 2, operationType: 'min', isBucketed: true }), + a: mockCol({ operationType: 'count', isBucketed: true }), + b: mockCol({ operationType: 'max', isBucketed: true }), + c: mockCol({ operationType: 'min', isBucketed: true }), }, indexPatternId: 'foo', }} @@ -227,9 +226,9 @@ describe('BucketNestingEditor', () => { layer={{ columnOrder: ['c', 'a', 'b'], columns: { - a: mockCol({ suggestedPriority: 0, operationType: 'count', isBucketed: true }), - b: mockCol({ suggestedPriority: 1, operationType: 'max', isBucketed: true }), - c: mockCol({ suggestedPriority: 2, operationType: 'min', isBucketed: true }), + a: mockCol({ operationType: 'count', isBucketed: true }), + b: mockCol({ operationType: 'max', isBucketed: true }), + c: mockCol({ operationType: 'min', isBucketed: true }), }, indexPatternId: 'foo', }} @@ -254,9 +253,9 @@ describe('BucketNestingEditor', () => { layer={{ columnOrder: ['c', 'a', 'b'], columns: { - a: mockCol({ suggestedPriority: 0, operationType: 'count', isBucketed: true }), - b: mockCol({ suggestedPriority: 1, operationType: 'max', isBucketed: true }), - c: mockCol({ suggestedPriority: 2, operationType: 'min', isBucketed: true }), + a: mockCol({ operationType: 'count', isBucketed: true }), + b: mockCol({ operationType: 'max', isBucketed: true }), + c: mockCol({ operationType: 'min', isBucketed: true }), }, indexPatternId: 'foo', }} diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_editor.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_editor.tsx index 7cbfbc1749382..cd196745f3315 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_editor.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_editor.tsx @@ -22,14 +22,16 @@ import { IndexPatternColumn, OperationType } from '../indexpattern'; import { operationDefinitionMap, getOperationDisplay, - buildColumn, - changeField, + insertOrReplaceColumn, + replaceColumn, + deleteColumn, + updateColumnParam, } from '../operations'; -import { deleteColumn, changeColumn, updateColumnParam, mergeLayer } from '../state_helpers'; +import { mergeLayer } from '../state_helpers'; import { FieldSelect } from './field_select'; import { hasField, fieldIsInvalid } from '../utils'; import { BucketNestingEditor } from './bucket_nesting_editor'; -import { IndexPattern } from '../types'; +import { IndexPattern, IndexPatternLayer } from '../types'; import { trackUiEvent } from '../../lens_ui_telemetry'; import { FormatSelector } from './format_selector'; @@ -170,21 +172,13 @@ export function DimensionEditor(props: DimensionEditorProps) { if (selectedColumn?.operationType === operationType) { return; } - setState( - changeColumn({ - state, - layerId, - columnId, - newColumn: buildColumn({ - columns: props.state.layers[props.layerId].columns, - suggestedPriority: props.suggestedPriority, - layerId: props.layerId, - op: operationType, - indexPattern: currentIndexPattern, - previousColumn: selectedColumn, - }), - }) - ); + const newLayer = insertOrReplaceColumn({ + layer: props.state.layers[props.layerId], + indexPattern: currentIndexPattern, + columnId, + op: operationType, + }); + setState(mergeLayer({ state, layerId, newLayer })); trackUiEvent(`indexpattern_dimension_operation_${operationType}`); return; } else if (!selectedColumn || !compatibleWithCurrentField) { @@ -192,18 +186,15 @@ export function DimensionEditor(props: DimensionEditorProps) { if (possibleFields.size === 1) { setState( - changeColumn({ + mergeLayer({ state, layerId, - columnId, - newColumn: buildColumn({ - columns: props.state.layers[props.layerId].columns, - suggestedPriority: props.suggestedPriority, - layerId: props.layerId, - op: operationType, + newLayer: insertOrReplaceColumn({ + layer: props.state.layers[props.layerId], indexPattern: currentIndexPattern, + columnId, + op: operationType, field: currentIndexPattern.getFieldByName(possibleFields.values().next().value), - previousColumn: selectedColumn, }), }) ); @@ -216,30 +207,21 @@ export function DimensionEditor(props: DimensionEditorProps) { setInvalidOperationType(null); - if (selectedColumn?.operationType === operationType) { + if (selectedColumn.operationType === operationType) { return; } - const newColumn: IndexPatternColumn = buildColumn({ - columns: props.state.layers[props.layerId].columns, - suggestedPriority: props.suggestedPriority, - layerId: props.layerId, - op: operationType, + const newLayer = replaceColumn({ + layer: props.state.layers[props.layerId], indexPattern: currentIndexPattern, + columnId, + op: operationType, field: hasField(selectedColumn) ? currentIndexPattern.getFieldByName(selectedColumn.sourceField) : undefined, - previousColumn: selectedColumn, }); - setState( - changeColumn({ - state, - layerId, - columnId, - newColumn, - }) - ); + setState(mergeLayer({ state, layerId, newLayer })); }, }; } @@ -297,30 +279,31 @@ export function DimensionEditor(props: DimensionEditorProps) { incompatibleSelectedOperationType={incompatibleSelectedOperationType} onDeleteColumn={() => { setState( - deleteColumn({ + mergeLayer({ state, layerId, - columnId, + newLayer: deleteColumn({ layer: state.layers[layerId], columnId }), }) ); }} onChoose={(choice) => { - let column: IndexPatternColumn; + let newLayer: IndexPatternLayer; if ( !incompatibleSelectedOperationType && selectedColumn && 'field' in choice && choice.operationType === selectedColumn.operationType ) { - // If we just changed the field are not in an error state and the operation didn't change, - // we use the operations onFieldChange method to calculate the new column. - column = changeField( - selectedColumn, - currentIndexPattern, - currentIndexPattern.getFieldByName(choice.field)! - ); + // Replaces just the field + newLayer = replaceColumn({ + layer: state.layers[layerId], + columnId, + indexPattern: currentIndexPattern, + op: choice.operationType, + field: currentIndexPattern.getFieldByName(choice.field)!, + }); } else { - // Otherwise we'll use the buildColumn method to calculate a new column + // Finds a new operation const compatibleOperations = ('field' in choice && operationSupportMatrix.operationByField[choice.field]) || new Set(); @@ -334,26 +317,16 @@ export function DimensionEditor(props: DimensionEditorProps) { } else if ('field' in choice) { operation = choice.operationType; } - column = buildColumn({ - columns: props.state.layers[props.layerId].columns, + newLayer = insertOrReplaceColumn({ + layer: state.layers[layerId], + columnId, field: currentIndexPattern.getFieldByName(choice.field), indexPattern: currentIndexPattern, - layerId: props.layerId, - suggestedPriority: props.suggestedPriority, op: operation as OperationType, - previousColumn: selectedColumn, }); } - setState( - changeColumn({ - state, - layerId, - columnId, - newColumn: column, - keepParams: false, - }) - ); + setState(mergeLayer({ state, layerId, newLayer })); setInvalidOperationType(null); }} /> diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx index 3ed04b08df58f..e9eb3fa4542fe 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx @@ -9,7 +9,6 @@ import React from 'react'; import { act } from 'react-dom/test-utils'; import { EuiComboBox, EuiListGroupItemProps, EuiListGroup, EuiRange } from '@elastic/eui'; import { DataPublicPluginStart } from '../../../../../../src/plugins/data/public'; -import { changeColumn } from '../state_helpers'; import { IndexPatternDimensionEditorComponent, IndexPatternDimensionEditorProps, @@ -18,14 +17,14 @@ import { mountWithIntl as mount, shallowWithIntl as shallow } from 'test_utils/e import { IUiSettingsClient, SavedObjectsClientContract, HttpSetup, CoreSetup } from 'kibana/public'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; import { IndexPatternPrivateState } from '../types'; -import { IndexPatternColumn } from '../operations'; +import { IndexPatternColumn, replaceColumn } from '../operations'; import { documentField } from '../document_field'; import { OperationMetadata } from '../../types'; import { DateHistogramIndexPatternColumn } from '../operations/definitions/date_histogram'; import { getFieldByNameFactory } from '../pure_helpers'; jest.mock('../loader'); -jest.mock('../state_helpers'); +jest.mock('../operations'); jest.mock('lodash', () => { const original = jest.requireActual('lodash'); @@ -682,7 +681,7 @@ describe('IndexPatternDimensionEditorPanel', () => { // Other parts of this don't matter for this test }), }, - columnOrder: ['col1', 'col2'], + columnOrder: ['col2', 'col1'], }, }, }); @@ -1029,15 +1028,13 @@ describe('IndexPatternDimensionEditorPanel', () => { ); }); - expect(changeColumn).toHaveBeenCalledWith({ - state: initialState, - columnId: 'col1', - layerId: 'first', - newColumn: expect.objectContaining({ - sourceField: 'bytes', - operationType: 'min', - }), - }); + expect(replaceColumn).toHaveBeenCalledWith( + expect.objectContaining({ + columnId: 'col1', + op: 'min', + field: expect.objectContaining({ name: 'bytes' }), + }) + ); }); it('should clear the dimension when removing the selection in field combobox', () => { diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.test.ts index 1d85c1f8f78ca..48240a5417108 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.test.ts @@ -17,7 +17,7 @@ import { OperationMetadata } from '../../types'; import { IndexPatternColumn } from '../operations'; import { getFieldByNameFactory } from '../pure_helpers'; -jest.mock('../state_helpers'); +jest.mock('../operations'); const fields = [ { @@ -56,8 +56,8 @@ const fields = [ ]; const expectedIndexPatterns = { - 1: { - id: '1', + foo: { + id: 'foo', title: 'my-fake-index-pattern', timeFieldName: 'timestamp', hasExistence: true, @@ -89,7 +89,7 @@ describe('IndexPatternDimensionEditorPanel', () => { state = { indexPatternRefs: [], indexPatterns: expectedIndexPatterns, - currentIndexPatternId: '1', + currentIndexPatternId: 'foo', isFirstExistenceFetch: false, existingFields: { 'my-fake-index-pattern': { @@ -101,7 +101,7 @@ describe('IndexPatternDimensionEditorPanel', () => { }, layers: { first: { - indexPatternId: '1', + indexPatternId: 'foo', columnOrder: ['col1'], columns: { col1: { @@ -156,84 +156,8 @@ describe('IndexPatternDimensionEditorPanel', () => { jest.clearAllMocks(); }); - function dragDropState(): IndexPatternPrivateState { - return { - indexPatternRefs: [], - existingFields: {}, - indexPatterns: { - foo: { - id: 'foo', - title: 'Foo pattern', - hasRestrictions: false, - fields: [ - { - aggregatable: true, - name: 'bar', - displayName: 'bar', - searchable: true, - type: 'number', - }, - { - aggregatable: true, - name: 'mystring', - displayName: 'mystring', - searchable: true, - type: 'string', - }, - ], - - getFieldByName: getFieldByNameFactory([ - { - aggregatable: true, - name: 'bar', - displayName: 'bar', - searchable: true, - type: 'number', - }, - { - aggregatable: true, - name: 'mystring', - displayName: 'mystring', - searchable: true, - type: 'string', - }, - ]), - }, - }, - currentIndexPatternId: '1', - isFirstExistenceFetch: false, - layers: { - myLayer: { - indexPatternId: 'foo', - columnOrder: ['col1'], - columns: { - col1: { - label: 'Date histogram of timestamp', - dataType: 'date', - isBucketed: true, - - // Private - operationType: 'date_histogram', - params: { - interval: '1d', - }, - sourceField: 'timestamp', - }, - }, - }, - }, - }; - } - it('is not droppable if no drag is happening', () => { - expect( - canHandleDrop({ - ...defaultProps, - dragDropContext, - state: dragDropState(), - layerId: 'myLayer', - }) - ).toBe(false); + expect(canHandleDrop({ ...defaultProps, dragDropContext })).toBe(false); }); it('is not droppable if the dragged item has no field', () => { @@ -260,9 +184,7 @@ describe('IndexPatternDimensionEditorPanel', () => { id: 'mystring', }, }, - state: dragDropState(), filterOperations: () => false, - layerId: 'myLayer', }) ).toBe(false); }); @@ -274,14 +196,12 @@ describe('IndexPatternDimensionEditorPanel', () => { dragDropContext: { ...dragDropContext, dragging: { - field: { type: 'number', name: 'bar', aggregatable: true }, + field: { type: 'number', name: 'bytes', aggregatable: true }, indexPatternId: 'foo', id: 'bar', }, }, - state: dragDropState(), filterOperations: (op: OperationMetadata) => op.dataType === 'number', - layerId: 'myLayer', }) ).toBe(true); }); @@ -298,9 +218,30 @@ describe('IndexPatternDimensionEditorPanel', () => { id: 'bar', }, }, - state: dragDropState(), filterOperations: (op: OperationMetadata) => op.dataType === 'number', - layerId: 'myLayer', + }) + ).toBe(false); + }); + + it('is not droppable if the dragged field is already in use by this operation', () => { + expect( + canHandleDrop({ + ...defaultProps, + dragDropContext: { + ...dragDropContext, + dragging: { + field: { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + aggregatable: true, + searchable: true, + exists: true, + }, + indexPatternId: 'foo', + id: 'bar', + }, + }, }) ).toBe(false); }); @@ -314,14 +255,11 @@ describe('IndexPatternDimensionEditorPanel', () => { dragging: { columnId: 'col1', groupId: 'a', - layerId: 'myLayer', + layerId: 'first', id: 'col1', }, }, - state: dragDropState(), columnId: 'col2', - filterOperations: (op: OperationMetadata) => true, - layerId: 'myLayer', }) ).toBe(true); }); @@ -335,14 +273,10 @@ describe('IndexPatternDimensionEditorPanel', () => { dragging: { columnId: 'col1', groupId: 'a', - layerId: 'myLayer', + layerId: 'first', id: 'bar', }, }, - state: dragDropState(), - columnId: 'col1', - filterOperations: (op: OperationMetadata) => true, - layerId: 'myLayer', }) ).toBe(false); }); @@ -356,25 +290,22 @@ describe('IndexPatternDimensionEditorPanel', () => { dragging: { columnId: 'col1', groupId: 'a', - layerId: 'myLayer', + layerId: 'first', id: 'bar', }, }, - state: dragDropState(), columnId: 'col2', filterOperations: (op: OperationMetadata) => op.dataType === 'number', - layerId: 'myLayer', }) ).toBe(false); }); it('appends the dropped column when a field is dropped', () => { const dragging = { - field: { type: 'number', name: 'bar', aggregatable: true }, + field: { type: 'number', name: 'bytes', aggregatable: true }, indexPatternId: 'foo', id: 'bar', }; - const testState = dragDropState(); onDrop({ ...defaultProps, @@ -383,24 +314,22 @@ describe('IndexPatternDimensionEditorPanel', () => { dragging, }, droppedItem: dragging, - state: testState, columnId: 'col2', filterOperations: (op: OperationMetadata) => op.dataType === 'number', - layerId: 'myLayer', }); expect(setState).toBeCalledTimes(1); expect(setState).toHaveBeenCalledWith({ - ...testState, + ...state, layers: { - myLayer: { - ...testState.layers.myLayer, + first: { + ...state.layers.first, columnOrder: ['col1', 'col2'], columns: { - ...testState.layers.myLayer.columns, + ...state.layers.first.columns, col2: expect.objectContaining({ dataType: 'number', - sourceField: 'bar', + sourceField: 'bytes', }), }, }, @@ -410,11 +339,10 @@ describe('IndexPatternDimensionEditorPanel', () => { it('selects the specific operation that was valid on drop', () => { const dragging = { - field: { type: 'string', name: 'mystring', aggregatable: true }, + field: { type: 'string', name: 'source', aggregatable: true }, indexPatternId: 'foo', id: 'bar', }; - const testState = dragDropState(); onDrop({ ...defaultProps, dragDropContext: { @@ -422,24 +350,22 @@ describe('IndexPatternDimensionEditorPanel', () => { dragging, }, droppedItem: dragging, - state: testState, columnId: 'col2', filterOperations: (op: OperationMetadata) => op.isBucketed, - layerId: 'myLayer', }); expect(setState).toBeCalledTimes(1); expect(setState).toHaveBeenCalledWith({ - ...testState, + ...state, layers: { - myLayer: { - ...testState.layers.myLayer, - columnOrder: ['col1', 'col2'], + first: { + ...state.layers.first, + columnOrder: ['col2', 'col1'], columns: { - ...testState.layers.myLayer.columns, + ...state.layers.first.columns, col2: expect.objectContaining({ dataType: 'string', - sourceField: 'mystring', + sourceField: 'source', }), }, }, @@ -449,11 +375,10 @@ describe('IndexPatternDimensionEditorPanel', () => { it('updates a column when a field is dropped', () => { const dragging = { - field: { type: 'number', name: 'bar', aggregatable: true }, + field: { type: 'number', name: 'bytes', aggregatable: true }, indexPatternId: 'foo', id: 'bar', }; - const testState = dragDropState(); onDrop({ ...defaultProps, dragDropContext: { @@ -461,20 +386,18 @@ describe('IndexPatternDimensionEditorPanel', () => { dragging, }, droppedItem: dragging, - state: testState, filterOperations: (op: OperationMetadata) => op.dataType === 'number', - layerId: 'myLayer', }); expect(setState).toBeCalledTimes(1); expect(setState).toHaveBeenCalledWith({ - ...testState, + ...state, layers: { - myLayer: expect.objectContaining({ + first: expect.objectContaining({ columns: expect.objectContaining({ col1: expect.objectContaining({ dataType: 'number', - sourceField: 'bar', + sourceField: 'bytes', }), }), }), @@ -482,13 +405,12 @@ describe('IndexPatternDimensionEditorPanel', () => { }); }); - it('does not set the size of the terms aggregation', () => { + it('keeps the operation when dropping a different compatible field', () => { const dragging = { - field: { type: 'string', name: 'mystring', aggregatable: true }, + field: { name: 'memory', type: 'number', aggregatable: true }, indexPatternId: 'foo', - id: 'bar', + id: '1', }; - const testState = dragDropState(); onDrop({ ...defaultProps, dragDropContext: { @@ -496,27 +418,41 @@ describe('IndexPatternDimensionEditorPanel', () => { dragging, }, droppedItem: dragging, - state: testState, - columnId: 'col2', - filterOperations: (op: OperationMetadata) => op.isBucketed, - layerId: 'myLayer', + state: { + ...state, + layers: { + first: { + indexPatternId: 'foo', + columnOrder: ['col1'], + columns: { + col1: { + label: 'Sum of bytes', + dataType: 'number', + isBucketed: false, + + // Private + operationType: 'sum', + sourceField: 'bytes', + }, + }, + }, + }, + }, }); expect(setState).toBeCalledTimes(1); expect(setState).toHaveBeenCalledWith({ - ...testState, + ...state, layers: { - myLayer: { - ...testState.layers.myLayer, - columnOrder: ['col1', 'col2'], - columns: { - ...testState.layers.myLayer.columns, - col2: expect.objectContaining({ - operationType: 'terms', - params: expect.objectContaining({ size: 3 }), + first: expect.objectContaining({ + columns: expect.objectContaining({ + col1: expect.objectContaining({ + operationType: 'sum', + dataType: 'number', + sourceField: 'memory', }), - }, - }, + }), + }), }, }); }); @@ -525,10 +461,9 @@ describe('IndexPatternDimensionEditorPanel', () => { const dragging = { columnId: 'col1', groupId: 'a', - layerId: 'myLayer', + layerId: 'first', id: 'bar', }; - const testState = dragDropState(); onDrop({ ...defaultProps, @@ -537,21 +472,18 @@ describe('IndexPatternDimensionEditorPanel', () => { dragging, }, droppedItem: dragging, - state: testState, columnId: 'col2', - filterOperations: (op: OperationMetadata) => true, - layerId: 'myLayer', }); expect(setState).toBeCalledTimes(1); expect(setState).toHaveBeenCalledWith({ - ...testState, + ...state, layers: { - myLayer: { - ...testState.layers.myLayer, + first: { + ...state.layers.first, columnOrder: ['col2'], columns: { - col2: testState.layers.myLayer.columns.col1, + col2: state.layers.first.columns.col1, }, }, }, @@ -562,15 +494,15 @@ describe('IndexPatternDimensionEditorPanel', () => { const dragging = { columnId: 'col2', groupId: 'a', - layerId: 'myLayer', + layerId: 'first', id: 'col2', }; - const testState = dragDropState(); - testState.layers.myLayer = { + const testState = { ...state }; + testState.layers.first = { indexPatternId: 'foo', columnOrder: ['col1', 'col2', 'col3'], columns: { - col1: testState.layers.myLayer.columns.col1, + col1: testState.layers.first.columns.col1, col2: { label: 'Top values of src', @@ -606,21 +538,18 @@ describe('IndexPatternDimensionEditorPanel', () => { }, droppedItem: dragging, state: testState, - columnId: 'col1', - filterOperations: (op: OperationMetadata) => true, - layerId: 'myLayer', }); expect(setState).toBeCalledTimes(1); expect(setState).toHaveBeenCalledWith({ ...testState, layers: { - myLayer: { - ...testState.layers.myLayer, + first: { + ...testState.layers.first, columnOrder: ['col1', 'col3'], columns: { - col1: testState.layers.myLayer.columns.col2, - col3: testState.layers.myLayer.columns.col3, + col1: testState.layers.first.columns.col2, + col3: testState.layers.first.columns.col3, }, }, }, @@ -631,13 +560,13 @@ describe('IndexPatternDimensionEditorPanel', () => { const dragging = { columnId: 'col1', groupId: 'a', - layerId: 'myLayer', + layerId: 'first', id: 'col1', }; const testState = { - ...dragDropState(), + ...state, layers: { - myLayer: { + first: { indexPatternId: 'foo', columnOrder: ['col1', 'col2', 'col3'], columns: { @@ -671,18 +600,17 @@ describe('IndexPatternDimensionEditorPanel', () => { droppedItem: dragging, state: testState, filterOperations: (op: OperationMetadata) => op.dataType === 'number', - layerId: 'myLayer', }; const stateWithColumnOrder = (columnOrder: string[]) => { return { ...testState, layers: { - myLayer: { - ...testState.layers.myLayer, + first: { + ...testState.layers.first, columnOrder, columns: { - ...testState.layers.myLayer.columns, + ...testState.layers.first.columns, }, }, }, @@ -704,7 +632,7 @@ describe('IndexPatternDimensionEditorPanel', () => { droppedItem: { columnId: 'col3', groupId: 'a', - layerId: 'myLayer', + layerId: 'first', id: 'col3', }, }); @@ -718,7 +646,7 @@ describe('IndexPatternDimensionEditorPanel', () => { droppedItem: { columnId: 'col2', groupId: 'a', - layerId: 'myLayer', + layerId: 'first', id: 'col2', }, }); @@ -732,7 +660,7 @@ describe('IndexPatternDimensionEditorPanel', () => { droppedItem: { columnId: 'col2', groupId: 'a', - layerId: 'myLayer', + layerId: 'first', id: 'col2', }, }); diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.ts b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.ts index a6ff550af96e9..e4eabafc6938e 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.ts @@ -10,9 +10,9 @@ import { isDraggedOperation, } from '../../types'; import { IndexPatternColumn } from '../indexpattern'; -import { buildColumn, changeField } from '../operations'; -import { changeColumn, mergeLayer } from '../state_helpers'; -import { isDraggedField, hasField } from '../utils'; +import { insertOrReplaceColumn } from '../operations'; +import { mergeLayer } from '../state_helpers'; +import { hasField, isDraggedField } from '../utils'; import { IndexPatternPrivateState, IndexPatternField } from '../types'; import { trackUiEvent } from '../../lens_ui_telemetry'; import { getOperationSupportMatrix } from './operation_support'; @@ -28,9 +28,12 @@ export function canHandleDrop(props: DatasourceDimensionDropProps columns.length); trackUiEvent(hasData ? 'drop_non_empty' : 'drop_empty'); - - setState( - changeColumn({ - state, - layerId, - columnId, - newColumn, - // If the field has changed, the onFieldChange method needs to take care of everything including moving - // over params. If we create a new column above we want changeColumn to move over params. - keepParams: !hasFieldChanged, - }) - ); + setState(mergeLayer({ state, layerId, newLayer })); return true; } diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.tsx index fa106e90d518a..e37c31559cd0c 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.tsx @@ -51,13 +51,14 @@ import { IndexPatternField, IndexPatternPrivateState, IndexPatternPersistedState import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; import { DataPublicPluginStart } from '../../../../../src/plugins/data/public'; import { VisualizeFieldContext } from '../../../../../src/plugins/ui_actions/public'; -import { deleteColumn } from './state_helpers'; +import { mergeLayer } from './state_helpers'; import { Datasource, StateSetter } from '../index'; import { ChartsPluginSetup } from '../../../../../src/plugins/charts/public'; +import { deleteColumn } from './operations'; import { FieldBasedIndexPatternColumn } from './operations/definitions/column_types'; import { Dragging } from '../drag_drop/providers'; -export { OperationType, IndexPatternColumn } from './operations'; +export { OperationType, IndexPatternColumn, deleteColumn } from './operations'; export type DraggedField = Dragging & { field: IndexPatternField; @@ -159,10 +160,10 @@ export function getIndexPatternDatasource({ }, removeColumn({ prevState, layerId, columnId }) { - return deleteColumn({ + return mergeLayer({ state: prevState, layerId, - columnId, + newLayer: deleteColumn({ layer: prevState.layers[layerId], columnId }), }); }, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx index 523a1be34ba3d..c88af50e525d4 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.test.tsx @@ -12,6 +12,7 @@ import { getDatasourceSuggestionsFromCurrentState, getDatasourceSuggestionsForVisualizeField, } from './indexpattern_suggestions'; +import { documentField } from './document_field'; import { getFieldByNameFactory } from './pure_helpers'; jest.mock('./loader'); @@ -60,6 +61,7 @@ const fieldsOne = [ aggregatable: true, searchable: true, }, + documentField, ]; const fieldsTwo = [ @@ -116,6 +118,7 @@ const fieldsTwo = [ }, }, }, + documentField, ]; const expectedIndexPatterns = { @@ -290,13 +293,13 @@ describe('IndexPattern Data Source suggestions', () => { state: expect.objectContaining({ layers: { id1: expect.objectContaining({ - columnOrder: ['id2', 'id3'], + columnOrder: ['id3', 'id2'], columns: { - id2: expect.objectContaining({ + id3: expect.objectContaining({ operationType: 'date_histogram', sourceField: 'timestamp', }), - id3: expect.objectContaining({ + id2: expect.objectContaining({ operationType: 'avg', sourceField: 'bytes', }), @@ -310,10 +313,10 @@ describe('IndexPattern Data Source suggestions', () => { isMultiRow: true, columns: [ expect.objectContaining({ - columnId: 'id2', + columnId: 'id3', }), expect.objectContaining({ - columnId: 'id3', + columnId: 'id2', }), ], layerId: 'id1', @@ -510,13 +513,13 @@ describe('IndexPattern Data Source suggestions', () => { state: expect.objectContaining({ layers: { previousLayer: expect.objectContaining({ - columnOrder: ['id1', 'id2'], + columnOrder: ['id2', 'id1'], columns: { - id1: expect.objectContaining({ + id2: expect.objectContaining({ operationType: 'date_histogram', sourceField: 'timestamp', }), - id2: expect.objectContaining({ + id1: expect.objectContaining({ operationType: 'avg', sourceField: 'bytes', }), @@ -530,10 +533,10 @@ describe('IndexPattern Data Source suggestions', () => { isMultiRow: true, columns: [ expect.objectContaining({ - columnId: 'id1', + columnId: 'id2', }), expect.objectContaining({ - columnId: 'id2', + columnId: 'id1', }), ], layerId: 'previousLayer', @@ -757,9 +760,9 @@ describe('IndexPattern Data Source suggestions', () => { layers: { previousLayer: initialState.layers.previousLayer, currentLayer: expect.objectContaining({ - columnOrder: ['id1', 'colb'], + columnOrder: ['cola', 'colb'], columns: { - id1: expect.objectContaining({ + cola: expect.objectContaining({ operationType: 'date_histogram', sourceField: 'start_date', }), @@ -867,7 +870,7 @@ describe('IndexPattern Data Source suggestions', () => { ); }); - it('replaces a metric column on a number field if only one other metric is already set', () => { + it('suggests both replacing and adding metric if only one other metric is set', () => { const initialState = stateWithNonEmptyTables(); const suggestions = getDatasourceSuggestionsForField(initialState, '1', { name: 'memory', @@ -895,6 +898,26 @@ describe('IndexPattern Data Source suggestions', () => { }), }) ); + + expect(suggestions).toContainEqual( + expect.objectContaining({ + state: expect.objectContaining({ + layers: expect.objectContaining({ + currentLayer: expect.objectContaining({ + columnOrder: ['cola', 'colb', 'id1'], + columns: { + cola: initialState.layers.currentLayer.columns.cola, + colb: initialState.layers.currentLayer.columns.colb, + id1: expect.objectContaining({ + operationType: 'avg', + sourceField: 'memory', + }), + }, + }), + }), + }), + }) + ); }); it('adds a metric column on a number field if no other metrics set', () => { @@ -941,7 +964,20 @@ describe('IndexPattern Data Source suggestions', () => { ); }); - it('adds a metric column on a number field if 2 or more other metric', () => { + it('skips duplicates when the field is already in use', () => { + const initialState = stateWithNonEmptyTables(); + const suggestions = getDatasourceSuggestionsForField(initialState, '1', { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + }); + + expect(suggestions).not.toContain(expect.objectContaining({ changeType: 'extended' })); + }); + + it('skips duplicates when the document-specific field is already in use', () => { const initialState = stateWithNonEmptyTables(); const modifiedState: IndexPatternPrivateState = { ...initialState, @@ -951,45 +987,20 @@ describe('IndexPattern Data Source suggestions', () => { ...initialState.layers.currentLayer, columns: { ...initialState.layers.currentLayer.columns, - colc: { - dataType: 'number', + colb: { + label: 'Count of records', + dataType: 'document', isBucketed: false, - sourceField: 'dest', - label: 'Unique count of dest', - operationType: 'cardinality', + + operationType: 'count', + sourceField: 'Records', }, }, - columnOrder: ['cola', 'colb', 'colc'], }, }, }; - const suggestions = getDatasourceSuggestionsForField(modifiedState, '1', { - name: 'memory', - displayName: 'memory', - type: 'number', - aggregatable: true, - searchable: true, - }); - - expect(suggestions).toContainEqual( - expect.objectContaining({ - state: expect.objectContaining({ - layers: { - previousLayer: modifiedState.layers.previousLayer, - currentLayer: expect.objectContaining({ - columnOrder: ['cola', 'colb', 'colc', 'id1'], - columns: { - ...modifiedState.layers.currentLayer.columns, - id1: expect.objectContaining({ - operationType: 'avg', - sourceField: 'memory', - }), - }, - }), - }, - }), - }) - ); + const suggestions = getDatasourceSuggestionsForField(modifiedState, '1', documentField); + expect(suggestions).not.toContain(expect.objectContaining({ changeType: 'extended' })); }); }); diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.ts b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.ts index c12d7d4be226b..b74d75207e112 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/indexpattern_suggestions.ts @@ -10,14 +10,14 @@ import { generateId } from '../id_generator'; import { DatasourceSuggestion, TableChangeType } from '../types'; import { columnToOperation } from './indexpattern'; import { - buildColumn, + insertNewColumn, + replaceColumn, + getMetricOperationTypes, getOperationTypesForField, operationDefinitionMap, IndexPatternColumn, OperationType, } from './operations'; -import { operationDefinitions } from './operations/definitions'; -import { TermsIndexPatternColumn } from './operations/definitions/terms'; import { hasField, hasInvalidReference } from './utils'; import { IndexPattern, @@ -137,6 +137,7 @@ export function getDatasourceSuggestionsForVisualizeField( ); } +// TODO: Stop hard-coding the specific operation types function getBucketOperation(field: IndexPatternField) { // We allow numeric bucket types in some cases, but it's generally not the right suggestion, // so we eliminate it here. @@ -160,29 +161,38 @@ function getExistingLayerSuggestionsForField( const suggestions: IndexPatternSugestion[] = []; if (usableAsBucketOperation && !fieldInUse) { - suggestions.push( - buildSuggestion({ - state, - updatedLayer: addFieldAsBucketOperation( - layer, + if ( + usableAsBucketOperation === 'date_histogram' && + layer.columnOrder.some((colId) => layer.columns[colId].operationType === 'date_histogram') + ) { + const previousDate = layer.columnOrder.find( + (colId) => layer.columns[colId].operationType === 'date_histogram' + )!; + suggestions.push( + buildSuggestion({ + state, + updatedLayer: replaceColumn({ + layer, + indexPattern, + field, + op: usableAsBucketOperation, + columnId: previousDate, + }), layerId, - indexPattern, - field, - usableAsBucketOperation - ), - layerId, - changeType: 'extended', - }) - ); - } - - if (!usableAsBucketOperation && operations.length > 0) { - const updatedLayer = addFieldAsMetricOperation(layer, layerId, indexPattern, field); - if (updatedLayer) { + changeType: 'initial', + }) + ); + } else { suggestions.push( buildSuggestion({ state, - updatedLayer, + updatedLayer: insertNewColumn({ + layer, + indexPattern, + field, + op: usableAsBucketOperation, + columnId: generateId(), + }), layerId, changeType: 'extended', }) @@ -190,6 +200,50 @@ function getExistingLayerSuggestionsForField( } } + if (!usableAsBucketOperation && operations.length > 0 && !fieldInUse) { + const [metricOperation] = getMetricOperationTypes(field); + if (metricOperation) { + const layerWithNewMetric = insertNewColumn({ + layer, + indexPattern, + field, + columnId: generateId(), + op: metricOperation.type, + }); + if (layerWithNewMetric) { + suggestions.push( + buildSuggestion({ + state, + layerId, + updatedLayer: layerWithNewMetric, + changeType: 'extended', + }) + ); + } + + const [, metrics] = separateBucketColumns(layer); + if (metrics.length === 1) { + const layerWithReplacedMetric = replaceColumn({ + layer, + indexPattern, + field, + columnId: metrics[0], + op: metricOperation.type, + }); + if (layerWithReplacedMetric) { + suggestions.push( + buildSuggestion({ + state, + layerId, + updatedLayer: layerWithReplacedMetric, + changeType: 'extended', + }) + ); + } + } + } + } + const metricSuggestion = createMetricSuggestion(indexPattern, layerId, state, field); if (metricSuggestion) { suggestions.push(metricSuggestion); @@ -198,100 +252,6 @@ function getExistingLayerSuggestionsForField( return suggestions; } -function addFieldAsMetricOperation( - layer: IndexPatternLayer, - layerId: string, - indexPattern: IndexPattern, - field: IndexPatternField -): IndexPatternLayer | undefined { - const newColumn = getMetricColumn(indexPattern, layerId, field); - const addedColumnId = generateId(); - - const [, metrics] = separateBucketColumns(layer); - - // Add metrics if there are 0 or > 1 metric - if (metrics.length !== 1) { - return { - indexPatternId: indexPattern.id, - columns: { - ...layer.columns, - [addedColumnId]: newColumn, - }, - columnOrder: [...layer.columnOrder, addedColumnId], - }; - } - - // Replacing old column with new column, keeping the old ID - const newColumns = { ...layer.columns, [metrics[0]]: newColumn }; - - return { - indexPatternId: indexPattern.id, - columns: newColumns, - columnOrder: layer.columnOrder, // Order is kept by replacing - }; -} - -function addFieldAsBucketOperation( - layer: IndexPatternLayer, - layerId: string, - indexPattern: IndexPattern, - field: IndexPatternField, - operation: OperationType -): IndexPatternLayer { - const newColumn = buildColumn({ - op: operation, - columns: layer.columns, - layerId, - indexPattern, - suggestedPriority: undefined, - field, - }); - const [buckets, metrics] = separateBucketColumns(layer); - const newColumnId = generateId(); - const updatedColumns = { - ...layer.columns, - [newColumnId]: newColumn, - }; - - if (buckets.length === 0 && operation === 'terms') { - (newColumn as TermsIndexPatternColumn).params.size = 5; - } - - const oldDateHistogramIndex = layer.columnOrder.findIndex( - (columnId) => layer.columns[columnId].operationType === 'date_histogram' - ); - const oldDateHistogramId = - oldDateHistogramIndex > -1 ? layer.columnOrder[oldDateHistogramIndex] : null; - - let updatedColumnOrder: string[] = []; - if (oldDateHistogramId) { - if (operation === 'terms') { - // Insert the new terms bucket above the first date histogram - updatedColumnOrder = [ - ...buckets.slice(0, oldDateHistogramIndex), - newColumnId, - ...buckets.slice(oldDateHistogramIndex, buckets.length), - ...metrics, - ]; - } else if (operation === 'date_histogram') { - // Replace date histogram with new date histogram - delete updatedColumns[oldDateHistogramId]; - updatedColumnOrder = layer.columnOrder.map((columnId) => - columnId !== oldDateHistogramId ? columnId : newColumnId - ); - } - } else { - // Insert the new bucket after existing buckets. Users will see the same data - // they already had, with an extra level of detail. - updatedColumnOrder = [...buckets, newColumnId, ...metrics]; - } - return { - indexPatternId: indexPattern.id, - columns: updatedColumns, - columnOrder: updatedColumnOrder, - }; -} - function getEmptyLayerSuggestionsForField( state: IndexPatternPrivateState, layerId: string, @@ -302,9 +262,9 @@ function getEmptyLayerSuggestionsForField( let newLayer: IndexPatternLayer | undefined; const bucketOperation = getBucketOperation(field); if (bucketOperation) { - newLayer = createNewLayerWithBucketAggregation(layerId, indexPattern, field, bucketOperation); + newLayer = createNewLayerWithBucketAggregation(indexPattern, field, bucketOperation); } else if (indexPattern.timeFieldName && getOperationTypesForField(field).length > 0) { - newLayer = createNewLayerWithMetricAggregation(layerId, indexPattern, field); + newLayer = createNewLayerWithMetricAggregation(indexPattern, field); } const newLayerSuggestions = newLayer @@ -324,77 +284,48 @@ function getEmptyLayerSuggestionsForField( } function createNewLayerWithBucketAggregation( - layerId: string, indexPattern: IndexPattern, field: IndexPatternField, operation: OperationType ): IndexPatternLayer { - const countColumn = buildColumn({ + return insertNewColumn({ op: 'count', - columns: {}, - indexPattern, - layerId, - suggestedPriority: undefined, + layer: insertNewColumn({ + op: operation, + layer: { indexPatternId: indexPattern.id, columns: {}, columnOrder: [] }, + columnId: generateId(), + field, + indexPattern, + }), + columnId: generateId(), field: documentField, - }); - - const col1 = generateId(); - const col2 = generateId(); - - // let column know about count column - const column = buildColumn({ - layerId, - op: operation, indexPattern, - columns: { - [col2]: countColumn, - }, - field, - suggestedPriority: undefined, }); - if (operation === 'terms') { - (column as TermsIndexPatternColumn).params.size = 5; - } - - return { - indexPatternId: indexPattern.id, - columns: { - [col1]: column, - [col2]: countColumn, - }, - columnOrder: [col1, col2], - }; } function createNewLayerWithMetricAggregation( - layerId: string, indexPattern: IndexPattern, field: IndexPatternField -): IndexPatternLayer { +): IndexPatternLayer | undefined { const dateField = indexPattern.getFieldByName(indexPattern.timeFieldName!); + const [metricOperation] = getMetricOperationTypes(field); + if (!metricOperation) { + return; + } - const column = getMetricColumn(indexPattern, layerId, field); - - const dateColumn = buildColumn({ + return insertNewColumn({ op: 'date_histogram', - columns: {}, - suggestedPriority: undefined, + layer: insertNewColumn({ + op: metricOperation.type, + layer: { indexPatternId: indexPattern.id, columns: {}, columnOrder: [] }, + columnId: generateId(), + field, + indexPattern, + }), + columnId: generateId(), field: dateField, indexPattern, - layerId, }); - - const col1 = generateId(); - const col2 = generateId(); - - return { - indexPatternId: indexPattern.id, - columns: { - [col1]: dateColumn, - [col2]: column, - }, - columnOrder: [col1, col2], - }; } export function getDatasourceSuggestionsFromCurrentState( @@ -527,57 +458,33 @@ function createChangedNestingSuggestion(state: IndexPatternPrivateState, layerId }); } -function getMetricColumn(indexPattern: IndexPattern, layerId: string, field: IndexPatternField) { - const operationDefinitionsMap = _.keyBy(operationDefinitions, 'type'); - const [column] = getOperationTypesForField(field) - .map((type) => - operationDefinitionsMap[type].buildColumn({ - field, - indexPattern, - layerId, - columns: {}, - suggestedPriority: 0, - }) - ) - .filter((op) => (op.dataType === 'number' || op.dataType === 'document') && !op.isBucketed); - return column; -} - function createMetricSuggestion( indexPattern: IndexPattern, layerId: string, state: IndexPatternPrivateState, field: IndexPatternField ) { - const column = getMetricColumn(indexPattern, layerId, field); + const [operation] = getMetricOperationTypes(field); - if (!column) { + if (!operation) { return; } - const newId = generateId(); - return buildSuggestion({ layerId, state, changeType: 'initial', - updatedLayer: { - indexPatternId: indexPattern.id, - columns: { - [newId]: - column.dataType !== 'document' - ? column - : buildColumn({ - op: 'count', - columns: {}, - indexPattern, - layerId, - suggestedPriority: undefined, - field: documentField, - }), + updatedLayer: insertNewColumn({ + layer: { + indexPatternId: indexPattern.id, + columns: {}, + columnOrder: [], }, - columnOrder: [newId], - }, + columnId: generateId(), + op: operation.type, + field: operation.type === 'count' ? documentField : field, + indexPattern, + }), }); } @@ -591,6 +498,7 @@ function getNestedTitle([outerBucketLabel, innerBucketLabel]: string[]) { }); } +// Replaces all metrics on the table with a different field-based function function createAlternativeMetricSuggestions( indexPattern: IndexPattern, layerId: string, @@ -598,6 +506,7 @@ function createAlternativeMetricSuggestions( ) { const layer = state.layers[layerId]; const suggestions: Array> = []; + layer.columnOrder.forEach((columnId) => { const column = layer.columns[columnId]; if (!hasField(column)) { @@ -607,39 +516,28 @@ function createAlternativeMetricSuggestions( if (!field) { return; } - const alternativeMetricOperations = getOperationTypesForField(field) - .map((op) => - buildColumn({ - op, - columns: layer.columns, - indexPattern, - layerId, - field, - suggestedPriority: undefined, - }) - ) - .filter( - (fullOperation) => - fullOperation.operationType !== column.operationType && !fullOperation.isBucketed - ); - if (alternativeMetricOperations.length === 0) { - return; - } - const newId = generateId(); - const newColumn = alternativeMetricOperations[0]; - const updatedLayer = { - indexPatternId: indexPattern.id, - columns: { [newId]: newColumn }, - columnOrder: [newId], - }; - suggestions.push( - buildSuggestion({ - state, - layerId, - updatedLayer, - changeType: 'initial', - }) + const possibleOperations = getMetricOperationTypes(field).filter( + ({ type }) => type !== column.operationType ); + if (possibleOperations.length) { + const layerWithNewMetric = replaceColumn({ + layer, + indexPattern, + field, + columnId, + op: possibleOperations[0].type, + }); + if (layerWithNewMetric) { + suggestions.push( + buildSuggestion({ + state, + layerId, + updatedLayer: layerWithNewMetric, + changeType: 'initial', + }) + ); + } + } }); return suggestions; } @@ -651,29 +549,17 @@ function createSuggestionWithDefaultDateHistogram( ) { const layer = state.layers[layerId]; const indexPattern = state.indexPatterns[layer.indexPatternId]; - const newId = generateId(); - const [buckets, metrics] = separateBucketColumns(layer); - const timeColumn = buildColumn({ - layerId, - op: 'date_histogram', - indexPattern, - columns: layer.columns, - field: timeField, - suggestedPriority: undefined, - }); - const updatedLayer = { - indexPatternId: layer.indexPatternId, - columns: { - ...layer.columns, - [newId]: timeColumn, - }, - columnOrder: [...buckets, newId, ...metrics], - }; return buildSuggestion({ state, layerId, - updatedLayer, + updatedLayer: insertNewColumn({ + layer, + indexPattern, + field: timeField, + op: 'date_histogram', + columnId: generateId(), + }), label: i18n.translate('xpack.lens.indexpattern.suggestions.overTimeLabel', { defaultMessage: 'Over time', }), diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/layerpanel.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/layerpanel.test.tsx index 40eb52fe67c6d..b7df3cc5c3687 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/layerpanel.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/layerpanel.test.tsx @@ -13,8 +13,6 @@ import { EuiSelectable } from '@elastic/eui'; import { ChangeIndexPattern } from './change_indexpattern'; import { getFieldByNameFactory } from './pure_helpers'; -jest.mock('./state_helpers'); - interface IndexPatternPickerOption { label: string; checked?: 'on' | 'off'; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/loader.ts b/x-pack/plugins/lens/public/indexpattern_datasource/loader.ts index fac5d7350e45e..64c4122245ce0 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/loader.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/loader.ts @@ -16,7 +16,7 @@ import { IndexPatternField, IndexPatternLayer, } from './types'; -import { updateLayerIndexPattern } from './state_helpers'; +import { updateLayerIndexPattern } from './operations'; import { DateRange, ExistingFields } from '../../common/types'; import { BASE_API_URL } from '../../common'; import { diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/__mocks__/index.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/__mocks__/index.ts index eeb19bba24006..72dfe85dfc0e9 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/__mocks__/index.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/__mocks__/index.ts @@ -4,20 +4,35 @@ * you may not use this file except in compliance with the Elastic License. */ -const actual = jest.requireActual('../../operations'); +const actualOperations = jest.requireActual('../operations'); +const actualHelpers = jest.requireActual('../layer_helpers'); -jest.spyOn(actual.operationDefinitionMap.date_histogram, 'paramEditor'); -jest.spyOn(actual.operationDefinitionMap.terms, 'onOtherColumnChanged'); +jest.spyOn(actualOperations.operationDefinitionMap.date_histogram, 'paramEditor'); +jest.spyOn(actualOperations.operationDefinitionMap.terms, 'onOtherColumnChanged'); +jest.spyOn(actualHelpers, 'insertOrReplaceColumn'); +jest.spyOn(actualHelpers, 'insertNewColumn'); +jest.spyOn(actualHelpers, 'replaceColumn'); export const { getAvailableOperationsByMetadata, - buildColumn, getOperations, getOperationDisplay, getOperationTypesForField, getOperationResultType, operationDefinitionMap, operationDefinitions, +} = actualOperations; + +export const { + insertOrReplaceColumn, + insertNewColumn, + replaceColumn, + getColumnOrder, + deleteColumn, + updateColumnParam, + sortByField, + hasField, + updateLayerIndexPattern, + mergeLayer, isColumnTransferable, - changeField, -} = actual; +} = actualHelpers; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/cardinality.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/cardinality.tsx index 1cfa63511a45c..bd8c4b4683396 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/cardinality.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/cardinality.tsx @@ -52,20 +52,20 @@ export const cardinalityOperation: OperationDefinition { + onFieldChange: (oldColumn, field) => { return { ...oldColumn, label: ofName(field.displayName), diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/column_types.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/column_types.ts index 2e95e3fd4250f..bd4b452a49e1d 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/column_types.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/column_types.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Operation, DimensionPriority } from '../../../types'; +import { Operation } from '../../../types'; /** * This is the root type of a column. If you are implementing a new @@ -14,7 +14,6 @@ import { Operation, DimensionPriority } from '../../../types'; export interface BaseIndexPatternColumn extends Operation { // Private operationType: string; - suggestedPriority?: DimensionPriority; customLabel?: boolean; } diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/count.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/count.tsx index cdf1a6b760493..e33fc681b2579 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/count.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/count.tsx @@ -25,7 +25,7 @@ export const countOperation: OperationDefinition { + onFieldChange: (oldColumn, field) => { return { ...oldColumn, label: field.displayName, @@ -41,20 +41,20 @@ export const countOperation: OperationDefinition { it('should create column object with auto interval for primary time field', () => { const column = dateHistogramOperation.buildColumn({ columns: {}, - suggestedPriority: 0, - layerId: 'first', indexPattern: createMockedIndexPattern(), field: { name: 'timestamp', @@ -207,8 +205,6 @@ describe('date_histogram', () => { it('should create column object with auto interval for non-primary time fields', () => { const column = dateHistogramOperation.buildColumn({ columns: {}, - suggestedPriority: 0, - layerId: 'first', indexPattern: createMockedIndexPattern(), field: { name: 'start_date', @@ -225,8 +221,6 @@ describe('date_histogram', () => { it('should create column object with restrictions', () => { const column = dateHistogramOperation.buildColumn({ columns: {}, - suggestedPriority: 0, - layerId: 'first', indexPattern: createMockedIndexPattern(), field: { name: 'timestamp', @@ -334,7 +328,7 @@ describe('date_histogram', () => { const indexPattern = createMockedIndexPattern(); const newDateField = indexPattern.getFieldByName('start_date')!; - const column = dateHistogramOperation.onFieldChange(oldColumn, indexPattern, newDateField); + const column = dateHistogramOperation.onFieldChange(oldColumn, newDateField); expect(column).toHaveProperty('sourceField', 'start_date'); expect(column).toHaveProperty('params.interval', 'd'); expect(column.label).toContain('start_date'); @@ -354,7 +348,7 @@ describe('date_histogram', () => { const indexPattern = createMockedIndexPattern(); const newDateField = indexPattern.getFieldByName('start_date')!; - const column = dateHistogramOperation.onFieldChange(oldColumn, indexPattern, newDateField); + const column = dateHistogramOperation.onFieldChange(oldColumn, newDateField); expect(column).toHaveProperty('sourceField', 'start_date'); expect(column).toHaveProperty('params.interval', 'auto'); expect(column.label).toContain('start_date'); diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.tsx index 19043c03e5a61..659390a42f261 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.tsx @@ -19,7 +19,7 @@ import { EuiTextColor, EuiSpacer, } from '@elastic/eui'; -import { updateColumnParam } from '../../state_helpers'; +import { updateColumnParam } from '../layer_helpers'; import { OperationDefinition } from './index'; import { FieldBasedIndexPatternColumn } from './column_types'; import { IndexPatternAggRestrictions, search } from '../../../../../../../src/plugins/data/public'; @@ -59,7 +59,7 @@ export const dateHistogramOperation: OperationDefinition< }; } }, - buildColumn({ suggestedPriority, field }) { + buildColumn({ field }) { let interval = autoInterval; let timeZone: string | undefined; if (field.aggregationRestrictions && field.aggregationRestrictions.date_histogram) { @@ -70,7 +70,6 @@ export const dateHistogramOperation: OperationDefinition< label: field.displayName, dataType: 'date', operationType: 'date_histogram', - suggestedPriority, sourceField: field.name, isBucketed: true, scale: 'interval', @@ -112,7 +111,7 @@ export const dateHistogramOperation: OperationDefinition< return column; }, - onFieldChange: (oldColumn, indexPattern, field) => { + onFieldChange: (oldColumn, field) => { return { ...oldColumn, label: field.displayName, @@ -168,15 +167,7 @@ export const dateHistogramOperation: OperationDefinition< const isCalendarInterval = calendarOnlyIntervals.has(newInterval.unit); const value = `${isCalendarInterval ? '1' : newInterval.value}${newInterval.unit || 'd'}`; - setState( - updateColumnParam({ - state, - layerId, - currentColumn, - value, - paramName: 'interval', - }) - ); + setState(updateColumnParam({ state, layerId, currentColumn, paramName: 'interval', value })); }; return ( diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filters.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filters.tsx index 076c1846e35a7..522e951bfba34 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filters.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/filters/filters.tsx @@ -9,7 +9,7 @@ import React, { MouseEventHandler, useState } from 'react'; import { omit } from 'lodash'; import { i18n } from '@kbn/i18n'; import { EuiFormRow, EuiLink, htmlIdGenerator } from '@elastic/eui'; -import { updateColumnParam } from '../../../state_helpers'; +import { updateColumnParam } from '../../layer_helpers'; import { OperationDefinition } from '../index'; import { BaseIndexPatternColumn } from '../column_types'; import { FilterPopover } from './filter_popover'; @@ -75,7 +75,7 @@ export const filtersOperation: OperationDefinition true, - buildColumn({ suggestedPriority, previousColumn }) { + buildColumn({ previousColumn }) { let params = { filters: [defaultFilter] }; if (previousColumn?.operationType === 'terms') { params = { @@ -96,7 +96,6 @@ export const filtersOperation: OperationDefinition { } interface BaseBuildColumnArgs { - suggestedPriority: DimensionPriority | undefined; - layerId: string; columns: Partial>; indexPattern: IndexPattern; } @@ -174,8 +172,7 @@ interface FieldBasedOperationDefinition { buildColumn: ( arg: BaseBuildColumnArgs & { field: IndexPatternField; - // previousColumn?: IndexPatternColumn; - previousColumn?: C; + previousColumn?: IndexPatternColumn; } ) => C; /** @@ -191,15 +188,9 @@ interface FieldBasedOperationDefinition { * index pattern not just a field. * * @param oldColumn The column before the user changed the field. - * @param indexPattern The index pattern that field is on. * @param field The field that the user changed to. */ - onFieldChange: ( - // oldColumn: FieldBasedIndexPatternColumn, - oldColumn: C, - indexPattern: IndexPattern, - field: IndexPatternField - ) => C; + onFieldChange: (oldColumn: C, field: IndexPatternField) => C; } interface OperationDefinitionMap { diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/metrics.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/metrics.tsx index fef575c61475c..37a7ef8ee2563 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/metrics.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/metrics.tsx @@ -52,18 +52,17 @@ function buildMetricOperation>({ (!newField.aggregationRestrictions || newField.aggregationRestrictions![type]) ); }, - buildColumn: ({ suggestedPriority, field, previousColumn }) => ({ + buildColumn: ({ field, previousColumn }) => ({ label: ofName(field.displayName), dataType: 'number', operationType: type, - suggestedPriority, sourceField: field.name, isBucketed: false, scale: 'ratio', params: previousColumn && previousColumn.dataType === 'number' ? previousColumn.params : undefined, }), - onFieldChange: (oldColumn, indexPattern, field) => { + onFieldChange: (oldColumn, field) => { return { ...oldColumn, label: ofName(field.displayName), diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx index c6cc6ae13f178..b1cb2312d5bb8 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx @@ -12,7 +12,8 @@ import { Range } from '../../../../../../../../src/plugins/expressions/common/ex import { RangeEditor } from './range_editor'; import { OperationDefinition } from '../index'; import { FieldBasedIndexPatternColumn } from '../column_types'; -import { updateColumnParam, changeColumn } from '../../../state_helpers'; +import { updateColumnParam } from '../../layer_helpers'; +import { mergeLayer } from '../../../state_helpers'; import { supportedFormats } from '../../../format_column'; import { MODES, AUTO_BARS, DEFAULT_INTERVAL, MIN_HISTOGRAM_BARS, SLICES } from './constants'; import { IndexPattern, IndexPatternField } from '../../../types'; @@ -121,12 +122,11 @@ export const rangeOperation: OperationDefinition { + onFieldChange: (oldColumn, field) => { return { ...oldColumn, label: field.name, @@ -211,23 +211,26 @@ export const rangeOperation: OperationDefinition column && isSortableByColumn(column)) .map(([id]) => id)[0]; + const previousBucketsLength = Object.values(columns).filter((col) => col && col.isBucketed) + .length; + return { label: ofName(field.displayName), dataType: field.type as DataType, operationType: 'terms', scale: 'ordinal', - suggestedPriority, sourceField: field.name, isBucketed: true, params: { - size: DEFAULT_SIZE, + size: previousBucketsLength === 0 ? 5 : DEFAULT_SIZE, orderBy: existingMetricColumn ? { type: 'column', columnId: existingMetricColumn } : { type: 'alphabetical' }, @@ -111,7 +113,7 @@ export const termsOperation: OperationDefinition { + onFieldChange: (oldColumn, field) => { const newParams = { ...oldColumn.params }; if ('format' in newParams && field.type !== 'number') { delete newParams.format; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/terms.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/terms.test.tsx index bb1b13ba74cc5..0c6d6d18a74dc 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/terms.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/terms/terms.test.tsx @@ -105,7 +105,7 @@ describe('terms', () => { const indexPattern = createMockedIndexPattern(); const newNumberField = indexPattern.getFieldByName('bytes')!; - const column = termsOperation.onFieldChange(oldColumn, indexPattern, newNumberField); + const column = termsOperation.onFieldChange(oldColumn, newNumberField); expect(column).toHaveProperty('dataType', 'number'); expect(column).toHaveProperty('sourceField', 'bytes'); expect(column).toHaveProperty('params.size', 5); @@ -133,7 +133,7 @@ describe('terms', () => { const indexPattern = createMockedIndexPattern(); const newStringField = indexPattern.fields.find((i) => i.name === 'source')!; - const column = termsOperation.onFieldChange(oldColumn, indexPattern, newStringField); + const column = termsOperation.onFieldChange(oldColumn, newStringField); expect(column).toHaveProperty('dataType', 'string'); expect(column).toHaveProperty('sourceField', 'source'); expect(column.params.format).toBeUndefined(); @@ -236,8 +236,6 @@ describe('terms', () => { describe('buildColumn', () => { it('should use type from the passed field', () => { const termsColumn = termsOperation.buildColumn({ - layerId: 'first', - suggestedPriority: undefined, indexPattern: createMockedIndexPattern(), field: { aggregatable: true, @@ -253,8 +251,6 @@ describe('terms', () => { it('should use existing metric column as order column', () => { const termsColumn = termsOperation.buildColumn({ - layerId: 'first', - suggestedPriority: undefined, indexPattern: createMockedIndexPattern(), columns: { col1: { @@ -279,6 +275,36 @@ describe('terms', () => { }) ); }); + + it('should use the default size when there is an existing bucket', () => { + const termsColumn = termsOperation.buildColumn({ + indexPattern: createMockedIndexPattern(), + columns: state.layers.first.columns, + field: { + aggregatable: true, + searchable: true, + type: 'boolean', + name: 'test', + displayName: 'test', + }, + }); + expect(termsColumn.params).toEqual(expect.objectContaining({ size: 3 })); + }); + + it('should use a size of 5 when there are no other buckets', () => { + const termsColumn = termsOperation.buildColumn({ + indexPattern: createMockedIndexPattern(), + columns: {}, + field: { + aggregatable: true, + searchable: true, + type: 'boolean', + name: 'test', + displayName: 'test', + }, + }); + expect(termsColumn.params).toEqual(expect.objectContaining({ size: 5 })); + }); }); describe('onOtherColumnChanged', () => { diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/index.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/index.ts index 31a36c59274da..f0e02c7ff0faf 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/index.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/index.ts @@ -5,4 +5,5 @@ */ export * from './operations'; +export * from './layer_helpers'; export { OperationType, IndexPatternColumn, FieldBasedIndexPatternColumn } from './definitions'; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/state_helpers.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.test.ts similarity index 52% rename from x-pack/plugins/lens/public/indexpattern_datasource/state_helpers.test.ts rename to x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.test.ts index 45008b2d9439a..e1a31dc274837 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/state_helpers.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.test.ts @@ -5,22 +5,658 @@ */ import { + insertNewColumn, + replaceColumn, updateColumnParam, - changeColumn, getColumnOrder, deleteColumn, updateLayerIndexPattern, -} from './state_helpers'; -import { operationDefinitionMap } from './operations'; -import { TermsIndexPatternColumn } from './operations/definitions/terms'; -import { DateHistogramIndexPatternColumn } from './operations/definitions/date_histogram'; -import { AvgIndexPatternColumn } from './operations/definitions/metrics'; -import { IndexPattern, IndexPatternPrivateState, IndexPatternLayer } from './types'; -import { getFieldByNameFactory } from './pure_helpers'; +} from './layer_helpers'; +import { operationDefinitionMap, OperationType } from '../operations'; +import { TermsIndexPatternColumn } from './definitions/terms'; +import { DateHistogramIndexPatternColumn } from './definitions/date_histogram'; +import { AvgIndexPatternColumn } from './definitions/metrics'; +import { IndexPattern, IndexPatternPrivateState, IndexPatternLayer } from '../types'; +import { documentField } from '../document_field'; +import { getFieldByNameFactory } from '../pure_helpers'; -jest.mock('./operations'); +jest.mock('../operations'); + +const indexPatternFields = [ + { + name: 'timestamp', + displayName: 'timestampLabel', + type: 'date', + aggregatable: true, + searchable: true, + }, + { + name: 'start_date', + displayName: 'start_date', + type: 'date', + aggregatable: true, + searchable: true, + }, + { + name: 'bytes', + displayName: 'bytes', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'memory', + displayName: 'memory', + type: 'number', + aggregatable: true, + searchable: true, + }, + { + name: 'source', + displayName: 'source', + type: 'string', + aggregatable: true, + searchable: true, + }, + { + name: 'dest', + displayName: 'dest', + type: 'string', + aggregatable: true, + searchable: true, + }, + documentField, +]; + +const indexPattern = { + id: '1', + title: 'my-fake-index-pattern', + timeFieldName: 'timestamp', + hasRestrictions: false, + fields: indexPatternFields, + getFieldByName: getFieldByNameFactory(indexPatternFields), +}; describe('state_helpers', () => { + describe('insertNewColumn', () => { + it('should throw for invalid operations', () => { + expect(() => { + insertNewColumn({ + layer: { indexPatternId: '', columns: {}, columnOrder: [] }, + indexPattern, + op: 'missing' as OperationType, + columnId: 'none', + }); + }).toThrow(); + }); + + it('should update order on inserting a bucketed fieldless operation', () => { + const layer: IndexPatternLayer = { + indexPatternId: '1', + columnOrder: ['col1'], + columns: { + col1: { + label: 'Average of bytes', + dataType: 'number', + isBucketed: false, + + // Private + operationType: 'avg', + sourceField: 'bytes', + }, + }, + }; + expect( + insertNewColumn({ + layer, + indexPattern, + columnId: 'col2', + op: 'filters', + }) + ).toEqual(expect.objectContaining({ columnOrder: ['col2', 'col1'] })); + }); + + it('should update order on inserting a bucketed field-based operation', () => { + const layer: IndexPatternLayer = { + indexPatternId: '1', + columnOrder: ['col1'], + columns: { + col1: { + label: 'Average of bytes', + dataType: 'number', + isBucketed: false, + + // Private + operationType: 'avg', + sourceField: 'bytes', + }, + }, + }; + expect( + insertNewColumn({ + layer, + indexPattern, + columnId: 'col2', + op: 'date_histogram', + field: indexPattern.fields[0], + }) + ).toEqual(expect.objectContaining({ columnOrder: ['col2', 'col1'] })); + }); + + it('should insert a metric after buckets', () => { + const layer: IndexPatternLayer = { + indexPatternId: '1', + columnOrder: ['col1'], + columns: { + col1: { + label: 'Date histogram of timestamp', + dataType: 'date', + isBucketed: true, + + // Private + operationType: 'date_histogram', + sourceField: 'timestamp', + params: { + interval: 'h', + }, + }, + }, + }; + expect( + insertNewColumn({ + layer, + indexPattern, + columnId: 'col2', + op: 'count', + field: documentField, + }) + ).toEqual(expect.objectContaining({ columnOrder: ['col1', 'col2'] })); + }); + + it('should insert new buckets at the end of previous buckets', () => { + const layer: IndexPatternLayer = { + indexPatternId: '1', + columnOrder: ['col1', 'col3'], + columns: { + col1: { + label: 'Date histogram of timestamp', + dataType: 'date', + isBucketed: true, + + // Private + operationType: 'date_histogram', + sourceField: 'timestamp', + params: { + interval: 'h', + }, + }, + col3: { + label: 'Count of records', + dataType: 'document', + isBucketed: false, + + // Private + operationType: 'count', + sourceField: 'Records', + }, + }, + }; + expect( + insertNewColumn({ + layer, + indexPattern, + columnId: 'col2', + op: 'filters', + }) + ).toEqual(expect.objectContaining({ columnOrder: ['col1', 'col2', 'col3'] })); + }); + + it('should throw if the aggregation does not support the field', () => { + expect(() => { + insertNewColumn({ + layer: { indexPatternId: '1', columnOrder: [], columns: {} }, + columnId: 'col1', + indexPattern, + op: 'terms', + field: indexPattern.fields[0], + }); + }).toThrow(); + }); + + it('should put the terms agg ahead of the date histogram', () => { + expect( + insertNewColumn({ + layer: { + indexPatternId: '1', + columnOrder: ['col1'], + columns: { + col1: { + label: 'Date histogram of timestamp', + dataType: 'date', + isBucketed: true, + + // Private + operationType: 'date_histogram', + sourceField: 'timestamp', + params: { + interval: 'h', + }, + }, + }, + }, + columnId: 'col2', + indexPattern, + op: 'terms', + field: indexPattern.fields[2], + }) + ).toEqual(expect.objectContaining({ columnOrder: ['col2', 'col1'] })); + }); + + it('should allow two date histograms', () => { + expect( + insertNewColumn({ + layer: { + indexPatternId: '1', + columnOrder: ['col1'], + columns: { + col1: { + label: 'Date histogram of timestamp', + dataType: 'date', + isBucketed: true, + + // Private + operationType: 'date_histogram', + sourceField: 'timestamp', + params: { + interval: 'h', + }, + }, + }, + }, + columnId: 'col2', + indexPattern, + op: 'date_histogram', + field: indexPattern.fields[0], + }) + ).toEqual(expect.objectContaining({ columnOrder: ['col1', 'col2'] })); + }); + + it('should allow multiple metrics', () => { + expect( + insertNewColumn({ + layer: { + indexPatternId: '1', + columnOrder: ['col1', 'col2'], + columns: { + col1: { + label: 'Average of bytes', + dataType: 'number', + isBucketed: false, + + // Private + operationType: 'avg', + sourceField: 'bytes', + }, + col2: { + label: 'Count of records', + dataType: 'document', + isBucketed: false, + + // Private + operationType: 'count', + sourceField: 'Records', + }, + }, + }, + columnId: 'col3', + indexPattern, + op: 'sum', + field: indexPattern.fields[2], + }) + ).toEqual(expect.objectContaining({ columnOrder: ['col1', 'col2', 'col3'] })); + }); + }); + + describe('replaceColumn', () => { + it('should throw if there is no previous column', () => { + expect(() => { + replaceColumn({ + layer: { indexPatternId: '', columns: {}, columnOrder: [] }, + indexPattern, + op: 'count', + field: documentField, + columnId: 'none', + }); + }).toThrow(); + }); + + it('should throw for invalid operations', () => { + expect(() => { + replaceColumn({ + layer: { indexPatternId: '', columns: {}, columnOrder: [] }, + indexPattern, + op: 'missing' as OperationType, + columnId: 'none', + }); + }).toThrow(); + }); + + it('should update order on changing the column', () => { + const layer: IndexPatternLayer = { + indexPatternId: '1', + columnOrder: ['col1', 'col2'], + columns: { + col1: { + label: 'Average of bytes', + dataType: 'number', + isBucketed: false, + + // Private + operationType: 'avg', + sourceField: 'bytes', + }, + col2: { + label: 'Max of bytes', + dataType: 'number', + isBucketed: false, + + // Private + operationType: 'max', + sourceField: 'bytes', + }, + }, + }; + expect( + replaceColumn({ + layer, + indexPattern, + columnId: 'col2', + op: 'date_histogram', + field: indexPattern.fields[0], // date + }) + ).toEqual( + expect.objectContaining({ + columnOrder: ['col2', 'col1'], + }) + ); + }); + + it('should throw if nothing is changing', () => { + expect(() => { + replaceColumn({ + layer: { + indexPatternId: '1', + columnOrder: ['col1'], + columns: { + col1: { + label: 'Date histogram of timestamp', + dataType: 'date', + isBucketed: true, + + // Private + operationType: 'date_histogram', + sourceField: 'timestamp', + params: { + interval: 'h', + }, + }, + }, + }, + columnId: 'col1', + indexPattern, + op: 'date_histogram', + field: indexPattern.fields[0], + }); + }).toThrow(); + }); + + it('should throw if switching to a field-based operation without providing a field', () => { + expect(() => { + replaceColumn({ + layer: { + indexPatternId: '1', + columnOrder: ['col1'], + columns: { + col1: { + label: 'Date histogram of timestamp', + dataType: 'date', + isBucketed: true, + + // Private + operationType: 'date_histogram', + sourceField: 'timestamp', + params: { + interval: 'h', + }, + }, + }, + }, + columnId: 'col1', + indexPattern, + op: 'date_histogram', + }); + }).toThrow(); + }); + + it('should carry over params from old column if the switching fields', () => { + expect( + replaceColumn({ + layer: { + indexPatternId: '1', + columnOrder: ['col1'], + columns: { + col1: { + label: 'Date histogram of timestamp', + dataType: 'date', + isBucketed: true, + + // Private + operationType: 'date_histogram', + sourceField: 'timestamp', + params: { + interval: 'h', + }, + }, + }, + }, + columnId: 'col1', + indexPattern, + op: 'date_histogram', + field: indexPattern.fields[1], + }).columns.col1 + ).toEqual( + expect.objectContaining({ + params: { interval: 'h' }, + }) + ); + }); + + it('should transition from field-based to fieldless operation', () => { + expect( + replaceColumn({ + layer: { + indexPatternId: '1', + columnOrder: ['col1'], + columns: { + col1: { + label: 'Date histogram of timestamp', + dataType: 'date', + isBucketed: true, + + // Private + operationType: 'date_histogram', + sourceField: 'timestamp', + params: { + interval: 'h', + }, + }, + }, + }, + indexPattern, + columnId: 'col1', + op: 'filters', + }).columns.col1 + ).toEqual( + expect.objectContaining({ + operationType: 'filters', + }) + ); + }); + + it('should transition from fieldless to field-based operation', () => { + expect( + replaceColumn({ + layer: { + indexPatternId: '1', + columnOrder: ['col1'], + columns: { + col1: { + label: 'Filters', + dataType: 'string', + isBucketed: true, + + // Private + operationType: 'filters', + params: { + filters: [], + }, + }, + }, + }, + indexPattern, + columnId: 'col1', + op: 'date_histogram', + field: indexPattern.fields[0], + }).columns.col1 + ).toEqual( + expect.objectContaining({ + operationType: 'date_histogram', + }) + ); + }); + + it('should carry over label on field switch when customLabel flag is set', () => { + expect( + replaceColumn({ + layer: { + indexPatternId: '1', + columnOrder: ['col1'], + columns: { + col1: { + label: 'My custom label', + customLabel: true, + dataType: 'date', + isBucketed: true, + + // Private + operationType: 'date_histogram', + sourceField: 'timestamp', + params: { + interval: 'h', + }, + }, + }, + }, + indexPattern, + columnId: 'col1', + op: 'date_histogram', + field: indexPattern.fields[1], + }).columns.col1 + ).toEqual( + expect.objectContaining({ + label: 'My custom label', + customLabel: true, + }) + ); + }); + + it('should carry over label on operation switch when customLabel flag is set', () => { + expect( + replaceColumn({ + layer: { + indexPatternId: '1', + columnOrder: ['col1'], + columns: { + col1: { + label: 'My custom label', + customLabel: true, + dataType: 'date', + isBucketed: true, + + // Private + operationType: 'date_histogram', + sourceField: 'timestamp', + params: { + interval: 'h', + }, + }, + }, + }, + indexPattern, + columnId: 'col1', + op: 'terms', + field: indexPattern.fields[0], + }).columns.col1 + ).toEqual( + expect.objectContaining({ + label: 'My custom label', + customLabel: true, + }) + ); + }); + + it('should execute adjustments for other columns', () => { + const termsColumn: TermsIndexPatternColumn = { + label: 'Top values of source', + dataType: 'string', + isBucketed: true, + + // Private + operationType: 'terms', + sourceField: 'source', + params: { + orderBy: { type: 'alphabetical' }, + orderDirection: 'asc', + size: 5, + }, + }; + + replaceColumn({ + layer: { + indexPatternId: '1', + columnOrder: ['col1', 'col2'], + columns: { + col1: termsColumn, + col2: { + label: 'Count', + dataType: 'number', + isBucketed: false, + sourceField: 'Records', + operationType: 'count', + }, + }, + }, + indexPattern, + columnId: 'col2', + op: 'avg', + field: indexPattern.fields[2], // bytes field + }); + + expect(operationDefinitionMap.terms.onOtherColumnChanged).toHaveBeenCalledWith(termsColumn, { + col1: termsColumn, + col2: expect.objectContaining({ + label: 'Average of bytes', + dataType: 'number', + isBucketed: false, + + // Private + operationType: 'avg', + sourceField: 'bytes', + }), + }); + }); + }); + describe('deleteColumn', () => { it('should remove column', () => { const termsColumn: TermsIndexPatternColumn = { @@ -38,14 +674,9 @@ describe('state_helpers', () => { }, }; - const state: IndexPatternPrivateState = { - indexPatternRefs: [], - existingFields: {}, - indexPatterns: {}, - currentIndexPatternId: '1', - isFirstExistenceFetch: false, - layers: { - first: { + expect( + deleteColumn({ + layer: { indexPatternId: '1', columnOrder: ['col1', 'col2'], columns: { @@ -59,11 +690,8 @@ describe('state_helpers', () => { }, }, }, - }, - }; - - expect( - deleteColumn({ state, columnId: 'col2', layerId: 'first' }).layers.first.columns + columnId: 'col2', + }).columns ).toEqual({ col1: { ...termsColumn, @@ -92,34 +720,22 @@ describe('state_helpers', () => { }, }; - const state: IndexPatternPrivateState = { - indexPatternRefs: [], - existingFields: {}, - indexPatterns: {}, - currentIndexPatternId: '1', - isFirstExistenceFetch: false, - layers: { - first: { - indexPatternId: '1', - columnOrder: ['col1', 'col2'], - columns: { - col1: termsColumn, - col2: { - label: 'Count', - dataType: 'number', - isBucketed: false, - sourceField: 'Records', - operationType: 'count', - }, + deleteColumn({ + layer: { + indexPatternId: '1', + columnOrder: ['col1', 'col2'], + columns: { + col1: termsColumn, + col2: { + label: 'Count', + dataType: 'number', + isBucketed: false, + sourceField: 'Records', + operationType: 'count', }, }, }, - }; - - deleteColumn({ - state, columnId: 'col2', - layerId: 'first', }); expect(operationDefinitionMap.terms.onOtherColumnChanged).toHaveBeenCalledWith(termsColumn, { @@ -216,241 +832,6 @@ describe('state_helpers', () => { }); }); - describe('changeColumn', () => { - it('should update order on changing the column', () => { - const state: IndexPatternPrivateState = { - indexPatternRefs: [], - existingFields: {}, - indexPatterns: {}, - currentIndexPatternId: '1', - isFirstExistenceFetch: false, - layers: { - first: { - indexPatternId: '1', - columnOrder: ['col1', 'col2'], - columns: { - col1: { - label: 'Average of bytes', - dataType: 'number', - isBucketed: false, - - // Private - operationType: 'avg', - sourceField: 'bytes', - }, - col2: { - label: 'Max of bytes', - dataType: 'number', - isBucketed: false, - - // Private - operationType: 'max', - sourceField: 'bytes', - }, - }, - }, - }, - }; - expect( - changeColumn({ - state, - columnId: 'col2', - layerId: 'first', - newColumn: { - label: 'Date histogram of timestamp', - dataType: 'date', - isBucketed: true, - - // Private - operationType: 'date_histogram', - params: { - interval: '1d', - }, - sourceField: 'timestamp', - }, - }) - ).toEqual({ - ...state, - layers: { - first: expect.objectContaining({ - columnOrder: ['col2', 'col1'], - }), - }, - }); - }); - - it('should carry over params from old column if the operation type stays the same', () => { - const state: IndexPatternPrivateState = { - indexPatternRefs: [], - existingFields: {}, - indexPatterns: {}, - currentIndexPatternId: '1', - isFirstExistenceFetch: false, - layers: { - first: { - indexPatternId: '1', - columnOrder: ['col1'], - columns: { - col1: { - label: 'Date histogram of timestamp', - dataType: 'date', - isBucketed: true, - - // Private - operationType: 'date_histogram', - sourceField: 'timestamp', - params: { - interval: 'h', - }, - }, - }, - }, - }, - }; - expect( - changeColumn({ - state, - layerId: 'first', - columnId: 'col2', - newColumn: { - label: 'Date histogram of order_date', - dataType: 'date', - isBucketed: true, - - // Private - operationType: 'date_histogram', - sourceField: 'order_date', - params: { - interval: 'w', - }, - }, - }).layers.first.columns.col1 - ).toEqual( - expect.objectContaining({ - params: { interval: 'h' }, - }) - ); - }); - - it('should carry over label if customLabel flag is set', () => { - const state: IndexPatternPrivateState = { - indexPatternRefs: [], - existingFields: {}, - indexPatterns: {}, - currentIndexPatternId: '1', - isFirstExistenceFetch: false, - layers: { - first: { - indexPatternId: '1', - columnOrder: ['col1'], - columns: { - col1: { - label: 'My custom label', - customLabel: true, - dataType: 'date', - isBucketed: true, - - // Private - operationType: 'date_histogram', - sourceField: 'timestamp', - params: { - interval: 'h', - }, - }, - }, - }, - }, - }; - expect( - changeColumn({ - state, - layerId: 'first', - columnId: 'col2', - newColumn: { - label: 'Date histogram of order_date', - dataType: 'date', - isBucketed: true, - - // Private - operationType: 'date_histogram', - sourceField: 'order_date', - params: { - interval: 'w', - }, - }, - }).layers.first.columns.col1 - ).toEqual( - expect.objectContaining({ - label: 'My custom label', - customLabel: true, - }) - ); - }); - - it('should execute adjustments for other columns', () => { - const termsColumn: TermsIndexPatternColumn = { - label: 'Top values of source', - dataType: 'string', - isBucketed: true, - - // Private - operationType: 'terms', - sourceField: 'source', - params: { - orderBy: { type: 'alphabetical' }, - orderDirection: 'asc', - size: 5, - }, - }; - - const newColumn: AvgIndexPatternColumn = { - label: 'Average of bytes', - dataType: 'number', - isBucketed: false, - - // Private - operationType: 'avg', - sourceField: 'bytes', - }; - - const state: IndexPatternPrivateState = { - indexPatternRefs: [], - existingFields: {}, - indexPatterns: {}, - currentIndexPatternId: '1', - isFirstExistenceFetch: false, - layers: { - first: { - indexPatternId: '1', - columnOrder: ['col1', 'col2'], - columns: { - col1: termsColumn, - col2: { - label: 'Count', - dataType: 'number', - isBucketed: false, - sourceField: 'Records', - operationType: 'count', - }, - }, - }, - }, - }; - - changeColumn({ - state, - layerId: 'first', - columnId: 'col2', - newColumn, - }); - - expect(operationDefinitionMap.terms.onOtherColumnChanged).toHaveBeenCalledWith(termsColumn, { - col1: termsColumn, - col2: newColumn, - }); - }); - }); - describe('getColumnOrder', () => { it('should work for empty columns', () => { expect( @@ -532,57 +913,6 @@ describe('state_helpers', () => { }) ).toEqual(['col1', 'col3', 'col2']); }); - - it('should reorder aggregations based on suggested priority', () => { - expect( - getColumnOrder({ - indexPatternId: '', - columnOrder: [], - columns: { - col1: { - label: 'Top values of category', - dataType: 'string', - isBucketed: true, - - // Private - operationType: 'terms', - sourceField: 'category', - params: { - size: 5, - orderBy: { - type: 'alphabetical', - }, - orderDirection: 'asc', - }, - suggestedPriority: 2, - }, - col2: { - label: 'Average of bytes', - dataType: 'number', - isBucketed: false, - - // Private - operationType: 'avg', - sourceField: 'bytes', - suggestedPriority: 0, - }, - col3: { - label: 'Date histogram of timestamp', - dataType: 'date', - isBucketed: true, - - // Private - operationType: 'date_histogram', - sourceField: 'timestamp', - suggestedPriority: 1, - params: { - interval: '1d', - }, - }, - }, - }) - ).toEqual(['col3', 'col1', 'col2']); - }); }); describe('updateLayerIndexPattern', () => { @@ -635,7 +965,7 @@ describe('state_helpers', () => { type: 'date', }, ]; - const indexPattern: IndexPattern = { + const newIndexPattern: IndexPattern = { id: 'test', title: '', hasRestrictions: true, @@ -645,7 +975,7 @@ describe('state_helpers', () => { it('should switch index pattern id in layer', () => { const layer = { columnOrder: [], columns: {}, indexPatternId: 'original' }; - expect(updateLayerIndexPattern(layer, indexPattern)).toEqual({ + expect(updateLayerIndexPattern(layer, newIndexPattern)).toEqual({ ...layer, indexPatternId: 'test', }); @@ -677,7 +1007,7 @@ describe('state_helpers', () => { }, indexPatternId: 'original', }; - const updatedLayer = updateLayerIndexPattern(layer, indexPattern); + const updatedLayer = updateLayerIndexPattern(layer, newIndexPattern); expect(updatedLayer.columnOrder).toEqual(['col1']); expect(updatedLayer.columns).toEqual({ col1: layer.columns.col1, @@ -708,7 +1038,7 @@ describe('state_helpers', () => { }, indexPatternId: 'original', }; - const updatedLayer = updateLayerIndexPattern(layer, indexPattern); + const updatedLayer = updateLayerIndexPattern(layer, newIndexPattern); expect(updatedLayer.columnOrder).toEqual(['col2']); expect(updatedLayer.columns).toEqual({ col2: layer.columns.col2, @@ -732,7 +1062,7 @@ describe('state_helpers', () => { }, indexPatternId: 'original', }; - const updatedLayer = updateLayerIndexPattern(layer, indexPattern); + const updatedLayer = updateLayerIndexPattern(layer, newIndexPattern); expect(updatedLayer.columnOrder).toEqual(['col1']); expect(updatedLayer.columns).toEqual({ col1: { @@ -771,7 +1101,7 @@ describe('state_helpers', () => { }, indexPatternId: 'original', }; - const updatedLayer = updateLayerIndexPattern(layer, indexPattern); + const updatedLayer = updateLayerIndexPattern(layer, newIndexPattern); expect(updatedLayer.columnOrder).toEqual(['col1']); expect(updatedLayer.columns).toEqual({ col1: layer.columns.col1, @@ -804,7 +1134,7 @@ describe('state_helpers', () => { }, indexPatternId: 'original', }; - const updatedLayer = updateLayerIndexPattern(layer, indexPattern); + const updatedLayer = updateLayerIndexPattern(layer, newIndexPattern); expect(updatedLayer.columnOrder).toEqual(['col1']); expect(updatedLayer.columns).toEqual({ col1: layer.columns.col1, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.ts new file mode 100644 index 0000000000000..f071df1542147 --- /dev/null +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.ts @@ -0,0 +1,344 @@ +/* + * 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 _, { partition } from 'lodash'; +import { + operationDefinitionMap, + operationDefinitions, + OperationType, + IndexPatternColumn, +} from './definitions'; +import { + IndexPattern, + IndexPatternField, + IndexPatternLayer, + IndexPatternPrivateState, +} from '../types'; +import { getSortScoreByPriority } from './operations'; +import { mergeLayer } from '../state_helpers'; + +interface ColumnChange { + op: OperationType; + layer: IndexPatternLayer; + columnId: string; + indexPattern: IndexPattern; + field?: IndexPatternField; +} + +export function insertOrReplaceColumn(args: ColumnChange): IndexPatternLayer { + if (args.layer.columns[args.columnId]) { + return replaceColumn(args); + } + return insertNewColumn(args); +} + +export function insertNewColumn({ + op, + layer, + columnId, + field, + indexPattern, +}: ColumnChange): IndexPatternLayer { + const operationDefinition = operationDefinitionMap[op]; + + if (!operationDefinition) { + throw new Error('No suitable operation found for given parameters'); + } + + const baseOptions = { + columns: layer.columns, + indexPattern, + previousColumn: layer.columns[columnId], + }; + + // TODO: Reference based operations require more setup to create the references + + if (operationDefinition.input === 'none') { + const possibleOperation = operationDefinition.getPossibleOperation(); + if (!possibleOperation) { + throw new Error('Tried to create an invalid operation'); + } + const isBucketed = Boolean(possibleOperation.isBucketed); + if (isBucketed) { + return addBucket(layer, operationDefinition.buildColumn(baseOptions), columnId); + } else { + return addMetric(layer, operationDefinition.buildColumn(baseOptions), columnId); + } + } + + if (!field) { + throw new Error(`Invariant error: ${operationDefinition.type} operation requires field`); + } + + const possibleOperation = operationDefinition.getPossibleOperationForField(field); + if (!possibleOperation) { + throw new Error( + `Tried to create an invalid operation ${operationDefinition.type} on ${field.name}` + ); + } + const isBucketed = Boolean(possibleOperation.isBucketed); + if (isBucketed) { + return addBucket(layer, operationDefinition.buildColumn({ ...baseOptions, field }), columnId); + } else { + return addMetric(layer, operationDefinition.buildColumn({ ...baseOptions, field }), columnId); + } +} + +export function replaceColumn({ + layer, + columnId, + indexPattern, + op, + field, +}: ColumnChange): IndexPatternLayer { + const previousColumn = layer.columns[columnId]; + if (!previousColumn) { + throw new Error(`Can't replace column because there is no prior column`); + } + + const isNewOperation = Boolean(op) && op !== previousColumn.operationType; + const operationDefinition = operationDefinitionMap[op || previousColumn.operationType]; + + if (!operationDefinition) { + throw new Error('No suitable operation found for given parameters'); + } + + const baseOptions = { + columns: layer.columns, + indexPattern, + previousColumn, + }; + + if (isNewOperation) { + // TODO: Reference based operations require more setup to create the references + + if (operationDefinition.input === 'none') { + const newColumn = operationDefinition.buildColumn(baseOptions); + + if (previousColumn.customLabel) { + newColumn.customLabel = true; + newColumn.label = previousColumn.label; + } + + return { + ...layer, + columns: adjustColumnReferencesForChangedColumn( + { ...layer.columns, [columnId]: newColumn }, + columnId + ), + }; + } + + if (!field) { + throw new Error(`Invariant error: ${operationDefinition.type} operation requires field`); + } + + const newColumn = operationDefinition.buildColumn({ ...baseOptions, field }); + + if (previousColumn.customLabel) { + newColumn.customLabel = true; + newColumn.label = previousColumn.label; + } + + const newColumns = { ...layer.columns, [columnId]: newColumn }; + return { + ...layer, + columnOrder: getColumnOrder({ ...layer, columns: newColumns }), + columns: adjustColumnReferencesForChangedColumn(newColumns, columnId), + }; + } else if ( + operationDefinition.input === 'field' && + field && + 'sourceField' in previousColumn && + previousColumn.sourceField !== field.name + ) { + // Same operation, new field + const newColumn = operationDefinition.onFieldChange(previousColumn, field); + + if (previousColumn.customLabel) { + newColumn.customLabel = true; + newColumn.label = previousColumn.label; + } + + const newColumns = { ...layer.columns, [columnId]: newColumn }; + return { + ...layer, + columnOrder: getColumnOrder({ ...layer, columns: newColumns }), + columns: adjustColumnReferencesForChangedColumn(newColumns, columnId), + }; + } else { + throw new Error('nothing changed'); + } +} + +function addBucket( + layer: IndexPatternLayer, + column: IndexPatternColumn, + addedColumnId: string +): IndexPatternLayer { + const [buckets, metrics] = separateBucketColumns(layer); + + const oldDateHistogramIndex = layer.columnOrder.findIndex( + (columnId) => layer.columns[columnId].operationType === 'date_histogram' + ); + + let updatedColumnOrder: string[] = []; + if (oldDateHistogramIndex > -1 && column.operationType === 'terms') { + // Insert the new terms bucket above the first date histogram + updatedColumnOrder = [ + ...buckets.slice(0, oldDateHistogramIndex), + addedColumnId, + ...buckets.slice(oldDateHistogramIndex, buckets.length), + ...metrics, + ]; + } else { + // Insert the new bucket after existing buckets. Users will see the same data + // they already had, with an extra level of detail. + updatedColumnOrder = [...buckets, addedColumnId, ...metrics]; + } + return { + ...layer, + columns: { ...layer.columns, [addedColumnId]: column }, + columnOrder: updatedColumnOrder, + }; +} + +function addMetric( + layer: IndexPatternLayer, + column: IndexPatternColumn, + addedColumnId: string +): IndexPatternLayer { + return { + ...layer, + columns: { + ...layer.columns, + [addedColumnId]: column, + }, + columnOrder: [...layer.columnOrder, addedColumnId], + }; +} + +function separateBucketColumns(layer: IndexPatternLayer) { + return partition(layer.columnOrder, (columnId) => layer.columns[columnId]?.isBucketed); +} + +export function getMetricOperationTypes(field: IndexPatternField) { + return operationDefinitions.sort(getSortScoreByPriority).filter((definition) => { + if (definition.input !== 'field') return; + const metadata = definition.getPossibleOperationForField(field); + return metadata && !metadata.isBucketed && metadata.dataType === 'number'; + }); +} + +export function updateColumnParam({ + state, + layerId, + currentColumn, + paramName, + value, +}: { + state: IndexPatternPrivateState; + layerId: string; + currentColumn: C; + paramName: string; + value: unknown; +}): IndexPatternPrivateState { + const columnId = Object.entries(state.layers[layerId].columns).find( + ([_columnId, column]) => column === currentColumn + )![0]; + + const layer = state.layers[layerId]; + + return mergeLayer({ + state, + layerId, + newLayer: { + columns: { + ...layer.columns, + [columnId]: { + ...currentColumn, + params: { + ...currentColumn.params, + [paramName]: value, + }, + }, + }, + }, + }); +} + +function adjustColumnReferencesForChangedColumn( + columns: Record, + columnId: string +) { + const newColumns = { ...columns }; + Object.keys(newColumns).forEach((currentColumnId) => { + if (currentColumnId !== columnId) { + const currentColumn = newColumns[currentColumnId]; + const operationDefinition = operationDefinitionMap[currentColumn.operationType]; + newColumns[currentColumnId] = operationDefinition.onOtherColumnChanged + ? operationDefinition.onOtherColumnChanged(currentColumn, newColumns) + : currentColumn; + } + }); + return newColumns; +} + +export function deleteColumn({ + layer, + columnId, +}: { + layer: IndexPatternLayer; + columnId: string; +}): IndexPatternLayer { + const hypotheticalColumns = { ...layer.columns }; + delete hypotheticalColumns[columnId]; + + const newLayer = { + ...layer, + columns: adjustColumnReferencesForChangedColumn(hypotheticalColumns, columnId), + }; + return { ...newLayer, columnOrder: getColumnOrder(newLayer) }; +} + +export function getColumnOrder(layer: IndexPatternLayer): string[] { + const [aggregations, metrics] = _.partition( + Object.entries(layer.columns), + ([id, col]) => col.isBucketed + ); + + return aggregations.map(([id]) => id).concat(metrics.map(([id]) => id)); +} + +/** + * Returns true if the given column can be applied to the given index pattern + */ +export function isColumnTransferable(column: IndexPatternColumn, newIndexPattern: IndexPattern) { + return operationDefinitionMap[column.operationType].isTransferable(column, newIndexPattern); +} + +export function updateLayerIndexPattern( + layer: IndexPatternLayer, + newIndexPattern: IndexPattern +): IndexPatternLayer { + const keptColumns: IndexPatternLayer['columns'] = _.pickBy(layer.columns, (column) => + isColumnTransferable(column, newIndexPattern) + ); + const newColumns: IndexPatternLayer['columns'] = _.mapValues(keptColumns, (column) => { + const operationDefinition = operationDefinitionMap[column.operationType]; + return operationDefinition.transfer + ? operationDefinition.transfer(column, newIndexPattern) + : column; + }); + const newColumnOrder = layer.columnOrder.filter((columnId) => newColumns[columnId]); + + return { + ...layer, + indexPatternId: newIndexPattern.id, + columns: newColumns, + columnOrder: newColumnOrder, + }; +} diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/operations.test.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/operations.test.ts index 9767d4bdca688..99149c3e74568 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/operations.test.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/operations.test.ts @@ -4,10 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getOperationTypesForField, getAvailableOperationsByMetadata, buildColumn } from './index'; -import { AvgIndexPatternColumn } from './definitions/metrics'; -import { IndexPatternPrivateState } from '../types'; -import { documentField } from '../document_field'; +import { getOperationTypesForField, getAvailableOperationsByMetadata } from './index'; import { getFieldByNameFactory } from '../pure_helpers'; jest.mock('../loader'); @@ -157,73 +154,6 @@ describe('getOperationTypesForField', () => { }); }); - describe('buildColumn', () => { - const state: IndexPatternPrivateState = { - indexPatternRefs: [], - existingFields: {}, - currentIndexPatternId: '1', - isFirstExistenceFetch: false, - indexPatterns: expectedIndexPatterns, - layers: { - first: { - indexPatternId: '1', - columnOrder: ['col1'], - columns: { - col1: { - label: 'Date histogram of timestamp', - dataType: 'date', - isBucketed: true, - - // Private - operationType: 'date_histogram', - params: { - interval: '1d', - }, - sourceField: 'timestamp', - }, - }, - }, - }, - }; - - it('should build a column for the given field-based operation type if it is passed in', () => { - const column = buildColumn({ - layerId: 'first', - indexPattern: expectedIndexPatterns[1], - columns: state.layers.first.columns, - suggestedPriority: 0, - op: 'count', - field: documentField, - }); - expect(column.operationType).toEqual('count'); - }); - - it('should build a column for the given no-input operation type if it is passed in', () => { - const column = buildColumn({ - layerId: 'first', - indexPattern: expectedIndexPatterns[1], - columns: state.layers.first.columns, - suggestedPriority: 0, - op: 'filters', - }); - expect(column.operationType).toEqual('filters'); - }); - - it('should build a column for the given operation type and field if it is passed in', () => { - const field = expectedIndexPatterns[1].fields[1]; - const column = buildColumn({ - layerId: 'first', - indexPattern: expectedIndexPatterns[1], - columns: state.layers.first.columns, - suggestedPriority: 0, - op: 'avg', - field, - }) as AvgIndexPatternColumn; - expect(column.operationType).toEqual('avg'); - expect(column.sourceField).toEqual(field.name); - }); - }); - describe('getAvailableOperationsByMetaData', () => { it('should put the average operation first', () => { const numberOperation = getAvailableOperationsByMetadata(expectedIndexPatterns[1]).find( diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/operations.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/operations.ts index 46dd73ba849a2..8d489df366088 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/operations.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/operations.ts @@ -4,17 +4,19 @@ * you may not use this file except in compliance with the Elastic License. */ -import { DimensionPriority, OperationMetadata } from '../../types'; +import _ from 'lodash'; +import { OperationMetadata } from '../../types'; import { operationDefinitionMap, operationDefinitions, GenericOperationDefinition, OperationType, - IndexPatternColumn, } from './definitions'; import { IndexPattern, IndexPatternField } from '../types'; import { documentField } from '../document_field'; +export { operationDefinitionMap } from './definitions'; + /** * Returns all available operation types as a list at runtime. * This will be an array of each member of the union type `OperationType` @@ -24,13 +26,6 @@ export function getOperations(): OperationType[] { return Object.keys(operationDefinitionMap) as OperationType[]; } -/** - * Returns true if the given column can be applied to the given index pattern - */ -export function isColumnTransferable(column: IndexPatternColumn, newIndexPattern: IndexPattern) { - return operationDefinitionMap[column.operationType].isTransferable(column, newIndexPattern); -} - /** * Returns a list of the display names of all operations with any guaranteed order. */ @@ -51,7 +46,10 @@ export function getOperationDisplay() { return display; } -function getSortScoreByPriority(a: GenericOperationDefinition, b: GenericOperationDefinition) { +export function getSortScoreByPriority( + a: GenericOperationDefinition, + b: GenericOperationDefinition +) { return (b.priority || Number.NEGATIVE_INFINITY) - (a.priority || Number.NEGATIVE_INFINITY); } @@ -169,82 +167,3 @@ export function getAvailableOperationsByMetadata(indexPattern: IndexPattern) { return Object.values(operationByMetadata); } - -/** - * Changes the field of the passed in colum. To do so, this method uses the `onFieldChange` function of - * the operation definition of the column. Returns a new column object with the field changed. - * @param column The column object with the old field configured - * @param indexPattern The index pattern associated to the layer of the column - * @param newField The new field the column should be switched to - */ -export function changeField( - column: IndexPatternColumn, - indexPattern: IndexPattern, - newField: IndexPatternField -) { - const operationDefinition = operationDefinitionMap[column.operationType]; - - if (operationDefinition.input === 'field' && 'sourceField' in column) { - return operationDefinition.onFieldChange(column, indexPattern, newField); - } else { - throw new Error( - "Invariant error: Cannot change field if operation isn't a field based operaiton" - ); - } -} - -/** - * Builds a column object based on the context passed in. It tries - * to find the applicable operation definition and then calls the `buildColumn` - * function of that definition. It passes in the given `field` (if available), - * `suggestedPriority`, `layerId` and the currently existing `columns`. - * * If `op` is specified, the specified operation definition is used directly. - * * If `asDocumentOperation` is true, the first matching document-operation is used. - * * If `field` is specified, the first matching field based operation applicable to the field is used. - */ -export function buildColumn({ - op, - columns, - field, - layerId, - indexPattern, - suggestedPriority, - previousColumn, -}: { - op: OperationType; - columns: Partial>; - suggestedPriority: DimensionPriority | undefined; - layerId: string; - indexPattern: IndexPattern; - field?: IndexPatternField; - previousColumn?: IndexPatternColumn; -}): IndexPatternColumn { - const operationDefinition = operationDefinitionMap[op]; - - if (!operationDefinition) { - throw new Error('No suitable operation found for given parameters'); - } - - const baseOptions = { - columns, - suggestedPriority, - layerId, - indexPattern, - previousColumn, - }; - - if (operationDefinition.input === 'none') { - return operationDefinition.buildColumn(baseOptions); - } - - if (!field) { - throw new Error(`Invariant error: ${operationDefinition.type} operation requires field`); - } - - return operationDefinition.buildColumn({ - ...baseOptions, - field, - }); -} - -export { operationDefinitionMap } from './definitions'; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/state_helpers.ts b/x-pack/plugins/lens/public/indexpattern_datasource/state_helpers.ts index 2e92d4ad8f88b..32e45965f3e75 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/state_helpers.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/state_helpers.ts @@ -4,162 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import _ from 'lodash'; -import { isColumnTransferable, operationDefinitionMap, IndexPatternColumn } from './operations'; -import { IndexPattern, IndexPatternPrivateState, IndexPatternLayer } from './types'; - -export function updateColumnParam({ - state, - layerId, - currentColumn, - paramName, - value, -}: { - state: IndexPatternPrivateState; - layerId: string; - currentColumn: C; - paramName: string; - value: unknown; -}): IndexPatternPrivateState { - const columnId = Object.entries(state.layers[layerId].columns).find( - ([_columnId, column]) => column === currentColumn - )![0]; - - const layer = state.layers[layerId]; - - return mergeLayer({ - state, - layerId, - newLayer: { - columns: { - ...layer.columns, - [columnId]: { - ...currentColumn, - params: { - ...currentColumn.params, - [paramName]: value, - }, - }, - }, - }, - }); -} - -function adjustColumnReferencesForChangedColumn( - columns: Record, - columnId: string -) { - const newColumns = { ...columns }; - Object.keys(newColumns).forEach((currentColumnId) => { - if (currentColumnId !== columnId) { - const currentColumn = newColumns[currentColumnId]; - const operationDefinition = operationDefinitionMap[currentColumn.operationType]; - newColumns[currentColumnId] = operationDefinition.onOtherColumnChanged - ? operationDefinition.onOtherColumnChanged(currentColumn, newColumns) - : currentColumn; - } - }); - return newColumns; -} - -export function changeColumn({ - state, - layerId, - columnId, - newColumn, - keepParams = true, -}: { - state: IndexPatternPrivateState; - layerId: string; - columnId: string; - newColumn: C; - keepParams?: boolean; -}): IndexPatternPrivateState { - const oldColumn = state.layers[layerId].columns[columnId]; - - const updatedColumn = - keepParams && - oldColumn && - oldColumn.operationType === newColumn.operationType && - 'params' in oldColumn - ? { ...newColumn, params: oldColumn.params } - : newColumn; - - if (oldColumn && oldColumn.customLabel) { - updatedColumn.customLabel = true; - updatedColumn.label = oldColumn.label; - } - - const layer = { - ...state.layers[layerId], - }; - - const newColumns = adjustColumnReferencesForChangedColumn( - { - ...layer.columns, - [columnId]: updatedColumn, - }, - columnId - ); - - return mergeLayer({ - state, - layerId, - newLayer: { - columnOrder: getColumnOrder({ - ...layer, - columns: newColumns, - }), - columns: newColumns, - }, - }); -} - -export function deleteColumn({ - state, - layerId, - columnId, -}: { - state: IndexPatternPrivateState; - layerId: string; - columnId: string; -}): IndexPatternPrivateState { - const hypotheticalColumns = { ...state.layers[layerId].columns }; - delete hypotheticalColumns[columnId]; - - const newColumns = adjustColumnReferencesForChangedColumn(hypotheticalColumns, columnId); - const layer = { - ...state.layers[layerId], - columns: newColumns, - }; - - return mergeLayer({ - state, - layerId, - newLayer: { - ...layer, - columnOrder: getColumnOrder(layer), - }, - }); -} - -export function getColumnOrder(layer: IndexPatternLayer): string[] { - const [aggregations, metrics] = _.partition( - Object.entries(layer.columns), - ([id, col]) => col.isBucketed - ); - - return aggregations - .sort(([id, col], [id2, col2]) => { - return ( - // Sort undefined orders last - (col.suggestedPriority !== undefined ? col.suggestedPriority : Number.MAX_SAFE_INTEGER) - - (col2.suggestedPriority !== undefined ? col2.suggestedPriority : Number.MAX_SAFE_INTEGER) - ); - }) - .map(([id]) => id) - .concat(metrics.map(([id]) => id)); -} +import { IndexPatternPrivateState, IndexPatternLayer } from './types'; export function mergeLayer({ state, @@ -178,26 +23,3 @@ export function mergeLayer({ }, }; } - -export function updateLayerIndexPattern( - layer: IndexPatternLayer, - newIndexPattern: IndexPattern -): IndexPatternLayer { - const keptColumns: IndexPatternLayer['columns'] = _.pickBy(layer.columns, (column) => - isColumnTransferable(column, newIndexPattern) - ); - const newColumns: IndexPatternLayer['columns'] = _.mapValues(keptColumns, (column) => { - const operationDefinition = operationDefinitionMap[column.operationType]; - return operationDefinition.transfer - ? operationDefinition.transfer(column, newIndexPattern) - : column; - }); - const newColumnOrder = layer.columnOrder.filter((columnId) => newColumns[columnId]); - - return { - ...layer, - indexPatternId: newIndexPattern.id, - columns: newColumns, - columnOrder: newColumnOrder, - }; -} diff --git a/x-pack/plugins/lens/public/types.ts b/x-pack/plugins/lens/public/types.ts index 4ad849c5d441e..b8bceb5454bc8 100644 --- a/x-pack/plugins/lens/public/types.ts +++ b/x-pack/plugins/lens/public/types.ts @@ -72,9 +72,6 @@ export interface EditorFrameStart { createInstance: () => Promise; } -// Hints the default nesting to the data source. 0 is the highest priority -export type DimensionPriority = 0 | 1 | 2; - export interface TableSuggestionColumn { columnId: string; operation: Operation; @@ -220,11 +217,6 @@ interface SharedDimensionProps { */ filterOperations: (operation: OperationMetadata) => boolean; - /** Visualizations can hint at the role this dimension would play, which - * affects the default ordering of the query - */ - suggestedPriority?: DimensionPriority; - /** Some dimension editors will allow users to change the operation grouping * from the panel, and this lets the visualization hint that it doesn't want * users to have that level of control diff --git a/x-pack/plugins/lens/public/xy_visualization/visualization.tsx b/x-pack/plugins/lens/public/xy_visualization/visualization.tsx index 7e155de14a39a..1f135929dac21 100644 --- a/x-pack/plugins/lens/public/xy_visualization/visualization.tsx +++ b/x-pack/plugins/lens/public/xy_visualization/visualization.tsx @@ -178,7 +178,6 @@ export const getXyVisualization = ({ groupLabel: getAxisName('x', { isHorizontal }), accessors: layer.xAccessor ? [layer.xAccessor] : [], filterOperations: isBucketed, - suggestedPriority: 1, supportsMoreColumns: !layer.xAccessor, dataTestSubj: 'lnsXY_xDimensionPanel', }, @@ -199,7 +198,6 @@ export const getXyVisualization = ({ }), accessors: layer.splitAccessor ? [layer.splitAccessor] : [], filterOperations: isBucketed, - suggestedPriority: 0, supportsMoreColumns: !layer.splitAccessor, dataTestSubj: 'lnsXY_splitDimensionPanel', required: layer.seriesType.includes('percentage'), diff --git a/x-pack/plugins/lens/server/migrations.test.ts b/x-pack/plugins/lens/server/migrations.test.ts index 676494dcab619..957da5cbb3743 100644 --- a/x-pack/plugins/lens/server/migrations.test.ts +++ b/x-pack/plugins/lens/server/migrations.test.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { migrations } from './migrations'; -import { SavedObjectMigrationContext } from 'src/core/server'; +import { migrations, LensDocShape } from './migrations'; +import { SavedObjectMigrationContext, SavedObjectMigrationFn } from 'src/core/server'; describe('Lens migrations', () => { describe('7.7.0 missing dimensions in XY', () => { @@ -507,4 +507,88 @@ describe('Lens migrations', () => { expect(result).toMatchSnapshot(); }); }); + + describe('7.11.0 remove suggested priority', () => { + const context = ({ log: { warning: () => {} } } as unknown) as SavedObjectMigrationContext; + + const example = { + type: 'lens', + attributes: { + state: { + datasourceStates: { + indexpattern: { + currentIndexPatternId: 'ff959d40-b880-11e8-a6d9-e546fe2bba5f', + layers: { + 'bd09dc71-a7e2-42d0-83bd-85df8291f03c': { + indexPatternId: 'ff959d40-b880-11e8-a6d9-e546fe2bba5f', + columns: { + '1d9cc16c-1460-41de-88f8-471932ecbc97': { + label: 'products.created_on', + dataType: 'date', + operationType: 'date_histogram', + sourceField: 'products.created_on', + isBucketed: true, + scale: 'interval', + params: { interval: 'auto' }, + suggestedPriority: 0, + }, + '66115819-8481-4917-a6dc-8ffb10dd02df': { + label: 'Count of records', + dataType: 'number', + operationType: 'count', + suggestedPriority: 1, + isBucketed: false, + scale: 'ratio', + sourceField: 'Records', + }, + }, + columnOrder: [ + '1d9cc16c-1460-41de-88f8-471932ecbc97', + '66115819-8481-4917-a6dc-8ffb10dd02df', + ], + }, + }, + }, + }, + datasourceMetaData: { + filterableIndexPatterns: [ + { id: 'ff959d40-b880-11e8-a6d9-e546fe2bba5f', title: 'kibana_sample_data_ecommerce' }, + ], + }, + visualization: { + legend: { isVisible: true, position: 'right' }, + preferredSeriesType: 'bar_stacked', + layers: [ + { + layerId: 'bd09dc71-a7e2-42d0-83bd-85df8291f03c', + accessors: ['66115819-8481-4917-a6dc-8ffb10dd02df'], + position: 'top', + seriesType: 'bar_stacked', + showGridlines: false, + xAccessor: '1d9cc16c-1460-41de-88f8-471932ecbc97', + }, + ], + }, + query: { query: '', language: 'kuery' }, + filters: [], + }, + title: 'Bar chart', + visualizationType: 'lnsXY', + }, + }; + + it('should remove the suggested priority from all columns', () => { + const result = migrations['7.11.0'](example, context) as ReturnType< + SavedObjectMigrationFn + >; + const resultLayers = result.attributes.state.datasourceStates.indexpattern.layers; + const layersWithSuggestedPriority = Object.values(resultLayers).reduce( + (count, layer) => + count + Object.values(layer.columns).filter((col) => 'suggestedPriority' in col).length, + 0 + ); + + expect(layersWithSuggestedPriority).toEqual(0); + }); + }); }); diff --git a/x-pack/plugins/lens/server/migrations.ts b/x-pack/plugins/lens/server/migrations.ts index fdbfa1e455f60..3ec3abdfd6260 100644 --- a/x-pack/plugins/lens/server/migrations.ts +++ b/x-pack/plugins/lens/server/migrations.ts @@ -31,7 +31,7 @@ interface LensDocShapePre710 { string, { columnOrder: string[]; - columns: Record; + columns: Record>; indexPatternId: string; } >; @@ -43,7 +43,7 @@ interface LensDocShapePre710 { }; } -interface LensDocShape { +export interface LensDocShape { id?: string; type?: string; visualizationType: string | null; @@ -56,7 +56,7 @@ interface LensDocShape { string, { columnOrder: string[]; - columns: Record; + columns: Record>; } >; }; @@ -310,10 +310,34 @@ const extractReferences: SavedObjectMigrationFn = (doc) => { + const newDoc = cloneDeep(doc); + const datasourceLayers = newDoc.attributes.state.datasourceStates.indexpattern.layers || {}; + newDoc.attributes.state.datasourceStates.indexpattern.layers = Object.fromEntries( + Object.entries(datasourceLayers).map(([layerId, layer]) => { + return [ + layerId, + { + ...layer, + columns: Object.fromEntries( + Object.entries(layer.columns).map(([columnId, column]) => { + const copy = { ...column }; + delete copy.suggestedPriority; + return [columnId, copy]; + }) + ), + }, + ]; + }) + ); + return newDoc; +}; + export const migrations: SavedObjectMigrationMap = { '7.7.0': removeInvalidAccessors, // The order of these migrations matter, since the timefield migration relies on the aggConfigs // sitting directly on the esaggs as an argument and not a nested function (which lens_auto_date was). '7.8.0': (doc, context) => addTimeFieldToEsaggs(removeLensAutoDate(doc, context), context), '7.10.0': extractReferences, + '7.11.0': removeSuggestedPriority, }; From 8842e9b7a96640ea626f90ea7201233eafb217e5 Mon Sep 17 00:00:00 2001 From: Liza Katz Date: Tue, 10 Nov 2020 20:50:09 +0200 Subject: [PATCH 31/80] [Autocomplete] Support useTimeFilter option (#81515) * pass timefilter to autocomplete * ignoreTimeRange advanced setting * Show all results in filter bar autocomplete * Round timerange to minute for autocomplete memoization * Change useTimeFilter param name Update autocomplete tests and docs * Fix maps test useTimeFilter in uptime * docs * useTimeRange in apm * remove date validation * Update src/plugins/data/common/constants.ts Co-authored-by: Lukas Olson * docs Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Lukas Olson --- ...ns-data-public.querysuggestiongetfnargs.md | 1 + ...c.querysuggestiongetfnargs.usetimerange.md | 11 +++++ ...-plugin-plugins-data-public.ui_settings.md | 1 + ...-plugin-plugins-data-server.ui_settings.md | 1 + src/plugins/data/common/constants.ts | 1 + .../providers/query_suggestion_provider.ts | 1 + .../value_suggestion_provider.test.ts | 49 +++++++++++++++++++ .../providers/value_suggestion_provider.ts | 34 ++++++++++--- src/plugins/data/public/public.api.md | 3 ++ .../public/query/timefilter/timefilter.ts | 11 +++-- .../filter_editor/phrase_suggestor.tsx | 2 + .../autocomplete/value_suggestions_route.ts | 10 ++-- src/plugins/data/server/server.api.md | 1 + src/plugins/data/server/ui_settings.ts | 12 +++++ .../shared/KueryBar/get_bool_filter.ts | 18 +------ .../components/shared/KueryBar/index.tsx | 1 + .../providers/kql_query_suggestion/value.ts | 3 +- .../overview/kuery_bar/kuery_bar.tsx | 13 +---- .../apps/discover/value_suggestions.ts | 3 +- .../functional/apps/maps/vector_styling.js | 6 ++- 20 files changed, 136 insertions(+), 46 deletions(-) create mode 100644 docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.usetimerange.md diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.md index 96e43ca836891..de6f4563b678a 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.md @@ -23,4 +23,5 @@ export interface QuerySuggestionGetFnArgs | [selectionEnd](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.selectionend.md) | number | | | [selectionStart](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.selectionstart.md) | number | | | [signal](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.signal.md) | AbortSignal | | +| [useTimeRange](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.usetimerange.md) | boolean | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.usetimerange.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.usetimerange.md new file mode 100644 index 0000000000000..a29cddd81d885 --- /dev/null +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.querysuggestiongetfnargs.usetimerange.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [QuerySuggestionGetFnArgs](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.md) > [useTimeRange](./kibana-plugin-plugins-data-public.querysuggestiongetfnargs.usetimerange.md) + +## QuerySuggestionGetFnArgs.useTimeRange property + +Signature: + +```typescript +useTimeRange?: boolean; +``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.ui_settings.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.ui_settings.md index 6ed20beb396f1..9a0c37c8edd38 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.ui_settings.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.ui_settings.md @@ -37,5 +37,6 @@ UI_SETTINGS: { readonly INDEXPATTERN_PLACEHOLDER: "indexPattern:placeholder"; readonly FILTERS_PINNED_BY_DEFAULT: "filters:pinnedByDefault"; readonly FILTERS_EDITOR_SUGGEST_VALUES: "filterEditor:suggestValues"; + readonly AUTOCOMPLETE_USE_TIMERANGE: "autocomplete:useTimeRange"; } ``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ui_settings.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ui_settings.md index 2d4ce75b956df..c2edc64f292d2 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ui_settings.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ui_settings.md @@ -37,5 +37,6 @@ UI_SETTINGS: { readonly INDEXPATTERN_PLACEHOLDER: "indexPattern:placeholder"; readonly FILTERS_PINNED_BY_DEFAULT: "filters:pinnedByDefault"; readonly FILTERS_EDITOR_SUGGEST_VALUES: "filterEditor:suggestValues"; + readonly AUTOCOMPLETE_USE_TIMERANGE: "autocomplete:useTimeRange"; } ``` diff --git a/src/plugins/data/common/constants.ts b/src/plugins/data/common/constants.ts index 43120583bd3a4..a70c5eedbf847 100644 --- a/src/plugins/data/common/constants.ts +++ b/src/plugins/data/common/constants.ts @@ -49,4 +49,5 @@ export const UI_SETTINGS = { INDEXPATTERN_PLACEHOLDER: 'indexPattern:placeholder', FILTERS_PINNED_BY_DEFAULT: 'filters:pinnedByDefault', FILTERS_EDITOR_SUGGEST_VALUES: 'filterEditor:suggestValues', + AUTOCOMPLETE_USE_TIMERANGE: 'autocomplete:useTimeRange', } as const; diff --git a/src/plugins/data/public/autocomplete/providers/query_suggestion_provider.ts b/src/plugins/data/public/autocomplete/providers/query_suggestion_provider.ts index 16500ac9e239a..da523e740c3d6 100644 --- a/src/plugins/data/public/autocomplete/providers/query_suggestion_provider.ts +++ b/src/plugins/data/public/autocomplete/providers/query_suggestion_provider.ts @@ -39,6 +39,7 @@ export interface QuerySuggestionGetFnArgs { selectionStart: number; selectionEnd: number; signal?: AbortSignal; + useTimeRange?: boolean; boolFilter?: any; } diff --git a/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.test.ts b/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.test.ts index 6b0c0f07cf6c9..0ef5b7db958e4 100644 --- a/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.test.ts +++ b/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.test.ts @@ -21,6 +21,26 @@ import { stubIndexPattern, stubFields } from '../../stubs'; import { setupValueSuggestionProvider, ValueSuggestionsGetFn } from './value_suggestion_provider'; import { IUiSettingsClient, CoreSetup } from 'kibana/public'; +jest.mock('../../services', () => ({ + getQueryService: () => ({ + timefilter: { + timefilter: { + createFilter: () => { + return { + time: 'fake', + }; + }, + getTime: () => { + return { + to: 'now', + from: 'now-15m', + }; + }, + }, + }, + }), +})); + describe('FieldSuggestions', () => { let getValueSuggestions: ValueSuggestionsGetFn; let http: any; @@ -94,6 +114,7 @@ describe('FieldSuggestions', () => { indexPattern: stubIndexPattern, field, query: '', + useTimeRange: false, }); expect(http.fetch).toHaveBeenCalled(); @@ -107,6 +128,7 @@ describe('FieldSuggestions', () => { indexPattern: stubIndexPattern, field, query: '', + useTimeRange: false, }; await getValueSuggestions(args); @@ -123,6 +145,7 @@ describe('FieldSuggestions', () => { indexPattern: stubIndexPattern, field, query: '', + useTimeRange: false, }; const { now } = Date; @@ -146,50 +169,76 @@ describe('FieldSuggestions', () => { indexPattern: stubIndexPattern, field: fields[0], query: '', + useTimeRange: false, }); await getValueSuggestions({ indexPattern: stubIndexPattern, field: fields[0], query: 'query', + useTimeRange: false, }); await getValueSuggestions({ indexPattern: stubIndexPattern, field: fields[1], query: '', + useTimeRange: false, }); await getValueSuggestions({ indexPattern: stubIndexPattern, field: fields[1], query: 'query', + useTimeRange: false, }); const customIndexPattern = { ...stubIndexPattern, title: 'customIndexPattern', + useTimeRange: false, }; await getValueSuggestions({ indexPattern: customIndexPattern, field: fields[0], query: '', + useTimeRange: false, }); await getValueSuggestions({ indexPattern: customIndexPattern, field: fields[0], query: 'query', + useTimeRange: false, }); await getValueSuggestions({ indexPattern: customIndexPattern, field: fields[1], query: '', + useTimeRange: false, }); await getValueSuggestions({ indexPattern: customIndexPattern, field: fields[1], query: 'query', + useTimeRange: false, }); expect(http.fetch).toHaveBeenCalledTimes(8); }); + + it('should apply timefilter', async () => { + const [field] = stubFields.filter( + ({ type, aggregatable }) => type === 'string' && aggregatable + ); + + await getValueSuggestions({ + indexPattern: stubIndexPattern, + field, + query: '', + useTimeRange: true, + }); + const callParams = http.fetch.mock.calls[0][1]; + + expect(JSON.parse(callParams.body).filters).toHaveLength(1); + expect(http.fetch).toHaveBeenCalled(); + }); }); }); diff --git a/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts b/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts index a6a45a26f06b3..fe9f939a0261d 100644 --- a/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts +++ b/src/plugins/data/public/autocomplete/providers/value_suggestion_provider.ts @@ -17,15 +17,16 @@ * under the License. */ +import dateMath from '@elastic/datemath'; import { memoize } from 'lodash'; import { CoreSetup } from 'src/core/public'; -import { IIndexPattern, IFieldType, UI_SETTINGS } from '../../../common'; +import { IIndexPattern, IFieldType, UI_SETTINGS, buildQueryFromFilters } from '../../../common'; +import { getQueryService } from '../../services'; -function resolver(title: string, field: IFieldType, query: string, boolFilter: any) { +function resolver(title: string, field: IFieldType, query: string, filters: any[]) { // Only cache results for a minute const ttl = Math.floor(Date.now() / 1000 / 60); - - return [ttl, query, title, field.name, JSON.stringify(boolFilter)].join('|'); + return [ttl, query, title, field.name, JSON.stringify(filters)].join('|'); } export type ValueSuggestionsGetFn = (args: ValueSuggestionsGetFnArgs) => Promise; @@ -34,18 +35,31 @@ interface ValueSuggestionsGetFnArgs { indexPattern: IIndexPattern; field: IFieldType; query: string; + useTimeRange?: boolean; boolFilter?: any[]; signal?: AbortSignal; } +const getAutocompleteTimefilter = (indexPattern: IIndexPattern) => { + const { timefilter } = getQueryService().timefilter; + const timeRange = timefilter.getTime(); + + // Use a rounded timerange so that memoizing works properly + const roundedTimerange = { + from: dateMath.parse(timeRange.from)!.startOf('minute').toISOString(), + to: dateMath.parse(timeRange.to)!.endOf('minute').toISOString(), + }; + return timefilter.createFilter(indexPattern, roundedTimerange); +}; + export const getEmptyValueSuggestions = (() => Promise.resolve([])) as ValueSuggestionsGetFn; export const setupValueSuggestionProvider = (core: CoreSetup): ValueSuggestionsGetFn => { const requestSuggestions = memoize( - (index: string, field: IFieldType, query: string, boolFilter: any = [], signal?: AbortSignal) => + (index: string, field: IFieldType, query: string, filters: any = [], signal?: AbortSignal) => core.http.fetch(`/api/kibana/suggestions/values/${index}`, { method: 'POST', - body: JSON.stringify({ query, field: field.name, boolFilter }), + body: JSON.stringify({ query, field: field.name, filters }), signal, }), resolver @@ -55,12 +69,15 @@ export const setupValueSuggestionProvider = (core: CoreSetup): ValueSuggestionsG indexPattern, field, query, + useTimeRange, boolFilter, signal, }: ValueSuggestionsGetFnArgs): Promise => { const shouldSuggestValues = core!.uiSettings.get( UI_SETTINGS.FILTERS_EDITOR_SUGGEST_VALUES ); + useTimeRange = + useTimeRange ?? core!.uiSettings.get(UI_SETTINGS.AUTOCOMPLETE_USE_TIMERANGE); const { title } = indexPattern; if (field.type === 'boolean') { @@ -69,6 +86,9 @@ export const setupValueSuggestionProvider = (core: CoreSetup): ValueSuggestionsG return []; } - return await requestSuggestions(title, field, query, boolFilter, signal); + const timeFilter = useTimeRange ? getAutocompleteTimefilter(indexPattern) : undefined; + const filterQuery = timeFilter ? buildQueryFromFilters([timeFilter], indexPattern).filter : []; + const filters = [...(boolFilter ? boolFilter : []), ...filterQuery]; + return await requestSuggestions(title, field, query, filters, signal); }; }; diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 31b05bd4763a2..643bc46465360 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -1840,6 +1840,8 @@ export interface QuerySuggestionGetFnArgs { selectionStart: number; // (undocumented) signal?: AbortSignal; + // (undocumented) + useTimeRange?: boolean; } // Warning: (ae-missing-release-tag) "QuerySuggestionTypes" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -2309,6 +2311,7 @@ export const UI_SETTINGS: { readonly INDEXPATTERN_PLACEHOLDER: "indexPattern:placeholder"; readonly FILTERS_PINNED_BY_DEFAULT: "filters:pinnedByDefault"; readonly FILTERS_EDITOR_SUGGEST_VALUES: "filterEditor:suggestValues"; + readonly AUTOCOMPLETE_USE_TIMERANGE: "autocomplete:useTimeRange"; }; diff --git a/src/plugins/data/public/query/timefilter/timefilter.ts b/src/plugins/data/public/query/timefilter/timefilter.ts index 49a8c68f6916f..7278ceaaddcce 100644 --- a/src/plugins/data/public/query/timefilter/timefilter.ts +++ b/src/plugins/data/public/query/timefilter/timefilter.ts @@ -24,9 +24,14 @@ import { PublicMethodsOf } from '@kbn/utility-types'; import { areRefreshIntervalsDifferent, areTimeRangesDifferent } from './lib/diff_time_picker_vals'; import { getForceNow } from './lib/get_force_now'; import { TimefilterConfig, InputTimeRange, TimeRangeBounds } from './types'; -import { calculateBounds, getTime, RefreshInterval, TimeRange } from '../../../common'; +import { + calculateBounds, + getTime, + IIndexPattern, + RefreshInterval, + TimeRange, +} from '../../../common'; import { TimeHistoryContract } from './time_history'; -import { IndexPattern } from '../../index_patterns'; // TODO: remove! @@ -170,7 +175,7 @@ export class Timefilter { } }; - public createFilter = (indexPattern: IndexPattern, timeRange?: TimeRange) => { + public createFilter = (indexPattern: IIndexPattern, timeRange?: TimeRange) => { return getTime(indexPattern, timeRange ? timeRange : this._time, { forceNow: this.getForceNow(), }); diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_suggestor.tsx b/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_suggestor.tsx index 719827a98cc63..c420734a43d41 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_suggestor.tsx +++ b/src/plugins/data/public/ui/filter_bar/filter_editor/phrase_suggestor.tsx @@ -85,6 +85,8 @@ export class PhraseSuggestorUI extends React.Com field, query, signal: this.abortController.signal, + // Show all results in filter bar autocomplete + useTimeRange: false, }); this.setState({ suggestions, isLoading: false }); diff --git a/src/plugins/data/server/autocomplete/value_suggestions_route.ts b/src/plugins/data/server/autocomplete/value_suggestions_route.ts index 6a5b7d1d5b414..89ee0995f4140 100644 --- a/src/plugins/data/server/autocomplete/value_suggestions_route.ts +++ b/src/plugins/data/server/autocomplete/value_suggestions_route.ts @@ -45,7 +45,7 @@ export function registerValueSuggestionsRoute( { field: schema.string(), query: schema.string(), - boolFilter: schema.maybe(schema.any()), + filters: schema.maybe(schema.any()), }, { unknowns: 'allow' } ), @@ -53,7 +53,7 @@ export function registerValueSuggestionsRoute( }, async (context, request, response) => { const config = await config$.pipe(first()).toPromise(); - const { field: fieldName, query, boolFilter } = request.body; + const { field: fieldName, query, filters } = request.body; const { index } = request.params; const { client } = context.core.elasticsearch.legacy; const signal = getRequestAbortedSignal(request.events.aborted$); @@ -66,7 +66,7 @@ export function registerValueSuggestionsRoute( const indexPattern = await findIndexPatternById(context.core.savedObjects.client, index); const field = indexPattern && getFieldByName(fieldName, indexPattern); - const body = await getBody(autocompleteSearchOptions, field || fieldName, query, boolFilter); + const body = await getBody(autocompleteSearchOptions, field || fieldName, query, filters); try { const result = await client.callAsCurrentUser('search', { index, body }, { signal }); @@ -88,7 +88,7 @@ async function getBody( { timeout, terminate_after }: Record, field: IFieldType | string, query: string, - boolFilter: Filter[] = [] + filters: Filter[] = [] ) { const isFieldObject = (f: any): f is IFieldType => Boolean(f && f.name); @@ -108,7 +108,7 @@ async function getBody( terminate_after, query: { bool: { - filter: boolFilter, + filter: filters, }, }, aggs: { diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index 131b3e4c39c6b..2984ca336819a 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -1181,6 +1181,7 @@ export const UI_SETTINGS: { readonly INDEXPATTERN_PLACEHOLDER: "indexPattern:placeholder"; readonly FILTERS_PINNED_BY_DEFAULT: "filters:pinnedByDefault"; readonly FILTERS_EDITOR_SUGGEST_VALUES: "filterEditor:suggestValues"; + readonly AUTOCOMPLETE_USE_TIMERANGE: "autocomplete:useTimeRange"; }; // Warning: (ae-missing-release-tag) "usageProvider" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) diff --git a/src/plugins/data/server/ui_settings.ts b/src/plugins/data/server/ui_settings.ts index 763a086d7688d..9393700a0e771 100644 --- a/src/plugins/data/server/ui_settings.ts +++ b/src/plugins/data/server/ui_settings.ts @@ -684,5 +684,17 @@ export function getUiSettings(): Record> { }), schema: schema.boolean(), }, + [UI_SETTINGS.AUTOCOMPLETE_USE_TIMERANGE]: { + name: i18n.translate('data.advancedSettings.autocompleteIgnoreTimerange', { + defaultMessage: 'Use time range', + description: 'Restrict autocomplete results to the current time range', + }), + value: true, + description: i18n.translate('data.advancedSettings.autocompleteIgnoreTimerangeText', { + defaultMessage: + 'Disable this property to get autocomplete suggestions from your full dataset, rather than from the current time range.', + }), + schema: schema.boolean(), + }, }; } diff --git a/x-pack/plugins/apm/public/components/shared/KueryBar/get_bool_filter.ts b/x-pack/plugins/apm/public/components/shared/KueryBar/get_bool_filter.ts index 74d7ace20dae0..f0d12fd16bf7a 100644 --- a/x-pack/plugins/apm/public/components/shared/KueryBar/get_bool_filter.ts +++ b/x-pack/plugins/apm/public/components/shared/KueryBar/get_bool_filter.ts @@ -26,23 +26,7 @@ export function getBoolFilter({ serviceName?: string; urlParams: IUrlParams; }) { - const { start, end } = urlParams; - - if (!start || !end) { - throw new Error('Date range was not defined'); - } - - const boolFilter: ESFilter[] = [ - { - range: { - '@timestamp': { - gte: new Date(start).getTime(), - lte: new Date(end).getTime(), - format: 'epoch_millis', - }, - }, - }, - ]; + const boolFilter: ESFilter[] = []; if (serviceName) { boolFilter.push({ diff --git a/x-pack/plugins/apm/public/components/shared/KueryBar/index.tsx b/x-pack/plugins/apm/public/components/shared/KueryBar/index.tsx index 157e014bee424..dce8e49deec41 100644 --- a/x-pack/plugins/apm/public/components/shared/KueryBar/index.tsx +++ b/x-pack/plugins/apm/public/components/shared/KueryBar/index.tsx @@ -111,6 +111,7 @@ export function KueryBar() { query: inputValue, selectionStart, selectionEnd: selectionStart, + useTimeRange: true, })) || [] ) .filter((suggestion) => !startsWith(suggestion.text, 'span.')) diff --git a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/value.ts b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/value.ts index 441e5a6f775dd..cab3a657b7b6b 100644 --- a/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/value.ts +++ b/x-pack/plugins/data_enhanced/public/autocomplete/providers/kql_query_suggestion/value.ts @@ -27,7 +27,7 @@ const wrapAsSuggestions = (start: number, end: number, query: string, values: st export const setupGetValueSuggestions: KqlQuerySuggestionProvider = () => { return async ( - { indexPatterns, boolFilter, signal }, + { indexPatterns, boolFilter, useTimeRange, signal }, { start, end, prefix, suffix, fieldName, nestedPath } ): Promise => { const fullFieldName = nestedPath ? `${nestedPath}.${fieldName}` : fieldName; @@ -49,6 +49,7 @@ export const setupGetValueSuggestions: KqlQuerySuggestionProvider = () => { field, query, boolFilter, + useTimeRange, signal, }).then((valueSuggestions) => { const quotedValues = valueSuggestions.map((value) => diff --git a/x-pack/plugins/uptime/public/components/overview/kuery_bar/kuery_bar.tsx b/x-pack/plugins/uptime/public/components/overview/kuery_bar/kuery_bar.tsx index 61402008363da..f42f0e7385eb6 100644 --- a/x-pack/plugins/uptime/public/components/overview/kuery_bar/kuery_bar.tsx +++ b/x-pack/plugins/uptime/public/components/overview/kuery_bar/kuery_bar.tsx @@ -67,7 +67,7 @@ export function KueryBar({ let currentRequestCheck: string; const [getUrlParams, updateUrlParams] = useUrlParams(); - const { search: kuery, dateRangeStart, dateRangeEnd } = getUrlParams(); + const { search: kuery } = getUrlParams(); useEffect(() => { updateSearchText(kuery); @@ -105,16 +105,7 @@ export function KueryBar({ query: inputValue, selectionStart: selectionStart || 0, selectionEnd: selectionStart || 0, - boolFilter: [ - { - range: { - '@timestamp': { - gte: dateRangeStart, - lte: dateRangeEnd, - }, - }, - }, - ], + useTimeRange: true, })) || [] ).filter((suggestion: QuerySuggestion) => !suggestion.text.startsWith('span.')); if (currentRequest !== currentRequestCheck) { diff --git a/x-pack/test/functional/apps/discover/value_suggestions.ts b/x-pack/test/functional/apps/discover/value_suggestions.ts index 54720b94172f6..5d75927655228 100644 --- a/x-pack/test/functional/apps/discover/value_suggestions.ts +++ b/x-pack/test/functional/apps/discover/value_suggestions.ts @@ -10,13 +10,14 @@ import { FtrProviderContext } from '../../ftr_provider_context'; export default function ({ getService, getPageObjects }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const queryBar = getService('queryBar'); - const PageObjects = getPageObjects(['common']); + const PageObjects = getPageObjects(['common', 'timePicker']); describe('value suggestions', function describeIndexTests() { before(async function () { await esArchiver.loadIfNeeded('logstash_functional'); await esArchiver.load('dashboard/drilldowns'); await PageObjects.common.navigateToApp('discover'); + await PageObjects.timePicker.setDefaultAbsoluteRange(); }); after(async () => { diff --git a/x-pack/test/functional/apps/maps/vector_styling.js b/x-pack/test/functional/apps/maps/vector_styling.js index e4c5eaf892c76..56a8188c8341b 100644 --- a/x-pack/test/functional/apps/maps/vector_styling.js +++ b/x-pack/test/functional/apps/maps/vector_styling.js @@ -7,13 +7,17 @@ import expect from '@kbn/expect'; export default function ({ getService, getPageObjects }) { - const PageObjects = getPageObjects(['maps']); + const PageObjects = getPageObjects(['maps', 'timePicker']); const security = getService('security'); describe('vector styling', () => { before(async () => { await security.testUser.setRoles(['test_logstash_reader', 'global_maps_all']); await PageObjects.maps.loadSavedMap('document example'); + await PageObjects.timePicker.setAbsoluteRange( + 'Mar 1, 2015 @ 00:00:00.000', + 'Mar 1, 2016 @ 00:00:00.000' + ); }); after(async () => { await PageObjects.maps.refreshAndClearUnsavedChangesWarning(); From c7f085ff0bf22f0b53f5b1268c6b846a05f32954 Mon Sep 17 00:00:00 2001 From: Constance Date: Tue, 10 Nov 2020 10:52:20 -0800 Subject: [PATCH 32/80] [Enterprise Search] Tech debt/cleanup: remove I/E/T Typescript prefixes (#83027) * [All] Remove prefixes on simple self-contained type defs - Types should not be exported - Types should not be used outside each affected file * [All][kea] Remove ts prefixes and unnecessary exports Kea now takes care of type checking for us, so there should virtually never be a need to export our values and actions interfaces going forward * [shared] Remove createHref type prefixes * [shared] Remove breadcrumb prefixes * [shared] Remove telemetry prefixes * [shared] remove types.ts Opionionated change: it was only being used for IFlashMessage, and at this point I think it's more useful to go in one level deeper to grab the type you need * [server] remove route dependencies prefixes * [server] Various type cleanups - plugin.ts - remove unnecessary export - MockRouter - remove prefix for request type, change IMockRouter to match Kibana's IRouter - check_access - remove prefixes - callEnterpriseSearchConfigAPI - remove prefixes - EnterpriseSearchRequestHandler - remove prefixes * [common] Remove InitialAppData prefix + remove unnecessary export from public/plugin.ts * [common] Remove Meta prefixes * [common] Remove configured limits prefixes * [AS] Remove Account and Role prefixes * [AS] Remove Engine prefixes * [AS] Remove credentials prefixes * [AS] Remove log settings prefixes * [WS] Remove account/organization/initial data prefixes * [WS] Remove group(s), user, & content source prefixes + GroupLogic and GroupsLogic refactor - remove unnecessary defs in actions, it's already defined in the Actions interface above and in some cases (e.g. old History param) is causing out of date issues * [WS] Misc type fixes - TSpacerSize -> SpaceSizeTypes - SourcePriority - remove prefixes - IComponentLoader - this isn't used anywhere else and appears to be component props so it probably should live only within component_loader.tsx - Remove recent feed activity prefix * [WS][Opinionated] Move interfaces not used in server/ out of common/ and to public/ --- .../common/types/app_search.ts | 4 +- .../enterprise_search/common/types/index.ts | 28 +++---- .../common/types/workplace_search.ts | 58 ++------------ .../__mocks__/mount_async.mock.tsx | 4 +- .../applications/app_search/app_logic.ts | 18 ++--- .../form_components/key_read_write_access.tsx | 6 +- .../credentials_flyout/header.test.tsx | 4 +- .../credentials_list.test.tsx | 6 +- .../credentials_list/credentials_list.tsx | 20 ++--- .../credentials/credentials_list/key.tsx | 4 +- .../credentials/credentials_logic.ts | 40 +++++----- .../components/credentials/types.ts | 10 +-- .../credentials/utils/api_token_sort.test.ts | 4 +- .../credentials/utils/api_token_sort.ts | 4 +- .../utils/get_engines_display_text.test.tsx | 4 +- .../utils/get_engines_display_text.tsx | 4 +- .../utils/get_mode_display_text.test.ts | 4 +- .../utils/get_mode_display_text.ts | 4 +- .../components/engines/engines_overview.tsx | 8 +- .../components/engines/engines_table.tsx | 18 ++--- .../log_retention/log_retention_logic.test.ts | 30 ++++---- .../log_retention/log_retention_logic.ts | 26 +++---- .../settings/log_retention/types.ts | 26 +++---- .../utils/convert_log_retention.ts | 30 ++++---- .../public/applications/app_search/index.tsx | 10 +-- .../public/applications/app_search/types.ts | 4 +- .../app_search/utils/role/index.ts | 22 +++--- .../components/product_card/product_card.tsx | 4 +- .../product_selector/product_selector.tsx | 4 +- .../applications/enterprise_search/index.tsx | 4 +- .../public/applications/index.tsx | 4 +- .../flash_messages/flash_messages_logic.ts | 6 +- .../flash_messages/handle_api_errors.ts | 9 +-- .../shared/flash_messages/index.ts | 8 +- .../shared/hidden_text/hidden_text.tsx | 8 +- .../applications/shared/http/http_logic.ts | 10 +-- .../public/applications/shared/http/index.ts | 2 +- .../shared/kibana/kibana_logic.ts | 14 ++-- .../kibana_chrome/generate_breadcrumbs.ts | 16 ++-- .../shared/kibana_chrome/generate_title.ts | 10 +-- .../shared/kibana_chrome/set_chrome.tsx | 12 +-- .../applications/shared/layout/layout.tsx | 4 +- .../applications/shared/layout/side_nav.tsx | 12 +-- .../shared/licensing/licensing_logic.ts | 10 +-- .../react_router_helpers/create_href.ts | 8 +- .../shared/react_router_helpers/eui_link.tsx | 16 ++-- .../shared/react_router_helpers/index.ts | 2 +- .../react_router_helpers/link_events.ts | 10 +-- .../shared/setup_guide/setup_guide.tsx | 4 +- .../shared/table_header/table_header.tsx | 4 +- .../shared/telemetry/send_telemetry.tsx | 11 ++- .../shared/telemetry/telemetry_logic.ts | 24 +++--- .../shared/truncate/truncated_content.tsx | 4 +- .../public/applications/shared/types.ts | 7 -- .../workplace_search/app_logic.ts | 20 ++--- .../components/shared/api_key/api_key.tsx | 4 +- .../component_loader/component_loader.tsx | 6 +- .../content_section/content_section.tsx | 8 +- .../credential_item/credential_item.tsx | 4 +- .../source_config_fields.tsx | 4 +- .../shared/source_icon/source_icon.tsx | 4 +- .../shared/source_row/source_row.tsx | 8 +- .../shared/sources_table/sources_table.tsx | 8 +- .../table_pagination_bar.tsx | 4 +- .../components/shared/user_icon/user_icon.tsx | 4 +- .../components/shared/user_row/user_row.tsx | 8 +- .../view_content_header.tsx | 4 +- .../applications/workplace_search/index.tsx | 6 +- .../applications/workplace_search/types.ts | 52 +++++++++++-- .../groups/__mocks__/group_logic.mock.ts | 12 ++- .../groups/__mocks__/groups_logic.mock.ts | 12 ++- .../components/filterable_users_list.test.tsx | 4 +- .../components/filterable_users_list.tsx | 10 +-- .../components/filterable_users_popover.tsx | 8 +- .../groups/components/group_manager_modal.tsx | 8 +- .../views/groups/components/group_row.tsx | 4 +- .../components/group_row_sources_dropdown.tsx | 8 +- .../components/group_row_users_dropdown.tsx | 4 +- .../group_source_prioritization.tsx | 4 +- .../groups/components/group_sources.test.tsx | 4 +- .../views/groups/components/group_sources.tsx | 8 +- .../groups/components/group_users.test.tsx | 4 +- .../views/groups/components/group_users.tsx | 8 +- .../components/group_users_table.test.tsx | 4 +- .../groups/components/group_users_table.tsx | 4 +- .../groups/components/source_option_item.tsx | 8 +- .../views/groups/components/sources_list.tsx | 8 +- .../groups/components/user_option_item.tsx | 8 +- .../views/groups/group_logic.ts | 75 +++++++++---------- .../views/groups/groups_logic.ts | 72 +++++++++--------- .../overview/__mocks__/overview_logic.mock.ts | 4 +- .../views/overview/onboarding_card.tsx | 4 +- .../views/overview/overview_logic.ts | 14 ++-- .../views/overview/recent_activity.tsx | 6 +- .../views/overview/statistic_card.tsx | 4 +- .../enterprise_search/public/plugin.ts | 7 +- .../server/__mocks__/router.mock.ts | 14 ++-- .../server/collectors/app_search/telemetry.ts | 8 +- .../collectors/enterprise_search/telemetry.ts | 8 +- .../server/collectors/lib/telemetry.ts | 4 +- .../collectors/workplace_search/telemetry.ts | 8 +- .../server/lib/check_access.ts | 6 +- .../lib/enterprise_search_config_api.ts | 12 +-- .../lib/enterprise_search_request_handler.ts | 12 +-- .../enterprise_search/server/plugin.ts | 4 +- .../server/routes/app_search/credentials.ts | 4 +- .../server/routes/app_search/engines.ts | 8 +- .../server/routes/app_search/index.ts | 4 +- .../server/routes/app_search/settings.ts | 4 +- .../routes/enterprise_search/config_data.ts | 4 +- .../routes/enterprise_search/telemetry.ts | 8 +- .../server/routes/workplace_search/groups.ts | 19 ++--- .../server/routes/workplace_search/index.ts | 4 +- .../routes/workplace_search/overview.ts | 4 +- 114 files changed, 597 insertions(+), 625 deletions(-) delete mode 100644 x-pack/plugins/enterprise_search/public/applications/shared/types.ts diff --git a/x-pack/plugins/enterprise_search/common/types/app_search.ts b/x-pack/plugins/enterprise_search/common/types/app_search.ts index 203b77834bc15..9f754412ec730 100644 --- a/x-pack/plugins/enterprise_search/common/types/app_search.ts +++ b/x-pack/plugins/enterprise_search/common/types/app_search.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -export interface IAccount { +export interface Account { accountId: string; onboardingComplete: boolean; role: { @@ -21,7 +21,7 @@ export interface IAccount { }; } -export interface IConfiguredLimits { +export interface ConfiguredLimits { engine: { maxDocumentByteSize: number; maxEnginesPerMetaEngine: number; diff --git a/x-pack/plugins/enterprise_search/common/types/index.ts b/x-pack/plugins/enterprise_search/common/types/index.ts index 1006d39138759..39d9aa8607bc2 100644 --- a/x-pack/plugins/enterprise_search/common/types/index.ts +++ b/x-pack/plugins/enterprise_search/common/types/index.ts @@ -5,39 +5,39 @@ */ import { - IAccount as IAppSearchAccount, - IConfiguredLimits as IAppSearchConfiguredLimits, + Account as AppSearchAccount, + ConfiguredLimits as AppSearchConfiguredLimits, } from './app_search'; import { - IWorkplaceSearchInitialData, - IConfiguredLimits as IWorkplaceSearchConfiguredLimits, + WorkplaceSearchInitialData, + ConfiguredLimits as WorkplaceSearchConfiguredLimits, } from './workplace_search'; -export interface IInitialAppData { +export interface InitialAppData { readOnlyMode?: boolean; ilmEnabled?: boolean; isFederatedAuth?: boolean; - configuredLimits?: IConfiguredLimits; + configuredLimits?: ConfiguredLimits; access?: { hasAppSearchAccess: boolean; hasWorkplaceSearchAccess: boolean; }; - appSearch?: IAppSearchAccount; - workplaceSearch?: IWorkplaceSearchInitialData; + appSearch?: AppSearchAccount; + workplaceSearch?: WorkplaceSearchInitialData; } -export interface IConfiguredLimits { - appSearch: IAppSearchConfiguredLimits; - workplaceSearch: IWorkplaceSearchConfiguredLimits; +export interface ConfiguredLimits { + appSearch: AppSearchConfiguredLimits; + workplaceSearch: WorkplaceSearchConfiguredLimits; } -export interface IMetaPage { +export interface MetaPage { current: number; size: number; total_pages: number; total_results: number; } -export interface IMeta { - page: IMetaPage; +export interface Meta { + page: MetaPage; } diff --git a/x-pack/plugins/enterprise_search/common/types/workplace_search.ts b/x-pack/plugins/enterprise_search/common/types/workplace_search.ts index 886597fcd9891..883cc6939b4bc 100644 --- a/x-pack/plugins/enterprise_search/common/types/workplace_search.ts +++ b/x-pack/plugins/enterprise_search/common/types/workplace_search.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -export interface IAccount { +export interface Account { id: string; groups: string[]; isAdmin: boolean; @@ -14,65 +14,19 @@ export interface IAccount { viewedOnboardingPage: boolean; } -export interface IOrganization { +export interface Organization { name: string; defaultOrgName: string; } -export interface IWorkplaceSearchInitialData { - organization: IOrganization; - account: IAccount; +export interface WorkplaceSearchInitialData { + organization: Organization; + account: Account; } -export interface IConfiguredLimits { +export interface ConfiguredLimits { customApiSource: { maxDocumentByteSize: number; totalFields: number; }; } - -export interface IGroup { - id: string; - name: string; - createdAt: string; - updatedAt: string; - contentSources: IContentSource[]; - users: IUser[]; - usersCount: number; - color?: string; -} - -export interface IGroupDetails extends IGroup { - contentSources: IContentSourceDetails[]; - canEditGroup: boolean; - canDeleteGroup: boolean; -} - -export interface IUser { - id: string; - name: string | null; - initials: string; - pictureUrl: string | null; - color: string; - email: string; - role?: string; - groupIds: string[]; -} - -export interface IContentSource { - id: string; - serviceType: string; - name: string; -} - -export interface IContentSourceDetails extends IContentSource { - status: string; - statusMessage: string; - documentCount: string; - isFederatedSource: boolean; - searchable: boolean; - supportedByLicense: boolean; - errorReason: number; - allowsReauth: boolean; - boost: number; -} diff --git a/x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_async.mock.tsx b/x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_async.mock.tsx index a33e116c7ca72..a3d817e1da904 100644 --- a/x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_async.mock.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_async.mock.tsx @@ -20,13 +20,13 @@ import { mountWithIntl } from './'; * const wrapper = mountAsync(); */ -interface IOptions { +interface Options { i18n?: boolean; } export const mountAsync = async ( children: React.ReactElement, - options: IOptions + options: Options ): Promise => { let wrapper: ReactWrapper | undefined; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/app_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/app_logic.ts index 932e84af45c2b..2b475073c6ea5 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/app_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/app_logic.ts @@ -6,24 +6,24 @@ import { kea, MakeLogicType } from 'kea'; -import { IInitialAppData } from '../../../common/types'; -import { IConfiguredLimits, IAccount, IRole } from './types'; +import { InitialAppData } from '../../../common/types'; +import { ConfiguredLimits, Account, Role } from './types'; import { getRoleAbilities } from './utils/role'; -export interface IAppValues { +interface AppValues { hasInitialized: boolean; ilmEnabled: boolean; - configuredLimits: Partial; - account: Partial; - myRole: Partial; + configuredLimits: Partial; + account: Partial; + myRole: Partial; } -export interface IAppActions { - initializeAppData(props: IInitialAppData): Required; +interface AppActions { + initializeAppData(props: InitialAppData): Required; setOnboardingComplete(): boolean; } -export const AppLogic = kea>({ +export const AppLogic = kea>({ path: ['enterprise_search', 'app_search', 'app_logic'], actions: { initializeAppData: (props) => props, diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_flyout/form_components/key_read_write_access.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_flyout/form_components/key_read_write_access.tsx index a02b00b6ad377..d96c57b3c8bc3 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_flyout/form_components/key_read_write_access.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_flyout/form_components/key_read_write_access.tsx @@ -10,7 +10,7 @@ import { EuiCheckbox, EuiText, EuiTitle, EuiSpacer, EuiPanel } from '@elastic/eu import { i18n } from '@kbn/i18n'; import { CredentialsLogic } from '../../credentials_logic'; -import { ITokenReadWrite } from '../../types'; +import { TokenReadWrite } from '../../types'; export const FormKeyReadWriteAccess: React.FC = () => { const { setTokenReadWrite } = useActions(CredentialsLogic); @@ -37,7 +37,7 @@ export const FormKeyReadWriteAccess: React.FC = () => { name="read" id="read" checked={activeApiToken.read} - onChange={(e) => setTokenReadWrite(e.target as ITokenReadWrite)} + onChange={(e) => setTokenReadWrite(e.target as TokenReadWrite)} label={i18n.translate( 'xpack.enterpriseSearch.appSearch.credentials.formReadWrite.readLabel', { defaultMessage: 'Read Access' } @@ -47,7 +47,7 @@ export const FormKeyReadWriteAccess: React.FC = () => { name="write" id="write" checked={activeApiToken.write} - onChange={(e) => setTokenReadWrite(e.target as ITokenReadWrite)} + onChange={(e) => setTokenReadWrite(e.target as TokenReadWrite)} label={i18n.translate( 'xpack.enterpriseSearch.appSearch.credentials.formReadWrite.writeLabel', { defaultMessage: 'Write Access' } diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_flyout/header.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_flyout/header.test.tsx index a8d9505136faa..803789ebee568 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_flyout/header.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_flyout/header.test.tsx @@ -11,12 +11,12 @@ import { shallow } from 'enzyme'; import { EuiFlyoutHeader } from '@elastic/eui'; import { ApiTokenTypes } from '../constants'; -import { IApiToken } from '../types'; +import { ApiToken } from '../types'; import { CredentialsFlyoutHeader } from './header'; describe('CredentialsFlyoutHeader', () => { - const apiToken: IApiToken = { + const apiToken: ApiToken = { name: '', type: ApiTokenTypes.Private, read: true, diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_list/credentials_list.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_list/credentials_list.test.tsx index 97d29b9333f4b..4f5ded0a3ccc1 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_list/credentials_list.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_list/credentials_list.test.tsx @@ -10,7 +10,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import { EuiBasicTable, EuiCopy, EuiEmptyPrompt } from '@elastic/eui'; -import { IApiToken } from '../types'; +import { ApiToken } from '../types'; import { ApiTokenTypes } from '../constants'; import { HiddenText } from '../../../../shared/hidden_text'; @@ -18,7 +18,7 @@ import { Key } from './key'; import { CredentialsList } from './credentials_list'; describe('Credentials', () => { - const apiToken: IApiToken = { + const apiToken: ApiToken = { name: '', type: ApiTokenTypes.Private, read: true, @@ -77,7 +77,7 @@ describe('Credentials', () => { }); const wrapper = shallow(); const { items } = wrapper.find(EuiBasicTable).props(); - expect(items.map((i: IApiToken) => i.id)).toEqual([undefined, 1, 2]); + expect(items.map((i: ApiToken) => i.id)).toEqual([undefined, 1, 2]); }); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_list/credentials_list.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_list/credentials_list.tsx index f9752dca582e1..9240bade4975e 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_list/credentials_list.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_list/credentials_list.tsx @@ -14,7 +14,7 @@ import { i18n } from '@kbn/i18n'; import { CredentialsLogic } from '../credentials_logic'; import { Key } from './key'; import { HiddenText } from '../../../../shared/hidden_text'; -import { IApiToken } from '../types'; +import { ApiToken } from '../types'; import { TOKEN_TYPE_DISPLAY_NAMES } from '../constants'; import { apiTokenSort } from '../utils/api_token_sort'; import { getModeDisplayText, getEnginesDisplayText } from '../utils'; @@ -26,21 +26,21 @@ export const CredentialsList: React.FC = () => { const items = useMemo(() => apiTokens.slice().sort(apiTokenSort), [apiTokens]); - const columns: Array> = [ + const columns: Array> = [ { name: 'Name', width: '12%', - render: (token: IApiToken) => token.name, + render: (token: ApiToken) => token.name, }, { name: 'Type', width: '15%', - render: (token: IApiToken) => TOKEN_TYPE_DISPLAY_NAMES[token.type], + render: (token: ApiToken) => TOKEN_TYPE_DISPLAY_NAMES[token.type], }, { name: 'Key', width: '36%', - render: (token: IApiToken) => { + render: (token: ApiToken) => { const { key } = token; if (!key) return null; return ( @@ -64,12 +64,12 @@ export const CredentialsList: React.FC = () => { { name: 'Modes', width: '10%', - render: (token: IApiToken) => getModeDisplayText(token), + render: (token: ApiToken) => getModeDisplayText(token), }, { name: 'Engines', width: '18%', - render: (token: IApiToken) => getEnginesDisplayText(token), + render: (token: ApiToken) => getEnginesDisplayText(token), }, { actions: [ @@ -83,7 +83,7 @@ export const CredentialsList: React.FC = () => { type: 'icon', icon: 'pencil', color: 'primary', - onClick: (token: IApiToken) => showCredentialsForm(token), + onClick: (token: ApiToken) => showCredentialsForm(token), }, { name: i18n.translate('xpack.enterpriseSearch.actions.delete', { @@ -95,7 +95,7 @@ export const CredentialsList: React.FC = () => { type: 'icon', icon: 'trash', color: 'danger', - onClick: (token: IApiToken) => deleteApiKey(token.name), + onClick: (token: ApiToken) => deleteApiKey(token.name), }, ], }, @@ -108,7 +108,7 @@ export const CredentialsList: React.FC = () => { hidePerPageOptions: true, }; - const onTableChange = ({ page }: CriteriaWithPagination) => { + const onTableChange = ({ page }: CriteriaWithPagination) => { const { index: current } = page; fetchCredentials(current + 1); }; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_list/key.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_list/key.tsx index 5c0c24ec733a4..fa2d124cbccdf 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_list/key.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_list/key.tsx @@ -8,14 +8,14 @@ import React from 'react'; import { EuiButtonIcon } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -interface IProps { +interface Props { copy: () => void; toggleIsHidden: () => void; isHidden: boolean; text: React.ReactNode; } -export const Key: React.FC = ({ copy, toggleIsHidden, isHidden, text }) => { +export const Key: React.FC = ({ copy, toggleIsHidden, isHidden, text }) => { const hideIcon = isHidden ? 'eye' : 'eyeClosed'; const hideIconLabel = isHidden ? i18n.translate('xpack.enterpriseSearch.appSearch.credentials.showApiKey', { diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_logic.ts index 7b8b864b3a317..166cbae9a4512 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_logic.ts @@ -17,11 +17,11 @@ import { } from '../../../shared/flash_messages'; import { AppLogic } from '../../app_logic'; -import { IMeta } from '../../../../../common/types'; -import { IEngine } from '../../types'; -import { IApiToken, ICredentialsDetails, ITokenReadWrite } from './types'; +import { Meta } from '../../../../../common/types'; +import { Engine } from '../../types'; +import { ApiToken, CredentialsDetails, TokenReadWrite } from './types'; -export const defaultApiToken: IApiToken = { +export const defaultApiToken: ApiToken = { name: '', type: ApiTokenTypes.Private, read: true, @@ -29,21 +29,21 @@ export const defaultApiToken: IApiToken = { access_all_engines: true, }; -interface ICredentialsLogicActions { +interface CredentialsLogicActions { addEngineName(engineName: string): string; onApiKeyDelete(tokenName: string): string; - onApiTokenCreateSuccess(apiToken: IApiToken): IApiToken; + onApiTokenCreateSuccess(apiToken: ApiToken): ApiToken; onApiTokenError(formErrors: string[]): string[]; - onApiTokenUpdateSuccess(apiToken: IApiToken): IApiToken; + onApiTokenUpdateSuccess(apiToken: ApiToken): ApiToken; removeEngineName(engineName: string): string; setAccessAllEngines(accessAll: boolean): boolean; - setCredentialsData(meta: IMeta, apiTokens: IApiToken[]): { meta: IMeta; apiTokens: IApiToken[] }; - setCredentialsDetails(details: ICredentialsDetails): ICredentialsDetails; + setCredentialsData(meta: Meta, apiTokens: ApiToken[]): { meta: Meta; apiTokens: ApiToken[] }; + setCredentialsDetails(details: CredentialsDetails): CredentialsDetails; setNameInputBlurred(isBlurred: boolean): boolean; - setTokenReadWrite(tokenReadWrite: ITokenReadWrite): ITokenReadWrite; + setTokenReadWrite(tokenReadWrite: TokenReadWrite): TokenReadWrite; setTokenName(name: string): string; setTokenType(tokenType: string): string; - showCredentialsForm(apiToken?: IApiToken): IApiToken; + showCredentialsForm(apiToken?: ApiToken): ApiToken; hideCredentialsForm(): { value: boolean }; resetCredentials(): { value: boolean }; initializeCredentialsData(): { value: boolean }; @@ -54,25 +54,25 @@ interface ICredentialsLogicActions { onEngineSelect(engineName: string): string; } -interface ICredentialsLogicValues { - activeApiToken: IApiToken; +interface CredentialsLogicValues { + activeApiToken: ApiToken; activeApiTokenExists: boolean; activeApiTokenRawName: string; - apiTokens: IApiToken[]; + apiTokens: ApiToken[]; dataLoading: boolean; - engines: IEngine[]; + engines: Engine[]; formErrors: string[]; isCredentialsDataComplete: boolean; isCredentialsDetailsComplete: boolean; fullEngineAccessChecked: boolean; - meta: Partial; + meta: Partial; nameInputBlurred: boolean; shouldShowCredentialsForm: boolean; } -export const CredentialsLogic = kea< - MakeLogicType ->({ +type CredentialsLogicType = MakeLogicType; // If we leave this inline, Prettier does some horrifying indenting nonsense :/ + +export const CredentialsLogic = kea({ path: ['enterprise_search', 'app_search', 'credentials_logic'], actions: () => ({ addEngineName: (engineName) => engineName, @@ -267,7 +267,7 @@ export const CredentialsLogic = kea< onApiTokenChange: async () => { const { id, name, engines, type, read, write } = values.activeApiToken; - const data: IApiToken = { + const data: ApiToken = { name, type, }; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/types.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/types.ts index 9ca4d086d55c8..23f78b44c0db5 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/types.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/types.ts @@ -4,14 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { IEngine } from '../../types'; +import { Engine } from '../../types'; import { ApiTokenTypes } from './constants'; -export interface ICredentialsDetails { - engines: IEngine[]; +export interface CredentialsDetails { + engines: Engine[]; } -export interface IApiToken { +export interface ApiToken { access_all_engines?: boolean; key?: string; engines?: string[]; @@ -22,7 +22,7 @@ export interface IApiToken { write?: boolean; } -export interface ITokenReadWrite { +export interface TokenReadWrite { name: 'read' | 'write'; checked: boolean; } diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/api_token_sort.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/api_token_sort.test.ts index 84818322b3570..2287125bb5eb8 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/api_token_sort.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/api_token_sort.test.ts @@ -7,10 +7,10 @@ import { apiTokenSort } from '.'; import { ApiTokenTypes } from '../constants'; -import { IApiToken } from '../types'; +import { ApiToken } from '../types'; describe('apiTokenSort', () => { - const apiToken: IApiToken = { + const apiToken: ApiToken = { name: '', type: ApiTokenTypes.Private, read: true, diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/api_token_sort.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/api_token_sort.ts index 80a46f30e0930..b9fb501ccabe2 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/api_token_sort.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/api_token_sort.ts @@ -4,9 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import { IApiToken } from '../types'; +import { ApiToken } from '../types'; -export const apiTokenSort = (apiTokenA: IApiToken, apiTokenB: IApiToken): number => { +export const apiTokenSort = (apiTokenA: ApiToken, apiTokenB: ApiToken): number => { if (!apiTokenA.id) { return -1; } diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_engines_display_text.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_engines_display_text.test.tsx index b06ed63f8616c..bee19a44facd3 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_engines_display_text.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_engines_display_text.test.tsx @@ -8,10 +8,10 @@ import React from 'react'; import { shallow } from 'enzyme'; import { getEnginesDisplayText } from './get_engines_display_text'; -import { IApiToken } from '../types'; +import { ApiToken } from '../types'; import { ApiTokenTypes } from '../constants'; -const apiToken: IApiToken = { +const apiToken: ApiToken = { name: '', type: ApiTokenTypes.Private, read: true, diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_engines_display_text.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_engines_display_text.tsx index 1b216c46307db..fb23551302f3b 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_engines_display_text.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_engines_display_text.tsx @@ -6,9 +6,9 @@ import React from 'react'; import { ApiTokenTypes, ALL } from '../constants'; -import { IApiToken } from '../types'; +import { ApiToken } from '../types'; -export const getEnginesDisplayText = (apiToken: IApiToken): JSX.Element | string => { +export const getEnginesDisplayText = (apiToken: ApiToken): JSX.Element | string => { const { type, access_all_engines: accessAll, engines = [] } = apiToken; if (type === ApiTokenTypes.Admin) { return '--'; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_mode_display_text.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_mode_display_text.test.ts index b2083f22c8e1c..46b4c9b2c786c 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_mode_display_text.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_mode_display_text.test.ts @@ -5,11 +5,11 @@ */ import { ApiTokenTypes } from '../constants'; -import { IApiToken } from '../types'; +import { ApiToken } from '../types'; import { getModeDisplayText } from './get_mode_display_text'; -const apiToken: IApiToken = { +const apiToken: ApiToken = { name: '', type: ApiTokenTypes.Private, read: true, diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_mode_display_text.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_mode_display_text.ts index 9c8758d83882d..b150aa2cfc3be 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_mode_display_text.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/utils/get_mode_display_text.ts @@ -5,9 +5,9 @@ */ import { ApiTokenTypes, READ_ONLY, READ_WRITE, SEARCH_DISPLAY, WRITE_ONLY } from '../constants'; -import { IApiToken } from '../types'; +import { ApiToken } from '../types'; -export const getModeDisplayText = (apiToken: IApiToken): string => { +export const getModeDisplayText = (apiToken: ApiToken): string => { const { read = false, write = false, type } = apiToken; switch (type) { diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_overview.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_overview.tsx index 559fef695d63b..0381c3806fec7 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_overview.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_overview.tsx @@ -28,11 +28,11 @@ import { EnginesTable } from './engines_table'; import './engines_overview.scss'; -interface IGetEnginesParams { +interface GetEnginesParams { type: string; pageIndex: number; } -interface ISetEnginesCallbacks { +interface SetEnginesCallbacks { setResults: React.Dispatch>; setResultsTotal: React.Dispatch>; } @@ -49,12 +49,12 @@ export const EnginesOverview: React.FC = () => { const [metaEnginesPage, setMetaEnginesPage] = useState(1); const [metaEnginesTotal, setMetaEnginesTotal] = useState(0); - const getEnginesData = async ({ type, pageIndex }: IGetEnginesParams) => { + const getEnginesData = async ({ type, pageIndex }: GetEnginesParams) => { return await http.get('/api/app_search/engines', { query: { type, pageIndex }, }); }; - const setEnginesData = async (params: IGetEnginesParams, callbacks: ISetEnginesCallbacks) => { + const setEnginesData = async (params: GetEnginesParams, callbacks: SetEnginesCallbacks) => { const response = await getEnginesData(params); callbacks.setResults(response.results); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_table.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_table.tsx index a9cf64b3dffda..9591bbda1f7c2 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_table.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_table.tsx @@ -16,28 +16,28 @@ import { getEngineRoute } from '../../routes'; import { ENGINES_PAGE_SIZE } from '../../../../../common/constants'; -interface IEnginesTableData { +interface EnginesTableData { name: string; created_at: string; document_count: number; field_count: number; } -interface IEnginesTablePagination { +interface EnginesTablePagination { totalEngines: number; pageIndex: number; onPaginate(pageIndex: number): void; } -interface IEnginesTableProps { - data: IEnginesTableData[]; - pagination: IEnginesTablePagination; +interface EnginesTableProps { + data: EnginesTableData[]; + pagination: EnginesTablePagination; } -interface IOnChange { +interface OnChange { page: { index: number; }; } -export const EnginesTable: React.FC = ({ +export const EnginesTable: React.FC = ({ data, pagination: { totalEngines, pageIndex, onPaginate }, }) => { @@ -52,7 +52,7 @@ export const EnginesTable: React.FC = ({ }), }); - const columns: Array> = [ + const columns: Array> = [ { field: 'name', name: i18n.translate('xpack.enterpriseSearch.appSearch.enginesOverview.table.column.name', { @@ -144,7 +144,7 @@ export const EnginesTable: React.FC = ({ totalItemCount: totalEngines, hidePerPageOptions: true, }} - onChange={({ page }: IOnChange) => { + onChange={({ page }: OnChange) => { const { index } = page; onPaginate(index + 1); // Note on paging - App Search's API pages start at 1, EuiBasicTables' pages start at 0 }} diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_logic.test.ts index 367c7b085123f..c86d7e3e915e2 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_logic.test.ts @@ -17,7 +17,7 @@ jest.mock('../../../../shared/flash_messages', () => ({ })); import { flashAPIErrors } from '../../../../shared/flash_messages'; -import { ELogRetentionOptions } from './types'; +import { LogRetentionOptions } from './types'; import { LogRetentionLogic } from './log_retention_logic'; describe('LogRetentionLogic', () => { @@ -87,11 +87,11 @@ describe('LogRetentionLogic', () => { it('should be set to the provided value', () => { mount(); - LogRetentionLogic.actions.setOpenedModal(ELogRetentionOptions.Analytics); + LogRetentionLogic.actions.setOpenedModal(LogRetentionOptions.Analytics); expect(LogRetentionLogic.values).toEqual({ ...DEFAULT_VALUES, - openedModal: ELogRetentionOptions.Analytics, + openedModal: LogRetentionOptions.Analytics, }); }); }); @@ -194,10 +194,10 @@ describe('LogRetentionLogic', () => { describe('openedModal', () => { it('should be reset to null', () => { mount({ - openedModal: ELogRetentionOptions.Analytics, + openedModal: LogRetentionOptions.Analytics, }); - LogRetentionLogic.actions.saveLogRetention(ELogRetentionOptions.Analytics, true); + LogRetentionLogic.actions.saveLogRetention(LogRetentionOptions.Analytics, true); expect(LogRetentionLogic.values).toEqual({ ...DEFAULT_VALUES, @@ -211,7 +211,7 @@ describe('LogRetentionLogic', () => { const promise = Promise.resolve(TYPICAL_SERVER_LOG_RETENTION); http.put.mockReturnValue(promise); - LogRetentionLogic.actions.saveLogRetention(ELogRetentionOptions.Analytics, true); + LogRetentionLogic.actions.saveLogRetention(LogRetentionOptions.Analytics, true); expect(http.put).toHaveBeenCalledWith('/api/app_search/log_settings', { body: JSON.stringify({ @@ -233,7 +233,7 @@ describe('LogRetentionLogic', () => { const promise = Promise.reject('An error occured'); http.put.mockReturnValue(promise); - LogRetentionLogic.actions.saveLogRetention(ELogRetentionOptions.Analytics, true); + LogRetentionLogic.actions.saveLogRetention(LogRetentionOptions.Analytics, true); try { await promise; @@ -252,7 +252,7 @@ describe('LogRetentionLogic', () => { isLogRetentionUpdating: false, }); - LogRetentionLogic.actions.toggleLogRetention(ELogRetentionOptions.Analytics); + LogRetentionLogic.actions.toggleLogRetention(LogRetentionOptions.Analytics); expect(LogRetentionLogic.values).toEqual({ ...DEFAULT_VALUES, @@ -264,17 +264,17 @@ describe('LogRetentionLogic', () => { it('will call setOpenedModal if already enabled', () => { mount({ logRetention: { - [ELogRetentionOptions.Analytics]: { + [LogRetentionOptions.Analytics]: { enabled: true, }, }, }); jest.spyOn(LogRetentionLogic.actions, 'setOpenedModal'); - LogRetentionLogic.actions.toggleLogRetention(ELogRetentionOptions.Analytics); + LogRetentionLogic.actions.toggleLogRetention(LogRetentionOptions.Analytics); expect(LogRetentionLogic.actions.setOpenedModal).toHaveBeenCalledWith( - ELogRetentionOptions.Analytics + LogRetentionOptions.Analytics ); }); }); @@ -337,17 +337,17 @@ describe('LogRetentionLogic', () => { it('will call saveLogRetention if NOT already enabled', () => { mount({ logRetention: { - [ELogRetentionOptions.Analytics]: { + [LogRetentionOptions.Analytics]: { enabled: false, }, }, }); jest.spyOn(LogRetentionLogic.actions, 'saveLogRetention'); - LogRetentionLogic.actions.toggleLogRetention(ELogRetentionOptions.Analytics); + LogRetentionLogic.actions.toggleLogRetention(LogRetentionOptions.Analytics); expect(LogRetentionLogic.actions.saveLogRetention).toHaveBeenCalledWith( - ELogRetentionOptions.Analytics, + LogRetentionOptions.Analytics, true ); }); @@ -359,7 +359,7 @@ describe('LogRetentionLogic', () => { jest.spyOn(LogRetentionLogic.actions, 'saveLogRetention'); jest.spyOn(LogRetentionLogic.actions, 'setOpenedModal'); - LogRetentionLogic.actions.toggleLogRetention(ELogRetentionOptions.API); + LogRetentionLogic.actions.toggleLogRetention(LogRetentionOptions.API); expect(LogRetentionLogic.actions.saveLogRetention).not.toHaveBeenCalled(); expect(LogRetentionLogic.actions.setOpenedModal).not.toHaveBeenCalled(); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_logic.ts index 28830f2edb1d9..31fc41213492d 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/settings/log_retention/log_retention_logic.ts @@ -6,31 +6,31 @@ import { kea, MakeLogicType } from 'kea'; -import { ELogRetentionOptions, ILogRetention, ILogRetentionServer } from './types'; +import { LogRetentionOptions, LogRetention, LogRetentionServer } from './types'; import { HttpLogic } from '../../../../shared/http'; import { flashAPIErrors } from '../../../../shared/flash_messages'; import { convertLogRetentionFromServerToClient } from './utils/convert_log_retention'; -interface ILogRetentionActions { +interface LogRetentionActions { clearLogRetentionUpdating(): { value: boolean }; closeModals(): { value: boolean }; fetchLogRetention(): { value: boolean }; saveLogRetention( - option: ELogRetentionOptions, + option: LogRetentionOptions, enabled: boolean - ): { option: ELogRetentionOptions; enabled: boolean }; - setOpenedModal(option: ELogRetentionOptions): { option: ELogRetentionOptions }; - toggleLogRetention(option: ELogRetentionOptions): { option: ELogRetentionOptions }; - updateLogRetention(logRetention: ILogRetention): { logRetention: ILogRetention }; + ): { option: LogRetentionOptions; enabled: boolean }; + setOpenedModal(option: LogRetentionOptions): { option: LogRetentionOptions }; + toggleLogRetention(option: LogRetentionOptions): { option: LogRetentionOptions }; + updateLogRetention(logRetention: LogRetention): { logRetention: LogRetention }; } -interface ILogRetentionValues { - logRetention: ILogRetention | null; +interface LogRetentionValues { + logRetention: LogRetention | null; isLogRetentionUpdating: boolean; - openedModal: ELogRetentionOptions | null; + openedModal: LogRetentionOptions | null; } -export const LogRetentionLogic = kea>({ +export const LogRetentionLogic = kea>({ path: ['enterprise_search', 'app_search', 'log_retention_logic'], actions: () => ({ clearLogRetentionUpdating: true, @@ -72,7 +72,7 @@ export const LogRetentionLogic = kea ({ - [ELogRetentionOptions.Analytics]: convertLogRetentionSettingsFromServerToClient( - logRetention[ELogRetentionOptions.Analytics] + logRetention: LogRetentionServer +): LogRetention => ({ + [LogRetentionOptions.Analytics]: convertLogRetentionSettingsFromServerToClient( + logRetention[LogRetentionOptions.Analytics] ), - [ELogRetentionOptions.API]: convertLogRetentionSettingsFromServerToClient( - logRetention[ELogRetentionOptions.API] + [LogRetentionOptions.API]: convertLogRetentionSettingsFromServerToClient( + logRetention[LogRetentionOptions.API] ), }); @@ -29,7 +29,7 @@ const convertLogRetentionSettingsFromServerToClient = ({ disabled_at: disabledAt, enabled, retention_policy: retentionPolicy, -}: ILogRetentionServerSettings): ILogRetentionSettings => ({ +}: LogRetentionServerSettings): LogRetentionSettings => ({ disabledAt, enabled, retentionPolicy: @@ -39,7 +39,7 @@ const convertLogRetentionSettingsFromServerToClient = ({ const convertLogRetentionPolicyFromServerToClient = ({ min_age_days: minAgeDays, is_default: isDefault, -}: ILogRetentionServerPolicy): ILogRetentionPolicy => ({ +}: LogRetentionServerPolicy): LogRetentionPolicy => ({ isDefault, minAgeDays, }); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx index 4571ef10286e4..743cf63fb4bc3 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx @@ -12,7 +12,7 @@ import { getAppSearchUrl } from '../shared/enterprise_search_url'; import { KibanaLogic } from '../shared/kibana'; import { HttpLogic } from '../shared/http'; import { AppLogic } from './app_logic'; -import { IInitialAppData } from '../../../common/types'; +import { InitialAppData } from '../../../common/types'; import { APP_SEARCH_PLUGIN } from '../../../common/constants'; import { Layout, SideNav, SideNavLink } from '../shared/layout'; @@ -36,7 +36,7 @@ import { Settings, SETTINGS_TITLE } from './components/settings'; import { Credentials, CREDENTIALS_TITLE } from './components/credentials'; import { ROLE_MAPPINGS_TITLE } from './components/role_mappings'; -export const AppSearch: React.FC = (props) => { +export const AppSearch: React.FC = (props) => { const { config } = useValues(KibanaLogic); return !config.host ? : ; }; @@ -52,7 +52,7 @@ export const AppSearchUnconfigured: React.FC = () => ( ); -export const AppSearchConfigured: React.FC = (props) => { +export const AppSearchConfigured: React.FC = (props) => { const { initializeAppData } = useActions(AppLogic); const { hasInitialized } = useValues(AppLogic); const { errorConnecting, readOnlyMode } = useValues(HttpLogic); @@ -100,11 +100,11 @@ export const AppSearchConfigured: React.FC = (props) => { ); }; -interface IAppSearchNavProps { +interface AppSearchNavProps { subNav?: React.ReactNode; } -export const AppSearchNav: React.FC = ({ subNav }) => { +export const AppSearchNav: React.FC = ({ subNav }) => { const { myRole: { canViewSettings, canViewAccountCredentials, canViewRoleMappings }, } = useValues(AppLogic); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/types.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/types.ts index 568a0a3365982..ce7d906555d34 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/types.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/types.ts @@ -5,9 +5,9 @@ */ export * from '../../../common/types/app_search'; -export { IRole, TRole, TAbility } from './utils/role'; +export { Role, RoleTypes, AbilityTypes } from './utils/role'; -export interface IEngine { +export interface Engine { name: string; type: string; language: string; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/utils/role/index.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/utils/role/index.ts index a935fa657738c..21a80bc0c208f 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/utils/role/index.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/utils/role/index.ts @@ -4,18 +4,18 @@ * you may not use this file except in compliance with the Elastic License. */ -import { IAccount } from '../../types'; +import { Account } from '../../types'; -export type TRole = 'owner' | 'admin' | 'dev' | 'editor' | 'analyst'; -export type TAbility = 'manage' | 'edit' | 'view'; +export type RoleTypes = 'owner' | 'admin' | 'dev' | 'editor' | 'analyst'; +export type AbilityTypes = 'manage' | 'edit' | 'view'; -export interface IRole { +export interface Role { id: string; - roleType: TRole; - availableRoleTypes: TRole[]; + roleType: RoleTypes; + availableRoleTypes: RoleTypes[]; credentialTypes: string[]; canAccessAllEngines: boolean; - can(action: TAbility, subject: string): boolean; + can(action: AbilityTypes, subject: string): boolean; canViewMetaEngines: boolean; canViewAccountCredentials: boolean; canViewEngineAnalytics: boolean; @@ -48,10 +48,10 @@ export interface IRole { * Transforms the `role` data we receive from the Enterprise Search * server into a more convenient format for front-end use */ -export const getRoleAbilities = (role: IAccount['role']): IRole => { +export const getRoleAbilities = (role: Account['role']): Role => { // Role ability function helpers const myRole = { - can: (action: TAbility, subject: string): boolean => { + can: (action: AbilityTypes, subject: string): boolean => { return ( role?.ability?.manage?.includes(subject) || (Array.isArray(role.ability[action]) && role.ability[action].includes(subject)) @@ -63,8 +63,8 @@ export const getRoleAbilities = (role: IAccount['role']): IRole => { // Clone top-level role props, and move some props out of `ability` and into the top-level for convenience const topLevelProps = { id: role.id, - roleType: role.roleType as TRole, - availableRoleTypes: role.ability.availableRoleTypes as TRole[], + roleType: role.roleType as RoleTypes, + availableRoleTypes: role.ability.availableRoleTypes as RoleTypes[], credentialTypes: role.ability.credentialTypes, }; diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search/components/product_card/product_card.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search/components/product_card/product_card.tsx index ee778f49ef5b6..de553acf11f7b 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search/components/product_card/product_card.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search/components/product_card/product_card.tsx @@ -16,7 +16,7 @@ import { KibanaLogic } from '../../../shared/kibana'; import './product_card.scss'; -interface IProductCard { +interface ProductCardProps { // Expects product plugin constants (@see common/constants.ts) product: { ID: string; @@ -27,7 +27,7 @@ interface IProductCard { image: string; } -export const ProductCard: React.FC = ({ product, image }) => { +export const ProductCard: React.FC = ({ product, image }) => { const { sendEnterpriseSearchTelemetry } = useActions(TelemetryLogic); const { config } = useValues(KibanaLogic); diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search/components/product_selector/product_selector.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search/components/product_selector/product_selector.tsx index 235ececd8b6fc..579baf41f2ce3 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search/components/product_selector/product_selector.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search/components/product_selector/product_selector.tsx @@ -30,14 +30,14 @@ import { SetupGuideCta } from '../setup_guide'; import AppSearchImage from '../../assets/app_search.png'; import WorkplaceSearchImage from '../../assets/workplace_search.png'; -interface IProductSelectorProps { +interface ProductSelectorProps { access: { hasAppSearchAccess?: boolean; hasWorkplaceSearchAccess?: boolean; }; } -export const ProductSelector: React.FC = ({ access }) => { +export const ProductSelector: React.FC = ({ access }) => { const { hasAppSearchAccess, hasWorkplaceSearchAccess } = access; const { config } = useValues(KibanaLogic); diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search/index.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search/index.tsx index 048baabe6a1dd..b562cd577c56b 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search/index.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search/index.tsx @@ -9,7 +9,7 @@ import { Route, Switch } from 'react-router-dom'; import { useValues } from 'kea'; import { KibanaLogic } from '../shared/kibana'; -import { IInitialAppData } from '../../../common/types'; +import { InitialAppData } from '../../../common/types'; import { HttpLogic } from '../shared/http'; @@ -21,7 +21,7 @@ import { SetupGuide } from './components/setup_guide'; import './index.scss'; -export const EnterpriseSearch: React.FC = ({ access = {} }) => { +export const EnterpriseSearch: React.FC = ({ access = {} }) => { const { errorConnecting } = useValues(HttpLogic); const { config } = useValues(KibanaLogic); diff --git a/x-pack/plugins/enterprise_search/public/applications/index.tsx b/x-pack/plugins/enterprise_search/public/applications/index.tsx index b9c94e351089d..3436df851c8d8 100644 --- a/x-pack/plugins/enterprise_search/public/applications/index.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/index.tsx @@ -14,7 +14,7 @@ import { I18nProvider } from '@kbn/i18n/react'; import { AppMountParameters, CoreStart } from 'src/core/public'; import { PluginsStart, ClientConfigType, ClientData } from '../plugin'; -import { IInitialAppData } from '../../common/types'; +import { InitialAppData } from '../../common/types'; import { mountKibanaLogic } from './shared/kibana'; import { mountLicensingLogic } from './shared/licensing'; @@ -29,7 +29,7 @@ import { externalUrl } from './shared/enterprise_search_url'; */ export const renderApp = ( - App: React.FC, + App: React.FC, { params, core, plugins }: { params: AppMountParameters; core: CoreStart; plugins: PluginsStart }, { config, data }: { config: ClientConfigType; data: ClientData } ) => { diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages_logic.ts b/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages_logic.ts index 5a05a03adeb6b..7271a1dbbea39 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages_logic.ts @@ -15,12 +15,12 @@ export interface IFlashMessage { description?: ReactNode; } -export interface IFlashMessagesValues { +interface FlashMessagesValues { messages: IFlashMessage[]; queuedMessages: IFlashMessage[]; historyListener: Function | null; } -export interface IFlashMessagesActions { +interface FlashMessagesActions { setFlashMessages(messages: IFlashMessage | IFlashMessage[]): { messages: IFlashMessage[] }; clearFlashMessages(): void; setQueuedMessages(messages: IFlashMessage | IFlashMessage[]): { messages: IFlashMessage[] }; @@ -31,7 +31,7 @@ export interface IFlashMessagesActions { const convertToArray = (messages: IFlashMessage | IFlashMessage[]) => !Array.isArray(messages) ? [messages] : messages; -export const FlashMessagesLogic = kea>({ +export const FlashMessagesLogic = kea>({ path: ['enterprise_search', 'flash_messages_logic'], actions: { setFlashMessages: (messages) => ({ messages: convertToArray(messages) }), diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/handle_api_errors.ts b/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/handle_api_errors.ts index 2bd04d1d87f7d..c4b287ee08354 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/handle_api_errors.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/handle_api_errors.ts @@ -17,7 +17,7 @@ import { FlashMessagesLogic, IFlashMessage } from './'; * `errors` property in the response's data, which will contain messages we can * display to the user. */ -interface IErrorResponse { +interface ErrorResponse { statusCode: number; error: string; message: string; @@ -25,17 +25,14 @@ interface IErrorResponse { errors: string[]; }; } -interface IOptions { +interface Options { isQueued?: boolean; } /** * Converts API/HTTP errors into user-facing Flash Messages */ -export const flashAPIErrors = ( - error: HttpResponse, - { isQueued }: IOptions = {} -) => { +export const flashAPIErrors = (error: HttpResponse, { isQueued }: Options = {}) => { const defaultErrorMessage = 'An unexpected error occurred'; const errorFlashMessages: IFlashMessage[] = Array.isArray(error?.body?.attributes?.errors) diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/index.ts b/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/index.ts index 21c1a60efa6b7..8792c26f9bad4 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/index.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/index.ts @@ -5,12 +5,6 @@ */ export { FlashMessages } from './flash_messages'; -export { - FlashMessagesLogic, - IFlashMessage, - IFlashMessagesValues, - IFlashMessagesActions, - mountFlashMessagesLogic, -} from './flash_messages_logic'; +export { FlashMessagesLogic, IFlashMessage, mountFlashMessagesLogic } from './flash_messages_logic'; export { flashAPIErrors } from './handle_api_errors'; export { setSuccessMessage, setErrorMessage, setQueuedSuccessMessage } from './set_message_helpers'; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/hidden_text/hidden_text.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/hidden_text/hidden_text.tsx index 9b0833dfce541..69176b8a139e7 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/hidden_text/hidden_text.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/hidden_text/hidden_text.tsx @@ -7,18 +7,18 @@ import React, { useState, ReactElement } from 'react'; import { i18n } from '@kbn/i18n'; -interface IChildrenProps { +interface ChildrenProps { toggle: () => void; isHidden: boolean; hiddenText: React.ReactNode; } -interface IProps { +interface Props { text: string; - children(props: IChildrenProps): ReactElement; + children(props: ChildrenProps): ReactElement; } -export const HiddenText: React.FC = ({ text, children }) => { +export const HiddenText: React.FC = ({ text, children }) => { const [isHidden, toggleIsHidden] = useState(true); const hiddenLabel = i18n.translate('xpack.enterpriseSearch.hiddenText', { diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/http/http_logic.ts b/x-pack/plugins/enterprise_search/public/applications/shared/http/http_logic.ts index d16e507bfb3bc..76cefa4bc5a2c 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/http/http_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/http/http_logic.ts @@ -10,20 +10,20 @@ import { HttpSetup, HttpInterceptorResponseError, HttpResponse } from 'src/core/ import { READ_ONLY_MODE_HEADER } from '../../../../common/constants'; -export interface IHttpValues { +interface HttpValues { http: HttpSetup; httpInterceptors: Function[]; errorConnecting: boolean; readOnlyMode: boolean; } -export interface IHttpActions { +interface HttpActions { initializeHttpInterceptors(): void; setHttpInterceptors(httpInterceptors: Function[]): { httpInterceptors: Function[] }; setErrorConnecting(errorConnecting: boolean): { errorConnecting: boolean }; setReadOnlyMode(readOnlyMode: boolean): { readOnlyMode: boolean }; } -export const HttpLogic = kea>({ +export const HttpLogic = kea>({ path: ['enterprise_search', 'http_logic'], actions: { initializeHttpInterceptors: () => null, @@ -108,12 +108,12 @@ export const HttpLogic = kea>({ /** * Mount/props helper */ -interface IHttpLogicProps { +interface HttpLogicProps { http: HttpSetup; errorConnecting?: boolean; readOnlyMode?: boolean; } -export const mountHttpLogic = (props: IHttpLogicProps) => { +export const mountHttpLogic = (props: HttpLogicProps) => { HttpLogic(props); const unmount = HttpLogic.mount(); return unmount; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/http/index.ts b/x-pack/plugins/enterprise_search/public/applications/shared/http/index.ts index 46a52415f8564..5e41ea032d503 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/http/index.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/http/index.ts @@ -4,4 +4,4 @@ * you may not use this file except in compliance with the Elastic License. */ -export { HttpLogic, IHttpValues, IHttpActions, mountHttpLogic } from './http_logic'; +export { HttpLogic, mountHttpLogic } from './http_logic'; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana/kibana_logic.ts b/x-pack/plugins/enterprise_search/public/applications/shared/kibana/kibana_logic.ts index 89ed07f302b03..28f500a2c8a39 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana/kibana_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana/kibana_logic.ts @@ -11,9 +11,9 @@ import { History } from 'history'; import { ApplicationStart, ChromeBreadcrumb } from 'src/core/public'; import { HttpLogic } from '../http'; -import { createHref, ICreateHrefOptions } from '../react_router_helpers'; +import { createHref, CreateHrefOptions } from '../react_router_helpers'; -interface IKibanaLogicProps { +interface KibanaLogicProps { config: { host?: string }; history: History; navigateToUrl: ApplicationStart['navigateToUrl']; @@ -21,17 +21,17 @@ interface IKibanaLogicProps { setDocTitle(title: string): void; renderHeaderActions(HeaderActions: FC): void; } -export interface IKibanaValues extends IKibanaLogicProps { - navigateToUrl(path: string, options?: ICreateHrefOptions): Promise; +export interface KibanaValues extends KibanaLogicProps { + navigateToUrl(path: string, options?: CreateHrefOptions): Promise; } -export const KibanaLogic = kea>({ +export const KibanaLogic = kea>({ path: ['enterprise_search', 'kibana_logic'], reducers: ({ props }) => ({ config: [props.config || {}, {}], history: [props.history, {}], navigateToUrl: [ - (url: string, options?: ICreateHrefOptions) => { + (url: string, options?: CreateHrefOptions) => { const deps = { history: props.history, http: HttpLogic.values.http }; const href = createHref(url, deps, options); return props.navigateToUrl(href); @@ -44,7 +44,7 @@ export const KibanaLogic = kea>({ }), }); -export const mountKibanaLogic = (props: IKibanaLogicProps) => { +export const mountKibanaLogic = (props: KibanaLogicProps) => { KibanaLogic(props); const unmount = KibanaLogic.mount(); return unmount; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_chrome/generate_breadcrumbs.ts b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_chrome/generate_breadcrumbs.ts index e22334aeea371..25d4850425a6e 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_chrome/generate_breadcrumbs.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_chrome/generate_breadcrumbs.ts @@ -23,15 +23,15 @@ import { letBrowserHandleEvent, createHref } from '../react_router_helpers'; * Types */ -interface IBreadcrumb { +interface Breadcrumb { text: string; path?: string; // Used to navigate outside of the React Router basename, // i.e. if we need to go from App Search to Enterprise Search shouldNotCreateHref?: boolean; } -export type TBreadcrumbs = IBreadcrumb[]; -export type TBreadcrumbTrail = string[]; // A trail of breadcrumb text +export type Breadcrumbs = Breadcrumb[]; +export type BreadcrumbTrail = string[]; // A trail of breadcrumb text /** * Generate an array of breadcrumbs based on: @@ -50,7 +50,7 @@ export type TBreadcrumbTrail = string[]; // A trail of breadcrumb text * > Source Prioritization (linked to `/groups/{example-group-id}/source_prioritization`) */ -export const useGenerateBreadcrumbs = (trail: TBreadcrumbTrail): TBreadcrumbs => { +export const useGenerateBreadcrumbs = (trail: BreadcrumbTrail): Breadcrumbs => { const { history } = useValues(KibanaLogic); const pathArray = stripLeadingSlash(history.location.pathname).split('/'); @@ -65,7 +65,7 @@ export const useGenerateBreadcrumbs = (trail: TBreadcrumbTrail): TBreadcrumbs => * https://elastic.github.io/eui/#/navigation/breadcrumbs */ -export const useEuiBreadcrumbs = (breadcrumbs: TBreadcrumbs): EuiBreadcrumb[] => { +export const useEuiBreadcrumbs = (breadcrumbs: Breadcrumbs): EuiBreadcrumb[] => { const { navigateToUrl, history } = useValues(KibanaLogic); const { http } = useValues(HttpLogic); @@ -89,7 +89,7 @@ export const useEuiBreadcrumbs = (breadcrumbs: TBreadcrumbs): EuiBreadcrumb[] => * Product-specific breadcrumb helpers */ -export const useEnterpriseSearchBreadcrumbs = (breadcrumbs: TBreadcrumbs = []) => +export const useEnterpriseSearchBreadcrumbs = (breadcrumbs: Breadcrumbs = []) => useEuiBreadcrumbs([ { text: ENTERPRISE_SEARCH_PLUGIN.NAME, @@ -99,10 +99,10 @@ export const useEnterpriseSearchBreadcrumbs = (breadcrumbs: TBreadcrumbs = []) = ...breadcrumbs, ]); -export const useAppSearchBreadcrumbs = (breadcrumbs: TBreadcrumbs = []) => +export const useAppSearchBreadcrumbs = (breadcrumbs: Breadcrumbs = []) => useEnterpriseSearchBreadcrumbs([{ text: APP_SEARCH_PLUGIN.NAME, path: '/' }, ...breadcrumbs]); -export const useWorkplaceSearchBreadcrumbs = (breadcrumbs: TBreadcrumbs = []) => +export const useWorkplaceSearchBreadcrumbs = (breadcrumbs: Breadcrumbs = []) => useEnterpriseSearchBreadcrumbs([ { text: WORKPLACE_SEARCH_PLUGIN.NAME, path: '/' }, ...breadcrumbs, diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_chrome/generate_title.ts b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_chrome/generate_title.ts index de5f72de79192..a0e34106fe2a2 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_chrome/generate_title.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_chrome/generate_title.ts @@ -15,24 +15,24 @@ import { * https://github.com/elastic/kibana/blob/master/docs/development/core/public/kibana-plugin-core-public.chromedoctitle.md */ -export type TTitle = string[]; +type Title = string[]; /** * Given an array of page titles, return a final formatted document title * @param pages - e.g., ['Curations', 'some Engine', 'App Search'] * @returns - e.g., 'Curations - some Engine - App Search' */ -export const generateTitle = (pages: TTitle) => pages.join(' - '); +export const generateTitle = (pages: Title) => pages.join(' - '); /** * Product-specific helpers */ -export const enterpriseSearchTitle = (page: TTitle = []) => +export const enterpriseSearchTitle = (page: Title = []) => generateTitle([...page, ENTERPRISE_SEARCH_PLUGIN.NAME]); -export const appSearchTitle = (page: TTitle = []) => +export const appSearchTitle = (page: Title = []) => generateTitle([...page, APP_SEARCH_PLUGIN.NAME]); -export const workplaceSearchTitle = (page: TTitle = []) => +export const workplaceSearchTitle = (page: Title = []) => generateTitle([...page, WORKPLACE_SEARCH_PLUGIN.NAME]); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_chrome/set_chrome.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_chrome/set_chrome.tsx index a43e7053bb1e1..0e694a3d2bbc8 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_chrome/set_chrome.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_chrome/set_chrome.tsx @@ -14,7 +14,7 @@ import { useEnterpriseSearchBreadcrumbs, useAppSearchBreadcrumbs, useWorkplaceSearchBreadcrumbs, - TBreadcrumbTrail, + BreadcrumbTrail, } from './generate_breadcrumbs'; import { enterpriseSearchTitle, appSearchTitle, workplaceSearchTitle } from './generate_title'; @@ -33,11 +33,11 @@ import { enterpriseSearchTitle, appSearchTitle, workplaceSearchTitle } from './g * Title output: Workplace Search - Elastic */ -interface ISetChromeProps { - trail?: TBreadcrumbTrail; +interface SetChromeProps { + trail?: BreadcrumbTrail; } -export const SetEnterpriseSearchChrome: React.FC = ({ trail = [] }) => { +export const SetEnterpriseSearchChrome: React.FC = ({ trail = [] }) => { const { setBreadcrumbs, setDocTitle } = useValues(KibanaLogic); const title = reverseArray(trail); @@ -54,7 +54,7 @@ export const SetEnterpriseSearchChrome: React.FC = ({ trail = [ return null; }; -export const SetAppSearchChrome: React.FC = ({ trail = [] }) => { +export const SetAppSearchChrome: React.FC = ({ trail = [] }) => { const { setBreadcrumbs, setDocTitle } = useValues(KibanaLogic); const title = reverseArray(trail); @@ -71,7 +71,7 @@ export const SetAppSearchChrome: React.FC = ({ trail = [] }) => return null; }; -export const SetWorkplaceSearchChrome: React.FC = ({ trail = [] }) => { +export const SetWorkplaceSearchChrome: React.FC = ({ trail = [] }) => { const { setBreadcrumbs, setDocTitle } = useValues(KibanaLogic); const title = reverseArray(trail); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/layout/layout.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/layout/layout.tsx index ef8216e8b6711..0ee7de242dfe2 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/layout/layout.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/layout/layout.tsx @@ -12,7 +12,7 @@ import { i18n } from '@kbn/i18n'; import './layout.scss'; -interface ILayoutProps { +interface LayoutProps { navigation: React.ReactNode; restrictWidth?: boolean; readOnlyMode?: boolean; @@ -23,7 +23,7 @@ export interface INavContext { } export const NavContext = React.createContext({}); -export const Layout: React.FC = ({ +export const Layout: React.FC = ({ children, navigation, restrictWidth, diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/layout/side_nav.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/layout/side_nav.tsx index facfd0bfcb16d..6c4e1d084c16d 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/layout/side_nav.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/layout/side_nav.tsx @@ -23,7 +23,7 @@ import './side_nav.scss'; * Side navigation - product & icon + links wrapper */ -interface ISideNavProps { +interface SideNavProps { // Expects product plugin constants (@see common/constants.ts) product: { NAME: string; @@ -31,7 +31,7 @@ interface ISideNavProps { }; } -export const SideNav: React.FC = ({ product, children }) => { +export const SideNav: React.FC = ({ product, children }) => { return (