From 023e8a07ea74ea44b04b21b71ad77a5202b127aa Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Thu, 3 Sep 2026 19:11:21 +0100 Subject: [PATCH] web/components: fixups to long RepoHeader Signed-off-by: oppiliappan --- web/.storybook/MockAuth.svelte | 2 +- .../components/repo/RepoHeader.stories.svelte | 38 +++++++- web/src/lib/components/repo/RepoHeader.svelte | 74 ++++++++------- .../components/repo/TopicList.stories.svelte | 37 ++++++++ web/src/lib/components/repo/TopicList.svelte | 90 +++++++++++++++++++ 5 files changed, 200 insertions(+), 41 deletions(-) create mode 100644 web/src/lib/components/repo/TopicList.stories.svelte create mode 100644 web/src/lib/components/repo/TopicList.svelte diff --git a/web/.storybook/MockAuth.svelte b/web/.storybook/MockAuth.svelte index 1788afcb8..6ed7e515a 100644 --- a/web/.storybook/MockAuth.svelte +++ b/web/.storybook/MockAuth.svelte @@ -28,7 +28,7 @@ // land in the form's catch block by default. import { setContext, type Snippet } from "svelte"; import { AUTH_KEY, type Auth } from "$lib/auth.svelte"; - import oauthMetadata from "$lib/oauth-client-metadata.json"; + import oauthMetadata from "$lib/oauth-client-metadata"; interface Props { auth?: MockAuthParam; diff --git a/web/src/lib/components/repo/RepoHeader.stories.svelte b/web/src/lib/components/repo/RepoHeader.stories.svelte index c4f7c87a7..a1b174cfa 100644 --- a/web/src/lib/components/repo/RepoHeader.stories.svelte +++ b/web/src/lib/components/repo/RepoHeader.stories.svelte @@ -5,6 +5,7 @@ import type { RepoInfo } from "$lib/components/repo/types"; type PlayContext = Pick>, "canvas">; + type InteractionPlayContext = Pick>, "canvas" | "userEvent">; // the star control is the same ButtonGroup signed in or out, so it always // stands exactly as tall as the fork group beside it @@ -30,6 +31,26 @@ }; const counts = { stars: 128, issues: 7, pulls: 3, forks: 12 }; + const topicsExpand = async ({ canvas, userEvent }: InteractionPlayContext) => { + const summary = await canvas.findByText(/^\+\d+ more$/); + const details = summary.closest("details")!; + await expect(details.open).toBe(false); + await userEvent.click(summary); + await expect(details.open).toBe(true); + }; + + const manyTopics = Array.from({ length: 20 }, (_, i) => `topic-${i + 1}`); + + const noPlaceholderWhenForked = async ({ canvas }: PlayContext) => { + await canvas.findByText("forked from"); + expect(canvas.queryByText("This repository has no description")).toBe(null); + }; + + const placeholderWhenTrulyEmpty = async ({ canvas }: PlayContext) => { + const placeholder = await canvas.findByText("This repository has no description"); + expect(placeholder).toBeTruthy(); + }; + const signedOutStars = async ({ canvas }: Pick>, "canvas">) => { @@ -50,12 +71,27 @@ - + + + + + + + diff --git a/web/src/lib/components/repo/RepoHeader.svelte b/web/src/lib/components/repo/RepoHeader.svelte index f9884dab0..0e7c4d054 100644 --- a/web/src/lib/components/repo/RepoHeader.svelte +++ b/web/src/lib/components/repo/RepoHeader.svelte @@ -5,7 +5,7 @@ import Avatar from "$lib/components/ui/Avatar.svelte"; import Button from "$lib/components/ui/Button.svelte"; import ButtonGroup from "$lib/components/ui/ButtonGroup.svelte"; - import Tag from "$lib/components/ui/Tag.svelte"; + import TopicList from "$lib/components/repo/TopicList.svelte"; import Pending from "$lib/components/ui/Pending.svelte"; import Bones from "$lib/components/ui/Bones.svelte"; import bonesLoadingprimitivesCount from "$lib/bones/bones-loadingprimitives--count.bones.json"; @@ -96,49 +96,45 @@ {@render repoActions("hidden shrink-0 items-start gap-2 sm:flex")} -
- {#if repo.description} - {repo.description} - {:else} - This repository has no description - {/if} +
+
+ {#if repo.description} + {repo.description} + {/if} + + + {@const resolvedSource = await (source ?? repo.source)} + {#if resolvedSource} + + + {:else if !repo.description && !repo.website && topics.length === 0} + This repository has no description + {/if} + - - {@const resolvedSource = await (source ?? repo.source)} - {#if resolvedSource} - - {/if} - - - {#if repo.website} - - - {/if} +
- {#if topics.length} -
- {#each topics as topic (topic)} - {topic} - {/each} -
- {/if} +
{@render repoActions("mt-2 flex flex-wrap items-start justify-end gap-2 sm:hidden")} diff --git a/web/src/lib/components/repo/TopicList.stories.svelte b/web/src/lib/components/repo/TopicList.stories.svelte new file mode 100644 index 000000000..c8a762986 --- /dev/null +++ b/web/src/lib/components/repo/TopicList.stories.svelte @@ -0,0 +1,37 @@ + + + + + +
+ +
+
+ + +
+ +
+
diff --git a/web/src/lib/components/repo/TopicList.svelte b/web/src/lib/components/repo/TopicList.svelte new file mode 100644 index 000000000..b6542a54a --- /dev/null +++ b/web/src/lib/components/repo/TopicList.svelte @@ -0,0 +1,90 @@ + + +{#if topics.length} +
+ + +
+ {#each topics.slice(0, visibleCount) as topic (topic)} + {topic} + {/each} + {#if hiddenCount > 0} +
+ +{hiddenCount} more +
+ {#each topics.slice(visibleCount) as topic (topic)} + {topic} + {/each} +
+
+ {/if} +
+
+{/if} + + -- 2.51.2