frontend-plugin-api: switch extension factory to receive node instead of spec

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-11-21 20:30:41 +01:00
parent 08db02eda5
commit cc1fea7d05
4 changed files with 62 additions and 59 deletions
@@ -20,7 +20,7 @@ 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';
import { AppNode } from '../apis';
type RouteTrackerProps = PropsWithChildren<{
disableTracking?: boolean;
@@ -44,24 +44,24 @@ const RouteTracker = (props: RouteTrackerProps) => {
/** @public */
export interface ExtensionBoundaryProps {
spec: AppNodeSpec;
node: AppNode;
routable?: boolean;
children: ReactNode;
}
/** @public */
export function ExtensionBoundary(props: ExtensionBoundaryProps) {
const { spec, routable, children } = props;
const { node, routable, children } = props;
// Skipping "routeRef" attribute in the new system, the extension "id" should provide more insight
const attributes = {
extension: spec.id,
pluginId: spec.source?.id,
extension: node.spec.id,
pluginId: node.spec.source?.id,
};
return (
<ExtensionSuspense>
<ErrorBoundary plugin={spec.source}>
<ErrorBoundary plugin={node.spec.source}>
<AnalyticsContext attributes={attributes}>
<RouteTracker disableTracking={!routable}>{children}</RouteTracker>
</AnalyticsContext>
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { AppNodeSpec } from '../apis';
import { AppNode } from '../apis';
import { PortableSchema } from '../schema';
import { Expand } from '../types';
import { ExtensionDataRef } from './createExtensionDataRef';
@@ -80,7 +80,7 @@ export interface CreateExtensionOptions<
output: TOutput;
configSchema?: PortableSchema<TConfig>;
factory(options: {
spec: AppNodeSpec;
node: AppNode;
config: TConfig;
inputs: Expand<ExtensionInputValues<TInputs>>;
}): Expand<ExtensionDataValues<TOutput>>;
@@ -96,7 +96,7 @@ export interface Extension<TConfig> {
output: AnyExtensionDataMap;
configSchema?: PortableSchema<TConfig>;
factory(options: {
spec: AppNodeSpec;
node: AppNode;
config: TConfig;
inputs: Record<
string,