Skip to content

Commit 4e2311f

Browse files
committed
fix(ui): keep in-app navigation for links inside clickable table rows
Links in clickable rows stopped the click from propagating so the row would not also open, which also kept it from SvelteKit's router, so every such link reloaded the whole app. Rows now ignore clicks on links and controls inside them, as the runs list already did.
1 parent d802783 commit 4e2311f

14 files changed

Lines changed: 58 additions & 61 deletions

File tree

‎ui/src/lib/components/admin/role-cell.svelte‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<ul class="list">
3232
{#each shown as a (a.id)}
3333
<li class:stale={a.stale}>
34-
<a href={to(roleHref(a.role))} onclick={(e) => e.stopPropagation()}>{a.role}</a>
34+
<a href={to(roleHref(a.role))}>{a.role}</a>
3535
<span class="where">{scopeWords(a.scope.locationId, locations)}</span>
3636
<SourceChip assignment={a} />
3737
{#if a.stale}<span class="where">gives nothing</span>{/if}

‎ui/src/lib/paths.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { goto } from '$app/navigation';
12
import { resolve } from '$app/paths';
23

34
/** The path the UI is served under: empty when `sqb server` serves it, `/demo` for the static demo. */
@@ -8,3 +9,16 @@ export const to = (path: string): string => `${base}${path}`;
89

910
/** The app path of an address's pathname, without the path the UI is served under. */
1011
export const appPath = (pathname: string): string => (pathname.startsWith(`${base}/`) ? pathname.slice(base.length) : pathname);
12+
13+
/** The parts of a row that do their own thing when clicked, such as a link to another page. */
14+
const ROW_CONTROL = 'a, button, input, label, [data-control]';
15+
16+
/**
17+
* Opens the page a table row stands for, in a new tab with Ctrl, ⌘ or the middle button. A click on
18+
* a link or control in the row is left to it, so links keep SvelteKit's in-app navigation.
19+
*/
20+
export function openRow(e: MouseEvent, path: string): void {
21+
if ((e.target as Element).closest(ROW_CONTROL)) return;
22+
if (e.metaKey || e.ctrlKey || e.button === 1) window.open(to(path), '_blank', 'noopener');
23+
else void goto(to(path));
24+
}

‎ui/src/routes/admin/people/+page.svelte‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
2-
import { to } from '$lib/paths';
3-
import { goto } from '$app/navigation';
2+
import { openRow, to } from '$lib/paths';
43
import UserIcon from '@lucide/svelte/icons/user';
54
import ShieldQuestionIcon from '@lucide/svelte/icons/shield-question';
65
import TriangleAlertIcon from '@lucide/svelte/icons/triangle-alert';
@@ -73,12 +72,12 @@
7372
<tbody>
7473
{#each people.shown as a (a.name)}
7574
{@const risky = d.riskyOf(a.name)}
76-
<tr class:sb-row-off={a.disabled} class:static={!opensPeople} onclick={() => opensPeople && goto(to(personHref(a)))}>
75+
<tr class:sb-row-off={a.disabled} class:static={!opensPeople} onclick={(e) => opensPeople && openRow(e, personHref(a))}>
7776
<td>
7877
<div class="cell-name">
7978
<UserIcon size={15} strokeWidth={1.75} />
8079
<div class="min-w-0">
81-
{#if opensPeople}<a href={to(personHref(a))} onclick={(e) => e.stopPropagation()}>{a.displayName}</a>{:else}{a.displayName}{/if}
80+
{#if opensPeople}<a href={to(personHref(a))}>{a.displayName}</a>{:else}{a.displayName}{/if}
8281
<div class="cell-desc"><code>{a.name}</code> · {a.source === 'oidc' ? 'SSO' : a.source ? accountSourceLabel[a.source] : 'no password'}</div>
8382
</div>
8483
</div>

‎ui/src/routes/admin/roles/roles-tab.svelte‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
2-
import { to } from '$lib/paths';
3-
import { goto } from '$app/navigation';
2+
import { openRow, to } from '$lib/paths';
43
import LoadRow from '$lib/components/list/load-row.svelte';
54
import RoleSourceBadge from '$lib/components/admin/role-source-badge.svelte';
65
import { roleHref, roleSummary } from '$lib/platform/access';
@@ -23,9 +22,9 @@
2322
</thead>
2423
<tbody>
2524
{#each rs.roles.data ?? [] as r (r.name)}
26-
<tr onclick={() => goto(to(roleHref(r.name)))}>
25+
<tr onclick={(e) => openRow(e, roleHref(r.name))}>
2726
<td>
28-
<a class="link" href={to(roleHref(r.name))} onclick={(e) => e.stopPropagation()}><strong>{r.name}</strong></a>
27+
<a class="link" href={to(roleHref(r.name))}><strong>{r.name}</strong></a>
2928
<div class="cell-desc">{r.description}</div>
3029
</td>
3130
<td><RoleSourceBadge role={r} /></td>

‎ui/src/routes/catalog/+page.svelte‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { to } from '$lib/paths';
2+
import { openRow, to } from '$lib/paths';
33
import { goto } from '$app/navigation';
44
import { page } from '$app/state';
55
import type { CatalogNode, NodeKind } from '$lib/api';
@@ -125,12 +125,12 @@
125125
<tbody>
126126
{#each filtered as n (n.key)}
127127
{@const Glyph = nodeIcon[nodeIconKey(n)] ?? nodeIcon.table}
128-
<tr onclick={() => linksNodes && goto(to(`/catalog/${n.key}`))}>
128+
<tr onclick={(e) => linksNodes && openRow(e, `/catalog/${n.key}`)}>
129129
<td>
130130
<div class="cell-name">
131131
<Glyph size={15} strokeWidth={1.75} />
132132
<div class="min-w-0">
133-
{#if linksNodes}<a href={to(`/catalog/${n.key}`)} title={n.key} onclick={(e) => e.stopPropagation()}>{shortName(n.key)}</a>{:else}<span class="mono" title={n.key}>{shortName(n.key)}</span>{/if}
133+
{#if linksNodes}<a href={to(`/catalog/${n.key}`)} title={n.key}>{shortName(n.key)}</a>{:else}<span class="mono" title={n.key}>{shortName(n.key)}</span>{/if}
134134
<div class="cell-desc">{n.description}</div>
135135
</div>
136136
</div>

‎ui/src/routes/catalog/[name]/checks-tab.svelte‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
2-
import { to } from '$lib/paths';
3-
import { goto } from '$app/navigation';
2+
import { openRow, to } from '$lib/paths';
43
import type { CatalogNodeDetail } from '$lib/api';
54
import StatusLabel from '$lib/components/list/status-label.svelte';
65
import RelativeTime from '$lib/components/list/relative-time.svelte';
@@ -18,7 +17,7 @@
1817
<tbody>
1918
{#each node.checkResults as c (c.id)}
2019
{@const o = c.latest?.outcome ?? 'skipped'}
21-
<tr onclick={() => goto(to(`/checks/${c.id}`))}>
20+
<tr onclick={(e) => openRow(e, `/checks/${c.id}`)}>
2221
<td><a class="mono" href={to(`/checks/${c.id}`)}>{c.name}</a>{#if c.column}<div class="cell-desc">column {c.column}</div>{/if}</td>
2322
<td><StatusLabel tone={checkOutcomeTone[o]} label={checkOutcomeLabel[o]} /></td>
2423
<td class="muted capitalize">{c.severity}</td>

‎ui/src/routes/checks/+page.svelte‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { to } from '$lib/paths';
2+
import { openRow, to } from '$lib/paths';
33
import ShieldCheckIcon from '@lucide/svelte/icons/shield-check';
44
import { goto } from '$app/navigation';
55
import { page } from '$app/state';
@@ -108,19 +108,19 @@
108108
<tbody>
109109
{#each filtered as c (c.id)}
110110
{@const o = outcomeOf(c)}
111-
<tr onclick={() => goto(to(`/checks/${c.id}`))}>
111+
<tr onclick={(e) => openRow(e, `/checks/${c.id}`)}>
112112
<td>
113113
<div class="cell-name">
114114
<ShieldCheckIcon size={15} strokeWidth={1.75} />
115115
<div class="min-w-0">
116-
<a href={to(`/checks/${c.id}`)} class="check-name" onclick={(e) => e.stopPropagation()}>{c.name}</a>
116+
<a href={to(`/checks/${c.id}`)} class="check-name">{c.name}</a>
117117
<div class="cell-desc">{kindLabel(c)}</div>
118118
</div>
119119
</div>
120120
</td>
121121
<td><StatusLabel tone={checkOutcomeTone[o]} label={checkOutcomeLabel[o]} /></td>
122122
<td>
123-
{#if c.node}{#if linksNodes}<a href={to(`/catalog/${c.node}`)} class="link" onclick={(e) => e.stopPropagation()}>{c.node}</a>{:else}<span>{c.node}</span>{/if}{#if c.column}<span class="muted">.{c.column}</span>{/if}
123+
{#if c.node}{#if linksNodes}<a href={to(`/catalog/${c.node}`)} class="link">{c.node}</a>{:else}<span>{c.node}</span>{/if}{#if c.column}<span class="muted">.{c.column}</span>{/if}
124124
{:else}<span class="muted">{attachmentLabel[c.attachment]}</span>{/if}
125125
</td>
126126
<td class="muted capitalize">{c.severity}</td>

‎ui/src/routes/jobs/+page.svelte‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<script lang="ts">
2-
import { to } from '$lib/paths';
2+
import { openRow, to } from '$lib/paths';
33
import WorkflowIcon from '@lucide/svelte/icons/workflow';
44
import LayersIcon from '@lucide/svelte/icons/layers';
5-
import { goto } from '$app/navigation';
65
import type { JobKind, Trigger } from '$lib/api';
76
import AppTopbar from '$lib/components/app-topbar.svelte';
87
import ChoiceFilter from '$lib/components/list/choice-filter.svelte';
@@ -113,12 +112,12 @@
113112
<tbody>
114113
{#each filtered as j (j.key)}
115114
{@const jobTriggers = j.triggerIds.map((id) => triggerById.get(id)).filter((t) => t !== undefined)}
116-
<tr onclick={() => goto(to(`/jobs/${j.key}`))}>
115+
<tr onclick={(e) => openRow(e, `/jobs/${j.key}`)}>
117116
<td>
118117
<div class="cell-name">
119118
{#if j.kind === 'group'}<LayersIcon size={15} strokeWidth={1.75} />{:else}<WorkflowIcon size={15} strokeWidth={1.75} />{/if}
120119
<div class="min-w-0">
121-
<a href={to(`/jobs/${j.key}`)} onclick={(e) => e.stopPropagation()}>{j.key}</a>
120+
<a href={to(`/jobs/${j.key}`)}>{j.key}</a>
122121
<div class="cell-desc">{j.description}</div>
123122
</div>
124123
</div>
@@ -153,7 +152,7 @@
153152
aria-label="{t.state === 'running' ? 'Pause' : 'Turn on'} {t.name}"
154153
></button>
155154
</span>
156-
<a class:muted={t.state === 'paused'} href={to(`/triggers/${t.id}`)} title={t.cadence} onclick={(e) => e.stopPropagation()}>{t.name}</a>
155+
<a class:muted={t.state === 'paused'} href={to(`/triggers/${t.id}`)} title={t.cadence}>{t.name}</a>
157156
</div>
158157
{/each}
159158
</div>
@@ -162,7 +161,7 @@
162161
{#if showOwner}<td class="muted">{j.owner ?? '—'}</td>{/if}
163162
<td>
164163
{#if j.lastRun}
165-
<a class="last-run" href={to(`/runs/${j.lastRun.id}`)} onclick={(e) => e.stopPropagation()}>
164+
<a class="last-run" href={to(`/runs/${j.lastRun.id}`)}>
166165
<StatusLabel tone={runStatusTone[j.lastRun.status]} label={runStatusLabel[j.lastRun.status]} />
167166
{#if j.lastRun.startedAt}<RelativeTime value={formatAgo(j.lastRun.startedAt, app.now)} exact={formatStamp(j.lastRun.startedAt)} />{/if}
168167
</a>

‎ui/src/routes/jobs/[name]/job-view.svelte‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import Loading from '$lib/components/loading.svelte';
3-
import { to } from '$lib/paths';
3+
import { openRow, to } from '$lib/paths';
44
import { goto } from '$app/navigation';
55
import type { Trigger } from '$lib/api';
66
import AppTopbar from '$lib/components/app-topbar.svelte';
@@ -256,7 +256,7 @@
256256
</thead>
257257
<tbody>
258258
{#each runs as r (r.id)}
259-
<tr onclick={() => goto(to(`/runs/${r.id}`))}>
259+
<tr onclick={(e) => openRow(e, `/runs/${r.id}`)}>
260260
<td><i style:background={runStatusTone[r.status]}></i>{runStatusLabel[r.status]}</td>
261261
<td><a href={to(`/runs/${r.id}`)} class="mono" title={r.id}>{shortRunId(r.id)}</a>{#if r.narrowing}<span class="part" title="Ran part of the job: sqb build {narrowingText(r.narrowing)}">part</span>{/if}</td>
262262
<td class="faint">{runOriginLabel[r.origin]}{r.parentRunId ? ` in group run ${shortRunId(r.parentRunId)}` : r.triggerName ? ` · ${r.triggerName}` : ''}</td>

‎ui/src/routes/locations/+page.svelte‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
2-
import { to } from '$lib/paths';
3-
import { goto } from '$app/navigation';
2+
import { openRow, to } from '$lib/paths';
43
import MapPinIcon from '@lucide/svelte/icons/map-pin';
54
import AppTopbar from '$lib/components/app-topbar.svelte';
65
import Button from '$lib/components/ui/button/button.svelte';
@@ -78,12 +77,12 @@
7877
{#each filtered as l (l.id)}
7978
{@const test = tested[l.id] ?? l.connectionTest}
8079
{@const opens = opensDetail && l.health !== null}
81-
<tr class:static={!opens} onclick={() => opens && goto(to(`/locations/${l.id}`))}>
80+
<tr class:static={!opens} onclick={(e) => opens && openRow(e, `/locations/${l.id}`)}>
8281
<td>
8382
<div class="cell-name">
8483
<MapPinIcon size={15} strokeWidth={1.75} />
8584
<div class="min-w-0">
86-
{#if opens}<a href={to(`/locations/${l.id}`)} onclick={(e) => e.stopPropagation()}>{l.name}</a>{:else}{l.name}{/if}
85+
{#if opens}<a href={to(`/locations/${l.id}`)}>{l.name}</a>{:else}{l.name}{/if}
8786
<div class="cell-desc" title={l.target.connectionSummary}>{targetWords(l.target)}</div>
8887
</div>
8988
</div>
@@ -95,7 +94,7 @@
9594
<span title={partialTitle}><StatusLabel tone="var(--sb-text-faint)" label="Unknown" muted /></span>
9695
{/if}
9796
{#if l.activeProblems}
98-
<div class="cell-desc"><a class="link" href={to(`/locations/${l.id}#problems`)} onclick={(e) => e.stopPropagation()}>{l.activeProblems} open problem{l.activeProblems === 1 ? '' : 's'}</a></div>
97+
<div class="cell-desc"><a class="link" href={to(`/locations/${l.id}#problems`)}>{l.activeProblems} open problem{l.activeProblems === 1 ? '' : 's'}</a></div>
9998
{/if}
10099
</td>
101100
<td>

0 commit comments

Comments
 (0)