diff --git a/src/core/server/ui_settings/settings/announcements.test.ts b/src/core/server/ui_settings/settings/announcements.test.ts new file mode 100644 index 0000000000000..ef32e85ef192a --- /dev/null +++ b/src/core/server/ui_settings/settings/announcements.test.ts @@ -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 + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { UiSettingsParams } from '../../../types'; +import { getAnnouncementsSettings } from './announcements'; + +describe('announcements settings', () => { + const state = getAnnouncementsSettings(); + + const getValidationFn = (setting: UiSettingsParams) => (value: any) => + setting.schema.validate(value); + + describe('hideAnnouncements', () => { + const validate = getValidationFn(state.hideAnnouncements); + + it('should only accept boolean values', () => { + expect(() => validate(true)).not.toThrow(); + expect(() => validate(false)).not.toThrow(); + expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [boolean] but got [string]"` + ); + expect(() => validate(12)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [boolean] but got [number]"` + ); + }); + }); +}); diff --git a/src/core/server/ui_settings/settings/announcements.ts b/src/core/server/ui_settings/settings/announcements.ts new file mode 100644 index 0000000000000..1f049feb462e8 --- /dev/null +++ b/src/core/server/ui_settings/settings/announcements.ts @@ -0,0 +1,26 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { schema } from '@kbn/config-schema'; +import { i18n } from '@kbn/i18n'; +import { UiSettingsParams } from '../../../types'; + +export const getAnnouncementsSettings = (): Record => { + return { + hideAnnouncements: { + name: i18n.translate('core.ui_settings.params.hideAnnouncements', { + defaultMessage: 'Hide announcements', + }), + value: false, + description: i18n.translate('core.ui_settings.params.hideAnnouncementsText', { + defaultMessage: 'Stop showing messages and tours that highlight new features.', + }), + schema: schema.boolean(), + }, + }; +}; diff --git a/src/core/server/ui_settings/settings/index.test.ts b/src/core/server/ui_settings/settings/index.test.ts index 073e017d61df7..5b4323f8663c5 100644 --- a/src/core/server/ui_settings/settings/index.test.ts +++ b/src/core/server/ui_settings/settings/index.test.ts @@ -14,12 +14,14 @@ import { getNotificationsSettings } from './notifications'; import { getThemeSettings } from './theme'; import { getCoreSettings } from '.'; import { getStateSettings } from './state'; +import { getAnnouncementsSettings } from './announcements'; describe('getCoreSettings', () => { it('should not have setting overlaps', () => { const coreSettingsLength = Object.keys(getCoreSettings()).length; const summedLength = [ getAccessibilitySettings(), + getAnnouncementsSettings(), getDateFormatSettings(), getMiscUiSettings(), getNavigationSettings(), diff --git a/src/core/server/ui_settings/settings/index.ts b/src/core/server/ui_settings/settings/index.ts index 944ada3a63e4f..137443a6a1a2e 100644 --- a/src/core/server/ui_settings/settings/index.ts +++ b/src/core/server/ui_settings/settings/index.ts @@ -14,6 +14,7 @@ import { getNavigationSettings } from './navigation'; import { getNotificationsSettings } from './notifications'; import { getThemeSettings } from './theme'; import { getStateSettings } from './state'; +import { getAnnouncementsSettings } from './announcements'; interface GetCoreSettingsOptions { isDist?: boolean; @@ -24,6 +25,7 @@ export const getCoreSettings = ( ): Record => { return { ...getAccessibilitySettings(), + ...getAnnouncementsSettings(), ...getDateFormatSettings(), ...getMiscUiSettings(), ...getNavigationSettings(), diff --git a/src/plugins/discover/common/index.ts b/src/plugins/discover/common/index.ts index 2ea0215cad04d..b5f2238430d02 100644 --- a/src/plugins/discover/common/index.ts +++ b/src/plugins/discover/common/index.ts @@ -26,3 +26,4 @@ export const SHOW_MULTIFIELDS = 'discover:showMultiFields'; export const TRUNCATE_MAX_HEIGHT = 'truncate:maxHeight'; export const ROW_HEIGHT_OPTION = 'discover:rowHeightOption'; export const SEARCH_EMBEDDABLE_TYPE = 'search'; +export const HIDE_ANNOUNCEMENTS = 'hideAnnouncements'; diff --git a/src/plugins/discover/public/__mocks__/services.ts b/src/plugins/discover/public/__mocks__/services.ts index f1865049947b7..5e528433f22ab 100644 --- a/src/plugins/discover/public/__mocks__/services.ts +++ b/src/plugins/discover/public/__mocks__/services.ts @@ -16,6 +16,7 @@ import { MAX_DOC_FIELDS_DISPLAYED, SAMPLE_SIZE_SETTING, SORT_DEFAULT_ORDER_SETTING, + HIDE_ANNOUNCEMENTS, } from '../../common'; import { UI_SETTINGS } from '@kbn/data-plugin/public'; import { TopNavMenu } from '@kbn/navigation-plugin/public'; @@ -68,6 +69,8 @@ export const discoverServiceMock = { return 250; } else if (key === MAX_DOC_FIELDS_DISPLAYED) { return 50; + } else if (key === HIDE_ANNOUNCEMENTS) { + return false; } }), isDefault: (key: string) => { diff --git a/src/plugins/discover/public/application/main/components/document_explorer_callout/document_explorer_callout.tsx b/src/plugins/discover/public/application/main/components/document_explorer_callout/document_explorer_callout.tsx index e17f8bad92816..7d64e9b515a9a 100644 --- a/src/plugins/discover/public/application/main/components/document_explorer_callout/document_explorer_callout.tsx +++ b/src/plugins/discover/public/application/main/components/document_explorer_callout/document_explorer_callout.tsx @@ -88,6 +88,7 @@ export const DocumentExplorerCallout = () => { > !uiSettings.get(SEARCH_FIELDS_FROM_SOURCE), [uiSettings]); - + const hideAnnouncements = useMemo(() => uiSettings.get(HIDE_ANNOUNCEMENTS), [uiSettings]); const isLegacy = useMemo(() => uiSettings.get(DOC_TABLE_LEGACY), [uiSettings]); const sampleSize = useMemo(() => uiSettings.get(SAMPLE_SIZE_SETTING), [uiSettings]); @@ -137,7 +138,7 @@ function DiscoverDocumentsComponent({ {isLegacy && rows && rows.length && ( <> - + {!hideAnnouncements && } - - - + {!hideAnnouncements && ( + + + + )}
{ + await kibanaServer.uiSettings.replace({}); + }); + + it('should display take tour button', async function () { + await PageObjects.discover.selectIndexPattern('logstash-*'); + const tourButtonExists = await testSubjects.exists('discoverTakeTourButton'); + expect(tourButtonExists).to.be(true); + }); + + it('should not display take tour button', async function () { + await kibanaServer.uiSettings.update({ hideAnnouncements: true }); + await browser.refresh(); + const tourButtonExists = await testSubjects.exists('discoverTakeTourButton'); + expect(tourButtonExists).to.be(false); + }); + }); +} diff --git a/test/functional/apps/discover/classic/_hide_announcements.ts b/test/functional/apps/discover/classic/_hide_announcements.ts new file mode 100644 index 0000000000000..640e7904f07af --- /dev/null +++ b/test/functional/apps/discover/classic/_hide_announcements.ts @@ -0,0 +1,48 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../ftr_provider_context'; + +export default function ({ getService, getPageObjects }: FtrProviderContext) { + const esArchiver = getService('esArchiver'); + const PageObjects = getPageObjects(['common', 'home', 'settings', 'discover', 'timePicker']); + const kibanaServer = getService('kibanaServer'); + const testSubjects = getService('testSubjects'); + const browser = getService('browser'); + + describe('test hide announcements', function () { + before(async function () { + await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover.json'); + await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional'); + await kibanaServer.uiSettings.replace({ + defaultIndex: 'logstash-*', + 'doc_table:legacy': true, + }); + await PageObjects.common.navigateToApp('discover'); + await PageObjects.timePicker.setDefaultAbsoluteRange(); + }); + + after(async () => { + await kibanaServer.uiSettings.replace({}); + }); + + it('should display try document explorer button', async function () { + await PageObjects.discover.selectIndexPattern('logstash-*'); + const tourButtonExists = await testSubjects.exists('tryDocumentExplorerButton'); + expect(tourButtonExists).to.be(true); + }); + + it('should not display try document explorer button', async function () { + await kibanaServer.uiSettings.update({ hideAnnouncements: true }); + await browser.refresh(); + const tourButtonExists = await testSubjects.exists('tryDocumentExplorerButton'); + expect(tourButtonExists).to.be(false); + }); + }); +} diff --git a/test/functional/apps/discover/index.ts b/test/functional/apps/discover/index.ts index cd2742abe8e13..7d253200893f5 100644 --- a/test/functional/apps/discover/index.ts +++ b/test/functional/apps/discover/index.ts @@ -65,6 +65,8 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./_chart_hidden')); loadTestFile(require.resolve('./_context_encoded_url_params')); loadTestFile(require.resolve('./_data_view_editor')); + loadTestFile(require.resolve('./_hide_announcements')); + loadTestFile(require.resolve('./classic/_hide_announcements')); } }); }