Skip to content

Commit 96a1f7a

Browse files
committed
feat(plugin-sharing): sys_queue record page lists its members by queue name
The organization's queue gets a default full record page whose members list reads sys_queue_member keyed on `queue` = this queue's `name` (relationshipValueField), so the console's filter and its "New" prefill both carry the name the member rows store. sys_queue_member.queue is unchanged. Declared queues have no sys_queue row and so no page. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cyf254wVgypzQ5Uj1a
1 parent 2a14593 commit 96a1f7a

6 files changed

Lines changed: 335 additions & 16 deletions

File tree

‎packages/plugins/plugin-sharing/scripts/i18n-extract.config.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
* recognised flag spelling out of this whole comment, so a second spelling
3535
* would keep the opt-in switched on after someone deleted it from the command
3636
* block — the one place that decides.
37+
*
38+
* `pages` declares the record page this plugin ships (`sys_queue_detail`).
39+
* The command above writes the objects sub-tree only, so the page's one bundle
40+
* key, its page-level `label`, is HAND-AUTHORED in `src/translations/pages.ts`
41+
* and rides in the `translations` baseline below. Declaring the page here is
42+
* what puts its label in the coverage ratchet's population.
3743
*/
3844

3945
import { defineStack, type ObjectStackDefinition } from '@objectstack/spec';
@@ -42,6 +48,8 @@ import { enObjects } from '../src/translations/en.objects.generated.js';
4248
import { zhCNObjects } from '../src/translations/zh-CN.objects.generated.js';
4349
import { jaJPObjects } from '../src/translations/ja-JP.objects.generated.js';
4450
import { esESObjects } from '../src/translations/es-ES.objects.generated.js';
51+
import { SysQueueDetailPage } from '../src/sys-queue.page.js';
52+
import { sharingPageTranslations } from '../src/translations/pages.js';
4553

4654
/**
4755
* The annotation is load-bearing, not decoration (#10868). `defineStack`
@@ -59,11 +67,12 @@ import { esESObjects } from '../src/translations/es-ES.objects.generated.js';
5967
*/
6068
const config: ObjectStackDefinition = defineStack({
6169
objects: [SysRecordShare, SysSharingRule, SysShareLink, SysQueue, SysQueueMember] as any,
70+
pages: [SysQueueDetailPage],
6271
translations: [
63-
{ en: { objects: enObjects } },
64-
{ 'zh-CN': { objects: zhCNObjects } },
65-
{ 'ja-JP': { objects: jaJPObjects } },
66-
{ 'es-ES': { objects: esESObjects } },
72+
{ en: { objects: enObjects, pages: sharingPageTranslations.en } },
73+
{ 'zh-CN': { objects: zhCNObjects, pages: sharingPageTranslations['zh-CN'] } },
74+
{ 'ja-JP': { objects: jaJPObjects, pages: sharingPageTranslations['ja-JP'] } },
75+
{ 'es-ES': { objects: esESObjects, pages: sharingPageTranslations['es-ES'] } },
6776
],
6877
});
6978

‎packages/plugins/plugin-sharing/src/sharing-plugin.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
SysQueueMember,
5858
SysAssignmentCursor,
5959
} from './objects/index.js';
60+
import { SysQueueDetailPage } from './sys-queue.page.js';
6061
import { OwnershipQueueService, specsReadBusinessUnits, type OwnershipQueueEngine } from './ownership-queue-service.js';
6162
import { bindQueueGuards, bindQueueRecipientRecompute, reportShadowedAuthoredQueues } from './queue-hooks.js';
6263
import { SysBusinessUnit, SysBusinessUnitMember } from '@objectstack/platform-objects/identity';
@@ -652,6 +653,9 @@ export class SharingServicePlugin implements Plugin {
652653
SysQueueMember,
653654
SysAssignmentCursor,
654655
],
656+
// The queue's record page: its fields, and its members listed by the
657+
// queue's name with "New" pre-filled (`sys-queue.page.ts`).
658+
pages: [SysQueueDetailPage],
655659
// ADR-0029 D7 — contribute the sharing entries into the Setup app's
656660
// `group_access_control` slot (priority 200). This plugin owns these
657661
// objects (K2).
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* `sys_queue`'s record page (`sys-queue.page.ts`): an organization's queue
5+
* lists its members, keyed by the queue's NAME, with "New" pre-filled.
6+
*
7+
* No published page keyed a related list on `relationshipValueField: 'name'`
8+
* before this one, so both halves of what the console does with the key are
9+
* pinned here, read off the page and never retyped:
10+
*
11+
* - the FILTER: the list reads `sys_queue_member` where
12+
* `{ [relationshipField]: queue[relationshipValueField] }`;
13+
* - the "New" PREFILL: the member form opens with `relationshipField` set to
14+
* that same value, and "New" is not withheld (no authored `actions: []`).
15+
*
16+
* Both are measured on a REAL engine (ObjectQL + SqlDriver over in-memory
17+
* SQLite) carrying the shipped `sys_queue` / `sys_queue_member`, and the row
18+
* the prefilled form writes is the row the ownership-queue service expands as
19+
* a member: the list and the service agree on who is in the queue.
20+
*/
21+
22+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
23+
import { ObjectQL } from '@objectstack/objectql';
24+
import { SqlDriver } from '@objectstack/driver-sql';
25+
import { SysOrganization } from '@objectstack/platform-objects/identity';
26+
import { PageSchema, ComponentPropsMap } from '@objectstack/spec/ui';
27+
import { SysQueue, SysQueueMember } from './objects/index.js';
28+
import { SysQueueDetailPage } from './sys-queue.page.js';
29+
import { OwnershipQueueService } from './ownership-queue-service.js';
30+
import { SharingTranslations } from './translations/index.js';
31+
import { sharingPageTranslations } from './translations/pages.js';
32+
33+
type AnyRec = Record<string, any>;
34+
35+
const SYS = { isSystem: true, userId: 'usr_admin' } as any;
36+
const ORG = 'org_qa';
37+
38+
const PAGE = SysQueueDetailPage as AnyRec;
39+
const COMPONENTS = (PAGE.regions?.[0]?.components ?? []) as AnyRec[];
40+
const nodeOf = (type: string): AnyRec => COMPONENTS.find((c) => c.type === type) ?? {};
41+
const MEMBERS = nodeOf('record:related_list').properties as AnyRec;
42+
43+
describe('sys_queue record page — the page', () => {
44+
it('is the default full record page of sys_queue, and parses as a page', () => {
45+
expect(PAGE).toMatchObject({ name: 'sys_queue_detail', type: 'record', object: 'sys_queue', kind: 'full', isDefault: true });
46+
const parsed = PageSchema.safeParse(PAGE);
47+
expect(parsed.success, JSON.stringify(parsed.error?.issues ?? [])).toBe(true);
48+
});
49+
50+
it('every node\'s props parse against its own component props row', () => {
51+
const map = ComponentPropsMap as Record<string, { safeParse: (v: unknown) => { success: boolean } }>;
52+
const bad = COMPONENTS.filter((c) => !map[c.type]?.safeParse(c.properties ?? {}).success).map((c) => c.type);
53+
expect(bad).toEqual([]);
54+
});
55+
56+
it('authors the header, the strip, the details, the members and the discussion, in that order', () => {
57+
expect(COMPONENTS.map((c) => c.type)).toEqual([
58+
'page:header', 'record:highlights', 'record:details', 'record:related_list', 'record:discussion',
59+
]);
60+
// The strip is the object's highlightFields minus the title field.
61+
expect(nodeOf('record:highlights').properties.fields)
62+
.toEqual((SysQueue.highlightFields ?? []).filter((f: string) => f !== SysQueue.nameField));
63+
// The details draw every field the queue declares.
64+
expect([...nodeOf('record:details').properties.fields].sort()).toEqual(Object.keys(SysQueue.fields).sort());
65+
});
66+
67+
it('the members list is sys_queue_member keyed by the queue NAME, and "New" is not withheld', () => {
68+
expect(MEMBERS).toMatchObject({ objectName: 'sys_queue_member', relationshipField: 'queue', relationshipValueField: 'name' });
69+
expect(MEMBERS.actions).toBeUndefined();
70+
// The two sides of the key: the member's `queue` is text holding a name,
71+
// and the queue's `name` is the identity every reference uses.
72+
expect((SysQueueMember.fields as AnyRec).queue).toMatchObject({ type: 'text', required: true });
73+
expect((SysQueue.indexes ?? []).some((i: AnyRec) => i.unique && i.fields?.join() === 'name')).toBe(true);
74+
const memberFields = Object.keys(SysQueueMember.fields);
75+
const columns = MEMBERS.columns as string[];
76+
expect(columns.filter((c) => !memberFields.includes(c) && c !== 'updated_at')).toEqual([]);
77+
});
78+
79+
it('its label is translated in every shipped locale, `en` byte-equal to the page literal', () => {
80+
expect(sharingPageTranslations.en.sys_queue_detail?.label).toBe(PAGE.label);
81+
for (const [locale, bundle] of Object.entries(SharingTranslations)) {
82+
expect((bundle as AnyRec).pages?.sys_queue_detail?.label, locale)
83+
.toBe((sharingPageTranslations as AnyRec)[locale].sys_queue_detail.label);
84+
}
85+
});
86+
});
87+
88+
describe('sys_queue record page — the members list on a real engine', () => {
89+
let engine: ObjectQL;
90+
let billing: AnyRec;
91+
92+
/** The rows the page's list shows on `queue`'s page. */
93+
const listedOn = async (queue: AnyRec): Promise<AnyRec[]> =>
94+
(await engine.find('sys_queue_member', {
95+
where: { [MEMBERS.relationshipField]: queue[MEMBERS.relationshipValueField] },
96+
context: SYS,
97+
})) as AnyRec[];
98+
/** What the prefilled "New" form carries before the administrator fills in the member. */
99+
const prefilledNew = (queue: AnyRec): AnyRec => ({ [MEMBERS.relationshipField]: queue[MEMBERS.relationshipValueField] });
100+
101+
beforeAll(async () => {
102+
const driver = new SqlDriver({ client: 'better-sqlite3', connection: { filename: ':memory:' }, useNullAsDefault: true });
103+
await driver.connect();
104+
engine = new ObjectQL();
105+
engine.registerDriver(driver as never, true);
106+
await engine.init();
107+
for (const def of [SysOrganization, SysQueue, SysQueueMember]) {
108+
engine.registry.registerObject(def as never, 'plugin-sharing', 'sys');
109+
}
110+
await engine.syncSchemas();
111+
await engine.insert('sys_organization', { id: ORG, name: 'QA Org', slug: 'qa-org' }, { context: SYS });
112+
113+
billing = (await engine.insert('sys_queue', { name: 'billing', label: 'Billing', organization_id: ORG }, { context: SYS })) as AnyRec;
114+
await engine.insert('sys_queue', { name: 'support', label: 'Support', organization_id: ORG }, { context: SYS });
115+
for (const [queue, type, id] of [
116+
['billing', 'user', 'u_ada'],
117+
['billing', 'position', 'billing_clerk'],
118+
['support', 'user', 'u_bob'],
119+
] as const) {
120+
await engine.insert('sys_queue_member', { queue, recipient_type: type, recipient_id: id, organization_id: ORG }, { context: SYS });
121+
}
122+
});
123+
124+
afterAll(async () => {
125+
try { await engine?.destroy(); } catch { /* noop */ }
126+
});
127+
128+
it('the FILTER: a queue\'s page lists its own members, by name, and no other queue\'s', async () => {
129+
// Control: keyed on the id, the default, the list would find nothing — the
130+
// members store the name, which is why the page names `name`.
131+
expect(billing.id).not.toBe(billing.name);
132+
expect(await engine.find('sys_queue_member', { where: { queue: billing.id }, context: SYS })).toEqual([]);
133+
134+
const listed = await listedOn(billing);
135+
expect(listed.map((m) => `${m.recipient_type}:${m.recipient_id}`).sort()).toEqual(['position:billing_clerk', 'user:u_ada']);
136+
});
137+
138+
it('the "New" PREFILL: the form carries the queue\'s name, and the member it saves is listed on the page', async () => {
139+
const draft = prefilledNew(billing);
140+
expect(draft).toEqual({ queue: 'billing' });
141+
await engine.insert(
142+
'sys_queue_member',
143+
{ ...draft, recipient_type: 'user', recipient_id: 'u_cy', organization_id: ORG },
144+
{ context: SYS },
145+
);
146+
expect((await listedOn(billing)).map((m) => m.recipient_id)).toContain('u_cy');
147+
});
148+
149+
it('the list and the ownership-queue service agree on who is in the queue', async () => {
150+
const service = new OwnershipQueueService({ engine: () => engine as never });
151+
const resolved = await service.resolveQueue(billing.name, ORG);
152+
expect(resolved?.source).toBe('authored');
153+
const listed = (await listedOn(billing)).map((m) => `${m.recipient_type}:${m.recipient_id}`).sort();
154+
expect((resolved?.members ?? []).map((m) => `${m.type}:${m.value}`).sort()).toEqual(listed);
155+
});
156+
});
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
import type { Page } from '@objectstack/spec/ui';
4+
5+
/**
6+
* sys_queue — Record Detail Page (`kind: 'full'`, default for ALL sys_queue
7+
* records).
8+
*
9+
* **Audience**: an administrator managing an organization's own queue in
10+
* Setup → Queues, who needs to see and change who is in it without switching
11+
* to the separate Queue Members list.
12+
*
13+
* ## The members list, keyed by NAME
14+
*
15+
* A member row names its queue by the queue's machine name:
16+
* `sys_queue_member.queue` is a text column holding `sys_queue.name`, the key
17+
* every queue reference uses (ADR-0142 D1/D2), and it stays that. So the list
18+
* declares `relationshipValueField: 'name'`: the console filters
19+
* `sys_queue_member` on `queue` equal to this queue's `name`, and its "New"
20+
* opens the member form with `queue` filled in with that name. A member added
21+
* here is the row the ownership-queue service expands, under the same name.
22+
*
23+
* Declared queues are out: a package's queue is a registry item with no
24+
* `sys_queue` row (ADR-0131 D6, regime C), so it has no record page. An
25+
* organization's member rows under a declared queue's name are listed on the
26+
* Queue Members list, as before.
27+
*
28+
* ## The nodes
29+
*
30+
* - `page:header` with `placedActions: true`: the synthesized header's
31+
* action set, read live.
32+
* - `record:highlights` over the object's `highlightFields` minus the title
33+
* field `name` (the H1).
34+
* - `record:details` with the queue's fields. A `full` page draws only what
35+
* it authors, and a bare node draws the object's `highlightFields`, so the
36+
* fields are spelled out.
37+
* - the members `record:related_list` above.
38+
* - `record:discussion`, the synthesized discussion footer.
39+
*
40+
* Copy inside the components is authored as inline locale maps, the ruled
41+
* route for page prose; the page-level `label` is the one key a translation
42+
* bundle reaches (`pages.sys_queue_detail.label`, in `translations/pages.ts`).
43+
*/
44+
export const SysQueueDetailPage: Page = {
45+
name: 'sys_queue_detail',
46+
label: 'Queue',
47+
type: 'record',
48+
object: 'sys_queue',
49+
template: 'default',
50+
kind: 'full',
51+
isDefault: true,
52+
53+
regions: [
54+
{
55+
name: 'main',
56+
width: 'full',
57+
components: [
58+
{ type: 'page:header', properties: { placedActions: true } },
59+
60+
{ type: 'record:highlights', properties: { fields: ['label'] } },
61+
62+
{ type: 'record:details', properties: { fields: ['name', 'label', 'description'] } },
63+
64+
{
65+
type: 'record:related_list',
66+
properties: {
67+
objectName: 'sys_queue_member',
68+
relationshipField: 'queue',
69+
// The member row stores the queue's NAME, not its id.
70+
relationshipValueField: 'name',
71+
columns: ['recipient_type', 'recipient_id', 'updated_at'],
72+
sort: [{ field: 'recipient_type', order: 'asc' }],
73+
limit: 50,
74+
showViewAll: true,
75+
title: { en: 'Members', 'zh-CN': '成员', 'ja-JP': 'メンバー', 'es-ES': 'Miembros' },
76+
},
77+
},
78+
79+
{ type: 'record:discussion' },
80+
],
81+
},
82+
],
83+
};

‎packages/plugins/plugin-sharing/src/translations/index.ts‎

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
* SharingTranslations — i18n bundle owned by this plugin (ADR-0029 D8).
55
*
66
* Object label/field/view/action translations for the sys_* objects this
7-
* plugin owns. Loaded at runtime via the plugin's `kernel:ready` hook
8-
* (`i18n.loadTranslations`). Regenerate with `os i18n extract` against
9-
* `scripts/i18n-extract.config.ts`.
7+
* plugin owns, plus the `pages` entry of the record page it ships. Loaded at
8+
* runtime via the plugin's `kernel:ready` hook (`i18n.loadTranslations`).
9+
* Regenerate the `objects` bundles with `os i18n extract` against
10+
* `scripts/i18n-extract.config.ts`; the `pages` entry is hand-authored in
11+
* `./pages.ts`.
1012
*/
1113

1214
import type { TranslationBundle, TranslationData } from '@objectstack/spec/system';
@@ -18,6 +20,7 @@ import { esESObjects } from './es-ES.objects.generated.js';
1820
import { zhCNGeneratedSourceHashes } from './zh-CN.source-hashes.generated.js';
1921
import { jaJPGeneratedSourceHashes } from './ja-JP.source-hashes.generated.js';
2022
import { esESGeneratedSourceHashes } from './es-ES.source-hashes.generated.js';
23+
import { sharingPageTranslations, sharingPageSourceHashes } from './pages.js';
2124

2225
/**
2326
* ## The provenance companions are READ here, not merely recorded
@@ -36,21 +39,31 @@ import { esESGeneratedSourceHashes } from './es-ES.source-hashes.generated.js';
3639
* before it can testify. So the only reader-visible consequence was the wrong
3740
* string on the page.
3841
*
39-
* `recorded` (3rd argument) stays `undefined` on purpose: it judges the
40-
* HAND-AUTHORED sections (`apps` / `dashboards` / `pages`), which this set does
41-
* not have — its bundles are entirely generated. The companion goes in the 4th
42-
* slot, which judges the generated ones. This is the shape
43-
* `@objectstack/platform-objects`'s own `metadata-translations/index.ts` uses.
42+
* `recorded` (3rd argument) judges the HAND-AUTHORED sections (`apps` /
43+
* `dashboards` / `pages`). This set has exactly one: the `pages` entry of the
44+
* record page the plugin ships (`./pages.ts`), whose recorded digests go there.
45+
* The generated companion goes in the 4th slot, which judges the generated
46+
* `objects` bundles. Two tables, two predicates — the shape
47+
* `@objectstack/plugin-approvals` uses for its own record page.
4448
*
4549
* ⛔ Do not drop the 4th argument to quiet a staleness report. Serving the
4650
* superseded draft is the bug; `check:i18n-stale-fill`'s UNSERVED PROVENANCE
4751
* verdict fails the build if a committed companion stops being consulted here.
4852
*/
49-
const enSource: TranslationData = { objects: enObjects };
53+
const enSource: TranslationData = { objects: enObjects, pages: sharingPageTranslations.en };
5054

5155
export const SharingTranslations: TranslationBundle = {
5256
en: enSource,
53-
'zh-CN': withSourceFallback({ objects: zhCNObjects }, enSource, undefined, zhCNGeneratedSourceHashes),
54-
'ja-JP': withSourceFallback({ objects: jaJPObjects }, enSource, undefined, jaJPGeneratedSourceHashes),
55-
'es-ES': withSourceFallback({ objects: esESObjects }, enSource, undefined, esESGeneratedSourceHashes),
57+
'zh-CN': withSourceFallback(
58+
{ objects: zhCNObjects, pages: sharingPageTranslations['zh-CN'] },
59+
enSource, sharingPageSourceHashes['zh-CN'], zhCNGeneratedSourceHashes,
60+
),
61+
'ja-JP': withSourceFallback(
62+
{ objects: jaJPObjects, pages: sharingPageTranslations['ja-JP'] },
63+
enSource, sharingPageSourceHashes['ja-JP'], jaJPGeneratedSourceHashes,
64+
),
65+
'es-ES': withSourceFallback(
66+
{ objects: esESObjects, pages: sharingPageTranslations['es-ES'] },
67+
enSource, sharingPageSourceHashes['es-ES'], esESGeneratedSourceHashes,
68+
),
5669
};

0 commit comments

Comments
 (0)