desktop: Extract a shared card for issue, patch and release teasers

The release card had drifted from issues and patches in padding and
icon spacing. With one card component they can't drift again, and the
cards can now be opened with Enter or Space.
This commit is contained in:
Rūdolfs Ošiņš
2026-11-23 16:24:37 +01:00
parent 48e1f2f56c
commit 8a1f0fdc9a
6 changed files with 273 additions and 311 deletions
+113
View File
@@ -0,0 +1,113 @@
<script lang="ts">
import type { Snippet } from "svelte";
interface Props {
badges?: Snippet;
chipBackground?: string;
chipColor?: string;
contextActive?: boolean;
focussed?: boolean;
heading: Snippet;
icon: Snippet;
meta: Snippet;
onclick: () => void;
oncontextmenu?: (event: MouseEvent) => void;
}
const {
badges,
chipBackground,
chipColor,
contextActive,
focussed,
heading,
icon,
meta,
onclick,
oncontextmenu,
}: Props = $props();
function onkeydown(event: KeyboardEvent) {
if (event.target !== event.currentTarget) return;
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
onclick();
}
}
</script>
<style>
.cob-teaser {
display: flex;
align-items: flex-start;
gap: 0.25rem;
min-height: 5rem;
background-color: var(--color-surface-canvas);
padding: 1.25rem;
cursor: pointer;
font: var(--txt-body-l-regular);
word-break: break-word;
width: 100%;
}
.cob-teaser.focussed {
padding: 1rem;
}
.cob-teaser:hover,
.cob-teaser.context-active {
background-color: var(--color-surface-subtle);
}
.chip {
padding: 0;
margin-right: 1rem;
}
.focus-ring {
display: flex;
border: 1px solid var(--color-border-brand);
border-radius: var(--border-radius-sm);
background-color: var(--color-surface-canvas);
}
</style>
{#snippet teaser()}
<div
tabindex="0"
role="button"
class="cob-teaser"
class:focussed
class:context-active={contextActive}
{oncontextmenu}
{onclick}
{onkeydown}>
<div class="global-flex" style:align-items="flex-start">
<div
class="global-chip chip"
style:color={chipColor}
style:background-color={chipBackground}>
{@render icon()}
</div>
<div
class="global-flex"
style:flex-direction="column"
style:align-items="flex-start">
{@render heading()}
<div class="global-flex txt-body-m-regular" style:flex-wrap="wrap">
{@render meta()}
</div>
</div>
</div>
{#if badges}
<div class="global-flex" style:margin-left="auto">
{@render badges()}
</div>
{/if}
</div>
{/snippet}
{#if focussed}
<div class="focus-ring">
{@render teaser()}
</div>
{:else}
{@render teaser()}
{/if}
+33
View File
@@ -0,0 +1,33 @@
<script lang="ts">
import type { ComponentProps } from "svelte";
import Icon from "@app/components/Icon.svelte";
interface Props {
count: number;
icon: ComponentProps<typeof Icon>["name"];
title?: string;
}
const { count, icon, title }: Props = $props();
</script>
<style>
.count-badge {
display: flex;
align-items: center;
gap: 0.25rem;
font: var(--txt-body-m-regular);
white-space: nowrap;
border: 1px solid var(--color-border-subtle);
border-radius: var(--border-radius-sm);
height: 1.5rem;
padding: 0 0.5rem;
color: var(--color-text-tertiary);
}
</style>
<div class="count-badge" {title}>
<Icon name={icon} />
{count}
</div>
+38 -108
View File
@@ -11,6 +11,8 @@
issueStatusColor,
} from "@app/lib/utils";
import CobTeaser from "@app/components/CobTeaser.svelte";
import CountBadge from "@app/components/CountBadge.svelte";
import Icon from "@app/components/Icon.svelte";
import Id from "@app/components/Id.svelte";
import InlineTitle from "@app/components/InlineTitle.svelte";
@@ -30,111 +32,39 @@
$props();
</script>
<style>
.issue-teaser {
display: flex;
align-items: center;
gap: 0.25rem;
min-height: 5rem;
background-color: var(--color-surface-canvas);
padding: 1rem;
cursor: pointer;
font: var(--txt-body-l-regular);
word-break: break-word;
width: 100%;
}
.issue-teaser:hover,
.issue-teaser.context-active {
background-color: var(--color-surface-subtle);
}
.status {
padding: 0;
margin-right: 1rem;
}
.issue-teaser:first-of-type {
border-radius: var(--border-radius-sm) var(--border-radius-sm) 0 0;
}
.issue-teaser:last-of-type {
border-radius: 0 0 var(--border-radius-sm) var(--border-radius-sm);
}
.issue-teaser:only-of-type {
border-radius: var(--border-radius-sm);
}
</style>
{#snippet issueSnippet()}
<!-- svelte-ignore a11y_click_events_have_key_events -->
<div
tabindex="0"
role="button"
class="issue-teaser"
class:context-active={contextActive}
{oncontextmenu}
style:align-items="flex-start"
style:clip-path={focussed ? "none" : undefined}
style:padding={focussed ? "1rem" : "20px"}
onclick={() => {
void push({ resource: "repo.issue", rid, issue: issue.id, status });
}}>
<div class="global-flex" style:align-items="flex-start">
<div
class="global-chip status"
style:color={issueStatusColor[issue.state.status]}
style:background-color={issueStatusBackgroundColor[issue.state.status]}>
{#if issue.state.status === "open"}
<Icon name="issue" />
{:else}
<Icon name="issue-closed" />
{/if}
</div>
<div
class="global-flex"
style:flex-direction="column"
style:align-items="flex-start">
<InlineTitle content={issue.title} />
<div class="global-flex txt-body-m-regular" style:flex-wrap="wrap">
<NodeId {...authorForNodeId(issue.author)} />
opened
<Id id={issue.id} clipboard={issue.id} label="issue ID" />
<span title={absoluteTimestamp(issue.timestamp)}>
{formatTimestamp(issue.timestamp)}
</span>
</div>
</div>
</div>
<div class="global-flex" style:margin-left="auto">
{#each issue.labels as label}
<Label {label} />
{/each}
{#if issue.commentCount > 0}
<div
class="txt-body-m-regular global-flex"
style:gap="0.25rem"
style:border="1px solid var(--color-border-subtle)"
style:border-radius="var(--border-radius-sm)"
style:height="1.5rem"
style:padding="0 0.5rem"
style:color="var(--color-text-tertiary)">
<Icon name="comment" />
{issue.commentCount}
</div>
{/if}
</div>
</div>
{/snippet}
{#if focussed}
<div
style:border="1px solid var(--color-border-brand)"
style:border-radius="var(--border-radius-sm)"
style:display="flex"
style:gap="0.5rem"
style:align-items="center"
style:background-color="var(--color-surface-canvas)">
{@render issueSnippet()}
</div>
{:else}
{@render issueSnippet()}
{/if}
<CobTeaser
{contextActive}
{focussed}
{oncontextmenu}
chipColor={issueStatusColor[issue.state.status]}
chipBackground={issueStatusBackgroundColor[issue.state.status]}
onclick={() => {
void push({ resource: "repo.issue", rid, issue: issue.id, status });
}}>
{#snippet icon()}
{#if issue.state.status === "open"}
<Icon name="issue" />
{:else}
<Icon name="issue-closed" />
{/if}
{/snippet}
{#snippet heading()}
<InlineTitle content={issue.title} />
{/snippet}
{#snippet meta()}
<NodeId {...authorForNodeId(issue.author)} />
opened
<Id id={issue.id} clipboard={issue.id} label="issue ID" />
<span title={absoluteTimestamp(issue.timestamp)}>
{formatTimestamp(issue.timestamp)}
</span>
{/snippet}
{#snippet badges()}
{#each issue.labels as label}
<Label {label} />
{/each}
{#if issue.commentCount > 0}
<CountBadge icon="comment" count={issue.commentCount} title="Comments" />
{/if}
{/snippet}
</CobTeaser>
+60 -138
View File
@@ -14,6 +14,8 @@
patchStatusColor,
} from "@app/lib/utils";
import CobTeaser from "@app/components/CobTeaser.svelte";
import CountBadge from "@app/components/CountBadge.svelte";
import DiffStatBadge from "@app/components/DiffStatBadge.svelte";
import Icon from "@app/components/Icon.svelte";
import Id from "@app/components/Id.svelte";
@@ -59,147 +61,67 @@
});
</script>
<style>
.patch-teaser {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.25rem;
min-height: 5rem;
background-color: var(--color-surface-canvas);
padding: 1rem;
cursor: pointer;
font: var(--txt-body-l-regular);
word-break: break-word;
width: 100%;
}
.patch-teaser:hover,
.patch-teaser.context-active {
background-color: var(--color-surface-subtle);
}
.status {
padding: 0;
margin-right: 1rem;
}
.patch-teaser:first-of-type {
border-radius: var(--border-radius-sm) var(--border-radius-sm) 0 0;
}
.patch-teaser:last-of-type {
border-radius: 0 0 var(--border-radius-sm) var(--border-radius-sm);
}
.patch-teaser:only-of-type {
border-radius: var(--border-radius-sm);
}
</style>
{#snippet patchSnippet()}
<!-- svelte-ignore a11y_click_events_have_key_events -->
<div
tabindex="0"
role="button"
class="patch-teaser"
class:context-active={contextActive}
{oncontextmenu}
style:align-items="flex-start"
style:clip-path={focussed ? "none" : undefined}
style:padding={focussed ? "1rem" : "1.25rem"}
onclick={() => {
void push({
resource: "repo.patch",
rid,
patch: patch.id,
status,
reviewId: undefined,
});
}}>
<div class="global-flex" style:align-items="flex-start">
<CobTeaser
{contextActive}
{focussed}
{oncontextmenu}
chipColor={patchStatusColor[patch.state.status]}
chipBackground={patchStatusBackgroundColor[patch.state.status]}
onclick={() => {
void push({
resource: "repo.patch",
rid,
patch: patch.id,
status,
reviewId: undefined,
});
}}>
{#snippet icon()}
<Icon
name={patch.state.status === "open"
? "patch"
: `patch-${patch.state.status}`} />
{/snippet}
{#snippet heading()}
<InlineTitle content={patch.title} />
{/snippet}
{#snippet meta()}
<NodeId {...authorForNodeId(patch.author)} />
opened
<Id id={patch.id} clipboard={patch.id} label="patch ID" />
<span title={absoluteTimestamp(patch.timestamp)}>
{formatTimestamp(patch.timestamp)}
</span>
{/snippet}
{#snippet badges()}
{#if hasDraftReview}
<div
class="global-chip status"
style:color={patchStatusColor[patch.state.status]}
style:background-color={patchStatusBackgroundColor[patch.state.status]}>
<Icon
name={patch.state.status === "open"
? "patch"
: `patch-${patch.state.status}`} />
</div>
<div
class="global-flex"
style:flex-direction="column"
style:align-items="flex-start">
<InlineTitle content={patch.title} />
<div class="global-flex txt-body-m-regular" style:flex-wrap="wrap">
<NodeId {...authorForNodeId(patch.author)} />
opened
<Id id={patch.id} clipboard={patch.id} label="patch ID" />
<span title={absoluteTimestamp(patch.timestamp)}>
{formatTimestamp(patch.timestamp)}
</span>
</div>
</div>
</div>
<div class="global-flex" style:margin-left="auto">
{#if hasDraftReview}
<div
class="txt-body-m-regular"
style:white-space="nowrap"
style:border="1px solid var(--color-border-subtle)"
style:border-radius="var(--border-radius-sm)"
style:padding="0.125rem 0.5rem"
style:color="var(--color-text-primary)">
Review in progress
</div>
{/if}
{#await cachedDiffStats(rid, patch.base, patch.head) then stats}
<DiffStatBadge {stats} />
{/await}
{#each patch.labels as label}
<Label {label} />
{/each}
{#if patch.commentCount > 0}
<div
class="txt-body-m-regular global-flex"
style:gap="0.25rem"
style:border="1px solid var(--color-border-subtle)"
style:border-radius="var(--border-radius-sm)"
style:height="1.5rem"
style:padding="0 0.5rem"
style:color="var(--color-text-tertiary)">
<Icon name="comment" />
{patch.commentCount}
</div>
{/if}
<ReviewSummary
reviews={entriesFromReviewers(patch.reviewers)}
revisionCount={patch.revisionIds.length} />
<div
class="txt-body-m-regular global-flex"
style:gap="0.25rem"
class="txt-body-m-regular"
style:white-space="nowrap"
style:border="1px solid var(--color-border-subtle)"
style:border-radius="var(--border-radius-sm)"
style:height="1.5rem"
style:padding="0 0.5rem"
style:color="var(--color-text-tertiary)">
<Icon name="revision" />
{patch.revisionIds.length}
style:padding="0.125rem 0.5rem"
style:color="var(--color-text-primary)">
Review in progress
</div>
</div>
</div>
{/snippet}
{/if}
{#if focussed}
<div
style:border="1px solid var(--color-border-brand)"
style:border-radius="var(--border-radius-sm)"
style:display="flex"
style:gap="0.5rem"
style:align-items="center"
style:background-color="var(--color-surface-canvas)">
{@render patchSnippet()}
</div>
{:else}
{@render patchSnippet()}
{/if}
{#await cachedDiffStats(rid, patch.base, patch.head) then stats}
<DiffStatBadge {stats} />
{/await}
{#each patch.labels as label}
<Label {label} />
{/each}
{#if patch.commentCount > 0}
<CountBadge icon="comment" count={patch.commentCount} title="Comments" />
{/if}
<ReviewSummary
reviews={entriesFromReviewers(patch.reviewers)}
revisionCount={patch.revisionIds.length} />
<CountBadge
icon="revision"
count={patch.revisionIds.length}
title="Revisions" />
{/snippet}
</CobTeaser>
+28 -64
View File
@@ -8,6 +8,8 @@
formatTimestamp,
} from "@app/lib/utils";
import CobTeaser from "@app/components/CobTeaser.svelte";
import CountBadge from "@app/components/CountBadge.svelte";
import DelegateBadge from "@app/components/DelegateBadge.svelte";
import Icon from "@app/components/Icon.svelte";
import Id from "@app/components/Id.svelte";
@@ -22,30 +24,10 @@
const { delegateIds, release, rid }: Props = $props();
const title = $derived(release.title || release.tagName || release.id);
const releaseTitle = $derived(release.title || release.tagName || release.id);
</script>
<style>
.release-teaser {
display: flex;
align-items: flex-start;
gap: 0.25rem;
min-height: 5rem;
background-color: var(--color-surface-canvas);
padding: 1rem;
cursor: pointer;
font: var(--txt-body-l-regular);
word-break: break-word;
width: 100%;
}
.release-teaser:hover {
background-color: var(--color-surface-subtle);
}
.icon {
padding: 0;
margin-right: 1rem;
color: var(--color-text-tertiary);
}
.tag {
font: var(--txt-body-s-regular);
color: var(--color-text-tertiary);
@@ -54,24 +36,10 @@
padding: 0 0.375rem;
white-space: nowrap;
}
.counter {
display: flex;
align-items: center;
gap: 0.25rem;
font: var(--txt-body-m-regular);
border: 1px solid var(--color-border-subtle);
border-radius: var(--border-radius-sm);
height: 1.5rem;
padding: 0 0.5rem;
color: var(--color-text-tertiary);
}
</style>
<!-- svelte-ignore a11y_click_events_have_key_events -->
<div
tabindex="0"
role="button"
class="release-teaser"
<CobTeaser
chipColor="var(--color-text-tertiary)"
onclick={() => {
void push({
resource: "repo.release",
@@ -79,36 +47,32 @@
release: release.id,
});
}}>
<div class="global-chip icon">
{#snippet icon()}
<Icon name="parcel" />
</div>
<div
class="global-flex"
style:flex-direction="column"
style:align-items="flex-start">
{/snippet}
{#snippet heading()}
<div class="global-flex" style:flex-wrap="wrap">
<InlineTitle content={title} />
<InlineTitle content={releaseTitle} />
{#if release.tagName}
<span class="tag">{release.tagName}</span>
{/if}
</div>
<div class="global-flex txt-body-m-regular" style:flex-wrap="wrap">
<NodeId {...authorForNodeId(release.creator)} />
{#if delegateIds.has(release.creator.did)}
<DelegateBadge />
{/if}
created
<Id id={release.id} clipboard={release.id} label="release ID" />
<span title={absoluteTimestamp(release.createdAt)}>
{formatTimestamp(release.createdAt)}
</span>
</div>
</div>
<div class="global-flex" style:margin-left="auto">
<div class="counter" title="Artifacts">
<Icon name="attach" />
{release.artifacts.length}
</div>
</div>
</div>
{/snippet}
{#snippet meta()}
<NodeId {...authorForNodeId(release.creator)} />
{#if delegateIds.has(release.creator.did)}
<DelegateBadge />
{/if}
created
<Id id={release.id} clipboard={release.id} label="release ID" />
<span title={absoluteTimestamp(release.createdAt)}>
{formatTimestamp(release.createdAt)}
</span>
{/snippet}
{#snippet badges()}
<CountBadge
icon="attach"
count={release.artifacts.length}
title="Artifacts" />
{/snippet}
</CobTeaser>
+1 -1
View File
@@ -3,6 +3,6 @@ import { cobRid, expect, test } from "@tests/support/fixtures.js";
test("navigate issues listing", async ({ page }) => {
await page.goto(`/repos/${cobRid}/issues?status=all`);
await page.getByRole("link", { name: "Closed" }).click();
await expect(page.locator(".issue-teaser")).toHaveCount(2);
await expect(page.locator(".cob-teaser")).toHaveCount(2);
await expect(page).toHaveURL(`/repos/${cobRid}/issues?status=closed`);
});