Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ test('deployment facts: agent, kernels, warnings and the policies covering each
/Unavailable on general: tcp_connect is not a kernel symbol there\./u,
)
const web = frame.locator('[data-entity-id="workload:StatefulSet:checkout:checkout-web"]')
await expect(web.locator('.rp-chip.added.filled')).toContainText('protect-credentials')
await expect(web.locator('.rp-chip.unchanged')).toContainText('egress-audit')
await expect(web.locator('.rp-chip[data-change="added"]')).toContainText('protect-credentials')
await expect(web.locator('.rp-chip:not([data-chip-change])')).toContainText('egress-audit')
await expect.poll(() => facts(renderer)).toContain('1 agent configuration changed')
await renderer.iframe.screenshot({path: test.info().outputPath('deployment.png')})
})
Expand Down
57 changes: 25 additions & 32 deletions packages/renderers/runtime-policy/src/chips.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {codeSpan} from '@githubnext/projections-schemas'
import {Chip as KitChip} from '@githubnext/projections-renderer-kit/react'
import {proseOf, type Chip, type Item} from './model.js'
import {chipPrefix} from './prose.js'
import {emphasisStyle, regionOf, type Frame} from './frame.js'
import {regionOf, type Frame} from './frame.js'
import {Prose} from './breaks.js'

/** How a covering policy acts on a workload, as prose: its strongest effect, and the containers a container selector picks. */
Expand Down Expand Up @@ -55,43 +56,35 @@ export function Chips({
const own = chip.subject.row.status
const change =
frame.side === 'diff' ? chip.change : strength > 0 && (own === 'added' || own === 'removed') ? own : ('unchanged' as const)
const word = change === 'added' ? 'Added' : change === 'removed' ? 'Removed' : undefined
// A chip of an added or removed row arrives or leaves with it: marked by its sign, not a second fill.
const filled = frame.side === 'diff' && change !== 'unchanged' && change !== ownerRegion
const prefix = chipPrefix(chip)
const follow = chip.data?.followChildren === true
return (
<button
<KitChip
key={chip.key}
type="button"
className={`rp-chip pk-part ${change}${filled ? ' filled' : ''}${selected ? ' selected' : ''}`}
{...(change === 'unchanged' ? {} : {'data-change-hue': change})}
data-entity-id={chip.subject.row.id}
{...(filled ? {'data-change': change} : {})}
aria-pressed={selected}
style={emphasisStyle(change === 'unchanged' ? 0 : strength)}
onClick={event => {
event.stopPropagation()
frame.props.onSelect(chip.subject.row.id)
}}
>
{frame.side === 'diff' && change !== 'unchanged' && (
<span className="rp-chip-sign pk-label" aria-hidden="true">
{change === 'added' ? '+' : '−'}
</span>
)}
{word && <span className="sr-only">{word}: </span>}
{prefix && <span className="rp-chip-prefix pk-label">{prefix} </span>}
<span className="rp-chip-label pk-label">
<Prose>{subjectProse(chip)}</Prose>
{follow && <span className="rp-chip-prefix"> and children</span>}
{chip.kind === 'covers' && (
<span className="rp-chip-prefix">
<Prose>{coverage(chip)}</Prose>
</span>
)}
</span>
</button>
className="rp-chip"
id={chip.subject.row.id}
selected={selected}
onSelect={frame.props.onSelect}
change={change}
paint={filled}
sign={frame.side === 'diff'}
emphasis={change === 'unchanged' ? 0 : strength}
font="text"
label={
<>
{prefix && <span className="rp-chip-prefix">{prefix} </span>}
<Prose>{subjectProse(chip)}</Prose>
{follow && <span className="rp-chip-prefix"> and children</span>}
{chip.kind === 'covers' && (
<span className="rp-chip-prefix">
<Prose>{coverage(chip)}</Prose>
</span>
)}
</>
}
/>
)
})}
</span>
Expand Down
60 changes: 6 additions & 54 deletions packages/renderers/runtime-policy/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@
.rp-chip.pk-part:hover {
background-image: linear-gradient(var(--hover), var(--hover));
}
.rp-row.pk-part.selected,
.rp-chip.pk-part.selected {
.rp-row.pk-part.selected {
background-image: linear-gradient(var(--pk-part-tint), var(--pk-part-tint));
}
/* A selected part also carries an accent bar on its leading edge, drawn as an image so a change edge stays. */
Expand All @@ -230,20 +229,13 @@
* Change regions are the kit's (pk-region with data-change): a fill and a
* same-hue edge, both following --emphasis. A changed row, a probe's own
* region and a changed hook lane are regions; rows inside one inherit it.
* The change hue here only colors signs and chip edges.
* The change hue here only colors signs. Chips are the kit's (`Chip`).
*/
:is(.rp-row, .rp-region, .rp-lane)[data-change],
.rp-chip[data-change-hue] {
:is(.rp-row, .rp-region, .rp-lane)[data-change] {
--change: var(--pk-change-ink);
--change-soft: var(--pk-region-fill);
--change-edge: var(--pk-region-edge);
}
/* An unchanged chip is never emphasized; its hue is the neutral it mixes with. */
.rp-chip:not([data-change-hue]) {
--change: var(--muted);
--change-soft: var(--raised);
--change-edge: var(--divider);
}
/* Removed content is struck once, wherever its region was marked. */
:is(.rp-row.departed, .rp-region.departed, .rp-lane.departed) :is(.rp-main, .rp-effect) {
color: var(--muted);
Expand Down Expand Up @@ -374,55 +366,15 @@
font-weight: var(--projections-font-weight-semibold);
}

/* Chips: edged in their change's hue when they arrive or leave on their own. */
/* Chips (the kit's `Chip`): edged in their change's hue when they arrive or leave on their own. */
.rp-chips {
display: flex;
flex-wrap: wrap;
gap: var(--projections-space-1);
min-width: 0;
}
.rp-chip {
appearance: none;
position: relative;
display: inline-flex;
/* Its sign, prefix and label are labels (`pk-label`) in one font: centred, their capitals line up, in a taller chip too. */
align-items: center;
gap: 0.35em;
max-width: 100%;
padding: 0 var(--projections-label-padding-x);
border: var(--projections-border-width) solid var(--divider);
border-radius: var(--projections-radius-sm);
background: var(--raised);
color: var(--text);
font: inherit;
font-size: var(--projections-font-size-xs);
line-height: var(--projections-line-height);
text-align: left;
cursor: pointer;
}
.rp-chip.filled {
border-color: color-mix(in srgb, var(--change-edge) calc(var(--emphasis, 0) * 100%), var(--divider));
background: color-mix(in srgb, var(--change-soft) calc(var(--emphasis, 0) * 100%), var(--raised));
}
.rp-chip-label {
min-width: 0;
}
.rp-chip.removed .rp-chip-label {
color: var(--muted);
text-decoration: line-through;
}
.rp-chip-sign {
flex: none;
font-family: var(--font-mono);
font-weight: var(--projections-font-weight-semibold);
color: color-mix(in srgb, var(--change) calc(var(--emphasis, 0) * 100%), var(--muted));
}
/*
* No nested change colors: a row's sign takes its change only when the row marks it itself, and a chip's when the
* chip is filled; a row inside a changed region, or a chip arriving or leaving with its row, says so by its glyph.
*/
.rp-row:not([data-change]) > .rp-sign,
.rp-chip:not([data-change]) > .rp-chip-sign {
/* No nested change colors: a row's sign takes its change only when the row marks it itself. */
.rp-row:not([data-change]) > .rp-sign {
color: var(--muted);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ test('markup: identifiers are marked, effects are words, and status footers are
assert.doesNotMatch(diff, /[▲⇱⚠]/u, 'status is words, not glyphs')
assert.match(
diff,
/class="rp-chip pk-part removed filled"[^>]*><span class="rp-chip-sign pk-label" aria-hidden="true">−<\/span><span class="sr-only">Removed: <\/span>/u,
/class="pk-chip pk-part rp-chip" data-change="removed" data-chip-change="removed"[^>]*><span class="pk-chip-body"><span class="pk-chip-sign pk-label" aria-hidden="true">−<\/span><span class="sr-only">Removed: <\/span>/u,
)

const quiet = renderToStaticMarkup(
Expand Down
Loading