mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-28 17:50:28 +08:00
Improve the Branch Selector
We now also let people select branches if they only have one branch. Renamed also some variables to make it clearer what they represent.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
type T = $$Generic;
|
||||
|
||||
export let items: T[];
|
||||
export let styleDropdownMinWidth: string | undefined = undefined;
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -20,7 +21,7 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="dropdown">
|
||||
<div class="dropdown" style:min-width={styleDropdownMinWidth}>
|
||||
{#each items as item}
|
||||
<div class="dropdown-item">
|
||||
<slot name="item" {item} />
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
export let selectedBranch: string | undefined;
|
||||
export let selectedCommitId: string;
|
||||
|
||||
$: hideDropdown = branches.length <= 1;
|
||||
$: onCanonicalBranch = branches.length === 0;
|
||||
$: selectedCommitShortId = utils.formatCommit(selectedCommitId);
|
||||
</script>
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
<div class="branch">
|
||||
{#if selectedBranch}
|
||||
{#if hideDropdown}
|
||||
{#if onCanonicalBranch}
|
||||
<HoverPopover popoverPositionLeft="0" popoverPositionTop="0.5rem">
|
||||
<Button
|
||||
ariaLabel="canonical-branch"
|
||||
@@ -73,15 +73,18 @@
|
||||
on:click={toggle}
|
||||
slot="toggle"
|
||||
styleBorderRadius="var(--border-radius-tiny) 0 0 var(--border-radius-tiny)"
|
||||
title="Change branch"
|
||||
disabled={hideDropdown}>
|
||||
title="Change branch">
|
||||
<IconSmall name="branch" />
|
||||
<div class="identifier">{selectedBranch}</div>
|
||||
<IconSmall
|
||||
name={hideDropdown && expanded ? "chevron-up" : "chevron-down"} />
|
||||
{#if !onCanonicalBranch}
|
||||
<IconSmall name={expanded ? "chevron-up" : "chevron-down"} />
|
||||
{/if}
|
||||
</Button>
|
||||
|
||||
<DropdownList slot="popover" items={branches}>
|
||||
<DropdownList
|
||||
slot="popover"
|
||||
styleDropdownMinWidth="12.5rem"
|
||||
items={branches}>
|
||||
<svelte:fragment slot="item" let:item>
|
||||
<Link route={item.route} on:afterNavigate={() => closeFocused()}>
|
||||
<DropdownListItem selected={item.name === selectedBranch}>
|
||||
|
||||
@@ -352,7 +352,7 @@ test("peer and branch switching", async ({ page }) => {
|
||||
|
||||
// Default `main` branch.
|
||||
{
|
||||
await expect(page.getByLabel("canonical-branch")).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: "main" })).toBeVisible();
|
||||
await expect(page.getByTitle("Current HEAD")).toHaveText(
|
||||
bobHead.substring(0, 7),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user