frontend-plugin-api: make header actions a element[]

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2026-02-17 12:35:20 +01:00
parent c37e2bf6d4
commit b7ae1243e0
22 changed files with 47 additions and 46 deletions
@@ -14,9 +14,12 @@
* limitations under the License.
*/
import { ReactNode } from 'react';
import { JSX } from 'react';
import { type PluginHeaderActionsApi } from '@backstage/frontend-plugin-api';
// Stable reference
const EMPTY_ACTIONS = new Array<JSX.Element | null>();
type ActionInput = {
element: JSX.Element;
pluginId: string;
@@ -28,16 +31,18 @@ type ActionInput = {
* @internal
*/
export class DefaultPluginHeaderActionsApi implements PluginHeaderActionsApi {
constructor(private readonly actionsByPlugin: Map<string, ReactNode[]>) {}
constructor(
private readonly actionsByPlugin: Map<string, Array<JSX.Element | null>>,
) {}
getPluginHeaderActions(pluginId: string): ReactNode[] {
return this.actionsByPlugin.get(pluginId) ?? [];
getPluginHeaderActions(pluginId: string): Array<JSX.Element | null> {
return this.actionsByPlugin.get(pluginId) ?? EMPTY_ACTIONS;
}
static fromActions(
actions: Array<ActionInput>,
): DefaultPluginHeaderActionsApi {
const actionsByPlugin = new Map<string, ReactNode[]>();
const actionsByPlugin = new Map<string, Array<JSX.Element | null>>();
for (const action of actions) {
let pluginActions = actionsByPlugin.get(action.pluginId);