mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[dashboard] decouple DashboardCreationOptions from DashboardContainer (#194875)
PR decouples `DashboardCreationOptions` type from `DashboardContainer` and moves `DashboardCreationOptions` type into dashboard_api folder. `useControlGroupIntegration` removed from `DashboardCreationOptions` type since its no longer used. --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
afb671f561
commit
ecc7d4e2e6
19 changed files with 80 additions and 88 deletions
|
@ -68,7 +68,6 @@ export const DashboardWithControlsExample = ({ dataView }: { dataView: DataView
|
|||
});
|
||||
|
||||
return {
|
||||
useControlGroupIntegration: true,
|
||||
getInitialInput: () => ({
|
||||
timeRange: { from: 'now-30d', to: 'now' },
|
||||
viewMode: ViewMode.VIEW,
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
TracksOverlays,
|
||||
} from '@kbn/presentation-containers';
|
||||
import {
|
||||
EmbeddableAppContext,
|
||||
HasAppContext,
|
||||
HasType,
|
||||
PublishesDataViews,
|
||||
|
@ -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 &
|
||||
|
|
|
@ -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 {
|
||||
|
@ -143,7 +142,6 @@ export function DashboardApp({
|
|||
embeddableService.getStateTransfer().getIncomingEmbeddablePackage(DASHBOARD_APP_ID, true),
|
||||
|
||||
// integrations
|
||||
useControlGroupIntegration: true,
|
||||
useSessionStorageIntegration: true,
|
||||
useUnifiedSearchIntegration: true,
|
||||
unifiedSearchSettings: {
|
||||
|
|
|
@ -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) => {
|
||||
|
@ -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 }),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -96,6 +93,8 @@ function getLocatorParams({
|
|||
: undefined,
|
||||
panels: savedObjectId
|
||||
? undefined
|
||||
: (convertPanelMapToSavedPanels(panels) as DashboardLocatorParams['panels']),
|
||||
: (convertPanelMapToSavedPanels(
|
||||
dashboardApi.panels$.value
|
||||
) as DashboardLocatorParams['panels']),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -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[];
|
||||
|
|
|
@ -8,29 +8,20 @@
|
|||
*/
|
||||
|
||||
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,
|
||||
|
@ -38,35 +29,6 @@ export type DashboardContainerFactory = EmbeddableFactory<
|
|||
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',
|
||||
});
|
||||
|
|
|
@ -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', () => {
|
||||
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -82,7 +82,6 @@ async function getCreationOptions(
|
|||
}
|
||||
|
||||
return {
|
||||
useControlGroupIntegration: true,
|
||||
getInitialInput: () => ({
|
||||
viewMode: ViewMode.VIEW,
|
||||
panels,
|
||||
|
|
|
@ -103,7 +103,6 @@ export function ServiceDashboards({ checkForEntities = false }: { checkForEntiti
|
|||
});
|
||||
return Promise.resolve<DashboardCreationOptions>({
|
||||
getInitialInput,
|
||||
useControlGroupIntegration: true,
|
||||
});
|
||||
}, [rangeFrom, rangeTo]);
|
||||
|
||||
|
|
|
@ -137,7 +137,6 @@ export function Dashboards() {
|
|||
});
|
||||
return Promise.resolve<DashboardCreationOptions>({
|
||||
getInitialInput,
|
||||
useControlGroupIntegration: true,
|
||||
});
|
||||
}, [dateRange.from, dateRange.to]);
|
||||
|
||||
|
|
|
@ -62,7 +62,6 @@ describe('DashboardRenderer', () => {
|
|||
filters: undefined,
|
||||
})
|
||||
);
|
||||
expect(options.useControlGroupIntegration).toEqual(true);
|
||||
});
|
||||
|
||||
it('does not render when No Read Permission', () => {
|
||||
|
|
|
@ -108,7 +108,6 @@ const DashboardRendererComponent = ({
|
|||
const getCreationOptions: () => Promise<DashboardCreationOptions> = useCallback(() => {
|
||||
return Promise.resolve({
|
||||
useSessionStorageIntegration: true,
|
||||
useControlGroupIntegration: true,
|
||||
getInitialInput: () => {
|
||||
return initialInput.value;
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue