mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Use dashboard factory directly instead of pulling from registry (#193480)
PR removes dashboard embeddable from embeddable registry. No other application accesses the dashboard embeddable from the embeddable registry so registration is not needed. Plus, once lens embeddable is converted to a react embeddable, then we can remove the legacy embeddable registry prior to refactoring dashboard to not be an embeddable (which will be a large effort and we want to remove the legacy embeddable registry as soon as possible to avoid any one else using it). --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
3dd1ee8ae0
commit
3b6cfb685d
5 changed files with 46 additions and 43 deletions
|
@ -16,6 +16,10 @@ import {
|
|||
} from '../../lib/dashboard_panel_converters';
|
||||
import { DashboardAttributesAndReferences, ParsedDashboardAttributesWithType } from '../../types';
|
||||
import { DashboardAttributes, SavedDashboardPanel } from '../../content_management';
|
||||
import {
|
||||
createExtract,
|
||||
createInject,
|
||||
} from '../../dashboard_container/persistable_state/dashboard_container_references';
|
||||
|
||||
export interface InjectExtractDeps {
|
||||
embeddablePersistableStateService: EmbeddablePersistableStateService;
|
||||
|
@ -45,10 +49,8 @@ export function injectReferences(
|
|||
const parsedAttributes = parseDashboardAttributesWithType(attributes);
|
||||
|
||||
// inject references back into panels via the Embeddable persistable state service.
|
||||
const injectedState = deps.embeddablePersistableStateService.inject(
|
||||
parsedAttributes,
|
||||
references
|
||||
) as ParsedDashboardAttributesWithType;
|
||||
const inject = createInject(deps.embeddablePersistableStateService);
|
||||
const injectedState = inject(parsedAttributes, references) as ParsedDashboardAttributesWithType;
|
||||
const injectedPanels = convertPanelMapToSavedPanels(injectedState.panels);
|
||||
|
||||
const newAttributes = {
|
||||
|
@ -74,11 +76,11 @@ export function extractReferences(
|
|||
);
|
||||
}
|
||||
|
||||
const { references: extractedReferences, state: extractedState } =
|
||||
deps.embeddablePersistableStateService.extract(parsedAttributes) as {
|
||||
references: Reference[];
|
||||
state: ParsedDashboardAttributesWithType;
|
||||
};
|
||||
const extract = createExtract(deps.embeddablePersistableStateService);
|
||||
const { references: extractedReferences, state: extractedState } = extract(parsedAttributes) as {
|
||||
references: Reference[];
|
||||
state: ParsedDashboardAttributesWithType;
|
||||
};
|
||||
const extractedPanels = convertPanelMapToSavedPanels(extractedState.panels);
|
||||
|
||||
const newAttributes = {
|
||||
|
|
|
@ -18,11 +18,12 @@ 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, DashboardCreationOptions } from '../..';
|
||||
import { embeddableService } from '../../services/kibana_services';
|
||||
import { DashboardCreationOptions } from '../..';
|
||||
import { DashboardContainer } from '../embeddable/dashboard_container';
|
||||
import { DashboardRenderer } from './dashboard_renderer';
|
||||
|
||||
jest.mock('../embeddable/dashboard_container_factory', () => ({}));
|
||||
|
||||
describe('dashboard renderer', () => {
|
||||
let mockDashboardContainer: DashboardContainer;
|
||||
let mockDashboardFactory: DashboardContainerFactory;
|
||||
|
@ -38,7 +39,10 @@ describe('dashboard renderer', () => {
|
|||
mockDashboardFactory = {
|
||||
create: jest.fn().mockReturnValue(mockDashboardContainer),
|
||||
} as unknown as DashboardContainerFactory;
|
||||
embeddableService.getEmbeddableFactory = jest.fn().mockReturnValue(mockDashboardFactory);
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
require('../embeddable/dashboard_container_factory').DashboardContainerFactoryDefinition = jest
|
||||
.fn()
|
||||
.mockReturnValue(mockDashboardFactory);
|
||||
setPresentationPanelMocks();
|
||||
});
|
||||
|
||||
|
@ -46,7 +50,6 @@ describe('dashboard renderer', () => {
|
|||
await act(async () => {
|
||||
mountWithIntl(<DashboardRenderer />);
|
||||
});
|
||||
expect(embeddableService.getEmbeddableFactory).toHaveBeenCalledWith(DASHBOARD_CONTAINER_TYPE);
|
||||
expect(mockDashboardFactory.create).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
@ -103,7 +106,10 @@ describe('dashboard renderer', () => {
|
|||
mockDashboardFactory = {
|
||||
create: jest.fn().mockReturnValue(mockErrorEmbeddable),
|
||||
} as unknown as DashboardContainerFactory;
|
||||
embeddableService.getEmbeddableFactory = jest.fn().mockReturnValue(mockDashboardFactory);
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
require('../embeddable/dashboard_container_factory').DashboardContainerFactoryDefinition = jest
|
||||
.fn()
|
||||
.mockReturnValue(mockDashboardFactory);
|
||||
|
||||
let wrapper: ReactWrapper;
|
||||
await act(async () => {
|
||||
|
@ -125,7 +131,10 @@ describe('dashboard renderer', () => {
|
|||
const mockErrorFactory = {
|
||||
create: jest.fn().mockReturnValue(mockErrorEmbeddable),
|
||||
} as unknown as DashboardContainerFactory;
|
||||
embeddableService.getEmbeddableFactory = jest.fn().mockReturnValue(mockErrorFactory);
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
require('../embeddable/dashboard_container_factory').DashboardContainerFactoryDefinition = jest
|
||||
.fn()
|
||||
.mockReturnValue(mockErrorFactory);
|
||||
|
||||
// render the dashboard - it should run into an error and render the error embeddable.
|
||||
let wrapper: ReactWrapper;
|
||||
|
@ -146,7 +155,10 @@ describe('dashboard renderer', () => {
|
|||
const mockSuccessFactory = {
|
||||
create: jest.fn().mockReturnValue(mockSuccessEmbeddable),
|
||||
} as unknown as DashboardContainerFactory;
|
||||
embeddableService.getEmbeddableFactory = jest.fn().mockReturnValue(mockSuccessFactory);
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
require('../embeddable/dashboard_container_factory').DashboardContainerFactoryDefinition = jest
|
||||
.fn()
|
||||
.mockReturnValue(mockSuccessFactory);
|
||||
|
||||
// update the saved object id to trigger another dashboard load.
|
||||
await act(async () => {
|
||||
|
@ -175,7 +187,10 @@ describe('dashboard renderer', () => {
|
|||
const mockErrorFactory = {
|
||||
create: jest.fn().mockReturnValue(mockErrorEmbeddable),
|
||||
} as unknown as DashboardContainerFactory;
|
||||
embeddableService.getEmbeddableFactory = jest.fn().mockReturnValue(mockErrorFactory);
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
require('../embeddable/dashboard_container_factory').DashboardContainerFactoryDefinition = jest
|
||||
.fn()
|
||||
.mockReturnValue(mockErrorFactory);
|
||||
|
||||
// render the dashboard - it should run into an error and render the error embeddable.
|
||||
let wrapper: ReactWrapper;
|
||||
|
@ -238,7 +253,10 @@ describe('dashboard renderer', () => {
|
|||
const mockSuccessFactory = {
|
||||
create: jest.fn().mockReturnValue(mockSuccessEmbeddable),
|
||||
} as unknown as DashboardContainerFactory;
|
||||
embeddableService.getEmbeddableFactory = jest.fn().mockReturnValue(mockSuccessFactory);
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
require('../embeddable/dashboard_container_factory').DashboardContainerFactoryDefinition = jest
|
||||
.fn()
|
||||
.mockReturnValue(mockSuccessFactory);
|
||||
|
||||
let wrapper: ReactWrapper;
|
||||
await act(async () => {
|
||||
|
@ -263,7 +281,10 @@ describe('dashboard renderer', () => {
|
|||
const mockUseMarginFalseFactory = {
|
||||
create: jest.fn().mockReturnValue(mockUseMarginFalseEmbeddable),
|
||||
} as unknown as DashboardContainerFactory;
|
||||
embeddableService.getEmbeddableFactory = jest.fn().mockReturnValue(mockUseMarginFalseFactory);
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
require('../embeddable/dashboard_container_factory').DashboardContainerFactoryDefinition = jest
|
||||
.fn()
|
||||
.mockReturnValue(mockUseMarginFalseFactory);
|
||||
|
||||
let wrapper: ReactWrapper;
|
||||
await act(async () => {
|
||||
|
|
|
@ -20,15 +20,11 @@ import { SavedObjectNotFound } from '@kbn/kibana-utils-plugin/common';
|
|||
import { useStateFromPublishingSubject } from '@kbn/presentation-publishing';
|
||||
import { LocatorPublic } from '@kbn/share-plugin/common';
|
||||
|
||||
import { DASHBOARD_CONTAINER_TYPE } from '..';
|
||||
import { DashboardContainerInput } from '../../../common';
|
||||
import { DashboardApi } from '../../dashboard_api/types';
|
||||
import { embeddableService, screenshotModeService } from '../../services/kibana_services';
|
||||
import type { DashboardContainer } from '../embeddable/dashboard_container';
|
||||
import {
|
||||
DashboardContainerFactory,
|
||||
DashboardContainerFactoryDefinition,
|
||||
} from '../embeddable/dashboard_container_factory';
|
||||
import { DashboardContainerFactoryDefinition } from '../embeddable/dashboard_container_factory';
|
||||
import type { DashboardCreationOptions } from '../..';
|
||||
import { DashboardLocatorParams, DashboardRedirect } from '../types';
|
||||
import { Dashboard404Page } from './dashboard_404';
|
||||
|
@ -91,12 +87,8 @@ export function DashboardRenderer({
|
|||
(async () => {
|
||||
const creationOptions = await getCreationOptions?.();
|
||||
|
||||
const dashboardFactory = embeddableService.getEmbeddableFactory(
|
||||
DASHBOARD_CONTAINER_TYPE
|
||||
) as DashboardContainerFactory & {
|
||||
create: DashboardContainerFactoryDefinition['create'];
|
||||
};
|
||||
const container = await dashboardFactory?.create(
|
||||
const dashboardFactory = new DashboardContainerFactoryDefinition(embeddableService);
|
||||
const container = await dashboardFactory.create(
|
||||
{ id } as unknown as DashboardContainerInput, // Input from creationOptions is used instead.
|
||||
undefined,
|
||||
creationOptions,
|
||||
|
|
|
@ -15,10 +15,7 @@ export const DASHBOARD_CONTAINER_TYPE = 'dashboard';
|
|||
export const LATEST_DASHBOARD_CONTAINER_VERSION = convertNumberToDashboardVersion(LATEST_VERSION);
|
||||
|
||||
export type { DashboardContainer } from './embeddable/dashboard_container';
|
||||
export {
|
||||
type DashboardContainerFactory,
|
||||
DashboardContainerFactoryDefinition,
|
||||
} from './embeddable/dashboard_container_factory';
|
||||
export { type DashboardContainerFactory } from './embeddable/dashboard_container_factory';
|
||||
|
||||
export { LazyDashboardRenderer } from './external_api/lazy_dashboard_renderer';
|
||||
export type { DashboardLocatorParams } from './types';
|
||||
|
|
|
@ -72,7 +72,6 @@ import {
|
|||
LEGACY_DASHBOARD_APP_ID,
|
||||
SEARCH_SESSION_ID,
|
||||
} from './dashboard_constants';
|
||||
import { DashboardContainerFactoryDefinition } from './dashboard_container/embeddable/dashboard_container_factory';
|
||||
import {
|
||||
GetPanelPlacementSettings,
|
||||
registerDashboardPanelPlacementSetting,
|
||||
|
@ -227,14 +226,6 @@ export class DashboardPlugin
|
|||
},
|
||||
});
|
||||
|
||||
core.getStartServices().then(([, deps]) => {
|
||||
const dashboardContainerFactory = new DashboardContainerFactoryDefinition(deps.embeddable);
|
||||
embeddable.registerEmbeddableFactory(
|
||||
dashboardContainerFactory.type,
|
||||
dashboardContainerFactory
|
||||
);
|
||||
});
|
||||
|
||||
this.stopUrlTracking = () => {
|
||||
stopUrlTracker();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue