From a173f458ce61915ca7c33da4a1511900ad08bcf0 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Fri, 14 Jun 2024 11:38:55 +0200 Subject: [PATCH] Overhaul peer and branch selector --- package-lock.json | 6 + package.json | 1 + public/index.css | 5 + .../DropdownList/DropdownListItem.svelte | 2 + src/lib/search.ts | 21 ++ src/views/projects/History.svelte | 32 +-- src/views/projects/Source.svelte | 47 +--- .../projects/Source/BranchSelector.svelte | 100 ------- src/views/projects/Source/Header.svelte | 37 ++- src/views/projects/Source/PeerSelector.svelte | 130 --------- .../projects/Source/SourceSelector.svelte | 261 ++++++++++++++++++ .../Source/SourceSelector/PeerItem.svelte | 94 +++++++ .../projects/components/CommitButton.svelte | 2 +- src/views/projects/router.ts | 11 +- 14 files changed, 427 insertions(+), 322 deletions(-) create mode 100644 src/lib/search.ts delete mode 100644 src/views/projects/Source/BranchSelector.svelte delete mode 100644 src/views/projects/Source/PeerSelector.svelte create mode 100644 src/views/projects/Source/SourceSelector.svelte create mode 100644 src/views/projects/Source/SourceSelector/PeerItem.svelte diff --git a/package-lock.json b/package-lock.json index a6118c7e39..2611f9b130 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "hasInstallScript": true, "dependencies": { "@efstajas/svelte-stored-writable": "^0.2.0", + "@leeoniya/ufuzzy": "^1.0.14", "@radicle/gray-matter": "4.1.0", "@wooorm/starry-night": "^3.3.0", "async-mutex": "^0.5.0", @@ -693,6 +694,11 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@leeoniya/ufuzzy": { + "version": "1.0.14", + "resolved": "https://registry.npmjs.org/@leeoniya/ufuzzy/-/ufuzzy-1.0.14.tgz", + "integrity": "sha512-/xF4baYuCQMo+L/fMSUrZnibcu0BquEGnbxfVPiZhs/NbJeKj4c/UmFpQzW9Us0w45ui/yYW3vyaqawhNYsTzA==" + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", diff --git a/package.json b/package.json index af27987aa9..d8dc660c3d 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ }, "dependencies": { "@efstajas/svelte-stored-writable": "^0.2.0", + "@leeoniya/ufuzzy": "^1.0.14", "@radicle/gray-matter": "4.1.0", "@wooorm/starry-night": "^3.3.0", "async-mutex": "^0.5.0", diff --git a/public/index.css b/public/index.css index 9ab8efbd77..f6101c2720 100644 --- a/public/index.css +++ b/public/index.css @@ -96,6 +96,11 @@ pre { height: 100%; background-color: var(--color-fill-ghost); } +.global-flex-item { + display: flex; + gap: 0.5rem; + align-items: center; +} /* Breakpoints diff --git a/src/components/DropdownList/DropdownListItem.svelte b/src/components/DropdownList/DropdownListItem.svelte index a670d74b54..a2a3d0e9e2 100644 --- a/src/components/DropdownList/DropdownListItem.svelte +++ b/src/components/DropdownList/DropdownListItem.svelte @@ -2,6 +2,7 @@ export let selected: boolean; export let disabled: boolean = false; export let title: string | undefined = undefined; + export let style: string | undefined = undefined; - -
- {#if selectedBranch} - - - - - - closeFocused()}> - - -
- {item.name} -
- {#if onCanonical} - - Canonical - - {/if} -
- -
- - closeFocused()}> - - -
- {project.defaultBranch} -
-
- -
-
-
- {/if} - -
- -
diff --git a/src/views/projects/Source/Header.svelte b/src/views/projects/Source/Header.svelte index 81e0d4e4d8..afb5e659f3 100644 --- a/src/views/projects/Source/Header.svelte +++ b/src/views/projects/Source/Header.svelte @@ -1,26 +1,24 @@
- {#if peers.length > 0} - - {/if} - - +
diff --git a/src/views/projects/Source/PeerSelector.svelte b/src/views/projects/Source/PeerSelector.svelte deleted file mode 100644 index fd9160ad2a..0000000000 --- a/src/views/projects/Source/PeerSelector.svelte +++ /dev/null @@ -1,130 +0,0 @@ - - - - -
- - - - - - closeFocused()} route={item.route}> - -
- -
- - {item.remote.alias || formatNodeId(item.remote.id)} - - {#if $httpdStore.state !== "stopped" && item.remote.id === $httpdStore.node.id} - - You - - {/if} - {#if item.remote.delegate} - - - Delegate - - {/if} -
- -
-
-
- {#if selectedPeer} - - - - {/if} -
diff --git a/src/views/projects/Source/SourceSelector.svelte b/src/views/projects/Source/SourceSelector.svelte new file mode 100644 index 0000000000..2cc98221cd --- /dev/null +++ b/src/views/projects/Source/SourceSelector.svelte @@ -0,0 +1,261 @@ + + + + +
+ + + + + + {#if selectedPeer} + + + + {/if} +
diff --git a/src/views/projects/Source/SourceSelector/PeerItem.svelte b/src/views/projects/Source/SourceSelector/PeerItem.svelte new file mode 100644 index 0000000000..22714a1fe8 --- /dev/null +++ b/src/views/projects/Source/SourceSelector/PeerItem.svelte @@ -0,0 +1,94 @@ + + + + +
+
+ (expanded = !expanded)}> + + +
+ +
+ + {peer.remote.alias || formatNodeId(peer.remote.id)} + + {#if peer.remote.delegate} + + + Delegate + + {/if} +
+
+{#if expanded} + {#each Object.entries(peer.remote.heads) as [name, head]} + closeFocused()}> + + replace({ + resource: "project.source", + peer: peer.remote.id, + revision: name, + project: projectId, + node, + })} + style={`${subgridStyle} padding-left: 2.3rem; gap: inherit;`}> +
+ {name} +
+
+ + {formatCommit(head)} + +
+
+ + {/each} +{/if} diff --git a/src/views/projects/components/CommitButton.svelte b/src/views/projects/components/CommitButton.svelte index d6b851e3a8..648c0f6e1e 100644 --- a/src/views/projects/components/CommitButton.svelte +++ b/src/views/projects/components/CommitButton.svelte @@ -43,7 +43,7 @@
{commitShortId}
- + {commit.summary}
diff --git a/src/views/projects/router.ts b/src/views/projects/router.ts index 27cf29af9d..a01e80252e 100644 --- a/src/views/projects/router.ts +++ b/src/views/projects/router.ts @@ -438,7 +438,9 @@ async function loadTreeView( isLocalNodeSeeding(route), ]); - let branchMap: Record; + let branchMap: Record = { + [project.defaultBranch]: project.head, + }; if (route.peer) { const peer = peers.find(peer => peer.id === route.peer); if (!peer) { @@ -449,15 +451,10 @@ async function loadTreeView( } else { branchMap = peer.heads; } - } else { - branchMap = { [project.defaultBranch]: project.head }; } if (route.route) { - const { revision, path } = detectRevision( - route.route, - branchMap || { [project.defaultBranch]: project.head }, - ); + const { revision, path } = detectRevision(route.route, branchMap); route.revision = revision; route.path = path; }