fix(site/src/modules/workspaces/WorkspaceTiming): label timing rows directly instead of a color legend (#32393)
> [!NOTE] > Draft: the approach is still under design review, so this may change. Generated by Coder Agents on behalf of @chrifro. Resource and script bars in the build timeline could be told apart only by color, which fails WCAG 1.4.1 (Use of Color, Deque DEQ-255). Some actions, such as `state refresh` and unknown actions like `terraform` and `load`, also had identical swatches. Each timeline row now shows its action or status as text after the duration, and the toolbar legend is removed because it repeated that text. Bars keep their colors. The row text is `aria-hidden` because the bar's accessible name already includes the category (#32016). The legend types are renamed from `ChartLegend` to `ChartCategory`. Screenshots use real build timings from a coder/coder dogfood workspace (111 timings), served to a local build: | | Before | After | |---|---|---| | Plan |  |  | | Apply |  |  | | Startup scripts |  |  | <details> <summary>Verification with dogfood data</summary> I pulled the timings of 117 real builds from dogfood (1,089 script timings and 10,730 provisioner timings). I rendered three of them in the real app at 1400 and 768 px wide: a 111-row coder-kata build, a 114-row rebuild with 35 deletes, and an 18-row ephemeral build. Each stage was checked against the base commit: - Row counts per stage match the base commit (for example 4, 29, 27 and 15). - Every row has a label, and it matches the category in the bar's accessible name. - No label wraps, sits outside its row, or overlaps its bar. - No legend swatches remain (the base commit had 1 to 3 per stage). - At 768 px, two rows run past the chart's edge. On the base commit the same rows' bars and durations already run past it, and the chart scrolls horizontally to show them. - React warns about duplicate keys when a build deletes and recreates the same resource. The base commit has the same warning, so it is not caused by this PR. Every real script status was `ok`, so the other statuses are only covered by the existing stories, which still pass. </details> <details> <summary>Decision log</summary> - **Grey for the uncolored actions only:** rejected. It separates `terraform` from `state refresh`, but every category is still distinguished by color alone. - **3:1 contrast between legend entries:** rejected. The rule excludes colors that carry meaning (success, failure), the current fills are 1.0 to 1.4:1 against each other, and contrast can separate at most three entries within the 21:1 range. The charts have six or more. - **Icons for success and failure only:** rejected. The other script statuses and every resource action would still differ by color alone. - **Legend plus row text:** rejected after review because it repeated the same information. - **Row text without a legend (this PR):** each bar is labeled directly, so color carries no information that isn't shown as text. </details> Refs DEQ-255
This commit is contained in:
1 parent
267f1d8c9e
commit
8fae134458
5 files changed
+33
-43
No files matched your search
@@ -144,32 +144,27 @@ export const ChartSearch = (props: SearchFieldProps) => {
|
||||
);
|
||||
};
|
||||
|
||||
export type ChartLegend = {
|
||||
/** How a bar's category, such as a resource action or script status, is shown. */
|
||||
export type ChartCategory = {
|
||||
label: string;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
type ChartLegendsProps = {
|
||||
legends: ChartLegend[];
|
||||
type ChartCategoryLabelProps = {
|
||||
label: string;
|
||||
};
|
||||
|
||||
export const ChartLegends: React.FC<ChartLegendsProps> = ({ legends }) => {
|
||||
/**
|
||||
* Keeps a row's category readable without relying on bar color (WCAG 1.4.1).
|
||||
* Hidden from assistive technology because the bar's accessible name already
|
||||
* includes the label.
|
||||
*/
|
||||
export const ChartCategoryLabel: React.FC<ChartCategoryLabelProps> = ({
|
||||
label,
|
||||
}) => {
|
||||
return (
|
||||
<ul className="m-0 flex list-none items-center gap-6 pr-(--section-padding) p-0">
|
||||
{legends.map((l) => (
|
||||
<li
|
||||
key={l.label}
|
||||
className="flex items-center gap-2 font-medium leading-none"
|
||||
>
|
||||
<div
|
||||
className={cn(
|
||||
"size-icon-sm rounded border bg-surface-primary",
|
||||
l.className,
|
||||
)}
|
||||
/>
|
||||
{l.label}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<span aria-hidden className="whitespace-nowrap text-content-secondary">
|
||||
{label}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
@@ -105,7 +105,7 @@ export const ChartTableSection: React.FC<ChartTableSectionProps> = ({
|
||||
type ChartTableRowProps = {
|
||||
/** Row header content, such as the stage or resource name. */
|
||||
label: React.ReactNode;
|
||||
/** Timeline content, usually a bar followed by the duration. */
|
||||
/** Timeline content, usually a bar, its duration, and its category label. */
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ import { FocusableBar } from "./Chart/Bar";
|
||||
import {
|
||||
Chart,
|
||||
ChartBreadcrumbs,
|
||||
type ChartCategory,
|
||||
ChartCategoryLabel,
|
||||
ChartContent,
|
||||
type ChartLegend,
|
||||
ChartLegends,
|
||||
ChartSearch,
|
||||
ChartToolbar,
|
||||
} from "./Chart/Chart";
|
||||
@@ -57,9 +57,6 @@ export const ResourcesChart: React.FC<ResourcesChartProps> = ({
|
||||
(!isCoderResource(t.name) || isStageBoundary(t.name)) &&
|
||||
t.name.includes(filter),
|
||||
);
|
||||
const visibleLegends = [...new Set(visibleTimings.map((t) => t.action))].map(
|
||||
(a) => legendsByAction[a] ?? { label: a },
|
||||
);
|
||||
|
||||
return (
|
||||
<Chart>
|
||||
@@ -80,14 +77,15 @@ export const ResourcesChart: React.FC<ResourcesChartProps> = ({
|
||||
value={filter}
|
||||
onChange={setFilter}
|
||||
/>
|
||||
<ChartLegends legends={visibleLegends} />
|
||||
</ChartToolbar>
|
||||
<ChartContent>
|
||||
<ChartTable caption={`Resources in ${stage.name} stage`} ticks={ticks}>
|
||||
<ChartTableSection label={`${stage.name} stage`} ticks={ticks}>
|
||||
{visibleTimings.map((t) => {
|
||||
const duration = calcDuration(t.range);
|
||||
const legend = legendsByAction[t.action] ?? { label: t.action };
|
||||
const category = categoriesByAction[t.action] ?? {
|
||||
label: t.action,
|
||||
};
|
||||
const label = isStageBoundary(t.name)
|
||||
? "total stage duration"
|
||||
: t.name;
|
||||
@@ -97,11 +95,11 @@ export const ResourcesChart: React.FC<ResourcesChartProps> = ({
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<FocusableBar
|
||||
aria-label={`${label}: ${legend.label}`}
|
||||
aria-label={`${label}: ${category.label}`}
|
||||
value={duration}
|
||||
offset={calcOffset(t.range, generalTiming)}
|
||||
scale={scale}
|
||||
className={legend.className}
|
||||
className={category.className}
|
||||
/>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent
|
||||
@@ -112,6 +110,7 @@ export const ResourcesChart: React.FC<ResourcesChartProps> = ({
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
{formatTime(duration)}
|
||||
<ChartCategoryLabel label={category.label} />
|
||||
</ChartTableRow>
|
||||
);
|
||||
})}
|
||||
@@ -138,7 +137,7 @@ export const isCoderResource = (resource: string) => {
|
||||
// ProvisionerTiming to catch missing actions in the record. As a "workaround"
|
||||
// for now, we are using undefined since we don't have noUncheckedIndexedAccess
|
||||
// enabled.
|
||||
const legendsByAction: Record<string, ChartLegend | undefined> = {
|
||||
const categoriesByAction: Record<string, ChartCategory | undefined> = {
|
||||
"state refresh": {
|
||||
label: "state refresh",
|
||||
},
|
||||
|
||||
@@ -9,9 +9,9 @@ import { FocusableBar } from "./Chart/Bar";
|
||||
import {
|
||||
Chart,
|
||||
ChartBreadcrumbs,
|
||||
type ChartCategory,
|
||||
ChartCategoryLabel,
|
||||
ChartContent,
|
||||
type ChartLegend,
|
||||
ChartLegends,
|
||||
ChartSearch,
|
||||
ChartToolbar,
|
||||
} from "./Chart/Chart";
|
||||
@@ -53,9 +53,6 @@ export const ScriptsChart: React.FC<ScriptsChartProps> = ({
|
||||
const [ticks, scale] = makeTicks(totalTime);
|
||||
const [filter, setFilter] = useState("");
|
||||
const visibleTimings = timings.filter((t) => t.name.includes(filter));
|
||||
const visibleLegends = [...new Set(visibleTimings.map((t) => t.status))].map(
|
||||
(s) => legendsByStatus[s],
|
||||
);
|
||||
|
||||
return (
|
||||
<Chart>
|
||||
@@ -76,25 +73,24 @@ export const ScriptsChart: React.FC<ScriptsChartProps> = ({
|
||||
value={filter}
|
||||
onChange={setFilter}
|
||||
/>
|
||||
<ChartLegends legends={visibleLegends} />
|
||||
</ChartToolbar>
|
||||
<ChartContent>
|
||||
<ChartTable caption={`Scripts in ${stage.name} stage`} ticks={ticks}>
|
||||
<ChartTableSection label={`${stage.name} stage`} ticks={ticks}>
|
||||
{visibleTimings.map((t) => {
|
||||
const duration = calcDuration(t.range);
|
||||
const legend = legendsByStatus[t.status];
|
||||
const category = categoriesByStatus[t.status];
|
||||
|
||||
return (
|
||||
<ChartTableRow key={t.name} label={t.name}>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<FocusableBar
|
||||
aria-label={`${t.name}: ${legend.label}`}
|
||||
aria-label={`${t.name}: ${category.label}`}
|
||||
value={duration}
|
||||
offset={calcOffset(t.range, generalTiming)}
|
||||
scale={scale}
|
||||
className={legend.className}
|
||||
className={category.className}
|
||||
/>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent
|
||||
@@ -106,6 +102,7 @@ export const ScriptsChart: React.FC<ScriptsChartProps> = ({
|
||||
</Tooltip>
|
||||
|
||||
{formatTime(duration)}
|
||||
<ChartCategoryLabel label={category.label} />
|
||||
</ChartTableRow>
|
||||
);
|
||||
})}
|
||||
@@ -137,9 +134,9 @@ function tooltipContent(t: ScriptTiming): React.ReactNode {
|
||||
}
|
||||
}
|
||||
|
||||
// Keyed by the union so a status without a legend fails the type check
|
||||
// Keyed by the union so a status without a category fails the type check
|
||||
// instead of omitting its label at runtime.
|
||||
const legendsByStatus: Record<WorkspaceAgentScriptStatus, ChartLegend> = {
|
||||
const categoriesByStatus: Record<WorkspaceAgentScriptStatus, ChartCategory> = {
|
||||
ok: {
|
||||
label: "success",
|
||||
className: "bg-chart-success border-chart-success-border",
|
||||
|
||||
@@ -396,7 +396,6 @@ export const MissedAction: Story = {
|
||||
name: /^View apply details \d/,
|
||||
});
|
||||
await user.click(applyButton);
|
||||
await canvas.findByText("missed action");
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user