Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(eng-analytics): draw ci explorer job nodes (#111948)

Raúl Negrón-Otero86f3cde1f633
diff --git a/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerCanvas.scss b/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerCanvas.scss
new file mode 100644
index 000000000000..942fad66b6f2
--- /dev/null
+++ b/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerCanvas.scss
@@ -0,0 +1,678 @@
+// The canvas keeps lines and labels readable at any zoom. `--k` is the camera zoom and `--s` is how much a
+// tile's graph was shrunk to fit the tile, so `--k * --s` is the zoom a job node is seen at.
+.CIExplorer {
+ --ci-line: color-mix(in oklab, var(--color-text-primary) 34%, var(--color-bg-primary));
+ --ci-edge: color-mix(in oklab, var(--color-text-primary) 22%, transparent);
+ --ci-ease: cubic-bezier(0.22, 0.8, 0.24, 1);
+ --ci-shadow: 0 2px 0 color-mix(in oklab, var(--color-border-primary), transparent 10%);
+ --k: 1;
+ --i0: calc(1 / max(1, var(--k)));
+ --i1: min(1, calc(26 / (16 * var(--k))));
+
+ width: 100%;
+ height: 100%;
+ background: var(--color-bg-primary);
+
+ &:focus-visible {
+ outline: 2px solid var(--color-accent);
+ outline-offset: -2px;
+ }
+
+ &__cardButton:focus-visible {
+ outline: calc(2px * var(--i0)) solid var(--color-accent);
+ outline-offset: calc(2px * var(--i0));
+ }
+
+ // A node inside a tile's graph is also shrunk with the graph, so its outline is sized for both scales.
+ &__job:focus-visible,
+ &__cellHead:focus-visible,
+ &__step:focus-visible {
+ outline: calc(2px * var(--b2)) solid var(--color-accent);
+ outline-offset: calc(2px * var(--b2));
+ }
+
+ // The cell clips what extends past its border, so the outline of a shard is drawn inside the head.
+ &__cellHead:focus-visible {
+ outline-offset: calc(-2px * var(--b2));
+ }
+
+ .react-flow__pane {
+ cursor: grab;
+
+ &.dragging {
+ cursor: grabbing;
+ }
+ }
+
+ &__world {
+ position: absolute;
+ top: 0;
+ left: 0;
+ }
+
+ &__rail {
+ position: absolute;
+ inset: 0;
+ overflow: visible;
+ pointer-events: none;
+ transition: opacity 0.3s;
+
+ path {
+ fill: none;
+ stroke: var(--ci-edge);
+ stroke-width: 1.5;
+ }
+
+ circle {
+ fill: var(--ci-edge);
+ }
+ }
+
+ &__origin {
+ position: absolute;
+ top: 0;
+ display: flex;
+ gap: 8px;
+ align-items: baseline;
+ height: 40px;
+ font-weight: 600;
+ line-height: 40px;
+ white-space: nowrap;
+ transition: opacity 0.3s;
+
+ span {
+ font-weight: 400;
+ color: var(--color-text-secondary);
+ }
+ }
+
+ &[data-deep='true'] &__rail,
+ &[data-deep='true'] &__origin {
+ opacity: 0;
+ }
+
+ &__dot {
+ flex: none;
+ width: 0.55em;
+ height: 0.55em;
+ border-radius: 50%;
+
+ &--success {
+ background: var(--success);
+ }
+
+ &--failure {
+ background: var(--danger);
+ }
+
+ &--running {
+ background: var(--warning);
+ }
+
+ &--neutral {
+ background: var(--muted);
+ }
+ }
+
+ &__duration {
+ font-family: var(--font-mono);
+ color: var(--color-text-secondary);
+ white-space: nowrap;
+ }
+
+ // A workflow tile. Zoomed in, the tile fades and the job graph inside it takes over.
+ &__card {
+ --i2: min(1, calc(26 / (13 * var(--k) * var(--s))));
+ --b2: calc(1 / max(1, var(--k) * var(--s)));
+
+ position: absolute;
+ box-sizing: border-box;
+ width: 300px;
+ height: 134px;
+
+ // React Flow turns pointer events off for everything in its viewport that is not one of its nodes.
+ pointer-events: auto;
+ background: var(--color-bg-surface-primary);
+ border: calc(1px * var(--i0)) solid var(--color-border-primary);
+ border-radius: 8px;
+ box-shadow: var(--ci-shadow);
+
+ // No transition: a failed tile's red border would fade through the zoom and read as a flash.
+ &--failure {
+ border-color: var(--danger);
+ }
+ }
+
+ &[data-deep='true'] &__card {
+ background: transparent;
+ border-color: transparent;
+ box-shadow: none;
+ }
+
+ &__cardButton {
+ position: absolute;
+ inset: 0;
+ box-sizing: border-box;
+ display: block;
+ width: 100%;
+ padding: 16px;
+ color: inherit;
+ text-align: left;
+ cursor: zoom-in;
+ background: none;
+ border: 0;
+ border-radius: inherit;
+ }
+
+ &[data-deep='true'] &__cardButton {
+ cursor: grab;
+ }
+
+ &__cardHeader {
+ display: flex;
+ gap: 0.5em;
+ align-items: center;
+ height: 60px;
+ font-size: calc(16px * var(--i1));
+ line-height: 1.25;
+ transition: opacity 0.28s;
+
+ // A long workflow name wraps to three lines. The tooltip has the whole name.
+ b {
+ display: -webkit-box;
+ min-width: 0;
+ overflow: hidden;
+ font-weight: 600;
+ overflow-wrap: anywhere;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 3;
+ }
+ }
+
+ &__provider {
+ flex: none;
+ width: 1em;
+ height: 1em;
+ color: var(--color-text-primary);
+ }
+
+ &__cardHeader &__duration {
+ margin-left: auto;
+ font-size: 0.82em;
+ }
+
+ &__cardBar {
+ display: block;
+ height: 4px;
+ margin-top: 16px;
+ background: var(--color-border-primary);
+ border-radius: 2px;
+ transition: opacity 0.3s;
+
+ i {
+ display: block;
+ height: 100%;
+ background: var(--color-text-secondary);
+ border-radius: 2px;
+ }
+ }
+
+ &__card--failure &__cardBar i {
+ background: var(--danger);
+ }
+
+ &[data-deep='true'] &__cardHeader,
+ &[data-deep='true'] &__cardBar {
+ opacity: 0;
+ }
+
+ &__graph {
+ position: absolute;
+ pointer-events: none;
+ opacity: 0;
+ transition: opacity 0.3s;
+ transform-origin: 0 0;
+
+ > svg {
+ position: absolute;
+ inset: 0;
+ overflow: visible;
+ pointer-events: none;
+
+ path {
+ fill: none;
+ stroke: var(--ci-edge);
+ stroke-width: 1.5;
+ }
+
+ circle {
+ fill: var(--ci-edge);
+ }
+ }
+ }
+
+ &[data-deep='true'] &__graph {
+ pointer-events: auto;
+ opacity: 1;
+ }
+
+ // A job node. Its outline is the job's kind, drawn as two clipped layers so the line keeps its width.
+ &__unit {
+ --u: 1px;
+ --bw: calc(1.5px * var(--b2));
+ --shape: inset(0 round calc(4 * var(--u)));
+
+ position: absolute;
+ box-sizing: border-box;
+ padding-bottom: 10px;
+ isolation: isolate;
+
+ &::before,
+ &::after {
+ position: absolute;
+ inset: 0;
+ clip-path: var(--shape);
+ content: '';
+ }
+
+ &::before {
+ z-index: -2;
+ background: var(--ci-line);
+ }
+
+ &::after {
+ inset: var(--bw);
+ z-index: -1;
+ background: var(--color-bg-primary);
+ }
+
+ &:has(> .CIExplorer__job:hover)::after {
+ background: var(--color-bg-surface-primary);
+ }
+
+ &--setup,
+ &--report {
+ --shape: inset(0 round calc(24 * var(--u)));
+ }
+
+ &--check {
+ --c: calc(17 * var(--u));
+ --shape: polygon(
+ var(--c) 0,
+ calc(100% - var(--c)) 0,
+ 100% var(--c),
+ 100% calc(100% - var(--c)),
+ calc(100% - var(--c)) 100%,
+ var(--c) 100%,
+ 0 calc(100% - var(--c)),
+ 0 var(--c)
+ );
+ }
+
+ &--build {
+ --c: calc(16 * var(--u));
+ --shape: polygon(0 0, calc(100% - var(--c)) 0, 100% var(--c), 100% 100%, 0 100%);
+ }
+
+ &--failure::before {
+ background: var(--danger);
+ }
+
+ &--focus::before {
+ background: var(--color-text-primary);
+ }
+ }
+
+ // The second sheet behind a matrix node.
+ &__stack {
+ position: absolute;
+ inset: 0;
+ z-index: -3;
+ clip-path: var(--shape);
+ background: color-mix(in oklab, var(--color-text-primary) 20%, var(--color-bg-primary));
+ transform: translate(calc(6px * var(--b2)), calc(6px * var(--b2)));
+ }
+
+ &__job {
+ position: relative;
+ box-sizing: border-box;
+ display: block;
+ width: 100%;
+ padding: 0 12px;
+ color: inherit;
+ text-align: left;
+ cursor: zoom-in;
+ background: none;
+ border: 0;
+
+ &[aria-pressed='true'] {
+ cursor: default;
+ }
+ }
+
+ &__jobTitle {
+ display: flex;
+ gap: 0.6em;
+ align-items: center;
+ height: calc(var(--th) * var(--i2));
+ font-size: calc(13px * var(--i2));
+ }
+
+ // The layout reserves three lines for a job name. A longer one is cut there, and the tooltip has all of it.
+ &__jobName {
+ display: -webkit-box;
+ flex: 1;
+ min-width: 0;
+ overflow: hidden;
+ font-weight: 500;
+ line-height: 1.3;
+ overflow-wrap: anywhere;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 3;
+ }
+
+ &__unit--failure &__jobName {
+ color: var(--danger);
+ }
+
+ &__jobTitle &__duration {
+ font-size: 0.92em;
+ }
+
+ &__meter {
+ display: block;
+ height: 2px;
+ background: var(--color-border-primary);
+ border-radius: 1px;
+
+ i {
+ display: block;
+ height: 100%;
+ background: var(--color-text-secondary);
+ border-radius: 1px;
+ }
+ }
+
+ &__unit--failure &__meter i {
+ background: var(--danger);
+ }
+
+ // A matrix lays its shards out wide and scales them down. They appear once they are large enough to read.
+ &__cells {
+ position: relative;
+ margin: 12px 12px 0;
+ }
+
+ &__cellGrid {
+ position: absolute;
+ top: 0;
+ left: 0;
+ display: grid;
+ grid-template-columns: repeat(3, 1fr);
+ gap: 8px;
+ align-items: start;
+ width: 744px;
+ opacity: clamp(0, calc((var(--k) * var(--s) * 0.3226 - 0.4) * 10), 1);
+ transform-origin: 0 0;
+ }
+
+ // Shards too small to see must not take clicks or the keyboard focus. The canvas marks a tile once its
+ // shards are large enough to show.
+ &__card:not([data-shards='true']) &__cellGrid {
+ visibility: hidden;
+ }
+
+ &__cell {
+ box-sizing: border-box;
+ min-width: 0;
+ overflow: hidden;
+ font-size: 12px;
+ background: var(--color-bg-surface-primary);
+ border: 1px solid color-mix(in oklab, var(--color-text-primary) 22%, var(--color-bg-primary));
+ border-radius: 4px;
+
+ &:hover {
+ background: var(--color-bg-surface-secondary);
+ }
+
+ &--failure {
+ color: var(--danger);
+ background: var(--color-bg-fill-error-tertiary);
+ border-color: var(--danger);
+ }
+
+ // A focused shard takes a row of its own, which makes room for its steps.
+ &--focus {
+ grid-column: 1 / -1;
+ background: var(--color-bg-surface-primary);
+ border-color: var(--color-text-primary);
+ }
+ }
+
+ &__cellHead {
+ position: relative;
+ box-sizing: border-box;
+ display: flex;
+ gap: 8px;
+ align-items: center;
+ width: 100%;
+
+ // The cell's border takes the other two pixels of a 40px grid row.
+ height: 38px;
+ padding: 4px 10px;
+ color: inherit;
+ text-align: left;
+ cursor: zoom-in;
+ background: none;
+ border: 0;
+
+ // The shard's share of the slowest shard, as a fill behind its name.
+ &::before {
+ position: absolute;
+ inset: 0 auto 0 0;
+ width: calc(var(--w, 0) * 100%);
+ content: '';
+ background: color-mix(in oklab, var(--color-text-primary) 8%, transparent);
+ }
+
+ > * {
+ position: relative;
+ }
+
+ &[aria-pressed='true'] {
+ font-size: 14px;
+ font-weight: 600;
+ cursor: default;
+ }
+ }
+
+ &__cellSteps {
+ padding: 4px 10px 10px;
+ }
+
+ // The steps of a focused job are laid out as wide as a shard grid, then scaled down to fit the node.
+ &__cells--steps {
+ margin-top: 4px;
+ }
+
+ &__scaled {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 744px;
+ transform-origin: 0 0;
+ }
+
+ &__steps {
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+ padding: 0;
+ margin: 0;
+ list-style: none;
+ }
+
+ &__step {
+ position: relative;
+ box-sizing: border-box;
+ display: grid;
+ grid-template-columns: 28px minmax(0, 1fr) auto;
+ gap: 8px;
+ align-items: center;
+ height: 32px;
+ padding: 4px 10px;
+ overflow: hidden;
+ font-size: 13px;
+ font-weight: 400;
+ line-height: 18px;
+ color: var(--color-text-primary);
+ text-decoration: none;
+ border-radius: 6px;
+
+ // The step's share of the slowest step, as a fill behind its name.
+ &::before {
+ position: absolute;
+ inset: 0 auto 0 0;
+ width: calc(var(--w, 0) * 100%);
+ content: '';
+ background: color-mix(in oklab, var(--color-text-primary) 12%, transparent);
+ border-radius: 6px;
+ }
+
+ > * {
+ position: relative;
+ }
+
+ &--failure {
+ color: var(--danger);
+
+ &::before {
+ background: var(--color-bg-fill-error-tertiary);
+ }
+ }
+ }
+
+ // The step the Context tab is comparing.
+ &__step--compared {
+ outline: 1.5px solid var(--color-text-primary);
+ outline-offset: -1.5px;
+ }
+
+ a#{&}__step:hover {
+ color: var(--color-text-primary);
+ text-decoration: underline;
+ }
+
+ &__stepIndex {
+ font-family: var(--font-mono);
+ font-size: 11px;
+ color: var(--color-text-tertiary);
+ text-align: right;
+ }
+
+ &__stepLabel {
+ display: flex;
+ gap: 8px;
+ align-items: center;
+ min-width: 0;
+
+ // The name gives way before a chip does, because a chip is what the log found.
+ .LemonTag {
+ flex: none;
+ }
+ }
+
+ &__stepName {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+
+ &__step &__duration {
+ font-size: 12px;
+ }
+
+ &__cellName {
+ display: -webkit-box;
+ flex: 1;
+ min-width: 0;
+ overflow: hidden;
+ line-height: 15px;
+ overflow-wrap: anywhere;
+ -webkit-box-orient: vertical;
+ -webkit-line-clamp: 2;
+ }
+
+ &__cell &__duration {
+ font-size: 11px;
+ }
+
+ &__legend {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 4px 16px;
+ align-items: center;
+ padding: 6px 12px;
+ font-size: 12px;
+ color: var(--color-text-secondary);
+ background: var(--color-bg-surface-primary);
+ border: 1px solid var(--color-border-primary);
+ border-radius: 8px;
+ box-shadow: var(--ci-shadow);
+
+ span {
+ display: flex;
+ gap: 6px;
+ align-items: center;
+ }
+ }
+
+ &__swatch {
+ --u: 0.32px;
+ --shape: inset(0 round calc(4 * var(--u)));
+
+ flex: none;
+ width: 26px;
+ height: 14px;
+ clip-path: var(--shape);
+ background: var(--color-text-secondary);
+
+ &--setup {
+ --shape: inset(0 round calc(24 * var(--u)));
+ }
+
+ &--check {
+ --c: calc(17 * var(--u));
+ --shape: polygon(
+ var(--c) 0,
+ calc(100% - var(--c)) 0,
+ 100% var(--c),
+ 100% calc(100% - var(--c)),
+ calc(100% - var(--c)) 100%,
+ var(--c) 100%,
+ 0 calc(100% - var(--c)),
+ 0 var(--c)
+ );
+ }
+
+ &--build {
+ --c: calc(16 * var(--u));
+ --shape: polygon(0 0, calc(100% - var(--c)) 0, 100% var(--c), 100% 100%, 0 100%);
+ }
+
+ &--matrix {
+ width: 16px;
+ height: 9px;
+ margin-right: 4px;
+ clip-path: none;
+ border-radius: 2px;
+ box-shadow: 4px 3px 0 var(--color-border-primary);
+ }
+ }
+
+ @media (prefers-reduced-motion: reduce) {
+ * {
+ transition: none !important;
+ }
+ }
+}
diff --git a/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerChips.tsx b/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerChips.tsx
new file mode 100644
index 000000000000..b77da5cdc8a6
--- /dev/null
+++ b/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerChips.tsx
@@ -0,0 +1,49 @@
+import { LemonTag, LemonTagType } from '@posthog/lemon-ui'
+
+import { pluralize } from 'lib/utils/strings'
+
+import type { JobLogBadgeApi } from '../../generated/api.schemas'
+
+function counted(text: string, count: number): string {
+ return count > 1 ? `${text} ×${count}` : text
+}
+
+function chip(badge: JobLogBadgeApi): { text: string; type: LemonTagType } {
+ if (badge.kind === 'migrations') {
+ return {
+ text: badge.state === 'applied' ? pluralize(badge.count, 'migration') : 'no migrations',
+ type: 'muted',
+ }
+ }
+ switch (badge.state) {
+ case 'hit':
+ return { text: counted('cache hit', badge.count), type: 'success' }
+ case 'partial':
+ return { text: counted('older cache', badge.count), type: 'warning' }
+ case 'failed':
+ return { text: counted('cache restore failed', badge.count), type: 'warning' }
+ default:
+ return { text: counted('cache miss', badge.count), type: 'warning' }
+ }
+}
+
+/** What a job's log says a step did, a few words each. The cache keys are in the chip's tooltip. */
+export function CIExplorerChips({ badges }: { badges: JobLogBadgeApi[] }): JSX.Element {
+ return (
+ <>
+ {badges.map((badge) => {
+ const { text, type } = chip(badge)
+ return (
+ <LemonTag
+ key={`${badge.kind}-${badge.state}`}
+ type={type}
+ size="small"
+ title={badge.detail.filter(Boolean).join('\n')}
+ >
+ {text}
+ </LemonTag>
+ )
+ })}
+ </>
+ )
+}
diff --git a/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerLegend.tsx b/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerLegend.tsx
new file mode 100644
index 000000000000..c7c2a3ccf625
--- /dev/null
+++ b/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerLegend.tsx
@@ -0,0 +1,21 @@
+const KINDS: [string, string][] = [
+ ['test', 'Test'],
+ ['check', 'Check'],
+ ['build', 'Build'],
+ ['setup', 'Setup or report'],
+ ['matrix', 'Matrix'],
+]
+
+/** What each node outline means. Shown while job nodes are on screen. */
+export function CIExplorerLegend(): JSX.Element {
+ return (
+ <div className="CIExplorer__legend">
+ {KINDS.map(([kind, label]) => (
+ <span key={kind}>
+ <i className={`CIExplorer__swatch CIExplorer__swatch--${kind}`} />
+ {label}
+ </span>
+ ))}
+ </div>
+ )
+}
diff --git a/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerProviderMark.tsx b/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerProviderMark.tsx
new file mode 100644
index 000000000000..b52b690510bf
--- /dev/null
+++ b/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerProviderMark.tsx
@@ -0,0 +1,27 @@
+import { CIEngine, providerName } from '../../lib/ciExplorerDetails'
+
+// GitHub's mark is from Octicons (mark-github-16) and Depot's is the mark of depot.dev.
+const MARKS: Record<NonNullable<CIEngine>, { viewBox: string; path: string }> = {
+ github_actions: {
+ viewBox: '0 0 16 16',
+ path: 'M6.766 11.328c-2.063-.25-3.516-1.734-3.516-3.656 0-.781.281-1.625.75-2.188-.203-.515-.172-1.609.063-2.062.625-.078 1.468.25 1.968.703.594-.187 1.219-.281 1.985-.281.765 0 1.39.094 1.953.265.484-.437 1.344-.765 1.969-.687.218.422.25 1.515.046 2.047.5.593.766 1.39.766 2.203 0 1.922-1.453 3.375-3.547 3.64.531.344.89 1.094.89 1.954v1.625c0 .468.391.734.86.547C13.781 14.359 16 11.53 16 8.03 16 3.61 12.406 0 7.984 0 3.563 0 0 3.61 0 8.031a7.88 7.88 0 0 0 5.172 7.422c.422.156.828-.125.828-.547v-1.25c-.219.094-.5.156-.75.156-1.031 0-1.64-.562-2.078-1.609-.172-.422-.36-.672-.719-.719-.187-.015-.25-.093-.25-.187 0-.188.313-.328.625-.328.453 0 .844.281 1.25.86.313.452.64.655 1.031.655s.641-.14 1-.5c.266-.265.47-.5.657-.656',
+ },
+ depot_ci: {
+ viewBox: '0 0 512 512',
+ path: 'M512 438.857H365.714C347.94 438.858 332.142 447.317 322.109 460.422C322.085 460.483 322.048 460.532 321.999 460.581C321.828 460.8 321.657 461.02 321.499 461.239L321.438 461.275C301.763 487.204 272.457 505.429 238.812 510.537C232.497 511.5 226.024 512 219.429 512H0V438.857H182.857C189.452 438.857 195.926 438.358 202.24 437.395C235.886 432.287 265.192 414.062 284.867 388.133L284.928 388.096C285.086 387.876 285.257 387.657 285.428 387.438C285.476 387.389 285.513 387.34 285.537 387.279C295.57 374.175 311.369 365.714 329.143 365.714H512V438.857ZM170.667 292.571C197.742 292.571 221.379 307.285 234.021 329.143C221.379 351 197.742 365.714 170.667 365.714H0V292.571H170.667ZM219.429 146.286C226.024 146.286 232.497 146.786 238.812 147.749C272.457 152.857 301.763 171.082 321.438 197.011L321.499 197.047C321.657 197.266 321.828 197.486 321.999 197.705C322.048 197.754 322.085 197.802 322.109 197.863C332.142 210.968 347.94 219.429 365.714 219.429H512V292.571H329.143C311.369 292.571 295.57 284.112 285.537 271.007C285.513 270.946 285.477 270.896 285.428 270.848C285.257 270.628 285.086 270.409 284.928 270.189L284.867 270.153C265.192 244.224 235.886 225.999 202.24 220.892C195.926 219.929 189.452 219.429 182.857 219.429H0V146.286H219.429ZM292.571 0C299.166 0 305.639 0.499861 311.954 1.46289C345.6 6.57069 374.906 24.7955 394.581 50.7246L394.643 50.7607C394.801 50.9801 394.972 51.1995 395.143 51.4189C395.191 51.4677 395.228 51.5172 395.252 51.5781C405.285 64.6828 421.084 73.1426 438.857 73.1426H512V146.286H402.286C384.512 146.286 368.713 137.825 358.681 124.721C358.656 124.66 358.619 124.611 358.57 124.562C358.4 124.343 358.23 124.124 358.071 123.904L358.01 123.867C338.334 97.9382 309.028 79.7133 275.383 74.6055C269.068 73.6424 262.595 73.1426 256 73.1426H0V0H292.571Z',
+ },
+}
+
+/** The logo of the CI provider that ran a workflow. It names the provider, not the runner hardware. */
+export function CIExplorerProviderMark({ engine }: { engine: CIEngine | undefined }): JSX.Element | null {
+ if (!engine) {
+ return null
+ }
+ const mark = MARKS[engine]
+ return (
+ <svg className="CIExplorer__provider" viewBox={mark.viewBox} role="img" aria-label={providerName(engine)}>
+ <title>{providerName(engine)}</title>
+ <path d={mark.path} fill="currentColor" />
+ </svg>
+ )
+}
diff --git a/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerSteps.tsx b/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerSteps.tsx
new file mode 100644
index 000000000000..5e53fcbd2c02
--- /dev/null
+++ b/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerSteps.tsx
@@ -0,0 +1,89 @@
+import { useActions, useValues } from 'kea'
+import type { CSSProperties } from 'react'
+
+import { Link } from '@posthog/lemon-ui'
+
+import { cn } from 'lib/utils/css-classes'
+import { humanFriendlyDuration } from 'lib/utils/durations'
+
+import type { WorkflowJobApi } from '../../generated/api.schemas'
+import { statusLabel } from '../../lib/ciExplorerDetails'
+import { shownSteps, statusOf } from '../../lib/ciExplorerGraph'
+import { githubJobUrl } from '../../lib/github'
+import { ciExplorerContextLogic } from '../../scenes/ciExplorerContextLogic'
+import { ciExplorerLogic } from '../../scenes/ciExplorerLogic'
+import { CIExplorerChips } from './CIExplorerChips'
+
+/**
+ * The steps of a focused job, each with a bar for its share of the slowest step. A row opens the step on GitHub.
+ * While the Context tab is open, resting on a row or moving the keyboard focus to it compares that step.
+ */
+export function CIExplorerSteps({ job }: { job: WorkflowJobApi }): JSX.Element {
+ const { repoOwner, repoName, focusedJobInsights, focusedBadgedSteps } = useValues(ciExplorerLogic)
+ const { active: contextActive, stepNumber: contextStep } = useValues(ciExplorerContextLogic)
+ const { selectStep, hoverStep } = useActions(ciExplorerContextLogic)
+ const steps = shownSteps(job, focusedBadgedSteps)
+ const badgesOf = new Map((focusedJobInsights?.steps ?? []).map((step) => [step.number, step.badges]))
+ const longest = Math.max(1, ...steps.map((step) => step.duration_seconds ?? 0))
+ const onGitHub = job.ci_engine !== 'depot_ci'
+
+ return (
+ <ol className="CIExplorer__steps">
+ {steps.map((step) => {
+ const running = step.conclusion === null && step.status !== 'completed'
+ const status = running ? 'running' : statusOf(step.conclusion)
+ const row = (
+ <>
+ <span className="CIExplorer__stepIndex">{step.number}</span>
+ <span className="CIExplorer__stepLabel">
+ <span className="CIExplorer__stepName" title={step.name}>
+ {step.name}
+ </span>
+ <CIExplorerChips badges={badgesOf.get(step.number) ?? []} />
+ </span>
+ <span className="CIExplorer__duration">
+ {step.duration_seconds === null
+ ? ''
+ : humanFriendlyDuration(step.duration_seconds, { maxUnits: 2 })}
+ </span>
+ </>
+ )
+ const className = cn(
+ 'CIExplorer__step',
+ status === 'failure' && 'CIExplorer__step--failure',
+ contextActive && contextStep === step.number && 'CIExplorer__step--compared'
+ )
+ const style = { '--w': Math.max(0.004, (step.duration_seconds ?? 0) / longest) } as CSSProperties
+ const compare = contextActive
+ ? {
+ onMouseEnter: () => hoverStep(step.number),
+ onMouseLeave: () => hoverStep(null),
+ onFocus: () => selectStep(step.number),
+ }
+ : {}
+ return (
+ // eslint-disable-next-line react/forbid-dom-props
+ <li key={step.number} style={style}>
+ {onGitHub ? (
+ <Link
+ className={className}
+ to={githubJobUrl(repoOwner, repoName, job.run_id, job.id, step.number)}
+ target="_blank"
+ title="Open this step on GitHub in a new tab"
+ aria-label={`${step.name}, ${statusLabel(step.conclusion, step.status)}`}
+ data-attr="ci-explorer-step"
+ {...compare}
+ >
+ {row}
+ </Link>
+ ) : (
+ <div className={className} {...compare}>
+ {row}
+ </div>
+ )}
+ </li>
+ )
+ })}
+ </ol>
+ )
+}
diff --git a/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerTile.tsx b/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerTile.tsx
new file mode 100644
index 000000000000..dc962cfc9294
--- /dev/null
+++ b/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerTile.tsx
@@ -0,0 +1,110 @@
+import { useActions, useValues } from 'kea'
+import type { CSSProperties } from 'react'
+
+import { cn } from 'lib/utils/css-classes'
+import { humanFriendlyDuration } from 'lib/utils/durations'
+
+import { statusLabel } from '../../lib/ciExplorerDetails'
+import { CIExplorerLayout, CIExplorerWorkflow, TILE_WIDTH } from '../../lib/ciExplorerGraph'
+import { ciExplorerLogic } from '../../scenes/ciExplorerLogic'
+import { CIExplorerProviderMark } from './CIExplorerProviderMark'
+import { CIExplorerUnit } from './CIExplorerUnit'
+
+const TILE_PADDING = 17
+const GRAPH_TOP = 89
+// The room a tile has for its graph. A graph never shows larger than the cap, so a small workflow keeps its scale.
+const GRAPH_WIDTH = TILE_WIDTH - 34
+const GRAPH_HEIGHT = 28
+const GRAPH_MAX_SCALE = 0.45
+
+/** A workflow run: a name, a duration bar, and its job graph drawn small enough to fit inside. */
+export function CIExplorerTile({
+ workflow,
+ layout,
+ x,
+ y,
+ graphReachable,
+}: {
+ workflow: CIExplorerWorkflow
+ layout: CIExplorerLayout | undefined
+ x: number
+ y: number
+ /** False while the graph is too small to read, which keeps its nodes out of the tab order. */
+ graphReachable: boolean
+}): JSX.Element {
+ const { setFocus } = useActions(ciExplorerLogic)
+ const { focusedNodeId } = useValues(ciExplorerLogic)
+ const { run, status } = workflow
+ const scale = layout
+ ? Math.min(GRAPH_MAX_SCALE, GRAPH_WIDTH / layout.width, GRAPH_HEIGHT / layout.height)
+ : GRAPH_MAX_SCALE
+
+ return (
+ <section
+ className={cn('CIExplorer__card', status === 'failure' && 'CIExplorer__card--failure')}
+ data-node-id={workflow.id}
+ data-graph-scale={scale}
+ // eslint-disable-next-line react/forbid-dom-props
+ style={{ left: x, top: y, '--s': scale } as CSSProperties}
+ >
+ <button
+ type="button"
+ className="CIExplorer__cardButton"
+ aria-label={`${run.workflow}, ${statusLabel(run.conclusion)}`}
+ aria-pressed={focusedNodeId === workflow.id}
+ // Zoomed in, the jobs take the tab order and the tile around them leaves it.
+ tabIndex={graphReachable ? -1 : 0}
+ onClick={() => setFocus(workflow.id)}
+ data-attr="ci-explorer-workflow"
+ >
+ <span className="CIExplorer__cardHeader">
+ <i className={`CIExplorer__dot CIExplorer__dot--${status}`} />
+ <CIExplorerProviderMark engine={run.ciEngine} />
+ <b>{run.workflow}</b>
+ <span className="CIExplorer__duration" title="Elapsed, from the first job start to the last finish">
+ {run.durationSeconds === null
+ ? 'Running'
+ : humanFriendlyDuration(run.durationSeconds, { maxUnits: 2 })}
+ </span>
+ </span>
+ <span className="CIExplorer__cardBar">
+ {/* eslint-disable-next-line react/forbid-dom-props */}
+ <i style={{ width: `${Math.max(1, workflow.durationShare * 100)}%` }} />
+ </span>
+ </button>
+ {layout && workflow.items && (
+ <div
+ className="CIExplorer__graph"
+ data-graph
+ // React 18 types lack the attribute.
+ {...(graphReachable ? {} : { inert: '' })}
+ // eslint-disable-next-line react/forbid-dom-props
+ style={{
+ width: layout.width,
+ height: layout.height,
+ left: TILE_PADDING + (GRAPH_WIDTH - layout.width * scale) / 2,
+ top: GRAPH_TOP + (GRAPH_HEIGHT - layout.height * scale) / 2,
+ transform: `scale(${scale})`,
+ }}
+ >
+ <svg aria-hidden="true">
+ {layout.wires.map((d, index) => (
+ <path key={index} d={d} />
+ ))}
+ {layout.ends.map((end, index) => (
+ <circle key={index} cx={end.x} cy={end.y} r={3} />
+ ))}
+ </svg>
+ {workflow.items.map((item) => (
+ <CIExplorerUnit
+ key={item.id}
+ item={item}
+ x={layout.at[item.id]?.x ?? 0}
+ y={layout.at[item.id]?.y ?? 0}
+ />
+ ))}
+ </div>
+ )}
+ </section>
+ )
+}
diff --git a/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerUnit.tsx b/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerUnit.tsx
new file mode 100644
index 000000000000..116cbd6d8e95
--- /dev/null
+++ b/products/engineering_analytics/frontend/components/ciExplorer/CIExplorerUnit.tsx
@@ -0,0 +1,127 @@
+import { useActions, useValues } from 'kea'
+import type { CSSProperties, MouseEvent } from 'react'
+
+import { cn } from 'lib/utils/css-classes'
+import { humanFriendlyDuration } from 'lib/utils/durations'
+
+import { statusLabel } from '../../lib/ciExplorerDetails'
+import { CIExplorerItem, CIStatus, INNER_SCALE, NODE_WIDTH, itemSize, shownSteps } from '../../lib/ciExplorerGraph'
+import { ciExplorerLogic } from '../../scenes/ciExplorerLogic'
+import { clickedNodeId } from './ciExplorerFocus'
+import { CIExplorerSteps } from './CIExplorerSteps'
+
+// A matrix has one status for many jobs, so its neutral status covers cancelled and skipped shards alike.
+const ITEM_STATUS: Record<CIStatus, string> = {
+ success: 'Passed',
+ failure: 'Failed',
+ running: 'Running',
+ neutral: 'No verdict',
+}
+
+function duration(seconds: number | null): string {
+ return seconds === null ? '' : humanFriendlyDuration(seconds, { maxUnits: 2 })
+}
+
+/** One node of a workflow's graph: a job, or a matrix job with its shards inside it. A focused job lists its steps. */
+export function CIExplorerUnit({ item, x, y }: { item: CIExplorerItem; x: number; y: number }): JSX.Element {
+ const { focusedNodeId, focusedBadgedSteps } = useValues(ciExplorerLogic)
+ const { setFocus } = useActions(ciExplorerLogic)
+ const { titleHeight, gridHeight, stepsHeight } = itemSize(item, focusedNodeId, focusedBadgedSteps)
+ const focus = (event: MouseEvent<HTMLElement>): void => setFocus(clickedNodeId(event.currentTarget))
+ const focused = focusedNodeId === item.id
+
+ return (
+ <div
+ className={cn(
+ 'CIExplorer__unit',
+ `CIExplorer__unit--${item.kind}`,
+ item.status === 'failure' && 'CIExplorer__unit--failure',
+ focused && 'CIExplorer__unit--focus'
+ )}
+ data-node-id={item.id}
+ // eslint-disable-next-line react/forbid-dom-props
+ style={{ left: x, top: y, width: NODE_WIDTH }}
+ >
+ {item.shards.length > 0 && <i className="CIExplorer__stack" aria-hidden="true" />}
+ <button
+ type="button"
+ className="CIExplorer__job"
+ aria-label={`${item.name}, ${ITEM_STATUS[item.status]}`}
+ aria-pressed={focused}
+ onClick={focus}
+ data-attr="ci-explorer-job"
+ >
+ <span
+ className="CIExplorer__jobTitle"
+ // eslint-disable-next-line react/forbid-dom-props
+ style={{ '--th': `${titleHeight}px` } as CSSProperties}
+ >
+ <i className={`CIExplorer__dot CIExplorer__dot--${item.status}`} />
+ <span className="CIExplorer__jobName">
+ {item.name}
+ {item.shards.length > 0 && ` ×${item.shards.length}`}
+ </span>
+ <span className="CIExplorer__duration">{duration(item.durationSeconds)}</span>
+ </span>
+ <span className="CIExplorer__meter">
+ {/* eslint-disable-next-line react/forbid-dom-props */}
+ <i style={{ width: `${Math.max(2, item.durationShare * 100)}%` }} />
+ </span>
+ </button>
+ {item.job &&
+ stepsHeight > 0 && (
+ // eslint-disable-next-line react/forbid-dom-props
+ <div className="CIExplorer__cells CIExplorer__cells--steps" style={{ height: stepsHeight }}>
+ {/* eslint-disable-next-line react/forbid-dom-props */}
+ <div className="CIExplorer__scaled" style={{ transform: `scale(${INNER_SCALE})` }}>
+ <CIExplorerSteps job={item.job} />
+ </div>
+ </div>
+ )}
+ {item.shards.length > 0 && (
+ // eslint-disable-next-line react/forbid-dom-props
+ <div className="CIExplorer__cells" style={{ height: gridHeight }}>
+ {/* eslint-disable-next-line react/forbid-dom-props */}
+ <div className="CIExplorer__cellGrid" style={{ transform: `scale(${INNER_SCALE})` }}>
+ {item.shards.map((shard) => {
+ const shardFocused = focusedNodeId === shard.id
+ return (
+ <div
+ key={shard.id}
+ className={cn(
+ 'CIExplorer__cell',
+ shard.status === 'failure' && 'CIExplorer__cell--failure',
+ shardFocused && 'CIExplorer__cell--focus'
+ )}
+ data-node-id={shard.id}
+ >
+ <button
+ type="button"
+ className="CIExplorer__cellHead"
+ aria-label={`${shard.job.name}, ${statusLabel(shard.job.conclusion, shard.job.status)}`}
+ aria-pressed={shardFocused}
+ onClick={focus}
+ data-attr="ci-explorer-shard"
+ // eslint-disable-next-line react/forbid-dom-props
+ style={{ '--w': shard.durationShare } as CSSProperties}
+ >
+ <i className={`CIExplorer__dot CIExplorer__dot--${shard.status}`} />
+ <span className="CIExplorer__cellName">{shard.label}</span>
+ <span className="CIExplorer__duration">
+ {duration(shard.job.duration_seconds)}
+ </span>
+ </button>
+ {shardFocused && shownSteps(shard.job, focusedBadgedSteps).length > 0 && (
+ <div className="CIExplorer__cellSteps">
+ <CIExplorerSteps job={shard.job} />
+ </div>
+ )}
+ </div>
+ )
+ })}
+ </div>
+ </div>
+ )}
+ </div>
+ )
+}
diff --git a/products/engineering_analytics/frontend/components/ciExplorer/ciExplorerFocus.ts b/products/engineering_analytics/frontend/components/ciExplorer/ciExplorerFocus.ts
new file mode 100644
index 000000000000..a79b86b750b6
--- /dev/null
+++ b/products/engineering_analytics/frontend/components/ciExplorer/ciExplorerFocus.ts
@@ -0,0 +1,17 @@
+const MIN_CLICK_HEIGHT = 24
+
+/**
+ * The node a click on `element` means. A node too small to read is not what the person aimed at,
+ * so the click goes to the node around it.
+ */
+export function clickedNodeId(element: HTMLElement): string | null {
+ let target = element.closest<HTMLElement>('[data-node-id]')
+ while (target && target.getBoundingClientRect().height < MIN_CLICK_HEIGHT) {
+ const outer = target.parentElement?.closest<HTMLElement>('[data-node-id]')
+ if (!outer) {
+ break
+ }
+ target = outer
+ }
+ return target?.dataset.nodeId ?? null
+}