Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Remote clusters] Fix regression with xpack.remote_clusters.ui.enabled setting #57895

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion x-pack/plugins/remote_clusters/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { PluginInitializerContext } from 'kibana/public';
import { RemoteClustersUIPlugin } from './plugin';

export const plugin = () => new RemoteClustersUIPlugin();
export const plugin = (initializerContext: PluginInitializerContext) =>
new RemoteClustersUIPlugin(initializerContext);
72 changes: 43 additions & 29 deletions x-pack/plugins/remote_clusters/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,64 @@
*/

import { i18n } from '@kbn/i18n';
import { CoreSetup, Plugin, CoreStart } from 'kibana/public';
import { CoreSetup, Plugin, CoreStart, PluginInitializerContext } from 'kibana/public';
import { init as initBreadcrumbs } from './application/services/breadcrumb';
import { init as initDocumentation } from './application/services/documentation';
import { init as initHttp } from './application/services/http';
import { init as initUiMetric } from './application/services/ui_metric';
import { init as initNotification } from './application/services/notification';
import { init as initRedirect } from './application/services/redirect';
import { Dependencies } from './types';
import { Dependencies, ClientConfigType } from './types';

export class RemoteClustersUIPlugin implements Plugin<void, void, Dependencies, any> {
constructor(private readonly initializerContext: PluginInitializerContext) {}

setup(
{ notifications: { toasts }, http, getStartServices }: CoreSetup,
{ management, usageCollection }: Dependencies
) {
const esSection = management.sections.getSection('elasticsearch');

esSection!.registerApp({
id: 'remote_clusters',
title: i18n.translate('xpack.remoteClusters.appTitle', {
defaultMessage: 'Remote Clusters',
}),
mount: async ({ element, setBreadcrumbs }) => {
const [core] = await getStartServices();
const {
i18n: { Context: i18nContext },
docLinks,
fatalErrors,
} = core;

// Initialize services
initBreadcrumbs(setBreadcrumbs);
initDocumentation(docLinks);
initUiMetric(usageCollection);
initNotification(toasts, fatalErrors);
initHttp(http);

const { renderApp } = await import('./application');
return renderApp(element, i18nContext);
},
});
const {
ui: { enabled: isRemoteClustersUiEnabled },
} = this.initializerContext.config.get<ClientConfigType>();

if (isRemoteClustersUiEnabled) {
const esSection = management.sections.getSection('elasticsearch');

esSection!.registerApp({
id: 'remote_clusters',
title: i18n.translate('xpack.remoteClusters.appTitle', {
defaultMessage: 'Remote Clusters',
}),
mount: async ({ element, setBreadcrumbs }) => {
const [core] = await getStartServices();
const {
i18n: { Context: i18nContext },
docLinks,
fatalErrors,
} = core;

// Initialize services
initBreadcrumbs(setBreadcrumbs);
initDocumentation(docLinks);
initUiMetric(usageCollection);
initNotification(toasts, fatalErrors);
initHttp(http);

const { renderApp } = await import('./application');
return renderApp(element, i18nContext);
},
});
}
}

start({ application }: CoreStart) {
initRedirect(application.navigateToApp);
const {
ui: { enabled: isRemoteClustersUiEnabled },
} = this.initializerContext.config.get<ClientConfigType>();

if (isRemoteClustersUiEnabled) {
initRedirect(application.navigateToApp);
}
}

stop() {}
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/remote_clusters/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export interface Dependencies {
usageCollection: UsageCollectionSetup;
}

export interface ClientConfigType {
ui: {
enabled: boolean;
};
}

export { RegisterManagementAppArgs };

export { I18nStart };
5 changes: 4 additions & 1 deletion x-pack/plugins/remote_clusters/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import { PluginConfigDescriptor } from 'kibana/server';

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
ui: schema.object({
enabled: schema.boolean({ defaultValue: true }),
}),
});

export type ConfigType = TypeOf<typeof configSchema>;

export const config: PluginConfigDescriptor<ConfigType> = {
schema: configSchema,
exposeToBrowser: {
enabled: true,
ui: true,
},
};