side-pane-plugin-menu.fixture.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { useRef, useState } from "react";
  2. import { createRoot } from "react-dom/client";
  3. import type { IServiceAccessor } from "@zcode/services";
  4. import { AnimatedSidePanePanel } from "@/app-shell/AnimatedSidePanePanel.js";
  5. import { ResizablePanel, ResizablePanelGroup } from "@/components/ui/resizable.js";
  6. import { TooltipProvider } from "@/components/ui/tooltip.js";
  7. import { ServiceProvider } from "@/hooks/useServices.js";
  8. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  9. import { PluginUiWorkspaceProvider, openPluginUiSidePane } from "@/plugin-ui/index.js";
  10. import type { OpenPluginUiSideTabRequest } from "@/plugin-ui/contract.js";
  11. import type { WorkspaceSidePaneState } from "@/lib/workspaceSidePane.js";
  12. import type { PanelImperativeHandle } from "react-resizable-panels";
  13. import "@/styles.css";
  14. const params = new URLSearchParams(location.search);
  15. document.documentElement.classList.add(`theme-zai-${params.get("theme") ?? "light"}`);
  16. const workspacePath = "/workspace/example";
  17. const workspaceIdentity = "fixture-workspace";
  18. const remoteSessionId = "fixture-remote-session";
  19. const noop = () => {};
  20. const services = (params.has("noBridge")
  21. ? {}
  22. : {
  23. pluginUiBridgeService: {
  24. listSurfaces: async (scope: unknown) => {
  25. const response = await fetch("/surfaces", {
  26. method: "POST",
  27. body: JSON.stringify(scope),
  28. });
  29. return response.json();
  30. },
  31. },
  32. }) as unknown as IServiceAccessor;
  33. const existingTab: WorkspaceSidePaneState = {
  34. activeTabId: "whiteboard:fixture",
  35. tabs: [
  36. {
  37. id: "whiteboard:fixture",
  38. type: "whiteboard",
  39. boardId: "fixture",
  40. title: "Existing",
  41. ownerTaskId: "session-fixture",
  42. },
  43. ],
  44. };
  45. function Fixture() {
  46. const [hasTab, setHasTab] = useState(params.has("existing"));
  47. const [request, setRequest] = useState<OpenPluginUiSideTabRequest | null>(null);
  48. const [opened, setOpened] = useState<WorkspaceSidePaneState | null>(null);
  49. const panelRef = useRef<PanelImperativeHandle | null>(null);
  50. const panelElementRef = useRef<HTMLDivElement | null>(null);
  51. // 本测试在 tab owner 边界验收命令与去重;沙箱/Agent 不属于菜单交互回归。
  52. const open = (next: OpenPluginUiSideTabRequest) => {
  53. setRequest(next);
  54. setOpened((current) =>
  55. openPluginUiSidePane(current, { ...next, workspaceKey: workspaceIdentity }),
  56. );
  57. };
  58. const panel = (
  59. <AnimatedSidePanePanel
  60. services={services}
  61. isVisible
  62. isDesktop={!params.has("mobile")}
  63. mobileOverlay={params.has("mobile")}
  64. sidePaneState={hasTab ? existingTab : null}
  65. recentClosedSidePaneTabs={[]}
  66. isBrowserOpen={false}
  67. supportsEmbeddedBrowser={false}
  68. workspaceAbsPath={workspacePath}
  69. workspaceIdentity={workspaceIdentity}
  70. workspaceRemoteSessionId={remoteSessionId}
  71. activeTaskId={params.has("draft") ? null : "session-fixture"}
  72. sidePaneOwnerId="session-fixture"
  73. gitState={{} as Parameters<typeof AnimatedSidePanePanel>[0]["gitState"]}
  74. activeGitSourceId="unstaged"
  75. panelRef={panelRef}
  76. panelElementRef={panelElementRef}
  77. browserNavigationRequest={null}
  78. browserRestoreUrls={{}}
  79. fileChangeFindActiveIndex={0}
  80. fileChangeFindNavigationRequestId={0}
  81. fileChangeFindQuery=""
  82. onFileChangeFindMatchCountChange={noop}
  83. onCloseCodeViewer={noop}
  84. onCloseGit={noop}
  85. onActivateTab={noop}
  86. onReorderTab={noop}
  87. onCloseTab={noop}
  88. onCloseOtherTabs={noop}
  89. onCloseAllTabs={noop}
  90. onReopenClosedTab={noop}
  91. onOpenBrowserTab={noop}
  92. onOpenWhiteboard={noop}
  93. onOpenDeveloperTools={noop}
  94. onOpenTerminalTab={noop}
  95. onOpenReviewTab={noop}
  96. onOpenSelectionSideConversation={noop}
  97. onOpenBrowserUrl={noop}
  98. onOpenCodeViewer={noop}
  99. onOpenSubagentSession={noop}
  100. onRefreshGit={noop}
  101. onBrowserNavigationRequestHandled={noop}
  102. onBrowserUrlChange={noop}
  103. onBrowserPageMetadataChange={noop}
  104. onSelectGitSource={noop}
  105. />
  106. );
  107. return (
  108. <main className="h-screen min-w-0 bg-background text-foreground">
  109. <button data-testid="show-tabs" onClick={() => setHasTab(true)}>
  110. Show existing tab
  111. </button>
  112. <output data-testid="request" hidden>
  113. {JSON.stringify(request)}
  114. </output>
  115. <output data-testid="opened" hidden>
  116. {JSON.stringify(opened)}
  117. </output>
  118. <div className="h-5/6 min-w-0">
  119. {params.has("mobile") ? (
  120. renderPanel()
  121. ) : (
  122. <ResizablePanelGroup layoutId="plugin-menu-fixture" orientation="horizontal">
  123. <ResizablePanel defaultSize={40}>
  124. <div />
  125. </ResizablePanel>
  126. {renderPanel()}
  127. </ResizablePanelGroup>
  128. )}
  129. </div>
  130. </main>
  131. );
  132. function renderPanel() {
  133. return params.has("noHost") ? (
  134. panel
  135. ) : (
  136. <PluginUiWorkspaceProvider onOpenSidePane={open}>{panel}</PluginUiWorkspaceProvider>
  137. );
  138. }
  139. }
  140. createRoot(document.getElementById("root")!).render(
  141. <ServiceProvider services={services}>
  142. <ZCodeIntlProvider initialLocale={params.get("locale") === "zh-CN" ? "zh-CN" : "en-US"}>
  143. <TooltipProvider>
  144. <Fixture />
  145. </TooltipProvider>
  146. </ZCodeIntlProvider>
  147. </ServiceProvider>,
  148. );