Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 11 additions & 27 deletions packages/app/src/features/events/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,30 @@ import { api } from "factorize-api-client";
import { Button, Page, PageHeader, Table, tableCellClasses, tableHeadClasses, tableRowClasses } from "../../shared/ui";
import { OccurrenceTable } from "./occurrence-table";
import { eventsQuery, subscriptionsQuery } from "./queries";
import { EventSubscriptions, SubscriptionsTable, SubscriptionTime } from "./subscriptions-table";
import { SubscriptionsTable, SubscriptionTime } from "./subscriptions-table";

const linkClass = "rounded-lg px-3 py-2 hover:bg-stone-100 dark:hover:bg-slate-800";
const activeClass = "bg-factorize-50 text-factorize-700 dark:bg-factorize-500/10 dark:text-factorize-500";
function EventsLayout({ title, description, children, subscriptions }: { title: string; description?: string; children: ReactNode; subscriptions?: boolean }) {
return <Page><div className="grid min-w-0 gap-8 md:grid-cols-[13rem_minmax(0,1fr)] md:gap-10">
<nav aria-label="Event navigation" className="flex flex-wrap gap-2 border-b border-stone-200 pb-4 text-sm font-semibold dark:border-slate-800 md:flex-col md:border-b-0">
<Link to="/events" className={linkClass} activeOptions={{ exact: true }} inactiveProps={subscriptions ? {} : { className: activeClass, "aria-current": "location" }} activeProps={{ className: activeClass }}>Events</Link>
<Link to="/events/subscriptions" className={linkClass} activeProps={{ className: activeClass }}>Subscriptions</Link>
</nav>
<div className="min-w-0"><PageHeader title={title} description={description} />{children}</div>
</div></Page>;
function EventsLayout({ title, description, children, back }: { title: string; description?: string; children: ReactNode; back?: boolean }) {
return <Page>
{back && <Link to="/events" className="mb-4 inline-block text-sm underline">Back to Events</Link>}
<PageHeader title={title} description={description} />
{children}
</Page>;
}

export function EventsPage() {
const events = useQuery(eventsQuery);
const subscriptions = useQuery(subscriptionsQuery);
const counts = new Map<string, number>();
for (const row of subscriptions.data ?? []) if (row.status === "active") counts.set(row.eventId, (counts.get(row.eventId) ?? 0) + 1);
return <EventsLayout title="Events" description="MCP Events to help coordinate your agents">
{events.isPending && <p role="status">Loading Events…</p>}
{events.error && <p role="alert">{events.error.message}</p>}
{subscriptions.error && <p role="alert">Subscriber counts could not be loaded.</p>}
{events.data?.length === 0 && <p>No Events yet.</p>}
{!!events.data?.length && <Table aria-label="Events">
<thead className={tableHeadClasses}><tr>{["Name", "Description", "Subscribers"].map(label =>
<th key={label} scope="col" className={tableCellClasses} title={label === "Subscribers" ? "Active registrations for your connections in this workspace" : undefined}>{label}</th>)}</tr></thead>
<thead className={tableHeadClasses}><tr>{["Name", "Description"].map(label =>
<th key={label} scope="col" className={tableCellClasses}>{label}</th>)}</tr></thead>
<tbody>{events.data.map(item => <tr key={item.id} className={tableRowClasses}>
<th scope="row" className={`${tableCellClasses} font-medium`}><Link
to="/events/$eventId" params={{ eventId: item.id }}
className="underline after:absolute after:inset-0 focus-visible:after:ring-2 focus-visible:after:ring-inset focus-visible:after:ring-factorize-500">{item.name}</Link></th>
<td className={tableCellClasses}>{item.description || "No description"}</td>
<td className={tableCellClasses}>{subscriptions.error ? "—" : subscriptions.isPending ? "…" : counts.get(item.id) ?? 0}</td>
</tr>)}</tbody>
</Table>}
</EventsLayout>;
Expand Down Expand Up @@ -70,7 +61,7 @@ export function EventPage() {
await navigate({ to: "/events" });
},
});
return <EventsLayout title={event?.name ?? "Event"} description={event?.description || undefined}>
return <EventsLayout back title={event?.name ?? "Event"} description={event?.description || undefined}>
{events.isPending && <p role="status">Loading Event…</p>}
{events.error && <p role="alert">{events.error.message}</p>}
{!events.isPending && !events.error && !event && <p>Event not found.</p>}
Expand Down Expand Up @@ -109,7 +100,6 @@ export function EventPage() {
<pre className="overflow-x-auto whitespace-pre-wrap rounded bg-white p-3 text-sm dark:bg-slate-800">{detail.data.enrichment.rule}</pre>
<p className="text-xs">Read only. Edit this rule through the Factorize API or MCP.</p>
</section>}
<section><h2 className="mb-3">Subscriptions</h2><EventSubscriptions eventId={eventId} /></section>
<OccurrenceTable key={eventId} eventId={eventId} />
<Button disabled={remove.isPending} onClick={() => {
if (window.confirm(`Delete ${event.name}, its Triggers, subscriptions, and all occurrence history?`)) remove.mutate();
Expand All @@ -118,12 +108,6 @@ export function EventPage() {
</EventsLayout>;
}

export function SubscriptionsPage() {
return <EventsLayout subscriptions title="Subscriptions" description="MCP clients subscribed to Events. Active registrations may still be unable to receive deliveries.">
<EventSubscriptions />
</EventsLayout>;
}

export function SubscriptionPage() {
const { subscriptionId } = useParams({ from: "/events/subscriptions/$subscriptionId" });
const subscription = useQuery({
Expand All @@ -135,7 +119,7 @@ export function SubscriptionPage() {
return data;
},
});
return <EventsLayout subscriptions title="Subscription" description={subscription.data?.eventName}>
return <EventsLayout back title="Subscription" description={subscription.data?.eventName}>
{subscription.isPending && <p role="status">Loading subscription…</p>}
{subscription.error && <p role="alert">{subscription.error.message}</p>}
{subscription.data === null && <p>Event subscription not found.</p>}
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/features/events/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function eventRoutes(root: AnyRootRoute) {
createRoute({ getParentRoute: () => root, path: "/events", beforeLoad: guard, loader: loadEvents,
component: lazyRouteComponent(() => import("./events"), "EventsPage") }),
createRoute({ getParentRoute: () => root, path: "/events/subscriptions", beforeLoad: guard,
component: lazyRouteComponent(() => import("./events"), "SubscriptionsPage") }),
loader: () => { throw redirect({ to: "/events" }); } }),
createRoute({ getParentRoute: () => root, path: "/events/subscriptions/$subscriptionId", beforeLoad: guard,
component: lazyRouteComponent(() => import("./events"), "SubscriptionPage") }),
createRoute({ getParentRoute: () => root, path: "/events/$eventId", beforeLoad: guard, loader: loadEvents,
Expand Down
50 changes: 26 additions & 24 deletions packages/app/test/functional/critical.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ test("navigates Events, subscriptions and exact client connections through acces
{ grantId: "primary", clientName: "Order assistant", clientId: "same-app", appName: "Registered app", expiresAt: null, authorizationDate: timestamp },
{ grantId: "secondary", clientName: "Other connection", clientId: "same-app", appName: "Registered app", expiresAt: null, authorizationDate: timestamp },
] }));
await page.route("**/api/v1/event-subscriptions", route => route.fulfill({ json: deleted ? [other] : [required, expired, other] }));
let subscriptionListRequests = 0;
await page.route("**/api/v1/event-subscriptions", route => {
subscriptionListRequests++;
return route.fulfill({ json: deleted ? [other] : [required, expired, other] });
});
await page.route(`**/api/v1/event-subscriptions/${requiredId}`, route => route.fulfill({ json: required }));
const triggerId = "30000000-0000-4000-8000-000000000001";
const enrichment = {rule:"input.ready",extraDataUrls:[{name:"checks",method:"GET",path:"/status"}]};
Expand Down Expand Up @@ -71,9 +75,9 @@ test("navigates Events, subscriptions and exact client connections through acces
const nav = page.getByRole("navigation", { name: "Event navigation" });
const events = page.getByRole("table", { name: "Events", exact: true });
await expect(page.getByRole("heading", { name: "Events", exact: true })).toBeVisible();
await expect(nav.getByRole("link", { name: "Events", exact: true })).toHaveAttribute("aria-current", "page");
await expect(events.getByRole("columnheader")).toHaveText(["Name", "Description", "Subscribers"]);
await expect(events.getByRole("row", { name: /orders.created/ }).getByRole("cell").last()).toHaveText("1");
await expect(nav).toHaveCount(0);
await expect(page.getByRole("main").getByRole("link", { name: "Subscriptions" })).toHaveCount(0);
await expect(events.getByRole("columnheader")).toHaveText(["Name", "Description"]);
await expect(page.getByRole("button", { name: "Delete", exact: true })).toHaveCount(0);
await expect(page.getByRole("button", { name: "Create Event" })).toHaveCount(0);
await expect(page.getByRole("main").locator("form")).toHaveCount(0);
Expand All @@ -85,6 +89,10 @@ test("navigates Events, subscriptions and exact client connections through acces
await expect(page.getByRole("heading", { name: "orders.created", exact: true })).toBeVisible();
await expect(page.getByRole("navigation", { name: "Dashboard navigation" }).getByRole("link", { name: "Events" })).toBeVisible();
await expect(page.getByRole("heading", { name: "Payload schema" })).toHaveCount(0);
await expect(nav).toHaveCount(0);
await expect(page.getByRole("heading", { name: "Subscriptions" })).toHaveCount(0);
await expect(page.getByRole("table", { name: "Event subscriptions" })).toHaveCount(0);
await expect(page.getByRole("link", { name: "Back to Events" })).toHaveAttribute("href", "/events");
await expect(page.getByRole("link",{name:"Order signal"})).toHaveAttribute("href","/triggers/" + triggerId);
await expect(page.getByRole("heading",{name:"Match logic"})).toBeVisible();
await expect(page.getByRole("status").filter({ hasText: "Evaluation is paused because an integration used by this Event was deleted." })).toBeVisible();
Expand All @@ -106,14 +114,15 @@ test("navigates Events, subscriptions and exact client connections through acces
await expect(eventOccurrences.getByRole("row")).toHaveCount(11);
expect(historyRequests.event).toEqual([null, "event-page-two"]);
expect(fullPayloadRequests).toEqual([]);
expect(subscriptionListRequests).toBe(0);
await page.goto(origin + "/clients/primary");
const subscriptions = page.getByRole("table", { name: "Event subscriptions" });
await expect(subscriptions.getByRole("columnheader")).toHaveText(["Client", "Event", "Status", "Acknowledgment mode", "Expires", "Cooldown ends"]);
await expect(subscriptions.getByRole("row")).toHaveCount(3);
await expect(subscriptions.getByRole("columnheader")).toHaveText(["Event", "Status", "Acknowledgment mode", "Expires", "Cooldown ends"]);
await expect(subscriptions.getByRole("row")).toHaveCount(2);
await expect(subscriptions.getByRole("cell", { name: "Required" })).toBeVisible();
await expect(subscriptions.getByRole("cell", { name: "Expired" })).toBeVisible();
await expect(subscriptions.getByRole("cell", { name: "Expired" })).toHaveCount(0);
const endTime = subscriptions.locator(`time[datetime="${cooldownEnd}"]`);
await expect(endTime).toHaveCount(1);
await expect(subscriptions.locator(`time[datetime="${legacyCooldownEnd}"]`)).toHaveCount(1);
await expect(endTime).toBeVisible();
await subscriptions.getByRole("link", { name: /aaaaaaaa/ }).click();
await expect(page).toHaveURL(origin + "/events/subscriptions/" + requiredId);
await expect(page.getByText(requiredId, { exact: true })).toBeVisible();
Expand All @@ -135,25 +144,18 @@ test("navigates Events, subscriptions and exact client connections through acces
expect(historyRequests.subscription).toEqual([null, "subscription-page-two"]);
expect(fullPayloadRequests).toEqual([]);

await nav.getByRole("link", { name: "Subscriptions" }).click();
await expect(subscriptions.getByRole("row")).toHaveCount(4);
await expect(subscriptions.getByRole("columnheader", { name: "Cooldown ends" })).toBeVisible();
await expect(endTime).toBeVisible();
await expect(subscriptions.getByRole("cell", { name: "Not recorded" })).toBeVisible();
await page.goto(origin + "/clients/secondary");
await expect(subscriptions.getByRole("row")).toHaveCount(3);
await expect(subscriptions.getByRole("cell", { name: "Expired" })).toBeVisible();
await subscriptions.getByRole("link", { name: /bbbbbbbb/ }).click();
await expect(page.getByText("Last cooldown started", { exact: true })).toBeVisible();
await expect(page.getByText("Not recorded", { exact: true })).toBeVisible();
await expect(subscriptions.locator(`time[datetime="${legacyCooldownEnd}"]`)).toBeVisible();
await nav.getByRole("link", { name: "Subscriptions" }).click();
await subscriptions.getByRole("link", { name: "Order assistant" }).click();
await expect(page).toHaveURL(origin + "/clients/primary");
await expect(subscriptions.getByRole("columnheader")).toHaveText(["Event", "Status", "Acknowledgment mode", "Expires", "Cooldown ends"]);
await expect(subscriptions.getByRole("row")).toHaveCount(2);
await expect(endTime).toBeVisible();
await expect(subscriptions.getByRole("cell", { name: "Required" })).toBeVisible();
await expect(subscriptions.getByRole("cell", { name: "Expired" })).toHaveCount(0);
await page.getByRole("link", { name: "Back to Events" }).click();
await expect(page).toHaveURL(origin + "/events");

await page.goto(origin + "/events");
await page.goto(origin + "/events/subscriptions");
await expect(page).toHaveURL(origin + "/events");
const description = await events.getByRole("cell", { name: "New orders" }).boundingBox();
expect(description).not.toBeNull();
await page.mouse.click(description.x + description.width / 2, description.y + description.height / 2);
Expand All @@ -162,7 +164,7 @@ test("navigates Events, subscriptions and exact client connections through acces
await page.getByRole("button", { name: "Delete", exact: true }).click();
await expect(page).toHaveURL(origin + "/events");
await expect(events.getByRole("link", { name: "orders.created" })).toHaveCount(0);
await nav.getByRole("link", { name: "Subscriptions" }).click();
await page.goto(origin + "/clients/secondary");
await expect(subscriptions.getByRole("row")).toHaveCount(2);
await expect(subscriptions.getByRole("link", { name: /orders.shipped/ })).toBeVisible();
});
Loading