Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit cd14d8e

Browse files
fix(plugin-grid,types): read bulk confirmText as a string or a template envelope (#13319)
Refs #13183 Step 1 of the landing order for objectstack-ai/objectstack#24947 (the order set in the seat-hold comment 6296947690 on objectstack-ai/objectstack#24798): objectui reads a bulk action's `confirmText` in both shapes, so objectstack's `.objectui-sha` can move past this before objectstack-ai/objectstack#24947 lands. The fill step of #13183 (`{{ count }}`, then the param roots) is not part of this PR, so #13183 remains open. ## What changes - `@object-ui/types`: `BulkActionDef.confirmText` is `string | { dialect?: 'template'; source: string }`. The envelope arm is the shape objectstack-ai/objectstack#24947 serves: there a bare string is shorthand for `{ dialect: 'template', source }`, and a parsed def carries the envelope (read from `BulkConfirmTextSchema` in objectstack-ai/objectstack#24947's `packages/spec/src/ui/bulk-action.zod.ts`; a blank string still parses as itself there). - `@object-ui/types` zod mirror: `ObjectGridBulkActionDefSchema.confirmText` takes the same two arms. The `zod-mirror-parity` ledger (`assertionDriftMatchesLedger`) compares the mirror with the interface member for member and went red on the type change alone. This file was not in the claim's declared file surface; it is the same member's mirror in the same package. - `@object-ui/plugin-grid`: new helper `bulkConfirmTextSource` (in `components/bulkConfirmText.ts`) returns the string, or the envelope's `source` verbatim, and `undefined` when the value is absent, blank or has no string `source`. It follows the precedent of core's `formatTitleTemplate`, which reads `titleFormat` as `string | { source }`. `BulkActionDialog`'s confirm step renders through it and keeps the default sentence (`grid.bulk.confirmDefault`) when it returns `undefined`. Holes are not filled. - Changeset: `.changeset/13183-bulk-confirm-text-envelope.md` (patch, types + plugin-grid). Behaviour change to note: a blank `confirmText` (`''` or whitespace) used to render an empty description, because the dialog used `??`. It now shows the default sentence, as the claim asked. ## Other readers of a bulk def's confirmText Grepped every `confirmText` in `packages/*/src` and `apps/*/src`. `BulkActionDialog` is the only place that reads a bulk def's `confirmText` for display. The others either read an object action's `confirmText` (a different slot; objectstack-ai/objectstack#24947 does not change it), for example `toBulkActionDef` in `resolveBulkActions.ts`, which forwards `action.confirmText` only when it is a string, or just destructure it away (`stripCollectedActionKeys` in `ObjectGrid.tsx`). No other TypeScript module outside plugin-grid and types imports `BulkActionDef`. objectui has no i18n extractor for bulk defs; the extractor gap is on the objectstack side and objectstack-ai/objectstack#24947 fixes it. ## Verification (head fef2d04) - `pnpm exec vitest run --maxWorkers=2 packages/types/ packages/plugin-grid/`: Test Files 629 passed (629), Tests 12745 passed (12745). - New test file `packages/plugin-grid/src/__tests__/bulkConfirmTextEnvelope-13183.test.tsx`, 10 tests. Reader: string, envelope, envelope without `dialect`, blank string or blank source, absent or null, envelope with no source. Real `BulkActionDialog`: the envelope's source is the sentence and `[object Object]` is absent; a plain string renders unchanged; absent and blank keep the default sentence. - Reverse check: with the render site set back to `def.confirmText` (committed fix first, mutation checked on disk, then restored with `git checkout HEAD`; restore proven by an empty `git diff HEAD` and a matching HEAD blob hash), 2 failed and 8 passed: "renders an envelope's source, never [object Object]" and "keeps the default sentence when the slot is blank". - `pnpm --filter @object-ui/types --filter @object-ui/plugin-grid run type-check`: exit 0, both scripts named in the output, after building plugin-grid's dependency closure (13 turbo tasks). - `apps/console/src/__tests__/registry-inputs-spec-parity.test.ts`: 260 passed. - eslint on the 5 touched source and test files: 0 errors (warnings only, `no-explicit-any` and hook warnings already in the files plus two `as any` casts in the new test). The repo-wide lint is left to CI. - Gates: `check:new-line-citations`, `check:control-bytes`, `check:spec-symbols`, `check:changeset-claims`, `check:pending-changeset-literals`, `check:unreferenced-sources`, `check:test-path-roots` and `scripts/check-changeset-presence.mjs` all exit 0. ## Acceptance notes - The `@object-ui/types` member is widened ahead of the installed spec, which still types the slot as a plain string. The claim's order asks for this (a renderer that reads both shapes, Clause-2 no). When objectstack-ai/objectstack#24947 is released and pinned here, the `string` arm stays: a bare string is still valid authoring. - The commit `bbb06a1f1` carries a `Refs #13183` line in its message body. Force-push is not allowed in this repo, so it stays. --- _Generated by [Claude Code](https://claude.ai/code/session_01D6F9axfoPzR7t8G1J7Ytzz)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 56cf4d8 commit cd14d8e

6 files changed

Lines changed: 176 additions & 4 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@object-ui/types': patch
3+
'@object-ui/plugin-grid': patch
4+
---
5+
6+
The bulk action confirm step reads `confirmText` as a string or as a `{ dialect: 'template', source }` envelope (objectui#13183).
7+
8+
`@objectstack/spec` is making a bulk action's `confirmText` a `template` slot (objectstack#24947), so a parsed bulk definition serves the envelope where it served a string. The confirm step rendered `confirmText` as it came, so an envelope would have broken it. It now shows the string, or the envelope's `source` as written; a blank or absent value still shows the default sentence ("This will apply to N record(s)."). `{{ }}` holes are not filled yet: `{{ count }}` still shows as written. `BulkActionDef.confirmText` in `@object-ui/types` is typed `string | { dialect?: 'template'; source: string }`, and `@object-ui/plugin-grid` reads it through one helper, `bulkConfirmTextSource`.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectui#13183 step 1 — a bulk action's `confirmText` is read as a string or
11+
* as the `{ dialect: 'template', source }` envelope the protocol serves once
12+
* objectstack#24947 makes the slot a `template` slot.
13+
*
14+
* Two halves:
15+
* - the reader `bulkConfirmTextSource`: a string, an envelope (with and
16+
* without `dialect`), blank and absent values;
17+
* - the real `BulkActionDialog`: an envelope's `source` is the confirm
18+
* sentence (never `[object Object]`), a plain string renders unchanged, and
19+
* a blank or absent value keeps the default sentence.
20+
* Holes are not filled at this step: `{{ count }}` stays as written.
21+
*/
22+
import { describe, it, expect, vi, beforeAll } from 'vitest';
23+
import React from 'react';
24+
import { render, screen, cleanup } from '@testing-library/react';
25+
import '@testing-library/jest-dom';
26+
import type { BulkActionDef } from '@object-ui/types';
27+
28+
import { BulkActionDialog } from '../components/BulkActionDialog';
29+
import { bulkConfirmTextSource } from '../components/bulkConfirmText';
30+
31+
beforeAll(() => {
32+
if (!Element.prototype.scrollIntoView) {
33+
Element.prototype.scrollIntoView = vi.fn() as any;
34+
}
35+
});
36+
37+
describe('bulkConfirmTextSource (objectui#13183)', () => {
38+
it('returns a plain string as written', () => {
39+
expect(bulkConfirmTextSource('Archive these accounts?')).toBe('Archive these accounts?');
40+
});
41+
42+
it("returns an envelope's source verbatim, holes unfilled", () => {
43+
expect(
44+
bulkConfirmTextSource({ dialect: 'template', source: 'Update {{ count }} record(s)?' }),
45+
).toBe('Update {{ count }} record(s)?');
46+
});
47+
48+
it('reads an envelope that omits `dialect`', () => {
49+
expect(bulkConfirmTextSource({ source: 'Close these deals?' })).toBe('Close these deals?');
50+
});
51+
52+
it('returns undefined for a blank string or a blank source', () => {
53+
expect(bulkConfirmTextSource('')).toBeUndefined();
54+
expect(bulkConfirmTextSource(' ')).toBeUndefined();
55+
expect(bulkConfirmTextSource({ dialect: 'template', source: ' ' })).toBeUndefined();
56+
});
57+
58+
it('returns undefined when absent', () => {
59+
expect(bulkConfirmTextSource(undefined)).toBeUndefined();
60+
expect(bulkConfirmTextSource(null)).toBeUndefined();
61+
});
62+
63+
it('returns undefined for an envelope with no string source', () => {
64+
expect(bulkConfirmTextSource({ dialect: 'template' } as never)).toBeUndefined();
65+
});
66+
});
67+
68+
const ROWS = [{ id: 'r1', name: 'Acme' }, { id: 'r2', name: 'Globex' }];
69+
70+
function openConfirm(confirmText: BulkActionDef['confirmText']) {
71+
cleanup();
72+
const def: BulkActionDef = {
73+
name: 'archive',
74+
label: 'Archive',
75+
operation: 'update',
76+
patch: { archived: true },
77+
...(confirmText !== undefined && { confirmText }),
78+
};
79+
render(
80+
<BulkActionDialog
81+
def={def}
82+
rows={ROWS}
83+
resource="account"
84+
dataSource={{ update: vi.fn(async () => ({})), delete: vi.fn(async () => ({})) } as any}
85+
open
86+
onClose={() => {}}
87+
/>,
88+
);
89+
}
90+
91+
describe('BulkActionDialog renders confirmText through the reader (objectui#13183)', () => {
92+
it("renders an envelope's source, never [object Object]", async () => {
93+
openConfirm({ dialect: 'template', source: 'Archive {{ count }} account(s)?' });
94+
expect(await screen.findByText('Archive {{ count }} account(s)?')).toBeInTheDocument();
95+
expect(screen.queryByText(/\[object Object\]/)).toBeNull();
96+
});
97+
98+
it('renders a plain string unchanged', async () => {
99+
openConfirm('Archive these accounts?');
100+
expect(await screen.findByText('Archive these accounts?')).toBeInTheDocument();
101+
});
102+
103+
it('keeps the default sentence when the slot is absent', async () => {
104+
openConfirm(undefined);
105+
expect(await screen.findByText(/This will apply to 2 record/)).toBeInTheDocument();
106+
});
107+
108+
it('keeps the default sentence when the slot is blank', async () => {
109+
openConfirm({ dialect: 'template', source: ' ' });
110+
expect(await screen.findByText(/This will apply to 2 record/)).toBeInTheDocument();
111+
});
112+
});

‎packages/plugin-grid/src/components/BulkActionDialog.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
lookupTargetObject,
4040
} from './bulkParamToField';
4141
import { unresolvedFieldOf } from '../resolveBulkActions';
42+
import { bulkConfirmTextSource } from './bulkConfirmText';
4243

4344
/**
4445
* The name the confirm step lists an affected record by (objectui#13107).
@@ -409,7 +410,7 @@ export const BulkActionDialog: React.FC<BulkActionDialogProps> = ({
409410
</DialogTitle>
410411
{step === 'confirm' && (
411412
<DialogDescription>
412-
{def.confirmText ?? t('grid.bulk.confirmDefault', { count: rows.length, defaultValue: `This will apply to ${rows.length} record(s).` })}
413+
{bulkConfirmTextSource(def.confirmText) ?? t('grid.bulk.confirmDefault', { count: rows.length, defaultValue: `This will apply to ${rows.length} record(s).` })}
413414
</DialogDescription>
414415
)}
415416
</DialogHeader>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
import type { BulkActionDef } from '@object-ui/types';
10+
11+
/**
12+
* The text a bulk action's `confirmText` carries: the string itself, or the
13+
* `source` of a `{ dialect: 'template', source }` envelope, verbatim. Returns
14+
* `undefined` when the slot is absent, blank (empty or whitespace-only), or
15+
* carries no string `source` — the caller shows its default sentence then.
16+
*
17+
* Why two arms (objectui#13183, step 1 of the landing order for
18+
* objectstack#24947): the protocol is making this slot a `template`-dialect
19+
* slot, so a parsed bulk def serves the envelope where it served a string.
20+
* Rendered as a React child, the envelope is an object and the confirm step
21+
* breaks. This reader accepts both shapes, the way core's
22+
* `formatTitleTemplate` reads `titleFormat`, so the renderer can move before
23+
* the spec does.
24+
*
25+
* ⚠️ The `{{ }}` holes are NOT filled here: `source` is returned as written.
26+
* Filling `{{ count }}` and the param roots is the card's next step.
27+
*/
28+
export function bulkConfirmTextSource(
29+
confirmText: BulkActionDef['confirmText'] | null | undefined,
30+
): string | undefined {
31+
const text =
32+
typeof confirmText === 'string'
33+
? confirmText
34+
: confirmText !== null && typeof confirmText === 'object' && typeof confirmText.source === 'string'
35+
? confirmText.source
36+
: undefined;
37+
return text !== undefined && text.trim() !== '' ? text : undefined;
38+
}

‎packages/types/src/objectql.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,19 @@ export interface BulkActionDef {
676676
* dialog skips the params step and jumps straight to confirm.
677677
*/
678678
params?: BulkActionParam[];
679-
/** Confirmation text shown above the affected-record summary. */
680-
confirmText?: string;
679+
/**
680+
* Confirmation text shown above the affected-record summary.
681+
*
682+
* Two arms, because the protocol is moving this slot to ADR-0032's
683+
* `template` dialect (objectstack#24798, landed by objectstack#24947): there
684+
* a bare string is shorthand for `{ dialect: 'template', source }`, and a
685+
* parsed definition (what `os compile` serializes) carries the envelope. The
686+
* installed spec still types the slot as a plain string, so both arms reach
687+
* the renderer during the move. Read it through plugin-grid's
688+
* `bulkConfirmTextSource`, never as a React child: the envelope arm is an
689+
* object.
690+
*/
691+
confirmText?: string | { dialect?: 'template'; source: string };
681692
/** Custom Confirm button label (default: "Run"). */
682693
confirmLabel?: string;
683694
/**

‎packages/types/src/zod/objectql.zod.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,9 @@ const ObjectGridBulkActionDefSchema = z.strictObject({
584584
operation: stripImportedDefaults(SpecBulkActionOperationSchema),
585585
patch: z.record(z.string(), z.unknown()).optional(),
586586
params: z.array(ObjectGridBulkActionParamSchema).optional(),
587-
confirmText: z.string().optional(),
587+
// The twin's two arms (objectui#13183): a string, or the `template` envelope a
588+
// parsed def carries once the spec makes the slot a template slot (objectstack#24947).
589+
confirmText: z.union([z.string(), z.object({ dialect: z.literal('template').optional(), source: z.string() })]).optional(),
588590
confirmLabel: z.string().optional(),
589591
visible: z.union([ExpressionWireSchema, stripImportedDefaults(SpecBulkActionDefSchema).shape.visible]).optional(),
590592
requiredPermissions: z.array(z.string()).optional(),

0 commit comments

Comments
 (0)