mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 18:20:30 +08:00
Hide filters if all releases/artifacts by delegates
- Show delegate badge for releases - Hide filters if all artifacts are non-delegate - Decide release filter visibility once per route to avoid layout shift when loading more - Say "No releases by delegates" when all holds some
This commit is contained in:
@@ -61,21 +61,33 @@
|
||||
delegateIds.has(a.author.id),
|
||||
);
|
||||
// Artifacts are scoped to delegate authors by default; the endpoint returns
|
||||
// all of them, so filtering happens client-side.
|
||||
$: authorArtifacts = allAuthors ? release.artifacts : delegateArtifacts;
|
||||
// all of them, so filtering happens client-side. With no delegate artifact
|
||||
// at all, fall back to every author.
|
||||
$: authorArtifacts =
|
||||
allAuthors || delegateArtifacts.length === 0
|
||||
? release.artifacts
|
||||
: delegateArtifacts;
|
||||
$: shownArtifacts = visible(authorArtifacts, showRedacted, delegateIds);
|
||||
// The redacted count is the hidden set within the current author scope.
|
||||
$: redactedCount = authorArtifacts.filter(a =>
|
||||
redactedByTrusted(a, delegateIds),
|
||||
).length;
|
||||
|
||||
// Segment counts reflect what each choice would actually show; the redacted
|
||||
// count is the hidden set within the current author scope.
|
||||
// Segment counts reflect what each choice would actually show, so an
|
||||
// artifact hidden as redacted never counts towards a scope. They label the
|
||||
// segments only: the author scope and the filter visibility come from the
|
||||
// unfiltered sets, so toggling redacted artifacts never moves them.
|
||||
$: delegateCount = visible(
|
||||
delegateArtifacts,
|
||||
showRedacted,
|
||||
delegateIds,
|
||||
).length;
|
||||
$: allCount = visible(release.artifacts, showRedacted, delegateIds).length;
|
||||
$: redactedCount = authorArtifacts.filter(a =>
|
||||
redactedByTrusted(a, delegateIds),
|
||||
).length;
|
||||
|
||||
// Filter only when both scopes hold something.
|
||||
$: showFilters =
|
||||
delegateArtifacts.length > 0 &&
|
||||
delegateArtifacts.length !== release.artifacts.length;
|
||||
|
||||
// Format a byte count as a human-readable size (mirrors the CLI display).
|
||||
function formatBytes(bytes: number): string {
|
||||
@@ -171,6 +183,12 @@
|
||||
padding: 1rem;
|
||||
border-bottom: 1px solid var(--color-border-subtle);
|
||||
}
|
||||
.redacted-toggle {
|
||||
margin-left: auto;
|
||||
}
|
||||
.filter-divider {
|
||||
border-bottom: 1px solid var(--color-border-subtle);
|
||||
}
|
||||
.empty-artifacts {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -406,6 +424,9 @@
|
||||
{baseUrl}
|
||||
nodeId={release.creator.id}
|
||||
alias={release.creator.alias} />
|
||||
{#if delegateIds.has(release.creator.id)}
|
||||
<DelegateBadge />
|
||||
{/if}
|
||||
released
|
||||
<Id id={release.id} />
|
||||
<span title={utils.absoluteTimestamp(release.createdAt)}>
|
||||
@@ -415,59 +436,71 @@
|
||||
</CobHeader>
|
||||
|
||||
<div class="artifacts">
|
||||
<div class="filter">
|
||||
<div class="segmented">
|
||||
<Link
|
||||
route={{
|
||||
resource: "repo.release",
|
||||
repo: repoId,
|
||||
node: baseUrl,
|
||||
release: release.id,
|
||||
}}>
|
||||
<Button let:hover variant={!allAuthors ? "gray" : "background"}>
|
||||
<Icon name="badge" />
|
||||
<div class="title-counter">
|
||||
Delegates
|
||||
<span
|
||||
class="counter"
|
||||
class:selected={!allAuthors}
|
||||
class:hover={hover && allAuthors}>
|
||||
{delegateCount}
|
||||
</span>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
<Link
|
||||
route={{
|
||||
resource: "repo.release",
|
||||
repo: repoId,
|
||||
node: baseUrl,
|
||||
release: release.id,
|
||||
allAuthors: true,
|
||||
}}>
|
||||
<Button let:hover variant={allAuthors ? "gray" : "background"}>
|
||||
<Icon name="avatar-incognito" />
|
||||
<div class="title-counter">
|
||||
All
|
||||
<span
|
||||
class="counter"
|
||||
class:selected={allAuthors}
|
||||
class:hover={hover && !allAuthors}>
|
||||
{allCount}
|
||||
</span>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
{#if showFilters || redactedCount > 0}
|
||||
<div class="filter">
|
||||
{#if showFilters}
|
||||
<div class="segmented">
|
||||
<Link
|
||||
route={{
|
||||
resource: "repo.release",
|
||||
repo: repoId,
|
||||
node: baseUrl,
|
||||
release: release.id,
|
||||
}}>
|
||||
<Button
|
||||
let:hover
|
||||
variant={!allAuthors ? "gray" : "background"}>
|
||||
<Icon name="badge" />
|
||||
<div class="title-counter">
|
||||
Delegates
|
||||
<span
|
||||
class="counter"
|
||||
class:selected={!allAuthors}
|
||||
class:hover={hover && allAuthors}>
|
||||
{delegateCount}
|
||||
</span>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
<Link
|
||||
route={{
|
||||
resource: "repo.release",
|
||||
repo: repoId,
|
||||
node: baseUrl,
|
||||
release: release.id,
|
||||
allAuthors: true,
|
||||
}}>
|
||||
<Button
|
||||
let:hover
|
||||
variant={allAuthors ? "gray" : "background"}>
|
||||
<Icon name="avatar-incognito" />
|
||||
<div class="title-counter">
|
||||
All
|
||||
<span
|
||||
class="counter"
|
||||
class:selected={allAuthors}
|
||||
class:hover={hover && !allAuthors}>
|
||||
{allCount}
|
||||
</span>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
{/if}
|
||||
{#if redactedCount > 0}
|
||||
<div class="redacted-toggle">
|
||||
<Button
|
||||
variant="background"
|
||||
on:click={() => (showRedacted = !showRedacted)}>
|
||||
{showRedacted ? "Hide redacted" : "Show redacted"}
|
||||
<span class="counter">{redactedCount}</span>
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if redactedCount > 0}
|
||||
<Button
|
||||
variant="background"
|
||||
on:click={() => (showRedacted = !showRedacted)}>
|
||||
{showRedacted ? "Hide redacted" : "Show redacted"}
|
||||
<span class="counter">{redactedCount}</span>
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="filter-divider"></div>
|
||||
{/if}
|
||||
|
||||
{#if shownArtifacts.length === 0}
|
||||
<div class="empty-artifacts">
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
import { absoluteTimestamp, formatTimestamp } from "@app/lib/utils";
|
||||
|
||||
import DelegateBadge from "./DelegateBadge.svelte";
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
import Id from "@app/components/Id.svelte";
|
||||
import InlineTitle from "@app/views/repos/components/InlineTitle.svelte";
|
||||
@@ -10,6 +11,7 @@
|
||||
import NodeId from "@app/components/NodeId.svelte";
|
||||
|
||||
export let baseUrl: BaseUrl;
|
||||
export let delegateIds: Set<string>;
|
||||
export let release: Release;
|
||||
export let repoId: string;
|
||||
export let allAuthors: boolean = false;
|
||||
@@ -101,6 +103,9 @@
|
||||
{baseUrl}
|
||||
nodeId={release.creator.id}
|
||||
alias={release.creator.alias} />
|
||||
{#if delegateIds.has(release.creator.id)}
|
||||
<DelegateBadge />
|
||||
{/if}
|
||||
released
|
||||
<Id id={release.id} />
|
||||
<span title={absoluteTimestamp(release.createdAt)}>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
export let repo: Repo;
|
||||
export let repoId: string;
|
||||
export let allAuthors: boolean;
|
||||
export let showFilters: boolean;
|
||||
export let nodeId: string;
|
||||
export let nodeAvatarUrl: string | undefined;
|
||||
|
||||
@@ -36,13 +37,15 @@
|
||||
}
|
||||
|
||||
$: delegateIds = new Set(repo.delegates.map(d => d.id));
|
||||
// The delegate count isn't in repo metadata; derive it from the loaded list.
|
||||
// In the all-authors view we filter for delegates; otherwise the loaded list
|
||||
// already is the delegate set.
|
||||
// The delegate count isn't in repo metadata; derive it from the loaded
|
||||
// pages. It labels the segment only, and reads as "30+" while pages are
|
||||
// outstanding; whether the segments show at all is settled by the router.
|
||||
$: delegateReleaseCount = allAuthors
|
||||
? allReleases.filter(r => delegateIds.has(r.creator.id)).length
|
||||
: allReleases.length;
|
||||
|
||||
$: releaseCount = repo.payloads["xyz.radicle.project"].meta.releases;
|
||||
|
||||
const api = new HttpdClient(baseUrl);
|
||||
|
||||
async function loadReleases(): Promise<void> {
|
||||
@@ -133,46 +136,49 @@
|
||||
Releases
|
||||
</Link>
|
||||
</svelte:fragment>
|
||||
<div slot="header" class="header">
|
||||
<Link route={{ resource: "repo.releases", repo: repoId, node: baseUrl }}>
|
||||
<Button let:hover variant={!allAuthors ? "gray" : "background"}>
|
||||
<Icon name="badge" />
|
||||
<div class="title-counter">
|
||||
Delegates
|
||||
<span
|
||||
class="counter"
|
||||
class:selected={!allAuthors}
|
||||
class:hover={hover && allAuthors}>
|
||||
{delegateReleaseCount}{showMoreButton ? "+" : ""}
|
||||
</span>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
<Link
|
||||
route={{
|
||||
resource: "repo.releases",
|
||||
repo: repoId,
|
||||
node: baseUrl,
|
||||
allAuthors: true,
|
||||
}}>
|
||||
<Button let:hover variant={allAuthors ? "gray" : "background"}>
|
||||
<Icon name="avatar-incognito" />
|
||||
<div class="title-counter">
|
||||
All
|
||||
<!-- Only the full (all-authors) count is in repo metadata; absent on
|
||||
older nodes. -->
|
||||
{#if repo.payloads["xyz.radicle.project"].meta.releases !== undefined}
|
||||
<span
|
||||
class="counter"
|
||||
class:selected={allAuthors}
|
||||
class:hover={hover && !allAuthors}>
|
||||
{repo.payloads["xyz.radicle.project"].meta.releases}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
<svelte:fragment slot="header">
|
||||
{#if showFilters}
|
||||
<div class="header">
|
||||
<Link
|
||||
route={{ resource: "repo.releases", repo: repoId, node: baseUrl }}>
|
||||
<Button let:hover variant={!allAuthors ? "gray" : "background"}>
|
||||
<Icon name="badge" />
|
||||
<div class="title-counter">
|
||||
Delegates
|
||||
<span
|
||||
class="counter"
|
||||
class:selected={!allAuthors}
|
||||
class:hover={hover && allAuthors}>
|
||||
{delegateReleaseCount}{showMoreButton ? "+" : ""}
|
||||
</span>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
<Link
|
||||
route={{
|
||||
resource: "repo.releases",
|
||||
repo: repoId,
|
||||
node: baseUrl,
|
||||
allAuthors: true,
|
||||
}}>
|
||||
<Button let:hover variant={allAuthors ? "gray" : "background"}>
|
||||
<Icon name="avatar-incognito" />
|
||||
<div class="title-counter">
|
||||
All
|
||||
{#if releaseCount !== undefined}
|
||||
<span
|
||||
class="counter"
|
||||
class:selected={allAuthors}
|
||||
class:hover={hover && !allAuthors}>
|
||||
{releaseCount}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
|
||||
<List items={allReleases}>
|
||||
<ReleaseTeaser
|
||||
@@ -181,6 +187,7 @@
|
||||
{baseUrl}
|
||||
{repoId}
|
||||
{allAuthors}
|
||||
{delegateIds}
|
||||
release={item} />
|
||||
</List>
|
||||
|
||||
@@ -195,7 +202,11 @@
|
||||
|
||||
{#if allReleases.length === 0 && !error}
|
||||
<div class="placeholder">
|
||||
<Placeholder iconName="desert" caption="No releases" />
|
||||
<Placeholder
|
||||
iconName="desert"
|
||||
caption={showFilters && !allAuthors
|
||||
? "No releases by delegates"
|
||||
: "No releases"} />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -283,6 +283,7 @@ export type RepoLoadedRoute =
|
||||
repoId: string;
|
||||
releases: Release[];
|
||||
allAuthors: boolean;
|
||||
showFilters: boolean;
|
||||
nodeId: string;
|
||||
nodeAvatarUrl: string | undefined;
|
||||
};
|
||||
@@ -509,8 +510,10 @@ async function loadReleasesView(
|
||||
|
||||
// Fetch releases alongside the repo so the common path stays parallel; the
|
||||
// repo's `meta.releases` then tells us whether a failure is an unsupported
|
||||
// node or a genuine error.
|
||||
const [repo, releasesResult, node] = await Promise.all([
|
||||
// node or a genuine error. The delegate scope is a subset of every author,
|
||||
// so the all-authors view sizes both scopes from its own page, while the
|
||||
// delegate view has to ask for the other scope to size it.
|
||||
const [repo, releasesResult, everyAuthorPage, node] = await Promise.all([
|
||||
api.repo.getByRid(route.repo),
|
||||
api.repo
|
||||
.getAllReleases(route.repo, {
|
||||
@@ -522,23 +525,59 @@ async function loadReleasesView(
|
||||
releases => ({ releases }),
|
||||
(error: unknown) => ({ error }),
|
||||
),
|
||||
allAuthors
|
||||
? undefined
|
||||
: api.repo
|
||||
.getAllReleases(route.repo, {
|
||||
allAuthors: true,
|
||||
page: 0,
|
||||
perPage: RELEASES_PER_PAGE,
|
||||
})
|
||||
// Only the filter rides on this, so a failure here shouldn't take
|
||||
// the page down with it.
|
||||
.catch(() => undefined),
|
||||
api.getNode(),
|
||||
]);
|
||||
|
||||
if (repo.payloads["xyz.radicle.project"].meta.releases === undefined) {
|
||||
const releaseCount = repo.payloads["xyz.radicle.project"].meta.releases;
|
||||
if (releaseCount === undefined) {
|
||||
return releasesNotSupported(route.node);
|
||||
}
|
||||
if ("error" in releasesResult) {
|
||||
throw releasesResult.error;
|
||||
}
|
||||
|
||||
const releases = releasesResult.releases;
|
||||
|
||||
// Offer the author filter only where the two scopes hold different releases,
|
||||
// so a repo whose releases are all by delegates carries no filter with an
|
||||
// identical list behind it, and one with none of its own still leaves a way
|
||||
// through to the others. Both sizes come from a list the endpoint returned:
|
||||
// `meta.releases` counts every release COB, including ones the endpoint
|
||||
// hides such as fully redacted releases, so it would overcount either scope.
|
||||
// A full page means the list may go on, so keep the filter rather than have
|
||||
// it appear or vanish as the user pages, and keep it too if the other scope
|
||||
// failed to load. Decided here so it stays fixed for the life of the route.
|
||||
const delegateIds = new Set(repo.delegates.map(d => d.id));
|
||||
const delegateReleaseCount = allAuthors
|
||||
? releases.filter(r => delegateIds.has(r.creator.id)).length
|
||||
: releases.length;
|
||||
const everyAuthorCount = allAuthors
|
||||
? releases.length
|
||||
: everyAuthorPage?.length;
|
||||
const showFilters =
|
||||
everyAuthorCount === undefined ||
|
||||
everyAuthorCount === RELEASES_PER_PAGE ||
|
||||
delegateReleaseCount !== everyAuthorCount;
|
||||
|
||||
return {
|
||||
resource: "repo.releases",
|
||||
params: {
|
||||
baseUrl: route.node,
|
||||
repoId: route.repo,
|
||||
releases: releasesResult.releases,
|
||||
releases,
|
||||
allAuthors,
|
||||
showFilters,
|
||||
repo,
|
||||
nodeId: node.id,
|
||||
nodeAvatarUrl: node.avatarUrl,
|
||||
|
||||
@@ -76,7 +76,7 @@ test.describe(() => {
|
||||
const { rid } = await createRepo(peer, { name: "no-releases" });
|
||||
|
||||
await page.goto(`${peer.uiUrl()}/${rid}/releases`);
|
||||
await expect(page.getByText("No releases")).toBeVisible();
|
||||
await expect(page.getByText("No releases", { exact: true })).toBeVisible();
|
||||
});
|
||||
|
||||
test("hide fully redacted releases", async ({ page, peer }) => {
|
||||
@@ -97,7 +97,7 @@ test.describe(() => {
|
||||
]);
|
||||
|
||||
await page.goto(`${peer.uiUrl()}/${rid}/releases`);
|
||||
await expect(page.getByText("No releases")).toBeVisible();
|
||||
await expect(page.getByText("No releases", { exact: true })).toBeVisible();
|
||||
|
||||
// The tab counter comes from the repo metadata, which counts every release
|
||||
// COB, redacted or not.
|
||||
|
||||
Reference in New Issue
Block a user