Skip to content

Commit

Permalink
[8.x] [dashboard] decouple DashboardCreationOptions from DashboardCon…
Browse files Browse the repository at this point in the history
…tainer (elastic#194875) (elastic#195322)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[dashboard] decouple DashboardCreationOptions from DashboardContainer
(elastic#194875)](elastic#194875)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nathan
Reese","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-07T20:43:12Z","message":"[dashboard]
decouple DashboardCreationOptions from DashboardContainer
(elastic#194875)\n\nPR decouples `DashboardCreationOptions` type from
`DashboardContainer`\r\nand moves `DashboardCreationOptions` type into
dashboard_api folder.\r\n`useControlGroupIntegration` removed from
`DashboardCreationOptions`\r\ntype since its no longer
used.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"ecc7d4e2e6099beca9028c6aacec978ad0e7e992","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Dashboard","Team:Presentation","loe:small","release_note:skip","impact:low","v9.0.0","ci:project-deploy-observability","Team:obs-ux-infra_services","apm:review","project:embeddableRebuild","v8.16.0","backport:version"],"title":"[dashboard]
decouple DashboardCreationOptions from
DashboardContainer","number":194875,"url":"https://github.com/elastic/kibana/pull/194875","mergeCommit":{"message":"[dashboard]
decouple DashboardCreationOptions from DashboardContainer
(elastic#194875)\n\nPR decouples `DashboardCreationOptions` type from
`DashboardContainer`\r\nand moves `DashboardCreationOptions` type into
dashboard_api folder.\r\n`useControlGroupIntegration` removed from
`DashboardCreationOptions`\r\ntype since its no longer
used.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"ecc7d4e2e6099beca9028c6aacec978ad0e7e992"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/194875","number":194875,"mergeCommit":{"message":"[dashboard]
decouple DashboardCreationOptions from DashboardContainer
(elastic#194875)\n\nPR decouples `DashboardCreationOptions` type from
`DashboardContainer`\r\nand moves `DashboardCreationOptions` type into
dashboard_api folder.\r\n`useControlGroupIntegration` removed from
`DashboardCreationOptions`\r\ntype since its no longer
used.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"ecc7d4e2e6099beca9028c6aacec978ad0e7e992"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Nathan Reese <[email protected]>
  • Loading branch information
kibanamachine and nreese authored Oct 7, 2024
1 parent 6939c8d commit 41f3e79
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export const DashboardWithControlsExample = ({ dataView }: { dataView: DataView
});

return {
useControlGroupIntegration: true,
getInitialInput: () => ({
timeRange: { from: 'now-30d', to: 'now' },
viewMode: ViewMode.VIEW,
Expand Down
43 changes: 41 additions & 2 deletions src/plugins/dashboard/public/dashboard_api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
TracksOverlays,
} from '@kbn/presentation-containers';
import {
EmbeddableAppContext,
HasAppContext,
HasType,
PublishesDataViews,
Expand All @@ -29,11 +30,49 @@ import {
} from '@kbn/presentation-publishing';
import { ControlGroupApi, ControlGroupSerializedState } from '@kbn/controls-plugin/public';
import { Filter, Query, TimeRange } from '@kbn/es-query';
import { DefaultEmbeddableApi, ErrorEmbeddable, IEmbeddable } from '@kbn/embeddable-plugin/public';
import {
DefaultEmbeddableApi,
EmbeddablePackageState,
ErrorEmbeddable,
IEmbeddable,
} from '@kbn/embeddable-plugin/public';
import { Observable } from 'rxjs';
import { SearchSessionInfoProvider } from '@kbn/data-plugin/public';
import { IKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public';
import { DashboardPanelMap, DashboardPanelState } from '../../common';
import { SaveDashboardReturn } from '../services/dashboard_content_management_service/types';
import {
LoadDashboardReturn,
SaveDashboardReturn,
SavedDashboardInput,
} from '../services/dashboard_content_management_service/types';
import { DashboardStateFromSettingsFlyout, UnsavedPanelState } from '../dashboard_container/types';

export interface DashboardCreationOptions {
getInitialInput?: () => Partial<SavedDashboardInput>;

getIncomingEmbeddable?: () => EmbeddablePackageState | undefined;

useSearchSessionsIntegration?: boolean;
searchSessionSettings?: {
sessionIdToRestore?: string;
sessionIdUrlChangeObservable?: Observable<string | undefined>;
getSearchSessionIdFromURL: () => string | undefined;
removeSessionIdFromUrl: () => void;
createSessionRestorationDataProvider: (dashboardApi: DashboardApi) => SearchSessionInfoProvider;
};

useSessionStorageIntegration?: boolean;

useUnifiedSearchIntegration?: boolean;
unifiedSearchSettings?: { kbnUrlStateStorage: IKbnUrlStateStorage };

validateLoadedSavedObject?: (result: LoadDashboardReturn) => 'valid' | 'invalid' | 'redirected';

isEmbeddedExternally?: boolean;

getEmbeddableAppContext?: (dashboardId?: string) => EmbeddableAppContext;
}

export type DashboardApi = CanExpandPanels &
HasAppContext &
HasRuntimeChildState &
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/dashboard/public/dashboard_app/dashboard_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ import { ViewMode } from '@kbn/embeddable-plugin/public';
import { useExecutionContext } from '@kbn/kibana-react-plugin/public';
import { createKbnUrlStateStorage, withNotifyOnErrors } from '@kbn/kibana-utils-plugin/public';

import { DashboardApi, DashboardRenderer } from '..';
import { DashboardApi, DashboardCreationOptions, DashboardRenderer } from '..';
import { SharedDashboardState } from '../../common';
import {
DASHBOARD_APP_ID,
DASHBOARD_STATE_STORAGE_KEY,
createDashboardEditUrl,
} from '../dashboard_constants';
import type { DashboardCreationOptions } from '../dashboard_container/embeddable/dashboard_container_factory';
import { DashboardRedirect } from '../dashboard_container/types';
import { DashboardTopNav } from '../dashboard_top_nav';
import {
Expand Down Expand Up @@ -143,7 +142,6 @@ export function DashboardApp({
embeddableService.getStateTransfer().getIncomingEmbeddablePackage(DASHBOARD_APP_ID, true),

// integrations
useControlGroupIntegration: true,
useSessionStorageIntegration: true,
useUnifiedSearchIntegration: true,
unifiedSearchSettings: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import {
import { replaceUrlHashQuery } from '@kbn/kibana-utils-plugin/common';
import type { Query } from '@kbn/es-query';
import { SearchSessionInfoProvider } from '@kbn/data-plugin/public';

import type { ViewMode } from '@kbn/embeddable-plugin/common';
import { DASHBOARD_APP_LOCATOR } from '@kbn/deeplinks-analytics';
import { SEARCH_SESSION_ID } from '../../dashboard_constants';
import { DashboardContainer, DashboardLocatorParams } from '../../dashboard_container';
import { DashboardLocatorParams } from '../../dashboard_container';
import { convertPanelMapToSavedPanels } from '../../../common';
import { dataService } from '../../services/kibana_services';
import { DashboardApi } from '../../dashboard_api/types';

export const removeSearchSessionIdFromURL = (kbnUrlStateStorage: IKbnUrlStateStorage) => {
kbnUrlStateStorage.kbnUrlControls.updateAsync((nextUrl) => {
Expand All @@ -46,14 +47,15 @@ export const getSessionURLObservable = (history: History) =>
);

export function createSessionRestorationDataProvider(
container: DashboardContainer
dashboardApi: DashboardApi
): SearchSessionInfoProvider<DashboardLocatorParams> {
return {
getName: async () => container.getTitle(),
getName: async () =>
dashboardApi.panelTitle.value ?? dashboardApi.savedObjectId.value ?? dashboardApi.uuid$.value,
getLocatorData: async () => ({
id: DASHBOARD_APP_LOCATOR,
initialState: getLocatorParams({ container, shouldRestoreSearchSession: false }),
restoreState: getLocatorParams({ container, shouldRestoreSearchSession: true }),
initialState: getLocatorParams({ dashboardApi, shouldRestoreSearchSession: false }),
restoreState: getLocatorParams({ dashboardApi, shouldRestoreSearchSession: true }),
}),
};
}
Expand All @@ -63,24 +65,19 @@ export function createSessionRestorationDataProvider(
* as it was.
*/
function getLocatorParams({
container,
dashboardApi,
shouldRestoreSearchSession,
}: {
container: DashboardContainer;
dashboardApi: DashboardApi;
shouldRestoreSearchSession: boolean;
}): DashboardLocatorParams {
const {
explicitInput: { panels, query, viewMode },
} = container.getState();

const savedObjectId = container.savedObjectId.value;

const savedObjectId = dashboardApi.savedObjectId.value;
return {
viewMode,
viewMode: (dashboardApi.viewMode.value as ViewMode) ?? 'view',
useHash: false,
preserveSavedFilters: false,
filters: dataService.query.filterManager.getFilters(),
query: dataService.query.queryString.formatQuery(query) as Query,
query: dataService.query.queryString.formatQuery(dashboardApi.query$.value) as Query,
dashboardId: savedObjectId,
searchSessionId: shouldRestoreSearchSession
? dataService.search.session.getSessionId()
Expand All @@ -96,6 +93,8 @@ function getLocatorParams({
: undefined,
panels: savedObjectId
? undefined
: (convertPanelMapToSavedPanels(panels) as DashboardLocatorParams['panels']),
: (convertPanelMapToSavedPanels(
dashboardApi.panels$.value
) as DashboardLocatorParams['panels']),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { createKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public';
import { DEFAULT_DASHBOARD_INPUT } from '../../../dashboard_constants';
import { getSampleDashboardPanel, mockControlGroupApi } from '../../../mocks';
import { dataService, embeddableService } from '../../../services/kibana_services';
import { DashboardCreationOptions } from '../dashboard_container_factory';
import { DashboardCreationOptions } from '../../..';
import { createDashboard } from './create_dashboard';
import { getDashboardContentManagementService } from '../../../services/dashboard_content_management_service';
import { getDashboardBackupService } from '../../../services/dashboard_backup_service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { runPanelPlacementStrategy } from '../../panel_placement/place_new_panel
import { startDiffingDashboardState } from '../../state/diffing/dashboard_diffing_integration';
import { UnsavedPanelState } from '../../types';
import { DashboardContainer } from '../dashboard_container';
import { DashboardCreationOptions } from '../dashboard_container_factory';
import type { DashboardCreationOptions } from '../../..';
import { startSyncingDashboardDataViews } from './data_views/sync_dashboard_data_views';
import { startQueryPerformanceTracking } from './performance/query_performance_tracking';
import { startDashboardSearchSessionIntegration } from './search_sessions/start_dashboard_search_session_integration';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { noSearchSessionStorageCapabilityMessage } from '@kbn/data-plugin/public

import { dataService } from '../../../../services/kibana_services';
import { DashboardContainer } from '../../dashboard_container';
import { DashboardCreationOptions } from '../../dashboard_container_factory';
import type { DashboardApi, DashboardCreationOptions } from '../../../..';
import { newSession$ } from './new_session';
import { getDashboardCapabilities } from '../../../../utils/get_dashboard_capabilities';

Expand All @@ -33,15 +33,18 @@ export function startDashboardSearchSessionIntegration(
createSessionRestorationDataProvider,
} = searchSessionSettings;

dataService.search.session.enableStorage(createSessionRestorationDataProvider(this), {
isDisabled: () =>
getDashboardCapabilities().storeSearchSession
? { disabled: false }
: {
disabled: true,
reasonText: noSearchSessionStorageCapabilityMessage,
},
});
dataService.search.session.enableStorage(
createSessionRestorationDataProvider(this as DashboardApi),
{
isDisabled: () =>
getDashboardCapabilities().storeSearchSession
? { disabled: false }
: {
disabled: true,
reasonText: noSearchSessionStorageCapabilityMessage,
},
}
);

// force refresh when the session id in the URL changes. This will also fire off the "handle search session change" below.
const searchSessionIdChangeSubscription = sessionIdUrlChangeObservable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ import {
} from './create/controls/dashboard_control_group_integration';
import { initializeDashboard } from './create/create_dashboard';
import {
DashboardCreationOptions,
dashboardTypeDisplayLowercase,
dashboardTypeDisplayName,
} from './dashboard_container_factory';
import { InitialComponentState, getDashboardApi } from '../../dashboard_api/get_dashboard_api';
import type { DashboardCreationOptions } from '../..';

export interface InheritedChildInput {
filters: Filter[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,27 @@
*/

import { i18n } from '@kbn/i18n';
import { Observable } from 'rxjs';

import { SearchSessionInfoProvider } from '@kbn/data-plugin/public';
import { EmbeddablePersistableStateService } from '@kbn/embeddable-plugin/common';
import {
Container,
ContainerOutput,
EmbeddableFactory,
EmbeddableFactoryDefinition,
EmbeddablePackageState,
ErrorEmbeddable,
} from '@kbn/embeddable-plugin/public';
import { IKbnUrlStateStorage } from '@kbn/kibana-utils-plugin/public';
import { EmbeddableAppContext } from '@kbn/presentation-publishing';

import { DASHBOARD_CONTAINER_TYPE } from '..';
import { createExtract, createInject, DashboardContainerInput } from '../../../common';
import { DEFAULT_DASHBOARD_INPUT } from '../../dashboard_constants';
import {
LoadDashboardReturn,
SavedDashboardInput,
} from '../../services/dashboard_content_management_service/types';
import type { DashboardContainer } from './dashboard_container';
import type { DashboardCreationOptions } from '../..';

export type DashboardContainerFactory = EmbeddableFactory<
DashboardContainerInput,
ContainerOutput,
DashboardContainer
>;

export interface DashboardCreationOptions {
getInitialInput?: () => Partial<SavedDashboardInput>;

getIncomingEmbeddable?: () => EmbeddablePackageState | undefined;

useSearchSessionsIntegration?: boolean;
searchSessionSettings?: {
sessionIdToRestore?: string;
sessionIdUrlChangeObservable?: Observable<string | undefined>;
getSearchSessionIdFromURL: () => string | undefined;
removeSessionIdFromUrl: () => void;
createSessionRestorationDataProvider: (
container: DashboardContainer
) => SearchSessionInfoProvider;
};

useControlGroupIntegration?: boolean;
useSessionStorageIntegration?: boolean;

useUnifiedSearchIntegration?: boolean;
unifiedSearchSettings?: { kbnUrlStateStorage: IKbnUrlStateStorage };

validateLoadedSavedObject?: (result: LoadDashboardReturn) => 'valid' | 'invalid' | 'redirected';

isEmbeddedExternally?: boolean;

getEmbeddableAppContext?: (dashboardId?: string) => EmbeddableAppContext;
}

export const dashboardTypeDisplayName = i18n.translate('dashboard.factory.displayName', {
defaultMessage: 'Dashboard',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import { SavedObjectNotFound } from '@kbn/kibana-utils-plugin/common';
import { setStubKibanaServices as setPresentationPanelMocks } from '@kbn/presentation-panel-plugin/public/mocks';
import { BehaviorSubject } from 'rxjs';
import { DashboardContainerFactory } from '..';
import { DASHBOARD_CONTAINER_TYPE } from '../..';
import { DASHBOARD_CONTAINER_TYPE, DashboardCreationOptions } from '../..';
import { embeddableService } from '../../services/kibana_services';
import { DashboardContainer } from '../embeddable/dashboard_container';
import { DashboardCreationOptions } from '../embeddable/dashboard_container_factory';
import { DashboardRenderer } from './dashboard_renderer';

describe('dashboard renderer', () => {
Expand Down Expand Up @@ -53,7 +52,6 @@ describe('dashboard renderer', () => {

test('saved object id & creation options are passed to dashboard factory', async () => {
const options: DashboardCreationOptions = {
useControlGroupIntegration: true,
useSessionStorageIntegration: true,
useUnifiedSearchIntegration: true,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import type { DashboardContainer } from '../embeddable/dashboard_container';
import {
DashboardContainerFactory,
DashboardContainerFactoryDefinition,
DashboardCreationOptions,
} from '../embeddable/dashboard_container_factory';
import type { DashboardCreationOptions } from '../..';
import { DashboardLocatorParams, DashboardRedirect } from '../types';
import { Dashboard404Page } from './dashboard_404';

Expand Down
1 change: 0 additions & 1 deletion src/plugins/dashboard/public/dashboard_container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const LATEST_DASHBOARD_CONTAINER_VERSION = convertNumberToDashboardVersio
export type { DashboardContainer } from './embeddable/dashboard_container';
export {
type DashboardContainerFactory,
type DashboardCreationOptions,
DashboardContainerFactoryDefinition,
} from './embeddable/dashboard_container_factory';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { childrenUnsavedChanges$ } from '@kbn/presentation-containers';
import { omit } from 'lodash';
import { AnyAction, Middleware } from 'redux';
import { combineLatest, debounceTime, skipWhile, startWith, switchMap } from 'rxjs';
import { DashboardContainer, DashboardCreationOptions } from '../..';
import { DashboardContainer } from '../..';
import { DashboardCreationOptions } from '../../..';
import { DashboardContainerInput } from '../../../../common';
import { CHANGE_CHECK_DEBOUNCE } from '../../../dashboard_constants';
import {
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/dashboard/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ export {
DASHBOARD_GRID_COLUMN_COUNT,
PanelPlacementStrategy,
} from './dashboard_constants';
export type { DashboardApi } from './dashboard_api/types';
export type { DashboardApi, DashboardCreationOptions } from './dashboard_api/types';
export {
LazyDashboardRenderer as DashboardRenderer,
DASHBOARD_CONTAINER_TYPE,
type DashboardCreationOptions,
type DashboardLocatorParams,
type IProvidesLegacyPanelPlacementSettings,
} from './dashboard_container';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ async function getCreationOptions(
}

return {
useControlGroupIntegration: true,
getInitialInput: () => ({
viewMode: ViewMode.VIEW,
panels,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export function ServiceDashboards({ checkForEntities = false }: { checkForEntiti
});
return Promise.resolve<DashboardCreationOptions>({
getInitialInput,
useControlGroupIntegration: true,
});
}, [rangeFrom, rangeTo]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export function Dashboards() {
});
return Promise.resolve<DashboardCreationOptions>({
getInitialInput,
useControlGroupIntegration: true,
});
}, [dateRange.from, dateRange.to]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ describe('DashboardRenderer', () => {
filters: undefined,
})
);
expect(options.useControlGroupIntegration).toEqual(true);
});

it('does not render when No Read Permission', () => {
Expand Down
Loading

0 comments on commit 41f3e79

Please sign in to comment.