Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions x-pack/plugins/discover_log_explorer/common/locators/index.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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<SingleDatasetLocatorParams>;

export class SingleDatasetLocatorDefinition
implements LocatorDefinition<SingleDatasetLocatorParams>
{
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;
}
}
Original file line number Diff line number Diff line change
@@ -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<DiscoverAppLocatorParams, DiscoverPropertiesToOmit>;

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'];
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { Dataset } from '../../../common/datasets';
import { Dataset } from '../../datasets';
import { encodeDatasetSelection } from './encoding';
import { DatasetSelectionStrategy } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { Dataset } from '../../../common/datasets';
import { Dataset } from '../../datasets';
import { encodeDatasetSelection } from './encoding';
import { DatasetSelectionStrategy, SingleDatasetSelectionPayload } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/discover_log_explorer/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
AllDatasetSelection,
DatasetSelection,
DatasetSelectionChange,
} from '../../utils/dataset_selection';
} from '../../../common/utils/dataset_selection';

const meta: Meta<typeof DatasetSelector> = {
component: DatasetSelector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,30 @@ 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'));

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,
Expand All @@ -53,7 +54,7 @@ export const createLogExplorerProfileCustomizations =
id: 'search_bar',
CustomDataViewPicker: () => (
<LazyCustomDatasetSelector
datasetsClient={datasetsService.client}
datasetsClient={datasetsClient}
logExplorerProfileStateService={logExplorerProfileStateService}
/>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/discover_log_explorer/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DiscoverLogExplorerConfig>) {
return new DiscoverLogExplorerPlugin(context);
}
35 changes: 32 additions & 3 deletions x-pack/plugins/discover_log_explorer/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,62 @@
* 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';

export class DiscoverLogExplorerPlugin
implements Plugin<DiscoverLogExplorerPluginSetup, DiscoverLogExplorerPluginStart>
{
private config: DiscoverLogExplorerConfig;
private locators?: DiscoverLogExplorerLocators;
private datasetsService: DatasetsService;
private datasetsClient?: DatasetsServiceSetup['client'];

constructor(context: PluginInitializerContext<DiscoverLogExplorerConfig>) {
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 })],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Loading