plugin-concurrent-install.fixture.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { createRoot } from "react-dom/client";
  2. import type { IPluginManagementService } from "@zcode/services";
  3. import { createPluginManagementStore } from "@/store/pluginManagementStore.js";
  4. import { PluginStoreInstallButton } from "@/settings/PluginStoreCard.js";
  5. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  6. import { logger } from "@/logger.js";
  7. import "@/styles.css";
  8. const params = new URLSearchParams(location.search);
  9. document.documentElement.className =
  10. params.get("theme") === "light" ? "light theme-zai-light" : "dark theme-zai-dark";
  11. const releases = new Map<string, () => void>();
  12. const service = {
  13. listPlugins: async () => ({ plugins: [], diagnostics: [] }),
  14. getPluginsOverview: async () => ({
  15. marketplaces: [],
  16. availablePlugins: [],
  17. installedPlugins: [],
  18. restorableBuiltins: [],
  19. diagnostics: [],
  20. }),
  21. installPlugin: ({ pluginName }: { pluginName: string }) =>
  22. new Promise((resolve) => {
  23. releases.set(pluginName, () =>
  24. resolve({ installedPlugins: [], dependencyClosure: [], diagnostics: [] }),
  25. );
  26. }),
  27. } as unknown as IPluginManagementService;
  28. const store = createPluginManagementStore(service);
  29. await store.getState().initialize({ workspacePath: "/workspace/fixture", pluginService: service });
  30. store.subscribe((state) => logger.debug("install-state", JSON.stringify(state.activeOperations)));
  31. function Fixture() {
  32. const state = store();
  33. return (
  34. <ZCodeIntlProvider initialLocale={params.get("locale") === "zh-CN" ? "zh-CN" : "en-US"}>
  35. <main className="flex flex-col gap-4 bg-background p-4 text-foreground">
  36. {["first", "second"].map((name) => (
  37. <div key={name}>
  38. <span>{name}</span>
  39. <PluginStoreInstallButton
  40. item={{
  41. id: `${name}@personal`,
  42. name,
  43. marketplace: "personal",
  44. installed: false,
  45. restorable: false,
  46. orphaned: false,
  47. }}
  48. actions={{
  49. ...state,
  50. onInstall: () => {
  51. void state.installPlugin(name, "personal", service);
  52. },
  53. onOpenDetail: () => {},
  54. onUninstall: () => {},
  55. onUpdate: () => {},
  56. }}
  57. />
  58. <button data-testid={`finish-${name}`} onClick={() => releases.get(name)?.()}>
  59. Finish {name}
  60. </button>
  61. </div>
  62. ))}
  63. </main>
  64. </ZCodeIntlProvider>
  65. );
  66. }
  67. createRoot(document.getElementById("root")!).render(<Fixture />);