~james/core

core/web/src/lib/components/repo/CommitRow.svelte -rw-r--r-- 6.2 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<script lang="ts">
	import { resolve } from "$app/paths";
	import Copy from "$icon/copy";
	import FolderCode from "$icon/folder-code";
	import CommitAuthor from "#lib/components/repo/CommitAuthor.svelte";
	import CommitBodyToggle from "#lib/components/repo/CommitBodyToggle.svelte";
	import CommitShaButton from "#lib/components/repo/CommitShaButton.svelte";
	import { verifiedSignature } from "#lib/components/repo/commitSignature.ts";
	import Button, { type ButtonVariants } from "#lib/components/ui/Button.svelte";
	import DropdownItem from "#lib/components/ui/DropdownItem.svelte";
	import MoreMenu from "#lib/components/ui/MoreMenu.svelte";
	import Pending from "#lib/components/ui/Pending.svelte";
	import Tag from "#lib/components/ui/Tag.svelte";
	import TimeAgo from "#lib/components/ui/TimeAgo.svelte";
	import type { CommitStatuses } from "#lib/api/commitStatuses.ts";
	import PipelineWorkflows from "#lib/components/repo/pipelines/PipelineWorkflows.svelte";
	import type { CommitSummary } from "#lib/components/repo/types.ts";
	import { cn, tv } from "tailwind-variants";

	const row = tv({
		base: "relative grid grid-cols-[minmax(0,max-content)_max-content_max-content_1fr] items-center gap-1 p-4 hover:bg-background-subtle max-md:text-foreground-muted md:col-span-full md:grid-cols-subgrid md:grid-rows-[minmax(3rem,auto)] md:gap-x-[normal] md:gap-y-0 md:py-0"
	});

	interface Props {
		ownerHandle: string;
		repoName: string;
		commit: CommitSummary;
		changeIds?: string[];
		tagsByCommit?: Record<string, string[]> | Promise<Record<string, string[]>>;
		pipelineStatuses?: Promise<CommitStatuses>;
		hasCi?: boolean;
		class?: string;
	}

	let {
		ownerHandle,
		repoName,
		commit,
		changeIds,
		tagsByCommit,
		pipelineStatuses,
		hasCi = false,
		class: className
	}: Props = $props();

	const base = $derived(`/${ownerHandle}/${repoName}`);
	const commitHref = $derived(resolve(`${base}/commit/${commit.hash}` as "/"));
	const treeHref = $derived(resolve(`${base}/tree/${commit.hash}` as "/"));

	let expanded = $state(false);
	const hasBody = $derived(commit.body.trim() !== "");
	const lead = $derived(commit.subject.slice(0, commit.subject.lastIndexOf(" ") + 1));
	const last = $derived(commit.subject.slice(lead.length));
</script>

{#snippet author(extra = "")}
	<span class="relative z-1 flex min-h-7 min-w-0 items-center gap-xs {extra}">
		<CommitAuthor
			name={commit.authorName}
			email={commit.authorEmail}
			did={commit.authorDid}
			handle={commit.authorHandle}
		/>
	</span>
{/snippet}

{#snippet actions()}
	<span class="flex items-center gap-xs">
		<div class="flex flex-row gap-none">
			<Button
				variant="ghost"
				size="small"
				href={treeHref}
				title="Browse repository at this commit"
				aria-label="Browse repository at this commit"
				icon={FolderCode}
				class="fill-foreground-muted stroke-foreground-muted text-foreground-muted"
			/>
		</div>
	</span>
{/snippet}

{#snippet subject()}
	<span class="min-w-0 space-x-xs md:flex md:items-center md:gap-xs md:space-x-0">
		{#if hasBody}
			<a
				href={commitHref}
				class="wrap-break-word text-foreground-default no-underline after:absolute after:inset-0 hover:no-underline max-md:me-0 md:truncate"
				title={commit.subject}>{lead}<span class="max-md:sr-only">{last}</span></a
			><span class="whitespace-nowrap"
				><span class="text-foreground-default md:hidden" aria-hidden="true">{last}</span>
				<CommitBodyToggle
					{expanded}
					onclick={() => (expanded = !expanded)}
					class="relative z-1 ml-xs align-middle md:ml-0"
				/></span
			>
		{:else}
			<a
				href={commitHref}
				class="wrap-break-word text-foreground-default no-underline after:absolute after:inset-0 hover:no-underline md:truncate"
				title={commit.subject}
			>
				{commit.subject}
			</a>
		{/if}
		{#if tagsByCommit}
			<Pending>
				{#each (await tagsByCommit)[commit.hash] ?? [] as name (name)}
					<Tag
						color="inset"
						class="max-w-40 shrink-0 typography-monospace-regular font-normal"
						truncate
						title={name}>{name}</Tag
					>
				{/each}
			</Pending>
		{/if}
		{@render pipeline("min-h-0 inline-flex align-middle md:hidden", "small")}
	</span>
{/snippet}

{#snippet pipeline(extra = "", size: ButtonVariants["size"] = "regular")}
	{#if pipelineStatuses}
		<span class={cn("relative z-1 flex min-h-9 items-center", extra)}>
			<Pending>
				{@const status = (await pipelineStatuses)[commit.hash]}
				{#if status}
					<PipelineWorkflows {ownerHandle} {repoName} pipeline={status} {size} />
				{/if}
			</Pending>
		</span>
	{/if}
{/snippet}

{#snippet mobileMenu()}
	<MoreMenu label="More actions for commit {commit.shortHash}" size="small">
		<DropdownItem icon={Copy} onclick={() => navigator.clipboard.writeText(commit.hash)}>
			Copy SHA
		</DropdownItem>
		<DropdownItem icon={FolderCode} href={treeHref}>Browse repository</DropdownItem>
	</MoreMenu>
{/snippet}

{#snippet when()}
	<TimeAgo
		value={commit.when}
		class="relative z-1 order-5 shrink-0 whitespace-nowrap text-foreground-muted md:order-0"
	/>
{/snippet}

<!--
	only the columns come from CommitRows; the rows are the row's own, so the cells
	keep a comfortable height and an expanded body drops underneath them.
-->
<div class={row({ class: className })}>
	{@render author("order-3 md:order-none md:col-start-1 md:row-start-1")}
	<span
		class="relative z-1 hidden items-center justify-between gap-xs md:col-start-2 md:row-start-1 md:flex"
	>
		{@render actions()}
		<CommitShaButton
			hash={commit.hash}
			shortHash={commit.shortHash}
			changeId={commit.changeId}
			{changeIds}
			signature={verifiedSignature(commit)}
		/>
	</span>
	<div class="order-1 col-span-full flex min-w-0 items-start md:order-0 md:contents">
		{@render subject()}
		<span class="relative z-1 ml-auto shrink-0 md:hidden">{@render mobileMenu()}</span>
	</div>
	<span class="order-4 shrink-0 md:hidden">committed</span>
	<span
		class="contents items-center gap-xs md:col-start-4 md:row-start-1 md:flex md:justify-self-end"
	>
		{@render pipeline(hasCi ? "max-md:hidden min-w-24 justify-end" : "max-md:hidden")}
		{@render when()}
	</span>
	{#if hasBody && expanded}
		<p
			class="relative z-1 order-2 col-span-full pb-xs typography-paragraph-small wrap-anywhere whitespace-pre-wrap text-foreground-muted md:order-0 md:col-span-1 md:col-start-3 md:row-start-2"
		>
			{commit.body}
		</p>
	{/if}
</div>