Skip to content

Commit

Permalink
adding context to registry provider
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jun 11, 2020
1 parent cc03fa5 commit fe126ac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
14 changes: 9 additions & 5 deletions x-pack/plugins/apm/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
pluginSetupDeps.home.featureCatalogue.register(featureCatalogueEntry);

if (plugins.observability) {
plugins.observability.dataAccess.registerProvider(
this.initializerContext.opaqueId,
'apm',
getObservabilityChartData
);
plugins.observability.dataAccess.registerProvider({
pluginOpaqueId: this.initializerContext.opaqueId,
dataType: 'apm',
handler: getObservabilityChartData,
providedContext: {
licensing: plugins.licensing,
home: plugins.home,
},
});
}

core.application.register({
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/observability/public/data_access_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ export class ObservabilityDataAccessService implements Plugin<Setup, void> {
this.contextContainer = core.context.createContextContainer();

const api: Setup = {
registerProvider: (pluginOpaqueId, dataType, handler) => {
registerProvider: ({ pluginOpaqueId, dataType, handler, providedContext }) => {
if (!this.contextContainer) {
throw new Error("Context container wasn't defined");
}
if (providedContext) {
this.contextContainer!.registerContext(pluginOpaqueId, dataType, () => providedContext);
}

this.dataProviders.set(
dataType,
this.contextContainer.createHandler(pluginOpaqueId, handler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ export type DataAccessHandlerProvider = (
) => ReturnType<ChartDataFetcher>;

export interface Setup {
registerProvider: (
pluginOpaqueId: symbol,
dataType: string,
handler: DataAccessHandlerProvider
) => void;
registerProvider: ({
pluginOpaqueId,
dataType,
handler,
providedContext,
}: {
pluginOpaqueId: symbol;
dataType: string;
handler: DataAccessHandlerProvider;
providedContext?: Record<string, unknown>;
}) => void;
registerContext: (
pluginOpaqueId: symbol,
contextDataType: string,
Expand Down

0 comments on commit fe126ac

Please sign in to comment.