diff --git a/x-pack/plugins/discover_log_explorer/common/locators/index.ts b/x-pack/plugins/discover_log_explorer/common/locators/index.ts new file mode 100644 index 0000000000000..b7e5fc201294f --- /dev/null +++ b/x-pack/plugins/discover_log_explorer/common/locators/index.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { SingleDatasetLocator } from './single_dataset'; + +export * from './single_dataset'; + +export interface DiscoverLogExplorerLocators { + singleDatasetLocator: SingleDatasetLocator; +} diff --git a/x-pack/plugins/discover_log_explorer/common/locators/single_dataset/constants.ts b/x-pack/plugins/discover_log_explorer/common/locators/single_dataset/constants.ts new file mode 100644 index 0000000000000..86c91fb075c12 --- /dev/null +++ b/x-pack/plugins/discover_log_explorer/common/locators/single_dataset/constants.ts @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export const SINGLE_DATASET_LOCATOR_ID = 'SINGLE_DATASET_LOCATOR'; diff --git a/x-pack/plugins/discover_log_explorer/common/locators/single_dataset/index.ts b/x-pack/plugins/discover_log_explorer/common/locators/single_dataset/index.ts new file mode 100644 index 0000000000000..ae8e21e7c8296 --- /dev/null +++ b/x-pack/plugins/discover_log_explorer/common/locators/single_dataset/index.ts @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export * from './single_dataset_locator'; diff --git a/x-pack/plugins/discover_log_explorer/common/locators/single_dataset/single_dataset_locator.ts b/x-pack/plugins/discover_log_explorer/common/locators/single_dataset/single_dataset_locator.ts new file mode 100644 index 0000000000000..fd817bc023437 --- /dev/null +++ b/x-pack/plugins/discover_log_explorer/common/locators/single_dataset/single_dataset_locator.ts @@ -0,0 +1,53 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { LocatorDefinition, LocatorPublic } from '@kbn/share-plugin/public'; +import { SingleDatasetSelection } from '../../utils/dataset_selection'; +import { LOG_EXPLORER_PROFILE_ID } from '../../constants'; +import { SINGLE_DATASET_LOCATOR_ID } from './constants'; +import { SingleDatasetLocatorDependencies, SingleDatasetLocatorParams } from './types'; + +export type SingleDatasetLocator = LocatorPublic; + +export class SingleDatasetLocatorDefinition + implements LocatorDefinition +{ + public readonly id = SINGLE_DATASET_LOCATOR_ID; + + constructor(protected readonly deps: SingleDatasetLocatorDependencies) {} + + public readonly getLocation = async (params: SingleDatasetLocatorParams) => { + const { integration, dataset, ...discoverParams } = params; + + const dataViewId = await this.generateDataViewId(integration, dataset); + + const discoverDeepLink = await this.deps.discover.locator?.getLocation({ + ...discoverParams, + dataViewId, + profile: LOG_EXPLORER_PROFILE_ID, + }); + + return discoverDeepLink!; + }; + + private async generateDataViewId(integration: string, dataset: string) { + const { items } = await this.deps.datasetsClient.findIntegrations({ + nameQuery: integration, + }); + + // There should only be one matching integration with the given name + const installedIntegration = items[0]; + + const datasetSelection = SingleDatasetSelection.create( + installedIntegration.datasets.find((d) => d.title === dataset)! + ); + + const dataViewId = datasetSelection.toDataviewSpec().id; + + return dataViewId; + } +} diff --git a/x-pack/plugins/discover_log_explorer/common/locators/single_dataset/types.ts b/x-pack/plugins/discover_log_explorer/common/locators/single_dataset/types.ts new file mode 100644 index 0000000000000..4304955d5096e --- /dev/null +++ b/x-pack/plugins/discover_log_explorer/common/locators/single_dataset/types.ts @@ -0,0 +1,35 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { DiscoverAppLocatorParams } from '@kbn/discover-plugin/common'; +import type { DiscoverSetup } from '@kbn/discover-plugin/public'; +import type { DatasetsServiceSetup } from '../../../public/services/datasets'; + +type DiscoverPropertiesToOmit = + | 'savedSearchId' + | 'dataViewId' + | 'indexPatternId' + | 'dataViewSpec' + | 'profile'; + +type DiscoverLocatorUsableProperties = Omit; + +export interface SingleDatasetLocatorParams extends DiscoverLocatorUsableProperties { + /** + * Integration name to be selected. + */ + integration: string; + /** + * Dataset name to be selected. + */ + dataset: string; +} + +export interface SingleDatasetLocatorDependencies { + discover: DiscoverSetup; + datasetsClient: DatasetsServiceSetup['client']; +} diff --git a/x-pack/plugins/discover_log_explorer/public/utils/comparator_by_field.ts b/x-pack/plugins/discover_log_explorer/common/utils/comparator_by_field.ts similarity index 100% rename from x-pack/plugins/discover_log_explorer/public/utils/comparator_by_field.ts rename to x-pack/plugins/discover_log_explorer/common/utils/comparator_by_field.ts diff --git a/x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/all_dataset_selection.ts b/x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/all_dataset_selection.ts similarity index 95% rename from x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/all_dataset_selection.ts rename to x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/all_dataset_selection.ts index ebe3254968fb0..fdc40aed3c449 100644 --- a/x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/all_dataset_selection.ts +++ b/x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/all_dataset_selection.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { Dataset } from '../../../common/datasets'; +import { Dataset } from '../../datasets'; import { encodeDatasetSelection } from './encoding'; import { DatasetSelectionStrategy } from './types'; diff --git a/x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/encoding.test.ts b/x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/encoding.test.ts similarity index 100% rename from x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/encoding.test.ts rename to x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/encoding.test.ts diff --git a/x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/encoding.ts b/x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/encoding.ts similarity index 95% rename from x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/encoding.ts rename to x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/encoding.ts index 5a84c398e7d4e..f6eef288f67ad 100644 --- a/x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/encoding.ts +++ b/x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/encoding.ts @@ -7,7 +7,7 @@ import { decode, encode, RisonValue } from '@kbn/rison'; import * as lz from 'lz-string'; -import { decodeOrThrow } from '../../../common/runtime_types'; +import { decodeOrThrow } from '../../runtime_types'; import { DatasetEncodingError } from './errors'; import { DatasetSelectionPlain, datasetSelectionPlainRT } from './types'; diff --git a/x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/errors.ts b/x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/errors.ts similarity index 100% rename from x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/errors.ts rename to x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/errors.ts diff --git a/x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/hydrate_dataset_selection.ts.ts b/x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/hydrate_dataset_selection.ts.ts similarity index 100% rename from x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/hydrate_dataset_selection.ts.ts rename to x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/hydrate_dataset_selection.ts.ts diff --git a/x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/index.ts b/x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/index.ts similarity index 100% rename from x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/index.ts rename to x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/index.ts diff --git a/x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/single_dataset_selection.ts b/x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/single_dataset_selection.ts similarity index 97% rename from x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/single_dataset_selection.ts rename to x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/single_dataset_selection.ts index 6f772200cf6c0..47e794c33c2c3 100644 --- a/x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/single_dataset_selection.ts +++ b/x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/single_dataset_selection.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { Dataset } from '../../../common/datasets'; +import { Dataset } from '../../datasets'; import { encodeDatasetSelection } from './encoding'; import { DatasetSelectionStrategy, SingleDatasetSelectionPayload } from './types'; diff --git a/x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/types.ts b/x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/types.ts similarity index 96% rename from x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/types.ts rename to x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/types.ts index a25f16cee7654..d6dcbf2bdcee3 100644 --- a/x-pack/plugins/discover_log_explorer/public/utils/dataset_selection/types.ts +++ b/x-pack/plugins/discover_log_explorer/common/utils/dataset_selection/types.ts @@ -6,7 +6,7 @@ */ import { DataViewSpec } from '@kbn/data-views-plugin/common'; import * as rt from 'io-ts'; -import { datasetRT } from '../../../common/datasets'; +import { datasetRT } from '../../datasets'; export const allDatasetSelectionPlainRT = rt.type({ selectionType: rt.literal('all'), diff --git a/x-pack/plugins/discover_log_explorer/public/utils/dynamic.tsx b/x-pack/plugins/discover_log_explorer/common/utils/dynamic.tsx similarity index 100% rename from x-pack/plugins/discover_log_explorer/public/utils/dynamic.tsx rename to x-pack/plugins/discover_log_explorer/common/utils/dynamic.tsx diff --git a/x-pack/plugins/discover_log_explorer/kibana.jsonc b/x-pack/plugins/discover_log_explorer/kibana.jsonc index 89d00e3ce4eeb..1b7e42abe391b 100644 --- a/x-pack/plugins/discover_log_explorer/kibana.jsonc +++ b/x-pack/plugins/discover_log_explorer/kibana.jsonc @@ -8,7 +8,7 @@ "server": true, "browser": true, "configPath": ["xpack", "discoverLogExplorer"], - "requiredPlugins": ["data", "dataViews", "discover", "fleet", "kibanaReact", "kibanaUtils", "controls", "embeddable"], + "requiredPlugins": ["controls", "data", "dataViews", "discover","embeddable", "fleet", "kibanaReact", "kibanaUtils", "share"], "optionalPlugins": [], "requiredBundles": [] } diff --git a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/dataset_selector.stories.tsx b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/dataset_selector.stories.tsx index d96cdc07bd9bc..32b02065e4c9a 100644 --- a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/dataset_selector.stories.tsx +++ b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/dataset_selector.stories.tsx @@ -18,7 +18,7 @@ import { AllDatasetSelection, DatasetSelection, DatasetSelectionChange, -} from '../../utils/dataset_selection'; +} from '../../../common/utils/dataset_selection'; const meta: Meta = { component: DatasetSelector, diff --git a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/dataset_selector.tsx b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/dataset_selector.tsx index 444ec69c9d266..307ce4976e525 100644 --- a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/dataset_selector.tsx +++ b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/dataset_selector.tsx @@ -8,7 +8,7 @@ import { EuiContextMenu, EuiHorizontalRule } from '@elastic/eui'; import React, { useMemo } from 'react'; import { useIntersectionRef } from '../../hooks/use_intersection_ref'; -import { dynamic } from '../../utils/dynamic'; +import { dynamic } from '../../../common/utils/dynamic'; import { contextMenuStyles, DATA_VIEW_POPOVER_CONTENT_WIDTH, diff --git a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/state_machine/defaults.ts b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/state_machine/defaults.ts index a818c6645bda7..0c9da440b5ab7 100644 --- a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/state_machine/defaults.ts +++ b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/state_machine/defaults.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { AllDatasetSelection } from '../../../utils/dataset_selection'; +import { AllDatasetSelection } from '../../../../common/utils/dataset_selection'; import { HashedCache } from '../../../../common/hashed_cache'; import { INTEGRATION_PANEL_ID } from '../constants'; import { DatasetsSelectorSearchParams } from '../types'; diff --git a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/state_machine/state_machine.ts b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/state_machine/state_machine.ts index aea09e7c6f2e7..3b0c2eef04a61 100644 --- a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/state_machine/state_machine.ts +++ b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/state_machine/state_machine.ts @@ -6,7 +6,10 @@ */ import { actions, assign, createMachine, raise } from 'xstate'; -import { AllDatasetSelection, SingleDatasetSelection } from '../../../utils/dataset_selection'; +import { + AllDatasetSelection, + SingleDatasetSelection, +} from '../../../../common/utils/dataset_selection'; import { UNMANAGED_STREAMS_PANEL_ID } from '../constants'; import { defaultSearch, DEFAULT_CONTEXT } from './defaults'; import { diff --git a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/state_machine/types.ts b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/state_machine/types.ts index 17e526aea87f9..e41dde917d667 100644 --- a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/state_machine/types.ts +++ b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/state_machine/types.ts @@ -4,7 +4,10 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { DatasetSelection, DatasetSelectionChange } from '../../../utils/dataset_selection'; +import { + DatasetSelection, + DatasetSelectionChange, +} from '../../../../common/utils/dataset_selection'; import { Dataset } from '../../../../common/datasets/models/dataset'; import { ReloadDatasets, SearchDatasets } from '../../../hooks/use_datasets'; import { diff --git a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/sub_components/datasets_popover.tsx b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/sub_components/datasets_popover.tsx index 7428ffbd47612..3c06f2103e702 100644 --- a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/sub_components/datasets_popover.tsx +++ b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/sub_components/datasets_popover.tsx @@ -18,7 +18,7 @@ import { } from '@elastic/eui'; import styled from '@emotion/styled'; import { PackageIcon } from '@kbn/fleet-plugin/public'; -import { DatasetSelection } from '../../../utils/dataset_selection'; +import { DatasetSelection } from '../../../../common/utils/dataset_selection'; import { DATA_VIEW_POPOVER_CONTENT_WIDTH, POPOVER_ID, selectDatasetLabel } from '../constants'; import { getPopoverButtonStyles } from '../utils'; diff --git a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/types.ts b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/types.ts index 50cbcf6c1c5ba..9f9267abd7d69 100644 --- a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/types.ts +++ b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/types.ts @@ -15,7 +15,10 @@ import { SearchIntegrations, } from '../../hooks/use_integrations'; import { INTEGRATION_PANEL_ID, UNMANAGED_STREAMS_PANEL_ID } from './constants'; -import type { DatasetSelection, DatasetSelectionChange } from '../../utils/dataset_selection'; +import type { + DatasetSelection, + DatasetSelectionChange, +} from '../../../common/utils/dataset_selection'; export interface DatasetSelectorProps { /* The generic data stream list */ diff --git a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/utils.tsx b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/utils.tsx index 868aa76dac9f3..24634d8103dcb 100644 --- a/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/utils.tsx +++ b/x-pack/plugins/discover_log_explorer/public/components/dataset_selector/utils.tsx @@ -20,7 +20,7 @@ import { } from './constants'; import { DatasetSelectionHandler } from './types'; import { LoadDatasets } from '../../hooks/use_datasets'; -import { dynamic } from '../../utils/dynamic'; +import { dynamic } from '../../../common/utils/dynamic'; import type { IntegrationsListStatusProps } from './sub_components/integrations_list_status'; const IntegrationsListStatus = dynamic(() => import('./sub_components/integrations_list_status')); diff --git a/x-pack/plugins/discover_log_explorer/public/customizations/log_explorer_profile.tsx b/x-pack/plugins/discover_log_explorer/public/customizations/log_explorer_profile.tsx index d9b7a15269cb5..00083a3efe67d 100644 --- a/x-pack/plugins/discover_log_explorer/public/customizations/log_explorer_profile.tsx +++ b/x-pack/plugins/discover_log_explorer/public/customizations/log_explorer_profile.tsx @@ -9,7 +9,8 @@ import { DataPublicPluginStart } from '@kbn/data-plugin/public'; import type { CoreStart } from '@kbn/core/public'; import { CustomizationCallback } from '@kbn/discover-plugin/public'; import React from 'react'; -import { dynamic } from '../utils/dynamic'; +import { dynamic } from '../../common/utils/dynamic'; +import { DatasetsServiceSetup } from '../services/datasets'; const LazyCustomDatasetSelector = dynamic(() => import('./custom_dataset_selector')); const LazyCustomDatasetFilters = dynamic(() => import('./custom_dataset_filters')); @@ -17,21 +18,21 @@ const LazyCustomDatasetFilters = dynamic(() => import('./custom_dataset_filters' interface CreateLogExplorerProfileCustomizationsDeps { core: CoreStart; data: DataPublicPluginStart; + datasetsClient: DatasetsServiceSetup['client']; } export const createLogExplorerProfileCustomizations = - ({ core, data }: CreateLogExplorerProfileCustomizationsDeps): CustomizationCallback => + ({ + core, + data, + datasetsClient, + }: CreateLogExplorerProfileCustomizationsDeps): CustomizationCallback => async ({ customizations, stateContainer }) => { // Lazy load dependencies - const datasetServiceModuleLoadable = import('../services/datasets'); const logExplorerMachineModuleLoadable = import('../state_machines/log_explorer_profile'); - const [{ DatasetsService }, { initializeLogExplorerProfileStateService, waitForState }] = - await Promise.all([datasetServiceModuleLoadable, logExplorerMachineModuleLoadable]); - - const datasetsService = new DatasetsService().start({ - http: core.http, - }); + const { initializeLogExplorerProfileStateService, waitForState } = + await logExplorerMachineModuleLoadable; const logExplorerProfileStateService = initializeLogExplorerProfileStateService({ stateContainer, @@ -53,7 +54,7 @@ export const createLogExplorerProfileCustomizations = id: 'search_bar', CustomDataViewPicker: () => ( ), diff --git a/x-pack/plugins/discover_log_explorer/public/hooks/use_dataset_selection.ts b/x-pack/plugins/discover_log_explorer/public/hooks/use_dataset_selection.ts index 05fbc2bc81506..c588a37cf1d81 100644 --- a/x-pack/plugins/discover_log_explorer/public/hooks/use_dataset_selection.ts +++ b/x-pack/plugins/discover_log_explorer/public/hooks/use_dataset_selection.ts @@ -8,7 +8,7 @@ import { useSelector } from '@xstate/react'; import { useCallback } from 'react'; import { LogExplorerProfileStateService } from '../state_machines/log_explorer_profile'; -import { DatasetSelectionChange } from '../utils/dataset_selection'; +import { DatasetSelectionChange } from '../../common/utils/dataset_selection'; export const useDatasetSelection = ( logExplorerProfileStateService: LogExplorerProfileStateService diff --git a/x-pack/plugins/discover_log_explorer/public/index.ts b/x-pack/plugins/discover_log_explorer/public/index.ts index 0c4298100c558..f7eeeb49f7a1f 100644 --- a/x-pack/plugins/discover_log_explorer/public/index.ts +++ b/x-pack/plugins/discover_log_explorer/public/index.ts @@ -9,6 +9,8 @@ import { PluginInitializerContext } from '@kbn/core/public'; import { DiscoverLogExplorerConfig } from '../common/plugin_config'; import { DiscoverLogExplorerPlugin } from './plugin'; +export type { DiscoverLogExplorerPluginSetup } from './types'; + export function plugin(context: PluginInitializerContext) { return new DiscoverLogExplorerPlugin(context); } diff --git a/x-pack/plugins/discover_log_explorer/public/plugin.ts b/x-pack/plugins/discover_log_explorer/public/plugin.ts index e39c831cdb432..cdc21968d86be 100644 --- a/x-pack/plugins/discover_log_explorer/public/plugin.ts +++ b/x-pack/plugins/discover_log_explorer/public/plugin.ts @@ -5,14 +5,17 @@ * 2.0. */ -import { CoreStart, Plugin, PluginInitializerContext } from '@kbn/core/public'; +import { CoreStart, CoreSetup, Plugin, PluginInitializerContext } from '@kbn/core/public'; import { LOG_EXPLORER_PROFILE_ID } from '../common/constants'; +import { DiscoverLogExplorerLocators, SingleDatasetLocatorDefinition } from '../common/locators'; import { DiscoverLogExplorerConfig } from '../common/plugin_config'; import { createLogExplorerProfileCustomizations } from './customizations/log_explorer_profile'; import { getLogExplorerDeepLink } from './deep_links'; +import { DatasetsService, DatasetsServiceSetup } from './services/datasets'; import { DiscoverLogExplorerPluginSetup, DiscoverLogExplorerPluginStart, + DiscoverLogExplorerSetupDeps, DiscoverLogExplorerStartDeps, } from './types'; @@ -20,18 +23,44 @@ export class DiscoverLogExplorerPlugin implements Plugin { private config: DiscoverLogExplorerConfig; + private locators?: DiscoverLogExplorerLocators; + private datasetsService: DatasetsService; + private datasetsClient?: DatasetsServiceSetup['client']; constructor(context: PluginInitializerContext) { this.config = context.config.get(); + this.datasetsService = new DatasetsService(); } - public setup() {} + public setup(core: CoreSetup, plugins: DiscoverLogExplorerSetupDeps) { + const { share, discover } = plugins; + + this.datasetsClient = this.datasetsService.setup({ + http: core.http, + }).client; + + const singleDatasetLocator = share.url.locators.create( + new SingleDatasetLocatorDefinition({ discover, datasetsClient: this.datasetsClient }) + ); + + this.locators = { + singleDatasetLocator, + }; + + return { + locators: this.locators, + }; + } public start(core: CoreStart, plugins: DiscoverLogExplorerStartDeps) { const { discover, data } = plugins; discover.registerCustomizationProfile(LOG_EXPLORER_PROFILE_ID, { - customize: createLogExplorerProfileCustomizations({ core, data }), + customize: createLogExplorerProfileCustomizations({ + core, + data, + datasetsClient: this.datasetsClient!, + }), deepLinks: [getLogExplorerDeepLink({ isVisible: this.config.featureFlags.deepLinkVisible })], }); } diff --git a/x-pack/plugins/discover_log_explorer/public/services/datasets/datasets_service.mock.ts b/x-pack/plugins/discover_log_explorer/public/services/datasets/datasets_service.mock.ts index 003264ea3e559..b6384bfb8900a 100644 --- a/x-pack/plugins/discover_log_explorer/public/services/datasets/datasets_service.mock.ts +++ b/x-pack/plugins/discover_log_explorer/public/services/datasets/datasets_service.mock.ts @@ -6,11 +6,11 @@ */ import { createDatasetsClientMock } from './datasets_client.mock'; -import { DatasetsServiceStart } from './types'; +import { DatasetsServiceSetup } from './types'; -export const createDatasetsServiceStartMock = () => ({ +export const createDatasetsServiceSetupMock = () => ({ client: createDatasetsClientMock(), }); -export const _ensureTypeCompatibility = (): DatasetsServiceStart => - createDatasetsServiceStartMock(); +export const _ensureTypeCompatibility = (): DatasetsServiceSetup => + createDatasetsServiceSetupMock(); diff --git a/x-pack/plugins/discover_log_explorer/public/services/datasets/datasets_service.ts b/x-pack/plugins/discover_log_explorer/public/services/datasets/datasets_service.ts index 7e6c016f94ab9..e24887f8fbf17 100644 --- a/x-pack/plugins/discover_log_explorer/public/services/datasets/datasets_service.ts +++ b/x-pack/plugins/discover_log_explorer/public/services/datasets/datasets_service.ts @@ -6,18 +6,18 @@ */ import { DatasetsClient } from './datasets_client'; -import { DatasetsServiceStartDeps, DatasetsServiceSetup, DatasetsServiceStart } from './types'; +import { DatasetsServiceSetup, DatasetsServiceStart, DatasetsServiceSetupDeps } from './types'; export class DatasetsService { constructor() {} - public setup(): DatasetsServiceSetup {} - - public start({ http }: DatasetsServiceStartDeps): DatasetsServiceStart { + public setup({ http }: DatasetsServiceSetupDeps): DatasetsServiceSetup { const client = new DatasetsClient(http); return { client, }; } + + public start(): DatasetsServiceStart {} } diff --git a/x-pack/plugins/discover_log_explorer/public/services/datasets/types.ts b/x-pack/plugins/discover_log_explorer/public/services/datasets/types.ts index 86a0da207fa8d..da718ec124e8b 100644 --- a/x-pack/plugins/discover_log_explorer/public/services/datasets/types.ts +++ b/x-pack/plugins/discover_log_explorer/public/services/datasets/types.ts @@ -13,16 +13,16 @@ import { FindIntegrationsValue, } from '../../../common/latest'; -export type DatasetsServiceSetup = void; - -export interface DatasetsServiceStart { +export interface DatasetsServiceSetup { client: IDatasetsClient; } -export interface DatasetsServiceStartDeps { +export interface DatasetsServiceSetupDeps { http: HttpStart; } +export type DatasetsServiceStart = void; + export interface IDatasetsClient { findDatasets(params?: FindDatasetsRequestQuery): Promise; findIntegrations(params?: FindIntegrationsRequestQuery): Promise; diff --git a/x-pack/plugins/discover_log_explorer/public/state_machines/integrations/src/state_machine.ts b/x-pack/plugins/discover_log_explorer/public/state_machines/integrations/src/state_machine.ts index e3c858e6f2658..3f25d041393c0 100644 --- a/x-pack/plugins/discover_log_explorer/public/state_machines/integrations/src/state_machine.ts +++ b/x-pack/plugins/discover_log_explorer/public/state_machines/integrations/src/state_machine.ts @@ -7,7 +7,7 @@ import { assign, createMachine } from 'xstate'; import { isEmpty, isError, omitBy } from 'lodash'; -import { createComparatorByField } from '../../../utils/comparator_by_field'; +import { createComparatorByField } from '../../../../common/utils/comparator_by_field'; import { Dataset, Integration } from '../../../../common/datasets'; import { IDatasetsClient } from '../../../services/datasets'; import { DEFAULT_CONTEXT } from './defaults'; diff --git a/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/defaults.ts b/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/defaults.ts index fe19f34d7565c..96cb3d192f171 100644 --- a/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/defaults.ts +++ b/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/defaults.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { AllDatasetSelection } from '../../../utils/dataset_selection'; +import { AllDatasetSelection } from '../../../../common/utils/dataset_selection'; import { ControlPanels, DefaultLogExplorerProfileState } from './types'; export const DEFAULT_CONTEXT: DefaultLogExplorerProfileState = { diff --git a/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/state_machine.ts b/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/state_machine.ts index 617c66b10140f..40c5f39b2f53a 100644 --- a/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/state_machine.ts +++ b/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/state_machine.ts @@ -8,7 +8,7 @@ import { IToasts } from '@kbn/core/public'; import { DiscoverStateContainer } from '@kbn/discover-plugin/public'; import { actions, createMachine, interpret, InterpreterFrom, raise } from 'xstate'; -import { isDatasetSelection } from '../../../utils/dataset_selection'; +import { isDatasetSelection } from '../../../../common/utils/dataset_selection'; import { createAndSetDataView } from './data_view_service'; import { DEFAULT_CONTEXT } from './defaults'; import { diff --git a/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/types.ts b/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/types.ts index 621f1c8f56b76..42ede62a9584d 100644 --- a/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/types.ts +++ b/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/types.ts @@ -8,7 +8,10 @@ import * as rt from 'io-ts'; import { ControlGroupAPI } from '@kbn/controls-plugin/public'; import { DoneInvokeEvent } from 'xstate'; -import type { DatasetEncodingError, DatasetSelection } from '../../../utils/dataset_selection'; +import type { + DatasetEncodingError, + DatasetSelection, +} from '../../../../common/utils/dataset_selection'; export interface WithDatasetSelection { datasetSelection: DatasetSelection; diff --git a/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/url_state_storage_service.ts b/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/url_state_storage_service.ts index f2e467f15afff..ccfc6e872832e 100644 --- a/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/url_state_storage_service.ts +++ b/x-pack/plugins/discover_log_explorer/public/state_machines/log_explorer_profile/src/url_state_storage_service.ts @@ -15,7 +15,7 @@ import { decodeDatasetSelectionId, hydrateDatasetSelection, isDatasetSelection, -} from '../../../utils/dataset_selection'; +} from '../../../../common/utils/dataset_selection'; import { ControlPanelRT, ControlPanels, diff --git a/x-pack/plugins/discover_log_explorer/public/types.ts b/x-pack/plugins/discover_log_explorer/public/types.ts index 4ec95ba94ec5a..d58e53d304306 100644 --- a/x-pack/plugins/discover_log_explorer/public/types.ts +++ b/x-pack/plugins/discover_log_explorer/public/types.ts @@ -5,11 +5,20 @@ * 2.0. */ import { DataPublicPluginStart } from '@kbn/data-plugin/public'; -import { DiscoverStart } from '@kbn/discover-plugin/public'; +import { DiscoverSetup, DiscoverStart } from '@kbn/discover-plugin/public'; +import { SharePluginSetup } from '@kbn/share-plugin/public'; +import { DiscoverLogExplorerLocators } from '../common/locators'; -export type DiscoverLogExplorerPluginSetup = void; +export interface DiscoverLogExplorerPluginSetup { + locators: DiscoverLogExplorerLocators; +} export type DiscoverLogExplorerPluginStart = void; +export interface DiscoverLogExplorerSetupDeps { + share: SharePluginSetup; + discover: DiscoverSetup; +} + export interface DiscoverLogExplorerStartDeps { data: DataPublicPluginStart; discover: DiscoverStart; diff --git a/x-pack/plugins/discover_log_explorer/tsconfig.json b/x-pack/plugins/discover_log_explorer/tsconfig.json index 61ea70ece2d38..8ed35df73875b 100644 --- a/x-pack/plugins/discover_log_explorer/tsconfig.json +++ b/x-pack/plugins/discover_log_explorer/tsconfig.json @@ -20,6 +20,7 @@ "@kbn/data-plugin", "@kbn/unified-field-list", "@kbn/config-schema", + "@kbn/share-plugin", ], "exclude": ["target/**/*"] } diff --git a/x-pack/plugins/observability_onboarding/kibana.jsonc b/x-pack/plugins/observability_onboarding/kibana.jsonc index 97689407aff41..a24735edadc55 100644 --- a/x-pack/plugins/observability_onboarding/kibana.jsonc +++ b/x-pack/plugins/observability_onboarding/kibana.jsonc @@ -7,7 +7,7 @@ "server": true, "browser": true, "configPath": ["xpack", "observability_onboarding"], - "requiredPlugins": ["data", "observability", "observabilityShared", "discover"], + "requiredPlugins": ["data", "observability", "observabilityShared", "discoverLogExplorer"], "optionalPlugins": ["cloud", "usageCollection"], "requiredBundles": ["kibanaReact"], "extraPublicDirs": ["common"] diff --git a/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx b/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx index 184ef62d81277..511b4fbd45f5b 100644 --- a/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx +++ b/x-pack/plugins/observability_onboarding/public/components/app/custom_logs/wizard/install_elastic_agent.tsx @@ -37,14 +37,13 @@ import { } from '../../../shared/step_panel'; import { ApiKeyBanner } from './api_key_banner'; import { BackButton } from './back_button'; -import { getDiscoverNavigationParams } from '../../utils'; import { WindowsInstallStep } from '../../../shared/windows_install_step'; import { TroubleshootingLink } from '../../../shared/troubleshooting_link'; export function InstallElasticAgent() { const { services: { - discover: { locator }, + discoverLogExplorer: { locators }, }, } = useKibana(); const { goBack, goToStep, getState, setState } = useWizard(); @@ -56,9 +55,10 @@ export function InstallElasticAgent() { goToStep('inspect'); } async function onContinue() { - await locator?.navigate( - getDiscoverNavigationParams([wizardState.datasetName]) - ); + await locators.singleDatasetLocator.navigate({ + integration: wizardState.integrationName, + dataset: wizardState.datasetName, + }); } function onAutoDownloadConfig() { diff --git a/x-pack/plugins/observability_onboarding/public/components/app/system_logs/install_elastic_agent.tsx b/x-pack/plugins/observability_onboarding/public/components/app/system_logs/install_elastic_agent.tsx index 5a71c588c0711..9a71324f03d33 100644 --- a/x-pack/plugins/observability_onboarding/public/components/app/system_logs/install_elastic_agent.tsx +++ b/x-pack/plugins/observability_onboarding/public/components/app/system_logs/install_elastic_agent.tsx @@ -16,7 +16,6 @@ import { import { i18n } from '@kbn/i18n'; import { useKibana } from '@kbn/kibana-react-plugin/public'; import { default as React, useCallback, useEffect, useState } from 'react'; -import { getSystemLogsDataStreams } from '../../../../common/elastic_agent_logs'; import { ObservabilityOnboardingPluginSetupDeps } from '../../../plugin'; import { useWizard } from '.'; import { FETCH_STATUS, useFetcher } from '../../../hooks/use_fetcher'; @@ -36,7 +35,6 @@ import { StepPanelFooter, } from '../../shared/step_panel'; import { ApiKeyBanner } from '../custom_logs/wizard/api_key_banner'; -import { getDiscoverNavigationParams } from '../utils'; import { WindowsInstallStep } from '../../shared/windows_install_step'; import { SystemIntegrationBanner } from './system_integration_banner'; import { TroubleshootingLink } from '../../shared/troubleshooting_link'; @@ -44,7 +42,7 @@ import { TroubleshootingLink } from '../../shared/troubleshooting_link'; export function InstallElasticAgent() { const { services: { - discover: { locator }, + discoverLogExplorer: { locators }, }, } = useKibana(); @@ -60,11 +58,10 @@ export function InstallElasticAgent() { navigateToKibanaUrl('/app/observabilityOnboarding'); } async function onContinue() { - const dataStreams = getSystemLogsDataStreams(); - const dataSets = dataStreams.map( - (dataSream) => dataSream.data_stream.dataset - ); - await locator?.navigate(getDiscoverNavigationParams(dataSets)); + await locators.singleDatasetLocator.navigate({ + integration: 'system', + dataset: 'syslog', + }); } function onAutoDownloadConfig() { diff --git a/x-pack/plugins/observability_onboarding/public/components/app/utils.ts b/x-pack/plugins/observability_onboarding/public/components/app/utils.ts deleted file mode 100644 index 843002cb1fcc6..0000000000000 --- a/x-pack/plugins/observability_onboarding/public/components/app/utils.ts +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import type { DataViewSpec } from '@kbn/data-views-plugin/common'; -import { DiscoverAppLocatorParams } from '@kbn/discover-plugin/common'; -import { Filter, FilterStateStore } from '@kbn/es-query'; - -type DiscoverPropertiesToPick = 'dataViewId' | 'dataViewSpec' | 'filters'; - -type DiscoverNavigationParams = Pick< - DiscoverAppLocatorParams, - DiscoverPropertiesToPick ->; - -const defaultFilterKey = 'data_stream.dataset'; -const defaultLogsDataViewId = 'logs-*'; -const defaultLogsDataView: DataViewSpec = { - id: defaultLogsDataViewId, - title: defaultLogsDataViewId, -}; - -const getDefaultDatasetFilter = (datasets: string[]): Filter[] => [ - { - meta: { - index: defaultLogsDataViewId, - key: defaultFilterKey, - params: datasets, - type: 'phrases', - }, - query: { - bool: { - minimum_should_match: 1, - should: datasets.map((dataset) => ({ - match_phrase: { - [defaultFilterKey]: dataset, - }, - })), - }, - }, - $state: { - store: FilterStateStore.APP_STATE, - }, - }, -]; - -export const getDiscoverNavigationParams = ( - datasets: string[] -): DiscoverNavigationParams => ({ - dataViewId: defaultLogsDataViewId, - dataViewSpec: defaultLogsDataView, - filters: getDefaultDatasetFilter(datasets), -}); diff --git a/x-pack/plugins/observability_onboarding/public/plugin.ts b/x-pack/plugins/observability_onboarding/public/plugin.ts index 8769991169090..18c55e745205a 100644 --- a/x-pack/plugins/observability_onboarding/public/plugin.ts +++ b/x-pack/plugins/observability_onboarding/public/plugin.ts @@ -23,7 +23,7 @@ import { DataPublicPluginSetup, DataPublicPluginStart, } from '@kbn/data-plugin/public'; -import type { DiscoverSetup } from '@kbn/discover-plugin/public'; +import type { DiscoverLogExplorerPluginSetup } from '@kbn/discover-log-explorer-plugin/public'; import type { ObservabilityOnboardingConfig } from '../server'; export type ObservabilityOnboardingPluginSetup = void; @@ -32,7 +32,7 @@ export type ObservabilityOnboardingPluginStart = void; export interface ObservabilityOnboardingPluginSetupDeps { data: DataPublicPluginSetup; observability: ObservabilityPublicSetup; - discover: DiscoverSetup; + discoverLogExplorer: DiscoverLogExplorerPluginSetup; } export interface ObservabilityOnboardingPluginStartDeps { diff --git a/x-pack/plugins/observability_onboarding/tsconfig.json b/x-pack/plugins/observability_onboarding/tsconfig.json index 2119563923cb9..2a1e8407d902f 100644 --- a/x-pack/plugins/observability_onboarding/tsconfig.json +++ b/x-pack/plugins/observability_onboarding/tsconfig.json @@ -14,7 +14,7 @@ "kbn_references": [ "@kbn/core", "@kbn/data-plugin", - "@kbn/discover-plugin", + "@kbn/discover-log-explorer-plugin", "@kbn/kibana-react-plugin", "@kbn/observability-plugin", "@kbn/i18n", @@ -30,8 +30,6 @@ "@kbn/core-http-server", "@kbn/security-plugin", "@kbn/std", - "@kbn/data-views-plugin", - "@kbn/es-query", "@kbn/use-tracked-promise", ], "exclude": [