Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+25
@@ -0,0 +1,25 @@
|
||||
// Interim-UI helper (AD-28): a labeled native <input type="date"> for server forms.
|
||||
// Deliberate exception to "compose from ~/ui" — the ~/ui TextInput.Input type prop
|
||||
// excludes "date" and the ~/ui DatePicker is a controlled component that does not
|
||||
// submit a form field. Styled with the same design tokens as ~/ui inputs (control
|
||||
// height Medium 36 = h-9, radius small 4, neutral border/text) so it reads David-near.
|
||||
|
||||
export type DateFieldProps = {
|
||||
label: string;
|
||||
name: string;
|
||||
defaultValue?: string;
|
||||
};
|
||||
|
||||
export function DateField({ label, name, defaultValue }: DateFieldProps) {
|
||||
return (
|
||||
<label className="flex flex-col gap-1">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{label}</span>
|
||||
<input
|
||||
type="date"
|
||||
name={name}
|
||||
defaultValue={defaultValue}
|
||||
className="h-9 rounded-[4px] border border-solid border-border-default bg-transparent px-3 text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary outline-none"
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import { buildTaskDetailVM, type BuildTaskDetailVMInput, type TaskDetailData, type TaskDetailSource } from "@hivegrid/view-models";
|
||||
|
||||
import { TaskDetailPage } from "./TaskDetailPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
function source(overrides: Partial<TaskDetailSource> = {}): TaskDetailSource {
|
||||
return {
|
||||
id: "t1",
|
||||
title: "Angebot nachfassen",
|
||||
description: "Kunde bis Freitag anrufen",
|
||||
status: "open",
|
||||
priority: "high",
|
||||
deadlineIso: "2026-02-01T10:00:00.000Z",
|
||||
isOverdue: false,
|
||||
assignee: { kind: "user", label: "Alex Meier" },
|
||||
linkedEntity: { entityType: "contact", entityId: "c9", labelKey: "tasks.entity.contact" },
|
||||
source: "manual",
|
||||
sourceHref: null,
|
||||
watchers: [{ userId: "u2", label: "Sam Fischer" }],
|
||||
createdAtIso: "2026-01-02T10:00:00.000Z",
|
||||
completedAtIso: null,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function data(input: Partial<BuildTaskDetailVMInput> = {}): TaskDetailData {
|
||||
const vm = buildTaskDetailVM({
|
||||
task: source(),
|
||||
assignableUsers: [{ id: "u1", label: "Alex Meier" }],
|
||||
assignableGroups: [{ id: "g1", label: "Vertrieb" }],
|
||||
canWrite: true,
|
||||
canDelete: true,
|
||||
listHref: "/acme/tasks",
|
||||
...input,
|
||||
});
|
||||
if (vm.status !== "ready" || !vm.data) throw new Error("expected ready VM");
|
||||
return vm.data;
|
||||
}
|
||||
|
||||
describe("TaskDetailPage (interim-UI)", () => {
|
||||
it("renders the detail surface + title + linked entity + edit form", () => {
|
||||
const { container, getAllByText } = render(
|
||||
<Router>
|
||||
<TaskDetailPage data={data()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail.linkedEntity"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail.edit"]')).toBeInTheDocument();
|
||||
// Title appears in both the breadcrumb (active) and the header.
|
||||
expect(getAllByText("Angebot nachfassen").length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("renders the watcher list with a per-watcher marker", () => {
|
||||
const { container, getByText } = render(
|
||||
<Router>
|
||||
<TaskDetailPage data={data()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-watcher-id="u2"]')).toBeInTheDocument();
|
||||
expect(getByText("Sam Fischer")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("exposes complete + delete actions for a writable, non-done task", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TaskDetailPage data={data()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail.complete"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail.delete"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("hides the edit form + action buttons for a read-only viewer", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TaskDetailPage data={data({ canWrite: false, canDelete: false })} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail.edit"]')).not.toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail.complete"]')).not.toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.detail.delete"]')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+262
@@ -0,0 +1,262 @@
|
||||
// AK-P4b Interim-UI (AD-28) — Task detail preview screen composed from ~/ui.
|
||||
// Presentational: renders the unwrapped TaskDetailData; mutations stay server-driven
|
||||
// (<form method="post"> + intent, exactly like the baseline route action). The delete
|
||||
// confirmation is a real ~/ui Dialog (David standard), not a Card fake. No
|
||||
// useLoaderData / server imports. Final Subframe optics land as a design-nachzug.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherArchive, FeatherCheck, FeatherTrash2 } from "@subframe/core";
|
||||
import type { TaskDetailData, TaskPriority, TaskStatus } from "@hivegrid/view-models";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Breadcrumbs } from "~/ui/components/Breadcrumbs";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { IconButton } from "~/ui/components/IconButton";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Tag_Label } from "~/ui/components/Tag_Label";
|
||||
import { TextArea } from "~/ui/components/TextArea";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import { DateField } from "./DateField";
|
||||
|
||||
const STATUSES: readonly TaskStatus[] = ["open", "in_progress", "blocked", "done", "cancelled"];
|
||||
const PRIORITIES: readonly TaskPriority[] = ["low", "normal", "high", "urgent"];
|
||||
|
||||
export type TaskDetailPageProps = {
|
||||
data: TaskDetailData;
|
||||
};
|
||||
|
||||
type BadgeFarbe = "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-neutral";
|
||||
|
||||
function statusFarbe(status: TaskStatus): BadgeFarbe {
|
||||
switch (status) {
|
||||
case "done":
|
||||
return "subtle-positive";
|
||||
case "blocked":
|
||||
return "subtle-negative";
|
||||
case "in_progress":
|
||||
return "subtle-warning";
|
||||
case "cancelled":
|
||||
case "open":
|
||||
default:
|
||||
return "subtle-neutral";
|
||||
}
|
||||
}
|
||||
|
||||
function MetaRow({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{label}</span>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{value}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function TaskDetailPage({ data }: TaskDetailPageProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium" });
|
||||
const deadlineLabel = data.deadlineIso ? dateFormatter.format(new Date(data.deadlineIso)) : "—";
|
||||
|
||||
return (
|
||||
<div className="flex w-full max-w-[960px] flex-col gap-6 p-6" data-ui-id="ui.tasks.detail">
|
||||
<Breadcrumbs>
|
||||
<a href={data.listHref} className="no-underline">
|
||||
<Breadcrumbs.Item>{t("tasks.nav.title")}</Breadcrumbs.Item>
|
||||
</a>
|
||||
<Breadcrumbs.Divider />
|
||||
<Breadcrumbs.Item active>{data.title}</Breadcrumbs.Item>
|
||||
</Breadcrumbs>
|
||||
|
||||
{/* Header + action bar */}
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{data.title}</span>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<BadgeFeedback farbe={statusFarbe(data.status)} size="small">
|
||||
{t(data.statusKey)}
|
||||
</BadgeFeedback>
|
||||
<Tag_Label tone="neutral-subtle" size="small" noAction>
|
||||
{t(data.priorityKey)}
|
||||
</Tag_Label>
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{t(data.sourceKey)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2" data-ui-id="ui.tasks.detail.actions">
|
||||
{data.canWrite && data.status !== "done" ? (
|
||||
<form method="post">
|
||||
<Button type="submit" name="intent" value="complete" variant="tertiary" icon={<FeatherCheck />} data-ui-id="ui.tasks.detail.complete">
|
||||
{t("tasks.detail.actions.complete")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
{data.canWrite ? (
|
||||
<form method="post">
|
||||
<Button type="submit" name="intent" value="archive" variant="tertiary" icon={<FeatherArchive />} data-ui-id="ui.tasks.detail.archive">
|
||||
{t("tasks.detail.actions.archive")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
{data.canDelete ? (
|
||||
<Button type="button" variant="destructive" icon={<FeatherTrash2 />} onClick={() => setDeleteOpen(true)} data-ui-id="ui.tasks.detail.delete">
|
||||
{t("tasks.detail.actions.delete")}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Metadata */}
|
||||
<Card>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("tasks.detail.section.overview")}</span>
|
||||
<div className="grid w-full grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<div data-ui-id="ui.tasks.detail.deadline" data-overdue={data.isOverdue}>
|
||||
<MetaRow label={t("tasks.detail.field.deadline")} value={deadlineLabel} />
|
||||
</div>
|
||||
<MetaRow label={t("tasks.detail.field.assignee")} value={data.assignee ? data.assignee.label : t("tasks.detail.unassigned")} />
|
||||
{data.linkedEntity ? (
|
||||
<div data-ui-id="ui.tasks.detail.linkedEntity">
|
||||
<MetaRow label={t(data.linkedEntity.labelKey)} value={data.linkedEntity.entityId} />
|
||||
</div>
|
||||
) : null}
|
||||
<MetaRow label={t("tasks.detail.field.created")} value={dateFormatter.format(new Date(data.createdAtIso))} />
|
||||
</div>
|
||||
{data.description ? (
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{t("tasks.detail.section.description")}</span>
|
||||
<span className="whitespace-pre-wrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{data.description}</span>
|
||||
</div>
|
||||
) : null}
|
||||
</Card>
|
||||
|
||||
{/* Edit form (writers only) */}
|
||||
{data.canWrite ? (
|
||||
<Card>
|
||||
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t("tasks.detail.section.edit")}</span>
|
||||
<form method="post" className="flex w-full flex-col gap-4" data-ui-id="ui.tasks.detail.edit">
|
||||
<input type="hidden" name="intent" value="update" />
|
||||
<TextInput label={t("tasks.detail.field.title")} showLabel>
|
||||
<TextInput.Input name="title" defaultValue={data.title} required />
|
||||
</TextInput>
|
||||
<TextArea label={t("tasks.detail.field.description")} showLabel>
|
||||
<TextArea.Input name="description" defaultValue={data.description ?? ""} />
|
||||
</TextArea>
|
||||
<div className="flex flex-wrap items-end gap-4">
|
||||
<Select className="max-w-[200px]" name="status" label={t("tasks.detail.field.status")} showLabel defaultValue={data.status}>
|
||||
{STATUSES.map((status) => (
|
||||
<Select.Item key={status} value={status}>
|
||||
{t(`tasks.status.${status}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Select className="max-w-[200px]" name="priority" label={t("tasks.detail.field.priority")} showLabel defaultValue={data.priority}>
|
||||
{PRIORITIES.map((priority) => (
|
||||
<Select.Item key={priority} value={priority}>
|
||||
{t(`tasks.priority.${priority}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<DateField label={t("tasks.detail.field.deadline")} name="deadline" defaultValue={data.deadlineIso ? data.deadlineIso.slice(0, 10) : ""} />
|
||||
</div>
|
||||
<Button type="submit" className="w-fit">
|
||||
{t("tasks.detail.actions.save")}
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<form method="post" className="flex w-full flex-wrap items-end gap-4" data-ui-id="ui.tasks.detail.reassign">
|
||||
<input type="hidden" name="intent" value="reassign" />
|
||||
<Select className="max-w-[200px]" name="assigneeType" label={t("tasks.detail.field.assigneeType")} showLabel defaultValue="user">
|
||||
<Select.Item value="user">{t("tasks.detail.assignee.user")}</Select.Item>
|
||||
<Select.Item value="group">{t("tasks.detail.assignee.group")}</Select.Item>
|
||||
</Select>
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
name="assigneeId"
|
||||
label={t("tasks.detail.field.assignee")}
|
||||
showLabel
|
||||
defaultValue={data.assignableUsers[0]?.id ?? data.assignableGroups[0]?.id}
|
||||
>
|
||||
{data.assignableUsers.map((user) => (
|
||||
<Select.Item key={`u-${user.id}`} value={user.id}>
|
||||
{user.label}
|
||||
</Select.Item>
|
||||
))}
|
||||
{data.assignableGroups.map((group) => (
|
||||
<Select.Item key={`g-${group.id}`} value={group.id}>
|
||||
{group.label}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Button type="submit" variant="secondary">
|
||||
{t("tasks.detail.actions.reassign")}
|
||||
</Button>
|
||||
</form>
|
||||
</Card>
|
||||
) : null}
|
||||
|
||||
{/* Watchers */}
|
||||
<div className="flex flex-col gap-3" data-ui-id="ui.tasks.detail.watchers">
|
||||
<span className="text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-tertiary">{t("tasks.detail.section.watchers")}</span>
|
||||
{data.watchers.length > 0 ? (
|
||||
<ul className="flex flex-col gap-2">
|
||||
{data.watchers.map((watcher) => (
|
||||
<li
|
||||
key={watcher.userId}
|
||||
className="flex items-center justify-between gap-3 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-3 py-2"
|
||||
data-watcher-id={watcher.userId}
|
||||
>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{watcher.label}</span>
|
||||
{data.canWrite ? (
|
||||
<form method="post">
|
||||
<input type="hidden" name="intent" value="removeWatcher" />
|
||||
<input type="hidden" name="userId" value={watcher.userId} />
|
||||
<IconButton type="submit" variant="ghost" size="small" icon={<FeatherTrash2 />} aria-label={t("tasks.detail.actions.removeWatcher")} />
|
||||
</form>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{t("tasks.detail.watchers.empty")}</span>
|
||||
)}
|
||||
{data.canWrite && data.assignableUsers.length > 0 ? (
|
||||
<form method="post" className="flex flex-wrap items-end gap-2">
|
||||
<input type="hidden" name="intent" value="addWatcher" />
|
||||
<Select className="max-w-[240px]" name="userId" label={t("tasks.detail.field.watcher")} showLabel defaultValue={data.assignableUsers[0]?.id}>
|
||||
{data.assignableUsers.map((user) => (
|
||||
<Select.Item key={`w-${user.id}`} value={user.id}>
|
||||
{user.label}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Button type="submit" variant="secondary">
|
||||
{t("tasks.detail.actions.addWatcher")}
|
||||
</Button>
|
||||
</form>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Delete confirmation dialog (real ~/ui Dialog, size XS) */}
|
||||
<Dialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<Dialog.Content className="w-[420px] max-w-[90vw] p-8">
|
||||
<div className="flex w-full flex-col gap-6">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("tasks.detail.delete.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">{t("tasks.detail.delete.body")}</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
<Button type="button" variant="tertiary" onClick={() => setDeleteOpen(false)}>
|
||||
{t("tasks.detail.dialog.cancel")}
|
||||
</Button>
|
||||
<form method="post">
|
||||
<Button type="submit" name="intent" value="delete" variant="destructive" icon={<FeatherTrash2 />}>
|
||||
{t("tasks.detail.delete.confirm")}
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
|
||||
import { TaskNewPage, type TaskNewPageProps } from "./TaskNewPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
function baseProps(overrides: Partial<TaskNewPageProps> = {}): TaskNewPageProps {
|
||||
return {
|
||||
assignableUsers: [{ id: "u1", label: "Alex Meier" }],
|
||||
assignableGroups: [{ id: "g1", label: "Vertrieb" }],
|
||||
prefill: null,
|
||||
cancelHref: "/acme/tasks",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("TaskNewPage (interim-UI)", () => {
|
||||
it("renders the create form surface + title/submit/cancel markers", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TaskNewPage {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.new"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.new.title"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.new.submit"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.new.cancel"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the entity prefill marker + hidden inputs when prefilled", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TaskNewPage {...baseProps({ prefill: { entityType: "contact", entityId: "c9" } })} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.new.prefill"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('input[type="hidden"][name="entityType"][value="contact"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('input[type="hidden"][name="entityId"][value="c9"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("omits the prefill block when not prefilled", () => {
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TaskNewPage {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.new.prefill"]')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
// AK-P4b Interim-UI (AD-28) — Task create preview screen composed from ~/ui.
|
||||
// Presentational: the form posts to the route action (server-driven create); the
|
||||
// loader injects the assignee picker options + optional entity pre-fill. No
|
||||
// useLoaderData / server imports. Final Subframe optics land as a design-nachzug.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus } from "@subframe/core";
|
||||
import type { TaskPriority } from "@hivegrid/view-models";
|
||||
import { Breadcrumbs } from "~/ui/components/Breadcrumbs";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Card } from "~/ui/components/Card";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { TextArea } from "~/ui/components/TextArea";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import { DateField } from "./DateField";
|
||||
|
||||
const PRIORITIES: readonly TaskPriority[] = ["low", "normal", "high", "urgent"];
|
||||
|
||||
// The ~/ui Select forbids an empty-string option value, so the "creator (default)"
|
||||
// choice uses a sentinel. The route action maps it back to "no explicit assignee".
|
||||
export const TASK_CREATOR_ASSIGNEE = "__creator__";
|
||||
|
||||
export type TaskPickerOption = { readonly id: string; readonly label: string };
|
||||
export type TaskNewPrefill = { readonly entityType: string; readonly entityId: string } | null;
|
||||
|
||||
export type TaskNewPageProps = {
|
||||
assignableUsers: readonly TaskPickerOption[];
|
||||
assignableGroups: readonly TaskPickerOption[];
|
||||
prefill: TaskNewPrefill;
|
||||
/** Back link to the task list (breadcrumb / cancel target). */
|
||||
cancelHref: string;
|
||||
};
|
||||
|
||||
export function TaskNewPage({ assignableUsers, assignableGroups, prefill, cancelHref }: TaskNewPageProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className="flex w-full max-w-[720px] flex-col gap-6 p-6" data-ui-id="ui.tasks.new">
|
||||
<Breadcrumbs>
|
||||
<a href={cancelHref} className="no-underline">
|
||||
<Breadcrumbs.Item>{t("tasks.nav.title")}</Breadcrumbs.Item>
|
||||
</a>
|
||||
<Breadcrumbs.Divider />
|
||||
<Breadcrumbs.Item active>{t("tasks.new.title")}</Breadcrumbs.Item>
|
||||
</Breadcrumbs>
|
||||
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("tasks.new.title")}</span>
|
||||
|
||||
<Card>
|
||||
<form method="post" className="flex w-full flex-col gap-4">
|
||||
<TextInput label={t("tasks.detail.field.title")} showLabel>
|
||||
<TextInput.Input name="title" required data-ui-id="ui.tasks.new.title" />
|
||||
</TextInput>
|
||||
<TextArea label={t("tasks.detail.field.description")} showLabel>
|
||||
<TextArea.Input name="description" />
|
||||
</TextArea>
|
||||
<div className="flex flex-wrap items-end gap-4">
|
||||
<Select className="max-w-[200px]" name="priority" label={t("tasks.detail.field.priority")} showLabel defaultValue="normal">
|
||||
{PRIORITIES.map((priority) => (
|
||||
<Select.Item key={priority} value={priority}>
|
||||
{t(`tasks.priority.${priority}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<DateField label={t("tasks.detail.field.deadline")} name="deadline" />
|
||||
</div>
|
||||
<div className="flex flex-wrap items-end gap-4">
|
||||
<Select className="max-w-[200px]" name="assigneeType" label={t("tasks.detail.field.assigneeType")} showLabel defaultValue="user">
|
||||
<Select.Item value="user">{t("tasks.detail.assignee.user")}</Select.Item>
|
||||
<Select.Item value="group">{t("tasks.detail.assignee.group")}</Select.Item>
|
||||
</Select>
|
||||
<Select className="max-w-[240px]" name="assigneeId" label={t("tasks.detail.field.assignee")} showLabel defaultValue={TASK_CREATOR_ASSIGNEE}>
|
||||
<Select.Item value={TASK_CREATOR_ASSIGNEE}>{t("tasks.new.assignee.default")}</Select.Item>
|
||||
{assignableUsers.map((user) => (
|
||||
<Select.Item key={`u-${user.id}`} value={user.id}>
|
||||
{user.label}
|
||||
</Select.Item>
|
||||
))}
|
||||
{assignableGroups.map((group) => (
|
||||
<Select.Item key={`g-${group.id}`} value={group.id}>
|
||||
{group.label}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{prefill ? (
|
||||
<div data-ui-id="ui.tasks.new.prefill">
|
||||
<input type="hidden" name="entityType" value={prefill.entityType} />
|
||||
<input type="hidden" name="entityId" value={prefill.entityId} />
|
||||
<span className="text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
|
||||
{t(`tasks.entity.${prefill.entityType}`)} · {prefill.entityId}
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Button type="submit" icon={<FeatherPlus />} data-ui-id="ui.tasks.new.submit">
|
||||
{t("tasks.new.actions.create")}
|
||||
</Button>
|
||||
<a href={cancelHref} className="no-underline" data-ui-id="ui.tasks.new.cancel">
|
||||
<Button type="button" variant="tertiary">
|
||||
{t("tasks.new.actions.cancel")}
|
||||
</Button>
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
import { vi, describe, it, expect } from "vitest";
|
||||
import "@testing-library/jest-dom";
|
||||
import { render } from "@testing-library/react";
|
||||
import { BrowserRouter as Router } from "react-router";
|
||||
import {
|
||||
buildTaskListVM,
|
||||
taskPriorityKey,
|
||||
taskStatusKey,
|
||||
type TaskListFilterState,
|
||||
type TaskListRow,
|
||||
} from "@hivegrid/view-models";
|
||||
|
||||
import { TasksListPage } from "./TasksListPage";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
||||
}));
|
||||
|
||||
function row(overrides: Partial<TaskListRow> = {}): TaskListRow {
|
||||
return {
|
||||
id: "t1",
|
||||
title: "Angebot nachfassen",
|
||||
status: "open",
|
||||
statusKey: taskStatusKey("open"),
|
||||
priority: "high",
|
||||
priorityKey: taskPriorityKey("high"),
|
||||
deadlineIso: "2026-02-01T10:00:00.000Z",
|
||||
isOverdue: false,
|
||||
assignee: { kind: "user", label: "Alex Meier" },
|
||||
linkedEntity: null,
|
||||
source: "manual",
|
||||
sourceKey: "tasks.source.manual",
|
||||
sourceHref: null,
|
||||
detailHref: "/acme/tasks/t1",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
const filter: TaskListFilterState = { preset: "all", status: null, priority: null, assignedToUserId: null, includeArchived: false };
|
||||
|
||||
function baseProps() {
|
||||
return { includeDemoData: false, nextHref: null, actions: { onApply: vi.fn() } };
|
||||
}
|
||||
|
||||
describe("TasksListPage (interim-UI)", () => {
|
||||
it("renders the browser surface + table rows from the VM", () => {
|
||||
const vm = buildTaskListVM({ rows: [row()], filter, canWrite: true, canDelete: false, createHref: "/acme/tasks/new" });
|
||||
const { container, getByText } = render(
|
||||
<Router>
|
||||
<TasksListPage vm={vm} {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.list"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.list.table"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-row-id="t1"]')).toBeInTheDocument();
|
||||
expect(getByText("Angebot nachfassen")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the empty state when there are no rows", () => {
|
||||
const vm = buildTaskListVM({ rows: [], filter, canWrite: true, canDelete: false, createHref: "/acme/tasks/new" });
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TasksListPage vm={vm} {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.list.empty"]')).toBeInTheDocument();
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.list.table"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the create CTA only when the user may write", () => {
|
||||
const readonlyVm = buildTaskListVM({ rows: [row()], filter, canWrite: false, canDelete: false, createHref: "/acme/tasks/new" });
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TasksListPage vm={readonlyVm} {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.list.new"]')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders the preset tabs + status/priority filter selects", () => {
|
||||
const vm = buildTaskListVM({ rows: [row()], filter, canWrite: true, canDelete: false, createHref: "/acme/tasks/new" });
|
||||
const { container, getByText } = render(
|
||||
<Router>
|
||||
<TasksListPage vm={vm} {...baseProps()} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.list.presets"]')).toBeInTheDocument();
|
||||
expect(getByText("tasks.list.filter.status.label")).toBeInTheDocument();
|
||||
expect(getByText("tasks.list.filter.priority.label")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows the pagination link when a next page exists", () => {
|
||||
const vm = buildTaskListVM({ rows: [row()], filter, canWrite: true, canDelete: false, createHref: "/acme/tasks/new", nextCursor: "cur2" });
|
||||
const { container } = render(
|
||||
<Router>
|
||||
<TasksListPage vm={vm} {...{ ...baseProps(), nextHref: "?cursor=cur2" }} />
|
||||
</Router>,
|
||||
);
|
||||
expect(container.querySelector('[data-ui-id="ui.tasks.list.pagination"]')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
+242
@@ -0,0 +1,242 @@
|
||||
// AK-P4b Interim-UI (AD-28) — Tasks browser preview screen composed from ~/ui.
|
||||
// Pure presentational component: renders the server-built TaskListVM passed as a
|
||||
// prop and reports preset/filter changes through injected actions (server-side
|
||||
// navigation). No useLoaderData, no server imports. This is the REUSABLE task list
|
||||
// (DoD 8); the standalone /tasks route is its host, entity detail views embed it.
|
||||
// Final Subframe optics land as a tracked design-nachzug once David's D-P4 ships.
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherPlus } from "@subframe/core";
|
||||
import type { TaskListPreset, TaskListRow, TaskListVM, TaskPriority, TaskStatus } from "@hivegrid/view-models";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Checkbox } from "~/ui/components/Checkbox";
|
||||
import { EmptyState } from "~/ui/components/EmptyState";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { Table } from "~/ui/components/Table";
|
||||
import { Tag_Label } from "~/ui/components/Tag_Label";
|
||||
import { ToggleGroup } from "~/ui/components/ToggleGroup";
|
||||
|
||||
const PRESETS: readonly TaskListPreset[] = ["mine", "created", "all"];
|
||||
const STATUSES: readonly TaskStatus[] = ["open", "in_progress", "blocked", "done", "cancelled"];
|
||||
const PRIORITIES: readonly TaskPriority[] = ["low", "normal", "high", "urgent"];
|
||||
|
||||
// Shared "no filter" sentinel for the status/priority Selects (empty string is not
|
||||
// a valid Select value, so a non-empty sentinel maps back to null).
|
||||
const FILTER_ALL = "__all__";
|
||||
|
||||
export type TaskListQuery = {
|
||||
preset: TaskListPreset;
|
||||
status: TaskStatus | null;
|
||||
priority: TaskPriority | null;
|
||||
includeArchived: boolean;
|
||||
includeDemoData: boolean;
|
||||
};
|
||||
|
||||
export type TasksListActions = {
|
||||
/** Navigate (GET) to the same route with the given preset/filter state. */
|
||||
onApply: (query: TaskListQuery) => void;
|
||||
};
|
||||
|
||||
export type TasksListPageProps = {
|
||||
vm: TaskListVM;
|
||||
/** Whether demo-data rows are currently shown (kept out of the VM). */
|
||||
includeDemoData: boolean;
|
||||
/** Href for the next cursor page, or null on the last page. */
|
||||
nextHref: string | null;
|
||||
actions: TasksListActions;
|
||||
};
|
||||
|
||||
type BadgeFarbe = "subtle-positive" | "subtle-warning" | "subtle-negative" | "subtle-neutral";
|
||||
|
||||
function statusFarbe(status: TaskStatus): BadgeFarbe {
|
||||
switch (status) {
|
||||
case "done":
|
||||
return "subtle-positive";
|
||||
case "blocked":
|
||||
return "subtle-negative";
|
||||
case "in_progress":
|
||||
return "subtle-warning";
|
||||
case "cancelled":
|
||||
case "open":
|
||||
default:
|
||||
return "subtle-neutral";
|
||||
}
|
||||
}
|
||||
|
||||
export function TasksListPage({ vm, includeDemoData, nextHref, actions }: TasksListPageProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
|
||||
// Loading / not-ready: keep the marker so the shell + e2e see a stable surface.
|
||||
if (vm.status !== "ready" || !vm.data) {
|
||||
return <div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.tasks.list" />;
|
||||
}
|
||||
|
||||
const { rows, filter, canWrite, createHref, emptyHeadlineKey, emptyBodyKey } = vm.data;
|
||||
const dateFormatter = new Intl.DateTimeFormat(i18n.language, { dateStyle: "medium" });
|
||||
|
||||
function applyPatch(patch: Partial<TaskListQuery>) {
|
||||
actions.onApply({
|
||||
preset: filter.preset,
|
||||
status: filter.status,
|
||||
priority: filter.priority,
|
||||
includeArchived: filter.includeArchived,
|
||||
includeDemoData,
|
||||
...patch,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-6 p-6" data-ui-id="ui.tasks.list">
|
||||
{/* Header: title + subtitle (0px rhythm) + create CTA */}
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
<div className="flex flex-col gap-0">
|
||||
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("tasks.list.title")}</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("tasks.list.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
{canWrite ? (
|
||||
<a href={createHref} className="no-underline" data-ui-id="ui.tasks.list.new">
|
||||
<Button icon={<FeatherPlus />}>{t("tasks.list.actions.new")}</Button>
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Preset tabs (server-side navigation) */}
|
||||
<div className="flex flex-wrap items-center gap-4" data-ui-id="ui.tasks.list.presets">
|
||||
<ToggleGroup
|
||||
value={filter.preset}
|
||||
onValueChange={(value: string) => {
|
||||
if (PRESETS.includes(value as TaskListPreset)) applyPatch({ preset: value as TaskListPreset });
|
||||
}}
|
||||
>
|
||||
{PRESETS.map((preset) => (
|
||||
<ToggleGroup.Item key={preset} value={preset} aria-label={t(`tasks.list.preset.${preset}`)}>
|
||||
{t(`tasks.list.preset.${preset}`)}
|
||||
</ToggleGroup.Item>
|
||||
))}
|
||||
</ToggleGroup>
|
||||
</div>
|
||||
|
||||
{/* Filter bar (server-side, navigation on change) */}
|
||||
<div className="flex flex-wrap items-center gap-4" data-ui-id="ui.tasks.list.filter">
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("tasks.list.filter.status.label")}
|
||||
showLabel
|
||||
value={filter.status ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ status: value === FILTER_ALL ? null : (value as TaskStatus) })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("tasks.list.filter.status.all")}</Select.Item>
|
||||
{STATUSES.map((status) => (
|
||||
<Select.Item key={status} value={status}>
|
||||
{t(`tasks.status.${status}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Select
|
||||
className="max-w-[240px]"
|
||||
label={t("tasks.list.filter.priority.label")}
|
||||
showLabel
|
||||
value={filter.priority ?? FILTER_ALL}
|
||||
onValueChange={(value: string) => applyPatch({ priority: value === FILTER_ALL ? null : (value as TaskPriority) })}
|
||||
>
|
||||
<Select.Item value={FILTER_ALL}>{t("tasks.list.filter.priority.all")}</Select.Item>
|
||||
{PRIORITIES.map((priority) => (
|
||||
<Select.Item key={priority} value={priority}>
|
||||
{t(`tasks.priority.${priority}`)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
<Checkbox
|
||||
label={t("tasks.list.filter.archived")}
|
||||
checked={filter.includeArchived}
|
||||
onCheckedChange={(checked: boolean) => applyPatch({ includeArchived: checked })}
|
||||
/>
|
||||
<Checkbox
|
||||
label={t("tasks.list.filter.demo")}
|
||||
checked={includeDemoData}
|
||||
onCheckedChange={(checked: boolean) => applyPatch({ includeDemoData: checked })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<div data-ui-id="ui.tasks.list.empty">
|
||||
<EmptyState title={t(emptyHeadlineKey)} body={t(emptyBodyKey)} />
|
||||
</div>
|
||||
) : (
|
||||
<TableView rows={rows} dateFormatter={dateFormatter} t={t} statusFarbe={statusFarbe} />
|
||||
)}
|
||||
|
||||
{nextHref ? (
|
||||
<div className="flex justify-center pt-2" data-ui-id="ui.tasks.list.pagination">
|
||||
<a href={nextHref} className="no-underline">
|
||||
<Button variant="tertiary">{t("tasks.list.pagination.next")}</Button>
|
||||
</a>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TableView({
|
||||
rows,
|
||||
dateFormatter,
|
||||
t,
|
||||
statusFarbe,
|
||||
}: {
|
||||
rows: readonly TaskListRow[];
|
||||
dateFormatter: Intl.DateTimeFormat;
|
||||
t: (key: string) => string;
|
||||
statusFarbe: (status: TaskStatus) => BadgeFarbe;
|
||||
}) {
|
||||
return (
|
||||
<div className="w-full overflow-x-auto" data-ui-id="ui.tasks.list.table">
|
||||
<Table
|
||||
header={
|
||||
<Table.HeaderRow>
|
||||
<Table.HeaderCell>{t("tasks.list.column.title")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("tasks.list.column.status")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("tasks.list.column.priority")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("tasks.list.column.assignee")}</Table.HeaderCell>
|
||||
<Table.HeaderCell>{t("tasks.list.column.deadline")}</Table.HeaderCell>
|
||||
</Table.HeaderRow>
|
||||
}
|
||||
>
|
||||
{rows.map((row) => (
|
||||
<Table.Row key={row.id} data-row-id={row.id}>
|
||||
<Table.Cell>
|
||||
<a href={row.detailHref} className="text-body-default-medium-0 font-body-default-medium-0 text-text-feedback-link-default">
|
||||
{row.title}
|
||||
</a>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<BadgeFeedback farbe={statusFarbe(row.status)} size="small">
|
||||
{t(row.statusKey)}
|
||||
</BadgeFeedback>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Tag_Label tone="neutral-subtle" size="small" noAction>
|
||||
{t(row.priorityKey)}
|
||||
</Tag_Label>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
|
||||
{row.assignee ? row.assignee.label : t("tasks.detail.unassigned")}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<span
|
||||
className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary"
|
||||
data-overdue={row.isOverdue}
|
||||
>
|
||||
{row.deadlineIso ? dateFormatter.format(new Date(row.deadlineIso)) : "—"}
|
||||
</span>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user