diff --git a/packages/frontend-app-api/package.json b/packages/frontend-app-api/package.json index ce68871133..c3564c31c4 100644 --- a/packages/frontend-app-api/package.json +++ b/packages/frontend-app-api/package.json @@ -32,10 +32,11 @@ "dependencies": { "@backstage/config": "workspace:^", "@backstage/frontend-plugin-api": "workspace:^", - "@backstage/plugin-graphiql": "workspace:^" + "@backstage/plugin-graphiql": "workspace:^", + "lodash": "^4.17.21" }, "peerDependencies": { - "react": "*", - "react-router-dom": "*" + "react": "^16.13.1 || ^17.0.0", + "react-router-dom": "6.0.0-beta.0 || ^6.3.0" } } diff --git a/packages/frontend-app-api/src/createApp.tsx b/packages/frontend-app-api/src/createApp.tsx index 9c06ed2902..46cd0a7aed 100644 --- a/packages/frontend-app-api/src/createApp.tsx +++ b/packages/frontend-app-api/src/createApp.tsx @@ -19,11 +19,13 @@ import { Config, ConfigReader } from '@backstage/config'; import { ExtensionInstanceConfig, BackstagePlugin, - ExtensionInstance, - createExtensionInstance, coreExtensionData, } from '@backstage/frontend-plugin-api'; import { RouteExtension } from './extensions/RouteExtension'; +import { + createExtensionInstance, + ExtensionInstance, +} from './createExtensionInstance'; // Since we'll never merge arrays in config the config reader context // isn't too much of a help. Fall back to manual config reading logic diff --git a/packages/frontend-app-api/src/createExtensionInstance.ts b/packages/frontend-app-api/src/createExtensionInstance.ts new file mode 100644 index 0000000000..0b62df74ae --- /dev/null +++ b/packages/frontend-app-api/src/createExtensionInstance.ts @@ -0,0 +1,52 @@ +/* + * 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 { Extension } from '@backstage/frontend-plugin-api'; +import mapValues from 'lodash/mapValues'; + +/** @internal */ +export interface ExtensionInstance { + id: string; + data: Map; + $$type: 'extension-instance'; +} + +/** @internal */ +export function createExtensionInstance(options: { + id: string; + extension: Extension; + config: unknown; + attachments: Record; +}): ExtensionInstance { + const { extension, config, attachments } = options; + const extensionData = new Map(); + extension.factory({ + config, + bind: mapValues(extension.output, ref => { + return (value: unknown) => extensionData.set(ref.id, value); + }), + inputs: mapValues( + extension.inputs, + ({ extensionData: pointData }, inputName) => { + // TODO: validation + return (attachments[inputName] ?? []).map(attachment => + mapValues(pointData, ref => attachment.data.get(ref.id)), + ); + }, + ), + }); + return { id: options.id, data: extensionData, $$type: 'extension-instance' }; +} diff --git a/packages/frontend-plugin-api/api-report.md b/packages/frontend-plugin-api/api-report.md index 660662599b..4337b0b8c2 100644 --- a/packages/frontend-plugin-api/api-report.md +++ b/packages/frontend-plugin-api/api-report.md @@ -43,14 +43,6 @@ export function createExtension< >, >(options: CreateExtensionOptions): Extension; -// @public (undocumented) -export function createExtensionInstance(options: { - id: string; - extension: Extension; - config: unknown; - attachments: Record; -}): ExtensionInstance; - // @public (undocumented) export interface CreateExtensionOptions< TData extends AnyExtensionDataMap, @@ -106,9 +98,6 @@ export type ExtensionDataBind = { [K in keyof TData]: (value: TData[K]['T']) => void; }; -// @public (undocumented) -export type ExtensionDataId = string; - // @public (undocumented) export type ExtensionDataRef = { id: string; @@ -121,16 +110,6 @@ export type ExtensionDataValue = { [K in keyof TData]: TData[K]['T']; }; -// @public (undocumented) -export interface ExtensionInstance { - // (undocumented) - $$type: 'extension-instance'; - // (undocumented) - data: Map; - // (undocumented) - id: string; -} - // @public (undocumented) export interface ExtensionInstanceConfig { // (undocumented) diff --git a/packages/frontend-plugin-api/src/index.ts b/packages/frontend-plugin-api/src/index.ts index dbc5e130e7..e36391131d 100644 --- a/packages/frontend-plugin-api/src/index.ts +++ b/packages/frontend-plugin-api/src/index.ts @@ -22,18 +22,15 @@ export { createExtension, - createExtensionInstance, coreExtensionData, createPlugin, type ExtensionInstanceConfig, type BackstagePlugin, - type ExtensionInstance, type Extension, type AnyExtensionDataMap, type BackstagePluginOptions, type CreateExtensionOptions, type ExtensionDataBind, - type ExtensionDataId, type ExtensionDataRef, type ExtensionDataValue, } from './types'; diff --git a/packages/frontend-plugin-api/src/types.ts b/packages/frontend-plugin-api/src/types.ts index cb5bce0af9..b2d131c62f 100644 --- a/packages/frontend-plugin-api/src/types.ts +++ b/packages/frontend-plugin-api/src/types.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import mapValues from 'lodash/mapValues'; import { ComponentType } from 'react'; /** @public */ @@ -86,43 +85,6 @@ export function createExtension< return { ...options, $$type: 'extension', inputs: options.inputs ?? {} }; } -/** @public */ -export type ExtensionDataId = string; - -/** @public */ -export interface ExtensionInstance { - id: string; - data: Map; - $$type: 'extension-instance'; -} - -/** @public */ -export function createExtensionInstance(options: { - id: string; - extension: Extension; - config: unknown; - attachments: Record; -}): ExtensionInstance { - const { extension, config, attachments } = options; - const extensionData = new Map(); - extension.factory({ - config, - bind: mapValues(extension.output, ref => { - return (value: unknown) => extensionData.set(ref.id, value); - }), - inputs: mapValues( - extension.inputs, - ({ extensionData: pointData }, inputName) => { - // TODO: validation - return (attachments[inputName] ?? []).map(attachment => - mapValues(pointData, ref => attachment.data.get(ref.id)), - ); - }, - ), - }); - return { id: options.id, data: extensionData, $$type: 'extension-instance' }; -} - /** @public */ export interface ExtensionInstanceConfig { id: string; diff --git a/yarn.lock b/yarn.lock index 6e4b036475..0bfbe3d111 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4069,9 +4069,10 @@ __metadata: "@backstage/frontend-plugin-api": "workspace:^" "@backstage/plugin-graphiql": "workspace:^" "@testing-library/jest-dom": ^5.10.1 + lodash: ^4.17.21 peerDependencies: - react: "*" - react-router-dom: "*" + react: ^16.13.1 || ^17.0.0 + react-router-dom: 6.0.0-beta.0 || ^6.3.0 languageName: unknown linkType: soft