refactor(home): bundle widget data into single extension ref

Following FormFieldBlueprint pattern, bundle component and metadata
into a single comprehensive homePageWidgetDataRef instead of outputting
them separately. This addresses review feedback about outputting data
that nothing consumes.
- Create homePageWidgetDataRef in plugin-home-react
- Update HomepageWidgetBlueprint to output bundled data
- Update HomepageBlueprint to consume bundled data and extract component
- Remove unused widgetMetadataRef export
Signed-off-by: Adam Kunicki <kunickiaj@gmail.com>
This commit is contained in:
Adam Kunicki
2025-10-26 19:25:02 -07:00
parent 66f29d2921
commit aeae90c969
4 changed files with 77 additions and 23 deletions
+4 -1
View File
@@ -26,7 +26,10 @@
export { homeReactTranslationRef } from './translation';
export {
HomepageWidgetBlueprint,
widgetMetadataRef,
type HomepageWidgetBlueprintParams,
} from './alpha/blueprints/HomepageWidgetBlueprint';
export {
homePageWidgetDataRef,
type HomePageWidgetData,
} from './alpha/dataRefs';
export type { ComponentParts, CardLayout, CardSettings } from './extensions';
@@ -17,9 +17,7 @@
import { lazy, ReactElement } from 'react';
import { compatWrapper } from '@backstage/core-compat-api';
import {
coreExtensionData,
createExtensionBlueprint,
createExtensionDataRef,
ExtensionBoundary,
} from '@backstage/frontend-plugin-api';
import {
@@ -29,6 +27,7 @@ import {
CardSettings,
ComponentParts,
} from '../../extensions';
import { homePageWidgetDataRef } from '../dataRefs';
/** @alpha */
export interface HomepageWidgetBlueprintParams {
@@ -68,18 +67,6 @@ const DEFAULT_WIDGET_ATTACH_POINT = {
input: 'widgets',
} as const;
/**
* Extension data ref for widget metadata.
* @alpha
*/
export const widgetMetadataRef = createExtensionDataRef<{
name?: string;
title?: string;
description?: string;
layout?: CardLayout;
settings?: CardSettings;
}>().with({ id: 'home.widget.metadata' });
/**
* Creates widgets that can be installed into the home page grid.
*
@@ -88,7 +75,7 @@ export const widgetMetadataRef = createExtensionDataRef<{
export const HomepageWidgetBlueprint = createExtensionBlueprint({
kind: 'home-widget',
attachTo: DEFAULT_WIDGET_ATTACH_POINT,
output: [coreExtensionData.reactElement, widgetMetadataRef],
output: [homePageWidgetDataRef],
*factory(params: HomepageWidgetBlueprintParams, { node }) {
const isCustomizable = params.settings?.schema !== undefined;
const LazyCard = lazy(() =>
@@ -113,11 +100,8 @@ export const HomepageWidgetBlueprint = createExtensionBlueprint({
</ExtensionBoundary>,
);
yield coreExtensionData.reactElement(
<Widget {...(params.componentProps ?? {})} />,
);
yield widgetMetadataRef({
yield homePageWidgetDataRef({
component: <Widget {...(params.componentProps ?? {})} />,
name: params.name,
title: params.title,
description: params.description,
+66
View File
@@ -0,0 +1,66 @@
/*
* Copyright 2025 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 { createExtensionDataRef } from '@backstage/frontend-plugin-api';
import { ReactElement } from 'react';
import type { CardLayout, CardSettings } from '../extensions';
/**
* Extension data for homepage widgets, bundling the rendered component
* with its metadata.
*
* @alpha
*/
export interface HomePageWidgetData {
/**
* The rendered widget component (typically a card with header, content, etc.)
*/
component: ReactElement;
/**
* Optional name identifier for the widget
*/
name?: string;
/**
* Optional title displayed in the widget header
*/
title?: string;
/**
* Optional description shown in widget catalogs or configuration UIs
*/
description?: string;
/**
* Optional layout hints for positioning and sizing
*/
layout?: CardLayout;
/**
* Optional settings schema for widget configuration
*/
settings?: CardSettings;
}
/**
* Extension data ref for homepage widgets.
*
* This follows the pattern from FormFieldBlueprint, bundling the component
* and metadata into a single comprehensive data ref rather than outputting
* them separately.
*
* @alpha
*/
export const homePageWidgetDataRef =
createExtensionDataRef<HomePageWidgetData>().with({
id: 'home.widget.data',
});