feat(web): add global app status surface (#1869)
* feat(web): add app status bar * feat(web): add app status bar visibility toggle * feat(web): persist status bar item order * fix(web): refine app status bar behavior * fix(web): polish app status bar presentation * test(web): split plugin slot coverage groups * fix(web): address status surface review feedback * fix(web): stabilize status bar overlay tests
This commit is contained in:
@@ -65,7 +65,7 @@ export function PluginPageFrame({ registration, children }: PluginPageFrameProps
|
||||
const Icon = lookupPluginIcon(chrome.icon);
|
||||
const Actions = chrome.Actions;
|
||||
return (
|
||||
<div className="flex h-screen w-full flex-col bg-background">
|
||||
<div className="flex h-full min-h-0 w-full flex-col bg-background">
|
||||
<PageTopbar
|
||||
title={chrome.title}
|
||||
subtitle={chrome.subtitle}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import { act, cleanup, render, screen } from "@testing-library/react";
|
||||
import { useState } from "react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { pluginRegistry } from "@/lib/plugins/registry";
|
||||
import { PluginSlot } from "./plugin-slot";
|
||||
@@ -10,12 +11,12 @@ function cleanupPlugins(...pluginIds: string[]) {
|
||||
pluginIds.forEach((id) => pluginRegistry.unregisterPlugin(id));
|
||||
}
|
||||
|
||||
describe("PluginSlot", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
cleanupPlugins("plugin-a", "plugin-b");
|
||||
});
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
cleanupPlugins("plugin-a", "plugin-b", "plugin-c");
|
||||
});
|
||||
|
||||
describe("PluginSlot", () => {
|
||||
it("renders nothing when no plugin has registered a component for the slot", () => {
|
||||
const { container } = render(<PluginSlot name={SLOT} />);
|
||||
expect(container.innerHTML).toBe("");
|
||||
@@ -101,7 +102,9 @@ describe("PluginSlot", () => {
|
||||
expect(screen.getByTestId("slot-b")).not.toBeNull();
|
||||
consoleError.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
describe("PluginSlot registration identity", () => {
|
||||
it("isolates a throwing slot component so a sibling still renders", () => {
|
||||
// eslint-disable-next-line no-console -- expected error boundary log, assert + silence it
|
||||
const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
@@ -116,6 +119,69 @@ describe("PluginSlot", () => {
|
||||
render(<PluginSlot name={SLOT} />);
|
||||
|
||||
expect(screen.getByTestId("slot-b")).not.toBeNull();
|
||||
expect(consoleError).toHaveBeenCalledWith(
|
||||
'[plugins] plugin "plugin-a" slot "task-sidebar" component threw',
|
||||
expect.any(Error),
|
||||
expect.any(String),
|
||||
);
|
||||
consoleError.mockRestore();
|
||||
});
|
||||
|
||||
it("does not give a healthy plugin the removed plugin's error state", () => {
|
||||
// eslint-disable-next-line no-console -- expected error boundary log, assert + silence it
|
||||
const consoleError = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
|
||||
pluginRegistry.forPlugin("plugin-a").registerComponent(SLOT, () => {
|
||||
throw new Error("boom");
|
||||
});
|
||||
pluginRegistry
|
||||
.forPlugin("plugin-b")
|
||||
.registerComponent(SLOT, () => <div data-testid="slot-b">B</div>);
|
||||
|
||||
render(<PluginSlot name={SLOT} />);
|
||||
|
||||
act(() => {
|
||||
pluginRegistry.unregisterPlugin("plugin-a");
|
||||
});
|
||||
|
||||
expect(screen.getByTestId("slot-b")).not.toBeNull();
|
||||
consoleError.mockRestore();
|
||||
});
|
||||
|
||||
it("keeps healthy plugin component identity through live slot changes", () => {
|
||||
let nextMountId = 0;
|
||||
function StatefulSlot({ id }: { id: string }) {
|
||||
const [mountId] = useState(() => ++nextMountId);
|
||||
return <div data-testid={id}>{mountId}</div>;
|
||||
}
|
||||
|
||||
pluginRegistry
|
||||
.forPlugin("plugin-a")
|
||||
.registerComponent(SLOT, () => <StatefulSlot id="slot-a" />);
|
||||
pluginRegistry
|
||||
.forPlugin("plugin-b")
|
||||
.registerComponent(SLOT, () => <StatefulSlot id="slot-b" />);
|
||||
|
||||
render(<PluginSlot name={SLOT} />);
|
||||
|
||||
expect(screen.getByTestId("slot-a").textContent).toBe("1");
|
||||
expect(screen.getByTestId("slot-b").textContent).toBe("2");
|
||||
|
||||
act(() => {
|
||||
pluginRegistry
|
||||
.forPlugin("plugin-c")
|
||||
.registerComponent(SLOT, () => <StatefulSlot id="slot-c" />);
|
||||
});
|
||||
|
||||
expect(screen.getByTestId("slot-a").textContent).toBe("1");
|
||||
expect(screen.getByTestId("slot-b").textContent).toBe("2");
|
||||
expect(screen.getByTestId("slot-c").textContent).toBe("3");
|
||||
|
||||
act(() => {
|
||||
pluginRegistry.unregisterPlugin("plugin-a");
|
||||
});
|
||||
|
||||
expect(screen.getByTestId("slot-b").textContent).toBe("2");
|
||||
expect(screen.getByTestId("slot-c").textContent).toBe("3");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { usePluginRegistry } from "@/lib/plugins/registry";
|
||||
import type { SlotComponent } from "@/lib/plugins/types";
|
||||
import type { PluginSlotRegistration } from "@/lib/plugins/registry";
|
||||
import { PluginErrorBoundary } from "./plugin-error-boundary";
|
||||
|
||||
export type PluginSlotProps = {
|
||||
@@ -26,22 +26,39 @@ export type PluginSlotProps = {
|
||||
*/
|
||||
export function PluginSlot({ name, slotProps, ownerPluginId }: PluginSlotProps) {
|
||||
const registry = usePluginRegistry();
|
||||
const components = ownerPluginId
|
||||
? registry.getSlotComponentsForPlugin(name, ownerPluginId)
|
||||
: registry.getSlotComponents(name);
|
||||
const registrations = registry
|
||||
.getSlotRegistrations(name)
|
||||
.filter((registration) => !ownerPluginId || registration.pluginId === ownerPluginId);
|
||||
|
||||
if (components.length === 0) return null;
|
||||
|
||||
// Key by owner too, so navigating A -> B resets the boundary instead of reusing A's error (hiding B).
|
||||
const keyBase = ownerPluginId ? `${name}-${ownerPluginId}` : name;
|
||||
if (registrations.length === 0) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
{components.map((SlotComponentImpl: SlotComponent, index) => (
|
||||
<PluginErrorBoundary key={`${keyBase}-${index}`} context={`slot "${name}" component`}>
|
||||
<SlotComponentImpl slotProps={slotProps} />
|
||||
</PluginErrorBoundary>
|
||||
{registrations.map((registration) => (
|
||||
<PluginSlotRegistrationView
|
||||
key={registration.registrationId}
|
||||
registration={registration}
|
||||
name={name}
|
||||
slotProps={slotProps}
|
||||
/>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function PluginSlotRegistrationView({
|
||||
registration,
|
||||
name,
|
||||
slotProps,
|
||||
}: {
|
||||
registration: PluginSlotRegistration;
|
||||
name: string;
|
||||
slotProps?: unknown;
|
||||
}) {
|
||||
const { pluginId, Component } = registration;
|
||||
return (
|
||||
<PluginErrorBoundary context={`plugin "${pluginId}" slot "${name}" component`}>
|
||||
<Component slotProps={slotProps} />
|
||||
</PluginErrorBoundary>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user