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:
Sebastian Martinez
2023-11-23 09:57:35 +01:00
committed by Rūdolfs Ošiņš
parent e172aac1af
commit b8408db4f1
3 changed files with 13 additions and 9 deletions
+2 -1
View File
@@ -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}>
+1 -1
View File
@@ -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),
);