diff --git a/.changeset/angry-badgers-beg.md b/.changeset/angry-badgers-beg.md new file mode 100644 index 0000000000..38952aef98 --- /dev/null +++ b/.changeset/angry-badgers-beg.md @@ -0,0 +1,5 @@ +--- +'@backstage/frontend-app-api': patch +--- + +Internal update for removal of experimental plugin configuration API. diff --git a/.changeset/eighty-actors-type.md b/.changeset/eighty-actors-type.md new file mode 100644 index 0000000000..5c55a7b0c6 --- /dev/null +++ b/.changeset/eighty-actors-type.md @@ -0,0 +1,5 @@ +--- +'@backstage/test-utils': patch +--- + +Removed the alpha `MockPluginProvider` export since the plugin configuration API has been removed. diff --git a/.changeset/fresh-kangaroos-tap.md b/.changeset/fresh-kangaroos-tap.md new file mode 100644 index 0000000000..5ac4d184eb --- /dev/null +++ b/.changeset/fresh-kangaroos-tap.md @@ -0,0 +1,5 @@ +--- +'@backstage/core-plugin-api': minor +--- + +Removed the exprimental plugin configuration API. The `__experimentalReconfigure()` from the plugin options as well as the `__experimentalConfigure()` method on plugin instances have both been removed. diff --git a/packages/core-plugin-api/alpha-api-report.md b/packages/core-plugin-api/alpha-api-report.md index d50bb0abd6..ba3583142f 100644 --- a/packages/core-plugin-api/alpha-api-report.md +++ b/packages/core-plugin-api/alpha-api-report.md @@ -4,9 +4,7 @@ ```ts import { ApiRef } from '@backstage/core-plugin-api'; -import { BackstagePlugin } from '@backstage/core-plugin-api'; import { Observable } from '@backstage/types'; -import { ReactNode } from 'react'; import { TranslationMessages as TranslationMessages_2 } from '@backstage/core-plugin-api/alpha'; import { TranslationRef as TranslationRef_2 } from '@backstage/core-plugin-api/alpha'; @@ -74,17 +72,6 @@ export function createTranslationResource< options: TranslationResourceOptions, ): TranslationResource; -// @alpha -export interface PluginOptionsProviderProps { - // (undocumented) - children: ReactNode; - // (undocumented) - plugin?: BackstagePlugin; -} - -// @alpha -export const PluginProvider: (props: PluginOptionsProviderProps) => JSX.Element; - // @alpha (undocumented) export type TranslationApi = { getTranslation< @@ -245,11 +232,6 @@ export type TranslationSnapshot< t: TranslationFunction; }; -// @alpha -export function usePluginOptions< - TPluginOptions extends {} = {}, ->(): TPluginOptions; - // @alpha (undocumented) export const useTranslationRef: < TMessages extends { diff --git a/packages/core-plugin-api/api-report.md b/packages/core-plugin-api/api-report.md index 930f1f979d..7873b23f13 100644 --- a/packages/core-plugin-api/api-report.md +++ b/packages/core-plugin-api/api-report.md @@ -222,7 +222,7 @@ export type BackstageIdentityResponse = { export type BackstagePlugin< Routes extends AnyRoutes = {}, ExternalRoutes extends AnyExternalRoutes = {}, - PluginInputOptions extends {} = {}, + _Ignored extends {} = {}, > = { getId(): string; getApis(): Iterable; @@ -230,7 +230,6 @@ export type BackstagePlugin< provide(extension: Extension): T; routes: Routes; externalRoutes: ExternalRoutes; - __experimentalReconfigure(options: PluginInputOptions): void; }; // @public @@ -318,10 +317,9 @@ export function createExternalRouteRef< export function createPlugin< Routes extends AnyRoutes = {}, ExternalRoutes extends AnyExternalRoutes = {}, - PluginInputOptions extends {} = {}, >( - config: PluginConfig, -): BackstagePlugin; + config: PluginConfig, +): BackstagePlugin; // @public export function createReactExtension< @@ -647,14 +645,12 @@ export type PendingOAuthRequest = { export type PluginConfig< Routes extends AnyRoutes, ExternalRoutes extends AnyExternalRoutes, - PluginInputOptions extends {}, > = { id: string; apis?: Iterable; routes?: Routes; externalRoutes?: ExternalRoutes; featureFlags?: PluginFeatureFlagConfig[]; - __experimentalConfigure?(options?: PluginInputOptions): {}; }; // @public diff --git a/packages/core-plugin-api/src/alpha.ts b/packages/core-plugin-api/src/alpha.ts index 505fd9b818..ebcbcf34c0 100644 --- a/packages/core-plugin-api/src/alpha.ts +++ b/packages/core-plugin-api/src/alpha.ts @@ -14,6 +14,5 @@ * limitations under the License. */ -export * from './plugin-options'; export * from './translation'; export * from './apis/alpha'; diff --git a/packages/core-plugin-api/src/extensions/extensions.tsx b/packages/core-plugin-api/src/extensions/extensions.tsx index a9a3127aee..b94354fa2c 100644 --- a/packages/core-plugin-api/src/extensions/extensions.tsx +++ b/packages/core-plugin-api/src/extensions/extensions.tsx @@ -21,7 +21,6 @@ import { RouteRef, useRouteRef } from '../routing'; import { attachComponentData } from './componentData'; import { Extension, BackstagePlugin } from '../plugin'; import { PluginErrorBoundary } from './PluginErrorBoundary'; -import { PluginProvider } from '../plugin-options'; import { routableExtensionRenderedEvent } from '../analytics/Tracker'; /** @@ -258,9 +257,7 @@ export function createReactExtension< ...(mountPoint && { routeRef: mountPoint.id }), }} > - - - + diff --git a/packages/core-plugin-api/src/plugin-options/index.ts b/packages/core-plugin-api/src/plugin-options/index.ts deleted file mode 100644 index 1737a1c836..0000000000 --- a/packages/core-plugin-api/src/plugin-options/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright 2020 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export { usePluginOptions, PluginProvider } from './usePluginOptions'; -export type { PluginOptionsProviderProps } from './usePluginOptions'; diff --git a/packages/core-plugin-api/src/plugin-options/usePluginOptions.test.tsx b/packages/core-plugin-api/src/plugin-options/usePluginOptions.test.tsx deleted file mode 100644 index 96691d503b..0000000000 --- a/packages/core-plugin-api/src/plugin-options/usePluginOptions.test.tsx +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2021 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import React from 'react'; -import { renderHook } from '@testing-library/react-hooks'; -import { usePluginOptions, PluginProvider } from './usePluginOptions'; -import { createPlugin } from '../plugin'; - -describe('usePluginOptions', () => { - it('should provide a versioned value to hook', () => { - type TestInputPluginOptions = { - 'key-1': string; - }; - - type TestPluginOptions = { - 'key-1': string; - 'key-2': string; - }; - - const plugin = createPlugin({ - id: 'my-plugin', - __experimentalConfigure(_: TestInputPluginOptions): TestPluginOptions { - return { 'key-1': 'value-1', 'key-2': 'value-2' }; - }, - }); - - const rendered = renderHook(() => usePluginOptions(), { - wrapper: ({ children }: React.PropsWithChildren<{}>) => ( - {children} - ), - }); - - const config = rendered.result.current; - - expect(config).toEqual({ - 'key-1': 'value-1', - 'key-2': 'value-2', - }); - }); -}); diff --git a/packages/core-plugin-api/src/plugin-options/usePluginOptions.tsx b/packages/core-plugin-api/src/plugin-options/usePluginOptions.tsx deleted file mode 100644 index 8b3f7c109c..0000000000 --- a/packages/core-plugin-api/src/plugin-options/usePluginOptions.tsx +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2020 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { - createVersionedContext, - createVersionedValueMap, - useVersionedContext, -} from '@backstage/version-bridge'; -import { BackstagePlugin } from '@backstage/core-plugin-api'; -import React, { ReactNode } from 'react'; - -const contextKey: string = 'plugin-context'; - -/** - * Properties for the PluginProvider component. - * - * @alpha - */ -export interface PluginOptionsProviderProps { - children: ReactNode; - plugin?: BackstagePlugin; -} - -/** - * Contains the plugin configuration. - * - * @alpha - */ -export const PluginProvider = ( - props: PluginOptionsProviderProps, -): JSX.Element => { - const { children, plugin } = props; - - const { Provider } = createVersionedContext<{ - 1: { plugin: BackstagePlugin | undefined }; - }>(contextKey); - - return ( - - {children} - - ); -}; - -/** - * Grab the current entity from the context, throws if the entity has not yet been loaded - * or is not available. - * - * @alpha - */ -export function usePluginOptions< - TPluginOptions extends {} = {}, ->(): TPluginOptions { - const versionedHolder = useVersionedContext<{ 1: TPluginOptions }>( - contextKey, - ); - - if (!versionedHolder) { - throw new Error('Plugin Options context is not available'); - } - - const value = versionedHolder.atVersion(1); - if (!value) { - throw new Error('Plugin Options v1 is not available'); - } - - return ( - value as unknown as { - plugin: { - getPluginOptions(): {}; - }; - } - ).plugin.getPluginOptions() as TPluginOptions; -} diff --git a/packages/core-plugin-api/src/plugin/Plugin.tsx b/packages/core-plugin-api/src/plugin/Plugin.tsx index da26cd4db0..d97554b27b 100644 --- a/packages/core-plugin-api/src/plugin/Plugin.tsx +++ b/packages/core-plugin-api/src/plugin/Plugin.tsx @@ -30,18 +30,9 @@ import { AnyApiFactory } from '../apis'; export class PluginImpl< Routes extends AnyRoutes, ExternalRoutes extends AnyExternalRoutes, - PluginInputOptions extends {}, -> implements BackstagePlugin +> implements BackstagePlugin { - constructor( - private readonly config: PluginConfig< - Routes, - ExternalRoutes, - PluginInputOptions - >, - ) {} - - private options: {} | undefined = undefined; + constructor(private readonly config: PluginConfig) {} getId(): string { return this.config.id; @@ -67,19 +58,6 @@ export class PluginImpl< return extension.expose(this); } - __experimentalReconfigure(options: PluginInputOptions): void { - if (this.config.__experimentalConfigure) { - this.options = this.config.__experimentalConfigure(options); - } - } - - getPluginOptions(): {} { - if (this.config.__experimentalConfigure && !this.options) { - this.options = this.config.__experimentalConfigure(); - } - return this.options ?? {}; - } - toString() { return `plugin{${this.config.id}}`; } @@ -94,9 +72,8 @@ export class PluginImpl< export function createPlugin< Routes extends AnyRoutes = {}, ExternalRoutes extends AnyExternalRoutes = {}, - PluginInputOptions extends {} = {}, >( - config: PluginConfig, -): BackstagePlugin { + config: PluginConfig, +): BackstagePlugin { return new PluginImpl(config); } diff --git a/packages/core-plugin-api/src/plugin/types.ts b/packages/core-plugin-api/src/plugin/types.ts index 37ce6c9e7c..3ba7706e16 100644 --- a/packages/core-plugin-api/src/plugin/types.ts +++ b/packages/core-plugin-api/src/plugin/types.ts @@ -52,7 +52,7 @@ export type AnyExternalRoutes = { [name: string]: ExternalRouteRef }; export type BackstagePlugin< Routes extends AnyRoutes = {}, ExternalRoutes extends AnyExternalRoutes = {}, - PluginInputOptions extends {} = {}, + _Ignored extends {} = {}, > = { getId(): string; getApis(): Iterable; @@ -63,7 +63,6 @@ export type BackstagePlugin< provide(extension: Extension): T; routes: Routes; externalRoutes: ExternalRoutes; - __experimentalReconfigure(options: PluginInputOptions): void; }; /** @@ -84,14 +83,12 @@ export type PluginFeatureFlagConfig = { export type PluginConfig< Routes extends AnyRoutes, ExternalRoutes extends AnyExternalRoutes, - PluginInputOptions extends {}, > = { id: string; apis?: Iterable; routes?: Routes; externalRoutes?: ExternalRoutes; featureFlags?: PluginFeatureFlagConfig[]; - __experimentalConfigure?(options?: PluginInputOptions): {}; }; /** diff --git a/packages/frontend-app-api/src/wiring/createApp.tsx b/packages/frontend-app-api/src/wiring/createApp.tsx index 462bfcdccc..12965f9bdf 100644 --- a/packages/frontend-app-api/src/wiring/createApp.tsx +++ b/packages/frontend-app-api/src/wiring/createApp.tsx @@ -314,7 +314,6 @@ function toLegacyPlugin(plugin: BackstagePlugin): LegacyBackstagePlugin { getApis: notImplemented, getFeatureFlags: notImplemented, provide: notImplemented, - __experimentalReconfigure: notImplemented, }; } diff --git a/packages/test-utils/alpha-api-report.md b/packages/test-utils/alpha-api-report.md index 4a9fd2e5a4..945c754f83 100644 --- a/packages/test-utils/alpha-api-report.md +++ b/packages/test-utils/alpha-api-report.md @@ -4,17 +4,10 @@ ```ts import { Observable } from '@backstage/types'; -import { PropsWithChildren } from 'react'; -import { default as React_2 } from 'react'; import { TranslationApi } from '@backstage/core-plugin-api/alpha'; import { TranslationRef } from '@backstage/core-plugin-api/alpha'; import { TranslationSnapshot } from '@backstage/core-plugin-api/alpha'; -// @alpha -export const MockPluginProvider: ({ - children, -}: PropsWithChildren<{}>) => React_2.JSX.Element; - // @alpha (undocumented) export class MockTranslationApi implements TranslationApi { // (undocumented) diff --git a/packages/test-utils/src/alpha.ts b/packages/test-utils/src/alpha.ts index c6801993bc..2077ad3586 100644 --- a/packages/test-utils/src/alpha.ts +++ b/packages/test-utils/src/alpha.ts @@ -14,5 +14,4 @@ * limitations under the License. */ -export * from './testUtils/MockPluginProvider'; export * from './testUtils/apis/TranslationApi'; diff --git a/packages/test-utils/src/testUtils/MockPluginProvider.tsx b/packages/test-utils/src/testUtils/MockPluginProvider.tsx deleted file mode 100644 index 25442ae267..0000000000 --- a/packages/test-utils/src/testUtils/MockPluginProvider.tsx +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2020 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import React, { PropsWithChildren } from 'react'; -import { PluginProvider } from '@backstage/core-plugin-api/alpha'; -import { createPlugin } from '@backstage/core-plugin-api'; - -/** - * Mock for PluginProvider to use in unit tests - * @alpha - */ -export const MockPluginProvider = ({ children }: PropsWithChildren<{}>) => { - type TestInputPluginOptions = {}; - type TestPluginOptions = {}; - const plugin = createPlugin({ - id: 'my-plugin', - __experimentalConfigure(_: TestInputPluginOptions): TestPluginOptions { - return {}; - }, - }); - - return {children}; -};