Manage paired displays: themed select, reassignment, live list, no revoked clutter
CI / verify (pull_request) Successful in 1m14s
CI / infrastructure-smoke (pull_request) Successful in 37s
CI / package-release (pull_request) Successful in 52s
CI / migration-smoke (pull_request) Successful in 2m28s
CI / image-build (pull_request) Successful in 1m9s
CI / deploy-smoke (same-origin) (pull_request) Successful in 45s
CI / package-publication (pull_request) Successful in 54s
CI / deploy-smoke (split) (pull_request) Successful in 8m58s

Real-device review of the platform display flow found four defects in
display management:

- Shared SelectMenu in @ekklesia/ui (additive): an Ekklesia-drawn
  single choice following the WAI-ARIA select-only combobox pattern,
  replacing the native select for "Show on this screen". It has a
  themed list, a chevron inside the control, keyboard support (arrows,
  Home/End, type-ahead, Enter/Space/Tab, and Escape that closes only
  the list), pointer and touch support, and focus that stays on the
  control. It is an ek-control, so it keeps the 16px phone size.
- Newly paired displays appear without a reload. Approval doesn't
  create the display; the screen does when it claims its credential a
  few seconds later. The page now shows a "Waiting for the screen to
  connect" placeholder and refetches every second until the new display
  appears (for up to a minute), and refreshes the list every 30
  seconds.
- What a display shows can change after pairing. In the single-target
  Stage 1 model, a display's current target is its one active display
  permission, so no migration is needed.
  PUT /api/v1/devices/:id/display, with core.devices.manage, a trusted
  origin and a bounded body, revokes its other active permission rows
  (kept as history) and grants the chosen module's declared display
  permission, in one transaction on the same device. The screen notices
  within about 30 seconds: a paired device on a module page that is no
  longer set to show it goes to /display/setup instead of re-pairing,
  and /display/setup opens the new target.
- Revoked displays leave the normal list at once. Their rows stay in
  the database as history.

Each display card now shows its name, Online/Offline/Not connected yet,
"Showing: ...", last seen and paired dates, and Change and Revoke.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
ekklesia
2026-10-16 18:29:15 -05:00
co-authored by Claude Opus 5.5
parent 300d9eab51
commit d9dafcb0f7
18 changed files with 1892 additions and 197 deletions
+72 -1
View File
@@ -1,6 +1,6 @@
import { createHash, randomBytes, randomInt } from "node:crypto";
import type { EkklesiaDeviceId, EkklesiaUserId, PermissionId } from "@ekklesia/contracts";
import { and, eq, gt, isNull, lt, or, sql } from "drizzle-orm";
import { and, eq, gt, isNull, lt, ne, or, sql } from "drizzle-orm";
import type { DeviceDrizzleDatabase } from "./database.js";
import {
ekklesiaCoreDevice,
@@ -184,6 +184,22 @@ export interface DeviceStore {
listDevices(): Promise<readonly DeviceSummary[]>;
/** A live, unrevoked device's own name and active permissions, or `undefined`. */
describeDevice(deviceId: EkklesiaDeviceId): Promise<DeviceSelf | undefined>;
/**
* Sets what a live display shows (ADR 0065): the one module display permission it holds, or none.
*
* In this single-target model a display's active display permission *is* its current target, so
* there is one source of truth for "may it show this" and "is it showing this". The change is one
* transaction on the same device: every other active permission row is revoked — kept, with its
* `revokedAt`, as history — and the new permission is granted if the device does not already hold
* it. The device row, its name, and its credential never change. Returns `false` for a device that
* does not exist or is revoked.
*/
setDisplayTarget(input: {
readonly deviceId: EkklesiaDeviceId;
readonly permissionId: PermissionId | undefined;
readonly changedBy: EkklesiaUserId;
readonly now: Date;
}): Promise<boolean>;
revokeDevice(input: {
readonly deviceId: EkklesiaDeviceId;
readonly revokedBy: EkklesiaUserId;
@@ -576,6 +592,61 @@ export function createDeviceStore(db: DeviceDrizzleDatabase): DeviceStore {
}
},
async setDisplayTarget(input): Promise<boolean> {
try {
return await db.transaction(async (tx) => {
// Locks the device row, so a concurrent revoke or change waits rather than interleaving.
const devices = await tx
.select({ id: ekklesiaCoreDevice.id })
.from(ekklesiaCoreDevice)
.where(
and(eq(ekklesiaCoreDevice.id, input.deviceId), isNull(ekklesiaCoreDevice.revokedAt)),
)
.for("update")
.limit(1);
if (devices.length === 0) {
return false;
}
const target = input.permissionId;
await tx
.update(ekklesiaCoreDevicePermission)
.set({ revokedAt: input.now })
.where(
and(
eq(ekklesiaCoreDevicePermission.deviceId, input.deviceId),
isNull(ekklesiaCoreDevicePermission.revokedAt),
...(target === undefined
? []
: [ne(ekklesiaCoreDevicePermission.permissionId, target)]),
),
);
if (target !== undefined) {
const held = await tx
.select({ id: ekklesiaCoreDevicePermission.id })
.from(ekklesiaCoreDevicePermission)
.where(
and(
eq(ekklesiaCoreDevicePermission.deviceId, input.deviceId),
eq(ekklesiaCoreDevicePermission.permissionId, target),
isNull(ekklesiaCoreDevicePermission.revokedAt),
),
)
.limit(1);
if (held.length === 0) {
await tx.insert(ekklesiaCoreDevicePermission).values({
deviceId: input.deviceId,
grantedByUserId: input.changedBy,
permissionId: target,
});
}
}
return true;
});
} catch (error) {
rethrowAsStoreError(error);
}
},
async revokeDevice(input): Promise<void> {
try {
const rows = await db