Skip to content

Commit

Permalink
Revert "[Embeddables Rebuild] Migrate Visualize (elastic#183197)"
Browse files Browse the repository at this point in the history
This reverts commit ee28e20.
  • Loading branch information
nreese committed Sep 3, 2024
1 parent 913b8f3 commit aea0e87
Show file tree
Hide file tree
Showing 42 changed files with 126 additions and 1,605 deletions.
13 changes: 6 additions & 7 deletions packages/presentation/presentation_containers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,23 @@ export {
type CanDuplicatePanels,
type CanExpandPanels,
} from './interfaces/panel_management';
export {
canTrackContentfulRender,
type TrackContentfulRender,
type TracksQueryPerformance,
} from './interfaces/performance_trackers';
export {
apiIsPresentationContainer,
combineCompatibleChildrenApis,
getContainerParentFromAPI,
listenForCompatibleApi,
combineCompatibleChildrenApis,
type PanelPackage,
type PresentationContainer,
} from './interfaces/presentation_container';
export { apiPublishesSettings, type PublishesSettings } from './interfaces/publishes_settings';
export {
apiHasSerializableState,
type HasSerializableState,
type HasSnapshottableState,
type SerializedPanelState,
} from './interfaces/serialized_state';
export { tracksOverlays, type TracksOverlays } from './interfaces/tracks_overlays';
export {
canTrackContentfulRender,
type TrackContentfulRender,
type TracksQueryPerformance,
} from './interfaces/performance_trackers';
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"@kbn/es-query",
"@kbn/data-views-plugin",
"@kbn/expressions-plugin",
"@kbn/core-execution-context-common"
"@kbn/core-execution-context-common",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ export type {
} from './latest';

export * as VisualizationV1 from './v1';
export type { Reference } from './v1';
4 changes: 1 addition & 3 deletions src/plugins/visualizations/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
BUCKET_TYPES,
} from '@kbn/data-plugin/common';
import type { SerializedFieldFormat } from '@kbn/field-formats-plugin/common';
import { Reference } from './content_management';

export interface VisParams {
[key: string]: any;
Expand All @@ -37,9 +36,8 @@ export type {
export interface SerializedVisData {
expression?: string;
aggs: AggConfigSerialized[];
searchSource: SerializedSearchSourceFields & { indexRefName?: string };
searchSource: SerializedSearchSourceFields;
savedSearchId?: string;
savedSearchRefName?: string | Reference;
}

export interface SerializedVis<T = VisParams> {
Expand Down
12 changes: 8 additions & 4 deletions src/plugins/visualizations/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@
"savedObjectsFinder",
"savedObjectsManagement",
"savedSearch",
"contentManagement"
"contentManagement",
],
"optionalPlugins": [
"home",
"share",
"spaces",
"savedObjectsTaggingOss",
"serverless",
"noDataPage",
"embeddableEnhanced"
"noDataPage"
],
"requiredBundles": [
"kibanaUtils",
"kibanaReact",
"charts",
"savedObjects",
],
"requiredBundles": ["kibanaUtils", "kibanaReact", "charts", "savedObjects"],
"extraPublicDirs": [
"common/constants",
"common/utils",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import { urlFor } from '../utils/saved_visualize_utils';
import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory';
import { createVisualizeEmbeddableAsync } from './visualize_embeddable_async';

/** @deprecated
* VisualizeEmbeddable is no longer registered with the legacy embeddable system and is only
* used within the visualize editor.
*/
export const createVisEmbeddableFromObject =
(deps: VisualizeEmbeddableFactoryDeps) =>
async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ export type VisualizeSavedObjectAttributes = SavedObjectAttributes & {
export type VisualizeByValueInput = { attributes: VisualizeSavedObjectAttributes } & VisualizeInput;
export type VisualizeByReferenceInput = SavedObjectEmbeddableInput & VisualizeInput;

/** @deprecated
* VisualizeEmbeddable is no longer registered with the legacy embeddable system and is only
* used within the visualize editor.
*/
export class VisualizeEmbeddable
extends Embeddable<VisualizeInput, VisualizeOutput>
implements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

import type { VisualizeEmbeddable as VisualizeEmbeddableType } from './visualize_embeddable';

/** @deprecated
* VisualizeEmbeddable is no longer registered with the legacy embeddable system and is only
* used within the visualize editor.
*/
export const createVisualizeEmbeddableAsync = async (
...args: ConstructorParameters<typeof VisualizeEmbeddableType>
) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ export interface VisualizeEmbeddableFactoryDeps {
>;
}

/** @deprecated
* VisualizeEmbeddable is no longer registered with the legacy embeddable system and is only
* used within the visualize editor.
*/
export class VisualizeEmbeddableFactory
implements
EmbeddableFactoryDefinition<
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/visualizations/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function plugin(initializerContext: PluginInitializerContext) {
export { TypesService } from './vis_types/types_service';
export {
apiHasVisualizeConfig,
VISUALIZE_EMBEDDABLE_TYPE,
VIS_EVENT_TO_TRIGGER,
COMMON_VISUALIZATION_GROUPING,
} from './embeddable';
Expand All @@ -37,13 +38,12 @@ export type {
VisualizationClient,
SerializableAttributes,
} from './vis_types';
export type { VisualizeEditorInput } from './react_embeddable/types';
export type { Vis, SerializedVis, SerializedVisData, VisData } from './vis';
export type VisualizeEmbeddableFactoryContract = PublicContract<VisualizeEmbeddableFactory>;
export type VisualizeEmbeddableContract = PublicContract<VisualizeEmbeddable>;
export type { VisualizeInput, VisualizeEmbeddable, HasVisualizeConfig } from './embeddable';
export type { SchemaConfig } from '../common/types';
export { updateOldState } from './legacy/vis_update_state';
export type { VisualizeInput, VisualizeEmbeddable, HasVisualizeConfig } from './embeddable';
export type { PersistedState } from './persisted_state';
export type {
ISavedVis,
Expand All @@ -63,7 +63,6 @@ export {
LegendSize,
LegendSizeToPixels,
DEFAULT_LEGEND_SIZE,
VISUALIZE_EMBEDDABLE_TYPE,
} from '../common/constants';
export type { SavedVisState, VisParams, Dimension } from '../common';
export { prepareLogTable, XYCurveTypes } from '../common';
Expand Down
1 change: 1 addition & 0 deletions src/plugins/visualizations/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const createInstance = async () => {
application: applicationServiceMock.createStartContract(),
embeddable: embeddablePluginMock.createStartContract(),
spaces: spacesPluginMock.createStartContract(),
getAttributeService: jest.fn(),
savedObjectsClient: coreMock.createStart().savedObjects.client,
savedObjects: savedObjectsPluginMock.createStartContract(),
savedObjectsTaggingOss: savedObjectTaggingOssPluginMock.createStart(),
Expand Down
84 changes: 44 additions & 40 deletions src/plugins/visualizations/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ import {
ContentManagementPublicStart,
} from '@kbn/content-management-plugin/public';
import type { NoDataPagePluginStart } from '@kbn/no-data-page-plugin/public';
import { EmbeddableEnhancedPluginStart } from '@kbn/embeddable-enhanced-plugin/public';

import type { TypesSetup, TypesStart } from './vis_types';
import type { VisualizeServices } from './visualize_app/types';
import {
Expand All @@ -85,6 +83,11 @@ import { xyDimension as xyDimensionExpressionFunction } from '../common/expressi
import { visDimension as visDimensionExpressionFunction } from '../common/expression_functions/vis_dimension';
import { range as rangeExpressionFunction } from '../common/expression_functions/range';
import { TypesService } from './vis_types/types_service';
import {
createVisEmbeddableFromObject,
VISUALIZE_EMBEDDABLE_TYPE,
VisualizeEmbeddableFactory,
} from './embeddable';
import {
setUISettings,
setTypes,
Expand Down Expand Up @@ -112,20 +115,18 @@ import {
setSavedObjectsManagement,
setContentManagement,
setSavedSearch,
setDataViews,
setInspector,
getTypes,
} from './services';
import { VisualizeConstants, VISUALIZE_EMBEDDABLE_TYPE } from '../common/constants';
import { VisualizeConstants } from '../common/constants';
import { EditInLensAction } from './actions/edit_in_lens_action';
import { ListingViewRegistry } from './types';
import { ListingViewRegistry, SerializedVis } from './types';
import {
LATEST_VERSION,
CONTENT_ID,
VisualizationSavedObjectAttributes,
} from '../common/content_management';
import { SerializedVisData } from '../common';
import { VisualizeByValueInput } from './embeddable/visualize_embeddable';
import { AddAggVisualizationPanelAction } from './actions/add_agg_vis_action';
import { VisualizeSerializedState } from './react_embeddable/types';

/**
* Interface for this plugin's returned setup/start contracts.
Expand Down Expand Up @@ -162,6 +163,7 @@ export interface VisualizationsStartDeps {
inspector: InspectorStart;
uiActions: UiActionsStart;
application: ApplicationStart;
getAttributeService: EmbeddableStart['getAttributeService'];
navigation: NavigationStart;
presentationUtil: PresentationUtilPluginStart;
savedObjects: SavedObjectsStart;
Expand All @@ -179,7 +181,6 @@ export interface VisualizationsStartDeps {
contentManagement: ContentManagementPublicStart;
serverless?: ServerlessPluginStart;
noDataPage?: NoDataPagePluginStart;
embeddableEnhanced?: EmbeddableEnhancedPluginStart;
}

/**
Expand Down Expand Up @@ -307,7 +308,6 @@ export class VisualizationsPlugin
* this should be replaced to use only scoped history after moving legacy apps to browser routing
*/
const history = createHashHistory();
const { createVisEmbeddableFromObject } = await import('./embeddable');
const services: VisualizeServices = {
...coreStart,
history,
Expand All @@ -332,7 +332,6 @@ export class VisualizationsPlugin
embeddable: pluginsStart.embeddable,
stateTransferService: pluginsStart.embeddable.getStateTransfer(),
setActiveUrl,
/** @deprecated */
createVisEmbeddableFromObject: createVisEmbeddableFromObject({ start }),
scopedHistory: params.history,
restorePreviousUrl,
Expand Down Expand Up @@ -401,31 +400,8 @@ export class VisualizationsPlugin
uiActions.registerTrigger(dashboardVisualizationPanelTrigger);
const editInLensAction = new EditInLensAction(data.query.timefilter.timefilter);
uiActions.addTriggerAction(CONTEXT_MENU_TRIGGER, editInLensAction);
embeddable.registerReactEmbeddableFactory(VISUALIZE_EMBEDDABLE_TYPE, async () => {
const {
plugins: { embeddable: embeddableStart, embeddableEnhanced: embeddableEnhancedStart },
} = start();

const { getVisualizeEmbeddableFactory } = await import('./react_embeddable');
return getVisualizeEmbeddableFactory({ embeddableStart, embeddableEnhancedStart });
});
embeddable.registerReactEmbeddableSavedObject<VisualizationSavedObjectAttributes>({
onAdd: (container, savedObject) => {
container.addNewPanel<VisualizeSerializedState>({
panelType: VISUALIZE_EMBEDDABLE_TYPE,
initialState: { savedObjectId: savedObject.id },
});
},
embeddableType: VISUALIZE_EMBEDDABLE_TYPE,
savedObjectType: VISUALIZE_EMBEDDABLE_TYPE,
savedObjectName: i18n.translate('visualizations.visualizeSavedObjectName', {
defaultMessage: 'Visualization',
}),
getIconForSavedObject: (savedObject) => {
const visState = JSON.parse(savedObject.attributes.visState ?? '{}');
return getTypes().get(visState.type)?.icon ?? '';
},
});
const embeddableFactory = new VisualizeEmbeddableFactory({ start });
embeddable.registerEmbeddableFactory(VISUALIZE_EMBEDDABLE_TYPE, embeddableFactory);

contentManagement.registry.register({
id: CONTENT_ID,
Expand All @@ -435,6 +411,37 @@ export class VisualizationsPlugin
name: 'Visualize Library',
});

embeddable.registerSavedObjectToPanelMethod<
VisualizationSavedObjectAttributes,
VisualizeByValueInput
>(CONTENT_ID, (savedObject) => {
const visState = savedObject.attributes.visState;

// not sure if visState actually is ever undefined, but following the type
if (!savedObject.managed || !visState) {
return {
savedObjectId: savedObject.id,
};
}

// data is not always defined, so I added a default value since the extract
// routine in the embeddable factory expects it to be there
const savedVis = JSON.parse(visState) as Omit<SerializedVis, 'data'> & {
data?: SerializedVisData;
};

if (!savedVis.data) {
savedVis.data = {
searchSource: {},
aggs: [],
};
}

return {
savedVis: savedVis as SerializedVis, // now we're sure we have "data" prop
};
});

return {
...this.types.setup(),
visEditorsRegistry,
Expand All @@ -449,15 +456,14 @@ export class VisualizationsPlugin
expressions,
uiActions,
embeddable,
savedObjects,
spaces,
savedObjectsTaggingOss,
fieldFormats,
usageCollection,
savedObjectsManagement,
contentManagement,
savedSearch,
dataViews,
inspector,
}: VisualizationsStartDeps
): VisualizationsStart {
const types = this.types.start();
Expand All @@ -482,8 +488,6 @@ export class VisualizationsPlugin
setSavedObjectsManagement(savedObjectsManagement);
setContentManagement(contentManagement);
setSavedSearch(savedSearch);
setDataViews(dataViews);
setInspector(inspector);

if (spaces) {
setSpaces(spaces);
Expand Down

This file was deleted.

Loading

0 comments on commit aea0e87

Please sign in to comment.