Skip to content

Commit

Permalink
integrate registrations with plugin lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon committed Feb 6, 2024
1 parent 0ca862b commit e61ea51
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 69 deletions.
26 changes: 13 additions & 13 deletions src/plugins/saved_search/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ export class SavedSearchPublicPlugin

expressions.registerType(kibanaContext);

registerSavedObjectToPanelMethod<SavedSearchAttributes, SearchByValueInput>(
SavedSearchType,
(savedObject) => {
if (!savedObject.managed) {
return { savedObjectId: savedObject.id };
}

return {
attributes: savedObjectToEmbeddableAttributes(savedObject),
};
}
);

return {};
}

Expand Down Expand Up @@ -149,16 +162,3 @@ export class SavedSearchPublicPlugin
};
}
}

registerSavedObjectToPanelMethod<SavedSearchAttributes, SearchByValueInput>(
SavedSearchType,
(savedObject) => {
if (!savedObject.managed) {
return { savedObjectId: savedObject.id };
}

return {
attributes: savedObjectToEmbeddableAttributes(savedObject),
};
}
);
62 changes: 31 additions & 31 deletions src/plugins/visualizations/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,37 @@ export class VisualizationsPlugin
name: 'Visualize Library',
});

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 Down Expand Up @@ -474,34 +505,3 @@ export class VisualizationsPlugin
}
}
}

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
};
}
);
30 changes: 15 additions & 15 deletions x-pack/plugins/lens/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,21 @@ export class LensPlugin {
() => startServices().plugins.data.nowProvider.get()
);

registerSavedObjectToPanelMethod<LensSavedObjectAttributes, LensByValueInput>(
CONTENT_ID,
(savedObject) => {
if (!savedObject.managed) {
return { savedObjectId: savedObject.id };
}

const panel = {
attributes: savedObjectToEmbeddableAttributes(savedObject),
};

return panel;
}
);

const getPresentationUtilContext = () =>
startServices().plugins.presentationUtil.ContextProvider;

Expand Down Expand Up @@ -723,18 +738,3 @@ export class LensPlugin {

stop() {}
}

registerSavedObjectToPanelMethod<LensSavedObjectAttributes, LensByValueInput>(
CONTENT_ID,
(savedObject) => {
if (!savedObject.managed) {
return { savedObjectId: savedObject.id };
}

const panel = {
attributes: savedObjectToEmbeddableAttributes(savedObject),
};

return panel;
}
);
20 changes: 10 additions & 10 deletions x-pack/plugins/maps/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ export class MapsPlugin
name: APP_NAME,
});

registerSavedObjectToPanelMethod<MapAttributes, MapByValueInput>(CONTENT_ID, (savedObject) => {
if (!savedObject.managed) {
return { savedObjectId: savedObject.id };
}

return {
attributes: savedObjectToEmbeddableAttributes(savedObject),
};
});

setupLensChoroplethChart(core, plugins.expressions, plugins.lens);

// register wrapper around legacy tile_map and region_map visualizations
Expand Down Expand Up @@ -259,13 +269,3 @@ export class MapsPlugin
};
}
}

registerSavedObjectToPanelMethod<MapAttributes, MapByValueInput>(CONTENT_ID, (savedObject) => {
if (!savedObject.managed) {
return { savedObjectId: savedObject.id };
}

return {
attributes: savedObjectToEmbeddableAttributes(savedObject),
};
});

0 comments on commit e61ea51

Please sign in to comment.