share-popover.fixture.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. import { useEffect, useState } from "react";
  2. import { createRoot } from "react-dom/client";
  3. import { ZCodeIntlProvider, useZCodeIntl } from "@/i18n/IntlProvider.js";
  4. import { TooltipProvider } from "@/components/ui/tooltip.js";
  5. import { ConversationShareMenu } from "@/ConversationShareMenu.js";
  6. import { ConversationSharePopover } from "@/conversation-share-interaction/ConversationSharePopover.js";
  7. import { ConversationShareSelectionPanel } from "@/v4/ConversationShareSelectionPanel.js";
  8. import { ConversationShareConfirmationDock } from "@/v4/ConversationShareConfirmationDock.js";
  9. import { ConversationShareSuccessDock } from "@/v4/ConversationShareSuccessDock.js";
  10. import { ConversationSharePreflightStatus } from "@/conversation-share-interaction/ConversationSharePreflightStatus.js";
  11. import {
  12. getConversationShareSelectedProductTurnIds,
  13. useConversationShareSelectionStore,
  14. DEFAULT_CONVERSATION_SHARE_DOCK_STATE,
  15. } from "@/store/conversationShareSelectionStore.js";
  16. import { aggregateConversationShareBlockingIssues } from "@/conversation-share-interaction/conversationSharePreflightCache.js";
  17. import "@/styles.css";
  18. const params = new URLSearchParams(location.search);
  19. document.documentElement.className =
  20. params.get("theme") === "light" ? "light theme-zai-light" : "dark theme-zai-dark";
  21. const items = Array.from({ length: Number(params.get("items") ?? 9) }, (_, i) => ({
  22. key: String(i),
  23. rowId: i + 1,
  24. unitIndex: i,
  25. userPreview: i === 0 ? "hello" : `你好,第 ${i + 1} 轮`,
  26. assistantPreview:
  27. "Hello! I'm ZCode, your coding assistant. I can help you explore the repository, understand the implementation, and improve the sharing experience.",
  28. isRunning: params.has("running") || i === 8,
  29. }));
  30. function Fixture() {
  31. const { intl } = useZCodeIntl();
  32. const [sessionId, setSessionId] = useState("a");
  33. const [inspected, setInspected] = useState(0);
  34. const [checking, setChecking] = useState(false);
  35. const [limitEnabled, setLimitEnabled] = useState(params.has("budget"));
  36. const [short, setShort] = useState(false);
  37. const [completed, setCompleted] = useState(false);
  38. const [copiedUrl, setCopiedUrl] = useState("");
  39. const [openedUrl, setOpenedUrl] = useState("");
  40. const candidates = completed ? items.map((item) => ({ ...item, isRunning: false })) : items;
  41. const visibleItems = short ? candidates.slice(0, 1) : candidates;
  42. const productTurnId = (id: number) => (params.has("grouped") && id <= 2 ? "group" : String(id));
  43. const state = useConversationShareSelectionStore();
  44. const draft = state.drafts[sessionId];
  45. const dock = state.dockStates[sessionId] ?? DEFAULT_CONVERSATION_SHARE_DOCK_STATE;
  46. const editing = draft?.pendingExcludedRowIds != null;
  47. const count = getConversationShareSelectedProductTurnIds(state, sessionId).length;
  48. const selected = new Set(
  49. (draft?.availableRowIds ?? []).filter(
  50. (id) => !(draft?.pendingExcludedRowIds ?? draft?.excludedRowIds ?? []).includes(id),
  51. ),
  52. );
  53. const pendingTurns = getConversationShareSelectedProductTurnIds(state, sessionId, "pending");
  54. const budgetIssues = aggregateConversationShareBlockingIssues(
  55. pendingTurns.map((id, i) => ({
  56. productTurnId: id,
  57. blockingIssues: [],
  58. skippableWarnings: [],
  59. deferredIssues: [],
  60. rowBudget: {
  61. count: params.has("budget")
  62. ? i === 0
  63. ? Number(params.get("budget"))
  64. : 0
  65. : id === "1"
  66. ? 120
  67. : 70,
  68. limit: Number(params.get("limit") ?? 500),
  69. },
  70. })),
  71. );
  72. const cancel = () => state.cancelSelectionEdit(sessionId);
  73. useEffect(() => {
  74. if (draft?.open)
  75. state.syncAvailableTurns(
  76. sessionId,
  77. candidates
  78. .filter((i) => !i.isRunning)
  79. .map((i) => ({ rowId: i.rowId, productTurnId: productTurnId(i.rowId) })),
  80. );
  81. }, [sessionId, draft?.open, completed]);
  82. const patch = (value: Parameters<typeof state.updateDockState>[1]) =>
  83. state.updateDockState(sessionId, value);
  84. return (
  85. <main className="relative flex h-screen flex-col bg-background text-foreground">
  86. <header className="flex h-12 shrink-0 items-center justify-end px-4">
  87. <button
  88. data-testid="toggle-preflight"
  89. data-conversation-share-keep-open="fixture"
  90. onClick={() => setChecking(!checking)}
  91. >
  92. 检查状态
  93. </button>
  94. <button
  95. data-testid="toggle-limit"
  96. data-conversation-share-keep-open="fixture"
  97. onClick={() => setLimitEnabled(!limitEnabled)}
  98. >
  99. Limit
  100. </button>
  101. <button
  102. data-testid="short-list"
  103. data-conversation-share-keep-open="fixture"
  104. onClick={() => setShort(!short)}
  105. >
  106. 短列表
  107. </button>
  108. <button
  109. data-testid="complete-turn"
  110. data-conversation-share-keep-open="fixture"
  111. onClick={() => setCompleted(true)}
  112. >
  113. 完成运行轮次
  114. </button>
  115. <ConversationShareMenu taskId={sessionId} />
  116. </header>
  117. <div className="relative min-h-0 flex-1">
  118. <button data-testid="outside" className="absolute bottom-20 right-4">
  119. 正文外部区域
  120. </button>
  121. <button
  122. data-testid="switch"
  123. data-conversation-share-keep-open="fixture"
  124. onClick={() => setSessionId(sessionId === "a" ? "b" : "a")}
  125. >
  126. 切换任务
  127. </button>
  128. <output data-testid="inspected">{inspected}</output>
  129. <output data-testid="copied-url">{copiedUrl}</output>
  130. <output data-testid="opened-url">{openedUrl}</output>
  131. <ConversationShareSelectionPanel
  132. visible={editing}
  133. items={visibleItems}
  134. selectedCount={pendingTurns.length}
  135. selectedRowIds={selected}
  136. preflight={
  137. checking
  138. ? { status: "checking" }
  139. : {
  140. status: "ready",
  141. revision: 1,
  142. logEpoch: "fixture",
  143. capabilitiesFingerprint: "fixture",
  144. blockingIssues: limitEnabled ? budgetIssues : [],
  145. skippableWarnings: [],
  146. deferredIssues: [],
  147. supportedArtifactTypes: [],
  148. turnResults: [],
  149. }
  150. }
  151. onSelectAllChange={(selected) => state.setAllPendingRowsSelected(sessionId, selected)}
  152. onToggle={(id) => state.togglePendingRow(sessionId, id)}
  153. onInspect={(target) => setInspected(target.rowId)}
  154. onConfirm={() => state.confirmSelectionEdit(sessionId)}
  155. onCancel={cancel}
  156. />
  157. </div>
  158. <textarea
  159. aria-label="Composer"
  160. className="m-4 h-20 shrink-0 rounded-xl border border-border"
  161. />
  162. <ConversationSharePopover
  163. sessionId={sessionId}
  164. open={draft?.open ?? false}
  165. publishing={dock.publishing}
  166. selecting={editing}
  167. onClose={() => state.closeShare(sessionId)}
  168. onCancelSelection={cancel}
  169. >
  170. {dock.publishedShareUrl ? (
  171. <ConversationShareSuccessDock
  172. title={
  173. dock.title ?? "国内海外双区域登录与下载分发适配,以及长标题布局和多语言兼容性验证"
  174. }
  175. url={dock.publishedShareUrl}
  176. onCopy={async () => {
  177. setCopiedUrl(dock.publishedShareUrl!);
  178. return true;
  179. }}
  180. onOpen={() => setOpenedUrl(dock.publishedShareUrl!)}
  181. onDismiss={() => state.closeShare(sessionId)}
  182. />
  183. ) : (
  184. <ConversationShareConfirmationDock
  185. preflightChecking={checking}
  186. publishDisabled={checking}
  187. preflightContent={
  188. <ConversationSharePreflightStatus
  189. preflight={
  190. params.has("issue")
  191. ? {
  192. status: "ready",
  193. revision: 1,
  194. logEpoch: "fixture",
  195. capabilitiesFingerprint: "fixture",
  196. blockingIssues: pendingTurns.includes("1")
  197. ? [
  198. {
  199. code: "running_turn",
  200. scope: "turn",
  201. productTurnId: "1",
  202. turnOrdinal: 1,
  203. },
  204. ]
  205. : [],
  206. skippableWarnings: [],
  207. deferredIssues: [],
  208. supportedArtifactTypes: [],
  209. turnResults: [],
  210. }
  211. : { status: "checking" }
  212. }
  213. onDeselectTurn={(id) => state.deselectProductTurn(sessionId, id)}
  214. />
  215. }
  216. selectedCount={count}
  217. totalCount={8}
  218. title={
  219. dock.title ?? "国内海外双区域登录与下载分发适配,以及长标题布局和多语言兼容性验证"
  220. }
  221. accessMode={draft?.accessMode}
  222. selectionEditing={editing}
  223. pending={dock.publishing}
  224. progressPhase={dock.progress}
  225. completedArtifacts={dock.completedArtifacts}
  226. totalArtifacts={3}
  227. progressLabel={intl.formatMessage({
  228. id: `conversationShare.progress.${dock.progress}`,
  229. })}
  230. error={dock.error}
  231. onCancel={() => state.closeShare(sessionId)}
  232. onEditSelection={() => state.beginSelectionEdit(sessionId)}
  233. onTitleChange={(title) => patch({ title })}
  234. onAccessModeChange={(mode) => state.setAccessMode(sessionId, mode)}
  235. disclosureAccepted={dock.disclosureAccepted}
  236. onDisclosureAcceptedChange={(disclosureAccepted) => patch({ disclosureAccepted })}
  237. onConfirm={() => patch({ publishing: true, error: null })}
  238. />
  239. )}
  240. </ConversationSharePopover>
  241. {dock.publishing ? (
  242. <button
  243. data-testid="fail-publish"
  244. onClick={() =>
  245. patch({
  246. publishing: false,
  247. error: { issues: [], issueCount: 0, messageId: "conversationShare.issue.unknown" },
  248. })
  249. }
  250. >
  251. 失败
  252. </button>
  253. ) : null}
  254. {dock.publishing ? (
  255. <button
  256. data-testid="advance-publish"
  257. onClick={() =>
  258. patch({
  259. progress: dock.progress === "collecting" ? "uploading" : "checking",
  260. completedArtifacts: 2,
  261. })
  262. }
  263. >
  264. 下一阶段
  265. </button>
  266. ) : null}
  267. {dock.publishing ? (
  268. <button
  269. data-testid="resolve-publish"
  270. onClick={() =>
  271. patch({
  272. publishing: false,
  273. publishedShareUrl:
  274. "https://example.com/share/long-share-link-for-reviewing-regional-download-distribution-and-layout",
  275. })
  276. }
  277. className="fixed bottom-0 left-0"
  278. >
  279. 完成模拟发布
  280. </button>
  281. ) : null}
  282. </main>
  283. );
  284. }
  285. createRoot(document.getElementById("root")!).render(
  286. <ZCodeIntlProvider initialLocale={params.get("locale") === "en-US" ? "en-US" : "zh-CN"}>
  287. <TooltipProvider>
  288. <Fixture />
  289. </TooltipProvider>
  290. </ZCodeIntlProvider>,
  291. );