fix(webui): re-derive the task status filter when the served catalog lands
This commit is contained in:
5 files changed
+123
-43
No files matched your search
@@ -1,36 +1,3 @@
|
||||
<script lang="ts">
|
||||
import { attentionStatusIds, statusIds } from "@/lib/task-meta";
|
||||
|
||||
// The vocabulary is the server catalog, not a hand-synced copy: the "needs
|
||||
// you" grouping and the set of known statuses come straight from task-meta so
|
||||
// a status added on the backend shows up here without a frontend change.
|
||||
// "needs_you" is a UI pseudo-status (work waiting on a human), so it is
|
||||
// prepended rather than stored in the catalog.
|
||||
//
|
||||
// Both are read at call time rather than captured at import. The catalog
|
||||
// arrives after this module loads, so module-level constants here would freeze
|
||||
// the defaults for the life of the process -- which is what they did, leaving
|
||||
// the task filter unable to see a served status no matter when it landed.
|
||||
export function taskStatuses(): Set<string> {
|
||||
return new Set(["needs_you", ...statusIds()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A ?status= value, kept only when the catalog knows it: the query string is
|
||||
* operator input, and an unknown status would filter the whole board away with
|
||||
* no control showing why.
|
||||
*/
|
||||
export function initialTaskFilter(requested: string | null | undefined): string {
|
||||
return requested && taskStatuses().has(requested) ? requested : "";
|
||||
}
|
||||
|
||||
export function taskMatchesStatus(task: { status?: string }, status: string): boolean {
|
||||
if (!status) return true;
|
||||
if (status === "needs_you") return attentionStatusIds().has(task.status ?? "");
|
||||
return task.status === status;
|
||||
}
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
|
||||
|
||||
@@ -19,8 +19,10 @@ import { useRoute, useRouter } from "vue-router";
|
||||
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { api } from "@/lib/api";
|
||||
import { statusList } from "@/lib/task-meta";
|
||||
import { useLiveResource } from "@/stores/live-updates";
|
||||
import TaskFilters, { initialTaskFilter, taskMatchesStatus } from "./TaskFilters.vue";
|
||||
import TaskFilters from "./TaskFilters.vue";
|
||||
import { initialTaskFilter, taskMatchesStatus } from "./task-filter";
|
||||
import type { Task } from "./TaskRow.vue";
|
||||
import TaskTable from "./TaskTable.vue";
|
||||
import TasksState from "./TasksState.vue";
|
||||
@@ -50,14 +52,14 @@ const requestedTaskId = computed(() => {
|
||||
|
||||
// The filter follows the URL as well as writing to it: a dashboard link or a
|
||||
// back-button step has to move the control, not just load the page behind it.
|
||||
const status = ref(initialTaskFilter(statusQuery.value));
|
||||
watch(statusQuery, (value) => {
|
||||
status.value = initialTaskFilter(value);
|
||||
});
|
||||
// It is derived from the query rather than captured from it, because the
|
||||
// served catalog lands after this page sets up -- a drop to the freeze-dried
|
||||
// defaults here would drop a shared link to a status the server serves.
|
||||
const status = computed(() => initialTaskFilter(statusQuery.value, statusList()));
|
||||
|
||||
const visible = computed(() =>
|
||||
(tasks.value ?? []).filter((task) => {
|
||||
if (!taskMatchesStatus(task, status.value)) return false;
|
||||
if (!taskMatchesStatus(task, status.value, statusList())) return false;
|
||||
const needle = search.value.trim().toLowerCase();
|
||||
if (!needle) return true;
|
||||
return `${task.title ?? ""} ${task.repo ?? ""}`.toLowerCase().includes(needle);
|
||||
@@ -93,12 +95,13 @@ useLiveResource("tasks", () => void load(), 500);
|
||||
onMounted(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. An empty status is
|
||||
// list: the table keeps its identity and only its rows move. The query is the
|
||||
// only filter state -- the control re-derives from it -- and an empty status is
|
||||
// dropped from the query rather than written as `?status=`.
|
||||
function setStatus(value: string) {
|
||||
status.value = initialTaskFilter(value);
|
||||
const requested = initialTaskFilter(value, statusList());
|
||||
const query = { ...route.query };
|
||||
if (status.value) query.status = status.value;
|
||||
if (requested) query.status = requested;
|
||||
else delete query.status;
|
||||
void router.replace({ query });
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// The status vocabulary the board filters by, as pure functions of the served
|
||||
// catalog. The catalog is an argument rather than a module-level import: it
|
||||
// arrives after the app boots, so anything that captured the freeze-dried
|
||||
// defaults at import or at setup kept them for the life of the page -- which
|
||||
// is how a shared link to a served-only status filtered nothing -- and there
|
||||
// is no way to test that capture without being able to replace the catalog.
|
||||
// A caller that passes the catalog from inside a `computed` re-derives when
|
||||
// `/api/task-meta` lands.
|
||||
import type { StatusMeta } from "@/lib/task-meta";
|
||||
|
||||
// The vocabulary is the server catalog, not a hand-synced copy: the set of
|
||||
// known statuses comes straight from what the server serves, so a status added
|
||||
// on the backend shows up here without a frontend change. "needs_you" is a UI
|
||||
// pseudo-status (work waiting on a human), so it is prepended rather than
|
||||
// stored in the catalog.
|
||||
export function taskStatuses(catalog: StatusMeta[]): Set<string> {
|
||||
return new Set(["needs_you", ...catalog.map((status) => status.id)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A ?status= value, kept only when the catalog knows it: the query string is
|
||||
* operator input, and an unknown status would filter the whole board away with
|
||||
* no control showing why.
|
||||
*/
|
||||
export function initialTaskFilter(requested: string | null | undefined, catalog: StatusMeta[]): string {
|
||||
return requested && taskStatuses(catalog).has(requested) ? requested : "";
|
||||
}
|
||||
|
||||
/** 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