From 7fb8102c0cf1bfb6688534ea8a2c66c2a3b29d4e Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 19 Aug 2024 14:58:09 +0200 Subject: [PATCH] frontend-plugin-api: remove deprecated extension creators Signed-off-by: Patrik Oldsberg --- .../src/extensions/createApiExtension.test.ts | 92 ---------- .../src/extensions/createApiExtension.ts | 82 --------- .../createAppRootElementExtension.test.tsx | 109 ----------- .../createAppRootElementExtension.ts | 72 -------- .../createAppRootWrapperExtension.test.tsx | 121 ------------- .../createAppRootWrapperExtension.tsx | 88 --------- .../src/extensions/createNavItemExtension.tsx | 69 ------- .../createNavLogoExtension.test.tsx | 48 ----- .../src/extensions/createNavLogoExtension.tsx | 61 ------- .../extensions/createPageExtension.test.tsx | 145 --------------- .../src/extensions/createPageExtension.tsx | 98 ---------- .../extensions/createRouterExtension.test.tsx | 169 ------------------ .../src/extensions/createRouterExtension.tsx | 88 --------- .../createSignInPageExtension.test.tsx | 47 ----- .../extensions/createSignInPageExtension.tsx | 88 --------- .../src/extensions/createThemeExtension.ts | 44 ----- .../createTranslationExtension.test.ts | 137 -------------- .../extensions/createTranslationExtension.ts | 47 ----- .../src/extensions/index.ts | 10 -- 19 files changed, 1615 deletions(-) delete mode 100644 packages/frontend-plugin-api/src/extensions/createApiExtension.test.ts delete mode 100644 packages/frontend-plugin-api/src/extensions/createApiExtension.ts delete mode 100644 packages/frontend-plugin-api/src/extensions/createAppRootElementExtension.test.tsx delete mode 100644 packages/frontend-plugin-api/src/extensions/createAppRootElementExtension.ts delete mode 100644 packages/frontend-plugin-api/src/extensions/createAppRootWrapperExtension.test.tsx delete mode 100644 packages/frontend-plugin-api/src/extensions/createAppRootWrapperExtension.tsx delete mode 100644 packages/frontend-plugin-api/src/extensions/createNavItemExtension.tsx delete mode 100644 packages/frontend-plugin-api/src/extensions/createNavLogoExtension.test.tsx delete mode 100644 packages/frontend-plugin-api/src/extensions/createNavLogoExtension.tsx delete mode 100644 packages/frontend-plugin-api/src/extensions/createPageExtension.test.tsx delete mode 100644 packages/frontend-plugin-api/src/extensions/createPageExtension.tsx delete mode 100644 packages/frontend-plugin-api/src/extensions/createRouterExtension.test.tsx delete mode 100644 packages/frontend-plugin-api/src/extensions/createRouterExtension.tsx delete mode 100644 packages/frontend-plugin-api/src/extensions/createSignInPageExtension.test.tsx delete mode 100644 packages/frontend-plugin-api/src/extensions/createSignInPageExtension.tsx delete mode 100644 packages/frontend-plugin-api/src/extensions/createThemeExtension.ts delete mode 100644 packages/frontend-plugin-api/src/extensions/createTranslationExtension.test.ts delete mode 100644 packages/frontend-plugin-api/src/extensions/createTranslationExtension.ts diff --git a/packages/frontend-plugin-api/src/extensions/createApiExtension.test.ts b/packages/frontend-plugin-api/src/extensions/createApiExtension.test.ts deleted file mode 100644 index 8f8a0cd9ac..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createApiExtension.test.ts +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2023 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 { createApiExtension } from './createApiExtension'; -import { createApiFactory, createApiRef } from '@backstage/core-plugin-api'; - -describe('createApiExtension', () => { - it('fills in the expected values for an existing factory', () => { - const api = createApiRef<{ foo: string }>({ id: 'test' }); - const factory = createApiFactory({ - api, - deps: {}, - factory: () => ({ foo: 'bar' }), - }); - - expect( - createApiExtension({ - factory, - }), - ).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - kind: 'api', - namespace: 'test', - attachTo: { id: 'app', input: 'apis' }, - disabled: false, - configSchema: undefined, - inputs: {}, - output: { - api: expect.objectContaining({ - $$type: '@backstage/ExtensionDataRef', - id: 'core.api.factory', - config: {}, - }), - }, - factory: expect.any(Function), - toString: expect.any(Function), - override: expect.any(Function), - }); - }); - - it('fills in the expected values for a ref and custom factory', () => { - const api = createApiRef<{ foo: string }>({ id: 'test' }); - const factory = jest.fn(() => ({ foo: 'bar' })); - - const extension = createApiExtension({ - api, - inputs: {}, - factory({ config: _config, inputs: _inputs }) { - return createApiFactory({ - api, - deps: {}, - factory, - }); - }, - }); - // boo - expect(extension).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - kind: 'api', - namespace: 'test', - attachTo: { id: 'app', input: 'apis' }, - disabled: false, - configSchema: undefined, - inputs: {}, - output: { - api: expect.objectContaining({ - $$type: '@backstage/ExtensionDataRef', - id: 'core.api.factory', - config: {}, - }), - }, - factory: expect.any(Function), - toString: expect.any(Function), - override: expect.any(Function), - }); - }); -}); diff --git a/packages/frontend-plugin-api/src/extensions/createApiExtension.ts b/packages/frontend-plugin-api/src/extensions/createApiExtension.ts deleted file mode 100644 index bb854d202f..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createApiExtension.ts +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2023 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 { AnyApiFactory, AnyApiRef } from '@backstage/core-plugin-api'; -import { PortableSchema } from '../schema'; -import { ResolvedExtensionInputs, createExtension } from '../wiring'; -import { AnyExtensionInputMap } from '../wiring/createExtension'; -import { Expand } from '../types'; -import { ApiBlueprint } from '../blueprints/ApiBlueprint'; - -/** - * @public - * @deprecated Use {@link ApiBlueprint} instead. - */ -export function createApiExtension< - TConfig extends {}, - TInputs extends AnyExtensionInputMap, ->( - options: ( - | { - api: AnyApiRef; - factory: (options: { - config: TConfig; - inputs: Expand>; - }) => AnyApiFactory; - } - | { - factory: AnyApiFactory; - } - ) & { - configSchema?: PortableSchema; - inputs?: TInputs; - }, -) { - const { factory, configSchema, inputs: extensionInputs } = options; - - const apiRef = - 'api' in options ? options.api : (factory as { api: AnyApiRef }).api; - - return createExtension({ - kind: 'api', - // Since ApiRef IDs use a global namespace we use the namespace here in order to override - // potential plugin IDs and always end up with the format `api:` - namespace: apiRef.id, - attachTo: { id: 'app', input: 'apis' }, - inputs: extensionInputs, - configSchema, - output: { - api: ApiBlueprint.dataRefs.factory, - }, - factory({ config, inputs }) { - if (typeof factory === 'function') { - return { api: factory({ config, inputs }) }; - } - return { api: factory }; - }, - }); -} - -/** - * @public - * @deprecated Use {@link ApiBlueprint} instead. - */ -export namespace createApiExtension { - /** - * @deprecated Use {@link ApiBlueprint} instead. - */ - export const factoryDataRef = ApiBlueprint.dataRefs.factory; -} diff --git a/packages/frontend-plugin-api/src/extensions/createAppRootElementExtension.test.tsx b/packages/frontend-plugin-api/src/extensions/createAppRootElementExtension.test.tsx deleted file mode 100644 index 6e80f6fe13..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createAppRootElementExtension.test.tsx +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2023 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 { createExtensionTester } from '@backstage/frontend-test-utils'; -import { screen } from '@testing-library/react'; -import React from 'react'; -import { createSchemaFromZod } from '../schema/createSchemaFromZod'; -import { coreExtensionData } from '../wiring/coreExtensionData'; -import { createExtension } from '../wiring/createExtension'; -import { createExtensionInput } from '../wiring/createExtensionInput'; -import { createAppRootElementExtension } from './createAppRootElementExtension'; - -describe('createAppRootElementExtension', () => { - it('works with simple options and just an element', async () => { - const extension = createAppRootElementExtension({ - element:
Hello
, - }); - - expect(extension).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - kind: 'app-root-element', - attachTo: { id: 'app/root', input: 'elements' }, - disabled: false, - inputs: {}, - output: { - element: expect.anything(), - }, - factory: expect.any(Function), - toString: expect.any(Function), - override: expect.any(Function), - }); - - createExtensionTester(extension).render(); - - await expect(screen.findByText('Hello')).resolves.toBeInTheDocument(); - }); - - it('works with complex options and a callback', async () => { - const schema = createSchemaFromZod(z => z.object({ name: z.string() })); - - const extension = createAppRootElementExtension({ - namespace: 'ns', - name: 'test', - configSchema: schema, - attachTo: { id: 'other', input: 'slot' }, - disabled: true, - inputs: { - children: createExtensionInput({ - element: coreExtensionData.reactElement, - }), - }, - element: ({ inputs, config }) => ( -
- Hello, {config.name}, {inputs.children.length} -
- ), - }); - - expect(extension).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - kind: 'app-root-element', - namespace: 'ns', - name: 'test', - attachTo: { id: 'other', input: 'slot' }, - configSchema: schema, - disabled: true, - inputs: { - children: createExtensionInput({ - element: coreExtensionData.reactElement, - }), - }, - output: { - element: expect.anything(), - }, - factory: expect.any(Function), - toString: expect.any(Function), - override: expect.any(Function), - }); - - createExtensionTester(extension, { config: { name: 'Robin' } }) - .add( - createExtension({ - attachTo: { id: 'app-root-element:ns/test', input: 'children' }, - output: { element: coreExtensionData.reactElement }, - factory: () => ({ element:
}), - }), - ) - .render(); - - await expect( - screen.findByText('Hello, Robin, 1'), - ).resolves.toBeInTheDocument(); - }); -}); diff --git a/packages/frontend-plugin-api/src/extensions/createAppRootElementExtension.ts b/packages/frontend-plugin-api/src/extensions/createAppRootElementExtension.ts deleted file mode 100644 index c8f7bdc366..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createAppRootElementExtension.ts +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2023 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 { JSX } from 'react'; -import { PortableSchema } from '../schema/types'; -import { Expand } from '../types'; -import { coreExtensionData } from '../wiring/coreExtensionData'; -import { - AnyExtensionInputMap, - ExtensionDefinition, - ResolvedExtensionInputs, - createExtension, -} from '../wiring/createExtension'; - -/** - * Creates an extension that renders a React element at the app root, outside of - * the app layout. This is useful for example for shared popups and similar. - * - * @public - * @deprecated Use {@link AppRootElementBlueprint} instead. - */ -export function createAppRootElementExtension< - TConfig extends {}, - TInputs extends AnyExtensionInputMap, ->(options: { - namespace?: string; - name?: string; - attachTo?: { id: string; input: string }; - configSchema?: PortableSchema; - disabled?: boolean; - inputs?: TInputs; - element: - | JSX.Element - | ((options: { - inputs: Expand>; - config: TConfig; - }) => JSX.Element); -}): ExtensionDefinition { - return createExtension({ - kind: 'app-root-element', - namespace: options.namespace, - name: options.name, - attachTo: options.attachTo ?? { id: 'app/root', input: 'elements' }, - configSchema: options.configSchema, - disabled: options.disabled, - inputs: options.inputs, - output: { - element: coreExtensionData.reactElement, - }, - factory({ inputs, config }) { - return { - element: - typeof options.element === 'function' - ? options.element({ inputs, config }) - : options.element, - }; - }, - }); -} diff --git a/packages/frontend-plugin-api/src/extensions/createAppRootWrapperExtension.test.tsx b/packages/frontend-plugin-api/src/extensions/createAppRootWrapperExtension.test.tsx deleted file mode 100644 index 993c4fdee3..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createAppRootWrapperExtension.test.tsx +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2023 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 { createExtensionTester } from '@backstage/frontend-test-utils'; -import { screen } from '@testing-library/react'; -import React from 'react'; -import { createSchemaFromZod } from '../schema/createSchemaFromZod'; -import { coreExtensionData } from '../wiring/coreExtensionData'; -import { createExtension } from '../wiring/createExtension'; -import { createExtensionInput } from '../wiring/createExtensionInput'; -import { createAppRootWrapperExtension } from './createAppRootWrapperExtension'; -import { createPageExtension } from './createPageExtension'; - -describe('createAppRootWrapperExtension', () => { - it('works with simple options and no props', async () => { - const extension = createAppRootWrapperExtension({ - Component: () =>
Hello
, - }); - - expect(extension).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - kind: 'app-root-wrapper', - attachTo: { id: 'app/root', input: 'wrappers' }, - disabled: false, - inputs: {}, - output: { - component: expect.anything(), - }, - factory: expect.any(Function), - toString: expect.any(Function), - override: expect.any(Function), - }); - - createExtensionTester( - createPageExtension({ - defaultPath: '/', - loader: async () =>
, - }), - ) - .add(extension) - .render(); - - await expect(screen.findByText('Hello')).resolves.toBeInTheDocument(); - }); - - it('works with complex options and props', async () => { - const schema = createSchemaFromZod(z => z.object({ name: z.string() })); - - const extension = createAppRootWrapperExtension({ - namespace: 'ns', - name: 'test', - configSchema: schema, - disabled: true, - inputs: { - children: createExtensionInput({ - element: coreExtensionData.reactElement, - }), - }, - Component: ({ inputs, config, children }) => ( -
- {children} -
- ), - }); - - expect(extension).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - kind: 'app-root-wrapper', - namespace: 'ns', - name: 'test', - attachTo: { id: 'app/root', input: 'wrappers' }, - configSchema: schema, - disabled: true, - inputs: { - children: createExtensionInput({ - element: coreExtensionData.reactElement, - }), - }, - output: { - component: expect.anything(), - }, - factory: expect.any(Function), - override: expect.any(Function), - toString: expect.any(Function), - }); - - createExtensionTester( - createPageExtension({ - defaultPath: '/', - loader: async () =>
Hello
, - }), - ) - .add(extension, { config: { name: 'Robin' } }) - .add( - createExtension({ - attachTo: { id: 'app-root-wrapper:ns/test', input: 'children' }, - output: { element: coreExtensionData.reactElement }, - factory: () => ({ element:
}), - }), - ) - .render(); - - await expect(screen.findByText('Hello')).resolves.toBeInTheDocument(); - await expect(screen.findByTestId('Robin-1')).resolves.toBeInTheDocument(); - }); -}); diff --git a/packages/frontend-plugin-api/src/extensions/createAppRootWrapperExtension.tsx b/packages/frontend-plugin-api/src/extensions/createAppRootWrapperExtension.tsx deleted file mode 100644 index f055618ffd..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createAppRootWrapperExtension.tsx +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2023 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, { ComponentType, PropsWithChildren } from 'react'; -import { PortableSchema } from '../schema/types'; -import { - AnyExtensionInputMap, - ExtensionDefinition, - ResolvedExtensionInputs, - createExtension, -} from '../wiring/createExtension'; -import { Expand } from '../types'; -import { AppRootWrapperBlueprint } from '../blueprints/AppRootWrapperBlueprint'; - -/** - * Creates an extension that renders a React wrapper at the app root, enclosing - * the app layout. This is useful for example for adding global React contexts - * and similar. - * - * @public - * @deprecated Use {@link AppRootWrapperBlueprint} instead. - */ -export function createAppRootWrapperExtension< - TConfig extends {}, - TInputs extends AnyExtensionInputMap, ->(options: { - namespace?: string; - name?: string; - attachTo?: { id: string; input: string }; - configSchema?: PortableSchema; - disabled?: boolean; - inputs?: TInputs; - Component: ComponentType< - PropsWithChildren<{ - inputs: Expand>; - config: TConfig; - }> - >; -}): ExtensionDefinition { - return createExtension({ - kind: 'app-root-wrapper', - namespace: options.namespace, - name: options.name, - attachTo: options.attachTo ?? { id: 'app/root', input: 'wrappers' }, - configSchema: options.configSchema, - disabled: options.disabled, - inputs: options.inputs, - output: { - component: AppRootWrapperBlueprint.dataRefs.component, - }, - factory({ inputs, config }) { - const Component = (props: PropsWithChildren<{}>) => { - return ( - - {props.children} - - ); - }; - return { - component: Component, - }; - }, - }); -} - -/** - * @public - * @deprecated Use {@link AppRootWrapperBlueprint} instead. - */ -export namespace createAppRootWrapperExtension { - /** - * @deprecated Use {@link AppRootWrapperBlueprint} instead. - */ - export const componentDataRef = AppRootWrapperBlueprint.dataRefs.component; -} diff --git a/packages/frontend-plugin-api/src/extensions/createNavItemExtension.tsx b/packages/frontend-plugin-api/src/extensions/createNavItemExtension.tsx deleted file mode 100644 index f6da531776..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createNavItemExtension.tsx +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2023 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 { IconComponent } from '@backstage/core-plugin-api'; -import { createSchemaFromZod } from '../schema/createSchemaFromZod'; -import { createExtension } from '../wiring'; -import { RouteRef } from '../routing'; -import { NavItemBlueprint } from '../blueprints/NavItemBlueprint'; - -/** - * Helper for creating extensions for a nav item. - * - * @public - * @deprecated Use {@link NavItemBlueprint} instead. - */ -export function createNavItemExtension(options: { - namespace?: string; - name?: string; - routeRef: RouteRef; - title: string; - icon: IconComponent; -}) { - const { routeRef, title, icon, namespace, name } = options; - return createExtension({ - namespace, - name, - kind: 'nav-item', - attachTo: { id: 'app/nav', input: 'items' }, - configSchema: createSchemaFromZod(z => - z.object({ - title: z.string().default(title), - }), - ), - output: { - navTarget: NavItemBlueprint.dataRefs.target, - }, - factory: ({ config }) => ({ - navTarget: { - title: config.title, - icon, - routeRef, - }, - }), - }); -} - -/** - * @public - * @deprecated Use {@link NavItemBlueprint} instead. - */ -export namespace createNavItemExtension { - /** - * @deprecated Use {@link NavItemBlueprint} instead. - */ - export const targetDataRef = NavItemBlueprint.dataRefs.target; -} diff --git a/packages/frontend-plugin-api/src/extensions/createNavLogoExtension.test.tsx b/packages/frontend-plugin-api/src/extensions/createNavLogoExtension.test.tsx deleted file mode 100644 index 17187a339d..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createNavLogoExtension.test.tsx +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2023 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 { createNavLogoExtension } from './createNavLogoExtension'; - -jest.mock('@backstage/core-plugin-api', () => ({ - ...jest.requireActual('@backstage/core-plugin-api'), -})); - -describe('createNavLogoExtension', () => { - it('creates the extension properly', () => { - expect( - createNavLogoExtension({ - name: 'test', - logoFull:
Logo Full
, - logoIcon:
Logo Icon
, - }), - ).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - kind: 'nav-logo', - name: 'test', - attachTo: { id: 'app/nav', input: 'logos' }, - disabled: false, - inputs: {}, - output: { - logos: expect.anything(), - }, - factory: expect.any(Function), - override: expect.any(Function), - toString: expect.any(Function), - }); - }); -}); diff --git a/packages/frontend-plugin-api/src/extensions/createNavLogoExtension.tsx b/packages/frontend-plugin-api/src/extensions/createNavLogoExtension.tsx deleted file mode 100644 index 449bddb342..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createNavLogoExtension.tsx +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2023 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 { createExtension } from '../wiring'; -import { NavLogoBlueprint } from '../blueprints/NavLogoBlueprint'; - -/** - * Helper for creating extensions for a nav logos. - * - * @public - * @deprecated Use {@link NavLogoBlueprint} instead. - */ -export function createNavLogoExtension(options: { - name?: string; - namespace?: string; - logoIcon: JSX.Element; - logoFull: JSX.Element; -}) { - const { logoIcon, logoFull } = options; - return createExtension({ - kind: 'nav-logo', - name: options?.name, - namespace: options?.namespace, - attachTo: { id: 'app/nav', input: 'logos' }, - output: { - logos: NavLogoBlueprint.dataRefs.logoElements, - }, - factory: () => { - return { - logos: { - logoIcon, - logoFull, - }, - }; - }, - }); -} - -/** - * @public - * @deprecated Use {@link NavLogoBlueprint} instead. - */ -export namespace createNavLogoExtension { - /** - * @deprecated Use {@link NavLogoBlueprint} instead. - */ - export const logoElementsDataRef = NavLogoBlueprint.dataRefs.logoElements; -} diff --git a/packages/frontend-plugin-api/src/extensions/createPageExtension.test.tsx b/packages/frontend-plugin-api/src/extensions/createPageExtension.test.tsx deleted file mode 100644 index e5dd4027c0..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createPageExtension.test.tsx +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2023 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 { useAnalytics } from '@backstage/core-plugin-api'; -import { waitFor } from '@testing-library/react'; -import { PortableSchema } from '../schema'; -import { coreExtensionData, createExtensionInput } from '../wiring'; -import { createPageExtension } from './createPageExtension'; -import { createExtensionTester } from '@backstage/frontend-test-utils'; - -jest.mock('@backstage/core-plugin-api', () => ({ - ...jest.requireActual('@backstage/core-plugin-api'), - useAnalytics: jest.fn(), -})); - -describe('createPageExtension', () => { - it('creates the extension properly', () => { - const configSchema: PortableSchema<{ path: string }> = { - parse: jest.fn(), - schema: {} as any, - }; - - expect( - createPageExtension({ - name: 'test', - configSchema, - loader: async () =>
, - }), - ).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - name: 'test', - kind: 'page', - attachTo: { id: 'app/routes', input: 'routes' }, - configSchema: expect.anything(), - disabled: false, - inputs: {}, - output: { - element: expect.anything(), - path: expect.anything(), - routeRef: expect.anything(), - }, - factory: expect.any(Function), - toString: expect.any(Function), - override: expect.any(Function), - }); - - expect( - createPageExtension({ - name: 'test', - attachTo: { id: 'other', input: 'place' }, - disabled: true, - configSchema, - inputs: { - first: createExtensionInput({ - element: coreExtensionData.reactElement, - }), - }, - loader: async () =>
, - }), - ).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - name: 'test', - kind: 'page', - attachTo: { id: 'other', input: 'place' }, - configSchema: expect.anything(), - override: expect.any(Function), - disabled: true, - inputs: { - first: createExtensionInput({ - element: coreExtensionData.reactElement, - }), - }, - output: { - element: expect.anything(), - path: expect.anything(), - routeRef: expect.anything(), - }, - factory: expect.any(Function), - toString: expect.any(Function), - }); - - expect( - createPageExtension({ - name: 'test', - defaultPath: '/here', - loader: async () =>
, - }), - ).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - name: 'test', - kind: 'page', - attachTo: { id: 'app/routes', input: 'routes' }, - configSchema: expect.anything(), - disabled: false, - inputs: {}, - output: { - element: expect.anything(), - path: expect.anything(), - routeRef: expect.anything(), - }, - factory: expect.any(Function), - toString: expect.any(Function), - override: expect.any(Function), - }); - }); - - it('capture page view event in analytics', async () => { - const captureEvent = jest.fn(); - - (useAnalytics as jest.Mock).mockReturnValue({ - captureEvent, - }); - - createExtensionTester( - createPageExtension({ - defaultPath: '/', - loader: async () =>
Component
, - }), - ).render(); - - await waitFor(() => - expect(captureEvent).toHaveBeenCalledWith( - '_ROUTABLE-EXTENSION-RENDERED', - '', - ), - ); - }); -}); diff --git a/packages/frontend-plugin-api/src/extensions/createPageExtension.tsx b/packages/frontend-plugin-api/src/extensions/createPageExtension.tsx deleted file mode 100644 index bef642e465..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createPageExtension.tsx +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2023 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, { lazy } from 'react'; -import { ExtensionBoundary } from '../components'; -import { createSchemaFromZod, PortableSchema } from '../schema'; -import { - coreExtensionData, - createExtension, - ResolvedExtensionInputs, - AnyExtensionInputMap, -} from '../wiring'; -import { RouteRef } from '../routing'; -import { Expand } from '../types'; -import { ExtensionDefinition } from '../wiring/createExtension'; - -/** - * Helper for creating extensions for a routable React page component. - * - * @public - * @deprecated Use {@link PageBlueprint} instead. - */ -export function createPageExtension< - TConfig extends { path: string }, - TInputs extends AnyExtensionInputMap, ->( - options: ( - | { - defaultPath: string; - } - | { - configSchema: PortableSchema; - } - ) & { - namespace?: string; - name?: string; - attachTo?: { id: string; input: string }; - disabled?: boolean; - inputs?: TInputs; - routeRef?: RouteRef; - loader: (options: { - config: TConfig; - inputs: Expand>; - }) => Promise; - }, -): ExtensionDefinition { - const configSchema = - 'configSchema' in options - ? options.configSchema - : (createSchemaFromZod(z => - z.object({ path: z.string().default(options.defaultPath) }), - ) as PortableSchema); - - return createExtension({ - kind: 'page', - namespace: options.namespace, - name: options.name, - attachTo: options.attachTo ?? { id: 'app/routes', input: 'routes' }, - configSchema, - inputs: options.inputs, - disabled: options.disabled, - output: { - element: coreExtensionData.reactElement, - path: coreExtensionData.routePath, - routeRef: coreExtensionData.routeRef.optional(), - }, - factory({ config, inputs, node }) { - const ExtensionComponent = lazy(() => - options - .loader({ config, inputs }) - .then(element => ({ default: () => element })), - ); - - return { - path: config.path, - routeRef: options.routeRef, - element: ( - - - - ), - }; - }, - }); -} diff --git a/packages/frontend-plugin-api/src/extensions/createRouterExtension.test.tsx b/packages/frontend-plugin-api/src/extensions/createRouterExtension.test.tsx deleted file mode 100644 index 2c16076fcf..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createRouterExtension.test.tsx +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright 2023 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 { createSpecializedApp } from '@backstage/frontend-app-api'; -import { render, screen } from '@testing-library/react'; -import React from 'react'; -import { MockConfigApi } from '@backstage/test-utils'; -import { MemoryRouter } from 'react-router-dom'; -import { createSchemaFromZod } from '../schema/createSchemaFromZod'; -import { coreExtensionData } from '../wiring/coreExtensionData'; -import { createExtension } from '../wiring/createExtension'; -import { createExtensionInput } from '../wiring/createExtensionInput'; -import { createExtensionOverrides } from '../wiring/createExtensionOverrides'; -import { createPageExtension } from './createPageExtension'; -import { createRouterExtension } from './createRouterExtension'; - -describe('createRouterExtension', () => { - it('works with simple options and no props', async () => { - const extension = createRouterExtension({ - namespace: 'test', - Component: ({ children }) => ( - -
{children}
-
- ), - }); - - expect(extension).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - kind: 'app-router-component', - namespace: 'test', - attachTo: { id: 'app/root', input: 'router' }, - disabled: false, - inputs: {}, - output: { - component: expect.anything(), - }, - factory: expect.any(Function), - override: expect.any(Function), - toString: expect.any(Function), - }); - - const app = createSpecializedApp({ - features: [ - createExtensionOverrides({ - extensions: [ - extension, - createPageExtension({ - namespace: 'test', - defaultPath: '/', - loader: async () =>
, - }), - ], - }), - ], - }); - - render(app.createRoot()); - - await expect( - screen.findByTestId('test-contents'), - ).resolves.toBeInTheDocument(); - await expect( - screen.findByTestId('test-router'), - ).resolves.toBeInTheDocument(); - }); - - it('works with complex options and props', async () => { - const schema = createSchemaFromZod(z => z.object({ name: z.string() })); - - const extension = createRouterExtension({ - namespace: 'test', - name: 'test', - configSchema: schema, - inputs: { - children: createExtensionInput({ - element: coreExtensionData.reactElement, - }), - }, - Component: ({ inputs, config, children }) => ( - -
- {children} -
-
- ), - }); - - expect(extension).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - kind: 'app-router-component', - namespace: 'test', - name: 'test', - attachTo: { id: 'app/root', input: 'router' }, - configSchema: schema, - disabled: false, - inputs: { - children: createExtensionInput({ - element: coreExtensionData.reactElement, - }), - }, - output: { - component: expect.anything(), - }, - factory: expect.any(Function), - override: expect.any(Function), - toString: expect.any(Function), - }); - - const app = createSpecializedApp({ - features: [ - createExtensionOverrides({ - extensions: [ - extension, - createExtension({ - namespace: 'test', - attachTo: { - id: 'app-router-component:test/test', - input: 'children', - }, - output: { element: coreExtensionData.reactElement }, // doesn't matter - factory: () => ({ element:
}), - }), - createPageExtension({ - namespace: 'test', - defaultPath: '/', - loader: async () =>
, - }), - ], - }), - ], - config: new MockConfigApi({ - app: { - extensions: [ - { - 'app-router-component:test/test': { config: { name: 'Robin' } }, - }, - ], - }, - }), - }); - - render(app.createRoot()); - - await expect( - screen.findByTestId('test-contents'), - ).resolves.toBeInTheDocument(); - await expect( - screen.findByTestId('test-router-Robin-1'), - ).resolves.toBeInTheDocument(); - }); -}); diff --git a/packages/frontend-plugin-api/src/extensions/createRouterExtension.tsx b/packages/frontend-plugin-api/src/extensions/createRouterExtension.tsx deleted file mode 100644 index 258940c694..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createRouterExtension.tsx +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2023 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, { ComponentType, PropsWithChildren } from 'react'; -import { PortableSchema } from '../schema/types'; -import { - AnyExtensionInputMap, - ExtensionDefinition, - ResolvedExtensionInputs, - createExtension, -} from '../wiring/createExtension'; -import { Expand } from '../types'; -import { RouterBlueprint } from '../blueprints/RouterBlueprint'; - -/** - * Creates an extension that replaces the router implementation at the app root. - * This is useful to be able to for example replace the BrowserRouter with a - * MemoryRouter in tests, or to add additional props to a BrowserRouter. - * - * @public - * @deprecated Use {@link RouterBlueprint} instead. - */ -export function createRouterExtension< - TConfig extends {}, - TInputs extends AnyExtensionInputMap, ->(options: { - namespace?: string; - name?: string; - attachTo?: { id: string; input: string }; - configSchema?: PortableSchema; - disabled?: boolean; - inputs?: TInputs; - Component: ComponentType< - PropsWithChildren<{ - inputs: Expand>; - config: TConfig; - }> - >; -}): ExtensionDefinition { - return createExtension({ - kind: 'app-router-component', - namespace: options.namespace, - name: options.name, - attachTo: options.attachTo ?? { id: 'app/root', input: 'router' }, - configSchema: options.configSchema, - disabled: options.disabled, - inputs: options.inputs, - output: { - component: RouterBlueprint.dataRefs.component, - }, - factory({ inputs, config }) { - const Component = (props: PropsWithChildren<{}>) => { - return ( - - {props.children} - - ); - }; - return { - component: Component, - }; - }, - }); -} - -/** - * @public - * @deprecated Use {@link RouterBlueprint} instead. - */ -export namespace createRouterExtension { - /** - * @deprecated Use {@link RouterBlueprint} instead. - */ - export const componentDataRef = RouterBlueprint.dataRefs.component; -} diff --git a/packages/frontend-plugin-api/src/extensions/createSignInPageExtension.test.tsx b/packages/frontend-plugin-api/src/extensions/createSignInPageExtension.test.tsx deleted file mode 100644 index d8835ae788..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createSignInPageExtension.test.tsx +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2023 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 { createExtensionTester } from '@backstage/frontend-test-utils'; -import { screen } from '@testing-library/react'; -import { createSignInPageExtension } from './createSignInPageExtension'; -import { coreExtensionData, createExtension } from '../wiring'; - -describe('createSignInPageExtension', () => { - it('renders a sign-in page', async () => { - const SignInPage = createSignInPageExtension({ - name: 'test', - loader: async () => () =>
, - }); - - createExtensionTester( - createExtension({ - name: 'dummy', - attachTo: { id: 'ignored', input: 'ignored' }, - output: { - element: coreExtensionData.reactElement, - }, - factory: () => ({ element:
}), - }), - ) - .add(SignInPage) - .render(); - - await expect( - screen.findByTestId('sign-in-page'), - ).resolves.toBeInTheDocument(); - }); -}); diff --git a/packages/frontend-plugin-api/src/extensions/createSignInPageExtension.tsx b/packages/frontend-plugin-api/src/extensions/createSignInPageExtension.tsx deleted file mode 100644 index 9c663b72f5..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createSignInPageExtension.tsx +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2023 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, { ComponentType, lazy } from 'react'; -import { ExtensionBoundary } from '../components'; -import { PortableSchema } from '../schema'; -import { - createExtension, - ResolvedExtensionInputs, - AnyExtensionInputMap, - ExtensionDefinition, -} from '../wiring'; -import { Expand } from '../types'; -import { SignInPageProps } from '@backstage/core-plugin-api'; -import { SignInPageBlueprint } from '../blueprints'; - -/** - * - * @public - * @deprecated Use {@link SignInPageBlueprint} instead. - */ -export function createSignInPageExtension< - TConfig extends {}, - TInputs extends AnyExtensionInputMap, ->(options: { - namespace?: string; - name?: string; - attachTo?: { id: string; input: string }; - configSchema?: PortableSchema; - disabled?: boolean; - inputs?: TInputs; - loader: (options: { - config: TConfig; - inputs: Expand>; - }) => Promise>; -}): ExtensionDefinition { - return createExtension({ - kind: 'sign-in-page', - namespace: options?.namespace, - name: options?.name, - attachTo: options.attachTo ?? { id: 'app/root', input: 'signInPage' }, - configSchema: options.configSchema, - inputs: options.inputs, - disabled: options.disabled, - output: { - component: createSignInPageExtension.componentDataRef, - }, - factory({ config, inputs, node }) { - const ExtensionComponent = lazy(() => - options - .loader({ config, inputs }) - .then(component => ({ default: component })), - ); - - return { - component: props => ( - - - - ), - }; - }, - }); -} - -/** - * @public - * @deprecated Use {@link SignInPageBlueprint} instead. - */ -export namespace createSignInPageExtension { - /** - * @deprecated Use {@link SignInPageBlueprint} instead. - */ - export const componentDataRef = SignInPageBlueprint.dataRefs.component; -} diff --git a/packages/frontend-plugin-api/src/extensions/createThemeExtension.ts b/packages/frontend-plugin-api/src/extensions/createThemeExtension.ts deleted file mode 100644 index 2662ebb39c..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createThemeExtension.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2023 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 { ThemeBlueprint } from '../blueprints/ThemeBlueprint'; -import { createExtension } from '../wiring'; -import { AppTheme } from '@backstage/core-plugin-api'; - -/** - * @public - * @deprecated Use {@link ThemeBlueprint} instead. - */ -export function createThemeExtension(theme: AppTheme) { - return createExtension({ - kind: 'theme', - namespace: 'app', - name: theme.id, - attachTo: { id: 'app', input: 'themes' }, - output: { - theme: ThemeBlueprint.dataRefs.theme, - }, - factory: () => ({ theme }), - }); -} - -/** - * @public - * @deprecated Use {@link ThemeBlueprint} instead. - */ -export namespace createThemeExtension { - export const themeDataRef = ThemeBlueprint.dataRefs.theme; -} diff --git a/packages/frontend-plugin-api/src/extensions/createTranslationExtension.test.ts b/packages/frontend-plugin-api/src/extensions/createTranslationExtension.test.ts deleted file mode 100644 index 019c565cbd..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createTranslationExtension.test.ts +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2023 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 { - createTranslationRef, - createTranslationMessages, - createTranslationResource, -} from '@backstage/core-plugin-api/alpha'; -import { createTranslationExtension } from './createTranslationExtension'; - -const translationRef = createTranslationRef({ - id: 'test', - messages: { - a: 'a', - b: 'b', - }, -}); - -describe('createTranslationExtension', () => { - it('creates a translation message extension', () => { - const messages = createTranslationMessages({ - ref: translationRef, - messages: { - a: 'A', - }, - }); - const extension = createTranslationExtension({ resource: messages }); - - expect(extension).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - kind: 'translation', - namespace: 'test', - attachTo: { id: 'app', input: 'translations' }, - disabled: false, - override: expect.any(Function), - inputs: {}, - output: { - resource: createTranslationExtension.translationDataRef, - }, - factory: expect.any(Function), - toString: expect.any(Function), - }); - - expect((extension as any).factory({} as any)).toEqual({ - resource: messages, - }); - }); - - it('creates a translation resource extension', () => { - const resource = createTranslationResource({ - ref: translationRef, - translations: { - sv: () => - Promise.resolve({ - default: createTranslationMessages({ - ref: translationRef, - messages: { - a: 'Ä', - b: 'Ö', - }, - }), - }), - }, - }); - const extension = createTranslationExtension({ resource }); - - expect(extension).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - kind: 'translation', - namespace: 'test', - attachTo: { id: 'app', input: 'translations' }, - disabled: false, - override: expect.any(Function), - inputs: {}, - output: { - resource: createTranslationExtension.translationDataRef, - }, - factory: expect.any(Function), - toString: expect.any(Function), - }); - - expect((extension as any).factory({} as any)).toEqual({ resource }); - }); - - it('creates a translation resource extension with a name', () => { - expect( - createTranslationExtension({ - name: 'sv', - resource: createTranslationResource({ - ref: translationRef, - translations: { - sv: () => - Promise.resolve({ - default: createTranslationMessages({ - ref: translationRef, - messages: { - a: 'Ä', - b: 'Ö', - }, - }), - }), - }, - }), - }), - ).toEqual({ - $$type: '@backstage/ExtensionDefinition', - version: 'v1', - kind: 'translation', - namespace: 'test', - override: expect.any(Function), - name: 'sv', - attachTo: { id: 'app', input: 'translations' }, - disabled: false, - inputs: {}, - output: { - resource: createTranslationExtension.translationDataRef, - }, - factory: expect.any(Function), - toString: expect.any(Function), - }); - }); -}); diff --git a/packages/frontend-plugin-api/src/extensions/createTranslationExtension.ts b/packages/frontend-plugin-api/src/extensions/createTranslationExtension.ts deleted file mode 100644 index 8a094cd593..0000000000 --- a/packages/frontend-plugin-api/src/extensions/createTranslationExtension.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2023 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 { TranslationBlueprint } from '../blueprints/TranslationBlueprint'; -import { TranslationMessages, TranslationResource } from '../translation'; -import { createExtension } from '../wiring'; - -/** - * @public - * @deprecated Use {@link TranslationBlueprint} instead. - */ -export function createTranslationExtension(options: { - name?: string; - resource: TranslationResource | TranslationMessages; -}) { - return createExtension({ - kind: 'translation', - namespace: options.resource.id, - name: options.name, - attachTo: { id: 'app', input: 'translations' }, - output: { - resource: TranslationBlueprint.dataRefs.translation, - }, - factory: () => ({ resource: options.resource }), - }); -} - -/** - * @public - * @deprecated Use {@link TranslationBlueprint} instead. - */ -export namespace createTranslationExtension { - export const translationDataRef = TranslationBlueprint.dataRefs.translation; -} diff --git a/packages/frontend-plugin-api/src/extensions/index.ts b/packages/frontend-plugin-api/src/extensions/index.ts index 562cb728cb..f75c7474ac 100644 --- a/packages/frontend-plugin-api/src/extensions/index.ts +++ b/packages/frontend-plugin-api/src/extensions/index.ts @@ -14,14 +14,4 @@ * limitations under the License. */ -export { createApiExtension } from './createApiExtension'; -export { createAppRootElementExtension } from './createAppRootElementExtension'; -export { createAppRootWrapperExtension } from './createAppRootWrapperExtension'; -export { createRouterExtension } from './createRouterExtension'; -export { createPageExtension } from './createPageExtension'; -export { createNavItemExtension } from './createNavItemExtension'; -export { createNavLogoExtension } from './createNavLogoExtension'; -export { createSignInPageExtension } from './createSignInPageExtension'; -export { createThemeExtension } from './createThemeExtension'; export { createComponentExtension } from './createComponentExtension'; -export { createTranslationExtension } from './createTranslationExtension';