feat(webui): page and filter the task list on the server
This commit is contained in:
15 files changed
+550
-384
No files matched your search
@@ -147,6 +147,18 @@ export const api = {
|
||||
request<void>("/api/access/policies", { method: "DELETE", body: policy, parse: false }),
|
||||
summary: <T = unknown>() => request<T>("/api/summary"),
|
||||
tasks: <T = unknown>() => request<T>("/api/tasks"),
|
||||
// taskPage reads one page of the board; next is the cursor for the page
|
||||
// after it, or null when this page was the last.
|
||||
taskPage: async <T = unknown>(params: QueryParams) => {
|
||||
const res = await send("/api/tasks" + qs(params), {
|
||||
headers: { Accept: "application/json" },
|
||||
signal: AbortSignal.timeout(DEFAULT_TIMEOUT_MS),
|
||||
});
|
||||
return {
|
||||
tasks: (await res.json()) as T[],
|
||||
next: res.headers.get("X-Next-Cursor"),
|
||||
};
|
||||
},
|
||||
taskMeta: <T = unknown>() => request<T>("/api/task-meta"),
|
||||
task: <T = unknown>(id: string) =>
|
||||
request<T>(`/api/tasks/${encodeURIComponent(id)}`),
|
||||
|
||||
@@ -27,15 +27,12 @@ import {
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { api } from "@/lib/api";
|
||||
import { statusList } from "@/lib/task-meta";
|
||||
import { useLiveResource } from "@/stores/live-updates";
|
||||
import TaskFilters from "./TaskFilters.vue";
|
||||
import {
|
||||
boardStatus,
|
||||
initialTaskFilter,
|
||||
taskMatchesStatus,
|
||||
} from "./task-filter";
|
||||
import { boardStatus, initialTaskFilter } from "./task-filter";
|
||||
import type { Task } from "./TaskRow.vue";
|
||||
import TaskTable from "./TaskTable.vue";
|
||||
import TasksState from "./TasksState.vue";
|
||||
@@ -53,6 +50,9 @@ const router = useRouter();
|
||||
// null means loading: an empty list and a list that has not arrived are
|
||||
// different states, and only one of them is worth a spinner.
|
||||
const tasks = ref<Task[] | null>(null);
|
||||
const next = ref<string | null>(null);
|
||||
const loadingMore = ref(false);
|
||||
const summary = ref<{ statuses?: Record<string, number>; needs_you?: number } | null>(null);
|
||||
const error = ref<string | null>(null);
|
||||
const search = ref("");
|
||||
|
||||
@@ -73,9 +73,9 @@ const requestedTaskId = computed(() => {
|
||||
// serves.
|
||||
const status = computed(() => boardStatus(statusQuery.value, statusList()));
|
||||
|
||||
// The server filters by status; search narrows the rows already loaded.
|
||||
const visible = computed(() =>
|
||||
(tasks.value ?? []).filter((task) => {
|
||||
if (!taskMatchesStatus(task, status.value, statusList())) return false;
|
||||
const needle = search.value.trim().toLowerCase();
|
||||
if (!needle) return true;
|
||||
return `${task.title ?? ""} ${task.repo ?? ""}`
|
||||
@@ -99,18 +99,51 @@ const state = computed<"loading" | "error" | "empty" | "no-match">(() => {
|
||||
return "no-match";
|
||||
});
|
||||
|
||||
const PAGE = 100;
|
||||
|
||||
// load re-reads the board from the top, as many rows as are showing, so a live
|
||||
// update or a row action does not collapse pages the operator loaded.
|
||||
async function load() {
|
||||
error.value = null;
|
||||
const limit = Math.min(Math.max(tasks.value?.length ?? 0, PAGE), 500);
|
||||
try {
|
||||
tasks.value = await api.tasks<Task[]>();
|
||||
const [page, counts] = await Promise.all([
|
||||
api.taskPage<Task>({ status: status.value || undefined, limit }),
|
||||
api.summary<{ statuses?: Record<string, number>; needs_you?: number }>(),
|
||||
]);
|
||||
tasks.value = page.tasks;
|
||||
next.value = page.next;
|
||||
summary.value = counts;
|
||||
} catch (err) {
|
||||
error.value = String((err as Error).message || err);
|
||||
tasks.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMore() {
|
||||
if (!next.value || loadingMore.value) return;
|
||||
loadingMore.value = true;
|
||||
try {
|
||||
const page = await api.taskPage<Task>({
|
||||
status: status.value || undefined,
|
||||
limit: PAGE,
|
||||
cursor: next.value,
|
||||
});
|
||||
tasks.value = [...(tasks.value ?? []), ...page.tasks];
|
||||
next.value = page.next;
|
||||
} catch (err) {
|
||||
error.value = String((err as Error).message || err);
|
||||
} finally {
|
||||
loadingMore.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
useLiveResource("tasks", () => void load(), 500);
|
||||
onMounted(load);
|
||||
watch(status, () => {
|
||||
tasks.value = null;
|
||||
void load();
|
||||
});
|
||||
|
||||
// A filter change is a query-only route change, so it must not remount the
|
||||
// list: the table keeps its identity and only its rows move. The query is the
|
||||
@@ -171,7 +204,7 @@ async function reveal(id: number) {
|
||||
</Card>
|
||||
|
||||
<template v-else>
|
||||
<TasksSummary v-if="tasks" :tasks="tasks" />
|
||||
<TasksSummary v-if="summary" :summary="summary" />
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
@@ -196,6 +229,14 @@ async function reveal(id: number) {
|
||||
<TasksState :kind="state" @clear="clearFilters" />
|
||||
</template>
|
||||
</TaskTable>
|
||||
<Button
|
||||
v-if="next"
|
||||
variant="outline"
|
||||
class="self-center"
|
||||
:disabled="loadingMore"
|
||||
@click="loadMore"
|
||||
>Load more</Button
|
||||
>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
@@ -3,41 +3,28 @@ import { computed } from "vue";
|
||||
|
||||
import StatTile from "@/base/StatTile.vue";
|
||||
import { delivered } from "@/lib/delivered";
|
||||
import { attentionStatusIds } from "@/lib/task-meta";
|
||||
import type { Task } from "./TaskRow.vue";
|
||||
|
||||
/**
|
||||
* The four numbers that say what the board holds, counted from the tasks the
|
||||
* page already has rather than from an aggregate endpoint: the same list feeds
|
||||
* the table, so a tile and a row can never disagree.
|
||||
* The four numbers that say what the board holds, counted by the server over
|
||||
* every task: the table pages, so counting its rows would count one page.
|
||||
*/
|
||||
const props = defineProps<{ tasks: Task[] }>();
|
||||
const props = defineProps<{
|
||||
summary: { statuses?: Record<string, number>; needs_you?: number };
|
||||
}>();
|
||||
|
||||
const counts = computed(() => {
|
||||
const tally: Record<string, number> = {};
|
||||
for (const task of props.tasks) {
|
||||
const status = task.status ?? "";
|
||||
tally[status] = (tally[status] ?? 0) + 1;
|
||||
}
|
||||
return tally;
|
||||
});
|
||||
const counts = computed(() => props.summary.statuses ?? {});
|
||||
|
||||
const total = computed(() => props.tasks.length);
|
||||
const total = computed(() =>
|
||||
Object.values(counts.value).reduce((sum, n) => sum + n, 0),
|
||||
);
|
||||
const working = computed(() => counts.value.running ?? 0);
|
||||
// Delivered counts everything whose work is out of archied's hands: merged,
|
||||
// in review, or finished with no change to make (completed, which is how a
|
||||
// no-change build and a no-code triage end).
|
||||
const done = computed(() => delivered(counts.value) + (counts.value.pr_open ?? 0));
|
||||
|
||||
// "Needs you" is the server's grouping, not a local pair of ids: the same set
|
||||
// backs the ?status=needs_you filter, so the tile and the filter cannot drift.
|
||||
const needsYou = computed(() => {
|
||||
const attention = attentionStatusIds();
|
||||
return Object.entries(counts.value).reduce(
|
||||
(sum, [status, n]) => (attention.has(status) ? sum + n : sum),
|
||||
0,
|
||||
);
|
||||
});
|
||||
// "Needs you" is grouped by the server, the same set ?status=needs_you filters.
|
||||
const needsYou = computed(() => props.summary.needs_you ?? 0);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -50,17 +50,3 @@ export function initialTaskFilter(
|
||||
export function boardStatus(query: string, catalog: StatusMeta[]): string {
|
||||
return initialTaskFilter(query, catalog);
|
||||
}
|
||||
|
||||
/** taskMatchesStatus reports whether a task survives the status filter. */
|
||||
export function taskMatchesStatus(
|
||||
task: { status?: string },
|
||||
status: string,
|
||||
catalog: StatusMeta[],
|
||||
): boolean {
|
||||
if (!status) return true;
|
||||
if (status === "needs_you")
|
||||
return catalog.some(
|
||||
(entry) => entry.needs_you && entry.id === (task.status ?? ""),
|
||||
);
|
||||
return task.status === status;
|
||||
}
|
||||
Reference in new issue
Block a user