mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 06:10:44 +08:00
Implement issue and patch list fuzzy finder
This commit is contained in:
@@ -4,7 +4,10 @@
|
||||
import type { IssueStatus } from "./router";
|
||||
import type { RepoInfo } from "@bindings/repo/RepoInfo";
|
||||
|
||||
import fuzzysort from "fuzzysort";
|
||||
|
||||
import * as router from "@app/lib/router";
|
||||
import { modifierKey } from "@app/lib/utils";
|
||||
|
||||
import Layout from "./Layout.svelte";
|
||||
|
||||
@@ -15,6 +18,7 @@
|
||||
import IssueTeaser from "@app/components/IssueTeaser.svelte";
|
||||
import IssuesSecondColumn from "@app/components/IssuesSecondColumn.svelte";
|
||||
import Sidebar from "@app/components/Sidebar.svelte";
|
||||
import TextInput from "@app/components/TextInput.svelte";
|
||||
|
||||
interface Props {
|
||||
repo: RepoInfo;
|
||||
@@ -23,7 +27,35 @@
|
||||
status: IssueStatus;
|
||||
}
|
||||
|
||||
const { repo, issues, config, status }: Props = $props();
|
||||
/* eslint-disable prefer-const */
|
||||
let { repo, issues, config, status }: Props = $props();
|
||||
/* eslint-enable prefer-const */
|
||||
|
||||
let searchInput = $state("");
|
||||
|
||||
const searchableIssues = $derived(
|
||||
issues
|
||||
.flatMap(i => {
|
||||
return {
|
||||
issue: i,
|
||||
labels: i.labels.join(" "),
|
||||
assignees: i.assignees
|
||||
.map(a => {
|
||||
return a.alias ?? "";
|
||||
})
|
||||
.join(" "),
|
||||
author: i.author.alias ?? "",
|
||||
};
|
||||
})
|
||||
.filter((item): item is NonNullable<typeof item> => item !== undefined),
|
||||
);
|
||||
|
||||
const searchResults = $derived(
|
||||
fuzzysort.go(searchInput, searchableIssues, {
|
||||
keys: ["issue.title", "labels", "assignees", "author"],
|
||||
all: true,
|
||||
}),
|
||||
);
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -40,7 +72,6 @@
|
||||
font-size: var(--font-size-medium);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
min-height: 40px;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
@@ -65,24 +96,55 @@
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<div>Issues</div>
|
||||
<div class="txt-regular txt-semibold">
|
||||
<Button
|
||||
variant="secondary"
|
||||
onclick={() => {
|
||||
void router.push({
|
||||
resource: "repo.createIssue",
|
||||
status,
|
||||
rid: repo.rid,
|
||||
});
|
||||
}}>
|
||||
<Icon name="plus" />New
|
||||
</Button>
|
||||
<div class="global-flex" style:margin-left="auto">
|
||||
<TextInput
|
||||
onSubmit={async () => {
|
||||
if (searchResults.length === 1) {
|
||||
await router.push({
|
||||
resource: "repo.issue",
|
||||
rid: repo.rid,
|
||||
issue: searchResults[0].obj.issue.id,
|
||||
status,
|
||||
});
|
||||
}
|
||||
}}
|
||||
onDismiss={() => {
|
||||
searchInput = "";
|
||||
}}
|
||||
placeholder={`Fuzzy filter issues ${modifierKey()} + f`}
|
||||
keyShortcuts="ctrl+f"
|
||||
bind:value={searchInput}>
|
||||
{#snippet left()}
|
||||
<div
|
||||
style:color="var(--color-foreground-dim)"
|
||||
style:padding-left="0.5rem">
|
||||
<Icon name="filter" />
|
||||
</div>
|
||||
{/snippet}
|
||||
</TextInput>
|
||||
<div class="txt-regular txt-semibold">
|
||||
<Button
|
||||
variant="secondary"
|
||||
onclick={() => {
|
||||
void router.push({
|
||||
resource: "repo.createIssue",
|
||||
status,
|
||||
rid: repo.rid,
|
||||
});
|
||||
}}>
|
||||
<Icon name="plus" />New
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="list">
|
||||
{#each issues as issue}
|
||||
<IssueTeaser {issue} rid={repo.rid} {status} />
|
||||
{#each searchResults as result}
|
||||
<IssueTeaser
|
||||
focussed={searchResults.length === 1 && searchInput !== ""}
|
||||
issue={result.obj.issue}
|
||||
rid={repo.rid}
|
||||
{status} />
|
||||
{/each}
|
||||
|
||||
{#if issues.length === 0}
|
||||
|
||||
@@ -2,18 +2,23 @@
|
||||
import type { Config } from "@bindings/config/Config";
|
||||
import type { PaginatedQuery } from "@bindings/cob/PaginatedQuery";
|
||||
import type { Patch } from "@bindings/cob/patch/Patch";
|
||||
import type { PatchStatus } from "./router";
|
||||
import { DEFAULT_TAKE, type PatchStatus } from "./router";
|
||||
import type { RepoInfo } from "@bindings/repo/RepoInfo";
|
||||
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
import fuzzysort from "fuzzysort";
|
||||
|
||||
import * as router from "@app/lib/router";
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
import { modifierKey } from "@app/lib/utils";
|
||||
|
||||
import Border from "@app/components/Border.svelte";
|
||||
import CopyableId from "@app/components/CopyableId.svelte";
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
import Layout from "./Layout.svelte";
|
||||
import PatchTeaser from "@app/components/PatchTeaser.svelte";
|
||||
import PatchesSecondColumn from "@app/components/PatchesSecondColumn.svelte";
|
||||
import Sidebar from "@app/components/Sidebar.svelte";
|
||||
import Border from "@app/components/Border.svelte";
|
||||
import TextInput from "@app/components/TextInput.svelte";
|
||||
|
||||
interface Props {
|
||||
repo: RepoInfo;
|
||||
@@ -24,6 +29,8 @@
|
||||
|
||||
const { repo, patches, config, status }: Props = $props();
|
||||
|
||||
let loading: boolean = $state(false);
|
||||
|
||||
let items = $state(patches.content);
|
||||
let cursor = patches.cursor;
|
||||
let more = patches.more;
|
||||
@@ -34,22 +41,53 @@
|
||||
more = patches.more;
|
||||
});
|
||||
|
||||
async function loadMoreContent() {
|
||||
async function loadMoreContent(all: boolean = false) {
|
||||
if (more) {
|
||||
const p = await invoke<PaginatedQuery<Patch[]>>("list_patches", {
|
||||
rid: repo.rid,
|
||||
skip: cursor + 20,
|
||||
skip: cursor + DEFAULT_TAKE,
|
||||
status,
|
||||
take: 20,
|
||||
take: all ? undefined : DEFAULT_TAKE,
|
||||
});
|
||||
|
||||
cursor = p.cursor;
|
||||
more = p.more;
|
||||
items = [...items, ...p.content];
|
||||
|
||||
if (all) {
|
||||
items = p.content;
|
||||
} else {
|
||||
items = [...items, ...p.content];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const project = $derived(repo.payloads["xyz.radicle.project"]!);
|
||||
|
||||
let searchInput = $state("");
|
||||
|
||||
const searchablePatches = $derived(
|
||||
items
|
||||
.flatMap(i => {
|
||||
return {
|
||||
patch: i,
|
||||
labels: i.labels.join(" "),
|
||||
assignees: i.assignees
|
||||
.map(a => {
|
||||
return a.alias ?? "";
|
||||
})
|
||||
.join(" "),
|
||||
author: i.author.alias ?? "",
|
||||
};
|
||||
})
|
||||
.filter((item): item is NonNullable<typeof item> => item !== undefined),
|
||||
);
|
||||
|
||||
const searchResults = $derived(
|
||||
fuzzysort.go(searchInput, searchablePatches, {
|
||||
keys: ["patch.title", "labels", "assignees", "author"],
|
||||
all: true,
|
||||
}),
|
||||
);
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -89,11 +127,57 @@
|
||||
{/snippet}
|
||||
|
||||
<div class="container">
|
||||
<div class="header">Patches</div>
|
||||
<div class="header">
|
||||
Patches
|
||||
|
||||
<div class="global-flex" style:margin-left="auto">
|
||||
<TextInput
|
||||
onFocus={async () => {
|
||||
try {
|
||||
loading = true;
|
||||
// Load all patches.
|
||||
await loadMoreContent(true);
|
||||
} catch (e) {
|
||||
console.error("Loading all patches failed: ", e);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}}
|
||||
onSubmit={async () => {
|
||||
if (searchResults.length === 1) {
|
||||
await router.push({
|
||||
patch: searchResults[0].obj.patch.id,
|
||||
resource: "repo.patch",
|
||||
reviewId: undefined,
|
||||
rid: repo.rid,
|
||||
status,
|
||||
});
|
||||
}
|
||||
}}
|
||||
onDismiss={() => {
|
||||
searchInput = "";
|
||||
}}
|
||||
placeholder={`Fuzzy filter issues ${modifierKey()} + f`}
|
||||
keyShortcuts="ctrl+f"
|
||||
bind:value={searchInput}>
|
||||
{#snippet left()}
|
||||
<div
|
||||
style:color="var(--color-foreground-dim)"
|
||||
style:padding-left="0.5rem">
|
||||
<Icon name={loading ? "clock" : "filter"} />
|
||||
</div>
|
||||
{/snippet}
|
||||
</TextInput>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="list">
|
||||
{#each items as patch}
|
||||
<PatchTeaser rid={repo.rid} {patch} {status} />
|
||||
{#each searchResults as result}
|
||||
<PatchTeaser
|
||||
focussed={searchResults.length === 1 && searchInput !== ""}
|
||||
patch={result.obj.patch}
|
||||
rid={repo.rid}
|
||||
{status} />
|
||||
{/each}
|
||||
|
||||
{#if patches.content.length === 0}
|
||||
|
||||
@@ -15,6 +15,8 @@ import { unreachable } from "@app/lib/utils";
|
||||
|
||||
export type IssueStatus = "all" | Issue["state"]["status"];
|
||||
|
||||
export const DEFAULT_TAKE = 20;
|
||||
|
||||
export interface RepoIssueRoute {
|
||||
resource: "repo.issue";
|
||||
rid: string;
|
||||
@@ -132,6 +134,7 @@ export async function loadPatch(
|
||||
invoke<PaginatedQuery<Patch[]>>("list_patches", {
|
||||
rid: route.rid,
|
||||
status: route.status,
|
||||
take: DEFAULT_TAKE,
|
||||
}),
|
||||
invoke<Patch>("patch_by_id", {
|
||||
rid: route.rid,
|
||||
@@ -178,6 +181,7 @@ export async function loadPatches(
|
||||
invoke<PaginatedQuery<Patch[]>>("list_patches", {
|
||||
rid: route.rid,
|
||||
status: route.status,
|
||||
take: DEFAULT_TAKE,
|
||||
}),
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user