Incorporated the feedback.
Signed-off-by: bnechyporenko <bnechyporenko@bol.com>
This commit is contained in:
@@ -19,13 +19,13 @@ import {
|
||||
createVersionedValueMap,
|
||||
useVersionedContext,
|
||||
} from '@backstage/version-bridge';
|
||||
import { BackstagePlugin, AnyPluginOptions } from '../plugin';
|
||||
import { BackstagePlugin } from '../plugin';
|
||||
import React, { ReactNode } from 'react';
|
||||
|
||||
const contextKey: string = 'plugin-context';
|
||||
|
||||
/**
|
||||
* Properties for the AsyncEntityProvider component.
|
||||
* Properties for the PluginProvider component.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
@@ -38,14 +38,15 @@ export const PluginProvider = ({
|
||||
children,
|
||||
plugin,
|
||||
}: PluginOptionsProviderProps): JSX.Element => {
|
||||
const { Provider } = createVersionedContext<{ 1: AnyPluginOptions }>(
|
||||
contextKey,
|
||||
);
|
||||
const { Provider } = createVersionedContext<{
|
||||
1: { plugin: BackstagePlugin<any, any, any> | undefined };
|
||||
}>(contextKey);
|
||||
|
||||
return (
|
||||
<Provider
|
||||
value={createVersionedValueMap({
|
||||
1: plugin as unknown as {
|
||||
getPluginOptions(): AnyPluginOptions;
|
||||
1: {
|
||||
plugin,
|
||||
},
|
||||
})}
|
||||
>
|
||||
@@ -61,7 +62,7 @@ export const PluginProvider = ({
|
||||
* @alpha
|
||||
*/
|
||||
export function usePluginOptions<
|
||||
TPluginOptions extends AnyPluginOptions = AnyPluginOptions,
|
||||
TPluginOptions extends {} = {},
|
||||
>(): TPluginOptions {
|
||||
const versionedHolder = useVersionedContext<{ 1: TPluginOptions }>(
|
||||
contextKey,
|
||||
@@ -78,7 +79,9 @@ export function usePluginOptions<
|
||||
|
||||
return (
|
||||
value as unknown as {
|
||||
getPluginOptions(): AnyPluginOptions;
|
||||
plugin: {
|
||||
getPluginOptions(): {};
|
||||
};
|
||||
}
|
||||
).getPluginOptions() as TPluginOptions;
|
||||
).plugin.getPluginOptions() as TPluginOptions;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ import {
|
||||
Extension,
|
||||
AnyRoutes,
|
||||
AnyExternalRoutes,
|
||||
AnyPluginOptions,
|
||||
AnyPluginInputOptions,
|
||||
PluginFeatureFlagConfig,
|
||||
} from './types';
|
||||
import { AnyApiFactory } from '../apis';
|
||||
@@ -30,8 +28,8 @@ import { AnyApiFactory } from '../apis';
|
||||
* @internal
|
||||
*/
|
||||
export class PluginImpl<
|
||||
PluginInputOptions extends AnyPluginInputOptions,
|
||||
PluginOptions extends AnyPluginOptions,
|
||||
PluginInputOptions extends {},
|
||||
PluginOptions extends {},
|
||||
Routes extends AnyRoutes,
|
||||
ExternalRoutes extends AnyExternalRoutes,
|
||||
> implements BackstagePlugin<PluginInputOptions, Routes, ExternalRoutes>
|
||||
@@ -45,7 +43,7 @@ export class PluginImpl<
|
||||
>,
|
||||
) {}
|
||||
|
||||
options: AnyPluginOptions | undefined = undefined;
|
||||
options: {} | undefined = undefined;
|
||||
|
||||
getId(): string {
|
||||
return this.config.id;
|
||||
@@ -77,11 +75,11 @@ export class PluginImpl<
|
||||
}
|
||||
}
|
||||
|
||||
getPluginOptions(): AnyPluginOptions {
|
||||
getPluginOptions(): {} {
|
||||
if (this.config.__experimentalConfigure && !this.options) {
|
||||
this.options = this.config.__experimentalConfigure();
|
||||
}
|
||||
return this.options ?? ({} as AnyPluginOptions);
|
||||
return this.options ?? {};
|
||||
}
|
||||
|
||||
toString() {
|
||||
@@ -96,8 +94,8 @@ export class PluginImpl<
|
||||
* @public
|
||||
*/
|
||||
export function createPlugin<
|
||||
PluginInputOptions extends AnyPluginInputOptions = {},
|
||||
PluginOptions extends AnyPluginInputOptions = {},
|
||||
PluginInputOptions extends {},
|
||||
PluginOptions extends {},
|
||||
Routes extends AnyRoutes = {},
|
||||
ExternalRoutes extends AnyExternalRoutes = {},
|
||||
>(
|
||||
|
||||
@@ -18,8 +18,6 @@ export { createPlugin } from './Plugin';
|
||||
|
||||
export type {
|
||||
AnyExternalRoutes,
|
||||
AnyPluginOptions,
|
||||
AnyPluginInputOptions,
|
||||
AnyRoutes,
|
||||
BackstagePlugin,
|
||||
Extension,
|
||||
|
||||
@@ -44,21 +44,13 @@ export type AnyRoutes = { [name: string]: RouteRef | SubRouteRef };
|
||||
*/
|
||||
export type AnyExternalRoutes = { [name: string]: ExternalRouteRef };
|
||||
|
||||
/**
|
||||
* Catch-all metadata type.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type AnyPluginOptions = { [name: string]: unknown };
|
||||
export type AnyPluginInputOptions = { [name: string]: unknown };
|
||||
|
||||
/**
|
||||
* Plugin type.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type BackstagePlugin<
|
||||
PluginInputOptions extends AnyPluginInputOptions = {},
|
||||
PluginInputOptions extends {} = {},
|
||||
Routes extends AnyRoutes = {},
|
||||
ExternalRoutes extends AnyExternalRoutes = {},
|
||||
> = {
|
||||
@@ -90,8 +82,8 @@ export type PluginFeatureFlagConfig = {
|
||||
* @public
|
||||
*/
|
||||
export type PluginConfig<
|
||||
PluginInputOptions extends AnyPluginInputOptions,
|
||||
PluginOptions extends AnyPluginOptions,
|
||||
PluginInputOptions extends {},
|
||||
PluginOptions extends {},
|
||||
Routes extends AnyRoutes,
|
||||
ExternalRoutes extends AnyExternalRoutes,
|
||||
> = {
|
||||
|
||||
Reference in New Issue
Block a user