frontend-plugin-api: refactor extension factory to receive spec instead of id + source
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -103,7 +103,7 @@ export function createAppNodeInstance(options: {
|
||||
attachments: ReadonlyMap<string, { id: string; instance: AppNodeInstance }[]>;
|
||||
}): AppNodeInstance {
|
||||
const { spec, attachments } = options;
|
||||
const { id, extension, config, source } = spec;
|
||||
const { id, extension, config } = spec;
|
||||
const extensionData = new Map<string, unknown>();
|
||||
const extensionDataRefs = new Set<ExtensionDataRef<unknown>>();
|
||||
|
||||
@@ -118,7 +118,7 @@ export function createAppNodeInstance(options: {
|
||||
|
||||
try {
|
||||
const namedOutputs = extension.factory({
|
||||
source,
|
||||
spec,
|
||||
config: parsedConfig,
|
||||
inputs: resolveInputs(extension.inputs, attachments),
|
||||
});
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
import React, { PropsWithChildren, ReactNode, useEffect } from 'react';
|
||||
import { AnalyticsContext, useAnalytics } from '@backstage/core-plugin-api';
|
||||
import { BackstagePlugin } from '../wiring';
|
||||
import { ErrorBoundary } from './ErrorBoundary';
|
||||
import { ExtensionSuspense } from './ExtensionSuspense';
|
||||
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
|
||||
import { routableExtensionRenderedEvent } from '../../../core-plugin-api/src/analytics/Tracker';
|
||||
import { AppNodeSpec } from '../apis';
|
||||
|
||||
type RouteTrackerProps = PropsWithChildren<{
|
||||
disableTracking?: boolean;
|
||||
@@ -44,25 +44,24 @@ const RouteTracker = (props: RouteTrackerProps) => {
|
||||
|
||||
/** @public */
|
||||
export interface ExtensionBoundaryProps {
|
||||
id: string;
|
||||
source?: BackstagePlugin;
|
||||
spec: AppNodeSpec;
|
||||
routable?: boolean;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export function ExtensionBoundary(props: ExtensionBoundaryProps) {
|
||||
const { id, source, routable, children } = props;
|
||||
const { spec, routable, children } = props;
|
||||
|
||||
// Skipping "routeRef" attribute in the new system, the extension "id" should provide more insight
|
||||
const attributes = {
|
||||
extension: id,
|
||||
pluginId: source?.id,
|
||||
extension: spec.id,
|
||||
pluginId: spec.source?.id,
|
||||
};
|
||||
|
||||
return (
|
||||
<ExtensionSuspense>
|
||||
<ErrorBoundary plugin={source}>
|
||||
<ErrorBoundary plugin={spec.source}>
|
||||
<AnalyticsContext attributes={attributes}>
|
||||
<RouteTracker disableTracking={!routable}>{children}</RouteTracker>
|
||||
</AnalyticsContext>
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AppNodeSpec } from '../apis';
|
||||
import { PortableSchema } from '../schema';
|
||||
import { Expand } from '../types';
|
||||
import { ExtensionDataRef } from './createExtensionDataRef';
|
||||
import { ExtensionInput } from './createExtensionInput';
|
||||
import { BackstagePlugin } from './createPlugin';
|
||||
|
||||
/** @public */
|
||||
export type AnyExtensionDataMap = {
|
||||
@@ -80,7 +80,7 @@ export interface CreateExtensionOptions<
|
||||
output: TOutput;
|
||||
configSchema?: PortableSchema<TConfig>;
|
||||
factory(options: {
|
||||
source?: BackstagePlugin;
|
||||
spec: AppNodeSpec;
|
||||
config: TConfig;
|
||||
inputs: Expand<ExtensionInputValues<TInputs>>;
|
||||
}): Expand<ExtensionDataValues<TOutput>>;
|
||||
@@ -96,7 +96,7 @@ export interface Extension<TConfig> {
|
||||
output: AnyExtensionDataMap;
|
||||
configSchema?: PortableSchema<TConfig>;
|
||||
factory(options: {
|
||||
source?: BackstagePlugin;
|
||||
spec: AppNodeSpec;
|
||||
config: TConfig;
|
||||
inputs: Record<
|
||||
string,
|
||||
|
||||
Reference in New Issue
Block a user