Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import React, { useMemo } from 'react';
import { EuiListGroupItem, UseEuiTheme } from '@elastic/eui';
import { css } from '@emotion/react';
import { METRIC_TYPE } from '@kbn/analytics';
import { DashboardLocatorParams } from '@kbn/dashboard-plugin/public';
import type { DashboardLocatorParams } from '@kbn/dashboard-plugin/common';
import { Query, isFilterPinned } from '@kbn/es-query';
import { useBatchedPublishingSubjects } from '@kbn/presentation-publishing';
import {
Expand Down
3 changes: 2 additions & 1 deletion src/platform/plugins/private/links/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { DefaultEmbeddableApi } from '@kbn/embeddable-plugin/public';
import { DynamicActionsSerializedState } from '@kbn/embeddable-enhanced-plugin/public/plugin';
import { HasSerializedChildState, PresentationContainer } from '@kbn/presentation-containers';
import { LocatorPublic } from '@kbn/share-plugin/common';
import { DashboardLocatorParams, DASHBOARD_API_TYPE } from '@kbn/dashboard-plugin/public';
import { DASHBOARD_API_TYPE } from '@kbn/dashboard-plugin/public';
import type { DashboardLocatorParams } from '@kbn/dashboard-plugin/common';
import type { DashboardAttributes } from '@kbn/dashboard-plugin/server';

import { CONTENT_ID } from '../common';
Expand Down
16 changes: 16 additions & 0 deletions src/platform/plugins/shared/dashboard/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export const LANDING_PAGE_PATH = '/list';
export const DASHBOARD_APP_ID = 'dashboards';
export const LEGACY_DASHBOARD_APP_ID = 'dashboard';
export const SEARCH_SESSION_ID = 'searchSessionId';
export const UI_SETTINGS = {
ENABLE_LABS_UI: 'labs:dashboard:enable_ui',
};
30 changes: 7 additions & 23 deletions src/platform/plugins/shared/dashboard/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,13 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export type { DashboardCapabilities } from './types';
export type {
DashboardCapabilities,
DashboardLocatorParams,
DashboardSettings,
DashboardState,
} from './types';

export type { DashboardPanelMap, DashboardPanelState } from './dashboard_container/types';

export {
type InjectExtractDeps,
injectReferences,
extractReferences,
} from './dashboard_saved_object/persistable_state/dashboard_saved_object_references';

export {
createInject,
createExtract,
} from './dashboard_container/persistable_state/dashboard_container_references';

export { prefixReferencesFromPanel } from './dashboard_container/persistable_state/dashboard_container_references';

export {
convertPanelsArrayToPanelMap,
convertPanelMapToPanelsArray,
generateNewPanelIds,
} from './lib/dashboard_panel_converters';

export const UI_SETTINGS = {
ENABLE_LABS_UI: 'labs:dashboard:enable_ui',
};
Copy link
Copy Markdown
Contributor Author

@nickpeihl nickpeihl Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These top level exports were removed to avoid bloating the bundle size. Aside from types, the imports from common in dashboard/public have been changed to deep imports.

export { type InjectExtractDeps } from './dashboard_saved_object/persistable_state/dashboard_saved_object_references';
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { isFilterPinned, type Query } from '@kbn/es-query';
import type { HasParentApi, PublishesUnifiedSearch } from '@kbn/presentation-publishing';
import type { DashboardDrilldownOptions } from '@kbn/presentation-util-plugin/public';
import { DashboardLocatorParams } from '../../dashboard_api/types';
import type { DashboardLocatorParams } from '..';

export const getDashboardLocatorParamsFromEmbeddable = (
api: Partial<PublishesUnifiedSearch & HasParentApi<Partial<PublishesUnifiedSearch>>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { ScopedHistory } from '@kbn/core-application-browser';
import type { ScopedHistory } from '@kbn/core-application-browser';

import { ForwardedDashboardState } from './locator';
import { convertPanelsArrayToPanelMap } from '../../../common';
import { DashboardState } from '../../dashboard_api/types';
import type { DashboardState } from '../types';
import { convertPanelsArrayToPanelMap } from '../lib/dashboard_panel_converters';

export const loadDashboardHistoryLocationState = (
getScopedHistory: () => ScopedHistory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import type { SerializableRecord } from '@kbn/utility-types';
import { flow } from 'lodash';

import type { Filter } from '@kbn/es-query';
import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public';
import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/common';
import type { LocatorDefinition, LocatorPublic } from '@kbn/share-plugin/public';
import type { GlobalQueryStateFromUrl } from '@kbn/data-plugin/public';

import { DASHBOARD_APP_LOCATOR } from '@kbn/deeplinks-analytics';
import { DASHBOARD_APP_ID, SEARCH_SESSION_ID } from '../../plugin_constants';
import { DashboardLocatorParams } from '../../dashboard_api/types';
import { DashboardLocatorParams } from '../types';
import { DASHBOARD_APP_ID, SEARCH_SESSION_ID } from '../constants';

/**
* Useful for ensuring that we don't pass any non-serializable values to history.push (for example, functions).
Expand Down
89 changes: 88 additions & 1 deletion src/platform/plugins/shared/dashboard/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,21 @@
*/

import type { Reference } from '@kbn/content-management-utils';
import type { SerializableRecord } from '@kbn/utility-types';
import type { Filter, Query, TimeRange } from '@kbn/es-query';
import type { ViewMode } from '@kbn/presentation-publishing';
import type { RefreshInterval } from '@kbn/data-plugin/public';
import type {
ControlGroupRuntimeState,
ControlGroupSerializedState,
} from '@kbn/controls-plugin/common';

import type { DashboardPanelMap } from './dashboard_container/types';
import type { DashboardAttributes } from '../server/content_management';
import type {
DashboardAttributes,
DashboardOptions,
DashboardPanel,
} from '../server/content_management';

export interface DashboardCapabilities {
showWriteControls: boolean;
Expand All @@ -31,3 +44,77 @@ export interface DashboardAttributesAndReferences {
attributes: DashboardAttributes;
references: Reference[];
}

export type DashboardSettings = DashboardOptions & {
description?: DashboardAttributes['description'];
tags: string[];
timeRestore: DashboardAttributes['timeRestore'];
title: DashboardAttributes['description'];
};

export interface DashboardState extends DashboardSettings {
query: Query;
filters: Filter[];
timeRange?: TimeRange;
refreshInterval?: RefreshInterval;
viewMode: ViewMode;
panels: DashboardPanelMap;

/**
* Temporary. Currently Dashboards are in charge of providing references to all of their children.
* Eventually this will be removed in favour of the Dashboard injecting references serverside.
*/
references?: Reference[];

/**
* Serialized control group state.
* Contains state loaded from dashboard saved object
*/
controlGroupInput?: ControlGroupSerializedState | undefined;
/**
* Runtime control group state.
* Contains state passed from dashboard locator
* Use runtime state when building input for portable dashboards
*/
controlGroupState?: Partial<ControlGroupRuntimeState>;
}

export type DashboardLocatorParams = Partial<
Omit<DashboardState, 'panels' | 'controlGroupInput' | 'references'>
> & {
/**
* If given, the dashboard saved object with this id will be loaded. If not given,
* a new, unsaved dashboard will be loaded up.
*/
dashboardId?: string;

/**
* If not given, will use the uiSettings configuration for `storeInSessionStorage`. useHash determines
* whether to hash the data in the url to avoid url length issues.
*/
useHash?: boolean;

/**
* When `true` filters from saved filters from destination dashboard as merged with applied filters
* When `false` applied filters take precedence and override saved filters
*
* true is default
*/
preserveSavedFilters?: boolean;

/**
* Search search session ID to restore.
* (Background search)
*/
searchSessionId?: string;

/**
* List of dashboard panels
*/
panels?: Array<DashboardPanel & SerializableRecord>; // used SerializableRecord here to force the GridData type to be read as serializable

/**
* Control group changes
*/
controlGroupState?: Partial<ControlGroupRuntimeState> & SerializableRecord; // used SerializableRecord here to force the GridData type to be read as serializable
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { DashboardState } from './types';
import { DashboardState } from '../../common';

export const DEFAULT_DASHBOARD_STATE: DashboardState = {
viewMode: 'view',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
getReferencesForControls,
getReferencesForPanelId,
} from '../../common/dashboard_container/persistable_state/dashboard_container_references';
import { DASHBOARD_APP_ID } from '../plugin_constants';
import { DASHBOARD_APP_ID } from '../../common/constants';
import { PANELS_CONTROL_GROUP_KEY } from '../services/dashboard_backup_service';
import { getDashboardContentManagementService } from '../services/dashboard_content_management_service';
import { LoadDashboardReturn } from '../services/dashboard_content_management_service/types';
Expand All @@ -38,9 +38,9 @@ import {
DashboardApi,
DashboardCreationOptions,
DashboardInternalApi,
DashboardState,
UnsavedPanelState,
} from './types';
import type { DashboardState } from '../../common/types';
import { initializeUnifiedSearchManager } from './unified_search_manager';
import { initializeUnsavedChangesManager } from './unsaved_changes_manager';
import { initializeViewModeManager } from './view_mode_manager';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import moment, { Moment } from 'moment';
import { RefreshInterval } from '@kbn/data-plugin/public';

import type { Reference } from '@kbn/content-management-utils';
import { convertPanelMapToPanelsArray, extractReferences, generateNewPanelIds } from '../../common';
import {
convertPanelMapToPanelsArray,
generateNewPanelIds,
} from '../../common/lib/dashboard_panel_converters';
import { extractReferences } from '../../common/dashboard_saved_object/persistable_state/dashboard_saved_object_references';
import type { DashboardAttributes } from '../../server';

import { convertDashboardVersionToNumber } from '../services/dashboard_content_management_service/lib/dashboard_versioning';
Expand All @@ -21,7 +25,7 @@ import {
embeddableService,
savedObjectsTaggingService,
} from '../services/kibana_services';
import { DashboardState } from './types';
import type { DashboardState } from '../../common';
import { LATEST_VERSION } from '../../common/content_management';
import { convertNumberToDashboardVersion } from '../services/dashboard_content_management_service/lib/dashboard_versioning';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import { ContentInsightsClient } from '@kbn/content-management-content-insights-public';
import { DashboardPanelMap } from '../../common';
import { DashboardPanelMap, DashboardState } from '../../common';
import { getDashboardContentManagementService } from '../services/dashboard_content_management_service';
import { DashboardCreationOptions, DashboardState, UnsavedPanelState } from './types';
import { DashboardCreationOptions, UnsavedPanelState } from './types';
import { getDashboardApi } from './get_dashboard_api';
import { startQueryPerformanceTracking } from './performance/query_performance_tracking';
import { coreServices } from '../services/kibana_services';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ import {
} from '@kbn/presentation-publishing';
import { i18n } from '@kbn/i18n';
import { coreServices, usageCollectionService } from '../services/kibana_services';
import { DashboardPanelMap, DashboardPanelState, prefixReferencesFromPanel } from '../../common';
import { prefixReferencesFromPanel } from '../../common/dashboard_container/persistable_state/dashboard_container_references';
import type { DashboardPanelMap, DashboardPanelState, DashboardState } from '../../common';
import type { initializeTrackPanel } from './track_panel';
import { getPanelAddedSuccessString } from '../dashboard_app/_dashboard_app_strings';
import { runPanelPlacementStrategy } from '../panel_placement/place_new_panel_strategies';
import { DEFAULT_PANEL_HEIGHT, DEFAULT_PANEL_WIDTH } from '../../common/content_management';
import { DASHBOARD_UI_METRIC_ID } from '../utils/telemetry_constants';
import { getDashboardPanelPlacementSetting } from '../panel_placement/panel_placement_registry';
import { DashboardState, UnsavedPanelState } from './types';
import { UnsavedPanelState } from './types';
import { arePanelLayoutsEqual } from './are_panel_layouts_equal';
import { dashboardClonePanelActionStrings } from '../dashboard_actions/_dashboard_actions_strings';
import { placeClonePanel } from '../panel_placement/place_clone_panel_strategy';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
savedObjectsTaggingService,
} from '../../services/kibana_services';
import { getDashboardContentManagementService } from '../../services/dashboard_content_management_service';
import { DashboardState } from '../types';
import { DashboardState } from '../../../common';
import { DASHBOARD_CONTENT_ID, SAVED_OBJECT_POST_TIME } from '../../utils/telemetry_constants';
import { extractTitleAndCount } from '../../utils/extract_title_and_count';
import { DashboardSaveModal } from './save_modal';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import fastIsEqual from 'fast-deep-equal';
import { StateComparators, initializeTitleManager } from '@kbn/presentation-publishing';
import { BehaviorSubject } from 'rxjs';
import { DashboardSettings, DashboardState } from './types';
import { DashboardSettings, DashboardState } from '../../common';
import { DEFAULT_DASHBOARD_STATE } from './default_dashboard_state';

export function initializeSettingsManager(initialState?: DashboardState) {
Expand Down
Loading