From 91a534142deaea27908d4bf6d63f811bc2c71625 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 1 Sep 2023 15:04:18 +0200 Subject: [PATCH] frontend-app-api: store attachemnts on extension instances MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fredrik Adelöw Co-authored-by: Philipp Hugenroth Co-authored-by: Johan Haals Signed-off-by: Patrik Oldsberg --- packages/frontend-app-api/src/createApp.tsx | 2 +- .../src/createExtensionInstance.ts | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/frontend-app-api/src/createApp.tsx b/packages/frontend-app-api/src/createApp.tsx index b3704fea4f..192e2485c6 100644 --- a/packages/frontend-app-api/src/createApp.tsx +++ b/packages/frontend-app-api/src/createApp.tsx @@ -83,7 +83,7 @@ export function createApp(options: { plugins: BackstagePlugin[] }): { return existingInstance; } - const attachments = Object.fromEntries( + const attachments = new Map( Array.from( attachmentMap.get(instanceParams.extension.id)?.entries() ?? [], ).map(([inputName, attachmentConfigs]) => [ diff --git a/packages/frontend-app-api/src/createExtensionInstance.ts b/packages/frontend-app-api/src/createExtensionInstance.ts index 911955f50a..a7c49d48cb 100644 --- a/packages/frontend-app-api/src/createExtensionInstance.ts +++ b/packages/frontend-app-api/src/createExtensionInstance.ts @@ -19,9 +19,16 @@ import mapValues from 'lodash/mapValues'; /** @internal */ export interface ExtensionInstance { - id: string; - data: Map; - $$type: 'extension-instance'; + readonly id: string; + /** + * Maps extension data ref IDs to extensions produced. + */ + readonly data: Map; + /** + * Maps input names to the actual instances given to them. + */ + readonly attachments: Map; + readonly $$type: 'extension-instance'; } /** @internal */ @@ -29,7 +36,7 @@ export function createExtensionInstance(options: { extension: Extension; config: unknown; source?: BackstagePlugin; - attachments: Record; + attachments: Map; }): ExtensionInstance { const { extension, config, source, attachments } = options; const extensionData = new Map(); @@ -54,7 +61,7 @@ export function createExtensionInstance(options: { extension.inputs, ({ extensionData: pointData }, inputName) => { // TODO: validation - return (attachments[inputName] ?? []).map(attachment => + return (attachments.get(inputName) ?? []).map(attachment => mapValues(pointData, ref => attachment.data.get(ref.id)), ); }, @@ -69,6 +76,7 @@ export function createExtensionInstance(options: { return { id: options.extension.id, data: extensionData, + attachments, $$type: 'extension-instance', }; }