UNPKG

@oberoncms/core

Version:

OberonCMS is a cloud deployable CMS written in typescript based on the Puck visual editor

88 lines (87 loc) 4.08 kB
"use client"; import { jsxs, Fragment, jsx } from "react/jsx-runtime"; import { Fragment as Fragment$1, useState, useRef, useEffect } from "react"; import { Button } from "@tohuhono/ui/button"; import { ScrollArea } from "@tohuhono/ui/scroll-area"; import { iterateStreamResponse } from "@tohuhono/utils"; import { useRouter } from "next/navigation"; import { Grid, GridHeading } from "@tohuhono/ui/grid"; import { Table } from "@tohuhono/ui/table"; import { useOberonActions } from "../hooks/use-oberon.js"; function useMigration() { const { migrateData } = useOberonActions(); const router = useRouter(); const [results, setResults] = useState(); const [summary, setSummary] = useState(); const scrollRef = useRef(null); useEffect(() => { scrollRef.current?.scrollIntoView(); }, [results, summary]); return { summary, scrollRef, results, migrateData: async () => { try { const response = iterateStreamResponse(migrateData()); let results2 = []; setResults([]); setSummary(void 0); for await (const result of response) { if (result.type === "transform") { results2 = [...results2, result]; setResults(results2); } if (result.type === "summary") { setSummary(result); } router.refresh(); } } catch (error) { console.error(error); } } }; } function Site({ config: { plugins, version: coreVersion, pendingMigrations } }) { const { summary, scrollRef, migrateData, results } = useMigration(); const migrateDisabled = !pendingMigrations || results && !summary; return /* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsx("h2", { children: "Scheduled events" }), /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: "Scheduling not enabled" }), /* @__PURE__ */ jsx("h2", { children: "Pending Migrations" }), /* @__PURE__ */ jsxs(Grid, { className: "grid-cols-[1fr_auto]", children: [ pendingMigrations ? /* @__PURE__ */ jsx("div", { children: `Components: ${pendingMigrations.join(", ")}` }) : /* @__PURE__ */ jsx("div", { className: "text-green-800", children: "No pending migrations" }), /* @__PURE__ */ jsx(Button, { onClick: migrateData, disabled: migrateDisabled, children: "Run migrations" }) ] }), results && /* @__PURE__ */ jsx("div", { className: "pt-2", children: /* @__PURE__ */ jsxs(ScrollArea, { className: "h-64 rounded-md border px-5", children: [ /* @__PURE__ */ jsx(Table, { className: "grid-cols-[1fr_auto] gap-0", children: results.map(({ key, status }) => /* @__PURE__ */ jsxs(Fragment$1, { children: [ /* @__PURE__ */ jsx("div", { children: key }), status === "success" ? /* @__PURE__ */ jsx("div", { className: "text-green-800", children: status }) : /* @__PURE__ */ jsx("div", { className: "text-red-700", children: status }) ] }, key)) }), /* @__PURE__ */ jsx("h4", { children: summary && `Successfully migrated ${summary.success.length} of ${summary.total} pages with ${summary.error.length} errors` }), /* @__PURE__ */ jsx("div", { ref: scrollRef }) ] }) }), /* @__PURE__ */ jsx("h2", { children: "Installed Packages" }), /* @__PURE__ */ jsxs(Grid, { className: "grid-cols-[1fr_auto]", children: [ /* @__PURE__ */ jsx(GridHeading, { children: "Core" }), /* @__PURE__ */ jsx(GridHeading, { children: "Version" }), /* @__PURE__ */ jsx("div", { children: "@oberoncms/core" }), /* @__PURE__ */ jsx("div", { children: coreVersion }), /* @__PURE__ */ jsx(GridHeading, { className: "col-span-2", children: "Plugins" }), plugins.map(({ name, disabled, version }) => /* @__PURE__ */ jsxs(Fragment$1, { children: [ /* @__PURE__ */ jsxs("div", { className: disabled ? "font-light" : "", children: [ name, " ", disabled && " (disabled)" ] }), /* @__PURE__ */ jsx("div", { children: version }) ] }, name)) ] }) ] }); } export { Site };