mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 03:01:21 -04:00
## Summary
Partially addresses https://github.com/elastic/kibana-team/issues/805
Follows https://github.com/elastic/kibana/pull/180003
These changes come up from searching in the code and finding where
certain kinds of deprecated AppEx-SharedUX modules are imported.
**Reviewers: Please interact with critical paths through the UI
components touched in this PR, ESPECIALLY in terms of testing dark mode
and i18n.**
This focuses on code within AppEx-SharedUX. [Reporting changes are
separate](https://github.com/elastic/kibana/pull/).
<img width="1107" alt="image"
src="c0d2ce08
-ac35-45a7-8192-0b2256fceb0e">
### Checklist
Delete any items that are not applicable to this PR.
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
132 lines
4.5 KiB
TypeScript
132 lines
4.5 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
* 2.0.
|
|
*/
|
|
|
|
import { InternalChromeStart } from '@kbn/core-chrome-browser-internal';
|
|
import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from '@kbn/core/public';
|
|
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
|
|
import { ProjectSwitcher, ProjectSwitcherKibanaProvider } from '@kbn/serverless-project-switcher';
|
|
import { ProjectType } from '@kbn/serverless-types';
|
|
import React from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
import { API_SWITCH_PROJECT as projectChangeAPIUrl } from '../common';
|
|
import { ServerlessConfig } from './config';
|
|
import {
|
|
generateManageOrgMembersNavCard,
|
|
manageOrgMembersNavCardName,
|
|
SideNavComponent,
|
|
} from './navigation';
|
|
import {
|
|
ServerlessPluginSetup,
|
|
ServerlessPluginSetupDependencies,
|
|
ServerlessPluginStart,
|
|
ServerlessPluginStartDependencies,
|
|
} from './types';
|
|
|
|
export class ServerlessPlugin
|
|
implements
|
|
Plugin<
|
|
ServerlessPluginSetup,
|
|
ServerlessPluginStart,
|
|
ServerlessPluginSetupDependencies,
|
|
ServerlessPluginStartDependencies
|
|
>
|
|
{
|
|
private readonly config: ServerlessConfig;
|
|
|
|
constructor(private readonly initializerContext: PluginInitializerContext) {
|
|
this.config = this.initializerContext.config.get<ServerlessConfig>();
|
|
}
|
|
|
|
public setup(
|
|
_core: CoreSetup,
|
|
_dependencies: ServerlessPluginSetupDependencies
|
|
): ServerlessPluginSetup {
|
|
return {};
|
|
}
|
|
|
|
public start(
|
|
core: CoreStart,
|
|
dependencies: ServerlessPluginStartDependencies
|
|
): ServerlessPluginStart {
|
|
const { developer } = this.config;
|
|
|
|
if (developer && developer.projectSwitcher && developer.projectSwitcher.enabled) {
|
|
const { currentType } = developer.projectSwitcher;
|
|
|
|
core.chrome.navControls.registerRight({
|
|
order: 500,
|
|
mount: (target) => this.mountProjectSwitcher(target, core, currentType),
|
|
});
|
|
}
|
|
|
|
core.chrome.setChromeStyle('project');
|
|
|
|
// Casting the "chrome.projects" service to an "internal" type: this is intentional to obscure the property from Typescript.
|
|
const { project } = core.chrome as InternalChromeStart;
|
|
const { cloud } = dependencies;
|
|
|
|
if (cloud.serverless.projectName) {
|
|
project.setProjectName(cloud.serverless.projectName);
|
|
}
|
|
project.setCloudUrls(cloud);
|
|
|
|
const activeNavigationNodes$ = project.getActiveNavigationNodes$();
|
|
const navigationTreeUi$ = project.getNavigationTreeUi$();
|
|
|
|
return {
|
|
setSideNavComponentDeprecated: (sideNavigationComponent) =>
|
|
project.setSideNavComponent(sideNavigationComponent),
|
|
initNavigation: (id, navigationTree$, { panelContentProvider, dataTestSubj } = {}) => {
|
|
project.initNavigation(id, navigationTree$);
|
|
project.setSideNavComponent(() => (
|
|
<SideNavComponent
|
|
navProps={{
|
|
navigationTree$: navigationTreeUi$,
|
|
dataTestSubj,
|
|
panelContentProvider,
|
|
}}
|
|
deps={{
|
|
core,
|
|
activeNodes$: activeNavigationNodes$,
|
|
}}
|
|
/>
|
|
));
|
|
},
|
|
setBreadcrumbs: (breadcrumbs, params) => project.setBreadcrumbs(breadcrumbs, params),
|
|
setProjectHome: (homeHref: string) => project.setHome(homeHref),
|
|
getNavigationCards: (roleManagementEnabled, extendCardNavDefinitions) => {
|
|
if (!roleManagementEnabled) return extendCardNavDefinitions;
|
|
|
|
const manageOrgMembersNavCard = generateManageOrgMembersNavCard(cloud.organizationUrl);
|
|
if (extendCardNavDefinitions) {
|
|
extendCardNavDefinitions[manageOrgMembersNavCardName] = manageOrgMembersNavCard;
|
|
return extendCardNavDefinitions;
|
|
}
|
|
return { [manageOrgMembersNavCardName]: manageOrgMembersNavCard };
|
|
},
|
|
};
|
|
}
|
|
|
|
public stop() {}
|
|
|
|
private mountProjectSwitcher(
|
|
targetDomElement: HTMLElement,
|
|
coreStart: CoreStart,
|
|
currentProjectType: ProjectType
|
|
) {
|
|
ReactDOM.render(
|
|
<KibanaRenderContextProvider i18n={coreStart.i18n} theme={coreStart.theme}>
|
|
<ProjectSwitcherKibanaProvider {...{ coreStart, projectChangeAPIUrl }}>
|
|
<ProjectSwitcher {...{ currentProjectType }} />
|
|
</ProjectSwitcherKibanaProvider>
|
|
</KibanaRenderContextProvider>,
|
|
targetDomElement
|
|
);
|
|
|
|
return () => ReactDOM.unmountComponentAtNode(targetDomElement);
|
|
}
|
|
}
|