plugin-installed-strip.fixture.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { StoreContext } from "@/store/StoreProvider.js";
  2. import { createZCodeStore } from "@/store/index.js";
  3. import type { IBroadcastService } from "@zcode/services";
  4. import { PluginStoreDetailView } from "@/settings/PluginStoreDetailView.js";
  5. import { useState } from "react";
  6. import { createRoot } from "react-dom/client";
  7. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  8. import { TooltipProvider } from "@/components/ui/tooltip.js";
  9. import { PluginStoreListView } from "@/settings/PluginStoreListView.js";
  10. import type { StorePluginItem } from "@/settings/pluginStoreListing.js";
  11. import "@/styles.css";
  12. const store = createZCodeStore({
  13. send: async () => {},
  14. onMessage: () => ({ dispose() {} }),
  15. acquireClaim: async () => ({ status: "unavailable" }),
  16. commitClaim: async () => {},
  17. releaseClaim: async () => {},
  18. tryClaim: async () => false,
  19. } as IBroadcastService);
  20. const params = new URLSearchParams(location.search);
  21. document.documentElement.className =
  22. params.get("theme") === "light" ? "light theme-zai-light" : "dark theme-zai-dark";
  23. const items: StorePluginItem[] = Array.from({ length: 12 }, (_, index) => {
  24. const name = `plugin-${String(index).padStart(2, "0")}`;
  25. return {
  26. id: `${name}@personal`,
  27. name,
  28. marketplace: "personal",
  29. installed: true,
  30. restorable: false,
  31. orphaned: false,
  32. installedMeta: {
  33. id: `${name}@personal`,
  34. name,
  35. marketplace: "personal",
  36. enabled: true,
  37. scope: "user",
  38. updateStatus: "update-available",
  39. },
  40. };
  41. });
  42. const uiItem: StorePluginItem = {
  43. ...items[0]!,
  44. listing: {
  45. displayName: "Panel",
  46. category: "utilities",
  47. heroImage: "https://example.com/panel.png",
  48. },
  49. info: {
  50. id: items[0]!.id,
  51. name: items[0]!.name,
  52. marketplace: "personal",
  53. enabled: !params.has("paused"),
  54. source: "directory",
  55. rootPath: "/workspace/plugin",
  56. skillCount: 0,
  57. skillRootCount: 0,
  58. commandRootCount: 0,
  59. mcpServerNames: ["panel"],
  60. declaredMcpServerNames: ["panel"],
  61. uiSurfaces: [
  62. {
  63. pluginId: items[0]!.id,
  64. pluginName: "Panel",
  65. id: "panel",
  66. title: "Panel",
  67. server: "panel",
  68. resourceUri: "ui://panel/app",
  69. availability: "session",
  70. },
  71. ],
  72. },
  73. };
  74. function Fixture() {
  75. const [updated, setUpdated] = useState("");
  76. const [opened, setOpened] = useState("");
  77. const [uiOpened, setUiOpened] = useState("");
  78. const [detailOpen, setDetailOpen] = useState(params.has("detail"));
  79. const openDetail = (id: string) => {
  80. setOpened(id);
  81. if (params.has("ui")) setDetailOpen(true);
  82. };
  83. return (
  84. <StoreContext.Provider value={store}>
  85. <ZCodeIntlProvider initialLocale={params.get("locale") === "zh-CN" ? "zh-CN" : "en-US"}>
  86. <TooltipProvider>
  87. <main className="@container/plugin-store min-h-screen bg-background p-4 text-foreground">
  88. {detailOpen ? (
  89. <PluginStoreDetailView
  90. item={uiItem}
  91. actions={{
  92. onOpenDetail: openDetail,
  93. // mainNav=1 模拟主导航市场:不提供打开 UI,只有会话右侧市场才有「打开」。
  94. onOpenUi: params.has("mainNav")
  95. ? undefined
  96. : (item) => {
  97. setUiOpened(item.id);
  98. setOpened(item.id);
  99. },
  100. onUpdate: setUpdated,
  101. onInstall: () => {},
  102. onUninstall: () => {},
  103. onSetEnabled: () => {},
  104. activeOperations: [],
  105. togglingPluginId: null,
  106. }}
  107. onRetryDescribe={() => {}}
  108. onUsePrompt={() => {}}
  109. />
  110. ) : (
  111. <PluginStoreListView
  112. items={params.has("ui") ? [uiItem] : items}
  113. marketplaces={[]}
  114. loading={false}
  115. query=""
  116. onQueryChange={() => {}}
  117. segment="personal"
  118. onSegmentChange={() => {}}
  119. actions={{
  120. onOpenDetail: openDetail,
  121. // mainNav=1 模拟主导航市场:不提供打开 UI,只有会话右侧市场才有「打开」。
  122. onOpenUi: params.has("mainNav")
  123. ? undefined
  124. : (item) => {
  125. setUiOpened(item.id);
  126. setOpened(item.id);
  127. },
  128. onUpdate: setUpdated,
  129. onInstall: () => {},
  130. onUninstall: () => {},
  131. onSetEnabled: () => {},
  132. activeOperations: [],
  133. togglingPluginId: null,
  134. }}
  135. />
  136. )}
  137. <output data-testid="updated">{updated}</output>
  138. <output data-testid="opened">{opened}</output>
  139. <output data-testid="ui-opened">{uiOpened}</output>
  140. </main>
  141. </TooltipProvider>
  142. </ZCodeIntlProvider>
  143. </StoreContext.Provider>
  144. );
  145. }
  146. createRoot(document.getElementById("root")!).render(<Fixture />);