From 2c22739f965fbda80d75a6f9014798290d9d0d56 Mon Sep 17 00:00:00 2001 From: Ryland Herrick Date: Fri, 20 Dec 2019 14:23:01 -0600 Subject: [PATCH] [SIEM] Migrating frontend services to NP (#53669) * [SIEM] Migrating frontend services to NP (#52783) * Remove legacy index_patterns import We'd already brought in the new interface in a previous commit; this was just used as an unnecessary type assertion. * Update snapshots following new docLink mocks * Remove unused manual mocks These are not picked up by jest; calling jest.mock('lib/compose/kibana_core') has the same effect whether or not these files exist. * WIP: Use kibana core mock everywhere we're doing it manually The timeline tests are the last place we're explicitly mocking useKibanaCore; removing the mocks cause tests to hang. I think hey're relying on the side effects of importing the mock/ui_settings file, but I'll figure that out next. * Replace ui/documentation_links with core NP service In most instances, this meant using the useContext hook with our NP core context. This also updates our mocks to leverage the factory so graciously provided by platform. There are a few failing tests, mostly due to links being previously undefined in tests. * Use new mocks on timeline test that doesn't hang The rest of these do, though. * Remove remaining uses of mockUiSettings in useKibanaCore mocks These have to be evaluated immediately so that we always return the same core object. Otherwise we get stuck in a loop between render/useEffect/setState due to the savedObjects client being different on each invocation. * Invoke platform's mock factory at mock time Previously, we were invoking it any time someone called `useKibanaCore`, getting a new object back each time. This both caused some bugs (looping with useEffect) and was not representative of how the actual hook worked. This also moves that invokation into the mock function, along with shaping the mocked module so that we don't have to do it in every call to jest.mock. * WIP: migrating to use kibana_react's provider and helpers We're re-exporting these locally to have more control around mocking them (until platform implements that). This breaks everything that was using the old mocks. Will fix. * WIP: Migrating to use kibana_react Instead of our homegrown hooks we can use these utilities instead. Unfortunately kibana_react doesn't yet have mocks, so we had to implement that ourselves. Luckily, we already had local mocks for the settings service. This migrates to a the new format. For clarity and consistency, we also re-export new platform's mocks here and use them to populate our kibana_react mocks. We started by migrating the UiSettings service to new platform, and let that drive the rest. With the mocks in place for kibana_react, removing the usage of useKibanaCore was a natural step as well. The next step is removing the usage of chrome.getUiSettingsClient with our useUiSetting$ hook, and with that (and maybe some config setup; I'm seeing errors at runtime), we should be ready to start migrating other services. * Bind a copy of kibana at mock creation We were previously returning a new copy any time e.g. useKibana was called, which is not the contract that consumers are expecting. and in fact caused looping with components employing useEffect etc. * Remove internal context providers and last usage We're now using kibana_react fully. * Fix tests failing due to wrong mocks Remaining failures are either due to a date format issue, or something being rendered differently. Those are up next. Still haven't touched use of chrome.getUiSettingsClient, that's after. * Fix test failures related to date formatting * mocks missing UI Setting (DEFAULT_TIMEZONE_BROWSER) which is required by our formatted_date utilities * mock timepicker ranges in the one test that uses it (SuperDatePicker) * Remove unnecessary and/or redundant mocks Since our TestProvider now mocks new platform, the only tests that should need to mock uiSettings related stuff (e.g. timezone preferences) would be the tests that (directly or no) use kibana_react to get it. * Refactor kibana_react mocks * adds a mock for the non-observable useUiSetting * removes the unmockable HOC withKibana * Replace usage of chrome.getUiSettingsClient with useUiSetting We're opting for the non-observable behavior here because I believe that's more analagous. There are a few remaining usages in non-react code. Tests are still using the mocks, those'll be removed next. * Remove ui_settings mocks Now that we're not using this hook there's no need for the mocks. Tests are green. * Remove siem's UI settings hook We're now using the ones provided by kibana_react. * Use withKibana HOC on our component classes React was kind enough to remind me that I can't put hooks in classes. Whoops. * Set defaults for some unknown UI settings The service claims not to know about these settings we're retrieving. Until I can figure out where they should come from, we're going to initialize them with what seem to be the defaults at plugin initialization. * Remove old hooks These have now been replaced with kibana_react's equivalents. * Fix type error on usage of useKibana hook This is one of the few places where we're using another plugin, which are not present in the default typings due to their opt-in nature. * Fix type error on ML call The indexPattern we get back is actually an array. The endpoint seems to handle this just fine (at least, it doesn't blow up), but once we started retrieving a typed value this error surfaced. * Export a 'bound' version of the useKibana function Rather than having to type this on each invocation. This requires us to define which plugins we depend on, which is a good thing. * Instantiate our mock function We aren't using these right now I didn't notice, but that wasn't the right reference. * Fix test that relies on unmocked service Our QueryBar component relies very (very, very) indirectly on a storage service that does not exist in New Platform, nor its corresponding mocks. To get it passing for now, we're just gonna pretend like it's there. * Remove use of ui/chrome in our charts Replaces with hooks that accomplish the same. * Remove last use of chrome.getUiSettingsClient This function is itself a hook, so we should be good here. * Remove unnecessary non-null assertions Now that we're using our typed version of the useKibana hook, typescript knows that these services will be available (once we actually enforce that in our kibana.json, of course). * Fix chart tests These rely on a kibana hook now, so we need to mock it out for these renders lest we blow up when the context isn't there. * Replace missing mock I deleted this in a previous commit, thinking it unneeded. However, getHostDetailsBreadcrumbs ultimately asks for some default date parameters for the timerange boundaries. * Add back tests for our theming hook * Style: cleanup * Remove unneeded default UI Settings values We were previously getting errors due to these values not being known to the client, but it looks like that was either fixed upstream, or a temporary issue caused by some improper context setup. * Simplify kibana_react mocks Let's leave JSX out of it. Co-authored-by: Elastic Machine * Update references to now-deleted hooks These hooks were deleted on a recent branch, but new usages were merged to master in the meantime. * Fix remaining uses of hooks/chrome that were not merge conflicts * Use HOC on class component Co-authored-by: Elastic Machine --- .../plugins/siem/public/apps/plugin.tsx | 8 +- .../plugins/siem/public/apps/start_app.tsx | 40 ++---- .../public/components/bytes/index.test.tsx | 2 - .../components/charts/areachart.test.tsx | 2 + .../public/components/charts/areachart.tsx | 8 +- .../components/charts/barchart.test.tsx | 2 + .../public/components/charts/barchart.tsx | 10 +- .../public/components/charts/common.test.tsx | 44 +++--- .../siem/public/components/charts/common.tsx | 50 +++---- .../utility_bar/utility_bar.test.tsx | 3 - .../utility_bar/utility_bar_action.test.tsx | 3 - .../utility_bar/utility_bar_group.test.tsx | 3 - .../utility_bar/utility_bar_section.test.tsx | 3 - .../utility_bar/utility_bar_text.test.tsx | 3 - .../__snapshots__/embedded_map.test.tsx.snap | 2 +- ...ndex_patterns_missing_prompt.test.tsx.snap | 2 +- .../embeddables/embeddable.test.tsx | 3 - .../embeddables/embeddable_header.test.tsx | 3 - .../embeddables/embedded_map.test.tsx | 21 +-- .../components/embeddables/embedded_map.tsx | 28 ++-- .../embeddables/embedded_map_helpers.test.tsx | 1 - .../index_patterns_missing_prompt.test.tsx | 6 +- .../index_patterns_missing_prompt.tsx | 116 +++++++-------- .../event_details/event_details.test.tsx | 2 - .../event_fields_browser.test.tsx | 2 +- .../events_viewer/events_viewer.test.tsx | 10 +- .../events_viewer/events_viewer.tsx | 6 +- .../components/events_viewer/index.test.tsx | 10 +- .../public/components/events_viewer/index.tsx | 4 +- .../public/components/flyout/index.test.tsx | 2 - .../components/flyout/pane/index.test.tsx | 15 +- .../components/formatted_bytes/index.test.tsx | 22 ++- .../components/formatted_bytes/index.tsx | 4 +- .../components/formatted_date/index.test.tsx | 60 +++----- .../components/formatted_date/index.tsx | 9 +- .../components/header_global/index.test.tsx | 3 +- .../components/header_page/index.test.tsx | 3 - .../components/header_section/index.test.tsx | 3 - .../components/last_event_time/index.test.tsx | 1 - .../components/link_icon/index.test.tsx | 3 - .../matrix_histogram/index.test.tsx | 11 +- .../components/matrix_histogram/index.tsx | 4 +- .../ml/anomaly/use_anomalies_table_data.ts | 8 +- .../permissions/ml_capabilities_provider.tsx | 4 +- .../ml/score/anomaly_score.test.tsx | 2 - .../ml/score/anomaly_scores.test.tsx | 2 - .../score/create_descriptions_list.test.tsx | 2 +- .../ml_popover/hooks/use_siem_jobs.tsx | 6 +- .../components/ml_popover/ml_popover.test.tsx | 3 +- .../components/ml_popover/ml_popover.tsx | 8 +- .../public/components/ml_popover/types.ts | 2 +- .../public/components/netflow/index.test.tsx | 2 - .../components/open_timeline/index.test.tsx | 2 +- .../open_timeline/open_timeline.test.tsx | 2 +- .../open_timeline_modal/index.test.tsx | 2 +- .../open_timeline_modal_body.test.tsx | 2 +- .../open_timeline_modal_button.test.tsx | 2 - .../timelines_table/actions_columns.test.tsx | 2 +- .../timelines_table/common_columns.test.tsx | 2 +- .../timelines_table/extended_columns.test.tsx | 2 +- .../icon_header_columns.test.tsx | 2 +- .../timelines_table/index.test.tsx | 2 +- .../histogram_signals/index.test.tsx | 3 - .../hosts/first_last_seen_host/index.test.tsx | 23 ++- .../page/hosts/host_overview/index.tsx | 4 +- .../page/hosts/hosts_table/index.test.tsx | 8 -- .../page/network/ip_overview/index.tsx | 4 +- .../network/network_dns_table/index.test.tsx | 2 - .../network/network_http_table/index.test.tsx | 2 - .../index.test.tsx | 1 - .../network_top_n_flow_table/index.test.tsx | 2 - .../page/network/tls_table/index.test.tsx | 2 - .../page/network/users_table/index.test.tsx | 2 - .../components/progress_inline/index.test.tsx | 3 - .../components/query_bar/index.test.tsx | 25 ++-- .../public/components/query_bar/index.tsx | 3 +- .../public/components/search_bar/index.tsx | 3 +- .../source_destination/index.test.tsx | 2 - .../source_destination_ip.test.tsx | 2 - .../public/components/subtitle/index.test.tsx | 3 - .../super_date_picker/index.test.tsx | 67 ++++++++- .../components/super_date_picker/index.tsx | 12 +- .../components/timeline/body/index.test.tsx | 2 - .../body/renderers/formatted_field.test.tsx | 2 +- .../netflow/netflow_row_renderer.test.tsx | 2 - .../renderers/plain_column_renderer.test.tsx | 2 +- .../system/generic_row_renderer.test.tsx | 2 +- .../components/timeline/header/index.test.tsx | 9 +- .../timeline/properties/index.test.tsx | 12 +- .../timeline/query_bar/index.test.tsx | 9 +- .../components/timeline/query_bar/index.tsx | 6 +- .../components/timeline/timeline.test.tsx | 9 +- .../public/components/timeline/timeline.tsx | 6 +- .../components/wrapper_page/index.test.tsx | 3 - .../alerts/alerts_over_time/index.tsx | 13 +- .../anomalies_query_tab_body/index.tsx | 4 +- .../authentications_over_time/index.tsx | 17 ++- .../containers/authentications/index.tsx | 13 +- .../detection_engine/rules/persist_rule.tsx | 4 +- .../detection_engine/rules/use_rule.tsx | 4 +- .../detection_engine/rules/use_rules.tsx | 4 +- .../detection_engine/signals/use_query.tsx | 4 +- .../events/events_over_time/index.tsx | 13 +- .../events/last_event_time/index.ts | 5 +- .../containers/hosts/first_last_seen/index.ts | 5 +- .../siem/public/containers/hosts/index.tsx | 14 +- .../containers/hosts/overview/index.tsx | 18 ++- .../public/containers/ip_overview/index.tsx | 4 +- .../containers/kpi_host_details/index.tsx | 4 +- .../public/containers/kpi_hosts/index.tsx | 4 +- .../public/containers/kpi_network/index.tsx | 4 +- .../containers/kuery_autocompletion/index.tsx | 6 +- .../public/containers/network_dns/index.tsx | 21 ++- .../public/containers/network_http/index.tsx | 10 +- .../network_top_countries/index.tsx | 10 +- .../containers/network_top_n_flow/index.tsx | 10 +- .../overview/overview_host/index.tsx | 4 +- .../overview/overview_network/index.tsx | 4 +- .../public/containers/source/index.test.tsx | 4 +- .../siem/public/containers/source/index.tsx | 13 +- .../containers/timeline/details/index.tsx | 4 +- .../siem/public/containers/timeline/index.tsx | 16 ++- .../siem/public/containers/tls/index.tsx | 14 +- .../containers/uncommon_processes/index.tsx | 13 +- .../siem/public/containers/users/index.tsx | 13 +- .../siem/public/hooks/use_index_patterns.tsx | 4 +- .../lib/compose/__mocks__/kibana_core.ts | 13 -- .../lib/compose/__mocks__/kibana_plugins.ts | 13 -- .../siem/public/lib/compose/kibana_core.tsx | 25 ---- .../public/lib/compose/kibana_plugins.tsx | 27 ---- .../siem/public/lib/kibana/__mocks__/index.ts | 19 +++ .../plugins/siem/public/lib/kibana/index.ts | 31 ++++ .../__mocks__/use_kibana_ui_setting.ts | 13 -- .../lib/settings/use_kibana_ui_setting.ts | 55 -------- .../settings/use_kibana_ui_settings.test.tsx | 50 ------- .../public/lib/settings/use_observable.ts | 21 --- .../siem/public/lib/theme/use_eui_theme.tsx | 4 +- .../plugins/siem/public/mock/kibana_core.ts | 13 ++ .../plugins/siem/public/mock/kibana_react.ts | 95 +++++++++++++ .../siem/public/mock/test_providers.tsx | 34 +---- .../plugins/siem/public/mock/ui_settings.ts | 75 ---------- .../components/signals/index.tsx | 9 +- .../signals/signals_utility_bar/index.tsx | 4 +- .../detection_engine_empty_page.tsx | 4 +- .../detection_engine/rules/all/index.tsx | 4 +- .../components/description_step/index.tsx | 6 +- .../import_rule_modal/index.test.tsx | 11 +- .../components/import_rule_modal/index.tsx | 4 +- .../rules/components/query_bar/index.tsx | 6 +- .../components/rule_switch/index.test.tsx | 14 +- .../rules/components/rule_switch/index.tsx | 4 +- .../components/step_define_rule/index.tsx | 2 +- .../pages/hosts/details/details_tabs.test.tsx | 10 +- .../siem/public/pages/hosts/details/index.tsx | 6 +- .../siem/public/pages/hosts/hosts.test.tsx | 19 +-- .../plugins/siem/public/pages/hosts/hosts.tsx | 6 +- .../public/pages/hosts/hosts_empty_page.tsx | 32 +++-- .../pages/network/ip_details/index.test.tsx | 16 +-- .../public/pages/network/ip_details/index.tsx | 6 +- .../public/pages/network/network.test.tsx | 16 +-- .../siem/public/pages/network/network.tsx | 6 +- .../pages/network/network_empty_page.tsx | 33 +++-- .../public/pages/overview/overview.test.tsx | 12 +- .../siem/public/pages/overview/overview.tsx | 5 +- .../siem/public/pages/overview/summary.tsx | 132 ++++++++++-------- .../utils/saved_query_services/index.tsx | 12 +- 166 files changed, 853 insertions(+), 1127 deletions(-) delete mode 100644 x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_core.ts delete mode 100644 x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_plugins.ts delete mode 100644 x-pack/legacy/plugins/siem/public/lib/compose/kibana_core.tsx delete mode 100644 x-pack/legacy/plugins/siem/public/lib/compose/kibana_plugins.tsx create mode 100644 x-pack/legacy/plugins/siem/public/lib/kibana/__mocks__/index.ts create mode 100644 x-pack/legacy/plugins/siem/public/lib/kibana/index.ts delete mode 100644 x-pack/legacy/plugins/siem/public/lib/settings/__mocks__/use_kibana_ui_setting.ts delete mode 100644 x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_setting.ts delete mode 100644 x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_settings.test.tsx delete mode 100644 x-pack/legacy/plugins/siem/public/lib/settings/use_observable.ts create mode 100644 x-pack/legacy/plugins/siem/public/mock/kibana_core.ts create mode 100644 x-pack/legacy/plugins/siem/public/mock/kibana_react.ts delete mode 100644 x-pack/legacy/plugins/siem/public/mock/ui_settings.ts diff --git a/x-pack/legacy/plugins/siem/public/apps/plugin.tsx b/x-pack/legacy/plugins/siem/public/apps/plugin.tsx index 1f19841788dd..700fec2557b1 100644 --- a/x-pack/legacy/plugins/siem/public/apps/plugin.tsx +++ b/x-pack/legacy/plugins/siem/public/apps/plugin.tsx @@ -15,6 +15,12 @@ import template from './template.html'; export const ROOT_ELEMENT_ID = 'react-siem-root'; +export type StartCore = LegacyCoreStart; +export type StartPlugins = Required< + Pick +>; +export type StartServices = StartCore & StartPlugins; + export class Plugin { constructor( // @ts-ignore this is added to satisfy the New Platform typing constraint, @@ -25,7 +31,7 @@ export class Plugin { this.chrome = chrome; } - public start(core: LegacyCoreStart, plugins: PluginsStart) { + public start(core: StartCore, plugins: StartPlugins) { // @ts-ignore improper type description this.chrome.setRootTemplate(template); const checkForRoot = () => { diff --git a/x-pack/legacy/plugins/siem/public/apps/start_app.tsx b/x-pack/legacy/plugins/siem/public/apps/start_app.tsx index 4549db946b81..6b7e3a7b8084 100644 --- a/x-pack/legacy/plugins/siem/public/apps/start_app.tsx +++ b/x-pack/legacy/plugins/siem/public/apps/start_app.tsx @@ -9,8 +9,6 @@ import React, { memo, FC } from 'react'; import { ApolloProvider } from 'react-apollo'; import { Provider as ReduxStoreProvider } from 'react-redux'; import { ThemeProvider } from 'styled-components'; -import { LegacyCoreStart } from 'kibana/public'; -import { PluginsStart } from 'ui/new_platform/new_platform'; import { EuiErrorBoundary } from '@elastic/eui'; import euiDarkVars from '@elastic/eui/dist/eui_theme_dark.json'; @@ -19,16 +17,14 @@ import { BehaviorSubject } from 'rxjs'; import { pluck } from 'rxjs/operators'; import { I18nContext } from 'ui/i18n'; -import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; +import { KibanaContextProvider, useUiSetting$ } from '../lib/kibana'; import { Storage } from '../../../../../../src/plugins/kibana_utils/public'; import { DEFAULT_DARK_MODE } from '../../common/constants'; import { ErrorToastDispatcher } from '../components/error_toast_dispatcher'; import { compose } from '../lib/compose/kibana_compose'; import { AppFrontendLibs } from '../lib/lib'; -import { KibanaCoreContextProvider } from '../lib/compose/kibana_core'; -import { KibanaPluginsContextProvider } from '../lib/compose/kibana_plugins'; -import { useKibanaUiSetting } from '../lib/settings/use_kibana_ui_setting'; +import { StartCore, StartPlugins } from './plugin'; import { PageRouter } from '../routes'; import { createStore } from '../store'; import { GlobalToaster, ManageGlobalToaster } from '../components/toasters'; @@ -44,7 +40,7 @@ const StartApp: FC = memo(libs => { const store = createStore(undefined, libs$.pipe(pluck('apolloClient'))); const AppPluginRoot = memo(() => { - const [darkMode] = useKibanaUiSetting(DEFAULT_DARK_MODE); + const [darkMode] = useUiSetting$(DEFAULT_DARK_MODE); return ( @@ -77,21 +73,15 @@ const StartApp: FC = memo(libs => { export const ROOT_ELEMENT_ID = 'react-siem-root'; -export const SiemApp = memo<{ core: LegacyCoreStart; plugins: PluginsStart }>( - ({ core, plugins }) => ( - - - - - - - - ) -); +export const SiemApp = memo<{ core: StartCore; plugins: StartPlugins }>(({ core, plugins }) => ( + + + +)); diff --git a/x-pack/legacy/plugins/siem/public/components/bytes/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/bytes/index.test.tsx index 2321b06c07cc..6816bff24f1c 100644 --- a/x-pack/legacy/plugins/siem/public/components/bytes/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/bytes/index.test.tsx @@ -12,8 +12,6 @@ import { useMountAppended } from '../../utils/use_mount_appended'; import { Bytes } from '.'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('Bytes', () => { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/charts/areachart.test.tsx b/x-pack/legacy/plugins/siem/public/components/charts/areachart.test.tsx index 25bd2a9d5605..2b99efc05fd8 100644 --- a/x-pack/legacy/plugins/siem/public/components/charts/areachart.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/charts/areachart.test.tsx @@ -11,6 +11,8 @@ import { AreaChartBaseComponent, AreaChartComponent } from './areachart'; import { ChartSeriesData } from './common'; import { ScaleType, AreaSeries, Axis } from '@elastic/charts'; +jest.mock('../../lib/kibana'); + const customHeight = '100px'; const customWidth = '120px'; const chartDataSets = [ diff --git a/x-pack/legacy/plugins/siem/public/components/charts/areachart.tsx b/x-pack/legacy/plugins/siem/public/components/charts/areachart.tsx index c644d148cc1c..297563c8e31c 100644 --- a/x-pack/legacy/plugins/siem/public/components/charts/areachart.tsx +++ b/x-pack/legacy/plugins/siem/public/components/charts/areachart.tsx @@ -21,7 +21,6 @@ import { getOr, get, isNull, isNumber } from 'lodash/fp'; import { AutoSizer } from '../auto_sizer'; import { ChartPlaceHolder } from './chart_place_holder'; import { - browserTimezone, chartDefaultSettings, ChartSeriesConfigs, ChartSeriesData, @@ -29,6 +28,8 @@ import { getChartWidth, getSeriesStyle, WrappedByAutoSizer, + useTheme, + useBrowserTimeZone, } from './common'; // custom series styles: https://ela.st/areachart-styling @@ -72,12 +73,15 @@ export const AreaChartBaseComponent = ({ height: string | null | undefined; configs?: ChartSeriesConfigs | undefined; }) => { + const theme = useTheme(); + const timeZone = useBrowserTimeZone(); const xTickFormatter = get('configs.axis.xTickFormatter', chartConfigs); const yTickFormatter = get('configs.axis.yTickFormatter', chartConfigs); const xAxisId = getAxisId(`group-${data[0].key}-x`); const yAxisId = getAxisId(`group-${data[0].key}-y`); const settings = { ...chartDefaultSettings, + theme, ...get('configs.settings', chartConfigs), }; return chartConfigs.width && chartConfigs.height ? ( @@ -95,7 +99,7 @@ export const AreaChartBaseComponent = ({ data={series.value || undefined} xScaleType={getOr(ScaleType.Linear, 'configs.series.xScaleType', chartConfigs)} yScaleType={getOr(ScaleType.Linear, 'configs.series.yScaleType', chartConfigs)} - timeZone={browserTimezone} + timeZone={timeZone} xAccessor="x" yAccessors={['y']} areaSeriesStyle={getSeriesLineStyle()} diff --git a/x-pack/legacy/plugins/siem/public/components/charts/barchart.test.tsx b/x-pack/legacy/plugins/siem/public/components/charts/barchart.test.tsx index e28d330d31ba..506b1ceb5ed8 100644 --- a/x-pack/legacy/plugins/siem/public/components/charts/barchart.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/charts/barchart.test.tsx @@ -11,6 +11,8 @@ import { BarChartBaseComponent, BarChartComponent } from './barchart'; import { ChartSeriesData } from './common'; import { BarSeries, ScaleType, Axis } from '@elastic/charts'; +jest.mock('../../lib/kibana'); + const customHeight = '100px'; const customWidth = '120px'; const chartDataSets = [ diff --git a/x-pack/legacy/plugins/siem/public/components/charts/barchart.tsx b/x-pack/legacy/plugins/siem/public/components/charts/barchart.tsx index 99ad995e4885..ee8b4eaf6b08 100644 --- a/x-pack/legacy/plugins/siem/public/components/charts/barchart.tsx +++ b/x-pack/legacy/plugins/siem/public/components/charts/barchart.tsx @@ -19,16 +19,17 @@ import { getOr, get, isNumber } from 'lodash/fp'; import { AutoSizer } from '../auto_sizer'; import { ChartPlaceHolder } from './chart_place_holder'; import { - browserTimezone, chartDefaultSettings, ChartSeriesConfigs, ChartSeriesData, checkIfAllValuesAreZero, - getSeriesStyle, getChartHeight, getChartWidth, + getSeriesStyle, SeriesType, WrappedByAutoSizer, + useBrowserTimeZone, + useTheme, } from './common'; const checkIfAllTheDataInTheSeriesAreValid = (series: ChartSeriesData): series is ChartSeriesData => @@ -53,6 +54,8 @@ export const BarChartBaseComponent = ({ height: string | null | undefined; configs?: ChartSeriesConfigs | undefined; }) => { + const theme = useTheme(); + const timeZone = useBrowserTimeZone(); const xTickFormatter = get('configs.axis.xTickFormatter', chartConfigs); const yTickFormatter = get('configs.axis.yTickFormatter', chartConfigs); const tickSize = getOr(0, 'configs.axis.tickSize', chartConfigs); @@ -60,6 +63,7 @@ export const BarChartBaseComponent = ({ const yAxisId = getAxisId(`stat-items-barchart-${data[0].key}-y`); const settings = { ...chartDefaultSettings, + theme, ...get('configs.settings', chartConfigs), }; @@ -79,7 +83,7 @@ export const BarChartBaseComponent = ({ yScaleType={getOr(ScaleType.Linear, 'configs.series.yScaleType', chartConfigs)} xAccessor="x" yAccessors={['y']} - timeZone={browserTimezone} + timeZone={timeZone} splitSeriesAccessors={['g']} data={series.value!} stackAccessors={get('configs.series.stackAccessors', chartConfigs)} diff --git a/x-pack/legacy/plugins/siem/public/components/charts/common.test.tsx b/x-pack/legacy/plugins/siem/public/components/charts/common.test.tsx index 0bb4da69a978..e9df0d3885a1 100644 --- a/x-pack/legacy/plugins/siem/public/components/charts/common.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/charts/common.test.tsx @@ -5,23 +5,27 @@ */ import { shallow } from 'enzyme'; import React from 'react'; +import { renderHook } from '@testing-library/react-hooks'; + +import { useUiSetting } from '../../lib/kibana'; import { checkIfAllValuesAreZero, defaultChartHeight, getChartHeight, getChartWidth, getSeriesStyle, - getTheme, SeriesType, WrappedByAutoSizer, ChartSeriesData, + useTheme, } from './common'; -import { mergeWithDefaultTheme, LIGHT_THEME } from '@elastic/charts'; + +jest.mock('../../lib/kibana'); jest.mock('@elastic/charts', () => { return { + ...jest.requireActual('@elastic/charts'), getSpecId: jest.fn(() => {}), - mergeWithDefaultTheme: jest.fn(), }; }); @@ -57,21 +61,6 @@ describe('getSeriesStyle', () => { }); }); -describe('getTheme', () => { - it('should merge custom theme with default theme', () => { - const defaultTheme = { - chartMargins: { bottom: 0, left: 0, right: 0, top: 4 }, - chartPaddings: { bottom: 0, left: 0, right: 0, top: 0 }, - scales: { - barsPadding: 0.05, - }, - }; - getTheme(); - expect((mergeWithDefaultTheme as jest.Mock).mock.calls[0][0]).toMatchObject(defaultTheme); - expect((mergeWithDefaultTheme as jest.Mock).mock.calls[0][1]).toEqual(LIGHT_THEME); - }); -}); - describe('getChartHeight', () => { it('should render customHeight', () => { const height = getChartHeight(10, 100); @@ -197,4 +186,23 @@ describe('checkIfAllValuesAreZero', () => { expect(result).toBeTruthy(); }); }); + + describe('useTheme', () => { + it('merges our spacing with the default theme', () => { + const { result } = renderHook(() => useTheme()); + + expect(result.current).toEqual( + expect.objectContaining({ chartMargins: expect.objectContaining({ top: 4, bottom: 0 }) }) + ); + }); + + it('returns a different theme depending on user settings', () => { + const { result: defaultResult } = renderHook(() => useTheme()); + (useUiSetting as jest.Mock).mockImplementation(() => true); + + const { result: darkResult } = renderHook(() => useTheme()); + + expect(defaultResult.current).not.toMatchObject(darkResult.current); + }); + }); }); diff --git a/x-pack/legacy/plugins/siem/public/components/charts/common.tsx b/x-pack/legacy/plugins/siem/public/components/charts/common.tsx index 7ac91437920e..dfb201fc3d92 100644 --- a/x-pack/legacy/plugins/siem/public/components/charts/common.tsx +++ b/x-pack/legacy/plugins/siem/public/components/charts/common.tsx @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import chrome from 'ui/chrome'; import { CustomSeriesColorsMap, DARK_THEME, @@ -21,6 +20,7 @@ import { } from '@elastic/charts'; import moment from 'moment-timezone'; import styled from 'styled-components'; +import { useUiSetting } from '../../lib/kibana'; import { DEFAULT_DATE_FORMAT_TZ, DEFAULT_DARK_MODE } from '../../../common/constants'; export const defaultChartHeight = '100%'; @@ -95,27 +95,28 @@ export const getSeriesStyle = ( }; // Apply margins and paddings: https://ela.st/charts-spacing -export const getTheme = () => { - const theme: PartialTheme = { - chartMargins: { - left: 0, - right: 0, - // Apply some paddings to the top to avoid chopping the y tick https://ela.st/chopping-edge - top: 4, - bottom: 0, - }, - chartPaddings: { - left: 0, - right: 0, - top: 0, - bottom: 0, - }, - scales: { - barsPadding: 0.05, - }, - }; - const isDarkMode: boolean = chrome.getUiSettingsClient().get(DEFAULT_DARK_MODE); +const theme: PartialTheme = { + chartMargins: { + left: 0, + right: 0, + // Apply some paddings to the top to avoid chopping the y tick https://ela.st/chopping-edge + top: 4, + bottom: 0, + }, + chartPaddings: { + left: 0, + right: 0, + top: 0, + bottom: 0, + }, + scales: { + barsPadding: 0.05, + }, +}; +export const useTheme = () => { + const isDarkMode = useUiSetting(DEFAULT_DARK_MODE); const defaultTheme = isDarkMode ? DARK_THEME : LIGHT_THEME; + return mergeWithDefaultTheme(theme, defaultTheme); }; @@ -126,11 +127,12 @@ export const chartDefaultSettings = { showLegend: false, showLegendDisplayValue: false, debug: false, - theme: getTheme(), }; -const kibanaTimezone: string = chrome.getUiSettingsClient().get(DEFAULT_DATE_FORMAT_TZ); -export const browserTimezone = kibanaTimezone === 'Browser' ? moment.tz.guess() : kibanaTimezone; +export const useBrowserTimeZone = () => { + const kibanaTimezone = useUiSetting(DEFAULT_DATE_FORMAT_TZ); + return kibanaTimezone === 'Browser' ? moment.tz.guess() : kibanaTimezone; +}; export const getChartHeight = (customHeight?: number, autoSizerHeight?: number): string => { const height = customHeight || autoSizerHeight; diff --git a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar.test.tsx b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar.test.tsx index 68522377bd84..a5eac381f921 100644 --- a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar.test.tsx @@ -9,7 +9,6 @@ import { mount, shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../../mock/ui_settings'; import { TestProviders } from '../../../mock'; import { UtilityBar, @@ -19,8 +18,6 @@ import { UtilityBarText, } from './index'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('UtilityBar', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_action.test.tsx b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_action.test.tsx index 7921c1ef4220..2610fb44532f 100644 --- a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_action.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_action.test.tsx @@ -8,12 +8,9 @@ import { mount, shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../../mock/ui_settings'; import { TestProviders } from '../../../mock'; import { UtilityBarAction } from './index'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('UtilityBarAction', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_group.test.tsx b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_group.test.tsx index 294d27fa95b3..59ef7021d404 100644 --- a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_group.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_group.test.tsx @@ -8,12 +8,9 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../../mock/ui_settings'; import { TestProviders } from '../../../mock'; import { UtilityBarGroup, UtilityBarText } from './index'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('UtilityBarGroup', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_section.test.tsx b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_section.test.tsx index e0e0acc3a71c..baa4331ced8f 100644 --- a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_section.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_section.test.tsx @@ -8,12 +8,9 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../../mock/ui_settings'; import { TestProviders } from '../../../mock'; import { UtilityBarGroup, UtilityBarSection, UtilityBarText } from './index'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('UtilityBarSection', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_text.test.tsx b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_text.test.tsx index 29e1844bb2d4..794f207fd88e 100644 --- a/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_text.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/detection_engine/utility_bar/utility_bar_text.test.tsx @@ -8,12 +8,9 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../../mock/ui_settings'; import { TestProviders } from '../../../mock'; import { UtilityBarText } from './index'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('UtilityBarText', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/embedded_map.test.tsx.snap b/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/embedded_map.test.tsx.snap index 2444fd0bc2b7..d5de7ab508a7 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/embedded_map.test.tsx.snap +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/embedded_map.test.tsx.snap @@ -9,7 +9,7 @@ exports[`EmbeddedMapComponent renders correctly against snapshot 1`] = ` size="xs" > Map configuration help diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/index_patterns_missing_prompt.test.tsx.snap b/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/index_patterns_missing_prompt.test.tsx.snap index 6794aab20570..2eefdf767dce 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/index_patterns_missing_prompt.test.tsx.snap +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/__snapshots__/index_patterns_missing_prompt.test.tsx.snap @@ -21,7 +21,7 @@ exports[`IndexPatternsMissingPrompt renders correctly against snapshot 1`] = ` values={ Object { "beats": diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable.test.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable.test.tsx index c0d70754e78b..884d5bc348d6 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable.test.tsx @@ -8,11 +8,8 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../mock/ui_settings'; import { Embeddable } from './embeddable'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('Embeddable', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable_header.test.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable_header.test.tsx index 6387de30aa26..aa247b69eb4e 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable_header.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/embeddable_header.test.tsx @@ -8,12 +8,9 @@ import { mount, shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../mock/ui_settings'; import { TestProviders } from '../../mock'; import { EmbeddableHeader } from './embeddable_header'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('EmbeddableHeader', () => { test('it renders', () => { const wrapper = shallow(); diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx index 1ed1075542f7..007916595fd6 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.test.tsx @@ -7,10 +7,10 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import * as React from 'react'; + +import { useIndexPatterns } from '../../hooks/use_index_patterns'; import { EmbeddedMapComponent } from './embedded_map'; import { SetQuery } from './types'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; -import { useIndexPatterns } from '../../hooks/use_index_patterns'; jest.mock('../search_bar', () => ({ siemFilterManager: { @@ -22,22 +22,7 @@ const mockUseIndexPatterns = useIndexPatterns as jest.Mock; jest.mock('../../hooks/use_index_patterns'); mockUseIndexPatterns.mockImplementation(() => [true, []]); -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: { - get$: () => 'world', - }, - injectedMetadata: { - getKibanaVersion: () => '8.0.0', - }, -})); - -jest.mock('../../lib/compose/kibana_plugins'); - -jest.mock('ui/vis/lib/timezone', () => ({ - timezoneProvider: () => () => 'America/New_York', -})); +jest.mock('../../lib/kibana'); describe('EmbeddedMapComponent', () => { let setQuery: SetQuery; diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.tsx index e33539af0bfe..b39d43cc01b4 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map.tsx @@ -8,16 +8,12 @@ import { EuiLink, EuiText } from '@elastic/eui'; import React, { useEffect, useState } from 'react'; import { createPortalNode, InPortal } from 'react-reverse-portal'; import styled, { css } from 'styled-components'; -import { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } from 'ui/documentation_links'; import { EmbeddablePanel } from '../../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public'; import { start } from '../../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public/legacy'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { getIndexPatternTitleIdMapping } from '../../hooks/api/helpers'; import { useIndexPatterns } from '../../hooks/use_index_patterns'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; -import { useKibanaPlugins } from '../../lib/compose/kibana_plugins'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; import { Loader } from '../loader'; import { useStateToaster } from '../toasters'; import { Embeddable } from './embeddable'; @@ -28,6 +24,7 @@ import { MapToolTip } from './map_tool_tip/map_tool_tip'; import * as i18n from './translations'; import { MapEmbeddable, SetQuery } from './types'; import { Query, esFilters } from '../../../../../../../src/plugins/data/public'; +import { useKibana, useUiSetting$ } from '../../lib/kibana'; import { SavedObjectFinderProps, SavedObjectFinderUi, @@ -96,7 +93,7 @@ export const EmbeddedMapComponent = ({ const [, dispatchToaster] = useStateToaster(); const [loadingKibanaIndexPatterns, kibanaIndexPatterns] = useIndexPatterns(); - const [siemDefaultIndices] = useKibanaUiSetting(DEFAULT_INDEX_KEY); + const [siemDefaultIndices] = useUiSetting$(DEFAULT_INDEX_KEY); // This portalNode provided by react-reverse-portal allows us re-parent the MapToolTip within our // own component tree instead of the embeddables (default). This is necessary to have access to @@ -104,8 +101,7 @@ export const EmbeddedMapComponent = ({ // Search InPortal/OutPortal for implementation touch points const portalNode = React.useMemo(() => createPortalNode(), []); - const plugins = useKibanaPlugins(); - const core = useKibanaCore(); + const { services } = useKibana(); // Initial Load useEffect useEffect(() => { @@ -131,7 +127,7 @@ export const EmbeddedMapComponent = ({ endDate, setQuery, portalNode, - plugins.embeddable + services.embeddable ); if (isSubscribed) { setEmbeddable(embeddableObject); @@ -180,7 +176,11 @@ export const EmbeddedMapComponent = ({ }, [startDate, endDate]); const SavedObjectFinder = (props: SavedObjectFinderProps) => ( - + ); return isError ? null : ( @@ -188,7 +188,7 @@ export const EmbeddedMapComponent = ({ {i18n.EMBEDDABLE_HEADER_HELP} @@ -205,12 +205,12 @@ export const EmbeddedMapComponent = ({ ) : !isLoading && isIndexError ? ( diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map_helpers.test.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map_helpers.test.tsx index b4b2b98ddb8d..4e5fcee43982 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map_helpers.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/embedded_map_helpers.test.tsx @@ -9,7 +9,6 @@ import { createUiNewPlatformMock } from 'ui/new_platform/__mocks__/helpers'; import { createPortalNode } from 'react-reverse-portal'; jest.mock('ui/new_platform'); -jest.mock('../../lib/settings/use_kibana_ui_setting'); jest.mock('uuid', () => { return { diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.test.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.test.tsx index d32b62900431..d04329edff47 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.test.tsx @@ -7,12 +7,10 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import * as React from 'react'; + import { IndexPatternsMissingPromptComponent } from './index_patterns_missing_prompt'; -jest.mock('ui/documentation_links', () => ({ - ELASTIC_WEBSITE_URL: 'https://www.elastic.co', - DOC_LINK_VERSION: 'current', -})); +jest.mock('../../lib/kibana'); describe('IndexPatternsMissingPrompt', () => { test('renders correctly against snapshot', () => { diff --git a/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.tsx b/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.tsx index 6533be49c343..798e3d2c10f9 100644 --- a/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.tsx +++ b/x-pack/legacy/plugins/siem/public/components/embeddables/index_patterns_missing_prompt.tsx @@ -8,66 +8,70 @@ import { EuiButton, EuiCode, EuiEmptyPrompt } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import * as React from 'react'; import chrome from 'ui/chrome'; -import { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } from 'ui/documentation_links'; +import { useKibana } from '../../lib/kibana'; import * as i18n from './translations'; -export const IndexPatternsMissingPromptComponent = () => ( - {i18n.ERROR_TITLE}} - titleSize="xs" - body={ - <> -

- - {'siem:defaultIndex'} - - ), - beats: ( - - {'beats'} - - ), - setup: {'setup'}, - example: {'./packetbeat setup'}, - }} - /> -

+export const IndexPatternsMissingPromptComponent = () => { + const docLinks = useKibana().services.docLinks; -

- -

- - } - actions={ - - {i18n.ERROR_BUTTON} - - } - /> -); + return ( + {i18n.ERROR_TITLE}} + titleSize="xs" + body={ + <> +

+ + {'siem:defaultIndex'} + + ), + beats: ( + + {'beats'} + + ), + setup: {'setup'}, + example: {'./packetbeat setup'}, + }} + /> +

+ +

+ +

+ + } + actions={ + + {i18n.ERROR_BUTTON} + + } + /> + ); +}; IndexPatternsMissingPromptComponent.displayName = 'IndexPatternsMissingPromptComponent'; diff --git a/x-pack/legacy/plugins/siem/public/components/event_details/event_details.test.tsx b/x-pack/legacy/plugins/siem/public/components/event_details/event_details.test.tsx index f1e96392d6af..d97da7797bb4 100644 --- a/x-pack/legacy/plugins/siem/public/components/event_details/event_details.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/event_details/event_details.test.tsx @@ -16,8 +16,6 @@ import { mockBrowserFields } from '../../containers/source/mock'; import { defaultHeaders } from '../../mock/header'; import { useMountAppended } from '../../utils/use_mount_appended'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('EventDetails', () => { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/event_details/event_fields_browser.test.tsx b/x-pack/legacy/plugins/siem/public/components/event_details/event_fields_browser.test.tsx index 2c28ab8696f0..25f95bfa1d38 100644 --- a/x-pack/legacy/plugins/siem/public/components/event_details/event_fields_browser.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/event_details/event_fields_browser.test.tsx @@ -14,7 +14,7 @@ import { mockBrowserFields } from '../../containers/source/mock'; import { defaultHeaders } from '../../mock/header'; import { useMountAppended } from '../../utils/use_mount_appended'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../lib/kibana'); describe('EventFieldsBrowser', () => { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.test.tsx b/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.test.tsx index 5ddf17bd77d7..b44d83c27a60 100644 --- a/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.test.tsx @@ -8,25 +8,17 @@ import React from 'react'; import { MockedProvider } from 'react-apollo/test-utils'; import { mockIndexPattern, TestProviders } from '../../mock'; -import { mockUiSettings } from '../../mock/ui_settings'; import { wait } from '../../lib/helpers'; import { mockEventViewerResponse } from './mock'; import { StatefulEventsViewer } from '.'; import { defaultHeaders } from './default_headers'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; import { useFetchIndexPatterns } from '../../containers/detection_engine/rules/fetch_index_patterns'; import { mockBrowserFields } from '../../containers/source/mock'; import { eventsDefaultModel } from './default_model'; import { useMountAppended } from '../../utils/use_mount_appended'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); +jest.mock('../../lib/kibana'); const mockUseFetchIndexPatterns: jest.Mock = useFetchIndexPatterns as jest.Mock; jest.mock('../../containers/detection_engine/rules/fetch_index_patterns'); diff --git a/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.tsx b/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.tsx index 7c4369e952d6..aaf88e68684c 100644 --- a/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.tsx +++ b/x-pack/legacy/plugins/siem/public/components/events_viewer/events_viewer.tsx @@ -12,7 +12,7 @@ import styled from 'styled-components'; import { BrowserFields } from '../../containers/source'; import { TimelineQuery } from '../../containers/timeline'; import { Direction } from '../../graphql/types'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; +import { useKibana } from '../../lib/kibana'; import { KqlMode } from '../../store/timeline/model'; import { AutoSizer } from '../auto_sizer'; import { HeaderSection } from '../header_section'; @@ -93,9 +93,9 @@ export const EventsViewer = React.memo( utilityBar, }) => { const columnsHeader = isEmpty(columns) ? defaultHeaders : columns; - const core = useKibanaCore(); + const kibana = useKibana(); const combinedQueries = combineQueries({ - config: esQuery.getEsQueryConfig(core.uiSettings), + config: esQuery.getEsQueryConfig(kibana.services.uiSettings), dataProviders, indexPattern, browserFields, diff --git a/x-pack/legacy/plugins/siem/public/components/events_viewer/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/events_viewer/index.test.tsx index e46153c18c2b..27c3abf7f682 100644 --- a/x-pack/legacy/plugins/siem/public/components/events_viewer/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/events_viewer/index.test.tsx @@ -7,10 +7,8 @@ import React from 'react'; import { MockedProvider } from 'react-apollo/test-utils'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; import { wait } from '../../lib/helpers'; import { mockIndexPattern, TestProviders } from '../../mock'; -import { mockUiSettings } from '../../mock/ui_settings'; import { useMountAppended } from '../../utils/use_mount_appended'; import { mockEventViewerResponse } from './mock'; @@ -19,13 +17,7 @@ import { useFetchIndexPatterns } from '../../containers/detection_engine/rules/f import { mockBrowserFields } from '../../containers/source/mock'; import { eventsDefaultModel } from './default_model'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); +jest.mock('../../lib/kibana'); const mockUseFetchIndexPatterns: jest.Mock = useFetchIndexPatterns as jest.Mock; jest.mock('../../containers/detection_engine/rules/fetch_index_patterns'); diff --git a/x-pack/legacy/plugins/siem/public/components/events_viewer/index.tsx b/x-pack/legacy/plugins/siem/public/components/events_viewer/index.tsx index 385352a62d5b..9b8ec243d5f3 100644 --- a/x-pack/legacy/plugins/siem/public/components/events_viewer/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/events_viewer/index.tsx @@ -8,7 +8,6 @@ import { isEqual } from 'lodash/fp'; import React, { useCallback, useEffect, useState } from 'react'; import { connect } from 'react-redux'; import { ActionCreator } from 'typescript-fsa'; -import chrome from 'ui/chrome'; import { inputsModel, inputsSelectors, State, timelineSelectors } from '../../store'; import { inputsActions, timelineActions } from '../../store/actions'; import { KqlMode, SubsetTimelineModel, TimelineModel } from '../../store/timeline/model'; @@ -18,6 +17,7 @@ import { Sort } from '../timeline/body/sort'; import { OnChangeItemsPerPage } from '../timeline/events'; import { esFilters, Query } from '../../../../../../../src/plugins/data/public'; +import { useUiSetting } from '../../lib/kibana'; import { EventsViewer } from './events_viewer'; import { InputsModelId } from '../../store/inputs/constants'; import { useFetchIndexPatterns } from '../../containers/detection_engine/rules/fetch_index_patterns'; @@ -116,7 +116,7 @@ const StatefulEventsViewerComponent = React.memo( }) => { const [showInspect, setShowInspect] = useState(false); const [{ browserFields, indexPatterns }] = useFetchIndexPatterns( - defaultIndices ?? chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY) + defaultIndices ?? useUiSetting(DEFAULT_INDEX_KEY) ); useEffect(() => { diff --git a/x-pack/legacy/plugins/siem/public/components/flyout/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/flyout/index.test.tsx index 86a8952a10ef..be7e8fac70bf 100644 --- a/x-pack/legacy/plugins/siem/public/components/flyout/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/flyout/index.test.tsx @@ -20,8 +20,6 @@ import { FlyoutButton } from './button'; const testFlyoutHeight = 980; const usersViewing = ['elastic']; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('Flyout', () => { const state: State = mockGlobalState; diff --git a/x-pack/legacy/plugins/siem/public/components/flyout/pane/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/flyout/pane/index.test.tsx index 66e9bc700b3a..246261035508 100644 --- a/x-pack/legacy/plugins/siem/public/components/flyout/pane/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/flyout/pane/index.test.tsx @@ -8,26 +8,15 @@ import { mount, shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import * as React from 'react'; -import { flyoutHeaderHeight } from '../'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; import { TestProviders } from '../../../mock'; -import { mockUiSettings } from '../../../mock/ui_settings'; +import { flyoutHeaderHeight } from '..'; import { Pane } from '.'; const testFlyoutHeight = 980; const testWidth = 640; const usersViewing = ['elastic']; -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('ui/new_platform'); -jest.mock('../../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); - -jest.mock('ui/vis/lib/timezone', () => ({ - timezoneProvider: () => () => 'America/New_York', -})); +jest.mock('../../../lib/kibana'); describe('Pane', () => { test('renders correctly against snapshot', () => { diff --git a/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.test.tsx index a517820361f9..8c27a55d3a6b 100644 --- a/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.test.tsx @@ -8,27 +8,25 @@ import { mount, shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import * as React from 'react'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; import { mockFrameworks, getMockKibanaUiSetting } from '../../mock'; +import { useUiSetting$ } from '../../lib/kibana'; import { PreferenceFormattedBytesComponent } from '.'; -const mockUseKibanaUiSetting: jest.Mock = useKibanaUiSetting as jest.Mock; -jest.mock('../../lib/settings/use_kibana_ui_setting', () => ({ - useKibanaUiSetting: jest.fn(), -})); +jest.mock('../../lib/kibana'); +const mockUseUiSetting$ = useUiSetting$ as jest.Mock; describe('formatted_bytes', () => { describe('PreferenceFormattedBytes', () => { describe('rendering', () => { beforeEach(() => { - mockUseKibanaUiSetting.mockClear(); + mockUseUiSetting$.mockClear(); }); const bytes = '2806422'; test('renders correctly against snapshot', () => { - mockUseKibanaUiSetting.mockImplementation( + mockUseUiSetting$.mockImplementation( getMockKibanaUiSetting(mockFrameworks.default_browser) ); const wrapper = shallow(); @@ -36,13 +34,13 @@ describe('formatted_bytes', () => { }); test('it renders bytes to hardcoded format when no configuration exists', () => { - mockUseKibanaUiSetting.mockImplementation(() => [null]); + mockUseUiSetting$.mockImplementation(() => [null]); const wrapper = mount(); expect(wrapper.text()).toEqual('2.7MB'); }); test('it renders bytes according to the default format', () => { - mockUseKibanaUiSetting.mockImplementation( + mockUseUiSetting$.mockImplementation( getMockKibanaUiSetting(mockFrameworks.default_browser) ); const wrapper = mount(); @@ -50,7 +48,7 @@ describe('formatted_bytes', () => { }); test('it renders bytes supplied as a number according to the default format', () => { - mockUseKibanaUiSetting.mockImplementation( + mockUseUiSetting$.mockImplementation( getMockKibanaUiSetting(mockFrameworks.default_browser) ); const wrapper = mount(); @@ -58,9 +56,7 @@ describe('formatted_bytes', () => { }); test('it renders bytes according to new format', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.bytes_short) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.bytes_short)); const wrapper = mount(); expect(wrapper.text()).toEqual('3MB'); }); diff --git a/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.tsx b/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.tsx index 408e8d7ad4d8..003ce0879b7b 100644 --- a/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/formatted_bytes/index.tsx @@ -8,10 +8,10 @@ import * as React from 'react'; import numeral from '@elastic/numeral'; import { DEFAULT_BYTES_FORMAT } from '../../../common/constants'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../lib/kibana'; export const PreferenceFormattedBytesComponent = ({ value }: { value: string | number }) => { - const [bytesFormat] = useKibanaUiSetting(DEFAULT_BYTES_FORMAT); + const [bytesFormat] = useUiSetting$(DEFAULT_BYTES_FORMAT); return ( <>{bytesFormat ? numeral(value).format(bytesFormat) : numeral(value).format('0,0.[0]b')} ); diff --git a/x-pack/legacy/plugins/siem/public/components/formatted_date/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/formatted_date/index.test.tsx index df361a06d380..dad1d5feb5c6 100644 --- a/x-pack/legacy/plugins/siem/public/components/formatted_date/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/formatted_date/index.test.tsx @@ -9,24 +9,18 @@ import toJson from 'enzyme-to-json'; import moment from 'moment-timezone'; import * as React from 'react'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../lib/kibana'; import { mockFrameworks, TestProviders, MockFrameworks, getMockKibanaUiSetting } from '../../mock'; - -import { PreferenceFormattedDate, FormattedDate, FormattedRelativePreferenceDate } from '.'; import { getEmptyString, getEmptyValue } from '../empty_value'; +import { PreferenceFormattedDate, FormattedDate, FormattedRelativePreferenceDate } from '.'; -const mockUseKibanaUiSetting: jest.Mock = useKibanaUiSetting as jest.Mock; -jest.mock('../../lib/settings/use_kibana_ui_setting', () => ({ - useKibanaUiSetting: jest.fn(), -})); +jest.mock('../../lib/kibana'); +const mockUseUiSetting$ = useUiSetting$ as jest.Mock; describe('formatted_date', () => { describe('PreferenceFormattedDate', () => { describe('rendering', () => { - beforeEach(() => { - mockUseKibanaUiSetting.mockClear(); - }); const isoDateString = '2019-02-25T22:27:05.000Z'; const isoDate = new Date(isoDateString); const configFormattedDateString = (dateString: string, config: MockFrameworks): string => @@ -38,21 +32,19 @@ describe('formatted_date', () => { .format(config.dateFormat); test('renders correctly against snapshot', () => { - mockUseKibanaUiSetting.mockImplementation(() => [null]); + mockUseUiSetting$.mockImplementation(() => [null]); const wrapper = mount(); expect(toJson(wrapper)).toMatchSnapshot(); }); test('it renders the UTC ISO8601 date string supplied when no configuration exists', () => { - mockUseKibanaUiSetting.mockImplementation(() => [null]); + mockUseUiSetting$.mockImplementation(() => [null]); const wrapper = mount(); expect(wrapper.text()).toEqual(isoDateString); }); test('it renders the UTC ISO8601 date supplied when the default configuration exists', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount(); expect(wrapper.text()).toEqual( @@ -61,7 +53,7 @@ describe('formatted_date', () => { }); test('it renders the correct tz when the default browser configuration exists', () => { - mockUseKibanaUiSetting.mockImplementation( + mockUseUiSetting$.mockImplementation( getMockKibanaUiSetting(mockFrameworks.default_browser) ); const wrapper = mount(); @@ -71,9 +63,7 @@ describe('formatted_date', () => { }); test('it renders the correct tz when a non-UTC configuration exists', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_MT) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_MT)); const wrapper = mount(); expect(wrapper.text()).toEqual( configFormattedDateString(isoDateString, mockFrameworks.default_MT) @@ -84,30 +74,20 @@ describe('formatted_date', () => { describe('FormattedDate', () => { describe('rendering', () => { - beforeEach(() => { - mockUseKibanaUiSetting.mockClear(); - }); - test('it renders against a numeric epoch', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount(); expect(wrapper.text()).toEqual('May 28, 2019 @ 21:35:39.000'); }); test('it renders against a string epoch', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount(); expect(wrapper.text()).toEqual('May 28, 2019 @ 21:35:39.000'); }); test('it renders against a ISO string', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount( ); @@ -115,9 +95,7 @@ describe('formatted_date', () => { }); test('it renders against an empty string as an empty string placeholder', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount( @@ -127,9 +105,7 @@ describe('formatted_date', () => { }); test('it renders against an null as a EMPTY_VALUE', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount( @@ -139,9 +115,7 @@ describe('formatted_date', () => { }); test('it renders against an undefined as a EMPTY_VALUE', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount( @@ -151,9 +125,7 @@ describe('formatted_date', () => { }); test('it renders against an invalid date time as just the string its self', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting(mockFrameworks.default_UTC) - ); + mockUseUiSetting$.mockImplementation(getMockKibanaUiSetting(mockFrameworks.default_UTC)); const wrapper = mount( diff --git a/x-pack/legacy/plugins/siem/public/components/formatted_date/index.tsx b/x-pack/legacy/plugins/siem/public/components/formatted_date/index.tsx index 37bf3653f3b6..19e8ec3f95d2 100644 --- a/x-pack/legacy/plugins/siem/public/components/formatted_date/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/formatted_date/index.tsx @@ -8,20 +8,21 @@ import moment from 'moment-timezone'; import * as React from 'react'; import { FormattedRelative } from '@kbn/i18n/react'; +import { useUiSetting$ } from '../../lib/kibana'; + import { DEFAULT_DATE_FORMAT, DEFAULT_DATE_FORMAT_TZ, DEFAULT_TIMEZONE_BROWSER, } from '../../../common/constants'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; import { getOrEmptyTagFromValue } from '../empty_value'; import { LocalizedDateTooltip } from '../localized_date_tooltip'; import { getMaybeDate } from './maybe_date'; export const PreferenceFormattedDate = React.memo<{ value: Date }>(({ value }) => { - const [dateFormat] = useKibanaUiSetting(DEFAULT_DATE_FORMAT); - const [dateFormatTz] = useKibanaUiSetting(DEFAULT_DATE_FORMAT_TZ); - const [timezone] = useKibanaUiSetting(DEFAULT_TIMEZONE_BROWSER); + const [dateFormat] = useUiSetting$(DEFAULT_DATE_FORMAT); + const [dateFormatTz] = useUiSetting$(DEFAULT_DATE_FORMAT_TZ); + const [timezone] = useUiSetting$(DEFAULT_TIMEZONE_BROWSER); return ( <> diff --git a/x-pack/legacy/plugins/siem/public/components/header_global/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/header_global/index.test.tsx index b3eb599af940..a45bed87829b 100644 --- a/x-pack/legacy/plugins/siem/public/components/header_global/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/header_global/index.test.tsx @@ -9,10 +9,9 @@ import toJson from 'enzyme-to-json'; import React from 'react'; import '../../mock/match_media'; -import '../../mock/ui_settings'; import { HeaderGlobal } from './index'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); +jest.mock('ui/new_platform'); // Test will fail because we will to need to mock some core services to make the test work // For now let's forget about SiemSearchBar diff --git a/x-pack/legacy/plugins/siem/public/components/header_page/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/header_page/index.test.tsx index 5644a344f91d..633ff90524de 100644 --- a/x-pack/legacy/plugins/siem/public/components/header_page/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/header_page/index.test.tsx @@ -10,12 +10,9 @@ import toJson from 'enzyme-to-json'; import React from 'react'; import { TestProviders } from '../../mock'; -import '../../mock/ui_settings'; import { HeaderPage } from './index'; import { useMountAppended } from '../../utils/use_mount_appended'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('HeaderPage', () => { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/header_section/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/header_section/index.test.tsx index 8606758c68d2..fbd8642c01fa 100644 --- a/x-pack/legacy/plugins/siem/public/components/header_section/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/header_section/index.test.tsx @@ -10,11 +10,8 @@ import toJson from 'enzyme-to-json'; import React from 'react'; import { TestProviders } from '../../mock'; -import '../../mock/ui_settings'; import { HeaderSection } from './index'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('HeaderSection', () => { test('it renders', () => { const wrapper = shallow(); diff --git a/x-pack/legacy/plugins/siem/public/components/last_event_time/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/last_event_time/index.test.tsx index e2ada4682fde..dcecc636d9f0 100644 --- a/x-pack/legacy/plugins/siem/public/components/last_event_time/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/last_event_time/index.test.tsx @@ -13,7 +13,6 @@ import { mockLastEventTimeQuery } from '../../containers/events/last_event_time/ import { useMountAppended } from '../../utils/use_mount_appended'; import { useLastEventTimeQuery } from '../../containers/events/last_event_time'; import { TestProviders } from '../../mock'; -import '../../mock/ui_settings'; import { LastEventTime } from '.'; diff --git a/x-pack/legacy/plugins/siem/public/components/link_icon/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/link_icon/index.test.tsx index 7f9133a0de7c..87761a51a431 100644 --- a/x-pack/legacy/plugins/siem/public/components/link_icon/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/link_icon/index.test.tsx @@ -9,11 +9,8 @@ import toJson from 'enzyme-to-json'; import React from 'react'; import { TestProviders } from '../../mock'; -import '../../mock/ui_settings'; import { LinkIcon } from './index'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('LinkIcon', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.test.tsx index bdd8a0c544ed..87d4e072e429 100644 --- a/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.test.tsx @@ -9,12 +9,7 @@ import * as React from 'react'; import { MatrixHistogram } from '.'; -jest.mock('@elastic/eui', () => { - return { - EuiPanel: (children: JSX.Element) => <>{children}, - EuiLoadingContent: () =>
, - }; -}); +jest.mock('../../lib/kibana'); jest.mock('../loader', () => { return { @@ -22,10 +17,6 @@ jest.mock('../loader', () => { }; }); -jest.mock('../../lib/settings/use_kibana_ui_setting', () => { - return { useKibanaUiSetting: () => [false] }; -}); - jest.mock('../header_section', () => { return { HeaderSection: () =>
, diff --git a/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.tsx b/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.tsx index e1ccfd79a89a..c29b5282e13a 100644 --- a/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/matrix_histogram/index.tsx @@ -14,7 +14,7 @@ import { BarChart } from '../charts/barchart'; import { HeaderSection } from '../header_section'; import { ChartSeriesData } from '../charts/common'; import { DEFAULT_DARK_MODE } from '../../../common/constants'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../lib/kibana'; import { Loader } from '../loader'; import { Panel } from '../panel'; import { getBarchartConfigs, getCustomChartData } from './utils'; @@ -45,7 +45,7 @@ export const MatrixHistogram = ({ showLegend, }); const [showInspect, setShowInspect] = useState(false); - const [darkMode] = useKibanaUiSetting(DEFAULT_DARK_MODE); + const [darkMode] = useUiSetting$(DEFAULT_DARK_MODE); const [loadingInitial, setLoadingInitial] = useState(false); const barChartData: ChartSeriesData[] = getCustomChartData(data, mapping); diff --git a/x-pack/legacy/plugins/siem/public/components/ml/anomaly/use_anomalies_table_data.ts b/x-pack/legacy/plugins/siem/public/components/ml/anomaly/use_anomalies_table_data.ts index 130c326339b1..bce99c943c7a 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/anomaly/use_anomalies_table_data.ts +++ b/x-pack/legacy/plugins/siem/public/components/ml/anomaly/use_anomalies_table_data.ts @@ -14,7 +14,7 @@ import { useStateToaster } from '../../toasters'; import { errorToToaster } from '../api/error_to_toaster'; import * as i18n from './translations'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_ANOMALY_SCORE, DEFAULT_TIMEZONE_BROWSER, @@ -67,9 +67,9 @@ export const useAnomaliesTableData = ({ const capabilities = useContext(MlCapabilitiesContext); const userPermissions = hasMlUserPermissions(capabilities); const [, dispatchToaster] = useStateToaster(); - const [timezone] = useKibanaUiSetting(DEFAULT_TIMEZONE_BROWSER); - const [anomalyScore] = useKibanaUiSetting(DEFAULT_ANOMALY_SCORE); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [timezone] = useUiSetting$(DEFAULT_TIMEZONE_BROWSER); + const [anomalyScore] = useUiSetting$(DEFAULT_ANOMALY_SCORE); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const siemJobIds = siemJobs.filter(job => job.isInstalled).map(job => job.id); diff --git a/x-pack/legacy/plugins/siem/public/components/ml/permissions/ml_capabilities_provider.tsx b/x-pack/legacy/plugins/siem/public/components/ml/permissions/ml_capabilities_provider.tsx index 352f39a75ded..b8d6908df464 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/permissions/ml_capabilities_provider.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/permissions/ml_capabilities_provider.tsx @@ -11,7 +11,7 @@ import { getMlCapabilities } from '../api/get_ml_capabilities'; import { emptyMlCapabilities } from '../empty_ml_capabilities'; import { errorToToaster } from '../api/error_to_toaster'; import { useStateToaster } from '../../toasters'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_KBN_VERSION } from '../../../../common/constants'; import * as i18n from './translations'; @@ -36,7 +36,7 @@ export const MlCapabilitiesProvider = React.memo<{ children: JSX.Element }>(({ c emptyMlCapabilitiesProvider ); const [, dispatchToaster] = useStateToaster(); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); useEffect(() => { let isSubscribed = true; diff --git a/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_score.test.tsx b/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_score.test.tsx index f7d9052b19a2..cf24d6c02a13 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_score.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_score.test.tsx @@ -17,8 +17,6 @@ import { Anomalies } from '../types'; const endDate: number = new Date('3000-01-01T00:00:00.000Z').valueOf(); const narrowDateRange = jest.fn(); -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('anomaly_scores', () => { let anomalies: Anomalies = cloneDeep(mockAnomalies); const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_scores.test.tsx b/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_scores.test.tsx index f01df3813845..759e84e36f4a 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_scores.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/score/anomaly_scores.test.tsx @@ -18,8 +18,6 @@ import { useMountAppended } from '../../../utils/use_mount_appended'; const endDate: number = new Date('3000-01-01T00:00:00.000Z').valueOf(); const narrowDateRange = jest.fn(); -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('anomaly_scores', () => { let anomalies: Anomalies = cloneDeep(mockAnomalies); const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/ml/score/create_descriptions_list.test.tsx b/x-pack/legacy/plugins/siem/public/components/ml/score/create_descriptions_list.test.tsx index d55c6972d5ca..f00fb62d74ac 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml/score/create_descriptions_list.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml/score/create_descriptions_list.test.tsx @@ -12,7 +12,7 @@ import { createDescriptionList } from './create_description_list'; import { EuiDescriptionList } from '@elastic/eui'; import { Anomaly } from '../types'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); const endDate: number = new Date('3000-01-01T00:00:00.000Z').valueOf(); diff --git a/x-pack/legacy/plugins/siem/public/components/ml_popover/hooks/use_siem_jobs.tsx b/x-pack/legacy/plugins/siem/public/components/ml_popover/hooks/use_siem_jobs.tsx index 0bef34a7edc4..f9d110d711d0 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml_popover/hooks/use_siem_jobs.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml_popover/hooks/use_siem_jobs.tsx @@ -12,7 +12,7 @@ import { hasMlUserPermissions } from '../../ml/permissions/has_ml_user_permissio import { MlCapabilitiesContext } from '../../ml/permissions/ml_capabilities_provider'; import { useStateToaster } from '../../toasters'; import { errorToToaster } from '../../ml/api/error_to_toaster'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_INDEX_KEY, DEFAULT_KBN_VERSION } from '../../../../common/constants'; import * as i18n from './translations'; @@ -33,8 +33,8 @@ export const useSiemJobs = (refetchData: boolean): Return => { const [loading, setLoading] = useState(true); const capabilities = useContext(MlCapabilitiesContext); const userPermissions = hasMlUserPermissions(capabilities); - const [siemDefaultIndex] = useKibanaUiSetting(DEFAULT_INDEX_KEY); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [siemDefaultIndex] = useUiSetting$(DEFAULT_INDEX_KEY); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [, dispatchToaster] = useStateToaster(); useEffect(() => { diff --git a/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.test.tsx b/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.test.tsx index 1a8360fe82c5..987c63be3f7b 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.test.tsx @@ -9,7 +9,8 @@ import { mountWithIntl } from 'test_utils/enzyme_helpers'; import { MlPopover } from './ml_popover'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); +jest.mock('ui/new_platform'); +jest.mock('../../lib/kibana'); jest.mock('../ml/permissions/has_ml_admin_permissions', () => ({ hasMlAdminPermissions: () => true, diff --git a/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.tsx b/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.tsx index 0b33ab83d2a4..c34ed51d2299 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.tsx +++ b/x-pack/legacy/plugins/siem/public/components/ml_popover/ml_popover.tsx @@ -9,10 +9,9 @@ import { FormattedMessage } from '@kbn/i18n/react'; import moment from 'moment'; import React, { useContext, useReducer, useState } from 'react'; import styled from 'styled-components'; -import { DOC_LINK_VERSION, ELASTIC_WEBSITE_URL } from 'ui/documentation_links'; import { DEFAULT_KBN_VERSION } from '../../../common/constants'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; +import { useKibana, useUiSetting$ } from '../../lib/kibana'; import { METRIC_TYPE, TELEMETRY_EVENT, trackUiAction as track } from '../../lib/track_usage'; import { errorToToaster } from '../ml/api/error_to_toaster'; import { hasMlAdminPermissions } from '../ml/permissions/has_ml_admin_permissions'; @@ -98,10 +97,11 @@ export const MlPopover = React.memo(() => { const [isPopoverOpen, setIsPopoverOpen] = useState(false); const [filterProperties, setFilterProperties] = useState(defaultFilterProps); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [isLoadingSiemJobs, siemJobs] = useSiemJobs(refreshToggle); const [, dispatchToaster] = useStateToaster(); const capabilities = useContext(MlCapabilitiesContext); + const docLinks = useKibana().services.docLinks; // Enable/Disable Job & Datafeed -- passed to JobsTable for use as callback on JobSwitch const enableDatafeed = async (job: SiemJob, latestTimestampMs: number, enable: boolean) => { @@ -226,7 +226,7 @@ export const MlPopover = React.memo(() => { values={{ mlDocs: ( diff --git a/x-pack/legacy/plugins/siem/public/components/ml_popover/types.ts b/x-pack/legacy/plugins/siem/public/components/ml_popover/types.ts index 88481e140cb0..f8794c196396 100644 --- a/x-pack/legacy/plugins/siem/public/components/ml_popover/types.ts +++ b/x-pack/legacy/plugins/siem/public/components/ml_popover/types.ts @@ -13,7 +13,7 @@ export interface Group { } export interface CheckRecognizerProps { - indexPatternName: string; + indexPatternName: string[]; kbnVersion: string; signal: AbortSignal; } diff --git a/x-pack/legacy/plugins/siem/public/components/netflow/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/netflow/index.test.tsx index 2d8c201e4146..22531983b239 100644 --- a/x-pack/legacy/plugins/siem/public/components/netflow/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/netflow/index.test.tsx @@ -57,8 +57,6 @@ import { } from '../source_destination/field_names'; import { useMountAppended } from '../../utils/use_mount_appended'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - const getNetflowInstance = () => ( { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.test.tsx index 690e8877b501..dbc7199aac72 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline.test.tsx @@ -17,7 +17,7 @@ import { mockTimelineResults } from '../../mock/timeline_results'; import { OpenTimeline } from './open_timeline'; import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from './constants'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../lib/kibana'); describe('OpenTimeline', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/index.test.tsx index 03383a6cb661..e3dc6d974b5e 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/index.test.tsx @@ -16,7 +16,7 @@ import { mockOpenTimelineQueryResults } from '../../../mock/timeline_results'; import { OpenTimelineModal } from '.'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); jest.mock('../../../utils/apollo_context', () => ({ useApolloClient: () => ({}), })); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_body.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_body.test.tsx index 4237caf8f3c5..a5abb42c2e3b 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_body.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_body.test.tsx @@ -17,7 +17,7 @@ import { mockTimelineResults } from '../../../mock/timeline_results'; import { OpenTimelineModalBody } from './open_timeline_modal_body'; import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); describe('OpenTimelineModal', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_button.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_button.test.tsx index a5e436c73f93..9a70fd476e89 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_button.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/open_timeline_modal/open_timeline_modal_button.test.tsx @@ -17,8 +17,6 @@ import * as i18n from '../translations'; import { OpenTimelineModalButton } from './open_timeline_modal_button'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - describe('OpenTimelineModalButton', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.test.tsx index 30a02a974ba9..749ba8672abe 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/actions_columns.test.tsx @@ -17,7 +17,7 @@ import { OpenTimelineResult } from '../types'; import { TimelinesTable } from '.'; import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); describe('#getActionsColumns', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/common_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/common_columns.test.tsx index ae68019c2fe6..fa08df1df478 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/common_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/common_columns.test.tsx @@ -21,7 +21,7 @@ import { TimelinesTable } from '.'; import * as i18n from '../translations'; import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); describe('#getCommonColumns', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/extended_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/extended_columns.test.tsx index bf5adc8aca53..13362e0f43a2 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/extended_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/extended_columns.test.tsx @@ -20,7 +20,7 @@ import { TimelinesTable } from '.'; import * as i18n from '../translations'; import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); describe('#getExtendedColumns', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/icon_header_columns.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/icon_header_columns.test.tsx index e5047662eef6..b6048b85eea7 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/icon_header_columns.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/icon_header_columns.test.tsx @@ -16,7 +16,7 @@ import { TimelinesTable } from '.'; import { OpenTimelineResult } from '../types'; import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); describe('#getActionsColumns', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.test.tsx index 6cf56ad6a770..d75863d1ccb8 100644 --- a/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/open_timeline/timelines_table/index.test.tsx @@ -18,7 +18,7 @@ import { TimelinesTable, TimelinesTableProps } from '.'; import * as i18n from '../translations'; import { DEFAULT_SORT_DIRECTION, DEFAULT_SORT_FIELD } from '../constants'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../lib/kibana'); describe('TimelinesTable', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/page/detection_engine/histogram_signals/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/detection_engine/histogram_signals/index.test.tsx index c0d0feca5d53..ad1d80a76185 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/detection_engine/histogram_signals/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/detection_engine/histogram_signals/index.test.tsx @@ -8,12 +8,9 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../../../mock/ui_settings'; import { TestProviders } from '../../../../mock'; import { HistogramSignals } from './index'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); - describe('HistogramSignals', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/page/hosts/first_last_seen_host/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/hosts/first_last_seen_host/index.test.tsx index 6c3ab0484923..35c1eded18f1 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/hosts/first_last_seen_host/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/hosts/first_last_seen_host/index.test.tsx @@ -12,26 +12,25 @@ import { render, act } from '@testing-library/react'; import { mockFirstLastSeenHostQuery } from '../../../../containers/hosts/first_last_seen/mock'; import { wait } from '../../../../lib/helpers'; import { TestProviders } from '../../../../mock'; -import '../../../../mock/ui_settings'; import { FirstLastSeenHost, FirstLastSeenHostType } from '.'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); - -// Suppress warnings about "react-apollo" until we migrate to apollo@3 -/* eslint-disable no-console */ -const originalError = console.error; -beforeAll(() => { - console.error = jest.fn(); -}); -afterAll(() => { - console.error = originalError; -}); +jest.mock('../../../../lib/kibana'); describe('FirstLastSeen Component', () => { const firstSeen = 'Apr 8, 2019 @ 16:09:40.692'; const lastSeen = 'Apr 8, 2019 @ 18:35:45.064'; + // Suppress warnings about "react-apollo" until we migrate to apollo@3 + /* eslint-disable no-console */ + const originalError = console.error; + beforeAll(() => { + console.error = jest.fn(); + }); + afterAll(() => { + console.error = originalError; + }); + test('Loading', async () => { const { container } = render( diff --git a/x-pack/legacy/plugins/siem/public/components/page/hosts/host_overview/index.tsx b/x-pack/legacy/plugins/siem/public/components/page/hosts/host_overview/index.tsx index 437d14edeb5c..9e3f8f91d5cf 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/hosts/host_overview/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/hosts/host_overview/index.tsx @@ -12,7 +12,7 @@ import React, { useContext, useState, useCallback } from 'react'; import { DEFAULT_DARK_MODE } from '../../../../../common/constants'; import { DescriptionList } from '../../../../../common/utility_types'; -import { useKibanaUiSetting } from '../../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../../lib/kibana'; import { getEmptyTagValue } from '../../../empty_value'; import { DefaultFieldRenderer, hostIdRenderer } from '../../../field_renderers/field_renderers'; import { InspectButton } from '../../../inspect'; @@ -59,7 +59,7 @@ export const HostOverview = React.memo( const [showInspect, setShowInspect] = useState(false); const capabilities = useContext(MlCapabilitiesContext); const userPermissions = hasMlUserPermissions(capabilities); - const [darkMode] = useKibanaUiSetting(DEFAULT_DARK_MODE); + const [darkMode] = useUiSetting$(DEFAULT_DARK_MODE); const getDefaultRenderer = (fieldName: string, fieldData: HostItem) => ( ({ - uiSettings: mockUiSettings, -})); - // Test will fail because we will to need to mock some core services to make the test work // For now let's forget about SiemSearchBar and QueryBar jest.mock('../../../search_bar', () => ({ diff --git a/x-pack/legacy/plugins/siem/public/components/page/network/ip_overview/index.tsx b/x-pack/legacy/plugins/siem/public/components/page/network/ip_overview/index.tsx index 8cb55f0d0fb5..0c4e59439951 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/network/ip_overview/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/network/ip_overview/index.tsx @@ -11,7 +11,7 @@ import React, { useContext, useState, useCallback } from 'react'; import { DEFAULT_DARK_MODE } from '../../../../../common/constants'; import { DescriptionList } from '../../../../../common/utility_types'; -import { useKibanaUiSetting } from '../../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../../lib/kibana'; import { FlowTarget, IpOverviewData, Overview } from '../../../../graphql/types'; import { networkModel } from '../../../../store'; import { getEmptyTagValue } from '../../../empty_value'; @@ -74,7 +74,7 @@ export const IpOverview = React.memo( const [showInspect, setShowInspect] = useState(false); const capabilities = useContext(MlCapabilitiesContext); const userPermissions = hasMlUserPermissions(capabilities); - const [darkMode] = useKibanaUiSetting(DEFAULT_DARK_MODE); + const [darkMode] = useUiSetting$(DEFAULT_DARK_MODE); const typeData: Overview = data[flowTarget]!; const column: DescriptionList[] = [ { diff --git a/x-pack/legacy/plugins/siem/public/components/page/network/network_dns_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/network/network_dns_table/index.test.tsx index 0537b95ca6cf..b88653bcadde 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/network/network_dns_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/network/network_dns_table/index.test.tsx @@ -18,8 +18,6 @@ import { useMountAppended } from '../../../../utils/use_mount_appended'; import { NetworkDnsTable } from '.'; import { mockData } from './mock'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); - describe('NetworkTopNFlow Table Component', () => { const loadPage = jest.fn(); const state: State = mockGlobalState; diff --git a/x-pack/legacy/plugins/siem/public/components/page/network/network_http_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/network/network_http_table/index.test.tsx index 50d64817f81f..81e0c7fad7b3 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/network/network_http_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/network/network_http_table/index.test.tsx @@ -18,8 +18,6 @@ import { createStore, networkModel, State } from '../../../../store'; import { NetworkHttpTable } from '.'; import { mockData } from './mock'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); - describe('NetworkHttp Table Component', () => { const loadPage = jest.fn(); const state: State = mockGlobalState; diff --git a/x-pack/legacy/plugins/siem/public/components/page/network/network_top_countries_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/network/network_top_countries_table/index.test.tsx index eb4179a04043..8fd245b07724 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/network/network_top_countries_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/network/network_top_countries_table/index.test.tsx @@ -24,7 +24,6 @@ import { createStore, networkModel, State } from '../../../../store'; import { NetworkTopCountriesTable } from '.'; import { mockData } from './mock'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); describe('NetworkTopCountries Table Component', () => { const loadPage = jest.fn(); const state: State = mockGlobalState; diff --git a/x-pack/legacy/plugins/siem/public/components/page/network/network_top_n_flow_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/network/network_top_n_flow_table/index.test.tsx index 3157847b3237..5c4aa862283f 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/network/network_top_n_flow_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/network/network_top_n_flow_table/index.test.tsx @@ -24,8 +24,6 @@ import { createStore, networkModel, State } from '../../../../store'; import { NetworkTopNFlowTable } from '.'; import { mockData } from './mock'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); - describe('NetworkTopNFlow Table Component', () => { const loadPage = jest.fn(); const state: State = mockGlobalState; diff --git a/x-pack/legacy/plugins/siem/public/components/page/network/tls_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/network/tls_table/index.test.tsx index 4313c455a0df..920d1cd8210e 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/network/tls_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/network/tls_table/index.test.tsx @@ -18,8 +18,6 @@ import { createStore, networkModel, State } from '../../../../store'; import { TlsTable } from '.'; import { mockTlsData } from './mock'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); - describe('Tls Table Component', () => { const loadPage = jest.fn(); const state: State = mockGlobalState; diff --git a/x-pack/legacy/plugins/siem/public/components/page/network/users_table/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/page/network/users_table/index.test.tsx index d6b9ec24de0a..d01923f01543 100644 --- a/x-pack/legacy/plugins/siem/public/components/page/network/users_table/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/page/network/users_table/index.test.tsx @@ -19,8 +19,6 @@ import { createStore, networkModel, State } from '../../../../store'; import { UsersTable } from '.'; import { mockUsersData } from './mock'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); - jest.mock('../../../search_bar', () => ({ siemFilterManager: { addFilters: jest.fn(), diff --git a/x-pack/legacy/plugins/siem/public/components/progress_inline/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/progress_inline/index.test.tsx index d99a4201c4c7..8ecc50402cef 100644 --- a/x-pack/legacy/plugins/siem/public/components/progress_inline/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/progress_inline/index.test.tsx @@ -8,11 +8,8 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../mock/ui_settings'; import { ProgressInline } from './index'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('ProgressInline', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/components/query_bar/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/query_bar/index.test.tsx index 10b769e2a791..e403963cbbe2 100644 --- a/x-pack/legacy/plugins/siem/public/components/query_bar/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/query_bar/index.test.tsx @@ -7,23 +7,16 @@ import { mount } from 'enzyme'; import React from 'react'; -import { FilterManager, SearchBar } from '../../../../../../../src/plugins/data/public'; -import { uiSettingsServiceMock } from '../../../../../../../src/core/public/ui_settings/ui_settings_service.mock'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; import { TestProviders, mockIndexPattern } from '../../mock'; -import { QueryBar, QueryBarComponentProps } from '.'; +import { createKibanaCoreStartMock } from '../../mock/kibana_core'; import { DEFAULT_FROM, DEFAULT_TO } from '../../../common/constants'; -import { mockUiSettings } from '../../mock/ui_settings'; +import { FilterManager, SearchBar } from '../../../../../../../src/plugins/data/public'; +import { QueryBar, QueryBarComponentProps } from '.'; +import { createKibanaContextProviderMock } from '../../mock/kibana_react'; -jest.mock('ui/new_platform'); +jest.mock('../../lib/kibana'); -const mockUseKibanaCore = useKibanaCore as jest.Mock; -const mockUiSettingsForFilterManager = uiSettingsServiceMock.createSetupContract(); -jest.mock('../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, - savedObjects: {}, -})); +const mockUiSettingsForFilterManager = createKibanaCoreStartMock().uiSettings; describe('QueryBar ', () => { // We are doing that because we need to wrapped this component with redux @@ -196,9 +189,13 @@ describe('QueryBar ', () => { describe('#onQueryChange', () => { test(' is the only reference that changed when filterQueryDraft props get updated', () => { + const KibanaWithStorageProvider = createKibanaContextProviderMock(); + const Proxy = (props: QueryBarComponentProps) => ( - + + + ); diff --git a/x-pack/legacy/plugins/siem/public/components/query_bar/index.tsx b/x-pack/legacy/plugins/siem/public/components/query_bar/index.tsx index 9f706790bec6..b2843348cc2e 100644 --- a/x-pack/legacy/plugins/siem/public/components/query_bar/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/query_bar/index.tsx @@ -6,7 +6,6 @@ import { isEqual } from 'lodash/fp'; import React, { memo, useState, useEffect, useMemo, useCallback } from 'react'; -import { IndexPattern } from 'ui/index_patterns'; import { esFilters, @@ -118,7 +117,7 @@ export const QueryBar = memo( ); const CustomButton = <>{null}; - const indexPatterns = useMemo(() => [indexPattern as IndexPattern], [indexPattern]); + const indexPatterns = useMemo(() => [indexPattern], [indexPattern]); const searchBarProps = savedQuery != null ? { savedQuery } : {}; diff --git a/x-pack/legacy/plugins/siem/public/components/search_bar/index.tsx b/x-pack/legacy/plugins/siem/public/components/search_bar/index.tsx index 3d02cff7b72e..089bade4a414 100644 --- a/x-pack/legacy/plugins/siem/public/components/search_bar/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/search_bar/index.tsx @@ -10,7 +10,6 @@ import { connect } from 'react-redux'; import { Dispatch } from 'redux'; import { Subscription } from 'rxjs'; import styled from 'styled-components'; -import { IndexPattern } from 'ui/index_patterns'; import { IIndexPattern } from 'src/plugins/data/public'; import { SavedQuery } from 'src/legacy/core_plugins/data/public'; @@ -254,7 +253,7 @@ const SearchBarComponent = memo [indexPattern as IndexPattern], [indexPattern]); + const indexPatterns = useMemo(() => [indexPattern], [indexPattern]); return ( ( { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/subtitle/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/subtitle/index.test.tsx index b54f3133de47..3424c05f32d6 100644 --- a/x-pack/legacy/plugins/siem/public/components/subtitle/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/subtitle/index.test.tsx @@ -8,12 +8,9 @@ import { mount, shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import React from 'react'; -import '../../mock/ui_settings'; import { TestProviders } from '../../mock'; import { Subtitle } from './index'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('Subtitle', () => { test('it renders', () => { const wrapper = shallow(); diff --git a/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.test.tsx index 011e2ddcdbde..013104da7c61 100644 --- a/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.test.tsx @@ -8,13 +8,69 @@ import { mount } from 'enzyme'; import * as React from 'react'; import { Provider as ReduxStoreProvider } from 'react-redux'; +import { useUiSetting$ } from '../../lib/kibana'; import { apolloClientObservable, mockGlobalState } from '../../mock'; +import { createUseUiSetting$Mock } from '../../mock/kibana_react'; import { createStore, State } from '../../store'; import { SuperDatePicker, makeMapStateToProps } from '.'; import { cloneDeep } from 'lodash/fp'; - -jest.mock('../../lib/settings/use_kibana_ui_setting'); +import { DEFAULT_TIMEPICKER_QUICK_RANGES } from '../../../common/constants'; + +jest.mock('../../lib/kibana'); +const mockUseUiSetting$ = useUiSetting$ as jest.Mock; +const timepickerRanges = [ + { + from: 'now/d', + to: 'now/d', + display: 'Today', + }, + { + from: 'now/w', + to: 'now/w', + display: 'This week', + }, + { + from: 'now-15m', + to: 'now', + display: 'Last 15 minutes', + }, + { + from: 'now-30m', + to: 'now', + display: 'Last 30 minutes', + }, + { + from: 'now-1h', + to: 'now', + display: 'Last 1 hour', + }, + { + from: 'now-24h', + to: 'now', + display: 'Last 24 hours', + }, + { + from: 'now-7d', + to: 'now', + display: 'Last 7 days', + }, + { + from: 'now-30d', + to: 'now', + display: 'Last 30 days', + }, + { + from: 'now-90d', + to: 'now', + display: 'Last 90 days', + }, + { + from: 'now-1y', + to: 'now', + display: 'Last 1 year', + }, +]; describe('SIEM Super Date Picker', () => { describe('#SuperDatePicker', () => { @@ -24,6 +80,13 @@ describe('SIEM Super Date Picker', () => { beforeEach(() => { jest.clearAllMocks(); store = createStore(state, apolloClientObservable); + mockUseUiSetting$.mockImplementation((key, defaultValue) => { + const useUiSetting$Mock = createUseUiSetting$Mock(); + + return key === DEFAULT_TIMEPICKER_QUICK_RANGES + ? [timepickerRanges, jest.fn()] + : useUiSetting$Mock(key, defaultValue); + }); }); describe('Pick Relative Date', () => { diff --git a/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.tsx b/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.tsx index a2e190da0f7b..0877906c721c 100644 --- a/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/super_date_picker/index.tsx @@ -18,7 +18,7 @@ import { connect } from 'react-redux'; import { Dispatch } from 'redux'; import { DEFAULT_TIMEPICKER_QUICK_RANGES } from '../../../common/constants'; -import { useKibanaUiSetting } from '../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../lib/kibana'; import { inputsModel, State } from '../../store'; import { inputsActions, timelineActions } from '../../store/actions'; import { InputsModelId } from '../../store/inputs/constants'; @@ -38,6 +38,12 @@ import { InputsRange, Policy } from '../../store/inputs/model'; const MAX_RECENTLY_USED_RANGES = 9; +interface Range { + from: string; + to: string; + display: string; +} + interface SuperDatePickerStateRedux { duration: number; end: number; @@ -196,10 +202,10 @@ export const SuperDatePickerComponent = React.memo( const endDate = kind === 'relative' ? toStr : new Date(end).toISOString(); const startDate = kind === 'relative' ? fromStr : new Date(start).toISOString(); - const [quickRanges] = useKibanaUiSetting(DEFAULT_TIMEPICKER_QUICK_RANGES); + const [quickRanges] = useUiSetting$(DEFAULT_TIMEPICKER_QUICK_RANGES); const commonlyUsedRanges = isEmpty(quickRanges) ? [] - : quickRanges.map(({ from, to, display }: { from: string; to: string; display: string }) => ({ + : quickRanges.map(({ from, to, display }) => ({ start: from, end: to, label: display, diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/index.test.tsx index d3eaedb3ef23..5c6a0872ce34 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/index.test.tsx @@ -17,8 +17,6 @@ import { Sort } from './sort'; import { wait } from '../../../lib/helpers'; import { useMountAppended } from '../../../utils/use_mount_appended'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - const testBodyHeight = 700; const mockGetNotesByIds = (eventId: string[]) => []; const mockSort: Sort = { diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/formatted_field.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/formatted_field.test.tsx index 3f27abfd2176..5c54e5be3374 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/formatted_field.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/formatted_field.test.tsx @@ -18,7 +18,7 @@ import { useMountAppended } from '../../../../utils/use_mount_appended'; import { FormattedFieldValue } from './formatted_field'; import { HOST_NAME_FIELD_NAME } from './constants'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../../lib/kibana'); describe('Events', () => { const theme = () => ({ eui: euiDarkVars, darkMode: true }); diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/netflow/netflow_row_renderer.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/netflow/netflow_row_renderer.test.tsx index 9f73d86dec40..6ba8f3f28dae 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/netflow/netflow_row_renderer.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/netflow/netflow_row_renderer.test.tsx @@ -25,8 +25,6 @@ export const justIdAndTimestamp: Ecs = { timestamp: '2018-11-12T19:03:25.936Z', }; -jest.mock('../../../../../lib/settings/use_kibana_ui_setting'); - describe('netflowRowRenderer', () => { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/plain_column_renderer.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/plain_column_renderer.test.tsx index 96865fd92821..008885b5264c 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/plain_column_renderer.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/plain_column_renderer.test.tsx @@ -18,7 +18,7 @@ import { useMountAppended } from '../../../../utils/use_mount_appended'; import { plainColumnRenderer } from './plain_column_renderer'; import { getValues, deleteItemIdx, findItem } from './helpers'; -jest.mock('../../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../../lib/kibana'); const mockFramework = mockFrameworks.default_UTC; diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/system/generic_row_renderer.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/system/generic_row_renderer.test.tsx index 3727e82c1d2a..b2dbdb6b0e45 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/system/generic_row_renderer.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/body/renderers/system/generic_row_renderer.test.tsx @@ -49,7 +49,7 @@ import { } from './generic_row_renderer'; import * as i18n from './translations'; -jest.mock('../../../../../lib/settings/use_kibana_ui_setting'); +jest.mock('../../../../../lib/kibana'); describe('GenericRowRenderer', () => { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/header/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/header/index.test.tsx index 977764803acb..4527e39128f8 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/header/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/header/index.test.tsx @@ -9,21 +9,14 @@ import toJson from 'enzyme-to-json'; import * as React from 'react'; import { Direction } from '../../../graphql/types'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; import { mockIndexPattern } from '../../../mock'; import { TestProviders } from '../../../mock/test_providers'; -import { mockUiSettings } from '../../../mock/ui_settings'; import { mockDataProviders } from '../data_providers/mock/mock_data_providers'; import { useMountAppended } from '../../../utils/use_mount_appended'; import { TimelineHeaderComponent } from '.'; -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, - savedObjects: {}, -})); +jest.mock('../../../lib/kibana'); describe('Header', () => { const indexPattern = mockIndexPattern; diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/properties/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/properties/index.test.tsx index eb82241b0412..bc05204cc47f 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/properties/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/properties/index.test.tsx @@ -8,22 +8,12 @@ import { mount } from 'enzyme'; import * as React from 'react'; import { Provider as ReduxStoreProvider } from 'react-redux'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; import { mockGlobalState, apolloClientObservable } from '../../../mock'; -import { mockUiSettings } from '../../../mock/ui_settings'; import { createStore, State } from '../../../store'; import { Properties, showDescriptionThreshold, showNotesThreshold } from '.'; -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); - -jest.mock('ui/vis/lib/timezone', () => ({ - timezoneProvider: () => () => 'America/New_York', -})); +jest.mock('../../../lib/kibana'); describe('Properties', () => { const usersViewing = ['elastic']; diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.test.tsx index b78691fabdcb..b978ef3d478d 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.test.tsx @@ -9,22 +9,15 @@ import React from 'react'; import { DEFAULT_FROM, DEFAULT_TO } from '../../../../common/constants'; import { mockBrowserFields } from '../../../containers/source/mock'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; import { convertKueryToElasticSearchQuery } from '../../../lib/keury'; import { mockIndexPattern, TestProviders } from '../../../mock'; -import { mockUiSettings } from '../../../mock/ui_settings'; import { QueryBar } from '../../query_bar'; import { mockDataProviders } from '../data_providers/mock/mock_data_providers'; import { buildGlobalQuery } from '../helpers'; import { QueryBarTimeline, QueryBarTimelineComponentProps, getDataProviderFilter } from './index'; -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, - savedObjects: {}, -})); +jest.mock('../../../lib/kibana'); describe('Timeline QueryBar ', () => { // We are doing that because we need to wrapped this component with redux diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.tsx index c55ead5e2d5d..c3b46c6cd0f7 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/query_bar/index.tsx @@ -19,7 +19,7 @@ import { import { BrowserFields } from '../../../containers/source'; import { convertKueryToElasticSearchQuery } from '../../../lib/keury'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; +import { useKibana } from '../../../lib/kibana'; import { KueryFilterQuery, KueryFilterQueryKind } from '../../../store'; import { KqlMode } from '../../../store/timeline/model'; import { useSavedQueryServices } from '../../../utils/saved_query_services'; @@ -92,8 +92,8 @@ export const QueryBarTimeline = memo( const [dataProvidersDsl, setDataProvidersDsl] = useState( convertKueryToElasticSearchQuery(buildGlobalQuery(dataProviders, browserFields), indexPattern) ); - const core = useKibanaCore(); - const [filterManager] = useState(new FilterManager(core.uiSettings)); + const kibana = useKibana(); + const [filterManager] = useState(new FilterManager(kibana.services.uiSettings)); const savedQueryServices = useSavedQueryServices(); diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/timeline.test.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/timeline.test.tsx index 180af88f21e4..bb500de239da 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/timeline.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/timeline.test.tsx @@ -12,10 +12,8 @@ import { MockedProvider } from 'react-apollo/test-utils'; import { timelineQuery } from '../../containers/timeline/index.gql_query'; import { mockBrowserFields } from '../../containers/source/mock'; import { Direction } from '../../graphql/types'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; import { defaultHeaders, mockTimelineData, mockIndexPattern } from '../../mock'; import { TestProviders } from '../../mock/test_providers'; -import { mockUiSettings } from '../../mock/ui_settings'; import { flyoutHeaderHeight } from '../flyout'; import { @@ -30,12 +28,7 @@ import { useMountAppended } from '../../utils/use_mount_appended'; const testFlyoutHeight = 980; -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, - savedObjects: {}, -})); +jest.mock('../../lib/kibana'); describe('Timeline', () => { const sort: Sort = { diff --git a/x-pack/legacy/plugins/siem/public/components/timeline/timeline.tsx b/x-pack/legacy/plugins/siem/public/components/timeline/timeline.tsx index ec7d10d2373d..5646b26428bf 100644 --- a/x-pack/legacy/plugins/siem/public/components/timeline/timeline.tsx +++ b/x-pack/legacy/plugins/siem/public/components/timeline/timeline.tsx @@ -12,7 +12,7 @@ import styled from 'styled-components'; import { BrowserFields } from '../../containers/source'; import { TimelineQuery } from '../../containers/timeline'; import { Direction } from '../../graphql/types'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; +import { useKibana } from '../../lib/kibana'; import { KqlMode } from '../../store/timeline/model'; import { AutoSizer } from '../auto_sizer'; import { ColumnHeader } from './body/column_headers/column_header'; @@ -113,9 +113,9 @@ export const TimelineComponent = ({ sort, toggleColumn, }: Props) => { - const core = useKibanaCore(); + const kibana = useKibana(); const combinedQueries = combineQueries({ - config: esQuery.getEsQueryConfig(core.uiSettings), + config: esQuery.getEsQueryConfig(kibana.services.uiSettings), dataProviders, indexPattern, browserFields, diff --git a/x-pack/legacy/plugins/siem/public/components/wrapper_page/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/wrapper_page/index.test.tsx index 3ea243fe5cfe..5d73e9bcf8e7 100644 --- a/x-pack/legacy/plugins/siem/public/components/wrapper_page/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/wrapper_page/index.test.tsx @@ -9,11 +9,8 @@ import toJson from 'enzyme-to-json'; import React from 'react'; import { TestProviders } from '../../mock'; -import '../../mock/ui_settings'; import { WrapperPage } from './index'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - describe('WrapperPage', () => { test('it renders', () => { const wrapper = shallow( diff --git a/x-pack/legacy/plugins/siem/public/containers/alerts/alerts_over_time/index.tsx b/x-pack/legacy/plugins/siem/public/containers/alerts/alerts_over_time/index.tsx index 98dcef51292a..9541e6d39d66 100644 --- a/x-pack/legacy/plugins/siem/public/containers/alerts/alerts_over_time/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/alerts/alerts_over_time/index.tsx @@ -8,10 +8,11 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { inputsModel, State, inputsSelectors, hostsModel } from '../../../store'; +import { withKibana, WithKibanaProps } from '../../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../../helpers'; import { QueryTemplate, QueryTemplateProps } from '../../query_template'; @@ -40,7 +41,7 @@ export interface AlertsOverTimeComponentReduxProps { isInspected: boolean; } -type AlertsOverTimeProps = OwnProps & AlertsOverTimeComponentReduxProps; +type AlertsOverTimeProps = OwnProps & AlertsOverTimeComponentReduxProps & WithKibanaProps; class AlertsOverTimeComponentQuery extends QueryTemplate< AlertsOverTimeProps, @@ -54,6 +55,7 @@ class AlertsOverTimeComponentQuery extends QueryTemplate< filterQuery, id = ID, isInspected, + kibana, sourceId, startDate, } = this.props; @@ -70,7 +72,7 @@ class AlertsOverTimeComponentQuery extends QueryTemplate< from: startDate!, to: endDate!, }, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), inspect: isInspected, }} > @@ -105,4 +107,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const AlertsOverTimeQuery = connect(makeMapStateToProps)(AlertsOverTimeComponentQuery); +export const AlertsOverTimeQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(AlertsOverTimeComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/anomalies/anomalies_query_tab_body/index.tsx b/x-pack/legacy/plugins/siem/public/containers/anomalies/anomalies_query_tab_body/index.tsx index 917f4dbcc211..f2c00cbae1a7 100644 --- a/x-pack/legacy/plugins/siem/public/containers/anomalies/anomalies_query_tab_body/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/anomalies/anomalies_query_tab_body/index.tsx @@ -12,7 +12,7 @@ import { AnomaliesOverTimeHistogram } from '../../../components/anomalies_over_t import { AnomaliesOverTimeQuery } from '../anomalies_over_time'; import { getAnomaliesFilterQuery } from './utils'; import { useSiemJobs } from '../../../components/ml_popover/hooks/use_siem_jobs'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_ANOMALY_SCORE } from '../../../../common/constants'; const AnomaliesOverTimeManage = manageQuery(AnomaliesOverTimeHistogram); @@ -33,7 +33,7 @@ export const AnomaliesQueryTabBody = ({ ip, }: AnomaliesQueryTabBodyProps) => { const [siemJobsLoading, siemJobs] = useSiemJobs(true); - const [anomalyScore] = useKibanaUiSetting(DEFAULT_ANOMALY_SCORE); + const [anomalyScore] = useUiSetting$(DEFAULT_ANOMALY_SCORE); const mergedFilterQuery = getAnomaliesFilterQuery( filterQuery, diff --git a/x-pack/legacy/plugins/siem/public/containers/authentications/authentications_over_time/index.tsx b/x-pack/legacy/plugins/siem/public/containers/authentications/authentications_over_time/index.tsx index 1d6d96869b6a..8f363d49f185 100644 --- a/x-pack/legacy/plugins/siem/public/containers/authentications/authentications_over_time/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/authentications/authentications_over_time/index.tsx @@ -8,10 +8,11 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { inputsModel, State, inputsSelectors, hostsModel } from '../../../store'; +import { withKibana, WithKibanaProps } from '../../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../../helpers'; import { QueryTemplate, QueryTemplateProps } from '../../query_template'; @@ -43,7 +44,9 @@ export interface AuthenticationsOverTimeComponentReduxProps { isInspected: boolean; } -type AuthenticationsOverTimeProps = OwnProps & AuthenticationsOverTimeComponentReduxProps; +type AuthenticationsOverTimeProps = OwnProps & + AuthenticationsOverTimeComponentReduxProps & + WithKibanaProps; class AuthenticationsOverTimeComponentQuery extends QueryTemplate< AuthenticationsOverTimeProps, @@ -56,6 +59,7 @@ class AuthenticationsOverTimeComponentQuery extends QueryTemplate< filterQuery, id = ID, isInspected, + kibana, sourceId, startDate, endDate, @@ -73,7 +77,7 @@ class AuthenticationsOverTimeComponentQuery extends QueryTemplate< from: startDate!, to: endDate!, }, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), inspect: isInspected, }} > @@ -108,6 +112,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const AuthenticationsOverTimeQuery = connect(makeMapStateToProps)( - AuthenticationsOverTimeComponentQuery -); +export const AuthenticationsOverTimeQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(AuthenticationsOverTimeComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/authentications/index.tsx b/x-pack/legacy/plugins/siem/public/containers/authentications/index.tsx index 6f896cfd9590..6d4a88c45a76 100644 --- a/x-pack/legacy/plugins/siem/public/containers/authentications/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/authentications/index.tsx @@ -8,8 +8,8 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { AuthenticationsEdges, @@ -19,6 +19,7 @@ import { import { hostsModel, hostsSelectors, inputsModel, State, inputsSelectors } from '../../store'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; import { authenticationsQuery } from './index.gql_query'; @@ -48,7 +49,7 @@ export interface AuthenticationsComponentReduxProps { limit: number; } -type AuthenticationsProps = OwnProps & AuthenticationsComponentReduxProps; +type AuthenticationsProps = OwnProps & AuthenticationsComponentReduxProps & WithKibanaProps; class AuthenticationsComponentQuery extends QueryTemplatePaginated< AuthenticationsProps, @@ -63,6 +64,7 @@ class AuthenticationsComponentQuery extends QueryTemplatePaginated< filterQuery, id = ID, isInspected, + kibana, limit, skip, sourceId, @@ -77,7 +79,7 @@ class AuthenticationsComponentQuery extends QueryTemplatePaginated< }, pagination: generateTablePaginationOptions(activePage, limit), filterQuery: createFilter(filterQuery), - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), inspect: isInspected, }; return ( @@ -142,4 +144,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const AuthenticationsQuery = connect(makeMapStateToProps)(AuthenticationsComponentQuery); +export const AuthenticationsQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(AuthenticationsComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/persist_rule.tsx b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/persist_rule.tsx index 371d28aebf7f..82490991236d 100644 --- a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/persist_rule.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/persist_rule.tsx @@ -6,7 +6,7 @@ import { useEffect, useState, Dispatch } from 'react'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_KBN_VERSION } from '../../../../common/constants'; import { useStateToaster } from '../../../components/toasters'; import { errorToToaster } from '../../../components/ml/api/error_to_toaster'; @@ -26,7 +26,7 @@ export const usePersistRule = (): Return => { const [rule, setRule] = useState(null); const [isSaved, setIsSaved] = useState(false); const [isLoading, setIsLoading] = useState(false); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [, dispatchToaster] = useStateToaster(); useEffect(() => { diff --git a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rule.tsx b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rule.tsx index 8ba59a86a2b8..ad0b87385ee7 100644 --- a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rule.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rule.tsx @@ -6,7 +6,7 @@ import { useEffect, useState } from 'react'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_KBN_VERSION } from '../../../../common/constants'; import { useStateToaster } from '../../../components/toasters'; import { errorToToaster } from '../../../components/ml/api/error_to_toaster'; @@ -25,7 +25,7 @@ type Return = [boolean, Rule | null]; export const useRule = (id: string | undefined): Return => { const [rule, setRule] = useState(null); const [loading, setLoading] = useState(true); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [, dispatchToaster] = useStateToaster(); useEffect(() => { diff --git a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rules.tsx b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rules.tsx index 2b8bb986a296..66285c804aa2 100644 --- a/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rules.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rules.tsx @@ -6,7 +6,7 @@ import { useEffect, useState } from 'react'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_KBN_VERSION } from '../../../../common/constants'; import { FetchRulesResponse, FilterOptions, PaginationOptions } from './types'; import { useStateToaster } from '../../../components/toasters'; @@ -35,7 +35,7 @@ export const useRules = ( data: [], }); const [loading, setLoading] = useState(true); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [, dispatchToaster] = useStateToaster(); useEffect(() => { diff --git a/x-pack/legacy/plugins/siem/public/containers/detection_engine/signals/use_query.tsx b/x-pack/legacy/plugins/siem/public/containers/detection_engine/signals/use_query.tsx index a1b3907e2b31..d86562528855 100644 --- a/x-pack/legacy/plugins/siem/public/containers/detection_engine/signals/use_query.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/detection_engine/signals/use_query.tsx @@ -6,7 +6,7 @@ import { useEffect, useState } from 'react'; -import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_KBN_VERSION } from '../../../../common/constants'; import { errorToToaster } from '../../../components/ml/api/error_to_toaster'; import { useStateToaster } from '../../../components/toasters'; @@ -26,7 +26,7 @@ type Return = [boolean, SignalSearchResponse | null]; export const useQuerySignals = (query: string): Return => { const [signals, setSignals] = useState | null>(null); const [loading, setLoading] = useState(true); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [, dispatchToaster] = useStateToaster(); useEffect(() => { diff --git a/x-pack/legacy/plugins/siem/public/containers/events/events_over_time/index.tsx b/x-pack/legacy/plugins/siem/public/containers/events/events_over_time/index.tsx index 77ce98e180ab..e102cd11f108 100644 --- a/x-pack/legacy/plugins/siem/public/containers/events/events_over_time/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/events/events_over_time/index.tsx @@ -8,12 +8,13 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { inputsModel, State, inputsSelectors, hostsModel } from '../../../store'; import { createFilter, getDefaultFetchPolicy } from '../../helpers'; import { QueryTemplate, QueryTemplateProps } from '../../query_template'; +import { withKibana, WithKibanaProps } from '../../../lib/kibana'; import { EventsOverTimeGqlQuery } from './events_over_time.gql_query'; import { GetEventsOverTimeQuery, MatrixOverTimeHistogramData } from '../../../graphql/types'; @@ -40,7 +41,7 @@ export interface EventsOverTimeComponentReduxProps { isInspected: boolean; } -type EventsOverTimeProps = OwnProps & EventsOverTimeComponentReduxProps; +type EventsOverTimeProps = OwnProps & EventsOverTimeComponentReduxProps & WithKibanaProps; class EventsOverTimeComponentQuery extends QueryTemplate< EventsOverTimeProps, @@ -54,6 +55,7 @@ class EventsOverTimeComponentQuery extends QueryTemplate< filterQuery, id = ID, isInspected, + kibana, sourceId, startDate, } = this.props; @@ -70,7 +72,7 @@ class EventsOverTimeComponentQuery extends QueryTemplate< from: startDate!, to: endDate!, }, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), inspect: isInspected, }} > @@ -105,4 +107,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const EventsOverTimeQuery = connect(makeMapStateToProps)(EventsOverTimeComponentQuery); +export const EventsOverTimeQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(EventsOverTimeComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/events/last_event_time/index.ts b/x-pack/legacy/plugins/siem/public/containers/events/last_event_time/index.ts index 3bfdbae8d30f..9cae503d3094 100644 --- a/x-pack/legacy/plugins/siem/public/containers/events/last_event_time/index.ts +++ b/x-pack/legacy/plugins/siem/public/containers/events/last_event_time/index.ts @@ -7,11 +7,11 @@ import { get } from 'lodash/fp'; import React, { useEffect, useState } from 'react'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { GetLastEventTimeQuery, LastEventIndexKey, LastTimeDetails } from '../../../graphql/types'; import { inputsModel } from '../../../store'; import { QueryTemplateProps } from '../../query_template'; +import { useUiSetting$ } from '../../../lib/kibana'; import { LastEventTimeGqlQuery } from './last_event_time.gql_query'; import { useApolloClient } from '../../../utils/apollo_context'; @@ -38,6 +38,7 @@ export function useLastEventTimeQuery( const [lastSeen, updateLastSeen] = useState(null); const [errorMessage, updateErrorMessage] = useState(null); const [currentIndexKey, updateCurrentIndexKey] = useState(null); + const [defaultIndex] = useUiSetting$(DEFAULT_INDEX_KEY); const apolloClient = useApolloClient(); async function fetchLastEventTime(signal: AbortSignal) { updateLoading(true); @@ -50,7 +51,7 @@ export function useLastEventTimeQuery( sourceId, indexKey, details, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex, }, context: { fetchOptions: { diff --git a/x-pack/legacy/plugins/siem/public/containers/hosts/first_last_seen/index.ts b/x-pack/legacy/plugins/siem/public/containers/hosts/first_last_seen/index.ts index 042de56fbd99..e36da5bfbe4e 100644 --- a/x-pack/legacy/plugins/siem/public/containers/hosts/first_last_seen/index.ts +++ b/x-pack/legacy/plugins/siem/public/containers/hosts/first_last_seen/index.ts @@ -8,7 +8,7 @@ import ApolloClient from 'apollo-client'; import { get } from 'lodash/fp'; import React, { useEffect, useState } from 'react'; -import chrome from 'ui/chrome'; +import { useUiSetting$ } from '../../../lib/kibana'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { GetHostFirstLastSeenQuery } from '../../../graphql/types'; import { inputsModel } from '../../../store'; @@ -39,6 +39,7 @@ export function useFirstLastSeenHostQuery( const [firstSeen, updateFirstSeen] = useState(null); const [lastSeen, updateLastSeen] = useState(null); const [errorMessage, updateErrorMessage] = useState(null); + const [defaultIndex] = useUiSetting$(DEFAULT_INDEX_KEY); async function fetchFirstLastSeenHost(signal: AbortSignal) { updateLoading(true); @@ -49,7 +50,7 @@ export function useFirstLastSeenHostQuery( variables: { sourceId, hostName, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex, }, context: { fetchOptions: { diff --git a/x-pack/legacy/plugins/siem/public/containers/hosts/index.tsx b/x-pack/legacy/plugins/siem/public/containers/hosts/index.tsx index d2be29e3e9e2..733c2224d840 100644 --- a/x-pack/legacy/plugins/siem/public/containers/hosts/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/hosts/index.tsx @@ -9,8 +9,8 @@ import memoizeOne from 'memoize-one'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { Direction, @@ -22,6 +22,7 @@ import { import { hostsModel, hostsSelectors, inputsModel, State, inputsSelectors } from '../../store'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { HostsTableQuery } from './hosts_table.gql_query'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; @@ -57,7 +58,7 @@ export interface HostsComponentReduxProps { direction: Direction; } -type HostsProps = OwnProps & HostsComponentReduxProps; +type HostsProps = OwnProps & HostsComponentReduxProps & WithKibanaProps; class HostsComponentQuery extends QueryTemplatePaginated< HostsProps, @@ -83,12 +84,14 @@ class HostsComponentQuery extends QueryTemplatePaginated< direction, filterQuery, endDate, + kibana, limit, startDate, skip, sourceId, sortField, } = this.props; + const defaultIndex = kibana.services.uiSettings.get(DEFAULT_INDEX_KEY); const variables: GetHostsTableQuery.Variables = { sourceId, @@ -103,7 +106,7 @@ class HostsComponentQuery extends QueryTemplatePaginated< }, pagination: generateTablePaginationOptions(activePage, limit), filterQuery: createFilter(filterQuery), - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex, inspect: isInspected, }; return ( @@ -174,4 +177,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const HostsQuery = connect(makeMapStateToProps)(HostsComponentQuery); +export const HostsQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(HostsComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/hosts/overview/index.tsx b/x-pack/legacy/plugins/siem/public/containers/hosts/overview/index.tsx index a9223143462f..5057e872b531 100644 --- a/x-pack/legacy/plugins/siem/public/containers/hosts/overview/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/hosts/overview/index.tsx @@ -7,12 +7,14 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; -import chrome from 'ui/chrome'; import { connect } from 'react-redux'; +import { compose } from 'redux'; + import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { inputsModel, inputsSelectors, State } from '../../../store'; import { getDefaultFetchPolicy } from '../../helpers'; import { QueryTemplate, QueryTemplateProps } from '../../query_template'; +import { withKibana, WithKibanaProps } from '../../../lib/kibana'; import { HostOverviewQuery } from './host_overview.gql_query'; import { GetHostOverviewQuery, HostItem } from '../../../graphql/types'; @@ -40,8 +42,10 @@ export interface OwnProps extends QueryTemplateProps { endDate: number; } +type HostsOverViewProps = OwnProps & HostOverviewReduxProps & WithKibanaProps; + class HostOverviewByNameComponentQuery extends QueryTemplate< - OwnProps & HostOverviewReduxProps, + HostsOverViewProps, GetHostOverviewQuery.Query, GetHostOverviewQuery.Variables > { @@ -51,6 +55,7 @@ class HostOverviewByNameComponentQuery extends QueryTemplate< isInspected, children, hostName, + kibana, skip, sourceId, startDate, @@ -70,7 +75,7 @@ class HostOverviewByNameComponentQuery extends QueryTemplate< from: startDate, to: endDate, }, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), inspect: isInspected, }} > @@ -102,6 +107,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const HostOverviewByNameQuery = connect(makeMapStateToProps)( - HostOverviewByNameComponentQuery -); +export const HostOverviewByNameQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(HostOverviewByNameComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/ip_overview/index.tsx b/x-pack/legacy/plugins/siem/public/containers/ip_overview/index.tsx index 003032493fca..9576c66c4c9a 100644 --- a/x-pack/legacy/plugins/siem/public/containers/ip_overview/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/ip_overview/index.tsx @@ -9,10 +9,10 @@ import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { GetIpOverviewQuery, IpOverviewData } from '../../graphql/types'; import { networkModel, inputsModel, inputsSelectors, State } from '../../store'; +import { useUiSetting } from '../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplateProps } from '../query_template'; @@ -49,7 +49,7 @@ const IpOverviewComponentQuery = React.memo(DEFAULT_INDEX_KEY), inspect: isInspected, }} > diff --git a/x-pack/legacy/plugins/siem/public/containers/kpi_host_details/index.tsx b/x-pack/legacy/plugins/siem/public/containers/kpi_host_details/index.tsx index 20ed7fa991d1..501bc8472b5e 100644 --- a/x-pack/legacy/plugins/siem/public/containers/kpi_host_details/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/kpi_host_details/index.tsx @@ -8,11 +8,11 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { KpiHostDetailsData, GetKpiHostDetailsQuery } from '../../graphql/types'; import { inputsModel, inputsSelectors, State } from '../../store'; +import { useUiSetting } from '../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplateProps } from '../query_template'; @@ -51,7 +51,7 @@ const KpiHostDetailsComponentQuery = React.memo(DEFAULT_INDEX_KEY), inspect: isInspected, }} > diff --git a/x-pack/legacy/plugins/siem/public/containers/kpi_hosts/index.tsx b/x-pack/legacy/plugins/siem/public/containers/kpi_hosts/index.tsx index f8aa8aa38e8e..32472ba6deed 100644 --- a/x-pack/legacy/plugins/siem/public/containers/kpi_hosts/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/kpi_hosts/index.tsx @@ -8,11 +8,11 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { GetKpiHostsQuery, KpiHostsData } from '../../graphql/types'; import { inputsModel, inputsSelectors, State } from '../../store'; +import { useUiSetting } from '../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplateProps } from '../query_template'; @@ -51,7 +51,7 @@ const KpiHostsComponentQuery = React.memo( to: endDate!, }, filterQuery: createFilter(filterQuery), - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: useUiSetting(DEFAULT_INDEX_KEY), inspect: isInspected, }} > diff --git a/x-pack/legacy/plugins/siem/public/containers/kpi_network/index.tsx b/x-pack/legacy/plugins/siem/public/containers/kpi_network/index.tsx index 269c3593d4d7..52b8814958ba 100644 --- a/x-pack/legacy/plugins/siem/public/containers/kpi_network/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/kpi_network/index.tsx @@ -8,11 +8,11 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { GetKpiNetworkQuery, KpiNetworkData } from '../../graphql/types'; import { inputsModel, inputsSelectors, State } from '../../store'; +import { useUiSetting } from '../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplateProps } from '../query_template'; @@ -51,7 +51,7 @@ const KpiNetworkComponentQuery = React.memo to: endDate!, }, filterQuery: createFilter(filterQuery), - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: useUiSetting(DEFAULT_INDEX_KEY), inspect: isInspected, }} > diff --git a/x-pack/legacy/plugins/siem/public/containers/kuery_autocompletion/index.tsx b/x-pack/legacy/plugins/siem/public/containers/kuery_autocompletion/index.tsx index d06f4f6fbbbf..6361f7abcf97 100644 --- a/x-pack/legacy/plugins/siem/public/containers/kuery_autocompletion/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/kuery_autocompletion/index.tsx @@ -9,7 +9,7 @@ import { AutocompleteSuggestion, IIndexPattern, } from '../../../../../../../src/plugins/data/public'; -import { useKibanaPlugins } from '../../lib/compose/kibana_plugins'; +import { useKibana } from '../../lib/kibana'; type RendererResult = React.ReactElement | null; type RendererFunction = (args: RenderArgs) => Result; @@ -34,13 +34,13 @@ export const KueryAutocompletion = React.memo null ); const [suggestions, setSuggestions] = useState([]); - const plugins = useKibanaPlugins(); + const kibana = useKibana(); const loadSuggestions = async ( expression: string, cursorPosition: number, maxSuggestions?: number ) => { - const autocompletionProvider = plugins.data.autocomplete.getProvider('kuery'); + const autocompletionProvider = kibana.services.data.autocomplete.getProvider('kuery'); const config = { get: () => true, }; diff --git a/x-pack/legacy/plugins/siem/public/containers/network_dns/index.tsx b/x-pack/legacy/plugins/siem/public/containers/network_dns/index.tsx index 592fe43b9873..b5ebf3deacd0 100644 --- a/x-pack/legacy/plugins/siem/public/containers/network_dns/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/network_dns/index.tsx @@ -8,8 +8,8 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { GetNetworkDnsQuery, @@ -19,6 +19,7 @@ import { MatrixOverOrdinalHistogramData, } from '../../graphql/types'; import { inputsModel, networkModel, networkSelectors, State, inputsSelectors } from '../../store'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; @@ -53,7 +54,7 @@ export interface NetworkDnsComponentReduxProps { limit: number; } -type NetworkDnsProps = OwnProps & NetworkDnsComponentReduxProps; +type NetworkDnsProps = OwnProps & NetworkDnsComponentReduxProps & WithKibanaProps; export class NetworkDnsComponentQuery extends QueryTemplatePaginated< NetworkDnsProps, @@ -70,13 +71,14 @@ export class NetworkDnsComponentQuery extends QueryTemplatePaginated< id = ID, isInspected, isPtrIncluded, + kibana, limit, skip, sourceId, startDate, } = this.props; const variables: GetNetworkDnsQuery.Variables = { - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), filterQuery: createFilter(filterQuery), inspect: isInspected, isPtrIncluded, @@ -172,7 +174,12 @@ const makeMapHistogramStateToProps = () => { return mapStateToProps; }; -export const NetworkDnsQuery = connect(makeMapStateToProps)(NetworkDnsComponentQuery); -export const NetworkDnsHistogramQuery = connect(makeMapHistogramStateToProps)( - NetworkDnsComponentQuery -); +export const NetworkDnsQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(NetworkDnsComponentQuery); + +export const NetworkDnsHistogramQuery = compose>( + connect(makeMapHistogramStateToProps), + withKibana +)(NetworkDnsComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/network_http/index.tsx b/x-pack/legacy/plugins/siem/public/containers/network_http/index.tsx index d76ab53b2de3..bf4e64f63d55 100644 --- a/x-pack/legacy/plugins/siem/public/containers/network_http/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/network_http/index.tsx @@ -9,7 +9,6 @@ import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { @@ -19,6 +18,7 @@ import { PageInfoPaginated, } from '../../graphql/types'; import { inputsModel, inputsSelectors, networkModel, networkSelectors, State } from '../../store'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; @@ -52,7 +52,7 @@ export interface NetworkHttpComponentReduxProps { sort: NetworkHttpSortField; } -type NetworkHttpProps = OwnProps & NetworkHttpComponentReduxProps; +type NetworkHttpProps = OwnProps & NetworkHttpComponentReduxProps & WithKibanaProps; class NetworkHttpComponentQuery extends QueryTemplatePaginated< NetworkHttpProps, @@ -68,6 +68,7 @@ class NetworkHttpComponentQuery extends QueryTemplatePaginated< id = ID, ip, isInspected, + kibana, limit, skip, sourceId, @@ -75,7 +76,7 @@ class NetworkHttpComponentQuery extends QueryTemplatePaginated< startDate, } = this.props; const variables: GetNetworkHttpQuery.Variables = { - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), filterQuery: createFilter(filterQuery), inspect: isInspected, ip, @@ -150,5 +151,6 @@ const makeMapStateToProps = () => { }; export const NetworkHttpQuery = compose>( - connect(makeMapStateToProps) + connect(makeMapStateToProps), + withKibana )(NetworkHttpComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/network_top_countries/index.tsx b/x-pack/legacy/plugins/siem/public/containers/network_top_countries/index.tsx index b179745dafa5..bd1e1a002bbc 100644 --- a/x-pack/legacy/plugins/siem/public/containers/network_top_countries/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/network_top_countries/index.tsx @@ -10,7 +10,6 @@ import { Query } from 'react-apollo'; import { connect } from 'react-redux'; import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { FlowTargetSourceDest, @@ -20,6 +19,7 @@ import { PageInfoPaginated, } from '../../graphql/types'; import { inputsModel, inputsSelectors, networkModel, networkSelectors, State } from '../../store'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; @@ -54,7 +54,7 @@ export interface NetworkTopCountriesComponentReduxProps { sort: NetworkTopTablesSortField; } -type NetworkTopCountriesProps = OwnProps & NetworkTopCountriesComponentReduxProps; +type NetworkTopCountriesProps = OwnProps & NetworkTopCountriesComponentReduxProps & WithKibanaProps; class NetworkTopCountriesComponentQuery extends QueryTemplatePaginated< NetworkTopCountriesProps, @@ -68,6 +68,7 @@ class NetworkTopCountriesComponentQuery extends QueryTemplatePaginated< endDate, flowTarget, filterQuery, + kibana, id = `${ID}-${flowTarget}`, ip, isInspected, @@ -78,7 +79,7 @@ class NetworkTopCountriesComponentQuery extends QueryTemplatePaginated< sort, } = this.props; const variables: GetNetworkTopCountriesQuery.Variables = { - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), filterQuery: createFilter(filterQuery), flowTarget, inspect: isInspected, @@ -154,5 +155,6 @@ const makeMapStateToProps = () => { }; export const NetworkTopCountriesQuery = compose>( - connect(makeMapStateToProps) + connect(makeMapStateToProps), + withKibana )(NetworkTopCountriesComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/network_top_n_flow/index.tsx b/x-pack/legacy/plugins/siem/public/containers/network_top_n_flow/index.tsx index 239576a48c49..f0f1f8257f29 100644 --- a/x-pack/legacy/plugins/siem/public/containers/network_top_n_flow/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/network_top_n_flow/index.tsx @@ -9,7 +9,6 @@ import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { @@ -19,6 +18,7 @@ import { NetworkTopTablesSortField, PageInfoPaginated, } from '../../graphql/types'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { inputsModel, inputsSelectors, networkModel, networkSelectors, State } from '../../store'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; @@ -54,7 +54,7 @@ export interface NetworkTopNFlowComponentReduxProps { sort: NetworkTopTablesSortField; } -type NetworkTopNFlowProps = OwnProps & NetworkTopNFlowComponentReduxProps; +type NetworkTopNFlowProps = OwnProps & NetworkTopNFlowComponentReduxProps & WithKibanaProps; class NetworkTopNFlowComponentQuery extends QueryTemplatePaginated< NetworkTopNFlowProps, @@ -68,6 +68,7 @@ class NetworkTopNFlowComponentQuery extends QueryTemplatePaginated< endDate, flowTarget, filterQuery, + kibana, id = `${ID}-${flowTarget}`, ip, isInspected, @@ -78,7 +79,7 @@ class NetworkTopNFlowComponentQuery extends QueryTemplatePaginated< sort, } = this.props; const variables: GetNetworkTopNFlowQuery.Variables = { - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), filterQuery: createFilter(filterQuery), flowTarget, inspect: isInspected, @@ -154,5 +155,6 @@ const makeMapStateToProps = () => { }; export const NetworkTopNFlowQuery = compose>( - connect(makeMapStateToProps) + connect(makeMapStateToProps), + withKibana )(NetworkTopNFlowComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/overview/overview_host/index.tsx b/x-pack/legacy/plugins/siem/public/containers/overview/overview_host/index.tsx index 6ef0ee7b3358..36cadd7872cc 100644 --- a/x-pack/legacy/plugins/siem/public/containers/overview/overview_host/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/overview/overview_host/index.tsx @@ -8,10 +8,10 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { GetOverviewHostQuery, OverviewHostData } from '../../../graphql/types'; +import { useUiSetting } from '../../../lib/kibana'; import { inputsModel, inputsSelectors } from '../../../store/inputs'; import { State } from '../../../store'; import { createFilter, getDefaultFetchPolicy } from '../../helpers'; @@ -53,7 +53,7 @@ const OverviewHostComponentQuery = React.memo(DEFAULT_INDEX_KEY), inspect: isInspected, }} > diff --git a/x-pack/legacy/plugins/siem/public/containers/overview/overview_network/index.tsx b/x-pack/legacy/plugins/siem/public/containers/overview/overview_network/index.tsx index 677d96c10eee..9e7d59de0e54 100644 --- a/x-pack/legacy/plugins/siem/public/containers/overview/overview_network/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/overview/overview_network/index.tsx @@ -9,9 +9,9 @@ import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { GetOverviewNetworkQuery, OverviewNetworkData } from '../../../graphql/types'; +import { useUiSetting } from '../../../lib/kibana'; import { State } from '../../../store'; import { inputsModel, inputsSelectors } from '../../../store/inputs'; import { createFilter, getDefaultFetchPolicy } from '../../helpers'; @@ -55,7 +55,7 @@ export const OverviewNetworkComponentQuery = React.memo< to: endDate, }, filterQuery: createFilter(filterQuery), - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: useUiSetting(DEFAULT_INDEX_KEY), inspect: isInspected, }} > diff --git a/x-pack/legacy/plugins/siem/public/containers/source/index.test.tsx b/x-pack/legacy/plugins/siem/public/containers/source/index.test.tsx index 7d6ac73357b1..d1a183a402e3 100644 --- a/x-pack/legacy/plugins/siem/public/containers/source/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/source/index.test.tsx @@ -11,11 +11,11 @@ import { MockedProvider } from 'react-apollo/test-utils'; import { wait } from '../../lib/helpers'; -import '../../mock/ui_settings'; - import { WithSource, indicesExistOrDataTemporarilyUnavailable } from '.'; import { mockBrowserFields, mockIndexFields, mocksSource } from './mock'; +jest.mock('../../lib/kibana'); + describe('Index Fields & Browser Fields', () => { test('Index Fields', async () => { mount( diff --git a/x-pack/legacy/plugins/siem/public/containers/source/index.tsx b/x-pack/legacy/plugins/siem/public/containers/source/index.tsx index 8bddbd14a367..94524dedbcd5 100644 --- a/x-pack/legacy/plugins/siem/public/containers/source/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/source/index.tsx @@ -10,7 +10,7 @@ import { Query } from 'react-apollo'; import React, { useEffect, useState } from 'react'; import memoizeOne from 'memoize-one'; import { IIndexPattern } from 'src/plugins/data/public'; -import chrome from 'ui/chrome'; +import { useUiSetting$ } from '../../lib/kibana'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { IndexField, SourceQuery } from '../../graphql/types'; @@ -82,6 +82,7 @@ export const getBrowserFields = memoizeOne( ); export const WithSource = React.memo(({ children, sourceId }) => { + const [defaultIndex] = useUiSetting$(DEFAULT_INDEX_KEY); return ( query={sourceQuery} @@ -89,20 +90,14 @@ export const WithSource = React.memo(({ children, sourceId }) = notifyOnNetworkStatusChange variables={{ sourceId, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex, }} > {({ data }) => children({ indicesExist: get('source.status.indicesExist', data), browserFields: getBrowserFields(get('source.status.indexFields', data)), - indexPattern: getIndexFields( - chrome - .getUiSettingsClient() - .get(DEFAULT_INDEX_KEY) - .join(), - get('source.status.indexFields', data) - ), + indexPattern: getIndexFields(defaultIndex.join(), get('source.status.indexFields', data)), }) } diff --git a/x-pack/legacy/plugins/siem/public/containers/timeline/details/index.tsx b/x-pack/legacy/plugins/siem/public/containers/timeline/details/index.tsx index cfb3f8bd8dc7..721cfefe0178 100644 --- a/x-pack/legacy/plugins/siem/public/containers/timeline/details/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/timeline/details/index.tsx @@ -8,10 +8,10 @@ import { getOr } from 'lodash/fp'; import memoizeOne from 'memoize-one'; import React from 'react'; import { Query } from 'react-apollo'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../../common/constants'; import { DetailItem, GetTimelineDetailsQuery } from '../../../graphql/types'; +import { useUiSetting } from '../../../lib/kibana'; import { timelineDetailsQuery } from './index.gql_query'; @@ -38,7 +38,7 @@ export const TimelineDetailsComponentQuery = React.memo( sourceId, indexName, eventId, - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: useUiSetting(DEFAULT_INDEX_KEY), }; return executeQuery ? ( diff --git a/x-pack/legacy/plugins/siem/public/containers/timeline/index.tsx b/x-pack/legacy/plugins/siem/public/containers/timeline/index.tsx index 40ed3b3747c1..f7c2d067a29f 100644 --- a/x-pack/legacy/plugins/siem/public/containers/timeline/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/timeline/index.tsx @@ -8,9 +8,9 @@ import { getOr } from 'lodash/fp'; import memoizeOne from 'memoize-one'; import React from 'react'; import { Query } from 'react-apollo'; - -import chrome from 'ui/chrome'; +import { compose } from 'redux'; import { connect } from 'react-redux'; + import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { GetTimelineQuery, @@ -20,6 +20,7 @@ import { TimelineItem, } from '../../graphql/types'; import { inputsModel, inputsSelectors, State } from '../../store'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { createFilter } from '../helpers'; import { QueryTemplate, QueryTemplateProps } from '../query_template'; @@ -50,7 +51,7 @@ export interface OwnProps extends QueryTemplateProps { sortField: SortField; fields: string[]; } -type TimelineQueryProps = OwnProps & TimelineQueryReduxProps; +type TimelineQueryProps = OwnProps & TimelineQueryReduxProps & WithKibanaProps; class TimelineQueryComponent extends QueryTemplate< TimelineQueryProps, @@ -71,6 +72,7 @@ class TimelineQueryComponent extends QueryTemplate< id, indexPattern, isInspected, + kibana, limit, fields, filterQuery, @@ -84,7 +86,8 @@ class TimelineQueryComponent extends QueryTemplate< pagination: { limit, cursor: null, tiebreaker: null }, sortField, defaultIndex: - indexPattern?.title.split(',') ?? chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + indexPattern?.title.split(',') ?? + kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), inspect: isInspected, }; return ( @@ -158,4 +161,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const TimelineQuery = connect(makeMapStateToProps)(TimelineQueryComponent); +export const TimelineQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(TimelineQueryComponent); diff --git a/x-pack/legacy/plugins/siem/public/containers/tls/index.tsx b/x-pack/legacy/plugins/siem/public/containers/tls/index.tsx index 7abe14ae745c..3738355c8846 100644 --- a/x-pack/legacy/plugins/siem/public/containers/tls/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/tls/index.tsx @@ -10,7 +10,6 @@ import { Query } from 'react-apollo'; import { connect } from 'react-redux'; import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { PageInfoPaginated, @@ -20,6 +19,7 @@ import { FlowTargetSourceDest, } from '../../graphql/types'; import { inputsModel, networkModel, networkSelectors, State, inputsSelectors } from '../../store'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; @@ -53,7 +53,7 @@ export interface TlsComponentReduxProps { sort: TlsSortField; } -type TlsProps = OwnProps & TlsComponentReduxProps; +type TlsProps = OwnProps & TlsComponentReduxProps & WithKibanaProps; class TlsComponentQuery extends QueryTemplatePaginated< TlsProps, @@ -70,6 +70,7 @@ class TlsComponentQuery extends QueryTemplatePaginated< id = ID, ip, isInspected, + kibana, limit, skip, sourceId, @@ -77,7 +78,7 @@ class TlsComponentQuery extends QueryTemplatePaginated< sort, } = this.props; const variables: GetTlsQuery.Variables = { - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), filterQuery: createFilter(filterQuery), flowTarget, inspect: isInspected, @@ -152,6 +153,7 @@ const makeMapStateToProps = () => { }; }; -export const TlsQuery = compose>(connect(makeMapStateToProps))( - TlsComponentQuery -); +export const TlsQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(TlsComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/uncommon_processes/index.tsx b/x-pack/legacy/plugins/siem/public/containers/uncommon_processes/index.tsx index e623110fb717..520ade954eb5 100644 --- a/x-pack/legacy/plugins/siem/public/containers/uncommon_processes/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/uncommon_processes/index.tsx @@ -8,8 +8,8 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { GetUncommonProcessesQuery, @@ -17,6 +17,7 @@ import { UncommonProcessesEdges, } from '../../graphql/types'; import { hostsModel, hostsSelectors, inputsModel, State, inputsSelectors } from '../../store'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; @@ -48,7 +49,7 @@ export interface UncommonProcessesComponentReduxProps { limit: number; } -type UncommonProcessesProps = OwnProps & UncommonProcessesComponentReduxProps; +type UncommonProcessesProps = OwnProps & UncommonProcessesComponentReduxProps & WithKibanaProps; class UncommonProcessesComponentQuery extends QueryTemplatePaginated< UncommonProcessesProps, @@ -63,13 +64,14 @@ class UncommonProcessesComponentQuery extends QueryTemplatePaginated< filterQuery, id = ID, isInspected, + kibana, limit, skip, sourceId, startDate, } = this.props; const variables: GetUncommonProcessesQuery.Variables = { - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), filterQuery: createFilter(filterQuery), inspect: isInspected, pagination: generateTablePaginationOptions(activePage, limit), @@ -142,4 +144,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const UncommonProcessesQuery = connect(makeMapStateToProps)(UncommonProcessesComponentQuery); +export const UncommonProcessesQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(UncommonProcessesComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/containers/users/index.tsx b/x-pack/legacy/plugins/siem/public/containers/users/index.tsx index ea6453b5c5dd..ece73b7b10ff 100644 --- a/x-pack/legacy/plugins/siem/public/containers/users/index.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/users/index.tsx @@ -8,8 +8,8 @@ import { getOr } from 'lodash/fp'; import React from 'react'; import { Query } from 'react-apollo'; import { connect } from 'react-redux'; +import { compose } from 'redux'; -import chrome from 'ui/chrome'; import { DEFAULT_INDEX_KEY } from '../../../common/constants'; import { GetUsersQuery, @@ -19,6 +19,7 @@ import { UsersSortField, } from '../../graphql/types'; import { inputsModel, networkModel, networkSelectors, State, inputsSelectors } from '../../store'; +import { withKibana, WithKibanaProps } from '../../lib/kibana'; import { createFilter, getDefaultFetchPolicy } from '../helpers'; import { generateTablePaginationOptions } from '../../components/paginated_table/helpers'; import { QueryTemplatePaginated, QueryTemplatePaginatedProps } from '../query_template_paginated'; @@ -53,7 +54,7 @@ export interface UsersComponentReduxProps { sort: UsersSortField; } -type UsersProps = OwnProps & UsersComponentReduxProps; +type UsersProps = OwnProps & UsersComponentReduxProps & WithKibanaProps; class UsersComponentQuery extends QueryTemplatePaginated< UsersProps, @@ -70,6 +71,7 @@ class UsersComponentQuery extends QueryTemplatePaginated< id = ID, ip, isInspected, + kibana, limit, skip, sourceId, @@ -77,7 +79,7 @@ class UsersComponentQuery extends QueryTemplatePaginated< sort, } = this.props; const variables: GetUsersQuery.Variables = { - defaultIndex: chrome.getUiSettingsClient().get(DEFAULT_INDEX_KEY), + defaultIndex: kibana.services.uiSettings.get(DEFAULT_INDEX_KEY), filterQuery: createFilter(filterQuery), flowTarget, inspect: isInspected, @@ -154,4 +156,7 @@ const makeMapStateToProps = () => { return mapStateToProps; }; -export const UsersQuery = connect(makeMapStateToProps)(UsersComponentQuery); +export const UsersQuery = compose>( + connect(makeMapStateToProps), + withKibana +)(UsersComponentQuery); diff --git a/x-pack/legacy/plugins/siem/public/hooks/use_index_patterns.tsx b/x-pack/legacy/plugins/siem/public/hooks/use_index_patterns.tsx index 091315df314d..f5b595b0d01c 100644 --- a/x-pack/legacy/plugins/siem/public/hooks/use_index_patterns.tsx +++ b/x-pack/legacy/plugins/siem/public/hooks/use_index_patterns.tsx @@ -10,7 +10,7 @@ import { DEFAULT_KBN_VERSION } from '../../common/constants'; import { useStateToaster } from '../components/toasters'; import { errorToToaster } from '../components/ml/api/error_to_toaster'; import { IndexPatternSavedObject } from '../components/ml_popover/types'; -import { useKibanaUiSetting } from '../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../lib/kibana'; import { getIndexPatterns } from './api/api'; import * as i18n from './translations'; @@ -21,7 +21,7 @@ export const useIndexPatterns = (refreshToggle = false): Return => { const [indexPatterns, setIndexPatterns] = useState([]); const [isLoading, setIsLoading] = useState(true); const [, dispatchToaster] = useStateToaster(); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); useEffect(() => { let isSubscribed = true; diff --git a/x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_core.ts b/x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_core.ts deleted file mode 100644 index 7511f65dfb30..000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_core.ts +++ /dev/null @@ -1,13 +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 { createUiNewPlatformMock } from 'ui/new_platform/__mocks__/helpers'; - -const npStart = createUiNewPlatformMock().npStart; - -export function useKibanaCore() { - return npStart.core; -} diff --git a/x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_plugins.ts b/x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_plugins.ts deleted file mode 100644 index ab255f7c73a0..000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/compose/__mocks__/kibana_plugins.ts +++ /dev/null @@ -1,13 +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 { createUiNewPlatformMock } from 'ui/new_platform/__mocks__/helpers'; - -const npStart = createUiNewPlatformMock().npStart; - -export function useKibanaPlugins() { - return npStart.plugins; -} diff --git a/x-pack/legacy/plugins/siem/public/lib/compose/kibana_core.tsx b/x-pack/legacy/plugins/siem/public/lib/compose/kibana_core.tsx deleted file mode 100644 index f2fa261bf3eb..000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/compose/kibana_core.tsx +++ /dev/null @@ -1,25 +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 React, { createContext, useContext } from 'react'; -import { LegacyCoreStart } from 'src/core/public'; - -interface CoreMountContext { - core: LegacyCoreStart; -} - -// TODO: Replace CoreStart/CoreSetup with AppMountContext -// see: https://github.com/elastic/kibana/pull/41007 - -export const KibanaCoreContext = createContext({} as CoreMountContext['core']); - -export const KibanaCoreContextProvider: React.FC<{ core: CoreMountContext['core'] }> = props => ( - -); - -export function useKibanaCore() { - return useContext(KibanaCoreContext); -} diff --git a/x-pack/legacy/plugins/siem/public/lib/compose/kibana_plugins.tsx b/x-pack/legacy/plugins/siem/public/lib/compose/kibana_plugins.tsx deleted file mode 100644 index 7d1f1bc01edd..000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/compose/kibana_plugins.tsx +++ /dev/null @@ -1,27 +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 React, { createContext, useContext } from 'react'; -import { PluginsStart } from 'ui/new_platform/new_platform'; - -interface PluginsMountContext { - plugins: PluginsStart; -} - -// TODO: Replace CoreStart/CoreSetup with AppMountContext -// see: https://github.com/elastic/kibana/pull/41007 - -export const KibanaPluginsContext = createContext({} as PluginsMountContext['plugins']); - -export const KibanaPluginsContextProvider: React.FC<{ - plugins: PluginsMountContext['plugins']; -}> = props => ( - -); - -export function useKibanaPlugins() { - return useContext(KibanaPluginsContext); -} diff --git a/x-pack/legacy/plugins/siem/public/lib/kibana/__mocks__/index.ts b/x-pack/legacy/plugins/siem/public/lib/kibana/__mocks__/index.ts new file mode 100644 index 000000000000..93fd37c4d14c --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/lib/kibana/__mocks__/index.ts @@ -0,0 +1,19 @@ +/* + * 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 { + createKibanaContextProviderMock, + createUseUiSettingMock, + createUseUiSetting$Mock, + createUseKibanaMock, + createWithKibanaMock, +} from '../../../mock/kibana_react'; + +export const useKibana = jest.fn(createUseKibanaMock()); +export const useUiSetting = jest.fn(createUseUiSettingMock()); +export const useUiSetting$ = jest.fn(createUseUiSetting$Mock()); +export const withKibana = jest.fn(createWithKibanaMock()); +export const KibanaContextProvider = jest.fn(createKibanaContextProviderMock()); diff --git a/x-pack/legacy/plugins/siem/public/lib/kibana/index.ts b/x-pack/legacy/plugins/siem/public/lib/kibana/index.ts new file mode 100644 index 000000000000..96d9c8330d26 --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/lib/kibana/index.ts @@ -0,0 +1,31 @@ +/* + * 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 { + KibanaContextProvider, + KibanaReactContextValue, + useKibana, + useUiSetting, + useUiSetting$, + withKibana, +} from '../../../../../../../src/plugins/kibana_react/public'; +import { StartServices } from '../../apps/plugin'; + +export type KibanaContext = KibanaReactContextValue; +export interface WithKibanaProps { + kibana: KibanaContext; +} + +// eslint-disable-next-line react-hooks/rules-of-hooks +const typedUseKibana = () => useKibana(); + +export { + KibanaContextProvider, + typedUseKibana as useKibana, + useUiSetting, + useUiSetting$, + withKibana, +}; diff --git a/x-pack/legacy/plugins/siem/public/lib/settings/__mocks__/use_kibana_ui_setting.ts b/x-pack/legacy/plugins/siem/public/lib/settings/__mocks__/use_kibana_ui_setting.ts deleted file mode 100644 index 9f5639ce1999..000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/settings/__mocks__/use_kibana_ui_setting.ts +++ /dev/null @@ -1,13 +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 { mockFrameworks, getMockKibanaUiSetting } from '../../../mock'; - -type GenericValue = string | boolean | number; - -export const useKibanaUiSetting = (key: string, defaultValue?: GenericValue) => { - return getMockKibanaUiSetting(mockFrameworks.default_UTC)(key); -}; diff --git a/x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_setting.ts b/x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_setting.ts deleted file mode 100644 index 0a89edb85e6e..000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_setting.ts +++ /dev/null @@ -1,55 +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 { useCallback, useMemo } from 'react'; -// @ts-ignore: path dynamic for kibana -import { timezoneProvider } from 'ui/vis/lib/timezone'; - -import { DEFAULT_KBN_VERSION, DEFAULT_TIMEZONE_BROWSER } from '../../../common/constants'; -import { useKibanaCore } from '../compose/kibana_core'; -import { useObservable } from './use_observable'; - -type GenericValue = string | boolean | number; - -/** - * This hook behaves like a `useState` hook in that it provides a requested - * setting value (with an optional default) from the Kibana UI settings (also - * known as "advanced settings") and a setter to change that setting: - * - * ``` - * const [darkMode, setDarkMode] = useKibanaUiSetting('theme:darkMode'); - * ``` - * - * This is not just a static consumption of the value, but will reactively - * update when the underlying setting subscription of the `UiSettingsClient` - * notifies of a change. - * - * Unlike the `useState`, it doesn't give type guarantees for the value, - * because the underlying `UiSettingsClient` doesn't support that. - */ -export const useKibanaUiSetting = (key: string, defaultValue?: GenericValue) => { - const core = useKibanaCore(); - const uiSettingsClient = core.uiSettings; - const uiInjectedMetadata = core.injectedMetadata; - - if (key === DEFAULT_KBN_VERSION) { - return [uiInjectedMetadata.getKibanaVersion()]; - } - - /* eslint-disable react-hooks/rules-of-hooks */ - if (key === DEFAULT_TIMEZONE_BROWSER) { - return [useMemo(() => timezoneProvider(uiSettingsClient)(), [uiSettingsClient])]; - } - - const uiSetting$ = useMemo(() => uiSettingsClient.get$(key, defaultValue), [uiSettingsClient]); - const uiSetting = useObservable(uiSetting$); - const setUiSetting = useCallback((value: GenericValue) => uiSettingsClient.set(key, value), [ - uiSettingsClient, - ]); - /* eslint-enable react-hooks/rules-of-hooks */ - - return [uiSetting, setUiSetting]; -}; diff --git a/x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_settings.test.tsx b/x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_settings.test.tsx deleted file mode 100644 index 9af4759b2560..000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/settings/use_kibana_ui_settings.test.tsx +++ /dev/null @@ -1,50 +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 * as React from 'react'; - -import { DEFAULT_KBN_VERSION, DEFAULT_TIMEZONE_BROWSER } from '../../../common/constants'; -import { HookWrapper } from '../../mock/hook_wrapper'; -import { useKibanaCore } from '../compose/kibana_core'; -import { useKibanaUiSetting } from './use_kibana_ui_setting'; -import { mount } from 'enzyme'; - -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - injectedMetadata: { - getKibanaVersion: () => '8.0.0', - }, - uiSettings: { - get$: () => 'world', - }, -})); - -jest.mock('ui/vis/lib/timezone', () => ({ - timezoneProvider: () => () => 'America/New_York', -})); - -jest.mock('./use_observable', () => ({ - useObservable: (val: string) => val, -})); - -describe('useKibanaUiSetting', () => { - test('getKibanaVersion', () => { - const wrapper = mount( useKibanaUiSetting(DEFAULT_KBN_VERSION)} />); - expect(wrapper.text()).toEqual('["8.0.0"]'); - }); - - test('getTimezone', () => { - const wrapper = mount( - useKibanaUiSetting(DEFAULT_TIMEZONE_BROWSER)} /> - ); - expect(wrapper.text()).toEqual('["America/New_York"]'); - }); - - test('get any ui settings', () => { - const wrapper = mount( useKibanaUiSetting('hello')} />); - expect(wrapper.text()).toEqual('["world",null]'); - }); -}); diff --git a/x-pack/legacy/plugins/siem/public/lib/settings/use_observable.ts b/x-pack/legacy/plugins/siem/public/lib/settings/use_observable.ts deleted file mode 100644 index 536b6b2723ae..000000000000 --- a/x-pack/legacy/plugins/siem/public/lib/settings/use_observable.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. - */ - -import { useEffect, useState } from 'react'; -import { Observable } from 'rxjs'; - -export function useObservable(observable$: Observable): T | undefined; -export function useObservable(observable$: Observable, initialValue: T): T; -export function useObservable(observable$: Observable, initialValue?: T): T | undefined { - const [value, update] = useState(initialValue); - - useEffect(() => { - const s = observable$.subscribe(update); - return () => s.unsubscribe(); - }, [observable$]); - - return value; -} diff --git a/x-pack/legacy/plugins/siem/public/lib/theme/use_eui_theme.tsx b/x-pack/legacy/plugins/siem/public/lib/theme/use_eui_theme.tsx index b1defcb34066..1696001203bc 100644 --- a/x-pack/legacy/plugins/siem/public/lib/theme/use_eui_theme.tsx +++ b/x-pack/legacy/plugins/siem/public/lib/theme/use_eui_theme.tsx @@ -8,9 +8,9 @@ import darkTheme from '@elastic/eui/dist/eui_theme_dark.json'; import lightTheme from '@elastic/eui/dist/eui_theme_light.json'; import { DEFAULT_DARK_MODE } from '../../../common/constants'; -import { useKibanaUiSetting } from '../settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../kibana'; export const useEuiTheme = () => { - const [darkMode] = useKibanaUiSetting(DEFAULT_DARK_MODE); + const [darkMode] = useUiSetting$(DEFAULT_DARK_MODE); return darkMode ? darkTheme : lightTheme; }; diff --git a/x-pack/legacy/plugins/siem/public/mock/kibana_core.ts b/x-pack/legacy/plugins/siem/public/mock/kibana_core.ts new file mode 100644 index 000000000000..cf3523a6260b --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/mock/kibana_core.ts @@ -0,0 +1,13 @@ +/* + * 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 { createUiNewPlatformMock } from 'ui/new_platform/__mocks__/helpers'; + +export const createKibanaCoreSetupMock = () => createUiNewPlatformMock().npSetup.core; +export const createKibanaPluginsSetupMock = () => createUiNewPlatformMock().npSetup.plugins; + +export const createKibanaCoreStartMock = () => createUiNewPlatformMock().npStart.core; +export const createKibanaPluginsStartMock = () => createUiNewPlatformMock().npStart.plugins; diff --git a/x-pack/legacy/plugins/siem/public/mock/kibana_react.ts b/x-pack/legacy/plugins/siem/public/mock/kibana_react.ts new file mode 100644 index 000000000000..15944df1822b --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/mock/kibana_react.ts @@ -0,0 +1,95 @@ +/* + * 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 { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; + +import { + DEFAULT_SIEM_TIME_RANGE, + DEFAULT_SIEM_REFRESH_INTERVAL, + DEFAULT_INDEX_KEY, + DEFAULT_DATE_FORMAT, + DEFAULT_DATE_FORMAT_TZ, + DEFAULT_DARK_MODE, + DEFAULT_TIME_RANGE, + DEFAULT_REFRESH_RATE_INTERVAL, + DEFAULT_FROM, + DEFAULT_TO, + DEFAULT_INTERVAL_PAUSE, + DEFAULT_INTERVAL_VALUE, + DEFAULT_TIMEZONE_BROWSER, +} from '../../common/constants'; +import { defaultIndexPattern } from '../../default_index_pattern'; +import { createKibanaCoreStartMock, createKibanaPluginsStartMock } from './kibana_core'; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const mockUiSettings: Record = { + [DEFAULT_TIME_RANGE]: { from: 'now-15m', to: 'now', mode: 'quick' }, + [DEFAULT_REFRESH_RATE_INTERVAL]: { pause: false, value: 0 }, + [DEFAULT_SIEM_TIME_RANGE]: { + from: DEFAULT_FROM, + to: DEFAULT_TO, + }, + [DEFAULT_SIEM_REFRESH_INTERVAL]: { + pause: DEFAULT_INTERVAL_PAUSE, + value: DEFAULT_INTERVAL_VALUE, + }, + [DEFAULT_INDEX_KEY]: defaultIndexPattern, + [DEFAULT_DATE_FORMAT_TZ]: 'UTC', + [DEFAULT_TIMEZONE_BROWSER]: 'America/New_York', + [DEFAULT_DATE_FORMAT]: 'MMM D, YYYY @ HH:mm:ss.SSS', + [DEFAULT_DARK_MODE]: false, +}; + +export const createUseUiSettingMock = () => ( + key: string, + defaultValue?: T +): T => { + const result = mockUiSettings[key]; + + if (typeof result != null) return result; + + if (defaultValue != null) { + return defaultValue; + } + + throw new Error(`Unexpected config key: ${key}`); +}; + +export const createUseUiSetting$Mock = () => { + const useUiSettingMock = createUseUiSettingMock(); + + return ( + key: string, + defaultValue?: T + ): [T, () => void] | undefined => [useUiSettingMock(key, defaultValue), jest.fn()]; +}; + +export const createUseKibanaMock = () => { + const services = { ...createKibanaCoreStartMock(), ...createKibanaPluginsStartMock() }; + + return () => ({ services }); +}; + +export const createWithKibanaMock = () => { + const kibana = createUseKibanaMock()(); + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return (Component: any) => (props: any) => { + return React.createElement(Component, { ...props, kibana }); + }; +}; + +export const createKibanaContextProviderMock = () => { + const kibana = createUseKibanaMock()(); + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return ({ services, ...rest }: any) => + React.createElement(KibanaContextProvider, { + ...rest, + services: { ...kibana.services, ...services }, + }); +}; diff --git a/x-pack/legacy/plugins/siem/public/mock/test_providers.tsx b/x-pack/legacy/plugins/siem/public/mock/test_providers.tsx index d4c06d998c5a..6c0a85e3ef77 100644 --- a/x-pack/legacy/plugins/siem/public/mock/test_providers.tsx +++ b/x-pack/legacy/plugins/siem/public/mock/test_providers.tsx @@ -17,12 +17,9 @@ import { Store } from 'redux'; import { BehaviorSubject } from 'rxjs'; import { ThemeProvider } from 'styled-components'; -import { CoreStart } from 'src/core/public'; -import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; - import { createStore, State } from '../store'; import { mockGlobalState } from './global_state'; -import { mockUiSettings } from './ui_settings'; +import { createKibanaContextProviderMock } from './kibana_react'; jest.mock('ui/new_platform'); @@ -41,29 +38,6 @@ export const apolloClient = new ApolloClient({ export const apolloClientObservable = new BehaviorSubject(apolloClient); -const services = { - uiSettings: mockUiSettings, - savedObjects: {} as CoreStart['savedObjects'], - notifications: {} as CoreStart['notifications'], - docLinks: { - links: { - query: { - kueryQuerySyntax: '', - }, - }, - } as CoreStart['docLinks'], - http: {} as CoreStart['http'], - overlays: {} as CoreStart['overlays'], - storage: { - get: () => {}, - }, - data: { - query: { - savedQueries: {}, - }, - }, -}; - const localStorageMock = () => { let store: Record = {}; @@ -84,11 +58,13 @@ Object.defineProperty(window, 'localStorage', { value: localStorageMock(), }); +const MockKibanaContextProvider = createKibanaContextProviderMock(); + /** A utility for wrapping children in the providers required to run most tests */ export const TestProviders = React.memo( ({ children, store = createStore(state, apolloClientObservable), onDragEnd = jest.fn() }) => ( - + ({ eui: euiDarkVars, darkMode: true })}> @@ -96,7 +72,7 @@ export const TestProviders = React.memo( - + ) ); diff --git a/x-pack/legacy/plugins/siem/public/mock/ui_settings.ts b/x-pack/legacy/plugins/siem/public/mock/ui_settings.ts deleted file mode 100644 index 6c6411c6bda5..000000000000 --- a/x-pack/legacy/plugins/siem/public/mock/ui_settings.ts +++ /dev/null @@ -1,75 +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 chrome from 'ui/chrome'; -import { - DEFAULT_SIEM_TIME_RANGE, - DEFAULT_SIEM_REFRESH_INTERVAL, - DEFAULT_INDEX_KEY, - DEFAULT_DATE_FORMAT, - DEFAULT_DATE_FORMAT_TZ, - DEFAULT_DARK_MODE, - DEFAULT_TIME_RANGE, - DEFAULT_REFRESH_RATE_INTERVAL, - DEFAULT_FROM, - DEFAULT_TO, - DEFAULT_INTERVAL_PAUSE, - DEFAULT_INTERVAL_VALUE, -} from '../../common/constants'; -import { defaultIndexPattern } from '../../default_index_pattern'; - -chrome.getUiSettingsClient().get.mockImplementation((key: string) => { - switch (key) { - case DEFAULT_TIME_RANGE: - return { from: 'now-15m', to: 'now', mode: 'quick' }; - case DEFAULT_REFRESH_RATE_INTERVAL: - return { pause: false, value: 0 }; - case DEFAULT_SIEM_TIME_RANGE: - return { - from: DEFAULT_FROM, - to: DEFAULT_TO, - }; - case DEFAULT_SIEM_REFRESH_INTERVAL: - return { - pause: DEFAULT_INTERVAL_PAUSE, - value: DEFAULT_INTERVAL_VALUE, - }; - case DEFAULT_INDEX_KEY: - return defaultIndexPattern; - case DEFAULT_DATE_FORMAT_TZ: - return 'Asia/Taipei'; - case DEFAULT_DATE_FORMAT: - return 'MMM D, YYYY @ HH:mm:ss.SSS'; - case DEFAULT_DARK_MODE: - return false; - default: - throw new Error(`Unexpected config key: ${key}`); - } -}); - -export interface MockNpSetUp { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - core: { uiSettings: any }; -} - -type Config = - | 'query:allowLeadingWildcards' - | 'query:queryString:options' - | 'courier:ignoreFilterIfFieldNotInIndex' - | 'dateFormat:tz'; - -export const mockUiSettings = { - get: (item: Config) => { - return mockUiSettings[item]; - }, - get$: () => ({ - subscribe: jest.fn(), - }), - 'query:allowLeadingWildcards': true, - 'query:queryString:options': {}, - 'courier:ignoreFilterIfFieldNotInIndex': true, - 'dateFormat:tz': 'Browser', -}; diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/index.tsx index 599870117890..aeb5e677374f 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/index.tsx @@ -25,7 +25,7 @@ import { SignalFilterOption, SignalsTableFilterGroup, } from './signals_filter_group'; -import { useKibanaUiSetting } from '../../../../lib/settings/use_kibana_ui_setting'; +import { useKibana, useUiSetting$ } from '../../../../lib/kibana'; import { DEFAULT_KBN_VERSION, DEFAULT_SIGNALS_INDEX } from '../../../../../common/constants'; import { defaultHeaders } from '../../../../components/timeline/body/column_headers/default_headers'; import { ColumnHeader } from '../../../../components/timeline/body/column_headers/column_header'; @@ -43,7 +43,6 @@ import { } from './types'; import { inputsActions } from '../../../../store/inputs'; import { combineQueries } from '../../../../components/timeline/helpers'; -import { useKibanaCore } from '../../../../lib/compose/kibana_core'; import { useFetchIndexPatterns } from '../../../../containers/detection_engine/rules/fetch_index_patterns'; import { InputsRange } from '../../../../store/inputs/model'; import { Query } from '../../../../../../../../../src/plugins/data/common/query'; @@ -122,13 +121,13 @@ export const SignalsTableComponent = React.memo( const [{ browserFields, indexPatterns }] = useFetchIndexPatterns([ `${DEFAULT_SIGNALS_INDEX}-default`, ]); // TODO Get from new FrankInspired XavierHook - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); - const core = useKibanaCore(); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); + const kibana = useKibana(); const getGlobalQuery = useCallback(() => { if (browserFields != null && indexPatterns != null) { return combineQueries({ - config: esQuery.getEsQueryConfig(core.uiSettings), + config: esQuery.getEsQueryConfig(kibana.services.uiSettings), dataProviders: [], indexPattern: indexPatterns, browserFields, diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/signals_utility_bar/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/signals_utility_bar/index.tsx index 8d754eb1d3e1..72b250470d19 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/signals_utility_bar/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals/signals_utility_bar/index.tsx @@ -16,7 +16,7 @@ import { } from '../../../../../components/detection_engine/utility_bar'; import * as i18n from './translations'; import { getBatchItems } from './batch_actions'; -import { useKibanaUiSetting } from '../../../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../../../lib/kibana'; import { DEFAULT_NUMBER_FORMAT } from '../../../../../../common/constants'; import { TimelineNonEcsData } from '../../../../../graphql/types'; import { SendSignalsToTimeline, UpdateSignalsStatus } from '../types'; @@ -45,7 +45,7 @@ export const SignalsUtilityBar = React.memo( updateSignalsStatus, sendSignalsToTimeline, }) => { - const [defaultNumberFormat] = useKibanaUiSetting(DEFAULT_NUMBER_FORMAT); + const [defaultNumberFormat] = useUiSetting$(DEFAULT_NUMBER_FORMAT); const getBatchItemsPopoverContent = useCallback( (closePopover: () => void) => ( diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/detection_engine_empty_page.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/detection_engine_empty_page.tsx index cb3e69061539..a217fd6a737e 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/detection_engine_empty_page.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/detection_engine_empty_page.tsx @@ -6,8 +6,8 @@ import React from 'react'; import chrome from 'ui/chrome'; -import { documentationLinks } from 'ui/documentation_links'; +import { useKibana } from '../../lib/kibana'; import { EmptyPage } from '../../components/empty_page'; import * as i18n from './translations'; @@ -21,7 +21,7 @@ export const DetectionEngineEmptyPage = React.memo(() => ( actionSecondaryIcon="popout" actionSecondaryLabel={i18n.EMPTY_ACTION_SECONDARY} actionSecondaryTarget="_blank" - actionSecondaryUrl={documentationLinks.siem} + actionSecondaryUrl={useKibana().services.docLinks.links.siem} data-test-subj="empty-page" title={i18n.EMPTY_TITLE} /> diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx index 4497474b387b..442360bbf148 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/all/index.tsx @@ -31,7 +31,7 @@ import { getBatchItems } from './batch_actions'; import { EuiBasicTableOnChange, TableData } from '../types'; import { allRulesReducer, State } from './reducer'; import * as i18n from '../translations'; -import { useKibanaUiSetting } from '../../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../../lib/kibana'; import { DEFAULT_KBN_VERSION } from '../../../../../common/constants'; import { JSONDownloader } from '../components/json_downloader'; import { useStateToaster } from '../../../../components/toasters'; @@ -78,7 +78,7 @@ export const AllRules = React.memo<{ importCompleteToggle: boolean }>(importComp const history = useHistory(); const [isInitialLoad, setIsInitialLoad] = useState(true); const [isLoadingRules, rulesData] = useRules(pagination, filterOptions, refreshToggle); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [, dispatchToaster] = useStateToaster(); const getBatchItemsPopoverContent = useCallback( diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx index f2fbd373cf4b..39c660a0079a 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/description_step/index.tsx @@ -25,7 +25,7 @@ import { FilterManager, Query, } from '../../../../../../../../../../src/plugins/data/public'; -import { useKibanaCore } from '../../../../../lib/compose/kibana_core'; +import { useKibana } from '../../../../../lib/kibana'; import { FilterLabel } from './filter_label'; import { FormSchema } from '../shared_imports'; import * as I18n from './translations'; @@ -70,8 +70,8 @@ const MyEuiTextArea = styled(EuiTextArea)` export const StepRuleDescription = memo( ({ data, direction = 'row', indexPatterns, schema }) => { - const core = useKibanaCore(); - const [filterManager] = useState(new FilterManager(core.uiSettings)); + const kibana = useKibana(); + const [filterManager] = useState(new FilterManager(kibana.services.uiSettings)); const keys = Object.keys(schema); const listItems = keys.reduce( diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/import_rule_modal/index.test.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/import_rule_modal/index.test.tsx index 8dcce36e1a40..381a3138bf61 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/import_rule_modal/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/import_rule_modal/index.test.tsx @@ -8,20 +8,11 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import * as React from 'react'; import { ImportRuleModalComponent } from './index'; -import { useKibanaUiSetting } from '../../../../../lib/settings/use_kibana_ui_setting'; -import { getMockKibanaUiSetting, MockFrameworks } from '../../../../../mock'; -import { DEFAULT_KBN_VERSION } from '../../../../../../common/constants'; -const mockUseKibanaUiSetting: jest.Mock = useKibanaUiSetting as jest.Mock; -jest.mock('../../../../../lib/settings/use_kibana_ui_setting', () => ({ - useKibanaUiSetting: jest.fn(), -})); +jest.mock('../../../../../lib/kibana'); describe('ImportRuleModal', () => { test('renders correctly against snapshot', () => { - mockUseKibanaUiSetting.mockImplementation( - getMockKibanaUiSetting((DEFAULT_KBN_VERSION as unknown) as MockFrameworks) - ); const wrapper = shallow( { const [selectedFiles, setSelectedFiles] = useState(null); const [isImporting, setIsImporting] = useState(false); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const [, dispatchToaster] = useStateToaster(); const cleanupAndCloseModal = () => { diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/query_bar/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/query_bar/index.tsx index d8d77fcf8abf..c294ec24c4cb 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/query_bar/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/query_bar/index.tsx @@ -20,7 +20,7 @@ import { } from '../../../../../../../../../../src/plugins/data/public'; import { QueryBar } from '../../../../../components/query_bar'; -import { useKibanaCore } from '../../../../../lib/compose/kibana_core'; +import { useKibana } from '../../../../../lib/kibana'; import { useSavedQueryServices } from '../../../../../utils/saved_query_services'; import { FieldHook, getFieldValidityAndErrorMessage } from '../shared_imports'; @@ -68,8 +68,8 @@ export const QueryBarDefineRule = ({ const [queryDraft, setQueryDraft] = useState({ query: '', language: 'kuery' }); const { isInvalid, errorMessage } = getFieldValidityAndErrorMessage(field); - const core = useKibanaCore(); - const [filterManager] = useState(new FilterManager(core.uiSettings)); + const kibana = useKibana(); + const [filterManager] = useState(new FilterManager(kibana.services.uiSettings)); const savedQueryServices = useSavedQueryServices(); diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.test.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.test.tsx index 6809acd4b33f..7a3a99b18397 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.test.tsx @@ -8,20 +8,8 @@ import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import * as React from 'react'; -import { useKibanaCore } from '../../../../../lib/compose/kibana_core'; - import { RuleSwitchComponent } from './index'; - -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../../../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: { - get$: () => 'world', - }, - injectedMetadata: { - getKibanaVersion: () => '8.0.0', - }, -})); +jest.mock('../../../../../lib/kibana'); describe('RuleSwitch', () => { test('renders correctly against snapshot', () => { diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.tsx index a5d983ec8e22..54f0fc453830 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/rule_switch/index.tsx @@ -17,7 +17,7 @@ import React, { useCallback, useState, useEffect } from 'react'; import { DEFAULT_KBN_VERSION } from '../../../../../../common/constants'; import { enableRules } from '../../../../../containers/detection_engine/rules'; -import { useKibanaUiSetting } from '../../../../../lib/settings/use_kibana_ui_setting'; +import { useUiSetting$ } from '../../../../../lib/kibana'; import { enableRulesAction } from '../../all/actions'; import { Action } from '../../all/reducer'; @@ -50,7 +50,7 @@ export const RuleSwitchComponent = ({ }: RuleSwitchProps) => { const [myIsLoading, setMyIsLoading] = useState(false); const [myEnabled, setMyEnabled] = useState(enabled ?? false); - const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); + const [kbnVersion] = useUiSetting$(DEFAULT_KBN_VERSION); const onRuleStateChange = useCallback( async (event: EuiSwitchEvent) => { diff --git a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_define_rule/index.tsx b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_define_rule/index.tsx index b94e3c35f3ea..cc4e959cc9c7 100644 --- a/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_define_rule/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/detection_engine/rules/components/step_define_rule/index.tsx @@ -9,9 +9,9 @@ import { isEqual, get } from 'lodash/fp'; import React, { memo, useCallback, useState, useEffect } from 'react'; import { IIndexPattern } from '../../../../../../../../../../src/plugins/data/public'; -import { useUiSetting$ } from '../../../../../../../../../../src/plugins/kibana_react/public'; import { useFetchIndexPatterns } from '../../../../../containers/detection_engine/rules'; import { DEFAULT_INDEX_KEY } from '../../../../../../common/constants'; +import { useUiSetting$ } from '../../../../../lib/kibana'; import * as RuleI18n from '../../translations'; import { DefineStepRule, RuleStep, RuleStepProps } from '../../types'; import { StepRuleDescription } from '../description_step'; diff --git a/x-pack/legacy/plugins/siem/public/pages/hosts/details/details_tabs.test.tsx b/x-pack/legacy/plugins/siem/public/pages/hosts/details/details_tabs.test.tsx index 8d45bbbe34d3..092c2463419d 100644 --- a/x-pack/legacy/plugins/siem/public/pages/hosts/details/details_tabs.test.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/hosts/details/details_tabs.test.tsx @@ -10,21 +10,13 @@ import { MemoryRouter } from 'react-router-dom'; import { mockIndexPattern } from '../../../mock/index_pattern'; import { TestProviders } from '../../../mock/test_providers'; -import { mockUiSettings } from '../../../mock/ui_settings'; import { HostDetailsTabs } from './details_tabs'; import { SetAbsoluteRangeDatePicker } from './types'; import { hostDetailsPagePath } from '../types'; import { type } from './utils'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; import { useMountAppended } from '../../../utils/use_mount_appended'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); +jest.mock('../../../lib/kibana'); jest.mock('../../../containers/source', () => ({ indicesExistOrDataTemporarilyUnavailable: () => true, diff --git a/x-pack/legacy/plugins/siem/public/pages/hosts/details/index.tsx b/x-pack/legacy/plugins/siem/public/pages/hosts/details/index.tsx index e062e65bde49..b548d91615d1 100644 --- a/x-pack/legacy/plugins/siem/public/pages/hosts/details/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/hosts/details/index.tsx @@ -28,7 +28,7 @@ import { HostOverviewByNameQuery } from '../../../containers/hosts/overview'; import { KpiHostDetailsQuery } from '../../../containers/kpi_host_details'; import { indicesExistOrDataTemporarilyUnavailable, WithSource } from '../../../containers/source'; import { LastEventIndexKey } from '../../../graphql/types'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; +import { useKibana } from '../../../lib/kibana'; import { convertToBuildEsQuery } from '../../../lib/keury'; import { inputsSelectors, State } from '../../../store'; import { setHostDetailsTablesActivePageToZero as dispatchHostDetailsTablesActivePageToZero } from '../../../store/hosts/actions'; @@ -63,7 +63,7 @@ const HostDetailsComponent = React.memo( setHostDetailsTablesActivePageToZero(null); }, [setHostDetailsTablesActivePageToZero, detailName]); const capabilities = useContext(MlCapabilitiesContext); - const core = useKibanaCore(); + const kibana = useKibana(); const hostDetailsPageFilters: esFilters.Filter[] = [ { meta: { @@ -100,7 +100,7 @@ const HostDetailsComponent = React.memo( {({ indicesExist, indexPattern }) => { const filterQuery = convertToBuildEsQuery({ - config: esQuery.getEsQueryConfig(core.uiSettings), + config: esQuery.getEsQueryConfig(kibana.services.uiSettings), indexPattern, queries: [query], filters: getFilters(), diff --git a/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.test.tsx b/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.test.tsx index f08cee824afa..00dcb5908a98 100644 --- a/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.test.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.test.tsx @@ -12,30 +12,15 @@ import { MockedProvider } from 'react-apollo/test-utils'; import { ActionCreator } from 'typescript-fsa'; import '../../mock/match_media'; - -import { SiemNavigation } from '../../components/navigation'; import { mocksSource } from '../../containers/source/mock'; import { wait } from '../../lib/helpers'; import { TestProviders } from '../../mock'; -import { mockUiSettings } from '../../mock/ui_settings'; import { InputsModelId } from '../../store/inputs/constants'; +import { SiemNavigation } from '../../components/navigation'; import { HostsComponentProps } from './types'; import { Hosts } from './hosts'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; - -jest.mock('../../lib/settings/use_kibana_ui_setting'); -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); - -jest.mock('ui/documentation_links', () => ({ - documentationLinks: { - kibana: 'http://www.example.com', - }, -})); +jest.mock('../../lib/kibana'); // Test will fail because we will to need to mock some core services to make the test work // For now let's forget about SiemSearchBar and QueryBar diff --git a/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.tsx b/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.tsx index 6d217a930188..6b69f06b97b8 100644 --- a/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/hosts/hosts.tsx @@ -25,7 +25,7 @@ import { GlobalTimeArgs } from '../../containers/global_time'; import { KpiHostsQuery } from '../../containers/kpi_hosts'; import { indicesExistOrDataTemporarilyUnavailable, WithSource } from '../../containers/source'; import { LastEventIndexKey } from '../../graphql/types'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; +import { useKibana } from '../../lib/kibana'; import { convertToBuildEsQuery } from '../../lib/keury'; import { inputsSelectors, State, hostsModel } from '../../store'; import { setAbsoluteRangeDatePicker as dispatchSetAbsoluteRangeDatePicker } from '../../store/inputs/actions'; @@ -54,7 +54,7 @@ const HostsComponent = React.memo( hostsPagePath, }) => { const capabilities = React.useContext(MlCapabilitiesContext); - const core = useKibanaCore(); + const kibana = useKibana(); const { tabName } = useParams(); const hostsFilters = React.useMemo(() => { @@ -75,7 +75,7 @@ const HostsComponent = React.memo( {({ indicesExist, indexPattern }) => { const filterQuery = convertToBuildEsQuery({ - config: esQuery.getEsQueryConfig(core.uiSettings), + config: esQuery.getEsQueryConfig(kibana.services.uiSettings), indexPattern, queries: [query], filters: hostsFilters, diff --git a/x-pack/legacy/plugins/siem/public/pages/hosts/hosts_empty_page.tsx b/x-pack/legacy/plugins/siem/public/pages/hosts/hosts_empty_page.tsx index ecd1e4f378cc..1d2a3f83e880 100644 --- a/x-pack/legacy/plugins/siem/public/pages/hosts/hosts_empty_page.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/hosts/hosts_empty_page.tsx @@ -6,26 +6,30 @@ import React from 'react'; import chrome from 'ui/chrome'; -import { documentationLinks } from 'ui/documentation_links'; import { EmptyPage } from '../../components/empty_page'; +import { useKibana } from '../../lib/kibana'; import * as i18n from './translations'; const basePath = chrome.getBasePath(); -export const HostsEmptyPage = React.memo(() => ( - -)); +export const HostsEmptyPage = React.memo(() => { + const docLinks = useKibana().services.docLinks; + + return ( + + ); +}); HostsEmptyPage.displayName = 'HostsEmptyPage'; diff --git a/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.test.tsx b/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.test.tsx index 72f785884764..d624631c1fea 100644 --- a/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.test.tsx @@ -16,27 +16,19 @@ import '../../../mock/match_media'; import { mocksSource } from '../../../containers/source/mock'; import { FlowTarget } from '../../../graphql/types'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; import { apolloClientObservable, mockGlobalState, TestProviders } from '../../../mock'; import { useMountAppended } from '../../../utils/use_mount_appended'; -import { mockUiSettings } from '../../../mock/ui_settings'; import { createStore, State } from '../../../store'; import { InputsModelId } from '../../../store/inputs/constants'; import { IPDetailsComponent, IPDetails } from './index'; -jest.mock('../../../lib/settings/use_kibana_ui_setting'); - type Action = 'PUSH' | 'POP' | 'REPLACE'; const pop: Action = 'POP'; type GlobalWithFetch = NodeJS.Global & { fetch: jest.Mock }; -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); +jest.mock('../../../lib/kibana'); // Test will fail because we will to need to mock some core services to make the test work // For now let's forget about SiemSearchBar and QueryBar @@ -106,12 +98,6 @@ const getMockProps = (ip: string) => ({ setIpDetailsTablesActivePageToZero: (jest.fn() as unknown) as ActionCreator, }); -jest.mock('ui/documentation_links', () => ({ - documentationLinks: { - siem: 'http://www.example.com', - }, -})); - describe('Ip Details', () => { const mount = useMountAppended(); diff --git a/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.tsx b/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.tsx index 97db422b539e..99ca12292a52 100644 --- a/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/network/ip_details/index.tsx @@ -24,7 +24,7 @@ import { WrapperPage } from '../../../components/wrapper_page'; import { IpOverviewQuery } from '../../../containers/ip_overview'; import { indicesExistOrDataTemporarilyUnavailable, WithSource } from '../../../containers/source'; import { FlowTargetSourceDest, LastEventIndexKey } from '../../../graphql/types'; -import { useKibanaCore } from '../../../lib/compose/kibana_core'; +import { useKibana } from '../../../lib/kibana'; import { decodeIpv6 } from '../../../lib/helpers'; import { convertToBuildEsQuery } from '../../../lib/keury'; import { ConditionalFlexGroup } from '../../../pages/network/navigation/conditional_flex_group'; @@ -70,7 +70,7 @@ export const IPDetailsComponent = ({ }, [setAbsoluteRangeDatePicker] ); - const core = useKibanaCore(); + const kibana = useKibana(); useEffect(() => { setIpDetailsTablesActivePageToZero(null); @@ -82,7 +82,7 @@ export const IPDetailsComponent = ({ {({ indicesExist, indexPattern }) => { const ip = decodeIpv6(detailName); const filterQuery = convertToBuildEsQuery({ - config: esQuery.getEsQueryConfig(core.uiSettings), + config: esQuery.getEsQueryConfig(kibana.services.uiSettings), indexPattern, queries: [query], filters, diff --git a/x-pack/legacy/plugins/siem/public/pages/network/network.test.tsx b/x-pack/legacy/plugins/siem/public/pages/network/network.test.tsx index 327b0fb4c1e5..335bb62c5c85 100644 --- a/x-pack/legacy/plugins/siem/public/pages/network/network.test.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/network/network.test.tsx @@ -13,24 +13,10 @@ import { MockedProvider } from 'react-apollo/test-utils'; import '../../mock/match_media'; import { mocksSource } from '../../containers/source/mock'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; import { TestProviders } from '../../mock'; -import { mockUiSettings } from '../../mock/ui_settings'; import { Network } from './network'; -jest.mock('../../lib/settings/use_kibana_ui_setting'); - -jest.mock('ui/documentation_links', () => ({ - documentationLinks: { - kibana: 'http://www.example.com', - }, -})); - -const mockUseKibanaCore = useKibanaCore as jest.Mock; -jest.mock('../../lib/compose/kibana_core'); -mockUseKibanaCore.mockImplementation(() => ({ - uiSettings: mockUiSettings, -})); +jest.mock('../../lib/kibana'); // Test will fail because we will to need to mock some core services to make the test work // For now let's forget about SiemSearchBar and QueryBar diff --git a/x-pack/legacy/plugins/siem/public/pages/network/network.tsx b/x-pack/legacy/plugins/siem/public/pages/network/network.tsx index 0d8d3a6753c5..c39935742a2e 100644 --- a/x-pack/legacy/plugins/siem/public/pages/network/network.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/network/network.tsx @@ -23,7 +23,7 @@ import { WrapperPage } from '../../components/wrapper_page'; import { KpiNetworkQuery } from '../../containers/kpi_network'; import { indicesExistOrDataTemporarilyUnavailable, WithSource } from '../../containers/source'; import { LastEventIndexKey } from '../../graphql/types'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; +import { useKibana } from '../../lib/kibana'; import { convertToBuildEsQuery } from '../../lib/keury'; import { networkModel, State, inputsSelectors } from '../../store'; import { setAbsoluteRangeDatePicker as dispatchSetAbsoluteRangeDatePicker } from '../../store/inputs/actions'; @@ -51,7 +51,7 @@ const NetworkComponent = React.memo( hasMlUserPermissions, capabilitiesFetched, }) => { - const core = useKibanaCore(); + const kibana = useKibana(); const { tabName } = useParams(); const networkFilters = useMemo(() => { @@ -72,7 +72,7 @@ const NetworkComponent = React.memo( {({ indicesExist, indexPattern }) => { const filterQuery = convertToBuildEsQuery({ - config: esQuery.getEsQueryConfig(core.uiSettings), + config: esQuery.getEsQueryConfig(kibana.services.uiSettings), indexPattern, queries: [query], filters: networkFilters, diff --git a/x-pack/legacy/plugins/siem/public/pages/network/network_empty_page.tsx b/x-pack/legacy/plugins/siem/public/pages/network/network_empty_page.tsx index 34e7f49bd9bd..e22802fd29d4 100644 --- a/x-pack/legacy/plugins/siem/public/pages/network/network_empty_page.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/network/network_empty_page.tsx @@ -6,26 +6,29 @@ import React from 'react'; import chrome from 'ui/chrome'; -import { documentationLinks } from 'ui/documentation_links'; +import { useKibana } from '../../lib/kibana'; import { EmptyPage } from '../../components/empty_page'; - import * as i18n from './translations'; const basePath = chrome.getBasePath(); -export const NetworkEmptyPage = React.memo(() => ( - -)); +export const NetworkEmptyPage = React.memo(() => { + const docLinks = useKibana().services.docLinks; + + return ( + + ); +}); NetworkEmptyPage.displayName = 'NetworkEmptyPage'; diff --git a/x-pack/legacy/plugins/siem/public/pages/overview/overview.test.tsx b/x-pack/legacy/plugins/siem/public/pages/overview/overview.test.tsx index 833030e0dc8a..300df4a742ad 100644 --- a/x-pack/legacy/plugins/siem/public/pages/overview/overview.test.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/overview/overview.test.tsx @@ -10,17 +10,11 @@ import * as React from 'react'; import { MockedProvider } from 'react-apollo/test-utils'; import { MemoryRouter } from 'react-router-dom'; -import { Overview } from './index'; - -import '../../mock/ui_settings'; -import { mocksSource } from '../../containers/source/mock'; import { TestProviders } from '../../mock'; +import { mocksSource } from '../../containers/source/mock'; +import { Overview } from './index'; -jest.mock('ui/documentation_links', () => ({ - documentationLinks: { - kibana: 'http://www.example.com', - }, -})); +jest.mock('../../lib/kibana'); let localSource: Array<{ request: {}; diff --git a/x-pack/legacy/plugins/siem/public/pages/overview/overview.tsx b/x-pack/legacy/plugins/siem/public/pages/overview/overview.tsx index de976b1a5c5a..a0e94431054c 100644 --- a/x-pack/legacy/plugins/siem/public/pages/overview/overview.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/overview/overview.tsx @@ -8,8 +8,8 @@ import { EuiFlexGroup } from '@elastic/eui'; import moment from 'moment'; import React from 'react'; import chrome from 'ui/chrome'; -import { documentationLinks } from 'ui/documentation_links'; +import { useKibana } from '../../lib/kibana'; import { EmptyPage } from '../../components/empty_page'; import { HeaderPage } from '../../components/header_page'; import { OverviewHost } from '../../components/page/overview/overview_host'; @@ -24,6 +24,7 @@ import * as i18n from './translations'; const basePath = chrome.getBasePath(); export const OverviewComponent = React.memo(() => { + const docLinks = useKibana().services.docLinks; const dateEnd = Date.now(); const dateRange = moment.duration(24, 'hours').asMilliseconds(); const dateStart = dateEnd - dateRange; @@ -62,7 +63,7 @@ export const OverviewComponent = React.memo(() => { actionSecondaryIcon="popout" actionSecondaryLabel={i18n.EMPTY_ACTION_SECONDARY} actionSecondaryTarget="_blank" - actionSecondaryUrl={documentationLinks.siem} + actionSecondaryUrl={docLinks.links.siem} data-test-subj="empty-page" title={i18n.EMPTY_TITLE} /> diff --git a/x-pack/legacy/plugins/siem/public/pages/overview/summary.tsx b/x-pack/legacy/plugins/siem/public/pages/overview/summary.tsx index 7fd8f84129d8..51cfcbe9374a 100644 --- a/x-pack/legacy/plugins/siem/public/pages/overview/summary.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/overview/summary.tsx @@ -4,73 +4,81 @@ * you may not use this file except in compliance with the Elastic License. */ +import React from 'react'; import { EuiFlexItem, EuiLink, EuiText } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import React from 'react'; -import { documentationLinks } from 'ui/documentation_links'; -export const Summary = React.memo(() => ( - - -

- -

+import { useKibana } from '../../lib/kibana'; + +export const Summary = React.memo(() => { + const docLinks = useKibana().services.docLinks; + + return ( + + +

+ +

-

- - - - ), - data: ( - - - - ), - siemSolution: ( - - - - ), - }} - /> -

+

+ + + + ), + data: ( + + + + ), + siemSolution: ( + + + + ), + }} + /> +

-

- -

+

+ +

-

- - - - ), - }} - /> -

-
-
-)); +

+ + + + ), + }} + /> +

+
+
+ ); +}); Summary.displayName = 'Summary'; diff --git a/x-pack/legacy/plugins/siem/public/utils/saved_query_services/index.tsx b/x-pack/legacy/plugins/siem/public/utils/saved_query_services/index.tsx index cda6882fe171..a8ee10ba2b80 100644 --- a/x-pack/legacy/plugins/siem/public/utils/saved_query_services/index.tsx +++ b/x-pack/legacy/plugins/siem/public/utils/saved_query_services/index.tsx @@ -10,16 +10,18 @@ import { createSavedQueryService, } from '../../../../../../../src/plugins/data/public'; -import { useKibanaCore } from '../../lib/compose/kibana_core'; +import { useKibana } from '../../lib/kibana'; export const useSavedQueryServices = () => { - const core = useKibanaCore(); + const kibana = useKibana(); + const client = kibana.services.savedObjects.client; + const [savedQueryService, setSavedQueryService] = useState( - createSavedQueryService(core.savedObjects.client) + createSavedQueryService(client) ); useEffect(() => { - setSavedQueryService(createSavedQueryService(core.savedObjects.client)); - }, [core.savedObjects.client]); + setSavedQueryService(createSavedQueryService(client)); + }, [client]); return savedQueryService; };