fix(ui): move task plugins into mobile menu
Move task plugin actions and destinations into the shared mobile Plugins menu, preserving a compact task header and accessible touch targets. Add focused mobile coverage, plugin authoring documentation, and process-probe stability handling.
This commit is contained in:
@@ -1,30 +1,71 @@
|
||||
import { cleanup, render, screen } from "@testing-library/react";
|
||||
import type { ReactNode } from "react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { pluginRegistry } from "@/lib/plugins/registry";
|
||||
import { MobilePluginNavSection } from "./mobile-plugin-nav-section";
|
||||
|
||||
const HELLO_PATH = "/plugins/hello";
|
||||
const HELLO_ITEM_TEST_ID = "mobile-plugin-nav-item-hello";
|
||||
|
||||
vi.mock("@/lib/routing/client-router", () => ({
|
||||
usePathname: () => "/",
|
||||
}));
|
||||
|
||||
function renderSection(onNavigate = () => {}) {
|
||||
return render(<MobilePluginNavSection onNavigate={onNavigate} />);
|
||||
function renderSection(onNavigate = () => {}, actions?: ReactNode, includeDestinations = true) {
|
||||
return render(
|
||||
<MobilePluginNavSection
|
||||
actions={actions}
|
||||
includeDestinations={includeDestinations}
|
||||
onNavigate={onNavigate}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("MobilePluginNavSection", () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
["plugin-a", "plugin-b"].forEach((id) => pluginRegistry.unregisterPlugin(id));
|
||||
window.history.pushState({}, "", "/");
|
||||
});
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
["plugin-a", "plugin-b"].forEach((id) => pluginRegistry.unregisterPlugin(id));
|
||||
window.history.pushState({}, "", "/");
|
||||
});
|
||||
|
||||
describe("MobilePluginNavSection actions", () => {
|
||||
it("renders nothing when no plugin has registered a nav item", () => {
|
||||
const { container } = renderSection();
|
||||
expect(container.innerHTML).toBe("");
|
||||
});
|
||||
|
||||
it("renders page actions without requiring a plugin destination", () => {
|
||||
const onNavigate = vi.fn();
|
||||
renderSection(
|
||||
onNavigate,
|
||||
<button type="button" data-testid="session-plugin-action">
|
||||
Session action
|
||||
</button>,
|
||||
);
|
||||
|
||||
const section = screen.getByTestId("mobile-plugin-nav-section");
|
||||
const action = screen.getByTestId("session-plugin-action");
|
||||
expect(section.contains(action)).toBe(true);
|
||||
action.click();
|
||||
expect(onNavigate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("combines page actions and destinations under one Plugins heading", () => {
|
||||
pluginRegistry
|
||||
.forPlugin("plugin-a")
|
||||
.registerNavItem({ id: "hello", label: "Hello", path: HELLO_PATH });
|
||||
|
||||
renderSection(() => {}, <span data-testid="session-plugin-status">Connected</span>);
|
||||
|
||||
expect(screen.getAllByText("Plugins")).toHaveLength(1);
|
||||
const action = screen.getByTestId("session-plugin-status");
|
||||
const destination = screen.getByTestId(HELLO_ITEM_TEST_ID);
|
||||
expect(
|
||||
action.compareDocumentPosition(destination) & Node.DOCUMENT_POSITION_FOLLOWING,
|
||||
).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("MobilePluginNavSection destinations", () => {
|
||||
it("renders main-section nav items so plugin pages are reachable on a phone", () => {
|
||||
pluginRegistry
|
||||
.forPlugin("plugin-a")
|
||||
@@ -33,7 +74,7 @@ describe("MobilePluginNavSection", () => {
|
||||
renderSection();
|
||||
|
||||
expect(screen.getByTestId("mobile-plugin-nav-section")).not.toBeNull();
|
||||
expect(screen.getByTestId("mobile-plugin-nav-item-hello")).not.toBeNull();
|
||||
expect(screen.getByTestId(HELLO_ITEM_TEST_ID)).not.toBeNull();
|
||||
expect(screen.getByText("Hello")).not.toBeNull();
|
||||
});
|
||||
|
||||
@@ -97,7 +138,7 @@ describe("MobilePluginNavSection", () => {
|
||||
renderSection();
|
||||
|
||||
expect(
|
||||
screen.getByTestId("mobile-plugin-nav-item-hello").querySelector("svg.tabler-icon-ticket"),
|
||||
screen.getByTestId(HELLO_ITEM_TEST_ID).querySelector("svg.tabler-icon-ticket"),
|
||||
).not.toBeNull();
|
||||
expect(
|
||||
screen.getByTestId("mobile-plugin-nav-item-other").querySelector("svg.tabler-icon-puzzle"),
|
||||
@@ -111,7 +152,7 @@ describe("MobilePluginNavSection", () => {
|
||||
.registerNavItem({ id: "hello", label: "Hello", path: HELLO_PATH });
|
||||
|
||||
renderSection(onNavigate);
|
||||
screen.getByTestId("mobile-plugin-nav-item-hello").click();
|
||||
screen.getByTestId(HELLO_ITEM_TEST_ID).click();
|
||||
|
||||
expect(window.location.pathname).toBe(HELLO_PATH);
|
||||
expect(onNavigate).toHaveBeenCalledTimes(1);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { DestinationRows } from "@/components/navigation/destination-rows";
|
||||
import { resolveDestinations } from "@/lib/navigation/resolve-destinations";
|
||||
@@ -9,6 +10,10 @@ import { usePluginRegistry } from "@/lib/plugins/registry";
|
||||
type MobilePluginNavSectionProps = {
|
||||
/** Closes the surrounding menu sheet once a plugin page is opened. */
|
||||
onNavigate: () => void;
|
||||
/** Page-scoped plugin status and controls for this menu. */
|
||||
actions?: ReactNode;
|
||||
/** Custom sidebar layouts already place plugin destinations themselves. */
|
||||
includeDestinations?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -19,29 +24,38 @@ type MobilePluginNavSectionProps = {
|
||||
* entry point at all. "integrations"-section items keep rendering inside
|
||||
* `MobileIntegrationsSection`.
|
||||
*/
|
||||
export function MobilePluginNavSection({ onNavigate }: MobilePluginNavSectionProps) {
|
||||
export function MobilePluginNavSection({
|
||||
onNavigate,
|
||||
actions,
|
||||
includeDestinations = true,
|
||||
}: MobilePluginNavSectionProps) {
|
||||
const { t } = useTranslation();
|
||||
const registry = usePluginRegistry();
|
||||
// Resolved directly rather than through `useStaticDestinations`: this group's
|
||||
// hrefs are static plugin paths, so it needs neither workspace context nor the
|
||||
// availability subscription. Matches the desktop rail in `plugin-nav-items.tsx`.
|
||||
const destinations = resolveDestinations({
|
||||
surface: "mobileMenu",
|
||||
section: "plugins",
|
||||
ctx: NO_WORKSPACE_CONTEXT,
|
||||
pluginItems: registry.getNavRegistrations(),
|
||||
});
|
||||
const destinations = includeDestinations
|
||||
? resolveDestinations({
|
||||
surface: "mobileMenu",
|
||||
section: "plugins",
|
||||
ctx: NO_WORKSPACE_CONTEXT,
|
||||
pluginItems: registry.getNavRegistrations(),
|
||||
})
|
||||
: [];
|
||||
|
||||
if (destinations.length === 0) return null;
|
||||
if (!actions && destinations.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="space-y-3" data-testid="mobile-plugin-nav-section">
|
||||
<div className="text-sm font-medium">{t("common:plugins")}</div>
|
||||
<DestinationRows
|
||||
destinations={destinations}
|
||||
onNavigate={onNavigate}
|
||||
pluginTestIdPrefix="mobile-plugin-nav-item-"
|
||||
/>
|
||||
{actions}
|
||||
{destinations.length > 0 && (
|
||||
<DestinationRows
|
||||
destinations={destinations}
|
||||
onNavigate={onNavigate}
|
||||
pluginTestIdPrefix="mobile-plugin-nav-item-"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user