Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+133
-23
@@ -5,41 +5,61 @@
|
||||
// standalone host.
|
||||
//
|
||||
// Interim-UI (AD-28): renders the ~/ui preview screen TasksListPage; the loader
|
||||
// owns navigation for preset/filter changes (server-side). Final Subframe optics
|
||||
// land as a tracked design-nachzug once David's D-P4 delta ships.
|
||||
// owns navigation for preset/filter changes (server-side) and provides the assignee
|
||||
// options for the "Neue Aufgabe" dialog (which posts to the tasks/new action). Final
|
||||
// Subframe optics land as a tracked design-nachzug once David's D-P4 delta ships.
|
||||
|
||||
import { type LoaderFunctionArgs, useLoaderData, useNavigate } from "react-router";
|
||||
import { type ActionFunctionArgs, type LoaderFunctionArgs, redirect, useLoaderData, useNavigate, useSubmit } from "react-router";
|
||||
import {
|
||||
buildTaskListVM,
|
||||
taskEntityLabelKey,
|
||||
taskPriorityKey,
|
||||
taskSourceKey,
|
||||
taskStatusKey,
|
||||
type TaskListPreset,
|
||||
type TaskListRow,
|
||||
type TaskListVM,
|
||||
} from "@hivegrid/view-models";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
import { loadTasksContext, notFoundResponse, requireTasksPermission } from "~/utils/integrations/taskAccess.server";
|
||||
import { badRequestResponse, loadTasksContext, notFoundResponse, requireTasksPermission } from "~/utils/integrations/taskAccess.server";
|
||||
import {
|
||||
listAssignableGroups,
|
||||
listAssignableUsers,
|
||||
listTasksForBrowser,
|
||||
resolveGroupLabels,
|
||||
resolveUserLabels,
|
||||
updateTask,
|
||||
type LabeledOption,
|
||||
type TaskPriority,
|
||||
type TaskRow,
|
||||
type TaskStatus,
|
||||
} from "~/utils/integrations/taskService.server";
|
||||
import { tasksDetailPath, tasksNewPath } from "~/utils/integrations/taskRoutePaths";
|
||||
import { auditTaskEvent } from "~/utils/integrations/taskAudit.server";
|
||||
import { tasksDetailPath, tasksListPath, tasksNewPath } from "~/utils/integrations/taskRoutePaths";
|
||||
import { isDemoDataUiEnabled } from "~/utils/services/.server/demoDataUi.server";
|
||||
import { TasksListPage, type TaskListQuery } from "~/components/screens/tasks/TasksListPage";
|
||||
import ServerError from "~/components/ui/errors/ServerError";
|
||||
|
||||
type LoaderData = { title: string; vm: TaskListVM; includeDemoData: boolean; nextHref: string | null };
|
||||
type LoaderData = {
|
||||
title: string;
|
||||
vm: TaskListVM;
|
||||
includeDemoData: boolean;
|
||||
demoDataUiEnabled: boolean;
|
||||
nextHref: string | null;
|
||||
// Assignee picker options for the "Neue Aufgabe" dialog — only loaded for writers.
|
||||
assignableUsers: LabeledOption[];
|
||||
assignableGroups: LabeledOption[];
|
||||
};
|
||||
|
||||
const PRESETS: readonly TaskListPreset[] = ["mine", "created", "all"];
|
||||
const TASK_STATUSES: readonly TaskStatus[] = ["open", "in_progress", "blocked", "done", "cancelled"];
|
||||
const TASK_PRIORITIES: readonly TaskPriority[] = ["low", "normal", "high", "urgent"];
|
||||
const TERMINAL: ReadonlySet<TaskStatus> = new Set<TaskStatus>(["done", "cancelled"]);
|
||||
/** Cap the needle so a pasted wall of text cannot turn into a pathological LIKE. */
|
||||
const MAX_SEARCH_LENGTH = 120;
|
||||
|
||||
function parsePreset(value: string | null): TaskListPreset {
|
||||
return PRESETS.includes(value as TaskListPreset) ? (value as TaskListPreset) : "all";
|
||||
/** Free-text needle from the URL; empty/whitespace-only means "no search". */
|
||||
function parseSearch(value: string | null): string | null {
|
||||
const needle = (value ?? "").trim();
|
||||
return needle ? needle.slice(0, MAX_SEARCH_LENGTH) : null;
|
||||
}
|
||||
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
@@ -47,12 +67,23 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const ctx = await loadTasksContext({ request, params });
|
||||
const tenantSlug = params.tenant ?? "";
|
||||
const url = new URL(request.url);
|
||||
const includeDemoData = url.searchParams.get("demo") === "show";
|
||||
// Outside staging/dev the `demo=show` query param is ignored server-side —
|
||||
// hiding the checkbox alone would leave demo rows reachable via URL.
|
||||
const demoDataUiEnabled = isDemoDataUiEnabled(undefined, { tenantId: ctx.tenantId, tenantSlug });
|
||||
const includeDemoData = demoDataUiEnabled && url.searchParams.get("demo") === "show";
|
||||
|
||||
const emptyFilter = { preset: "all" as TaskListPreset, status: null, priority: null, assignedToUserId: null, includeArchived: false };
|
||||
const emptyFilter = { search: null, status: null, priority: null, assignedToUserId: null, includeArchived: false };
|
||||
if (!ctx.hasModule) {
|
||||
const vm = buildTaskListVM({ rows: [], filter: emptyFilter, canWrite: false, canDelete: false, createHref: tasksNewPath(tenantSlug) });
|
||||
return Response.json({ title: `${t("tasks.list.title")} | ${process.env.APP_NAME}`, vm, includeDemoData, nextHref: null } satisfies LoaderData);
|
||||
return Response.json({
|
||||
title: `${t("tasks.list.title")} | ${process.env.APP_NAME}`,
|
||||
vm,
|
||||
includeDemoData,
|
||||
demoDataUiEnabled,
|
||||
nextHref: null,
|
||||
assignableUsers: [],
|
||||
assignableGroups: [],
|
||||
} satisfies LoaderData);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -61,7 +92,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
throw notFoundResponse();
|
||||
}
|
||||
|
||||
const preset = parsePreset(url.searchParams.get("preset"));
|
||||
const search = parseSearch(url.searchParams.get("q"));
|
||||
const status = (url.searchParams.get("status") as TaskStatus | null) || null;
|
||||
const priority = (url.searchParams.get("priority") as TaskPriority | null) || null;
|
||||
const includeArchived = url.searchParams.get("archived") === "1";
|
||||
@@ -70,7 +101,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const { rows, nextCursor } = await listTasksForBrowser({
|
||||
tenantId: ctx.tenantId,
|
||||
ctx,
|
||||
filter: { preset, status, priority, includeArchived, includeDemoData },
|
||||
filter: { search, status, priority, includeArchived, includeDemoData },
|
||||
cursor,
|
||||
});
|
||||
|
||||
@@ -88,18 +119,24 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
|
||||
const canWrite = ctx.permissions.includes("tasks.write");
|
||||
const canDelete = ctx.permissions.includes("tasks.delete");
|
||||
|
||||
// The create dialog lives on the list; readers never see it, so skip the queries.
|
||||
const [assignableUsers, assignableGroups] = canWrite
|
||||
? await Promise.all([listAssignableUsers(ctx.tenantId), listAssignableGroups(ctx.tenantId)])
|
||||
: [[] as LabeledOption[], [] as LabeledOption[]];
|
||||
|
||||
const vm = buildTaskListVM({
|
||||
rows: listRows,
|
||||
filter: { preset, status, priority, assignedToUserId: null, includeArchived },
|
||||
filter: { search, status, priority, assignedToUserId: null, includeArchived },
|
||||
canWrite,
|
||||
canDelete,
|
||||
createHref: tasksNewPath(tenantSlug),
|
||||
nextCursor,
|
||||
});
|
||||
|
||||
// Preserve the active preset/filter when paging via cursor.
|
||||
// Preserve the active search/filter when paging via cursor.
|
||||
const nextParams = new URLSearchParams();
|
||||
if (preset !== "all") nextParams.set("preset", preset);
|
||||
if (search) nextParams.set("q", search);
|
||||
if (status) nextParams.set("status", status);
|
||||
if (priority) nextParams.set("priority", priority);
|
||||
if (includeArchived) nextParams.set("archived", "1");
|
||||
@@ -107,7 +144,56 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
if (nextCursor) nextParams.set("cursor", nextCursor);
|
||||
const nextHref = nextCursor ? `?${nextParams.toString()}` : null;
|
||||
|
||||
return Response.json({ title: `${t("tasks.list.title")} | ${process.env.APP_NAME}`, vm, includeDemoData, nextHref } satisfies LoaderData);
|
||||
return Response.json({
|
||||
title: `${t("tasks.list.title")} | ${process.env.APP_NAME}`,
|
||||
vm,
|
||||
includeDemoData,
|
||||
demoDataUiEnabled,
|
||||
nextHref,
|
||||
assignableUsers,
|
||||
assignableGroups,
|
||||
} satisfies LoaderData);
|
||||
};
|
||||
|
||||
/**
|
||||
* Inline status/priority changes from the table (same affordance the lead inbox
|
||||
* has): the badge is the edit control, picking a value POSTs here and the list
|
||||
* reloads with the value stored. Permission + tenant visibility are enforced by
|
||||
* updateTask, which runs inside withTenantRLS.
|
||||
*/
|
||||
export const action = async ({ request, params }: ActionFunctionArgs) => {
|
||||
const ctx = await loadTasksContext({ request, params, requireModule: true });
|
||||
const tenantSlug = params.tenant ?? "";
|
||||
const formData = await request.formData();
|
||||
const intent = String(formData.get("intent") ?? "");
|
||||
const taskId = String(formData.get("taskId") ?? "").trim();
|
||||
|
||||
try {
|
||||
requireTasksPermission(ctx, "tasks.write");
|
||||
if (!taskId) throw badRequestResponse();
|
||||
|
||||
if (intent === "setStatus") {
|
||||
const status = String(formData.get("status") ?? "");
|
||||
if (!TASK_STATUSES.includes(status as TaskStatus)) throw badRequestResponse();
|
||||
await updateTask({ tenantId: ctx.tenantId, taskId, ctx, status: status as TaskStatus });
|
||||
await auditTaskEvent({ ctx, action: "task.updated", taskId, metadata: { status } });
|
||||
} else if (intent === "setPriority") {
|
||||
const priority = String(formData.get("priority") ?? "");
|
||||
if (!TASK_PRIORITIES.includes(priority as TaskPriority)) throw badRequestResponse();
|
||||
await updateTask({ tenantId: ctx.tenantId, taskId, ctx, priority: priority as TaskPriority });
|
||||
await auditTaskEvent({ ctx, action: "task.updated", taskId, metadata: { priority } });
|
||||
} else {
|
||||
throw badRequestResponse();
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Response) throw error;
|
||||
throw notFoundResponse();
|
||||
}
|
||||
|
||||
// Keep the active preset/filter/page: the POST goes to the current URL.
|
||||
const search = new URL(request.url).searchParams;
|
||||
search.set("toast", intent === "setStatus" ? "tasks.toast.statusChanged" : "tasks.toast.priorityChanged");
|
||||
return redirect(`${tasksListPath(tenantSlug)}?${search.toString()}`);
|
||||
};
|
||||
|
||||
/** Map a domain TaskRow to the routing-resolved TaskListRow (shared by embeds). */
|
||||
@@ -142,21 +228,45 @@ export function toTaskListRow(
|
||||
}
|
||||
|
||||
export default function TasksBrowserRoute() {
|
||||
const { vm, includeDemoData, nextHref } = useLoaderData<LoaderData>();
|
||||
const { vm, includeDemoData, demoDataUiEnabled, nextHref, assignableUsers, assignableGroups } = useLoaderData<LoaderData>();
|
||||
const navigate = useNavigate();
|
||||
const submit = useSubmit();
|
||||
const canWrite = vm.status === "ready" && Boolean(vm.data?.canWrite);
|
||||
|
||||
function postField(taskId: string, intent: "setStatus" | "setPriority", field: "status" | "priority", value: string) {
|
||||
const form = new FormData();
|
||||
form.set("intent", intent);
|
||||
form.set("taskId", taskId);
|
||||
form.set(field, value);
|
||||
void submit(form, { method: "post" });
|
||||
}
|
||||
|
||||
function onApply(query: TaskListQuery) {
|
||||
const params = new URLSearchParams();
|
||||
if (query.preset !== "all") params.set("preset", query.preset);
|
||||
if (query.search) params.set("q", query.search);
|
||||
if (query.status) params.set("status", query.status);
|
||||
if (query.priority) params.set("priority", query.priority);
|
||||
if (query.includeArchived) params.set("archived", "1");
|
||||
if (query.includeDemoData) params.set("demo", "show");
|
||||
// Reset cursor pagination whenever the preset/filter changes.
|
||||
// Reset cursor pagination whenever the search/filter changes.
|
||||
navigate({ search: params.toString() });
|
||||
}
|
||||
|
||||
return <TasksListPage vm={vm} includeDemoData={includeDemoData} nextHref={nextHref} actions={{ onApply }} />;
|
||||
return (
|
||||
<TasksListPage
|
||||
vm={vm}
|
||||
includeDemoData={includeDemoData}
|
||||
showDemoToggle={demoDataUiEnabled}
|
||||
nextHref={nextHref}
|
||||
assignableUsers={assignableUsers}
|
||||
assignableGroups={assignableGroups}
|
||||
actions={{
|
||||
onApply,
|
||||
onSetStatus: canWrite ? (taskId, status) => postField(taskId, "setStatus", "status", status) : undefined,
|
||||
onSetPriority: canWrite ? (taskId, priority) => postField(taskId, "setPriority", "priority", priority) : undefined,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function ErrorBoundary() {
|
||||
|
||||
Reference in new issue
Block a user