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 @@ -8,6 +8,7 @@
*/

export const LATEST_VERSION = 1;
export const DASHBOARD_API_VERSION = String(LATEST_VERSION);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think there's anything we need to do here right now, but it's coincidental that the LATEST_VERSION used by Content Management and the DASHBOARD_API_VERSION for the pubic API are both 1. I suspect we'll be removing CM from the Dashboard in the future and the LATEST_VERSION const will go away. When the Dashboard API reaches Tech Preview, the const will change to 2023-10-31.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why "2023-10-31" What does that date mean?

Copy link
Member

@nickpeihl nickpeihl Nov 3, 2025

Choose a reason for hiding this comment

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

It's the date-based API versioning scheme that Elastic uses for all public APIs. More info here and restriction implemented here. We just keep it at "1" for now as the endpoint is still internal only.


export const CONTENT_ID = 'dashboard';

Expand Down
10 changes: 0 additions & 10 deletions src/platform/plugins/shared/dashboard/jest_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
import {
mockDashboardBackupService,
mockDashboardContentManagementCache,
mockDashboardContentManagementService,
setStubKibanaServices,
setStubLogger,
} from './public/services/mocks';
Expand All @@ -26,14 +24,6 @@ setStubLogger();
// Start the kibana services with stubs
setStubKibanaServices();

// Mock the dashboard services
jest.mock('./public/services/dashboard_content_management_service', () => {
return {
getDashboardContentManagementCache: () => mockDashboardContentManagementCache,
getDashboardContentManagementService: () => mockDashboardContentManagementService,
};
});

jest.mock('./public/services/dashboard_backup_service', () => {
return {
getDashboardBackupService: () => mockDashboardBackupService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { CONTROLS_GROUP_TYPE } from '@kbn/controls-constants';
import { DASHBOARD_APP_ID } from '../../common/constants';
import { getReferencesForControls, getReferencesForPanelId } from '../../common';
import type { DashboardState } from '../../common/types';
import { getDashboardContentManagementService } from '../services/dashboard_content_management_service';
import type { LoadDashboardReturn } from '../services/dashboard_content_management_service/types';
import {
CONTROL_GROUP_EMBEDDABLE_ID,
initializeControlGroupManager,
Expand All @@ -37,6 +35,8 @@ import { initializeUnifiedSearchManager } from './unified_search_manager';
import { initializeUnsavedChangesManager } from './unsaved_changes_manager';
import { initializeViewModeManager } from './view_mode_manager';
import { mergeControlGroupStates } from './merge_control_group_states';
import type { DashboardAPIGetOut } from '../../server/content_management';
import { saveDashboard } from './save_modal/save_dashboard';

export function getDashboardApi({
creationOptions,
Expand All @@ -48,15 +48,19 @@ export function getDashboardApi({
creationOptions?: DashboardCreationOptions;
incomingEmbeddables?: EmbeddablePackageState[] | undefined;
initialState: DashboardState;
savedObjectResult?: LoadDashboardReturn;
savedObjectResult?: DashboardAPIGetOut;
savedObjectId?: string;
}) {
const fullScreenMode$ = new BehaviorSubject(creationOptions?.fullScreenMode ?? false);
const isManaged = savedObjectResult?.managed ?? false;
const isManaged = savedObjectResult?.meta.managed ?? false;
const savedObjectId$ = new BehaviorSubject<string | undefined>(savedObjectId);
const dashboardContainerRef$ = new BehaviorSubject<HTMLElement | null>(null);

const viewModeManager = initializeViewModeManager(incomingEmbeddables, savedObjectResult);
const viewModeManager = initializeViewModeManager({
incomingEmbeddables,
isManaged,
savedObjectId,
});
const trackPanel = initializeTrackPanel(async (id: string) => {
await layoutManager.api.getChildApi(id);
}, dashboardContainerRef$);
Expand Down Expand Up @@ -107,7 +111,7 @@ export function getDashboardApi({
viewMode$: viewModeManager.api.viewMode$,
storeUnsavedChanges: creationOptions?.useSessionStorageIntegration,
controlGroupManager,
lastSavedState: savedObjectResult?.dashboardInput ?? DEFAULT_DASHBOARD_STATE,
lastSavedState: savedObjectResult?.data ?? DEFAULT_DASHBOARD_STATE,
layoutManager,
savedObjectId$,
settingsManager,
Expand Down Expand Up @@ -209,7 +213,7 @@ export function getDashboardApi({
runQuickSave: async () => {
if (isManaged) return;
const { dashboardState, references } = getState();
const saveResult = await getDashboardContentManagementService().saveDashboardState({
const saveResult = await saveDashboard({
dashboardState,
references,
saveOptions: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ jest.mock('@kbn/content-management-content-insights-public', () => {
};
});

jest.mock('../../dashboard_client', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const defaultState = require('../default_dashboard_state');
return {
dashboardClient: {
get: jest.fn().mockResolvedValue({
data: { ...defaultState.DEFAULT_DASHBOARD_STATE },
}),
},
};
});

const lastSavedQuery = { query: 'memory:>220000', language: 'kuery' };

describe('loadDashboardApi', () => {
Expand All @@ -39,16 +51,6 @@ describe('loadDashboardApi', () => {
internalApi: {},
});

// eslint-disable-next-line @typescript-eslint/no-var-requires
require('../../services/dashboard_content_management_service').getDashboardContentManagementService =
() => ({
loadDashboardState: () => ({
dashboardFound: true,
dashboardInput: DEFAULT_DASHBOARD_STATE,
references: [],
}),
});

// eslint-disable-next-line @typescript-eslint/no-var-requires
require('../../services/dashboard_backup_service').getDashboardBackupService = () => ({
getState: () => ({
Expand All @@ -71,10 +73,7 @@ describe('loadDashboardApi', () => {
});
expect(getDashboardApiMock).toHaveBeenCalled();
// @ts-ignore
expect(getDashboardApiMock.mock.calls[0][0].initialState).toEqual({
...DEFAULT_DASHBOARD_STATE,
references: [],
});
expect(getDashboardApiMock.mock.calls[0][0].initialState).toEqual(DEFAULT_DASHBOARD_STATE);
});

test('should overwrite saved object state with unsaved state', async () => {
Expand All @@ -88,7 +87,6 @@ describe('loadDashboardApi', () => {
// @ts-ignore
expect(getDashboardApiMock.mock.calls[0][0].initialState).toEqual({
...DEFAULT_DASHBOARD_STATE,
references: [],
query: lastSavedQuery,
});
});
Expand All @@ -109,7 +107,6 @@ describe('loadDashboardApi', () => {
// @ts-ignore
expect(getDashboardApiMock.mock.calls[0][0].initialState).toEqual({
...DEFAULT_DASHBOARD_STATE,
references: [],
query: queryFromUrl,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
*/

import { ContentInsightsClient } from '@kbn/content-management-content-insights-public';
import type { DashboardState } from '../../../common';
import { getDashboardBackupService } from '../../services/dashboard_backup_service';
import { getDashboardContentManagementService } from '../../services/dashboard_content_management_service';
import { coreServices } from '../../services/kibana_services';
import { logger } from '../../services/logger';
import { getDashboardApi } from '../get_dashboard_api';
import { startQueryPerformanceTracking } from '../performance/query_performance_tracking';
import type { DashboardCreationOptions } from '../types';
import { transformPanels } from './transform_panels';
import { dashboardClient } from '../../dashboard_client';
import { DEFAULT_DASHBOARD_STATE } from '../default_dashboard_state';

export async function loadDashboardApi({
getCreationOptions,
Expand All @@ -28,13 +28,8 @@ export async function loadDashboardApi({
const creationStartTime = performance.now();
const creationOptions = await getCreationOptions?.();
const incomingEmbeddables = creationOptions?.getIncomingEmbeddables?.();
const savedObjectResult = await getDashboardContentManagementService().loadDashboardState({
id: savedObjectId,
});
const savedObjectResult = savedObjectId ? await dashboardClient.get(savedObjectId) : undefined;

// --------------------------------------------------------------------------------------
// Run validation.
// --------------------------------------------------------------------------------------
const validationResult =
savedObjectResult && creationOptions?.validateLoadedSavedObject?.(savedObjectResult);
if (validationResult === 'invalid') {
Expand All @@ -44,25 +39,10 @@ export async function loadDashboardApi({
return;
}

// --------------------------------------------------------------------------------------
// Combine saved object state and session storage state
// --------------------------------------------------------------------------------------
const sessionStorageInput = ((): Partial<DashboardState> | undefined => {
if (!creationOptions?.useSessionStorageIntegration) return;
return getDashboardBackupService().getState(savedObjectResult.dashboardId);
})();

const combinedSessionState: DashboardState = {
...(savedObjectResult?.dashboardInput ?? {}),
...sessionStorageInput,
};
combinedSessionState.references = sessionStorageInput?.references?.length
? sessionStorageInput?.references
: savedObjectResult?.references;
const unsavedChanges = creationOptions?.useSessionStorageIntegration
? getDashboardBackupService().getState(savedObjectId)
: undefined;

// --------------------------------------------------------------------------------------
// Combine state with overrides.
// --------------------------------------------------------------------------------------
const { viewMode, ...overrideState } = creationOptions?.getInitialInput?.() ?? {};
if (overrideState.panels) {
overrideState.panels = await transformPanels(overrideState.panels, overrideState.references);
Expand All @@ -73,14 +53,13 @@ export async function loadDashboardApi({
getDashboardBackupService().storeViewMode(viewMode);
}

// --------------------------------------------------------------------------------------
// get dashboard Api
// --------------------------------------------------------------------------------------
const { api, cleanup, internalApi } = getDashboardApi({
creationOptions,
incomingEmbeddables,
initialState: {
...combinedSessionState,
...DEFAULT_DASHBOARD_STATE,
...savedObjectResult?.data,
...unsavedChanges,
...overrideState,
},
savedObjectResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import type { Reference } from '@kbn/content-management-utils';
import { reportPerformanceMetricEvent } from '@kbn/ebt-tools';
import { showSaveModal } from '@kbn/saved-objects-plugin/public';
import { i18n } from '@kbn/i18n';
import type { SaveDashboardReturn } from '../../services/dashboard_content_management_service/types';
import type { DashboardSaveOptions } from './types';
import type { DashboardSaveOptions, SaveDashboardReturn } from './types';
import { coreServices, savedObjectsTaggingService } from '../../services/kibana_services';
import { getDashboardContentManagementService } from '../../services/dashboard_content_management_service';
import type { 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';
import { checkForDuplicateDashboardTitle } from '../../dashboard_client';
import { saveDashboard } from './save_dashboard';

/**
* @description exclusively for user directed dashboard save actions, also
Expand Down Expand Up @@ -51,7 +51,6 @@ export async function openSaveModal({
if (viewMode === 'edit' && isManaged) {
return undefined;
}
const dashboardContentManagementService = getDashboardContentManagementService();
const saveAsTitle = lastSavedId ? await getSaveAsTitle(title) : title;
return new Promise<(SaveDashboardReturn & { savedState: DashboardState }) | undefined>(
(resolve) => {
Expand All @@ -73,7 +72,7 @@ export async function openSaveModal({

try {
if (
!(await dashboardContentManagementService.checkForDuplicateDashboardTitle({
!(await checkForDuplicateDashboardTitle({
title: newTitle,
onTitleDuplicate,
lastSavedTitle: title,
Expand All @@ -99,7 +98,7 @@ export async function openSaveModal({

const beforeAddTime = window.performance.now();

const saveResult = await dashboardContentManagementService.saveDashboardState({
const saveResult = await saveDashboard({
references,
saveOptions,
dashboardState: dashboardStateToSave,
Expand Down Expand Up @@ -178,7 +177,7 @@ function generateDashboardNotSavedToast(title: string, errorMessage: any) {
async function getSaveAsTitle(title: string) {
const [baseTitle, baseCount] = extractTitleAndCount(title);
let saveAsTitle = `${baseTitle} (${baseCount + 1})`;
await getDashboardContentManagementService().checkForDuplicateDashboardTitle({
await checkForDuplicateDashboardTitle({
title: saveAsTitle,
lastSavedTitle: title,
copyOnSave: true,
Expand Down
Loading