mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
refactor: clarify publish diagnostics names
This commit is contained in:
1 parent
409b8803d2
commit
0fc46b6ad8
19 files changed
+255
-251
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { cssVar } from "@webstudio-is/design-system";
|
||||
import { AlertIcon, CheckCircleIcon, SpinnerIcon } from "@webstudio-is/icons";
|
||||
import type { PublishLog } from "./use-publish-logs";
|
||||
import type { SessionPublish } from "./use-session-publishes";
|
||||
|
||||
export const publishLogStatus = {
|
||||
pending: {
|
||||
@@ -19,7 +19,7 @@ export const publishLogStatus = {
|
||||
text: "Published",
|
||||
},
|
||||
} satisfies Record<
|
||||
PublishLog["status"],
|
||||
SessionPublish["status"],
|
||||
{
|
||||
Icon: typeof AlertIcon;
|
||||
color: string;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Flex, Text } from "@webstudio-is/design-system";
|
||||
import type { nativeClient } from "~/shared/trpc/trpc-client";
|
||||
import { ContentDatabasePublishWarning } from "./content-database-publish-warning-view";
|
||||
import type { PublishValidationFinding } from "./diagnostics";
|
||||
import type { DiagnosticFinding } from "./diagnostics";
|
||||
|
||||
type ContentDatabasePublishDiagnostics = Awaited<
|
||||
ReturnType<typeof nativeClient.build.contentDatabasePublishDiagnostics.query>
|
||||
@@ -28,7 +28,7 @@ const invalidMdxFixes = {
|
||||
export const getContentDatabasePublishFindings = (
|
||||
diagnostics: ContentDatabasePublishDiagnostics
|
||||
) => {
|
||||
const findings: PublishValidationFinding[] = diagnostics.mdxErrors.map(
|
||||
const findings: DiagnosticFinding[] = diagnostics.mdxErrors.map(
|
||||
({ filename, diagnostic }) => {
|
||||
const start =
|
||||
"sourceRange" in diagnostic ? diagnostic.sourceRange?.start : undefined;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { PublishValidationFinding } from "./diagnostics";
|
||||
import type { PublishLog } from "./use-publish-logs";
|
||||
import type { DiagnosticFinding } from "./diagnostics";
|
||||
import type { SessionPublish } from "./use-session-publishes";
|
||||
import { publishLogStatus } from "./constants";
|
||||
|
||||
export const getDiagnosticsReport = ({
|
||||
@@ -8,8 +8,8 @@ export const getDiagnosticsReport = ({
|
||||
canViewPublishLogs,
|
||||
includeLatestPublishFindings = true,
|
||||
}: {
|
||||
findings: PublishValidationFinding[];
|
||||
items: PublishLog[];
|
||||
findings: DiagnosticFinding[];
|
||||
items: SessionPublish[];
|
||||
canViewPublishLogs: boolean;
|
||||
includeLatestPublishFindings?: boolean;
|
||||
}) => {
|
||||
@@ -29,7 +29,7 @@ export const getDiagnosticsReport = ({
|
||||
]
|
||||
: []),
|
||||
...(canViewPublishLogs
|
||||
? (latestPublish?.issues?.map<PublishValidationFinding>((issue) => ({
|
||||
? (latestPublish?.issues?.map<DiagnosticFinding>((issue) => ({
|
||||
severity: issue.severity,
|
||||
source: "build" as const,
|
||||
title: issue.message,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useEffect } from "react";
|
||||
import { StorySection } from "@webstudio-is/design-system";
|
||||
import {
|
||||
PublishDiagnosticsDialog,
|
||||
type PublishValidationFinding,
|
||||
type DiagnosticFinding,
|
||||
} from "./diagnostics";
|
||||
|
||||
export default {
|
||||
@@ -10,7 +10,7 @@ export default {
|
||||
component: PublishDiagnosticsDialog,
|
||||
};
|
||||
|
||||
const errorsAndWarnings: PublishValidationFinding[] = [
|
||||
const errorsAndWarnings: DiagnosticFinding[] = [
|
||||
{
|
||||
severity: "error",
|
||||
title: "Unable to complete publish validation",
|
||||
@@ -25,11 +25,7 @@ const errorsAndWarnings: PublishValidationFinding[] = [
|
||||
},
|
||||
];
|
||||
|
||||
const ValidationStory = ({
|
||||
findings,
|
||||
}: {
|
||||
findings: PublishValidationFinding[];
|
||||
}) => {
|
||||
const ValidationStory = ({ findings }: { findings: DiagnosticFinding[] }) => {
|
||||
useEffect(() => {
|
||||
const open = () => {
|
||||
const button = Array.from(document.querySelectorAll("button")).find(
|
||||
|
||||
@@ -6,9 +6,9 @@ import { TooltipProvider } from "@webstudio-is/design-system";
|
||||
import {
|
||||
PublishDiagnosticsDialog,
|
||||
PublishValidationBanner,
|
||||
type PublishValidationFinding,
|
||||
type DiagnosticFinding,
|
||||
} from "./diagnostics";
|
||||
import type { PublishLog } from "./use-publish-logs";
|
||||
import type { SessionPublish } from "./use-session-publishes";
|
||||
|
||||
let root: Root | undefined;
|
||||
let container: HTMLDivElement | undefined;
|
||||
@@ -25,10 +25,10 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
const render = (
|
||||
findings: PublishValidationFinding[],
|
||||
findings: DiagnosticFinding[],
|
||||
canViewPublishLogs = true,
|
||||
items: PublishLog[] = [],
|
||||
onLoadLog?: (item: PublishLog) => void,
|
||||
items: SessionPublish[] = [],
|
||||
onLoadLog?: (item: SessionPublish) => void,
|
||||
open?: boolean
|
||||
) => {
|
||||
container = document.createElement("div");
|
||||
@@ -51,9 +51,9 @@ const render = (
|
||||
};
|
||||
|
||||
const createFinding = (
|
||||
severity: PublishValidationFinding["severity"],
|
||||
severity: DiagnosticFinding["severity"],
|
||||
index: number
|
||||
): PublishValidationFinding => ({
|
||||
): DiagnosticFinding => ({
|
||||
severity,
|
||||
title: `${severity}-${index}`,
|
||||
details: `details-${severity}-${index}`,
|
||||
@@ -328,7 +328,7 @@ test("Free hides log-derived issues, stage, and code", async () => {
|
||||
});
|
||||
|
||||
test("loads a completed publish when Publish opens and shows its log inline", async () => {
|
||||
const item: PublishLog = {
|
||||
const item: SessionPublish = {
|
||||
buildId: "build-1",
|
||||
logHandle: "log-handle-1",
|
||||
target: "site",
|
||||
|
||||
@@ -26,11 +26,11 @@ import {
|
||||
} from "@webstudio-is/design-system";
|
||||
import { CopyIcon } from "@webstudio-is/icons";
|
||||
import { CopyToClipboard } from "~/shared/copy-to-clipboard";
|
||||
import type { PublishLog } from "./use-publish-logs";
|
||||
import { getPublishDuration } from "./use-publish-logs";
|
||||
import type { SessionPublish } from "./use-session-publishes";
|
||||
import { getPublishDuration } from "./use-session-publishes";
|
||||
import { publishLogStatus } from "./constants";
|
||||
|
||||
export type PublishValidationFinding = {
|
||||
export type DiagnosticFinding = {
|
||||
severity: "error" | "warning";
|
||||
source?: "audit" | "build" | "publish";
|
||||
title: ReactNode;
|
||||
@@ -42,7 +42,7 @@ export type PublishValidationFinding = {
|
||||
buildId?: string;
|
||||
};
|
||||
|
||||
const shortFinding = (finding: PublishValidationFinding) =>
|
||||
const shortFinding = (finding: DiagnosticFinding) =>
|
||||
(
|
||||
finding.summary ?? (typeof finding.title === "string" ? finding.title : "")
|
||||
).slice(0, 160);
|
||||
@@ -52,7 +52,7 @@ export const PublishValidationBanner = ({
|
||||
passed = false,
|
||||
onOpen,
|
||||
}: {
|
||||
findings: PublishValidationFinding[];
|
||||
findings: DiagnosticFinding[];
|
||||
passed?: boolean;
|
||||
onOpen: () => void;
|
||||
}) => {
|
||||
@@ -101,9 +101,9 @@ const FindingList = ({
|
||||
issuesOmitted = 0,
|
||||
publishBuildIds,
|
||||
}: {
|
||||
findings: PublishValidationFinding[];
|
||||
findings: DiagnosticFinding[];
|
||||
canViewPublishLogs: boolean;
|
||||
onSelect: (finding: PublishValidationFinding) => void;
|
||||
onSelect: (finding: DiagnosticFinding) => void;
|
||||
onOpenPublish?: () => void;
|
||||
issuesOmitted?: number;
|
||||
publishBuildIds: string[];
|
||||
@@ -169,7 +169,7 @@ const FindingDetails = ({
|
||||
onBack,
|
||||
onNavigate,
|
||||
}: {
|
||||
finding: PublishValidationFinding;
|
||||
finding: DiagnosticFinding;
|
||||
onBack: () => void;
|
||||
onNavigate: () => void;
|
||||
}) => (
|
||||
@@ -209,12 +209,12 @@ const FindingDetails = ({
|
||||
</PanelContent>
|
||||
);
|
||||
|
||||
const PublishHistoryEntry = ({
|
||||
const SessionPublishEntry = ({
|
||||
item,
|
||||
defaultOpen,
|
||||
canViewPublishLogs,
|
||||
}: {
|
||||
item: PublishLog;
|
||||
item: SessionPublish;
|
||||
defaultOpen: boolean;
|
||||
canViewPublishLogs: boolean;
|
||||
}) => {
|
||||
@@ -309,14 +309,14 @@ const PublishHistoryEntry = ({
|
||||
);
|
||||
};
|
||||
|
||||
const PublishHistory = ({
|
||||
const SessionPublishList = ({
|
||||
items,
|
||||
canViewPublishLogs,
|
||||
onLoadLog,
|
||||
}: {
|
||||
items: PublishLog[];
|
||||
items: SessionPublish[];
|
||||
canViewPublishLogs: boolean;
|
||||
onLoadLog?: (item: PublishLog) => void;
|
||||
onLoadLog?: (item: SessionPublish) => void;
|
||||
}) => {
|
||||
useEffect(() => {
|
||||
if (!canViewPublishLogs) {
|
||||
@@ -344,7 +344,7 @@ const PublishHistory = ({
|
||||
<Text color="subtle">No publishes in this session.</Text>
|
||||
)}
|
||||
{items.map((item, index) => (
|
||||
<PublishHistoryEntry
|
||||
<SessionPublishEntry
|
||||
key={item.buildId}
|
||||
item={item}
|
||||
defaultOpen={index === items.length - 1}
|
||||
@@ -367,19 +367,18 @@ export const PublishDiagnosticsDialog = ({
|
||||
includeLatestPublishFindings = true,
|
||||
onLoadLog,
|
||||
}: {
|
||||
findings: PublishValidationFinding[];
|
||||
findings: DiagnosticFinding[];
|
||||
open?: boolean;
|
||||
onOpenChange?: (open: boolean) => void;
|
||||
target?: string;
|
||||
initialTab?: "warnings" | "errors" | "publish";
|
||||
items?: PublishLog[];
|
||||
items?: SessionPublish[];
|
||||
canViewPublishLogs?: boolean;
|
||||
includeLatestPublishFindings?: boolean;
|
||||
onLoadLog?: (item: PublishLog) => void;
|
||||
onLoadLog?: (item: SessionPublish) => void;
|
||||
}) => {
|
||||
const [internalOpen, setInternalOpen] = useState(false);
|
||||
const [selectedFinding, setSelectedFinding] =
|
||||
useState<PublishValidationFinding>();
|
||||
const [selectedFinding, setSelectedFinding] = useState<DiagnosticFinding>();
|
||||
const isOpen = open ?? internalOpen;
|
||||
const setIsOpen = onOpenChange ?? setInternalOpen;
|
||||
|
||||
@@ -503,7 +502,7 @@ export const PublishDiagnosticsDialog = ({
|
||||
value="publish"
|
||||
css={{ flex: 1, minHeight: 0, overflow: "hidden" }}
|
||||
>
|
||||
<PublishHistory
|
||||
<SessionPublishList
|
||||
items={orderedItems}
|
||||
canViewPublishLogs={canViewPublishLogs}
|
||||
onLoadLog={onLoadLog}
|
||||
|
||||
+9
-6
@@ -2,24 +2,27 @@ import type { ReactNode } from "react";
|
||||
import { IconButton, Tooltip } from "@webstudio-is/design-system";
|
||||
import type { AlertIcon } from "@webstudio-is/icons";
|
||||
import { publishLogStatus } from "./constants";
|
||||
import type { PublishLog } from "./use-publish-logs";
|
||||
import type { SessionPublish } from "./use-session-publishes";
|
||||
|
||||
export const DomainPublishStatus = ({
|
||||
export const DomainStatusButton = ({
|
||||
domain,
|
||||
buildId,
|
||||
latestLog,
|
||||
latestPublish,
|
||||
fallback,
|
||||
onOpenReport,
|
||||
}: {
|
||||
domain: string;
|
||||
buildId?: string;
|
||||
latestLog?: Pick<PublishLog, "buildId" | "status">;
|
||||
latestPublish?: Pick<SessionPublish, "buildId" | "status">;
|
||||
fallback: { Icon: typeof AlertIcon; color: string; text: ReactNode };
|
||||
onOpenReport?: () => void;
|
||||
}) => {
|
||||
const currentLog = latestLog?.buildId === buildId ? latestLog : undefined;
|
||||
const currentPublish =
|
||||
latestPublish?.buildId === buildId ? latestPublish : undefined;
|
||||
const { Icon, color, text } =
|
||||
currentLog === undefined ? fallback : publishLogStatus[currentLog.status];
|
||||
currentPublish === undefined
|
||||
? fallback
|
||||
: publishLogStatus[currentPublish.status];
|
||||
return (
|
||||
<Tooltip content={text}>
|
||||
<IconButton
|
||||
@@ -4,7 +4,7 @@ import { afterEach, expect, test, vi } from "vitest";
|
||||
import { TooltipProvider } from "@webstudio-is/design-system";
|
||||
import { __testing__, type Domain } from "./domains";
|
||||
import { PENDING_TIMEOUT } from "./publish-status";
|
||||
import type { PublishLog } from "./use-publish-logs";
|
||||
import type { SessionPublish } from "./use-session-publishes";
|
||||
|
||||
const { StatusIcon } = __testing__;
|
||||
let root: Root | undefined;
|
||||
@@ -26,13 +26,13 @@ const renderStatus = (
|
||||
{
|
||||
age = 0,
|
||||
isLoading = false,
|
||||
latestLog,
|
||||
latestPublish,
|
||||
onOpenReport,
|
||||
onSectionClick,
|
||||
}: {
|
||||
age?: number;
|
||||
isLoading?: boolean;
|
||||
latestLog?: PublishLog;
|
||||
latestPublish?: SessionPublish;
|
||||
onOpenReport?: (domain: string) => void;
|
||||
onSectionClick?: () => void;
|
||||
} = {}
|
||||
@@ -66,7 +66,7 @@ const renderStatus = (
|
||||
<StatusIcon
|
||||
projectDomain={projectDomain}
|
||||
isLoading={isLoading}
|
||||
latestLog={latestLog}
|
||||
latestPublish={latestPublish}
|
||||
onOpenReport={onOpenReport}
|
||||
/>
|
||||
</TooltipProvider>
|
||||
@@ -113,7 +113,7 @@ test.each([
|
||||
expect(
|
||||
renderStatus(status === "failed" ? "PUBLISHED" : "PENDING", {
|
||||
age: PENDING_TIMEOUT + 1000,
|
||||
latestLog: {
|
||||
latestPublish: {
|
||||
buildId: "current-build",
|
||||
target: "site",
|
||||
domains: ["example.com"],
|
||||
@@ -128,7 +128,7 @@ test.each([
|
||||
test("ignores a log for a different domain build", () => {
|
||||
expect(
|
||||
renderStatus("PUBLISHED", {
|
||||
latestLog: {
|
||||
latestPublish: {
|
||||
buildId: "old-build",
|
||||
target: "site",
|
||||
domains: ["example.com"],
|
||||
|
||||
@@ -40,11 +40,11 @@ import { extractCname } from "./cname";
|
||||
import { useEffectEvent } from "~/shared/hook-utils/effect-event";
|
||||
import { DomainCheckbox } from "./domain-checkbox";
|
||||
import { CopyToClipboard } from "~/shared/copy-to-clipboard";
|
||||
import { getPublishStatusAndText } from "./publish-status";
|
||||
import { getPublishStatusDisplay } from "./publish-status";
|
||||
import { $currentSystem } from "~/shared/system";
|
||||
import { getPublishUrl } from "./publish-url";
|
||||
import type { PublishLog } from "./use-publish-logs";
|
||||
import { DomainPublishStatus } from "./domain-publish-status";
|
||||
import type { SessionPublish } from "./use-session-publishes";
|
||||
import { DomainStatusButton } from "./domain-status-button";
|
||||
|
||||
export type Domain = Project["domainsVirtual"][number];
|
||||
|
||||
@@ -88,11 +88,11 @@ const getStatusText = (props: {
|
||||
text = "Status: Active, not published";
|
||||
|
||||
if (props.projectDomain.latestBuildVirtual !== null) {
|
||||
const publishText = getPublishStatusAndText(
|
||||
const publishText = getPublishStatusDisplay(
|
||||
props.projectDomain.latestBuildVirtual
|
||||
);
|
||||
|
||||
text = publishText.statusText;
|
||||
text = publishText.statusContent;
|
||||
color = publishText.color;
|
||||
Icon = publishText.Icon;
|
||||
}
|
||||
@@ -118,15 +118,15 @@ const getStatusText = (props: {
|
||||
const StatusIcon = (props: {
|
||||
projectDomain: Domain;
|
||||
isLoading: boolean;
|
||||
latestLog?: PublishLog;
|
||||
latestPublish?: SessionPublish;
|
||||
onOpenReport?: (domain: string) => void;
|
||||
}) => {
|
||||
const fallback = getStatusText(props);
|
||||
return (
|
||||
<DomainPublishStatus
|
||||
<DomainStatusButton
|
||||
domain={props.projectDomain.domain}
|
||||
buildId={props.projectDomain.latestBuildVirtual?.buildId}
|
||||
latestLog={props.latestLog}
|
||||
latestPublish={props.latestPublish}
|
||||
fallback={fallback}
|
||||
onOpenReport={() => props.onOpenReport?.(props.projectDomain.domain)}
|
||||
/>
|
||||
@@ -139,7 +139,7 @@ const DomainItem = ({
|
||||
refresh,
|
||||
validatedDomains,
|
||||
onOpenReport,
|
||||
latestLog,
|
||||
latestPublish,
|
||||
}: {
|
||||
initiallyOpen: boolean;
|
||||
projectDomain: Domain;
|
||||
@@ -147,7 +147,7 @@ const DomainItem = ({
|
||||
refresh: () => Promise<void>;
|
||||
validatedDomains?: readonly string[];
|
||||
onOpenReport?: (domain: string) => void;
|
||||
latestLog?: PublishLog;
|
||||
latestPublish?: SessionPublish;
|
||||
}) => {
|
||||
const timeSinceLastUpdateMs =
|
||||
Date.now() - new Date(projectDomain.updatedAt).getTime();
|
||||
@@ -323,7 +323,7 @@ const DomainItem = ({
|
||||
projectDomain={projectDomain}
|
||||
isLoading={isStatusLoading}
|
||||
onOpenReport={onOpenReport}
|
||||
latestLog={latestLog}
|
||||
latestPublish={latestPublish}
|
||||
/>
|
||||
|
||||
<CopyToClipboard
|
||||
@@ -537,7 +537,7 @@ type DomainsProps = {
|
||||
project: Project;
|
||||
validatedDomains?: readonly string[];
|
||||
onOpenReport?: (domain: string) => void;
|
||||
publishLogs?: PublishLog[];
|
||||
sessionPublishes?: SessionPublish[];
|
||||
};
|
||||
|
||||
export const Domains = ({
|
||||
@@ -547,7 +547,7 @@ export const Domains = ({
|
||||
project,
|
||||
validatedDomains,
|
||||
onOpenReport,
|
||||
publishLogs = [],
|
||||
sessionPublishes = [],
|
||||
}: DomainsProps) => {
|
||||
return (
|
||||
<>
|
||||
@@ -560,7 +560,7 @@ export const Domains = ({
|
||||
project={project}
|
||||
validatedDomains={validatedDomains}
|
||||
onOpenReport={onOpenReport}
|
||||
latestLog={publishLogs.find(
|
||||
latestPublish={sessionPublishes.find(
|
||||
(item) =>
|
||||
item.target === "site" &&
|
||||
item.domains.includes(projectDomain.domain)
|
||||
|
||||
@@ -13,9 +13,9 @@ import { PublishDiagnosticsDialog } from "./diagnostics";
|
||||
const {
|
||||
usePublishProgress,
|
||||
waitForPublishStatus,
|
||||
refreshUntilSuccess,
|
||||
refreshProjectWithRetry,
|
||||
useManualValidationFindings,
|
||||
getRefreshedProject,
|
||||
fetchAndStoreProject,
|
||||
reportPublishResult,
|
||||
} = __testing__;
|
||||
|
||||
@@ -254,7 +254,7 @@ test("reopening refresh retries after a rejected status request", async () => {
|
||||
};
|
||||
|
||||
try {
|
||||
const done = refreshUntilSuccess(refresh, () => true);
|
||||
const done = refreshProjectWithRetry(refresh, () => true);
|
||||
expect(attempts).toBe(1);
|
||||
await vi.advanceTimersByTimeAsync(5_000);
|
||||
await done;
|
||||
@@ -273,7 +273,7 @@ test("reopening resumes a retained pending session even after the Build is publi
|
||||
},
|
||||
} as Project;
|
||||
const onPending = vi.fn();
|
||||
await refreshUntilSuccess(
|
||||
await refreshProjectWithRetry(
|
||||
async () => project,
|
||||
() => true,
|
||||
onPending,
|
||||
@@ -319,9 +319,9 @@ test("reopening stops after three unsuccessful project refreshes and shows the e
|
||||
}));
|
||||
let isOpen = true;
|
||||
|
||||
const done = refreshUntilSuccess(
|
||||
const done = refreshProjectWithRetry(
|
||||
(showError) =>
|
||||
getRefreshedProject({ projectId: "project", showError, query }),
|
||||
fetchAndStoreProject({ projectId: "project", showError, query }),
|
||||
() => isOpen
|
||||
);
|
||||
await vi.advanceTimersByTimeAsync(15_000);
|
||||
@@ -355,7 +355,7 @@ test("a recovered pending build keeps polling after the popover closes", async (
|
||||
return (
|
||||
<button
|
||||
onClick={() => {
|
||||
void refreshUntilSuccess(
|
||||
void refreshProjectWithRetry(
|
||||
async () => refreshedProject(),
|
||||
() => true,
|
||||
() =>
|
||||
@@ -398,7 +398,7 @@ test("an in-flight status request cannot replace the project after navigation",
|
||||
const query = new Promise<{ success: true; project: Project }>((resolve) => {
|
||||
finishQuery = resolve;
|
||||
});
|
||||
const refresh = getRefreshedProject({
|
||||
const refresh = fetchAndStoreProject({
|
||||
projectId: oldProject.id,
|
||||
showError: false,
|
||||
query: () => query,
|
||||
@@ -423,7 +423,7 @@ test("an older popover refresh cannot overwrite a newer result", async () => {
|
||||
}
|
||||
);
|
||||
let isOpen = true;
|
||||
const oldRefresh = getRefreshedProject({
|
||||
const oldRefresh = fetchAndStoreProject({
|
||||
projectId: "project",
|
||||
showError: false,
|
||||
query: () => oldQuery,
|
||||
@@ -432,7 +432,7 @@ test("an older popover refresh cannot overwrite a newer result", async () => {
|
||||
|
||||
isOpen = false;
|
||||
const currentProject = { id: "project", domain: "new" } as Project;
|
||||
await getRefreshedProject({
|
||||
await fetchAndStoreProject({
|
||||
projectId: "project",
|
||||
showError: false,
|
||||
query: async () => ({ success: true, project: currentProject }),
|
||||
@@ -470,7 +470,7 @@ test("an older recovered poll cannot overwrite a newer popover refresh", async (
|
||||
const oldGeneration = progress!.beginPopoverRefresh();
|
||||
const polling = progress!.watchPendingPublish(
|
||||
() =>
|
||||
getRefreshedProject({
|
||||
fetchAndStoreProject({
|
||||
projectId: "project",
|
||||
query: () => oldQuery,
|
||||
isCurrent: () => progress!.isRefreshCurrent(oldGeneration),
|
||||
@@ -480,7 +480,7 @@ test("an older recovered poll cannot overwrite a newer popover refresh", async (
|
||||
|
||||
const newGeneration = progress!.beginPopoverRefresh();
|
||||
const currentProject = { id: "project", domain: "new" } as Project;
|
||||
await getRefreshedProject({
|
||||
await fetchAndStoreProject({
|
||||
projectId: "project",
|
||||
query: async () => ({ success: true, project: currentProject }),
|
||||
isCurrent: () => progress!.isRefreshCurrent(newGeneration),
|
||||
@@ -542,7 +542,7 @@ test("an old poll cannot update a newly mounted copy of the same project", async
|
||||
});
|
||||
const polling = waitForPublishStatus(
|
||||
() =>
|
||||
getRefreshedProject({
|
||||
fetchAndStoreProject({
|
||||
projectId: "project",
|
||||
isCurrent: progress!.isCurrentProject,
|
||||
query: () => query,
|
||||
@@ -572,13 +572,13 @@ test("publish failure updates the banner without a duplicate toast while Publish
|
||||
|
||||
$publishDialog.set("publish");
|
||||
reportPublishResult({
|
||||
result: { status: "PUBLISHED", statusText: publishedStatusText },
|
||||
result: { status: "PUBLISHED", statusContent: publishedStatusText },
|
||||
timesLeft: 11,
|
||||
maxDailyPublishesPerUser: 20,
|
||||
setPublishError,
|
||||
});
|
||||
reportPublishResult({
|
||||
result: { status: "FAILED", statusText: failedStatusText },
|
||||
result: { status: "FAILED", statusContent: failedStatusText },
|
||||
timesLeft: 11,
|
||||
maxDailyPublishesPerUser: 20,
|
||||
setPublishError,
|
||||
@@ -594,7 +594,7 @@ test("an old project completion does not show a success toast over an open Publi
|
||||
$publishDialog.set("publish");
|
||||
|
||||
reportPublishResult({
|
||||
result: { status: "PUBLISHED", statusText: <>Published</> },
|
||||
result: { status: "PUBLISHED", statusContent: <>Published</> },
|
||||
setPublishError: vi.fn(),
|
||||
isCurrentProject: () => false,
|
||||
});
|
||||
@@ -609,13 +609,13 @@ test("publish completion does not show a success toast in the Export view", () =
|
||||
$publishDialog.set("export");
|
||||
|
||||
reportPublishResult({
|
||||
result: { status: "PUBLISHED", statusText: <>Published</> },
|
||||
result: { status: "PUBLISHED", statusContent: <>Published</> },
|
||||
timesLeft: 11,
|
||||
maxDailyPublishesPerUser: 20,
|
||||
setPublishError,
|
||||
});
|
||||
reportPublishResult({
|
||||
result: { status: "FAILED", statusText: <>Publish failed</> },
|
||||
result: { status: "FAILED", statusContent: <>Publish failed</> },
|
||||
timesLeft: 11,
|
||||
maxDailyPublishesPerUser: 20,
|
||||
setPublishError,
|
||||
@@ -634,13 +634,13 @@ test("publish completion shows a toast after the dialog closes", () => {
|
||||
$publishDialog.set("none");
|
||||
|
||||
reportPublishResult({
|
||||
result: { status: "PUBLISHED", statusText: publishedStatusText },
|
||||
result: { status: "PUBLISHED", statusContent: publishedStatusText },
|
||||
timesLeft: 11,
|
||||
maxDailyPublishesPerUser: 20,
|
||||
setPublishError,
|
||||
});
|
||||
reportPublishResult({
|
||||
result: { status: "FAILED", statusText: failedStatusText },
|
||||
result: { status: "FAILED", statusContent: failedStatusText },
|
||||
timesLeft: 11,
|
||||
maxDailyPublishesPerUser: 20,
|
||||
setPublishError,
|
||||
@@ -824,7 +824,7 @@ test("a publish failure remains available after the panel remounts", () => {
|
||||
<button
|
||||
onClick={() =>
|
||||
reportPublishResult({
|
||||
result: { status: "FAILED", statusText: <>Build failed</> },
|
||||
result: { status: "FAILED", statusContent: <>Build failed</> },
|
||||
timesLeft: 11,
|
||||
maxDailyPublishesPerUser: 20,
|
||||
setPublishError: progress.setPublishStatusError,
|
||||
@@ -862,7 +862,7 @@ test("a successful status refresh clears a persisted publish failure", () => {
|
||||
<button
|
||||
onClick={() =>
|
||||
reportPublishResult({
|
||||
result: { status: "FAILED", statusText: <>Publish failed</> },
|
||||
result: { status: "FAILED", statusContent: <>Publish failed</> },
|
||||
timesLeft: 11,
|
||||
maxDailyPublishesPerUser: 20,
|
||||
setPublishError: progress.setPublishStatusError,
|
||||
|
||||
@@ -102,8 +102,8 @@ const Harness = ({
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<output>{flow.isPublishing ? "pending" : "idle"}</output>
|
||||
<output data-log-status>{flow.logs[0]?.status}</output>
|
||||
<output data-static-error>{flow.staticError?.severity}</output>
|
||||
<output data-log-status>{flow.publishes[0]?.status}</output>
|
||||
<output data-static-error>{flow.staticFailureFinding?.severity}</output>
|
||||
{open && (
|
||||
<publishModule.__testing__.PublishStatic
|
||||
templates={["ssg"]}
|
||||
@@ -114,14 +114,14 @@ const Harness = ({
|
||||
<diagnosticsModule.PublishDiagnosticsDialog
|
||||
findings={flow.reportFindings}
|
||||
includeLatestPublishFindings={flow.includeLatestPublishFindings}
|
||||
items={flow.reportItems}
|
||||
open={flow.selectedReport !== undefined}
|
||||
items={flow.reportPublishes}
|
||||
open={flow.diagnosticsSelection !== undefined}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
flow.closeReport();
|
||||
}
|
||||
}}
|
||||
initialTab={flow.selectedReport?.tab}
|
||||
initialTab={flow.diagnosticsSelection?.tab}
|
||||
canViewPublishLogs={false}
|
||||
/>
|
||||
</TooltipProvider>
|
||||
|
||||
@@ -6,7 +6,7 @@ import { RelativeTime } from "~/builder/shared/relative-time";
|
||||
export const PENDING_TIMEOUT =
|
||||
process.env.NODE_ENV === "production" ? 60 * 3 * 1000 : 35000;
|
||||
|
||||
export const getPublishStatusAndText = ({
|
||||
export const getPublishStatusDisplay = ({
|
||||
createdAt,
|
||||
publishStatus,
|
||||
}: Pick<
|
||||
@@ -22,16 +22,16 @@ export const getPublishStatusAndText = ({
|
||||
status = "FAILED";
|
||||
}
|
||||
|
||||
const textStart =
|
||||
const statusLabel =
|
||||
status === "PUBLISHED"
|
||||
? "Published"
|
||||
: status === "FAILED"
|
||||
? "Publish failed"
|
||||
: "Publishing started";
|
||||
|
||||
const statusText = (
|
||||
const statusContent = (
|
||||
<>
|
||||
{textStart} <RelativeTime time={new Date(createdAt)} />
|
||||
{statusLabel} <RelativeTime time={new Date(createdAt)} />
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -48,10 +48,10 @@ export const getPublishStatusAndText = ({
|
||||
? AlertIcon
|
||||
: SpinnerIcon;
|
||||
|
||||
return { statusText, status, color, Icon };
|
||||
return { statusContent, status, color, Icon };
|
||||
};
|
||||
|
||||
export const getStaticPublishStatusAndText = ({
|
||||
export const getStaticPublishStatusDisplay = ({
|
||||
updatedAt,
|
||||
publishStatus,
|
||||
}: {
|
||||
@@ -67,18 +67,18 @@ export const getStaticPublishStatusAndText = ({
|
||||
status = "FAILED";
|
||||
}
|
||||
|
||||
const textStart =
|
||||
const statusLabel =
|
||||
status === "PUBLISHED"
|
||||
? "Downloaded"
|
||||
: status === "FAILED"
|
||||
? "Download failed"
|
||||
: "Download started";
|
||||
|
||||
const statusText = (
|
||||
const statusContent = (
|
||||
<>
|
||||
{textStart} <RelativeTime time={new Date(updatedAt)} />
|
||||
{statusLabel} <RelativeTime time={new Date(updatedAt)} />
|
||||
</>
|
||||
);
|
||||
|
||||
return { statusText, status };
|
||||
return { statusContent, status };
|
||||
};
|
||||
@@ -26,7 +26,7 @@ import { flushExternalContentProject } from "~/shared/external-content-roots";
|
||||
import { nativeClient } from "~/shared/trpc/trpc-client";
|
||||
import { getContentDatabasePublishFindings } from "./content-database-publish-warning";
|
||||
import { getPublishValidationErrorMessage } from "./publish-error";
|
||||
import type { PublishValidationFinding } from "./diagnostics";
|
||||
import type { DiagnosticFinding } from "./diagnostics";
|
||||
|
||||
const getPrePublishInstanceTarget = (
|
||||
instanceId: string,
|
||||
@@ -92,7 +92,7 @@ const PrePublishInstanceLink = ({
|
||||
);
|
||||
};
|
||||
|
||||
const getPrePublishAuditFindings = (): PublishValidationFinding[] => {
|
||||
const getPrePublishAuditFindings = (): DiagnosticFinding[] => {
|
||||
const findings = runPrePublishAudit({
|
||||
pages: $pages.get(),
|
||||
instances: $instances.get(),
|
||||
@@ -198,7 +198,7 @@ export const runPublishValidation = async (
|
||||
|
||||
export const reportPublishValidationFailure = (
|
||||
error: unknown,
|
||||
setFindings: (findings: PublishValidationFinding[]) => void,
|
||||
setFindings: (findings: DiagnosticFinding[]) => void,
|
||||
{
|
||||
publishingContinues = false,
|
||||
showToast = true,
|
||||
@@ -246,7 +246,7 @@ export const getServerPublishFindings = (
|
||||
severity: "error" | "warning" | "info";
|
||||
message: string;
|
||||
}[]
|
||||
): PublishValidationFinding[] =>
|
||||
): DiagnosticFinding[] =>
|
||||
findings.flatMap((finding) =>
|
||||
finding.severity === "info"
|
||||
? []
|
||||
|
||||
@@ -105,22 +105,22 @@ import {
|
||||
PublishDiagnosticsDialog,
|
||||
PublishValidationBanner,
|
||||
} from "./diagnostics";
|
||||
import type { PublishLog } from "./use-publish-logs";
|
||||
import type { SessionPublish } from "./use-session-publishes";
|
||||
import { PublishActions } from "./publish-actions";
|
||||
import { usePublishFlow } from "./use-publish-flow";
|
||||
import { getRefreshedProject } from "./use-publish-progress";
|
||||
import { fetchAndStoreProject } from "./use-publish-progress";
|
||||
import {
|
||||
getPublishStatusAndText,
|
||||
getStaticPublishStatusAndText,
|
||||
getPublishStatusDisplay,
|
||||
getStaticPublishStatusDisplay,
|
||||
} from "./publish-status";
|
||||
import { DomainPublishStatus } from "./domain-publish-status";
|
||||
import { DomainStatusButton } from "./domain-status-button";
|
||||
|
||||
type ChangeProjectDomainProps = {
|
||||
project: Project;
|
||||
refresh: () => Promise<void>;
|
||||
validatedDomains?: readonly string[];
|
||||
onOpenReport: (domain: string) => void;
|
||||
latestLog?: PublishLog;
|
||||
latestPublish?: SessionPublish;
|
||||
};
|
||||
|
||||
const ChangeProjectDomain = ({
|
||||
@@ -128,7 +128,7 @@ const ChangeProjectDomain = ({
|
||||
refresh,
|
||||
validatedDomains,
|
||||
onOpenReport,
|
||||
latestLog,
|
||||
latestPublish,
|
||||
}: ChangeProjectDomainProps) => {
|
||||
const id = useId();
|
||||
const currentSystem = useStore($currentSystem);
|
||||
@@ -195,11 +195,11 @@ const ChangeProjectDomain = ({
|
||||
? project.latestBuildVirtual
|
||||
: undefined;
|
||||
|
||||
const { statusText, color, Icon } =
|
||||
const { statusContent, color, Icon } =
|
||||
latestProjectDomainBuild != null
|
||||
? getPublishStatusAndText(latestProjectDomainBuild)
|
||||
? getPublishStatusDisplay(latestProjectDomainBuild)
|
||||
: {
|
||||
statusText: "Not published",
|
||||
statusContent: "Not published",
|
||||
color: cssVar("--foreground-secondary"),
|
||||
Icon: InfoCircleIcon,
|
||||
};
|
||||
@@ -219,15 +219,15 @@ const ChangeProjectDomain = ({
|
||||
}
|
||||
suffix={
|
||||
<Grid flow="column" align="center">
|
||||
<DomainPublishStatus
|
||||
<DomainStatusButton
|
||||
domain={pageUrl.host}
|
||||
buildId={latestProjectDomainBuild?.buildId}
|
||||
latestLog={error === undefined ? latestLog : undefined}
|
||||
latestPublish={error === undefined ? latestPublish : undefined}
|
||||
fallback={{
|
||||
Icon: error === undefined ? Icon : AlertIcon,
|
||||
color:
|
||||
error === undefined ? color : cssVar("--foreground-negative"),
|
||||
text: error ?? <Text>{statusText}</Text>,
|
||||
text: error ?? <Text>{statusContent}</Text>,
|
||||
}}
|
||||
onOpenReport={() => onOpenReport(project.domain)}
|
||||
/>
|
||||
@@ -379,7 +379,7 @@ const Publish = ({
|
||||
validationState,
|
||||
validatedDomains,
|
||||
invalidateValidation,
|
||||
logs,
|
||||
publishes,
|
||||
siteError,
|
||||
siteErrorSource,
|
||||
openSiteReport: onOpenReport,
|
||||
@@ -391,7 +391,7 @@ const Publish = ({
|
||||
useState(false);
|
||||
const previousDomainsKey = useRef<string>();
|
||||
const hasPendingState = project.latestBuildVirtual
|
||||
? getPublishStatusAndText(project.latestBuildVirtual).status === "PENDING"
|
||||
? getPublishStatusDisplay(project.latestBuildVirtual).status === "PENDING"
|
||||
: false;
|
||||
const isPublishInProgress = isPublishing || hasPendingState;
|
||||
|
||||
@@ -460,7 +460,7 @@ const Publish = ({
|
||||
|
||||
const getForm = () => buttonRef.current?.closest("form");
|
||||
const findings = flow.siteFindings;
|
||||
const hasSessionPublish = logs.some(({ target }) => target === "site");
|
||||
const hasSessionPublish = publishes.some(({ target }) => target === "site");
|
||||
|
||||
return (
|
||||
<Flex gap={2} shrink={false} direction={"column"}>
|
||||
@@ -555,8 +555,8 @@ const PublishStatic = ({
|
||||
}) => {
|
||||
const {
|
||||
isPublishing,
|
||||
logs,
|
||||
staticError,
|
||||
publishes,
|
||||
staticFailureFinding,
|
||||
openStaticReport: onOpenReport,
|
||||
} = flow;
|
||||
const project = useStore($project);
|
||||
@@ -565,23 +565,23 @@ const PublishStatic = ({
|
||||
throw new Error("Project not found");
|
||||
}
|
||||
|
||||
const { status, statusText } =
|
||||
const { status, statusContent } =
|
||||
project.latestStaticBuild == null
|
||||
? { status: "LOADED" as const, statusText: "Not published" }
|
||||
: getStaticPublishStatusAndText(project.latestStaticBuild);
|
||||
const latestLog = logs.find(
|
||||
? { status: "LOADED" as const, statusContent: "Not published" }
|
||||
: getStaticPublishStatusDisplay(project.latestStaticBuild);
|
||||
const latestPublish = publishes.find(
|
||||
(item) =>
|
||||
item.target === "static" &&
|
||||
item.buildId === project.latestStaticBuild?.buildId
|
||||
);
|
||||
const logStatus =
|
||||
staticError !== undefined
|
||||
staticFailureFinding !== undefined
|
||||
? "FAILED"
|
||||
: latestLog?.status === "pending"
|
||||
: latestPublish?.status === "pending"
|
||||
? "PENDING"
|
||||
: latestLog?.status === "failed"
|
||||
: latestPublish?.status === "failed"
|
||||
? "FAILED"
|
||||
: latestLog?.status === "success"
|
||||
: latestPublish?.status === "success"
|
||||
? "PUBLISHED"
|
||||
: status;
|
||||
|
||||
@@ -592,8 +592,10 @@ const PublishStatic = ({
|
||||
<Flex gap={2} align="center">
|
||||
<Tooltip
|
||||
content={
|
||||
staticError?.title ??
|
||||
(latestLog?.status === "failed" ? "Publish failed" : statusText)
|
||||
staticFailureFinding?.title ??
|
||||
(latestPublish?.status === "failed"
|
||||
? "Publish failed"
|
||||
: statusContent)
|
||||
}
|
||||
>
|
||||
<IconButton
|
||||
@@ -667,7 +669,7 @@ const useUserPublishCount = () => {
|
||||
};
|
||||
|
||||
const refreshProject = async () => {
|
||||
await getRefreshedProject({ projectId: $project.get()!.id });
|
||||
await fetchAndStoreProject({ projectId: $project.get()!.id });
|
||||
};
|
||||
|
||||
const buttonLinkClass = css({
|
||||
@@ -816,7 +818,7 @@ const Content = (props: {
|
||||
const hasCustomDomains = project.domainsVirtual.some(
|
||||
(domain) => domain.status === "ACTIVE" && domain.verified
|
||||
);
|
||||
const hasSitePublish = props.flow.logs.some(
|
||||
const hasSitePublish = props.flow.publishes.some(
|
||||
({ target }) => target === "site"
|
||||
);
|
||||
const diagnosticFindings = props.flow.siteFindings;
|
||||
@@ -893,7 +895,7 @@ const Content = (props: {
|
||||
onOpenReport={(domain) =>
|
||||
props.flow.openSiteReport(domain, "publish")
|
||||
}
|
||||
latestLog={props.flow.logs.find(
|
||||
latestPublish={props.flow.publishes.find(
|
||||
(item) =>
|
||||
item.target === "site" &&
|
||||
item.domains.includes(project.domain)
|
||||
@@ -909,7 +911,7 @@ const Content = (props: {
|
||||
onOpenReport={(domain) =>
|
||||
props.flow.openSiteReport(domain, "publish")
|
||||
}
|
||||
publishLogs={props.flow.logs}
|
||||
sessionPublishes={props.flow.publishes}
|
||||
/>
|
||||
</RadioGroup>
|
||||
</ScrollArea>
|
||||
@@ -1174,7 +1176,8 @@ export const PublishButton = ({ projectId }: PublishProps) => {
|
||||
const authTokenPermissions = useStore($authTokenPermissions);
|
||||
const { allowPublishLogs = false } = useStore($planFeatures);
|
||||
const flow = usePublishFlow(projectId, allowPublishLogs, publishDialog);
|
||||
const { selectedReport, closeReport, reportFindings, reportItems } = flow;
|
||||
const { diagnosticsSelection, closeReport, reportFindings, reportPublishes } =
|
||||
flow;
|
||||
const { canPublishToStagingOnly } = useStore($permissions);
|
||||
const isPublishEnabled =
|
||||
authTokenPermissions.canPublish || canPublishToStagingOnly;
|
||||
@@ -1236,19 +1239,19 @@ export const PublishButton = ({ projectId }: PublishProps) => {
|
||||
<PublishDiagnosticsDialog
|
||||
findings={reportFindings}
|
||||
includeLatestPublishFindings={flow.includeLatestPublishFindings}
|
||||
open={selectedReport !== undefined}
|
||||
open={diagnosticsSelection !== undefined}
|
||||
onOpenChange={(open) => {
|
||||
if (open === false) {
|
||||
closeReport();
|
||||
}
|
||||
}}
|
||||
target={
|
||||
selectedReport?.target === "static"
|
||||
diagnosticsSelection?.target === "static"
|
||||
? "Static export"
|
||||
: selectedReport?.domain
|
||||
: diagnosticsSelection?.domain
|
||||
}
|
||||
initialTab={selectedReport?.tab}
|
||||
items={reportItems}
|
||||
initialTab={diagnosticsSelection?.tab}
|
||||
items={reportPublishes}
|
||||
canViewPublishLogs={allowPublishLogs}
|
||||
onLoadLog={flow.loadLog}
|
||||
/>
|
||||
|
||||
@@ -269,14 +269,14 @@ test.each([
|
||||
await dispatch.promise.catch(() => {});
|
||||
});
|
||||
await waitForUpdate(() =>
|
||||
expect(flow.staticError?.reportText).toBe(message)
|
||||
expect(flow.staticFailureFinding?.reportText).toBe(message)
|
||||
);
|
||||
act(() => flow.openStaticReport());
|
||||
expect(flow.reportFindings.map(({ reportText }) => reportText)).toEqual([
|
||||
...completed,
|
||||
message,
|
||||
]);
|
||||
expect(flow.selectedReport?.tab).toBe("errors");
|
||||
expect(flow.diagnosticsSelection?.tab).toBe("errors");
|
||||
expect(toast.error).toHaveBeenCalledWith(message);
|
||||
if (order === "server-first") {
|
||||
await completeChecks();
|
||||
@@ -402,7 +402,9 @@ test.each([
|
||||
);
|
||||
await dispatch.promise;
|
||||
});
|
||||
await waitForUpdate(() => expect(flow.logs[0]?.logState).toBe("available"));
|
||||
await waitForUpdate(() =>
|
||||
expect(flow.publishes[0]?.logState).toBe("available")
|
||||
);
|
||||
checks = deferred<Response>();
|
||||
dispatch = deferred<Response>();
|
||||
start(target);
|
||||
@@ -436,7 +438,7 @@ test.each([
|
||||
const report = () =>
|
||||
getDiagnosticsReport({
|
||||
findings: flow.reportFindings,
|
||||
items: flow.reportItems,
|
||||
items: flow.reportPublishes,
|
||||
canViewPublishLogs: true,
|
||||
includeLatestPublishFindings: flow.includeLatestPublishFindings,
|
||||
});
|
||||
|
||||
@@ -12,15 +12,15 @@ import { usePublishValidationState } from "./publish-actions";
|
||||
import {
|
||||
usePublishProgress,
|
||||
waitForPublishStatus,
|
||||
refreshUntilSuccess,
|
||||
getRefreshedProject,
|
||||
refreshProjectWithRetry,
|
||||
fetchAndStoreProject,
|
||||
reportPublishResult,
|
||||
} from "./use-publish-progress";
|
||||
import {
|
||||
selectPublishLogs,
|
||||
usePublishLogs,
|
||||
type PublishLog,
|
||||
} from "./use-publish-logs";
|
||||
selectSessionPublishes,
|
||||
useSessionPublishes,
|
||||
type SessionPublish,
|
||||
} from "./use-session-publishes";
|
||||
import {
|
||||
runPublishDiagnostics,
|
||||
runPublishValidation,
|
||||
@@ -28,7 +28,7 @@ import {
|
||||
getServerPublishFindings,
|
||||
} from "./publish-validation";
|
||||
import { runPublishAfterBestEffortChecks } from "./publish-preflight";
|
||||
import type { PublishValidationFinding } from "./diagnostics";
|
||||
import type { DiagnosticFinding } from "./diagnostics";
|
||||
|
||||
const downloadStatic = (name: string) => {
|
||||
window.location.href = `/cgi/static/ssg/${name}`;
|
||||
@@ -37,7 +37,7 @@ const downloadStatic = (name: string) => {
|
||||
const getPublishErrorFinding = (
|
||||
error: JSX.Element | string,
|
||||
buildId?: string
|
||||
): PublishValidationFinding => ({
|
||||
): DiagnosticFinding => ({
|
||||
severity: "error",
|
||||
source: "publish",
|
||||
buildId,
|
||||
@@ -51,16 +51,16 @@ export const usePublishFlow = (
|
||||
allowPublishLogs: boolean,
|
||||
publishDialog: "none" | "publish" | "export"
|
||||
) => {
|
||||
const publishLogs = usePublishLogs(projectId, allowPublishLogs);
|
||||
const pendingLogs = useRef(publishLogs.items);
|
||||
pendingLogs.current = publishLogs.items;
|
||||
const [selectedReport, setSelectedReport] = useState<{
|
||||
const sessionPublishes = useSessionPublishes(projectId, allowPublishLogs);
|
||||
const sessionPublishesRef = useRef(sessionPublishes.items);
|
||||
sessionPublishesRef.current = sessionPublishes.items;
|
||||
const [diagnosticsSelection, setDiagnosticsSelection] = useState<{
|
||||
target: "static" | "site";
|
||||
domain?: string;
|
||||
tab: "warnings" | "errors" | "publish";
|
||||
}>();
|
||||
useEffect(() => {
|
||||
setSelectedReport(undefined);
|
||||
setDiagnosticsSelection(undefined);
|
||||
}, [projectId]);
|
||||
const validation = usePublishValidationState(publishDialog);
|
||||
const progress = usePublishProgress(projectId);
|
||||
@@ -80,7 +80,7 @@ export const usePublishFlow = (
|
||||
complete: completePublishLog,
|
||||
loadLog: loadPublishLog,
|
||||
isCurrent,
|
||||
} = publishLogs;
|
||||
} = sessionPublishes;
|
||||
const validationFindings = progress.manualValidationFindings;
|
||||
const { invalidate: invalidateValidationFindings } = validationFindings;
|
||||
const { update: onValidationStateChange } = validation;
|
||||
@@ -92,7 +92,7 @@ export const usePublishFlow = (
|
||||
|
||||
const finishPublish = useCallback(
|
||||
(
|
||||
item: PublishLog | undefined,
|
||||
item: SessionPublish | undefined,
|
||||
result: Awaited<ReturnType<typeof waitForPublishStatus>>,
|
||||
onDownload = downloadStatic
|
||||
) => {
|
||||
@@ -118,7 +118,7 @@ export const usePublishFlow = (
|
||||
);
|
||||
|
||||
const waitForCompletion = async (
|
||||
item: PublishLog | undefined,
|
||||
item: SessionPublish | undefined,
|
||||
previousBuildId?: string,
|
||||
onDownload = downloadStatic
|
||||
) => {
|
||||
@@ -126,7 +126,7 @@ export const usePublishFlow = (
|
||||
return;
|
||||
}
|
||||
const result = await waitForPublishStatus(
|
||||
() => getRefreshedProject({ projectId, isCurrent }),
|
||||
() => fetchAndStoreProject({ projectId, isCurrent }),
|
||||
isCurrent,
|
||||
previousBuildId,
|
||||
{
|
||||
@@ -145,9 +145,9 @@ export const usePublishFlow = (
|
||||
if (publishDialog !== "none" && progress.isPublishing === false) {
|
||||
let isOpen = true;
|
||||
const generation = beginPopoverRefresh();
|
||||
void refreshUntilSuccess(
|
||||
void refreshProjectWithRetry(
|
||||
async (showError) => {
|
||||
const refreshedProject = await getRefreshedProject({
|
||||
const refreshedProject = await fetchAndStoreProject({
|
||||
projectId,
|
||||
showError,
|
||||
isCurrent: () => isOpen && isRefreshCurrent(generation),
|
||||
@@ -164,7 +164,7 @@ export const usePublishFlow = (
|
||||
() => isOpen,
|
||||
() => {
|
||||
const target = publishDialog === "export" ? "static" : "site";
|
||||
const pending = pendingLogs.current.find(
|
||||
const pending = sessionPublishesRef.current.find(
|
||||
(item) => item.target === target && item.status === "pending"
|
||||
);
|
||||
if (target === "static" && pending === undefined) {
|
||||
@@ -172,7 +172,7 @@ export const usePublishFlow = (
|
||||
}
|
||||
void watchPendingPublish(
|
||||
() =>
|
||||
getRefreshedProject({
|
||||
fetchAndStoreProject({
|
||||
projectId,
|
||||
showError: false,
|
||||
isCurrent: () => isRefreshCurrent(generation),
|
||||
@@ -190,7 +190,7 @@ export const usePublishFlow = (
|
||||
);
|
||||
},
|
||||
() =>
|
||||
pendingLogs.current.some(
|
||||
sessionPublishesRef.current.some(
|
||||
(item) =>
|
||||
item.target ===
|
||||
(publishDialog === "export" ? "static" : "site") &&
|
||||
@@ -216,41 +216,41 @@ export const usePublishFlow = (
|
||||
tab: "warnings" | "errors" | "publish"
|
||||
) => {
|
||||
$publishDialog.set("none");
|
||||
setSelectedReport({ target: "site", domain, tab });
|
||||
setDiagnosticsSelection({ target: "site", domain, tab });
|
||||
};
|
||||
const openStaticReport = (
|
||||
tab: "warnings" | "errors" | "publish" = staticError === undefined
|
||||
tab: "warnings" | "errors" | "publish" = staticFailureFinding === undefined
|
||||
? "publish"
|
||||
: "errors"
|
||||
) => {
|
||||
$publishDialog.set("none");
|
||||
setSelectedReport({ target: "static", tab });
|
||||
setDiagnosticsSelection({ target: "static", tab });
|
||||
};
|
||||
const reportItems = selectPublishLogs(
|
||||
publishLogs.items,
|
||||
selectedReport?.target ?? "site",
|
||||
selectedReport?.domain
|
||||
const reportPublishes = selectSessionPublishes(
|
||||
sessionPublishes.items,
|
||||
diagnosticsSelection?.target ?? "site",
|
||||
diagnosticsSelection?.domain
|
||||
);
|
||||
const domain = selectedReport?.domain;
|
||||
const domain = diagnosticsSelection?.domain;
|
||||
const siteFindings = [
|
||||
...validationFindings.findings,
|
||||
...progress.publishFindings,
|
||||
];
|
||||
const staticDiagnostics = progress.publishDiagnostics.static;
|
||||
const staticError = staticDiagnostics.rejected
|
||||
const staticFailureFinding = staticDiagnostics.rejected
|
||||
? staticDiagnostics.findings
|
||||
.filter(({ severity }) => severity === "error")
|
||||
.at(-1)
|
||||
: undefined;
|
||||
const findings: PublishValidationFinding[] = [];
|
||||
const findings: DiagnosticFinding[] = [];
|
||||
const diagnostics =
|
||||
progress.publishDiagnostics[selectedReport?.target ?? "site"];
|
||||
const isReportForDiagnostics =
|
||||
progress.publishDiagnostics[diagnosticsSelection?.target ?? "site"];
|
||||
const includesSelectedDomain =
|
||||
domain === undefined || diagnostics.domains.includes(domain);
|
||||
if (isReportForDiagnostics) {
|
||||
if (includesSelectedDomain) {
|
||||
findings.push(...diagnostics.findings);
|
||||
}
|
||||
if (selectedReport?.target !== "static") {
|
||||
if (diagnosticsSelection?.target !== "static") {
|
||||
if (domain === undefined || validationFindings.domains?.includes(domain)) {
|
||||
findings.push(...validationFindings.findings);
|
||||
}
|
||||
@@ -426,13 +426,13 @@ export const usePublishFlow = (
|
||||
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
// Refresh locally as it's always an error
|
||||
await getRefreshedProject({ projectId, isCurrent });
|
||||
await fetchAndStoreProject({ projectId, isCurrent });
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const accepted = publishLogs.record({
|
||||
const accepted = sessionPublishes.record({
|
||||
buildId: publishResult.buildId,
|
||||
logHandle: publishResult.logHandle,
|
||||
target: request.target,
|
||||
@@ -458,7 +458,7 @@ export const usePublishFlow = (
|
||||
isCurrentProject,
|
||||
});
|
||||
} else if (isCurrent() && outcome?.status === "FAILED") {
|
||||
toast.error(outcome.statusText);
|
||||
toast.error(outcome.statusContent);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -481,15 +481,15 @@ export const usePublishFlow = (
|
||||
siteError: progress.publishError,
|
||||
siteErrorSource: progress.publishErrorSource,
|
||||
siteFindings,
|
||||
staticError,
|
||||
logs: publishLogs.items,
|
||||
loadLog: publishLogs.loadLog,
|
||||
selectedReport,
|
||||
closeReport: () => setSelectedReport(undefined),
|
||||
reportItems,
|
||||
staticFailureFinding,
|
||||
publishes: sessionPublishes.items,
|
||||
loadLog: sessionPublishes.loadLog,
|
||||
diagnosticsSelection,
|
||||
closeReport: () => setDiagnosticsSelection(undefined),
|
||||
reportPublishes,
|
||||
reportFindings: findings,
|
||||
includeLatestPublishFindings: !(
|
||||
diagnostics.rejected && isReportForDiagnostics
|
||||
diagnostics.rejected && includesSelectedDomain
|
||||
),
|
||||
openSiteReport,
|
||||
openStaticReport,
|
||||
|
||||
@@ -12,10 +12,10 @@ import { $publishDialog } from "~/builder/shared/nano-states";
|
||||
import { nativeClient } from "~/shared/trpc/trpc-client";
|
||||
import {
|
||||
PENDING_TIMEOUT,
|
||||
getPublishStatusAndText,
|
||||
getStaticPublishStatusAndText,
|
||||
getPublishStatusDisplay,
|
||||
getStaticPublishStatusDisplay,
|
||||
} from "./publish-status";
|
||||
import type { PublishValidationFinding } from "./diagnostics";
|
||||
import type { DiagnosticFinding } from "./diagnostics";
|
||||
|
||||
const COUNTDOWN_DURATION = 60_000;
|
||||
|
||||
@@ -46,7 +46,7 @@ export const usePublishProgress = (projectId: Project["id"]) => {
|
||||
"site" | "static",
|
||||
{
|
||||
domains: string[];
|
||||
findings: PublishValidationFinding[];
|
||||
findings: DiagnosticFinding[];
|
||||
rejected?: boolean;
|
||||
}
|
||||
>
|
||||
@@ -136,9 +136,7 @@ export const usePublishProgress = (projectId: Project["id"]) => {
|
||||
...current,
|
||||
[target]: { domains, findings: [] },
|
||||
}));
|
||||
const setFindings = (
|
||||
findings: SetStateAction<PublishValidationFinding[]>
|
||||
) => {
|
||||
const setFindings = (findings: SetStateAction<DiagnosticFinding[]>) => {
|
||||
if (publishDiagnosticsSession.current[target] === session) {
|
||||
setPublishDiagnostics((current) => ({
|
||||
...current,
|
||||
@@ -155,7 +153,7 @@ export const usePublishProgress = (projectId: Project["id"]) => {
|
||||
return {
|
||||
isCurrent: () => publishDiagnosticsSession.current[target] === session,
|
||||
setFindings,
|
||||
finish: (findings?: SetStateAction<PublishValidationFinding[]>) => {
|
||||
finish: (findings?: SetStateAction<DiagnosticFinding[]>) => {
|
||||
if (findings !== undefined) {
|
||||
setFindings(findings);
|
||||
}
|
||||
@@ -180,14 +178,14 @@ export const usePublishProgress = (projectId: Project["id"]) => {
|
||||
);
|
||||
return;
|
||||
}
|
||||
const { status, statusText } = getPublishStatusAndText(build);
|
||||
const { status, statusContent } = getPublishStatusDisplay(build);
|
||||
const isNewBuild =
|
||||
build.buildId !== undefined &&
|
||||
build.buildId !== requestBaselineBuildId.current;
|
||||
if (status === "FAILED") {
|
||||
if (hasStartedPublishRequest.current && isNewBuild) {
|
||||
setPublishErrorState({
|
||||
value: statusText,
|
||||
value: statusContent,
|
||||
source: "status",
|
||||
buildId: build.buildId,
|
||||
});
|
||||
@@ -232,7 +230,7 @@ export const usePublishProgress = (projectId: Project["id"]) => {
|
||||
isCurrentProject,
|
||||
});
|
||||
} else if (result?.status === "FAILED") {
|
||||
toast.error(result.statusText);
|
||||
toast.error(result.statusContent);
|
||||
}
|
||||
onResult?.(result);
|
||||
})
|
||||
@@ -368,7 +366,7 @@ export const waitForPublishStatus = async (
|
||||
if (job.status === "failed") {
|
||||
return {
|
||||
status: "FAILED" as const,
|
||||
statusText: "Publish failed",
|
||||
statusContent: "Publish failed",
|
||||
code: job.code,
|
||||
};
|
||||
}
|
||||
@@ -390,19 +388,19 @@ export const waitForPublishStatus = async (
|
||||
(previousBuildId === undefined || buildId !== previousBuildId) &&
|
||||
(execution === undefined || buildId === execution.buildId)
|
||||
) {
|
||||
const { statusText, status } =
|
||||
const { statusContent, status } =
|
||||
execution?.target === "static" &&
|
||||
refreshedProject.latestStaticBuild != null
|
||||
? getStaticPublishStatusAndText(refreshedProject.latestStaticBuild)
|
||||
? getStaticPublishStatusDisplay(refreshedProject.latestStaticBuild)
|
||||
: refreshedProject.latestBuildVirtual != null
|
||||
? getPublishStatusAndText(refreshedProject.latestBuildVirtual)
|
||||
? getPublishStatusDisplay(refreshedProject.latestBuildVirtual)
|
||||
: {
|
||||
statusText: "Not published",
|
||||
statusContent: "Not published",
|
||||
status: "PENDING" as const,
|
||||
};
|
||||
|
||||
if (!runnerPending && (status === "PUBLISHED" || status === "FAILED")) {
|
||||
return { status, statusText };
|
||||
return { status, statusContent };
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -418,7 +416,7 @@ export const waitForPublishStatus = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const refreshUntilSuccess = async (
|
||||
export const refreshProjectWithRetry = async (
|
||||
refresh: (showError: boolean) => Promise<Project | undefined>,
|
||||
isOpen: () => boolean,
|
||||
onPending: (project: Project) => void = () => {},
|
||||
@@ -435,7 +433,7 @@ export const refreshUntilSuccess = async (
|
||||
if (refreshedProject !== undefined) {
|
||||
if (
|
||||
(refreshedProject.latestBuildVirtual != null &&
|
||||
getPublishStatusAndText(refreshedProject.latestBuildVirtual)
|
||||
getPublishStatusDisplay(refreshedProject.latestBuildVirtual)
|
||||
.status === "PENDING") ||
|
||||
hasSessionPending(refreshedProject)
|
||||
) {
|
||||
@@ -499,14 +497,14 @@ export const reportPublishResult = ({
|
||||
|
||||
if (result?.status === "FAILED") {
|
||||
if ($publishDialog.get() !== "publish") {
|
||||
toast.error(result.statusText);
|
||||
toast.error(result.statusContent);
|
||||
}
|
||||
setPublishError(result.statusText, buildId);
|
||||
setPublishError(result.statusContent, buildId);
|
||||
}
|
||||
};
|
||||
|
||||
const useManualValidationFindings = () => {
|
||||
const [findings, setFindings] = useState<PublishValidationFinding[]>([]);
|
||||
const [findings, setFindings] = useState<DiagnosticFinding[]>([]);
|
||||
const [domains, setDomains] = useState<string[]>();
|
||||
const session = useRef(0);
|
||||
const requestedDomains = useRef<string[]>([]);
|
||||
@@ -533,7 +531,7 @@ const useManualValidationFindings = () => {
|
||||
|
||||
const isCurrent = useCallback((id: number) => session.current === id, []);
|
||||
|
||||
const update = useCallback((id: number, next: PublishValidationFinding[]) => {
|
||||
const update = useCallback((id: number, next: DiagnosticFinding[]) => {
|
||||
if (session.current === id) {
|
||||
setFindings(next);
|
||||
setDomains(next.length > 0 ? requestedDomains.current : undefined);
|
||||
@@ -543,7 +541,7 @@ const useManualValidationFindings = () => {
|
||||
return { findings, domains, begin, invalidate, isCurrent, update };
|
||||
};
|
||||
|
||||
export const getRefreshedProject = async ({
|
||||
export const fetchAndStoreProject = async ({
|
||||
projectId,
|
||||
showError = true,
|
||||
query = () => nativeClient.domain.project.query({ projectId }),
|
||||
@@ -576,8 +574,8 @@ export const getRefreshedProject = async ({
|
||||
export const __testing__ = {
|
||||
usePublishProgress,
|
||||
waitForPublishStatus,
|
||||
refreshUntilSuccess,
|
||||
refreshProjectWithRetry,
|
||||
reportPublishResult,
|
||||
useManualValidationFindings,
|
||||
getRefreshedProject,
|
||||
fetchAndStoreProject,
|
||||
};
|
||||
+7
-7
@@ -4,8 +4,8 @@ import { afterAll, afterEach, beforeAll, expect, test, vi } from "vitest";
|
||||
|
||||
let root: Root | undefined;
|
||||
let container: HTMLDivElement | undefined;
|
||||
let sessionModule: typeof import("./use-publish-logs");
|
||||
let session: ReturnType<typeof sessionModule.usePublishLogs>;
|
||||
let sessionModule: typeof import("./use-session-publishes");
|
||||
let session: ReturnType<typeof sessionModule.useSessionPublishes>;
|
||||
let paid = false;
|
||||
let holdFirst = false;
|
||||
let releaseFirst: (() => void) | undefined;
|
||||
@@ -25,7 +25,7 @@ const Harness = ({
|
||||
projectId: string;
|
||||
canViewPublishLogs: boolean;
|
||||
}) => {
|
||||
session = sessionModule.usePublishLogs(projectId, canViewPublishLogs);
|
||||
session = sessionModule.useSessionPublishes(projectId, canViewPublishLogs);
|
||||
return (
|
||||
<output>
|
||||
{session.items
|
||||
@@ -92,7 +92,7 @@ beforeAll(async () => {
|
||||
}
|
||||
return response;
|
||||
});
|
||||
sessionModule = await import("./use-publish-logs");
|
||||
sessionModule = await import("./use-session-publishes");
|
||||
const { updateCsrfToken } = await import("~/shared/csrf.client");
|
||||
updateCsrfToken("test-token");
|
||||
});
|
||||
@@ -298,17 +298,17 @@ test("session selection keeps repeated domain publishes separate from static exp
|
||||
];
|
||||
expect(
|
||||
sessionModule
|
||||
.selectPublishLogs(items, "site", "a.example")
|
||||
.selectSessionPublishes(items, "site", "a.example")
|
||||
.map(({ buildId }) => buildId)
|
||||
).toEqual(["site-1"]);
|
||||
expect(
|
||||
sessionModule
|
||||
.selectPublishLogs(items, "site", "b.example")
|
||||
.selectSessionPublishes(items, "site", "b.example")
|
||||
.map(({ buildId }) => buildId)
|
||||
).toEqual(["site-1", "site-2"]);
|
||||
expect(
|
||||
sessionModule
|
||||
.selectPublishLogs(items, "static")
|
||||
.selectSessionPublishes(items, "static")
|
||||
.map(({ buildId }) => buildId)
|
||||
).toEqual(["static-1"]);
|
||||
});
|
||||
+22
-19
@@ -1,13 +1,13 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { nativeClient } from "~/shared/trpc/trpc-client";
|
||||
import type { PublishValidationFinding } from "./diagnostics";
|
||||
import type { DiagnosticFinding } from "./diagnostics";
|
||||
|
||||
export type PublishLog = {
|
||||
export type SessionPublish = {
|
||||
buildId: string;
|
||||
domains: string[];
|
||||
target: "site" | "static";
|
||||
staticName?: string;
|
||||
findings: PublishValidationFinding[];
|
||||
findings: DiagnosticFinding[];
|
||||
logHandle?: string;
|
||||
status: "pending" | "success" | "failed";
|
||||
code?: string;
|
||||
@@ -34,7 +34,7 @@ export const decodePublishLog = (chunks: string[]) => {
|
||||
.join("");
|
||||
};
|
||||
|
||||
export const getPublishDuration = (item: PublishLog) => {
|
||||
export const getPublishDuration = (item: SessionPublish) => {
|
||||
if (item.startedAt === undefined || item.completedAt === undefined) {
|
||||
return;
|
||||
}
|
||||
@@ -44,8 +44,8 @@ export const getPublishDuration = (item: PublishLog) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const selectPublishLogs = (
|
||||
items: PublishLog[],
|
||||
export const selectSessionPublishes = (
|
||||
items: SessionPublish[],
|
||||
target: "site" | "static",
|
||||
domain?: string
|
||||
) =>
|
||||
@@ -55,11 +55,11 @@ export const selectPublishLogs = (
|
||||
(domain === undefined || item.domains.includes(domain))
|
||||
);
|
||||
|
||||
export const usePublishLogs = (
|
||||
export const useSessionPublishes = (
|
||||
projectId: string,
|
||||
canViewPublishLogs: boolean
|
||||
) => {
|
||||
const [items, setItems] = useState<PublishLog[]>([]);
|
||||
const [items, setItems] = useState<SessionPublish[]>([]);
|
||||
const itemsProjectId = useRef(projectId);
|
||||
const currentProjectId = useRef(projectId);
|
||||
currentProjectId.current = projectId;
|
||||
@@ -121,20 +121,23 @@ export const usePublishLogs = (
|
||||
}
|
||||
}, [canViewPublishLogs]);
|
||||
|
||||
const update = useCallback((buildId: string, change: Partial<PublishLog>) => {
|
||||
setItems((current) =>
|
||||
current.map((item) =>
|
||||
item.buildId === buildId ? { ...item, ...change } : item
|
||||
)
|
||||
);
|
||||
}, []);
|
||||
const update = useCallback(
|
||||
(buildId: string, change: Partial<SessionPublish>) => {
|
||||
setItems((current) =>
|
||||
current.map((item) =>
|
||||
item.buildId === buildId ? { ...item, ...change } : item
|
||||
)
|
||||
);
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const record = useCallback(
|
||||
(item: Omit<PublishLog, "status">) => {
|
||||
(item: Omit<SessionPublish, "status">) => {
|
||||
if (isCurrent() === false) {
|
||||
return;
|
||||
}
|
||||
const accepted: PublishLog = {
|
||||
const accepted: SessionPublish = {
|
||||
...item,
|
||||
status: "pending",
|
||||
startedAt: permission.current.allowed
|
||||
@@ -171,7 +174,7 @@ export const usePublishLogs = (
|
||||
);
|
||||
|
||||
const loadLog = useCallback(
|
||||
async (item: PublishLog) => {
|
||||
async (item: SessionPublish) => {
|
||||
if (
|
||||
isCurrent() === false ||
|
||||
retainedBuilds.current.has(item.buildId) === false ||
|
||||
@@ -201,7 +204,7 @@ export const usePublishLogs = (
|
||||
try {
|
||||
let cursor: number | undefined;
|
||||
const chunks: string[] = [];
|
||||
const issues: NonNullable<PublishLog["issues"]> = [];
|
||||
const issues: NonNullable<SessionPublish["issues"]> = [];
|
||||
let issuesOmitted = 0;
|
||||
while (isReadCurrent()) {
|
||||
const result = await nativeClient.api.publish.getLog.query({
|
||||
Reference in new issue
Block a user