Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dashboard] clean up dashboard setup and start contracts #212968

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/platform/plugins/shared/dashboard/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type { DashboardApi, DashboardCreationOptions } from './dashboard_api/typ
export { DASHBOARD_API_TYPE } from './dashboard_api/types';
export { LazyDashboardRenderer as DashboardRenderer } from './dashboard_container/external_api/lazy_dashboard_renderer';
export type { DashboardLocatorParams } from './dashboard_container/types';
export type { DashboardSetup, DashboardStart, DashboardFeatureFlagConfig } from './plugin';
export type { DashboardStart } from './plugin';

export { DashboardListingTable } from './dashboard_listing';
export { DashboardTopNav } from './dashboard_top_nav';
Expand Down
47 changes: 9 additions & 38 deletions src/platform/plugins/shared/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ import type {
} from '@kbn/usage-collection-plugin/public';

import { CONTENT_ID, LATEST_VERSION } from '../common/content_management';
import {
DashboardAppLocatorDefinition,
type DashboardAppLocator,
} from './dashboard_app/locator/locator';
import { DashboardAppLocatorDefinition } from './dashboard_app/locator/locator';
import { DashboardMountContextProps } from './dashboard_app/types';
import {
DASHBOARD_APP_ID,
Expand All @@ -80,10 +77,7 @@ import type { FindDashboardsService } from './services/dashboard_content_managem
import { setKibanaServices, untilPluginStartServicesReady } from './services/kibana_services';
import { setLogger } from './services/logger';
import { registerActions } from './dashboard_actions/register_actions';

export interface DashboardFeatureFlagConfig {
allowByValueEmbeddables: boolean;
}
import type { ConfigSchema } from '../server/config';

export interface DashboardSetupDependencies {
data: DataPublicPluginSetup;
Expand Down Expand Up @@ -125,32 +119,17 @@ export interface DashboardStartDependencies {
observabilityAIAssistant?: ObservabilityAIAssistantPublicStart;
}

export interface DashboardSetup {
/**
* @deprecated
*
* Use `shareStartService.url.locators.get(DASHBOARD_APP_LOCATOR)` instead.
*/
locator?: DashboardAppLocator;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface DashboardSetup {}

export interface DashboardStart {
/**
* @deprecated
*
* Use `shareStartService.url.locators.get(DASHBOARD_APP_LOCATOR)` instead.
*/
locator?: DashboardAppLocator;
dashboardFeatureFlagConfig: DashboardFeatureFlagConfig;
findDashboardsService: () => Promise<FindDashboardsService>;
registerDashboardPanelPlacementSetting: <SerializedState extends object = object>(
embeddableType: string,
getPanelPlacementSettings: GetPanelPlacementSettings<SerializedState>
) => void;
}

export let resolveServicesReady: () => void;

export class DashboardPlugin
implements
Plugin<DashboardSetup, DashboardStart, DashboardSetupDependencies, DashboardStartDependencies>
Expand All @@ -162,23 +141,18 @@ export class DashboardPlugin
private appStateUpdater = new BehaviorSubject<AppUpdater>(() => ({}));
private stopUrlTracking: (() => void) | undefined = undefined;
private currentHistory: ScopedHistory | undefined = undefined;
private dashboardFeatureFlagConfig?: DashboardFeatureFlagConfig;
private locator?: DashboardAppLocator;

public setup(
core: CoreSetup<DashboardStartDependencies, DashboardStart>,
{ share, embeddable, home, urlForwarding, data, contentManagement }: DashboardSetupDependencies
): DashboardSetup {
this.dashboardFeatureFlagConfig =
this.initializerContext.config.get<DashboardFeatureFlagConfig>();

) {
core.analytics.registerEventType({
eventType: 'dashboard_loaded_with_data',
schema: {},
});

if (share) {
this.locator = share.url.locators.create(
share.url.locators.create(
new DashboardAppLocatorDefinition({
useHashedUrl: core.uiSettings.get('state:storeInSessionStorage'),
getDashboardFilterFields: async (dashboardId: string) => {
Expand Down Expand Up @@ -329,9 +303,7 @@ export class DashboardPlugin
name: dashboardAppTitle,
});

return {
locator: this.locator,
};
return {};
}

public start(core: CoreStart, plugins: DashboardStartDependencies): DashboardStart {
Expand All @@ -340,13 +312,12 @@ export class DashboardPlugin
untilPluginStartServicesReady().then(() => {
registerActions({
plugins,
allowByValueEmbeddables: this.dashboardFeatureFlagConfig?.allowByValueEmbeddables,
allowByValueEmbeddables:
this.initializerContext.config.get<ConfigSchema>()?.allowByValueEmbeddables ?? true,
});
});

return {
locator: this.locator,
dashboardFeatureFlagConfig: this.dashboardFeatureFlagConfig!,
registerDashboardPanelPlacementSetting,
findDashboardsService: async () => {
const { getDashboardContentManagementService } = await import(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
"dashboardEnhanced"
],
"requiredPlugins": [
"dashboard",
"data",
"embeddable",
"share",
"uiActionsEnhanced",
"unifiedSearch"
],
"requiredBundles": [
"dashboard",
"embeddable",
"embeddableEnhanced",
"kibanaUtils",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
AdvancedUiActionsSetup,
AdvancedUiActionsStart,
} from '@kbn/ui-actions-enhanced-plugin/public';
import { DashboardStart } from '@kbn/dashboard-plugin/public';
import { DashboardDrilldownsService } from './services';

export interface SetupDependencies {
Expand All @@ -27,7 +26,6 @@ export interface StartDependencies {
data: DataPublicPluginStart;
embeddable: EmbeddableStart;
share: SharePluginStart;
dashboard: DashboardStart;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
* 2.0.
*/

import type { KibanaLocation } from '@kbn/share-plugin/public';
import type { KibanaLocation, SharePluginStart } from '@kbn/share-plugin/public';
import React from 'react';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { DashboardStart } from '@kbn/dashboard-plugin/public';
import {
AdvancedUiActionsStart,
UiActionsEnhancedBaseActionFactoryContext as BaseActionFactoryContext,
UiActionsEnhancedDrilldownDefinition as Drilldown,
} from '@kbn/ui-actions-enhanced-plugin/public';
import { CollectConfigProps, StartServicesGetter } from '@kbn/kibana-utils-plugin/public';
import { DEFAULT_DASHBOARD_DRILLDOWN_OPTIONS } from '@kbn/presentation-util-plugin/public';
import { DASHBOARD_APP_LOCATOR } from '@kbn/deeplinks-analytics';

import { CollectConfigContainer } from './components';
import { txtGoToDashboard } from './i18n';
Expand All @@ -24,7 +24,7 @@ export interface Params {
start: StartServicesGetter<{
uiActionsEnhanced: AdvancedUiActionsStart;
data: DataPublicPluginStart;
dashboard: DashboardStart;
share: SharePluginStart;
}>;
}

Expand Down Expand Up @@ -87,7 +87,7 @@ export abstract class AbstractDashboardDrilldown<Context extends object = object
};

protected get locator() {
const locator = this.params.start().plugins.dashboard.locator;
const locator = this.params.start().plugins.share.url.locators.get(DASHBOARD_APP_LOCATOR);
if (!locator) throw new Error('Dashboard locator is required for dashboard drilldown.');
return locator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,21 @@ describe('.execute() & getHref', () => {
},
plugins: {
uiActionsEnhanced: {},
dashboard: {
locator: {
getLocation: async (params: DashboardLocatorParams) => {
return await definition.getLocation(params);
share: {
url: {
locators: {
get: () => ({
getLocation: async (params: DashboardLocatorParams) => {
return await definition.getLocation(params);
},
}),
},
},
},
},
self: {},
})) as unknown as StartServicesGetter<
Pick<StartDependencies, 'data' | 'uiActionsEnhanced' | 'dashboard'>
Pick<StartDependencies, 'data' | 'uiActionsEnhanced' | 'share'>
>,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"@kbn/presentation-util-plugin",
"@kbn/presentation-containers",
"@kbn/presentation-publishing",
"@kbn/react-kibana-mount"
"@kbn/react-kibana-mount",
"@kbn/deeplinks-analytics"
],
"exclude": ["target/**/*"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
import { isDefined } from '@kbn/ml-is-defined';
import { parseInterval } from '@kbn/ml-parse-interval';

import type { SharePluginStart } from '@kbn/share-plugin/public';
import { DASHBOARD_APP_LOCATOR } from '@kbn/deeplinks-analytics';
import type { DashboardItems } from '../../../services/dashboard_service';
import { categoryFieldTypes } from '../../../../../common/util/fields_utils';
import { TIME_RANGE_TYPE, URL_TYPE } from './constants';
Expand Down Expand Up @@ -221,12 +223,13 @@ export function isValidCustomUrlSettings(

export function buildCustomUrlFromSettings(
dashboardService: DashboardStart,
share: SharePluginStart,
settings: CustomUrlSettings
): Promise<MlUrlConfig> {
// Dashboard URL returns a Promise as a query is made to obtain the full dashboard config.
// So wrap the other two return types in a Promise for consistent return type.
if (settings.type === URL_TYPE.KIBANA_DASHBOARD) {
return buildDashboardUrlFromSettings(dashboardService, settings);
return buildDashboardUrlFromSettings(dashboardService, share, settings);
} else if (settings.type === URL_TYPE.KIBANA_DISCOVER) {
return Promise.resolve(buildDiscoverUrlFromSettings(settings));
} else {
Expand Down Expand Up @@ -256,6 +259,7 @@ function getUrlRangeFromSettings(settings: CustomUrlSettings) {

async function buildDashboardUrlFromSettings(
dashboardService: DashboardStart,
share: SharePluginStart,
settings: CustomUrlSettings,
isPartialDFAJob?: boolean
): Promise<MlUrlConfig> {
Expand Down Expand Up @@ -300,7 +304,7 @@ async function buildDashboardUrlFromSettings(

const { from, to } = getUrlRangeFromSettings(settings);

const location = await dashboardService.locator?.getLocation({
const location = await share.url.locators.get(DASHBOARD_APP_LOCATOR)?.getLocation({
dashboardId,
timeRange: {
from,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ export class CustomUrls extends Component<CustomUrlsProps, CustomUrlsState> {
};

addNewCustomUrl = () => {
const { dashboard } = this.context.services;
const { dashboard, share } = this.context.services;

buildCustomUrlFromSettings(dashboard, this.state.editorSettings as CustomUrlSettings)
buildCustomUrlFromSettings(dashboard, share, this.state.editorSettings as CustomUrlSettings)
.then((customUrl) => {
const customUrls = [...this.state.customUrls, customUrl];
this.props.setCustomUrls(customUrls);
Expand All @@ -179,6 +179,7 @@ export class CustomUrls extends Component<CustomUrlsProps, CustomUrlsState> {
data: { dataViews },
dashboard,
mlServices: { mlApi },
share,
} = this.context.services;
const dataViewId = this.state?.editorSettings?.kibanaSettings?.discoverIndexPatternId;
const job = this.props.job;
Expand All @@ -191,33 +192,34 @@ export class CustomUrls extends Component<CustomUrlsProps, CustomUrlsState> {
})
.then((dataView) => {
const timefieldName = dataView?.timeFieldName ?? null;
buildCustomUrlFromSettings(dashboard, this.state.editorSettings as CustomUrlSettings).then(
(customUrl) => {
getTestUrl(
mlApi,
job,
customUrl,
timefieldName,
this.props.currentTimeFilter,
this.props.isPartialDFAJob
)
.then((testUrl) => {
openCustomUrlWindow(testUrl, customUrl, basePath.get());
})
.catch((error) => {
this.toastNotificationService!.displayErrorToast(
error,
i18n.translate(
'xpack.ml.jobsList.editJobFlyout.customUrls.getTestUrlErrorNotificationMessage',
{
defaultMessage:
'An error occurred obtaining the URL to test the configuration',
}
)
);
});
}
);
buildCustomUrlFromSettings(
dashboard,
share,
this.state.editorSettings as CustomUrlSettings
).then((customUrl) => {
getTestUrl(
mlApi,
job,
customUrl,
timefieldName,
this.props.currentTimeFilter,
this.props.isPartialDFAJob
)
.then((testUrl) => {
openCustomUrlWindow(testUrl, customUrl, basePath.get());
})
.catch((error) => {
this.toastNotificationService!.displayErrorToast(
error,
i18n.translate(
'xpack.ml.jobsList.editJobFlyout.customUrls.getTestUrlErrorNotificationMessage',
{
defaultMessage: 'An error occurred obtaining the URL to test the configuration',
}
)
);
});
});
})
.catch((error) => {
this.toastNotificationService!.displayErrorToast(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ import type { IUiSettingsClient } from '@kbn/core/public';
import type { TimefilterContract } from '@kbn/data-plugin/public';
import { firstValueFrom } from 'rxjs';
import type { estypes } from '@elastic/elasticsearch';
import type {
DashboardApi,
DashboardLocatorParams,
DashboardStart,
} from '@kbn/dashboard-plugin/public';
import type { DashboardApi, DashboardLocatorParams } from '@kbn/dashboard-plugin/public';
import { getTitle } from '@kbn/presentation-publishing';
import type { Filter, Query, DataViewBase } from '@kbn/es-query';
import { FilterStateStore } from '@kbn/es-query';
import type { ErrorType } from '@kbn/ml-error-utils';
import type { DataViewsContract } from '@kbn/data-views-plugin/public';
import type { SharePluginStart } from '@kbn/share-plugin/public';
import { DASHBOARD_APP_LOCATOR } from '@kbn/deeplinks-analytics';
import type { MlApi } from '../../../services/ml_api_service';
import type { Job, Datafeed } from '../../../../../common/types/anomaly_detection_jobs';
import { getFiltersForDSLQuery } from '../../../../../common/util/job_utils';
Expand Down Expand Up @@ -55,7 +53,7 @@ export class QuickJobCreatorBase {
protected readonly dataViews: DataViewsContract,
protected readonly kibanaConfig: IUiSettingsClient,
protected readonly timeFilter: TimefilterContract,
protected readonly dashboardService: DashboardStart,
protected readonly share: SharePluginStart,
protected readonly mlApi: MlApi
) {}

Expand Down Expand Up @@ -246,7 +244,7 @@ export class QuickJobCreatorBase {
),
};

const location = await this.dashboardService.locator?.getLocation(params);
const location = await this.share.url.locators.get(DASHBOARD_APP_LOCATOR)?.getLocation(params);
if (location === undefined) {
return null;
}
Expand Down
Loading