mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* export flatten types from the root * add Chrome prefix for chrome types * export types for server services * remove comment * cleanup CoreSetup types * rename to setup * Apply @eliperelman suggestions from code review Co-Authored-By: restrry <restrry@gmail.com>
This commit is contained in:
parent
0d4bc9ff2b
commit
7f39e31739
24 changed files with 87 additions and 68 deletions
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { Brand, Breadcrumb, ChromeService, ChromeSetup } from './chrome_service';
|
||||
import { ChromeBrand, ChromeBreadcrumb, ChromeService, ChromeSetup } from './chrome_service';
|
||||
|
||||
const createSetupContractMock = () => {
|
||||
const setupContract: jest.Mocked<ChromeSetup> = {
|
||||
|
@ -35,11 +35,11 @@ const createSetupContractMock = () => {
|
|||
getHelpExtension$: jest.fn(),
|
||||
setHelpExtension: jest.fn(),
|
||||
};
|
||||
setupContract.getBrand$.mockReturnValue(new BehaviorSubject({} as Brand));
|
||||
setupContract.getBrand$.mockReturnValue(new BehaviorSubject({} as ChromeBrand));
|
||||
setupContract.getIsVisible$.mockReturnValue(new BehaviorSubject(false));
|
||||
setupContract.getIsCollapsed$.mockReturnValue(new BehaviorSubject(false));
|
||||
setupContract.getApplicationClasses$.mockReturnValue(new BehaviorSubject(['class-name']));
|
||||
setupContract.getBreadcrumbs$.mockReturnValue(new BehaviorSubject([{} as Breadcrumb]));
|
||||
setupContract.getBreadcrumbs$.mockReturnValue(new BehaviorSubject([{} as ChromeBreadcrumb]));
|
||||
setupContract.getHelpExtension$.mockReturnValue(new BehaviorSubject(undefined));
|
||||
return setupContract;
|
||||
};
|
||||
|
|
|
@ -32,18 +32,18 @@ function isEmbedParamInHash() {
|
|||
return Boolean(query.embed);
|
||||
}
|
||||
|
||||
export interface Brand {
|
||||
export interface ChromeBrand {
|
||||
logo?: string;
|
||||
smallLogo?: string;
|
||||
}
|
||||
|
||||
export interface Breadcrumb {
|
||||
export interface ChromeBreadcrumb {
|
||||
text: string;
|
||||
href?: string;
|
||||
'data-test-subj'?: string;
|
||||
}
|
||||
|
||||
export type HelpExtension = (element: HTMLDivElement) => (() => void);
|
||||
export type ChromeHelpExtension = (element: HTMLDivElement) => (() => void);
|
||||
|
||||
interface ConstructorParams {
|
||||
browserSupportsCsp: boolean;
|
||||
|
@ -65,12 +65,12 @@ export class ChromeService {
|
|||
public setup({ injectedMetadata, notifications }: SetupDeps) {
|
||||
const FORCE_HIDDEN = isEmbedParamInHash();
|
||||
|
||||
const brand$ = new Rx.BehaviorSubject<Brand>({});
|
||||
const brand$ = new Rx.BehaviorSubject<ChromeBrand>({});
|
||||
const isVisible$ = new Rx.BehaviorSubject(true);
|
||||
const isCollapsed$ = new Rx.BehaviorSubject(!!localStorage.getItem(IS_COLLAPSED_KEY));
|
||||
const applicationClasses$ = new Rx.BehaviorSubject<Set<string>>(new Set());
|
||||
const helpExtension$ = new Rx.BehaviorSubject<HelpExtension | undefined>(undefined);
|
||||
const breadcrumbs$ = new Rx.BehaviorSubject<Breadcrumb[]>([]);
|
||||
const helpExtension$ = new Rx.BehaviorSubject<ChromeHelpExtension | undefined>(undefined);
|
||||
const breadcrumbs$ = new Rx.BehaviorSubject<ChromeBreadcrumb[]>([]);
|
||||
|
||||
if (!this.browserSupportsCsp && injectedMetadata.getCspConfig().warnLegacyBrowsers) {
|
||||
notifications.toasts.addWarning(
|
||||
|
@ -95,7 +95,7 @@ export class ChromeService {
|
|||
* })
|
||||
*
|
||||
*/
|
||||
setBrand: (brand: Brand) => {
|
||||
setBrand: (brand: ChromeBrand) => {
|
||||
brand$.next(
|
||||
Object.freeze({
|
||||
logo: brand.logo,
|
||||
|
@ -179,7 +179,7 @@ export class ChromeService {
|
|||
/**
|
||||
* Override the current set of breadcrumbs
|
||||
*/
|
||||
setBreadcrumbs: (newBreadcrumbs: Breadcrumb[]) => {
|
||||
setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => {
|
||||
breadcrumbs$.next(newBreadcrumbs);
|
||||
},
|
||||
|
||||
|
@ -191,7 +191,7 @@ export class ChromeService {
|
|||
/**
|
||||
* Override the current set of breadcrumbs
|
||||
*/
|
||||
setHelpExtension: (helpExtension?: HelpExtension) => {
|
||||
setHelpExtension: (helpExtension?: ChromeHelpExtension) => {
|
||||
helpExtension$.next(helpExtension);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -17,4 +17,10 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
export { Breadcrumb, ChromeService, ChromeSetup, Brand, HelpExtension } from './chrome_service';
|
||||
export {
|
||||
ChromeBreadcrumb,
|
||||
ChromeService,
|
||||
ChromeSetup,
|
||||
ChromeBrand,
|
||||
ChromeHelpExtension,
|
||||
} from './chrome_service';
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
*/
|
||||
|
||||
import { BasePathSetup } from './base_path';
|
||||
import { ChromeSetup } from './chrome';
|
||||
import { ChromeBrand, ChromeBreadcrumb, ChromeHelpExtension, ChromeSetup } from './chrome';
|
||||
import { FatalErrorsSetup } from './fatal_errors';
|
||||
import { HttpSetup } from './http';
|
||||
import { I18nSetup } from './i18n';
|
||||
import { InjectedMetadataSetup } from './injected_metadata';
|
||||
import { NotificationsSetup } from './notifications';
|
||||
import { UiSettingsSetup } from './ui_settings';
|
||||
import { InjectedMetadataParams, InjectedMetadataSetup } from './injected_metadata';
|
||||
import { NotificationsSetup, Toast, ToastInput, ToastsSetup } from './notifications';
|
||||
import { UiSettingsClient, UiSettingsSetup, UiSettingsState } from './ui_settings';
|
||||
|
||||
export { CoreSystem } from './core_system';
|
||||
|
||||
|
@ -38,3 +38,23 @@ export interface CoreSetup {
|
|||
uiSettings: UiSettingsSetup;
|
||||
chrome: ChromeSetup;
|
||||
}
|
||||
|
||||
export {
|
||||
BasePathSetup,
|
||||
HttpSetup,
|
||||
FatalErrorsSetup,
|
||||
I18nSetup,
|
||||
ChromeSetup,
|
||||
ChromeBreadcrumb,
|
||||
ChromeBrand,
|
||||
ChromeHelpExtension,
|
||||
InjectedMetadataSetup,
|
||||
InjectedMetadataParams,
|
||||
NotificationsSetup,
|
||||
Toast,
|
||||
ToastInput,
|
||||
ToastsSetup,
|
||||
UiSettingsClient,
|
||||
UiSettingsState,
|
||||
UiSettingsSetup,
|
||||
};
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { ElasticsearchServiceSetup } from './elasticsearch';
|
||||
import { HttpServiceSetup } from './http';
|
||||
import { PluginsServiceSetup } from './plugins';
|
||||
|
||||
export { bootstrap } from './bootstrap';
|
||||
export { CallAPIOptions, ClusterClient } from './elasticsearch';
|
||||
|
@ -26,3 +29,9 @@ export {
|
|||
PluginName,
|
||||
PluginSetupContext,
|
||||
} from './plugins';
|
||||
|
||||
export interface CoreSetup {
|
||||
http: HttpServiceSetup;
|
||||
elasticsearch: ElasticsearchServiceSetup;
|
||||
plugins: PluginsServiceSetup;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
export { PluginsService } from './plugins_service';
|
||||
export { PluginsService, PluginsServiceSetup } from './plugins_service';
|
||||
|
||||
/** @internal */
|
||||
export { isNewPlatformPlugin } from './discovery';
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { BasePathSetup } from '../../../../../core/public/base_path';
|
||||
import { BasePathSetup } from '../../../../../core/public';
|
||||
let newPlatformBasePath: BasePathSetup;
|
||||
|
||||
export function __newPlatformInit__(instance: BasePathSetup) {
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
import { IRootScopeService } from 'angular';
|
||||
import { fatalError } from 'ui/notify/fatal_error';
|
||||
import { Breadcrumb, ChromeSetup } from '../../../../../core/public/chrome';
|
||||
export { Breadcrumb };
|
||||
import { ChromeBreadcrumb, ChromeSetup } from '../../../../../core/public';
|
||||
export type Breadcrumb = ChromeBreadcrumb;
|
||||
|
||||
export type BreadcrumbsApi = ReturnType<typeof createBreadcrumbsApi>['breadcrumbs'];
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
import * as Rx from 'rxjs';
|
||||
import { ChromeSetup } from '../../../../../core/public/chrome';
|
||||
import { ChromeSetup } from '../../../../../core/public';
|
||||
|
||||
let newPlatformChrome: ChromeSetup;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
import { IRootScopeService } from 'angular';
|
||||
|
||||
import { ChromeSetup, HelpExtension } from '../../../../../core/public/chrome';
|
||||
import { ChromeHelpExtension, ChromeSetup } from '../../../../../core/public';
|
||||
|
||||
let newPlatformChrome: ChromeSetup;
|
||||
export function __newPlatformInit__(instance: ChromeSetup) {
|
||||
|
@ -31,7 +31,7 @@ export function __newPlatformInit__(instance: ChromeSetup) {
|
|||
}
|
||||
|
||||
export type HelpExtensionApi = ReturnType<typeof createHelpExtensionApi>['helpExtension'];
|
||||
export { HelpExtension };
|
||||
export type HelpExtension = ChromeHelpExtension;
|
||||
|
||||
function createHelpExtensionApi() {
|
||||
/**
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
import { cloneDeep } from 'lodash';
|
||||
import { InjectedMetadataSetup } from '../../../../../core/public/injected_metadata';
|
||||
import { InjectedMetadataSetup } from '../../../../../core/public';
|
||||
|
||||
let newPlatformInjectedVars: InjectedMetadataSetup;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
import * as Rx from 'rxjs';
|
||||
|
||||
import { Brand, ChromeSetup } from '../../../../../core/public/chrome';
|
||||
import { ChromeBrand, ChromeSetup } from '../../../../../core/public';
|
||||
|
||||
let newPlatformChrome: ChromeSetup;
|
||||
|
||||
|
@ -32,18 +32,18 @@ export function __newPlatformInit__(instance: ChromeSetup) {
|
|||
}
|
||||
|
||||
export function initChromeThemeApi(chrome: { [key: string]: any }) {
|
||||
const brandCache$ = new Rx.BehaviorSubject<Brand>({});
|
||||
const brandCache$ = new Rx.BehaviorSubject<ChromeBrand>({});
|
||||
newPlatformChrome.getBrand$().subscribe(brandCache$);
|
||||
|
||||
const applicationClassesCache$ = new Rx.BehaviorSubject<string[]>([]);
|
||||
newPlatformChrome.getApplicationClasses$().subscribe(applicationClassesCache$);
|
||||
|
||||
chrome.setBrand = (brand: Brand) => {
|
||||
chrome.setBrand = (brand: ChromeBrand) => {
|
||||
newPlatformChrome.setBrand(brand);
|
||||
return chrome;
|
||||
};
|
||||
|
||||
chrome.getBrand = (key: keyof Brand) => {
|
||||
chrome.getBrand = (key: keyof ChromeBrand) => {
|
||||
return brandCache$.getValue()[key];
|
||||
};
|
||||
|
||||
|
|
|
@ -62,11 +62,11 @@ import { RecentlyAccessedHistoryItem } from 'ui/persisted_log';
|
|||
import { ChromeHeaderNavControlsRegistry } from 'ui/registry/chrome_header_nav_controls';
|
||||
import { relativeToAbsolute } from 'ui/url/relative_to_absolute';
|
||||
import { NavControlSide } from '../';
|
||||
import { Breadcrumb } from '../../../../../../../core/public/chrome';
|
||||
import { ChromeBreadcrumb } from '../../../../../../../core/public';
|
||||
|
||||
interface Props {
|
||||
appTitle?: string;
|
||||
breadcrumbs$: Rx.Observable<Breadcrumb[]>;
|
||||
breadcrumbs$: Rx.Observable<ChromeBreadcrumb[]>;
|
||||
homeHref: string;
|
||||
isVisible: boolean;
|
||||
navLinks$: Rx.Observable<NavLink[]>;
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
import { mount } from 'enzyme';
|
||||
import React from 'react';
|
||||
import * as Rx from 'rxjs';
|
||||
import { Breadcrumb } from '../../../../../../../core/public/chrome';
|
||||
import { ChromeBreadcrumb } from '../../../../../../../core/public';
|
||||
import { HeaderBreadcrumbs } from './header_breadcrumbs';
|
||||
|
||||
describe('HeaderBreadcrumbs', () => {
|
||||
it('renders updates to the breadcrumbs$ observable', () => {
|
||||
const breadcrumbs$ = new Rx.Subject<Breadcrumb[]>();
|
||||
const breadcrumbs$ = new Rx.Subject<ChromeBreadcrumb[]>();
|
||||
const wrapper = mount(<HeaderBreadcrumbs breadcrumbs$={breadcrumbs$} />);
|
||||
|
||||
breadcrumbs$.next([{ text: 'First' }]);
|
||||
|
|
|
@ -26,15 +26,15 @@ import {
|
|||
EuiHeaderBreadcrumbs,
|
||||
} from '@elastic/eui';
|
||||
|
||||
import { Breadcrumb } from '../../../../../../../core/public/chrome';
|
||||
import { ChromeBreadcrumb } from '../../../../../../../core/public';
|
||||
|
||||
interface Props {
|
||||
appTitle?: string;
|
||||
breadcrumbs$: Rx.Observable<Breadcrumb[]>;
|
||||
breadcrumbs$: Rx.Observable<ChromeBreadcrumb[]>;
|
||||
}
|
||||
|
||||
interface State {
|
||||
breadcrumbs: Breadcrumb[];
|
||||
breadcrumbs: ChromeBreadcrumb[];
|
||||
}
|
||||
|
||||
export class HeaderBreadcrumbs extends Component<Props, State> {
|
||||
|
|
6
src/legacy/ui/public/chrome/index.d.ts
vendored
6
src/legacy/ui/public/chrome/index.d.ts
vendored
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { Brand } from '../../../../core/public/chrome';
|
||||
import { ChromeBrand } from '../../../../core/public';
|
||||
import { SavedObjectsClient } from '../saved_objects';
|
||||
import { BreadcrumbsApi } from './api/breadcrumbs';
|
||||
import { HelpExtensionApi } from './api/help_extension';
|
||||
|
@ -40,8 +40,8 @@ declare interface Chrome extends ChromeNavLinks {
|
|||
setVisible(visible: boolean): any;
|
||||
getInjected(key: string, defaultValue?: any): any;
|
||||
setRootController(name: string, Controller: any): any;
|
||||
setBrand(brand: Brand): this;
|
||||
getBrand(key: keyof Brand): Brand[keyof Brand];
|
||||
setBrand(brand: ChromeBrand): this;
|
||||
getBrand(key: keyof ChromeBrand): ChromeBrand[keyof ChromeBrand];
|
||||
addApplicationClass(classNames: string | string[]): this;
|
||||
removeApplicationClass(classNames: string | string[]): this;
|
||||
getApplicationClasses(): string;
|
||||
|
|
|
@ -22,7 +22,7 @@ import React from 'react';
|
|||
import { i18nDirective, i18nFilter, I18nProvider } from '@kbn/i18n/angular';
|
||||
// @ts-ignore
|
||||
import { uiModules } from 'ui/modules';
|
||||
import { I18nSetup } from '../../../../core/public/i18n';
|
||||
import { I18nSetup } from '../../../../core/public';
|
||||
|
||||
export let I18nContext: I18nSetup['Context'] = null!;
|
||||
export function __newPlatformInit__(context: typeof I18nContext) {
|
||||
|
|
|
@ -17,29 +17,11 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { BasePathSetup } from '../../../../core/public/base_path';
|
||||
import { ChromeSetup } from '../../../../core/public/chrome';
|
||||
import { FatalErrorsSetup } from '../../../../core/public/fatal_errors';
|
||||
import { HttpSetup } from '../../../../core/public/http';
|
||||
import { I18nSetup } from '../../../../core/public/i18n';
|
||||
import { InjectedMetadataSetup } from '../../../../core/public/injected_metadata';
|
||||
import { NotificationsSetup } from '../../../../core/public/notifications';
|
||||
import { UiSettingsSetup } from '../../../../core/public/ui_settings';
|
||||
|
||||
interface CoreSetup {
|
||||
i18n: I18nSetup;
|
||||
injectedMetadata: InjectedMetadataSetup;
|
||||
fatalErrors: FatalErrorsSetup;
|
||||
notifications: NotificationsSetup;
|
||||
http: HttpSetup;
|
||||
basePath: BasePathSetup;
|
||||
uiSettings: UiSettingsSetup;
|
||||
chrome: ChromeSetup;
|
||||
}
|
||||
import { CoreSetup } from '../../../../core/public';
|
||||
|
||||
const runtimeContext = {
|
||||
setup: {
|
||||
core: null as CoreSetup | null,
|
||||
core: (null as unknown) as CoreSetup,
|
||||
plugins: {},
|
||||
},
|
||||
};
|
||||
|
@ -53,5 +35,8 @@ export function __newPlatformInit__(core: CoreSetup) {
|
|||
}
|
||||
|
||||
export function getNewPlatform() {
|
||||
if (runtimeContext.setup.core === null) {
|
||||
throw new Error('runtimeContext is not initialized yet');
|
||||
}
|
||||
return runtimeContext;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { FatalErrorsSetup } from '../../../../core/public/fatal_errors';
|
||||
import { FatalErrorsSetup } from '../../../../core/public';
|
||||
import {
|
||||
AngularHttpError,
|
||||
formatAngularHttpError,
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
import sinon from 'sinon';
|
||||
import { ToastsSetup } from '../../../../../core/public/notifications';
|
||||
import { ToastsSetup } from '../../../../../core/public';
|
||||
|
||||
import { ToastNotifications } from './toast_notifications';
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { Toast, ToastInput, ToastsSetup } from '../../../../../core/public/notifications';
|
||||
import { Toast, ToastInput, ToastsSetup } from '../../../../../core/public';
|
||||
|
||||
export { Toast, ToastInput };
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { ToastsSetup } from '../../../../../core/public/notifications';
|
||||
import { ToastsSetup } from '../../../../../core/public';
|
||||
import { ToastNotifications } from './toast_notifications';
|
||||
|
||||
export let toastNotifications: ToastNotifications;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
* WARNING: these types are incomplete
|
||||
*/
|
||||
|
||||
import { Breadcrumb } from '../../../../core/public/chrome';
|
||||
import { ChromeBreadcrumb } from '../../../../core/public';
|
||||
|
||||
interface RouteConfiguration {
|
||||
controller?: string | ((...args: any[]) => void);
|
||||
|
@ -29,7 +29,7 @@ interface RouteConfiguration {
|
|||
reloadOnSearch?: boolean;
|
||||
resolve?: object;
|
||||
template?: string;
|
||||
k7Breadcrumbs?: (...args: any[]) => Breadcrumb[];
|
||||
k7Breadcrumbs?: (...args: any[]) => ChromeBreadcrumb[];
|
||||
}
|
||||
|
||||
interface RouteManager {
|
||||
|
|
|
@ -24,8 +24,7 @@ import { parse as parseUrl } from 'url';
|
|||
import sinon from 'sinon';
|
||||
import { Notifier } from '../notify';
|
||||
import { metadata } from '../metadata';
|
||||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||
import { UiSettingsClient } from '../../../../core/public/ui_settings';
|
||||
import { UiSettingsClient } from '../../../../core/public';
|
||||
|
||||
import './test_harness.css';
|
||||
import 'ng_mock';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue