Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 35 additions & 23 deletions web/src/components/Inspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
BORDER_RADIUS,
SPACING,
getSpacingPx,
TYPOGRAPHY,
reducedMotion,
ScrollArea,
Text,
Tooltip,
Expand Down Expand Up @@ -58,34 +60,37 @@ const styles = (theme: Theme) =>
css({
"&": {
display: "grid",
gridTemplateRows: "auto auto 1fr auto",
gridTemplateRows: "auto auto minmax(0, 1fr) auto",
gridTemplateColumns: "100%",
backgroundColor: theme.vars.palette.background.default,
padding: "0",
width: "100%",
maxWidth: "500px",
minWidth: 0,
height: "100%",
containerType: "inline-size",
overflow: "hidden"
},

/* ---------- Head: icon + title + namespace + close ---------- */
".inspector-head": {
display: "grid",
gridTemplateColumns: "auto 1fr auto",
gridTemplateColumns: "auto minmax(0, 1fr) auto",
alignItems: "center",
gap: theme.spacing(1.5),
padding: `${theme.spacing(3)} ${theme.spacing(4)} ${theme.spacing(2)}`,
borderBottom: `1px solid ${theme.vars.palette.divider}`
padding: `${theme.spacing(SPACING.md)} ${theme.spacing(SPACING.lg)}`
},
".inspector-head:not(:has(.inspector-head-icon))": {
gridTemplateColumns: "minmax(0, 1fr) auto"
},
".inspector-head-icon": {
width: 32,
height: 32,
width: 24,
height: 24,
borderRadius: BORDER_RADIUS.md,
display: "grid",
placeItems: "center",
flexShrink: 0,
backgroundColor:
"var(--inspector-icon-tint, rgba(102,144,212,0.22))",
theme.vars.palette.c_overlay_subtle,
"& .icon-container": {
width: 16,
height: 16
Expand All @@ -103,9 +108,7 @@ const styles = (theme: Theme) =>
gap: 0
},
".inspector-title": {
fontFamily: theme.fontFamily1,
fontSize: "var(--fontSizeBig)",
fontWeight: 600,
...TYPOGRAPHY.sans.label,
letterSpacing: "-0.01em",
lineHeight: 1.2,
color: theme.vars.palette.text.primary,
Expand Down Expand Up @@ -133,13 +136,17 @@ const styles = (theme: Theme) =>
font: "inherit",
minWidth: 0,
display: "inline-flex",
alignItems: "center"
alignItems: "center",
"&:focus-visible": {
outline: `2px solid ${theme.vars.palette.primary.main}`,
outlineOffset: 2
}
},
".inspector-namespace-text": {
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
maxWidth: "26ch"
maxWidth: "100%"
},
".inspector-namespace .copy-button": {
width: 16,
Expand All @@ -150,20 +157,22 @@ const styles = (theme: Theme) =>
"& svg": { fontSize: "var(--fontSizeSmall)" }
},
".inspector-head-close": {
paddingTop: getSpacingPx(SPACING.micro)
paddingTop: getSpacingPx(SPACING.micro),
flexShrink: 0
},

/* ---------- Tabs ---------- */
".inspector-tabs": {
display: "flex",
alignItems: "stretch",
gap: 0,
padding: `0 ${theme.spacing(4)}`,
padding: `0 ${theme.spacing(SPACING.lg)}`,
borderBottom: `1px solid ${theme.vars.palette.divider}`,
backgroundColor: theme.vars.palette.background.default
},
".inspector-tab": {
position: "relative",
minHeight: 28,
background: "transparent",
border: "none",
cursor: "pointer",
Expand All @@ -179,6 +188,7 @@ const styles = (theme: Theme) =>
alignItems: "baseline",
gap: getSpacingPx(SPACING.sm),
transition: `color ${MOTION.fast}`,
...reducedMotion({ transition: MOTION.none }),
"&:hover": { color: theme.vars.palette.text.primary },
"&:focus-visible": {
outline: `2px solid ${theme.vars.palette.primary.main}`,
Expand Down Expand Up @@ -223,10 +233,11 @@ const styles = (theme: Theme) =>
gap: theme.spacing(3),
width: "100%",
height: "100%",
padding: theme.spacing(4)
padding: theme.spacing(SPACING.lg)
},
".top-content.tab-params": {
paddingLeft: `calc(${theme.spacing(3)} - 2px)`
".top-content.tab-params .node-property": {
padding: 0,
marginBottom: 0
},
".top-content > .node-property": {
display: "contents"
Expand All @@ -235,7 +246,8 @@ const styles = (theme: Theme) =>
/* ---------- Property rows ---------- */
".property-row": {
width: "100%",
minWidth: 0
minWidth: 0,
flexShrink: 0
},
".property-row .node-property": {
width: "100%",
Expand All @@ -251,7 +263,8 @@ const styles = (theme: Theme) =>
".property-row .inspector-header-toolbar.inspector-toolbar-hoverable .MuiIconButton-root, .property-row .inspector-header-toolbar.inspector-toolbar-hoverable .MuiButtonBase-root":
{
opacity: 0,
transition: `opacity ${MOTION.fast}`
transition: `opacity ${MOTION.fast}`,
...reducedMotion({ transition: MOTION.none })
},
".property-row:hover .inspector-header-toolbar.inspector-toolbar-hoverable .MuiIconButton-root, .property-row:hover .inspector-header-toolbar.inspector-toolbar-hoverable .MuiButtonBase-root, .property-row .inspector-header-toolbar.inspector-toolbar-hoverable:focus-within .MuiIconButton-root, .property-row .inspector-header-toolbar.inspector-toolbar-hoverable:focus-within .MuiButtonBase-root":
{
Expand Down Expand Up @@ -393,9 +406,8 @@ const styles = (theme: Theme) =>
letterSpacing: "0.02em",
color: theme.vars.palette.text.secondary,
padding: `${getSpacingPx(SPACING.micro)} ${getSpacingPx(SPACING.md)}`,
borderRadius: BORDER_RADIUS.pill,
backgroundColor: theme.vars.palette.action.hover,
border: `1px solid ${theme.vars.palette.divider}`
borderRadius: BORDER_RADIUS.sm,
backgroundColor: theme.vars.palette.action.hover
},
".help-meta": {
display: "flex",
Expand Down
46 changes: 44 additions & 2 deletions web/src/components/costs/WorkflowCostEstimatePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import { css } from "@emotion/react";
import React, { memo } from "react";
import { useTheme } from "@mui/material/styles";
import type { Theme } from "@mui/material/styles";
import { Box } from "../ui_primitives";
import { Box, Caption, CollapsibleSection, FlexRow, Label, SPACING } from "../ui_primitives";
import { useWorkflowCostEstimate } from "../../hooks/useWorkflowCostEstimate";
import { CostEstimateSummary } from "./CostEstimateSummary";
import { useCostEstimateSummary } from "./useCostEstimateSummary";

const styles = (theme: Theme) =>
css({
Expand Down Expand Up @@ -48,13 +49,54 @@ const styles = (theme: Theme) =>

interface WorkflowCostEstimatePanelProps {
workflowId: string;
compact?: boolean;
}

const WorkflowCostEstimatePanelInternal: React.FC<
WorkflowCostEstimatePanelProps
> = ({ workflowId }) => {
> = ({ workflowId, compact = false }) => {
const theme = useTheme();
const estimate = useWorkflowCostEstimate(workflowId);
const summary = useCostEstimateSummary(estimate);

if (compact) {
return (
<CollapsibleSection
defaultOpen={false}
unmountOnExit
onKeyDown={(event) => {
if (event.key === " " || event.key === "Enter") {
event.stopPropagation();
}
}}
title={
<FlexRow gap={SPACING.md} justify="space-between" wrap>
<Label>Cost estimate</Label>
<Caption>
{summary?.hasItems
? `${summary.isTotalLowerBound ? "≥ " : summary.isTotalApproximate ? "~" : ""}${summary.totalLabel}${summary.unknownCount > 0 ? " · incomplete" : " / run"}`
: "Per run"}
</Caption>
</FlexRow>
}
sx={{
px: SPACING.lg,
py: SPACING.xs,
"& > [role=button]": {
minHeight: 28,
"&:focus-visible": {
outline: `2px solid ${theme.vars.palette.primary.main}`,
outlineOffset: -2
}
}
}}
>
<Box sx={{ py: SPACING.md }}>
<CostEstimateSummary estimate={estimate} />
</Box>
</CollapsibleSection>
);
}

return (
<Box css={styles(theme)} className="cost-estimate">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,48 @@ const renderPanel = () =>
);

describe("WorkflowCostEstimatePanel", () => {
it("keeps a per-run estimate visible and opens details with the keyboard without canvas shortcuts", async () => {
mockHook.mockReturnValue(estimate as never);
render(
<ThemeProvider theme={mockTheme}>
<WorkflowCostEstimatePanel workflowId="wf_1" compact />
</ThemeProvider>
);
const disclosure = screen.getByRole("button", { name: /Cost estimate.*\/ run/ });
expect(disclosure).toHaveAttribute("aria-expanded", "false");
expect(screen.queryByText("Text To Image")).not.toBeInTheDocument();
const canvasShortcut = jest.fn();
window.addEventListener("keydown", canvasShortcut);
try {
disclosure.focus();
await userEvent.keyboard(" ");
expect(disclosure).toHaveAttribute("aria-expanded", "true");
expect(await screen.findByText("Text To Image")).toBeVisible();
expect(canvasShortcut).not.toHaveBeenCalled();
await userEvent.keyboard("{Enter}");
expect(disclosure).toHaveAttribute("aria-expanded", "false");
await waitFor(() => expect(screen.queryByText("Text To Image")).not.toBeInTheDocument());
} finally {
window.removeEventListener("keydown", canvasShortcut);
}
});

it("marks an incomplete estimate before its details are opened", () => {
mockHook.mockReturnValue({
...estimate,
total: 0,
unknown_count: 1,
items: [{ ...estimate.items[0], confidence: "unknown" }]
} as never);
render(
<ThemeProvider theme={mockTheme}>
<WorkflowCostEstimatePanel workflowId="wf_1" compact />
</ThemeProvider>
);
expect(screen.getByRole("button", { name: "Cost estimate — · incomplete" }))
.toHaveAttribute("aria-expanded", "false");
});

it("credits the price sources with the date the prices last moved", () => {
mockHook.mockReturnValue(estimate as never);
renderPanel();
Expand Down
32 changes: 17 additions & 15 deletions web/src/components/inspector/RunSelectedNodesSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ShortcutHint,
Text,
Tooltip,
MOTION, BORDER_RADIUS } from "../ui_primitives";
MOTION, BORDER_RADIUS, SPACING, TYPOGRAPHY, reducedMotion } from "../ui_primitives";
import { EditorButton } from "../editor_ui";
import {
MAX_RUNS,
Expand All @@ -27,28 +27,25 @@ const styles = (theme: Theme) =>
"&": {
borderTop: `1px solid ${theme.vars.palette.divider}`,
padding: `${theme.spacing(1.5)} ${theme.spacing(3)} ${theme.spacing(2)}`,
display: "flex",
flexDirection: "column",
gap: theme.spacing(1),
display: "grid",
gridTemplateColumns: "auto minmax(0, 1fr)",
alignItems: "center",
gap: theme.spacing(SPACING.md),
backgroundColor: theme.vars.palette.background.default
},
".runs-row": {
width: "100%"
width: "auto",
gap: theme.spacing(SPACING.xs)
},
".runs-label": {
fontFamily: theme.fontFamily1,
fontSize: "var(--fontSizeSmaller)",
fontWeight: 600,
letterSpacing: "0.08em",
textTransform: "uppercase",
...TYPOGRAPHY.sans.caption,
color: theme.vars.palette.text.secondary
},
".stepper-control": {
border: `1px solid ${theme.vars.palette.divider}`,
borderRadius: BORDER_RADIUS.md,
paddingLeft: theme.spacing(0.5),
paddingRight: theme.spacing(0.5),
backgroundColor: "transparent"
backgroundColor: theme.vars.palette.c_overlay_subtle
},
".stepper-control .MuiButtonBase-root": {
borderRadius: BORDER_RADIUS.sm,
Expand All @@ -71,10 +68,10 @@ const styles = (theme: Theme) =>
padding: `${theme.spacing(1)} ${theme.spacing(1.5)}`,
backgroundColor: theme.vars.palette.primary.main,
color: theme.vars.palette.primary.contrastText,
fontSize: theme.fontSizeNormal,
fontWeight: 500,
...TYPOGRAPHY.sans.label,
borderRadius: BORDER_RADIUS.md,
transition: `background-color ${MOTION.fast}`,
...reducedMotion({ transition: MOTION.none }),
"&:hover": {
backgroundColor: theme.vars.palette.primary.dark
},
Expand All @@ -93,6 +90,11 @@ const styles = (theme: Theme) =>
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap"
},
"@container (max-width: 240px)": {
"&": {
gridTemplateColumns: "minmax(0, 1fr)"
}
}
});

Expand Down Expand Up @@ -167,7 +169,7 @@ const RunSelectedNodesSectionInternal: React.FC = () => {
aria-label="Run selected nodes"
>
<PlayArrowIcon className="play-icon" />
<span className="run-label">Run selected nodes</span>
<span className="run-label">Run selected</span>
</EditorButton>
</Tooltip>
{inSequence && runProgress !== null ? (
Expand Down
Loading
Loading