UNPKG

@hawtio/react

Version:

A Hawtio reimplementation based on TypeScript + React.

252 lines (249 loc) 9.41 kB
import { ImportRemoteOptions } from '@module-federation/utilities'; import React__default from 'react'; declare const PATTERNFLY_MAJOR_VERSION: string; declare const PATTERNFLY_THEME_CLASS: string; /** * Components to be added to the header navbar * Can define either a single component type or * a component with a universal property. * * By default, components will only be displayed * if the plugin UI is also visible. However, setting * universal to 'true' will ensure the component * remains displayed regardless of which plugin is * given focus. */ interface UniversalHeaderItem { /** * The component that should be populated as * a dropdown item on the header bar. */ component: React__default.ComponentType<any>; /** * Should components remain visible on header even when * the plugin is not being displayed. */ universal: boolean; } type HeaderItem = React__default.ComponentType | UniversalHeaderItem; declare function isUniversalHeaderItem(item: HeaderItem): item is UniversalHeaderItem; /** * Type definition of the entry point for a Hawtio plugin. Such plugin (method) should use Hawtio API * to register plugin details with name, paths and components. * * This method is synchronous and should synchronously call one of the plugin registration methods: * * `addPlugin`: add `Plugin` object directly * * `addDeferredPlugin`: add a function returning a Promise resolving to a `Plugin` object * * `addUrl`: add a URL for an endpoint returning an array of `HawtioRemote` objects representing remote modules * loaded using Module Federation utilities */ type HawtioPlugin = () => void; /** * Type definition of a fully remote _plugin_ (function) that is called by Hawtio using @module-federation/utilities. * * This method should be asynchronous and return a Promise (with any value), so Hawtio can await for its resolution. */ type HawtioAsyncPlugin = () => Promise<unknown>; /** * Internal representation of a Hawtio plugin. */ type Plugin = { /** * Mandatory, unique plugin identifier */ id: string; /** * Title to be displayed in left PageSidebar */ title?: string; /** * Path for plugin's main component. Optional if the plugin only contributes header elements for example */ path?: string; /** * The order to be shown in the Hawtio sidebar. * * This only controls presentation and doesn't change the order of plugin to * be loaded. * * If it's not specified, it defaults to `100`. `0` ~ `30` are reserved for * the builtin plugins. */ order?: number; /** * If this plugin provides a login form component */ isLogin?: boolean; /** * Plugin's main component to be displayed inside `<HawtioPage>` */ component?: React__default.ComponentType; /** * Plugin's components to be added to `<HawtioHeaderToolbar>` */ headerItems?: HeaderItem[]; /** * List of URL query parameters known and handled by this plugin. * Any query parameters not in this list will be centrally stripped out during * routing. */ knownQueryParams?: string[]; /** * Returns if this plugin should be activated. * This method needs to return a promise as the process of resolving if a plugin * should be activated may require information collected asynchronously such as * the existence of some MBeans, etc. */ isActive: () => Promise<boolean>; }; /** * Extension of Module Federation {@link ImportRemoteOptions} for single federated module. */ interface HawtioRemote extends ImportRemoteOptions { pluginEntry?: string; } /** * Interface through which `HawtioCore` should be available when importing it through `@hawtio/core/init` entry point. * * All the public methods of the implementing class will be available to other parts of `@hawtio/react`, but when * accessed through `IHawtio`, only part of the public API will be available. */ interface IHawtio { /** * Adds a Hawtio plugin directly using `Plugin` object. The plugin will be added to a list of plugins processed * at bootstrap time * @param plugin */ addPlugin(plugin: Plugin): IHawtio; /** * Adds a Hawtio plugin in a deferred way. Instead of passing `Plugin` object directly, we pass a function that * returns a Promise resolving (for example after `import()`) to actual `Plugin` or an array of `Plugin` objects. * @param id Plugin ID * @param deferred a function returning a Promise resolving to a `Plugin` or array of `Plugin` objects */ addDeferredPlugin(id: string, deferred: () => Promise<Plugin | Plugin[]>): IHawtio; /** * Adds a URL for discovering plugins. Single URL defines an endpoint that returns an array of modules/plugins * defined by {@link HawtioRemote} type. * * @param url An URL to fetch the plugin information from. When the URL is relative, it is using * `document.baseURI` as the base. */ addUrl(url: string): IHawtio; /** * Bootstraps Hawtio. This method needs to be called by all applications that are bundled with `webpack` (or * similar web bundler). * * This method returns a Promise. When resolved we can finally render the `<Hawtio>` React/PatternFly component */ bootstrap(): Promise<boolean>; } /** * Hawtio core service. * * This service provides the following functionalities: * - Base path provisioning * - Plugin loader and discovery mechanism * - Bootstrapping the application */ declare class HawtioCore implements IHawtio { /** * Hawtio base path. */ private basePath?; /** * List of URLs that the plugin loader will try and discover plugins from. */ private urls; /** * Holds all of the Hawtio plugins that need to be bootstrapped. */ private plugins; /** * Holds all of the Hawtio plugins which will be evaluated in deferred way. */ private deferredPlugins; /** * The Window Theme Listener callback function */ private windowThemeListener; /** * Flag set once the window theme listener has been added */ private windowListenerAdded; addPlugin(plugin: Plugin): HawtioCore; addDeferredPlugin(id: string, deferred: () => Promise<Plugin | Plugin[]>): HawtioCore; addUrl(url: string): HawtioCore; bootstrap(): Promise<boolean>; /** * Returns all plugins registered using different plugin registration methods. */ getPlugins(): Plugin[]; /** * Resolves which of registered plugins are active in current environment. * * There are two types of plugins: normal plugins and login plugins. * If it's normal, it's only resolved when the user is already logged in. * If it's login, it's only resolved when the user is not logged in yet, and thus * can only affects the login page. * * Therefore, this method depends on the login status provided by the `userService`. */ resolvePlugins(): Promise<Plugin[]>; /** * Sets the base path of the Hawtio console. * If the given path includes trailing '/', it will be trimmed. */ setBasePath(path: string): void; /** * Returns the base path of the Hawtio console without trailing '/'. */ getBasePath(): string | undefined; /** * Adds an event listener to the window theme to update * css values in the event of a change in theme */ addWindowThemeListener(): void; /** * Removes the event listener to the window theme */ removeWindowThemeListener(): void; /** * Returns the base URL specified in html/head/base element, href attribute. It should end with trailing '/'. * Specified base affects how `fetch()` global function works. * @private */ private documentBase; /** * Downloads plugins from any configured URLs and loads them. * It is invoked at Hawtio's bootstrapping. * * This plugin mechanism is implemented using [Webpack Module Federation](https://module-federation.github.io/). */ private loadPlugins; /** * Loads external plugins from the given URL. The URL endpoint is expected to * return an array of HawtioRemote objects. These are not strictly "Hawtio plugins", but rather * "remote entry points" that when called may register Hawtio plugins (with `hawtio.addPlugin()` or * `hawtio.addDeferredPlugin()`). */ private loadExternalPlugins; /** * Evaluate all deferred plugins, so they are added to `plugins` array of available plugins * @private */ private loadDeferredPlugins; private themeList; /** * Detect what theme the browser has been set to and * return 'dark' | 'light' */ windowTheme(): string; /** * Update the document root with the PatternFly dark class * see https://www.patternfly.org/developer-resources/dark-theme-handbook */ private updateFromTheme; } declare const hawtio: HawtioCore; export { type HawtioPlugin as H, type IHawtio as I, type Plugin as P, type UniversalHeaderItem as U, type HawtioAsyncPlugin as a, HawtioCore as b, type HawtioRemote as c, type HeaderItem as d, PATTERNFLY_MAJOR_VERSION as e, PATTERNFLY_THEME_CLASS as f, hawtio as h, isUniversalHeaderItem as i };