Skip to content

Commit 3a1d31e

Browse files
committed
feat(landing/QueryLanding): select a cached row to inspect its state
1 parent dc97d4c commit 3a1d31e

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/components/landing/QueryLanding.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ function QueryCachePanel() {
188188
const [isLive, setIsLive] = React.useState(false)
189189
// `0` until the first tick, for the same first-render reason as `fetchedAt`.
190190
const [now, setNow] = React.useState(0)
191+
const [selectedId, setSelectedId] = React.useState(
192+
queryHeroInitialRows[0]?.id,
193+
)
191194

192195
const projectsQuery = useQuery({
193196
queryKey: queryHeroKey,
@@ -255,6 +258,11 @@ function QueryCachePanel() {
255258
: projectsQuery.isStale
256259
? 'stale'
257260
: 'fresh'
261+
// The selected row can fall out of the cache once five newer issues arrive,
262+
// so fall back to the top row rather than holding a dangling id.
263+
const selectedRow =
264+
projectsQuery.data.rows.find((row) => row.id === selectedId) ??
265+
projectsQuery.data.rows[0]
258266
const fetchedLabel =
259267
projectsQuery.data.fetchedAt > 0
260268
? `${Math.max(0, Math.round((Math.max(now, projectsQuery.data.fetchedAt) - projectsQuery.data.fetchedAt) / 1000))}s ago`
@@ -320,9 +328,12 @@ function QueryCachePanel() {
320328
</div>
321329

322330
{projectsQuery.data.rows.map((row) => (
323-
<div
331+
<button
324332
key={row.id}
325-
className="block w-full rounded-lg border border-transparent bg-background-subtle p-4 text-left"
333+
type="button"
334+
aria-pressed={row.id === selectedRow?.id}
335+
className="block w-full rounded-lg border border-transparent bg-background-subtle p-4 text-left transition-colors hover:border-text-primary/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--landing-accent-bright)] aria-pressed:border-[color:rgb(var(--landing-glow)/0.42)] aria-pressed:bg-[color:rgb(var(--landing-glow)/0.1)]"
336+
onClick={() => setSelectedId(row.id)}
326337
>
327338
<span className="flex items-start justify-between gap-4">
328339
<span className="min-w-0">
@@ -348,7 +359,7 @@ function QueryCachePanel() {
348359
{row.observers} obs
349360
</span>
350361
</span>
351-
</div>
362+
</button>
352363
))}
353364
</div>
354365

@@ -395,7 +406,7 @@ function QueryCachePanel() {
395406
<div className="mt-7" aria-live="polite">
396407
<p className="text-ds-heading-4">{queryLanding.hero.detailTitle}</p>
397408
<p className="mt-2 truncate font-ds-mono text-ds-mono-xs text-[var(--landing-accent-bright)]">
398-
['issues', '{projectsQuery.data.rows[0]?.id ?? 'router-cache'}']
409+
['issues', '{selectedRow?.id ?? 'router-cache'}']
399410
</p>
400411
<p className="mt-4 text-ds-body-sm text-text-primary/55">
401412
{queryLanding.hero.detailBody}
@@ -409,6 +420,11 @@ function QueryCachePanel() {
409420
label: 'isFetching',
410421
value: String(projectsQuery.isFetching),
411422
},
423+
{
424+
label: 'observers',
425+
value: String(selectedRow?.observers ?? 0),
426+
},
427+
{ label: 'priority', value: `P${selectedRow?.priority ?? 0}` },
412428
{ label: 'staleTime', value: '3,200' },
413429
{ label: 'mutation', value: addIssueMutation.status },
414430
].map((fact) => (

0 commit comments

Comments
 (0)