mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
Simplify publish diagnostics status and scrolling
This commit is contained in:
1 parent
9d69e71806
commit
ba0212cfb7
10 files changed
+123
-69
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import { cssVar } from "@webstudio-is/design-system";
|
||||
import { AlertIcon, CheckCircleIcon, SpinnerIcon } from "@webstudio-is/icons";
|
||||
import type { PublishLog } from "./use-publish-logs";
|
||||
|
||||
export const publishLogStatus = {
|
||||
pending: {
|
||||
Icon: SpinnerIcon,
|
||||
color: cssVar("--foreground-warning"),
|
||||
text: "Publishing started",
|
||||
},
|
||||
failed: {
|
||||
Icon: AlertIcon,
|
||||
color: cssVar("--foreground-negative"),
|
||||
text: "Publish failed",
|
||||
},
|
||||
success: {
|
||||
Icon: CheckCircleIcon,
|
||||
color: cssVar("--foreground-positive"),
|
||||
text: "Published",
|
||||
},
|
||||
} satisfies Record<
|
||||
PublishLog["status"],
|
||||
{
|
||||
Icon: typeof AlertIcon;
|
||||
color: string;
|
||||
text: 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 "./publish-diagnostics-dialog";
|
||||
import type { PublishValidationFinding } from "./diagnostics";
|
||||
|
||||
type ContentDatabasePublishDiagnostics = Awaited<
|
||||
ReturnType<typeof nativeClient.build.contentDatabasePublishDiagnostics.query>
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import { StorySection } from "@webstudio-is/design-system";
|
||||
import {
|
||||
PublishDiagnosticsDialog,
|
||||
type PublishValidationFinding,
|
||||
} from "./publish-diagnostics-dialog";
|
||||
} from "./diagnostics";
|
||||
|
||||
export default {
|
||||
title: "Publish/Validation results",
|
||||
+64
-1
@@ -7,7 +7,7 @@ import {
|
||||
PublishDiagnosticsDialog,
|
||||
PublishValidationBanner,
|
||||
type PublishValidationFinding,
|
||||
} from "./publish-diagnostics-dialog";
|
||||
} from "./diagnostics";
|
||||
import type { PublishLog } from "./use-publish-logs";
|
||||
|
||||
let root: Root | undefined;
|
||||
@@ -68,6 +68,69 @@ const openDetails = (element: HTMLElement) => {
|
||||
act(() => button?.click());
|
||||
};
|
||||
|
||||
test.each(["findings", "details", "publish"] as const)(
|
||||
"scrolls overflowing %s with the native scroll container",
|
||||
async (view) => {
|
||||
const content = <div data-overflow-content style={{ height: 2000 }} />;
|
||||
render(
|
||||
view === "publish"
|
||||
? []
|
||||
: [
|
||||
{
|
||||
severity: "error",
|
||||
title: view === "details" ? "finding" : content,
|
||||
details: content,
|
||||
reportText: "report",
|
||||
},
|
||||
],
|
||||
true,
|
||||
view === "publish"
|
||||
? [
|
||||
{
|
||||
buildId: "scrolling-build",
|
||||
target: "site",
|
||||
domains: ["example.com"],
|
||||
findings: [],
|
||||
status: "success",
|
||||
logState: "available",
|
||||
logText: "line\n".repeat(200),
|
||||
},
|
||||
]
|
||||
: [],
|
||||
undefined,
|
||||
true
|
||||
);
|
||||
if (view === "details") {
|
||||
const finding = Array.from(document.body.querySelectorAll("button")).find(
|
||||
(button) => button.textContent === "finding"
|
||||
);
|
||||
await act(async () => userEvent.click(finding!));
|
||||
}
|
||||
const contentElement = document.body.querySelector<HTMLElement>(
|
||||
view === "publish" ? "pre" : "[data-overflow-content]"
|
||||
);
|
||||
if (view === "details") {
|
||||
expect(getComputedStyle(contentElement!.parentElement!).userSelect).toBe(
|
||||
"text"
|
||||
);
|
||||
}
|
||||
let scrollContainer = contentElement?.parentElement;
|
||||
while (
|
||||
scrollContainer &&
|
||||
getComputedStyle(scrollContainer).overflowY !== "auto"
|
||||
) {
|
||||
scrollContainer = scrollContainer.parentElement;
|
||||
}
|
||||
expect(scrollContainer).toBeTruthy();
|
||||
expect(scrollContainer!.clientHeight).toBeGreaterThan(0);
|
||||
expect(scrollContainer!.scrollHeight).toBeGreaterThan(
|
||||
scrollContainer!.clientHeight
|
||||
);
|
||||
scrollContainer!.scrollTop = 100;
|
||||
expect(scrollContainer!.scrollTop).toBe(100);
|
||||
}
|
||||
);
|
||||
|
||||
test("renders no publish summary when there are no findings", () => {
|
||||
expect(render([]).textContent).toBe("");
|
||||
});
|
||||
+12
-13
@@ -17,7 +17,7 @@ import {
|
||||
PanelTabsContent,
|
||||
PanelTabsList,
|
||||
PanelTabsTrigger,
|
||||
ScrollArea,
|
||||
ScrollAreaNative,
|
||||
SectionTitle,
|
||||
Separator,
|
||||
Text,
|
||||
@@ -27,6 +27,7 @@ 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 { publishLogStatus } from "./constants";
|
||||
|
||||
export type PublishValidationFinding = {
|
||||
severity: "error" | "warning";
|
||||
@@ -101,7 +102,7 @@ const FindingList = ({
|
||||
onSelect: (finding: PublishValidationFinding) => void;
|
||||
onOpenPublish?: () => void;
|
||||
}) => (
|
||||
<ScrollArea css={{ height: "100%" }}>
|
||||
<ScrollAreaNative css={{ height: "100%" }}>
|
||||
<PanelContent as={Flex} direction="column" gap={3}>
|
||||
{findings.map((finding, index) => (
|
||||
<Fragment key={`${finding.severity}-${index}`}>
|
||||
@@ -149,7 +150,7 @@ const FindingList = ({
|
||||
</Fragment>
|
||||
))}
|
||||
</PanelContent>
|
||||
</ScrollArea>
|
||||
</ScrollAreaNative>
|
||||
);
|
||||
|
||||
export const PublishDiagnosticsDialog = ({
|
||||
@@ -290,9 +291,11 @@ export const PublishDiagnosticsDialog = ({
|
||||
{selectedFinding.title}
|
||||
</Text>
|
||||
{selectedFinding.details !== undefined && (
|
||||
<ScrollArea css={{ minHeight: 0, flex: 1 }}>
|
||||
<Text userSelect="text">{selectedFinding.details}</Text>
|
||||
</ScrollArea>
|
||||
<ScrollAreaNative css={{ minHeight: 0, flex: 1 }}>
|
||||
<Text css={{ userSelect: "text" }}>
|
||||
{selectedFinding.details}
|
||||
</Text>
|
||||
</ScrollAreaNative>
|
||||
)}
|
||||
<div
|
||||
onClick={(event) => {
|
||||
@@ -358,7 +361,7 @@ export const PublishDiagnosticsDialog = ({
|
||||
value="publish"
|
||||
css={{ flex: 1, minHeight: 0, overflow: "hidden" }}
|
||||
>
|
||||
<ScrollArea css={{ height: "100%" }}>
|
||||
<ScrollAreaNative css={{ height: "100%" }}>
|
||||
<PanelContent as={Flex} direction="column" gap={3}>
|
||||
{!canViewPublishLogs && (
|
||||
<PanelBanner variant="info" role="note">
|
||||
@@ -424,11 +427,7 @@ export const PublishDiagnosticsDialog = ({
|
||||
}}
|
||||
>
|
||||
<Text color="subtle">
|
||||
{item.status === "pending"
|
||||
? "Publishing started"
|
||||
: item.status === "success"
|
||||
? "Published"
|
||||
: "Publish failed"}
|
||||
{publishLogStatus[item.status].text}
|
||||
</Text>
|
||||
{canViewPublishLogs &&
|
||||
item.startedAt !== undefined && (
|
||||
@@ -523,7 +522,7 @@ export const PublishDiagnosticsDialog = ({
|
||||
);
|
||||
})}
|
||||
</PanelContent>
|
||||
</ScrollArea>
|
||||
</ScrollAreaNative>
|
||||
</PanelTabsContent>
|
||||
</PanelTabs>
|
||||
)}
|
||||
@@ -46,6 +46,7 @@ import { RelativeTime } from "~/builder/shared/relative-time";
|
||||
import { $currentSystem } from "~/shared/system";
|
||||
import { getPublishUrl } from "./publish-url";
|
||||
import type { PublishLog } from "./use-publish-logs";
|
||||
import { publishLogStatus } from "./constants";
|
||||
|
||||
export type Domain = Project["domainsVirtual"][number];
|
||||
|
||||
@@ -175,30 +176,8 @@ const StatusIcon = (props: {
|
||||
props.latestLog?.buildId === props.projectDomain.latestBuildVirtual?.buildId
|
||||
? props.latestLog
|
||||
: undefined;
|
||||
const Icon =
|
||||
latestLog?.status === "pending"
|
||||
? SpinnerIcon
|
||||
: latestLog?.status === "failed"
|
||||
? AlertIcon
|
||||
: latestLog?.status === "success"
|
||||
? CheckCircleIcon
|
||||
: fallback.Icon;
|
||||
const color =
|
||||
latestLog?.status === "pending"
|
||||
? cssVar("--foreground-warning")
|
||||
: latestLog?.status === "failed"
|
||||
? cssVar("--foreground-negative")
|
||||
: latestLog?.status === "success"
|
||||
? cssVar("--foreground-positive")
|
||||
: fallback.color;
|
||||
const text =
|
||||
latestLog?.status === "pending"
|
||||
? "Publishing started"
|
||||
: latestLog?.status === "failed"
|
||||
? "Publish failed"
|
||||
: latestLog?.status === "success"
|
||||
? "Published"
|
||||
: fallback.text;
|
||||
const { Icon, color, text } =
|
||||
latestLog === undefined ? fallback : publishLogStatus[latestLog.status];
|
||||
|
||||
return (
|
||||
<Tooltip content={text}>
|
||||
|
||||
@@ -8,7 +8,7 @@ import { $publishDialog } from "~/builder/shared/nano-states";
|
||||
import { $project } from "~/shared/sync/data-stores";
|
||||
import { __testing__ } from "./publish";
|
||||
import { DomainCheckbox, domainToPublishName } from "./domain-checkbox";
|
||||
import { PublishDiagnosticsDialog } from "./publish-diagnostics-dialog";
|
||||
import { PublishDiagnosticsDialog } from "./diagnostics";
|
||||
|
||||
const {
|
||||
usePublishProgress,
|
||||
|
||||
@@ -124,7 +124,7 @@ import {
|
||||
PublishDiagnosticsDialog,
|
||||
PublishValidationBanner,
|
||||
type PublishValidationFinding,
|
||||
} from "./publish-diagnostics-dialog";
|
||||
} from "./diagnostics";
|
||||
import {
|
||||
selectPublishLogs,
|
||||
usePublishLogs,
|
||||
@@ -134,6 +134,7 @@ import { PublishActions, usePublishValidationState } from "./publish-actions";
|
||||
import { flushExternalContentProject } from "~/shared/external-content-roots";
|
||||
import { getPublishValidationErrorMessage } from "./publish-error";
|
||||
import { runPublishAfterBestEffortChecks } from "./publish-preflight";
|
||||
import { publishLogStatus } from "./constants";
|
||||
|
||||
const getPrePublishInstanceTarget = (
|
||||
instanceId: string,
|
||||
@@ -455,30 +456,13 @@ const ChangeProjectDomain = ({
|
||||
latestLog?.buildId === latestProjectDomainBuild?.buildId
|
||||
? latestLog
|
||||
: undefined;
|
||||
const LogIcon =
|
||||
currentLog?.status === "pending"
|
||||
? SpinnerIcon
|
||||
: currentLog?.status === "failed"
|
||||
? AlertIcon
|
||||
: currentLog?.status === "success"
|
||||
? CheckCircleIcon
|
||||
: Icon;
|
||||
const logColor =
|
||||
currentLog?.status === "pending"
|
||||
? cssVar("--foreground-warning")
|
||||
: currentLog?.status === "failed"
|
||||
? cssVar("--foreground-negative")
|
||||
: currentLog?.status === "success"
|
||||
? cssVar("--foreground-positive")
|
||||
: color;
|
||||
const logStatusText =
|
||||
currentLog?.status === "pending"
|
||||
? "Publishing started"
|
||||
: currentLog?.status === "failed"
|
||||
? "Publish failed"
|
||||
: currentLog?.status === "success"
|
||||
? "Published"
|
||||
: statusText;
|
||||
const {
|
||||
Icon: LogIcon,
|
||||
color: logColor,
|
||||
text: logStatusText,
|
||||
} = currentLog === undefined
|
||||
? { Icon, color, text: statusText }
|
||||
: publishLogStatus[currentLog.status];
|
||||
|
||||
const isPublished = latestProjectDomainBuild != null;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { nativeClient } from "~/shared/trpc/trpc-client";
|
||||
import type { PublishValidationFinding } from "./publish-diagnostics-dialog";
|
||||
import type { PublishValidationFinding } from "./diagnostics";
|
||||
|
||||
export type PublishLog = {
|
||||
buildId: string;
|
||||
|
||||
@@ -79,8 +79,9 @@ type ScrollAreaProps = {
|
||||
} & Pick<ComponentProps<"div">, "onScroll" | "children">;
|
||||
|
||||
/**
|
||||
* @deprecated Use ScrollAreaNative instead. Native scrolling avoids interaction
|
||||
* bugs from the custom Radix scroll area implementation.
|
||||
* @deprecated Do not use in new code. Use ScrollAreaNative instead. This legacy
|
||||
* Radix implementation remains only for existing callers; native scrolling
|
||||
* avoids its interaction bugs.
|
||||
*/
|
||||
export const ScrollArea = forwardRef(
|
||||
(
|
||||
|
||||
Reference in new issue
Block a user