Add a repository identity document view

Adds a read-only page for a repository's identity document. It shows the
current document together with its full revision history. The data and
wording follow heartwood and the rad id / rad inspect CLI.

Co-Authored-By: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
Brandon Oxendine
2026-09-24 17:04:54 +02:00
committed by Rūdolfs Ošiņš
co-authored by Rūdolfs Ošiņš
parent 7c29fae1a7
commit 54835363a9
35 changed files with 2069 additions and 78 deletions
+2 -1
View File
@@ -89,7 +89,8 @@
flex-direction: row;
gap: 0.5rem;
justify-content: center;
z-index: 20;
/* Portaled to the body, so it has to clear the modal layer as well. */
z-index: 400;
background: var(--color-surface-subtle);
color: var(--color-text-primary);
border: 1px solid var(--color-border-subtle);
+137
View File
@@ -0,0 +1,137 @@
<script lang="ts">
import type { Change } from "@bindings/identity/Change";
import { authorForNodeId, unreachable } from "@app/lib/utils";
import Icon from "@app/components/Icon.svelte";
import NodeId from "@app/components/NodeId.svelte";
interface Props {
changes: Change[];
// An empty change list means something different for the root.
root?: boolean;
}
const { changes, root = false }: Props = $props();
</script>
<style>
.changes {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.change {
display: flex;
align-items: center;
gap: 0.5rem;
font: var(--txt-body-m-regular);
color: var(--color-text-primary);
}
.icon {
display: inline-flex;
flex-shrink: 0;
}
.added {
color: var(--color-feedback-success-text);
}
.removed {
color: var(--color-feedback-error-text);
}
.neutral {
color: var(--color-text-secondary);
}
.label {
color: var(--color-text-secondary);
}
.from {
color: var(--color-text-secondary);
text-decoration: line-through;
}
.value {
font: var(--txt-code-regular);
color: var(--color-text-primary);
}
.empty {
font: var(--txt-body-m-regular);
color: var(--color-text-secondary);
}
</style>
<div class="changes">
{#each changes as change}
<div class="change">
{#if change.type === "delegateAdded"}
<span class="icon added"><Icon name="plus" /></span>
<span class="label">Added delegate</span>
<NodeId {...authorForNodeId(change.delegate)} />
{:else if change.type === "delegateRemoved"}
<span class="icon removed"><Icon name="minus" /></span>
<span class="label">Removed delegate</span>
<NodeId {...authorForNodeId(change.delegate)} />
{:else if change.type === "thresholdChanged"}
<span class="icon neutral"><Icon name="badge" /></span>
<span class="label">Threshold</span>
<span class="from value">{change.from}</span>
<Icon name="arrow-right" />
<span class="value">{change.to}</span>
{:else if change.type === "allowAdded"}
<span class="icon added"><Icon name="plus" /></span>
<span class="label">Allowed to view</span>
<NodeId {...authorForNodeId(change.peer)} />
{:else if change.type === "allowRemoved"}
<span class="icon removed"><Icon name="minus" /></span>
<span class="label">No longer allowed to view</span>
<NodeId {...authorForNodeId(change.peer)} />
{:else if change.type === "visibilityChanged"}
<span class="icon neutral"><Icon name="eye" /></span>
<span class="label">Visibility</span>
<span class="from value">{change.from.type}</span>
<Icon name="arrow-right" />
<span class="value">{change.to.type}</span>
{:else if change.type === "nameChanged"}
<span class="icon neutral"><Icon name="repository" /></span>
<span class="label">Name</span>
<span class="from value">{change.from}</span>
<Icon name="arrow-right" />
<span class="value">{change.to}</span>
{:else if change.type === "descriptionChanged"}
<span class="icon neutral"><Icon name="document" /></span>
<span class="label">Description changed</span>
{:else if change.type === "defaultBranchChanged"}
<span class="icon neutral"><Icon name="branch" /></span>
<span class="label">Default branch</span>
<span class="from value">{change.from}</span>
<Icon name="arrow-right" />
<span class="value">{change.to}</span>
{:else if change.type === "payloadChanged"}
<span
class="icon"
class:added={change.operation === "added"}
class:removed={change.operation === "removed"}
class:neutral={change.operation === "updated"}>
<Icon
name={change.operation === "added"
? "plus"
: change.operation === "removed"
? "minus"
: "edit"} />
</span>
<span class="label">
Payload {change.operation}
</span>
<span class="value">{change.payload}</span>
{:else}
{unreachable(change)}
{/if}
</div>
{:else}
<div class="empty">
{#if root}
Establishes the repository's first identity document.
{:else}
No changes to the fields shown here. See the raw document for detail.
{/if}
</div>
{/each}
</div>
+248
View File
@@ -0,0 +1,248 @@
<script lang="ts">
import type { Doc } from "@bindings/identity/Doc";
import type { Revision } from "@bindings/identity/Revision";
import { authorForNodeId, pluralize } from "@app/lib/utils";
import Icon from "@app/components/Icon.svelte";
import Id from "@app/components/Id.svelte";
import IdentityJsonButton from "@app/components/IdentityJsonButton.svelte";
import NodeId from "@app/components/NodeId.svelte";
import VisibilityBadge from "@app/components/VisibilityBadge.svelte";
interface Props {
doc: Doc;
rid: string;
revision?: Revision;
}
const { doc, rid, revision }: Props = $props();
// Payloads rendered below; the rest are listed by name.
const knownPayloads = ["xyz.radicle.project", "xyz.radicle.crefs"];
const otherPayloads = $derived(
doc.payloadIds.filter(id => !knownPayloads.includes(id)),
);
</script>
<style>
.details {
min-width: 0;
}
.section {
padding: 0.875rem 0;
}
.section + .section {
border-top: 1px solid var(--color-border-subtle);
}
.section-title {
font: var(--txt-body-m-medium);
color: var(--color-text-primary);
margin: 0 0 0.625rem;
}
.delegates {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 0.5rem;
min-width: 0;
}
.delegate-chip {
display: inline-flex;
align-items: center;
height: 2rem;
padding: 0 0.5rem;
border: 1px solid var(--color-border-subtle);
border-radius: var(--border-radius-sm);
background-color: var(--color-surface-canvas);
font: var(--txt-body-m-regular);
}
.delegates-head {
display: flex;
align-items: baseline;
gap: 0.5rem;
margin-bottom: 0.625rem;
}
.delegates-head .section-title {
margin: 0;
}
.quorum {
font: var(--txt-body-m-regular);
color: var(--color-text-secondary);
white-space: nowrap;
}
.fields {
display: grid;
grid-template-columns: max-content minmax(0, 1fr);
column-gap: 2rem;
row-gap: 0.5rem;
align-items: baseline;
font: var(--txt-body-m-regular);
}
.field-label {
color: var(--color-text-secondary);
}
.field-value {
min-width: 0;
color: var(--color-text-primary);
overflow-wrap: anywhere;
justify-self: start;
}
.section-action {
margin-top: 0.875rem;
}
.mono {
font: var(--txt-code-regular);
}
.hint {
color: var(--color-text-secondary);
}
.empty {
color: var(--color-text-secondary);
}
.rules-error {
display: flex;
align-items: flex-start;
gap: 0.375rem;
margin-bottom: 0.625rem;
font: var(--txt-body-m-regular);
color: var(--color-feedback-warning-text);
}
.inline-list {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.5rem;
min-width: 0;
}
.rule + .rule {
margin-top: 0.625rem;
}
.rule-pattern {
font: var(--txt-code-regular);
color: var(--color-text-primary);
overflow-wrap: anywhere;
}
.rule-detail {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.375rem;
margin-top: 0.125rem;
font: var(--txt-body-m-regular);
color: var(--color-text-secondary);
}
</style>
<div class="details">
<div class="section">
<div class="delegates-head">
<h2 class="section-title">Delegates</h2>
<span class="quorum">
{doc.majority} of {doc.delegates.length} must sign to change this document
</span>
</div>
<div class="delegates">
{#each doc.delegates as delegate (delegate.did)}
<div class="delegate-chip">
<NodeId {...authorForNodeId(delegate)} />
</div>
{/each}
</div>
</div>
<div class="section">
<h2 class="section-title">Document</h2>
<div class="fields">
{#if doc.project}
<span class="field-label">Default branch</span>
<span class="field-value mono">{doc.project.defaultBranch}</span>
{/if}
<span class="field-label">Visibility</span>
<span class="field-value">
<VisibilityBadge type={doc.visibility.type} />
</span>
{#if doc.visibility.type === "private" && doc.visibility.allow}
<span class="field-label">Also visible to</span>
<span class="field-value inline-list">
{#each doc.visibility.allow as peer (peer.did)}
<NodeId {...authorForNodeId(peer)} />
{/each}
</span>
{/if}
<span class="field-label">Default branch threshold</span>
<span class="field-value">
{doc.threshold} of {doc.delegates.length}
<span class="hint">
— delegates whose {doc.project?.defaultBranch ?? "default"} branch must
contain the same commit for it to become canonical
</span>
</span>
<span class="field-label">Repository ID</span>
<span class="field-value mono">
<Id id={rid} clipboard={rid} label="repository ID" shorten={false} />
</span>
<span class="field-label">Document version</span>
<span class="field-value">{doc.version}</span>
</div>
<div class="section-action">
<IdentityJsonButton raw={doc.raw} {revision} />
</div>
</div>
<div class="section">
<h2 class="section-title">Canonical refs</h2>
{#if doc.canonicalRefsError}
<div class="rules-error">
<Icon name="warning" />
<span>
Heartwood rejects these rules: {doc.canonicalRefsError}
</span>
</div>
{/if}
{#if doc.canonicalRefs.length > 0}
{#each doc.canonicalRefs as rule (rule.pattern)}
<div class="rule">
<div class="rule-pattern">{rule.pattern}</div>
<div class="rule-detail">
{#if rule.allow.type === "delegates"}
<span>
Canonical once {rule.threshold} of {doc.delegates.length}
{pluralize("delegate", doc.delegates.length)}
{rule.threshold === 1 ? "agrees" : "agree"}
</span>
{:else if rule.allow.dids.length === 1}
<span>Canonical as published by</span>
<NodeId {...authorForNodeId(rule.allow.dids[0])} />
{:else}
<span>
Canonical once {rule.threshold} of these
{rule.allow.dids.length} peers
{rule.threshold === 1 ? "agrees" : "agree"}:
</span>
{#each rule.allow.dids as peer (peer.did)}
<NodeId {...authorForNodeId(peer)} />
{/each}
{/if}
</div>
</div>
{/each}
{:else}
<div class="empty">No canonical-refs rules.</div>
{/if}
</div>
{#if otherPayloads.length > 0}
<div class="section">
<h2 class="section-title">Other payloads</h2>
{#each otherPayloads as payload (payload)}
<div class="rule">
<div class="rule-pattern">{payload}</div>
<div class="rule-detail">
Not rendered by this app. See the raw document.
</div>
</div>
{/each}
</div>
{/if}
</div>
+26
View File
@@ -0,0 +1,26 @@
<script lang="ts">
import type { Revision } from "@bindings/identity/Revision";
import type { ComponentProps } from "svelte";
import { show } from "@app/lib/modal";
import Button from "@app/components/Button.svelte";
import Icon from "@app/components/Icon.svelte";
import RawIdentityDocumentModal from "@app/modals/RawIdentityDocument.svelte";
interface Props {
raw: string;
revision?: Revision;
styleHeight?: ComponentProps<typeof Button>["styleHeight"];
}
const { raw, revision, styleHeight = "2rem" }: Props = $props();
</script>
<Button
{styleHeight}
variant="outline"
onclick={() =>
show({ component: RawIdentityDocumentModal, props: { raw, revision } })}>
<Icon name="code" />View JSON
</Button>
+72
View File
@@ -0,0 +1,72 @@
<script lang="ts" module>
import type { State } from "@bindings/identity/State";
import { formatOid } from "@app/lib/utils";
const icons = {
active: "hourglass",
accepted: "checkmark",
rejected: "close",
} as const;
const labels = {
active: "Active",
accepted: "Accepted",
rejected: "Rejected",
};
export function stateIcon(state: State): (typeof icons)[State["status"]] {
return icons[state.status];
}
export function stateCaption(state: State): string | undefined {
if (state.status === "rejected") {
if (state.reason.type === "vote") return "Rejected by delegate votes";
if (state.reason.type === "parent")
return "Rejected because its parent revision was rejected";
return `Rejected because sibling ${formatOid(state.reason.revision)} was accepted`;
}
return undefined;
}
</script>
<script lang="ts">
import Icon from "@app/components/Icon.svelte";
interface Props {
state: State;
}
const { state }: Props = $props();
</script>
<style>
.badge {
gap: 0.375rem;
padding-right: 0.625rem;
font: var(--txt-body-s-regular);
white-space: nowrap;
}
.accepted {
background-color: var(--color-feedback-success-bg);
color: var(--color-feedback-success-text);
}
.active {
background-color: var(--color-feedback-warning-bg);
color: var(--color-feedback-warning-text);
}
.rejected {
background-color: var(--color-feedback-error-bg);
color: var(--color-feedback-error-text);
}
</style>
<span
class="global-chip badge"
class:accepted={state.status === "accepted"}
class:active={state.status === "active"}
class:rejected={state.status === "rejected"}
title={stateCaption(state)}>
<Icon name={stateIcon(state)} />
{labels[state.status]}
</span>
+27 -12
View File
@@ -22,6 +22,10 @@
alias?: string;
inline?: boolean;
styleFont?: string;
// Hides the alias; the card still shows it.
avatarOnly?: boolean;
avatarSize?: string;
oncardtoggle?: (expanded: boolean) => void;
}
const {
@@ -29,9 +33,17 @@
alias,
inline = false,
styleFont = undefined,
avatarOnly = false,
avatarSize = "1rem",
oncardtoggle,
}: Props = $props();
let cardExpanded = $state(false);
$effect(() => {
oncardtoggle?.(cardExpanded);
});
let openTimer: ReturnType<typeof setTimeout> | undefined;
let closeTimer: ReturnType<typeof setTimeout> | undefined;
let copyIcon: "copy" | "checkmark" = $state("copy");
@@ -118,8 +130,6 @@
border-radius: var(--border-radius-sm);
}
.avatar-container {
width: 1rem;
height: 1rem;
overflow: hidden;
flex-shrink: 0;
}
@@ -294,17 +304,22 @@
onmouseleave={scheduleClose}
onfocusin={openCard}
onfocusout={scheduleClose}>
<div class="avatar-container">
<UserAvatar nodeId={publicKey} styleWidth="1rem" />
<div
class="avatar-container"
style:width={avatarSize}
style:height={avatarSize}>
<UserAvatar nodeId={publicKey} styleWidth={avatarSize} />
</div>
{#if effectiveAlias}
<span class="txt-overflow alias">
{effectiveAlias}
</span>
{:else}
<span class="no-alias">
{truncateId(publicKey)}
</span>
{#if !avatarOnly}
{#if effectiveAlias}
<span class="txt-overflow alias">
{effectiveAlias}
</span>
{:else}
<span class="no-alias">
{truncateId(publicKey)}
</span>
{/if}
{/if}
</div>
{/snippet}
+81
View File
@@ -0,0 +1,81 @@
<script lang="ts">
import { File } from "@pierre/diffs";
import { untrack } from "svelte";
import { fontSettings } from "@app/lib/appearance.svelte";
import {
codeLineHeight,
getWorkerPool,
gutterUnsafeCSS,
surfaceUnsafeCSS,
themes,
} from "@app/lib/pierreView";
import { theme } from "@app/components/ThemeSwitch.svelte";
interface Props {
contents: string;
path: string;
// Keys the shared worker pool's highlight cache, so it must be unique to
// this exact text.
cacheKey: string;
}
const { contents, path, cacheKey }: Props = $props();
let container = $state<HTMLElement>();
let view = $state.raw<File | undefined>(undefined);
const lineHeightPx = $derived(codeLineHeight(fontSettings.size));
function options() {
return {
theme: themes,
themeType: $theme,
disableFileHeader: true,
unsafeCSS: gutterUnsafeCSS + surfaceUnsafeCSS,
};
}
$effect(() => {
const el = container;
if (!el) {
return;
}
const file = { name: path, contents, cacheKey };
return untrack(() => {
const instance = new File(options(), getWorkerPool());
view = instance;
instance.render({ file, containerWrapper: el });
return () => {
view = undefined;
instance.cleanUp();
};
});
});
$effect(() => {
void $theme;
void lineHeightPx;
const instance = view;
if (!instance) {
return;
}
untrack(() => {
instance.setOptions(options());
instance.rerender();
});
});
</script>
<style>
.file {
min-width: 0;
}
</style>
<div
bind:this={container}
class="file global-pierre-surface"
style:--diffs-line-height="{lineHeightPx}px">
</div>
+63 -55
View File
@@ -2,13 +2,12 @@
import type { Config } from "@bindings/config/Config";
import type { RepoInfo } from "@bindings/repo/RepoInfo";
import { explorerUrl, truncateDid } from "@app/lib/utils";
import * as router from "@app/lib/router";
import { authorForNodeId } from "@app/lib/utils";
import CheckoutRepoButton from "@app/components/CheckoutRepoButton.svelte";
import HoverPopover from "@app/components/HoverPopover.svelte";
import Icon from "@app/components/Icon.svelte";
import NodeId from "@app/components/NodeId.svelte";
import ShareButton from "@app/components/ShareButton.svelte";
import UserAvatar from "@app/components/UserAvatar.svelte";
import VisibilityBadge from "@app/components/VisibilityBadge.svelte";
interface Props {
@@ -19,6 +18,12 @@
const { repo, config }: Props = $props();
const project = $derived(repo.payloads["xyz.radicle.project"]!);
// The cards are portaled out of the stack, so moving onto one ends the
// stack's hover. Keep it fanned out while any card is still open.
let hovered = $state(false);
const cardsOpen: Record<string, boolean> = $state({});
const fanned = $derived(hovered || Object.values(cardsOpen).some(Boolean));
</script>
<style>
@@ -52,9 +57,25 @@
.meta-item {
display: flex;
align-items: center;
gap: 0.375rem;
gap: 0.25rem;
font: var(--txt-body-m-regular);
}
.delegates-button {
display: inline-flex;
align-items: center;
gap: 0.375rem;
height: 1.75rem;
padding: 0 0.5rem;
border: 0;
border-radius: var(--border-radius-sm);
background: none;
font: inherit;
cursor: pointer;
}
.delegates-button:hover,
.delegates-button:focus-visible {
background-color: var(--color-surface-subtle);
}
.meta-label {
color: var(--color-text-secondary);
}
@@ -64,13 +85,21 @@
.avatars {
display: flex;
align-items: center;
gap: 0.25rem;
}
.avatar-wrap {
width: 1.25rem;
height: 1.25rem;
overflow: hidden;
flex-shrink: 0;
/* Positioned so each avatar paints together with its ring; otherwise every
ring is painted before any image and the one below covers it. */
.avatar {
position: relative;
display: flex;
border-radius: 2px;
box-shadow: 0 0 0 2px var(--color-surface-canvas);
transition: margin-left 150ms ease;
}
.avatar + .avatar {
margin-left: -0.625rem;
}
.avatars.fanned .avatar + .avatar {
margin-left: 0.25rem;
}
.actions {
display: flex;
@@ -78,17 +107,6 @@
gap: 0.5rem;
flex-shrink: 0;
}
a {
color: inherit;
display: inline-flex;
align-items: center;
gap: 0.25rem;
text-decoration: none;
color: var(--color-text-secondary);
}
a:hover {
color: var(--color-text-primary);
}
</style>
<div class="header">
@@ -106,39 +124,29 @@
seeds={repo.seeding} />
<div class="meta-item">
<span class="meta-label">Delegates</span>
<span class="meta-value">{repo.threshold}/{repo.delegates.length}</span>
<div class="avatars">
{#each repo.delegates as delegate}
<HoverPopover placement="bottom-start" stylePadding="0.25rem 0.5rem">
{#snippet toggle()}
<div class="avatar-wrap">
<UserAvatar nodeId={delegate.did} styleWidth="1.25rem" />
</div>
{/snippet}
{#snippet popover()}
<a
class="global-flex txt-body-m-regular"
style:white-space="nowrap"
style:text-decoration="none"
style:width="100%"
href={explorerUrl(`users/${delegate.did}`, config)}
target="_blank">
{#if delegate.alias}
<span class="txt-overflow alias">
{delegate.alias}
</span>
{:else}
<span class="no-alias">
{truncateDid(delegate.did)}
</span>
{/if}
<span style:margin-left="auto">
<Icon name="open-external" />
</span>
</a>
{/snippet}
</HoverPopover>
<button
type="button"
class="delegates-button"
title={`A commit becomes canonical once ${repo.threshold} of ${repo.delegates.length} delegates have the same commit on their ${project.data.defaultBranch} branch`}
onclick={() =>
router.push({ resource: "repo.identity", rid: repo.rid })}>
<span class="meta-label">Delegates</span>
<span class="meta-value">{repo.threshold}/{repo.delegates.length}</span>
</button>
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="avatars"
class:fanned
onmouseenter={() => (hovered = true)}
onmouseleave={() => (hovered = false)}>
{#each repo.delegates as delegate, index (delegate.did)}
<div class="avatar" style:z-index={repo.delegates.length - index}>
<NodeId
{...authorForNodeId(delegate)}
avatarOnly
avatarSize="1.25rem"
oncardtoggle={expanded => (cardsOpen[delegate.did] = expanded)} />
</div>
{/each}
</div>
</div>
+8
View File
@@ -1200,6 +1200,14 @@
y={contextMenu.y}
target={contextMenu.target}
onclose={closeContextMenu}>
<button
class="menu-item"
role="menuitem"
onclick={() => router.push({ resource: "repo.identity", rid: repo.rid })}>
<Icon name="document" />
View identity document
</button>
<div class="menu-separator"></div>
<button
class="menu-item"
role="menuitem"