Skip to content

Commit 153ef58

Browse files
committed
feat(console): the param dialog's submit button reads the action's submitText
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibzPbVCsG2npDkDqikd
1 parent ebd312a commit 153ef58

8 files changed

Lines changed: 73 additions & 12 deletions

File tree

‎ui/packages/app-shell/src/hooks/useConsoleActionRuntime.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import React, { useCallback, useMemo, useRef, useState } from 'react';
2525
import { useNavigate } from 'react-router-dom';
2626
import { useAuth, createAuthenticatedFetch } from '@object-ui/auth';
2727
import { usePermissions } from '@object-ui/permissions';
28-
import { useObjectLabel, useObjectTranslation } from '@object-ui/i18n';
28+
import { useObjectLabel, useObjectTranslation, pickLocalized } from '@object-ui/i18n';
2929
import { ActionProvider, useGlobalUndo, useMetadata, type ActionProviderProps } from '@object-ui/react';
3030
import { toast } from 'sonner';
3131
import type {
@@ -170,7 +170,7 @@ export function useConsoleActionRuntime(opts: ConsoleActionRuntimeOptions): Cons
170170
// `requiredPermissions` action closed on exactly the deployments this
171171
// doctrine exists to protect (objectui#4656).
172172
const { systemPermissions } = usePermissions();
173-
const { fieldLabel, fieldOptionLabel, actionParamText, actionParamOptionLabel, actionDescription, actionResultDialog } = useObjectLabel();
173+
const { fieldLabel, fieldOptionLabel, actionParamText, actionParamOptionLabel, actionDescription, actionSubmitText, actionResultDialog } = useObjectLabel();
174174
// Entitlement 403s render as a dialog, not a toast — its copy is localized
175175
// here rather than taken from the server (objectui#2458 / cloud#959).
176176
// `language` also resolves inline per-locale action-param labels below, and
@@ -342,6 +342,11 @@ export function useConsoleActionRuntime(opts: ConsoleActionRuntimeOptions): Cons
342342
const overrideNotice = typeof action?.overrideNotice === 'string' && action.overrideNotice
343343
? action.overrideNotice
344344
: undefined;
345+
// The submit button's verb (`submitText`): the bundle's
346+
// `_actions.<name>.submitText` (`globalActions.<name>.submitText` for an
347+
// object-less action) first, then the authored `I18nLabel` collapsed to
348+
// the active language. Absent, the dialog keeps its default "Confirm".
349+
const submitText = actionSubmitText(objForI18n, action?.name, pickLocalized(action?.submitText, language) || undefined);
345350
setParamState({
346351
open: true,
347352
params: localized,
@@ -356,14 +361,15 @@ export function useConsoleActionRuntime(opts: ConsoleActionRuntimeOptions): Cons
356361
description: overrideNotice
357362
? [overrideNotice, declaredDescription].filter(Boolean).join('\n\n')
358363
: declaredDescription,
364+
submitText,
359365
interpolate,
360366
resolve,
361367
// The runner's `run`, so Confirm runs the action from inside the
362368
// dialog and a refusal keeps what the user typed (objectui#13161).
363369
run,
364370
});
365371
})(); });
366-
}, [objectName, objectDef, objects, metadata, fieldLabel, fieldOptionLabel, actionParamText, actionParamOptionLabel]);
372+
}, [objectName, objectDef, objects, metadata, fieldLabel, fieldOptionLabel, actionParamText, actionParamOptionLabel, actionSubmitText, language]);
367373

368374
const currentUser = user
369375
? { id: user.id, name: user.name, avatar: user.image, isPlatformAdmin: (user as any)?.isPlatformAdmin ?? false, systemPermissions }

‎ui/packages/app-shell/src/views/ActionParamDialog.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ export interface ParamDialogState {
9696
* so the dialog reads as the task, not a generic param prompt. */
9797
title?: string;
9898
description?: string;
99+
/**
100+
* Label of the submit button — the action's declared `submitText`, already
101+
* resolved by the caller (the translation bundle's
102+
* `_actions.<action>.submitText` first, then the authored text collapsed to
103+
* the active language). Absent, the button says the generic "Confirm"; while
104+
* a file is uploading it says "Uploading…" either way.
105+
*/
106+
submitText?: string;
99107
/**
100108
* Fills the `${...}` holes of each param's `helpText` — the runner's
101109
* `ParamCollectionHandler` `interpolate` argument, passed through. It runs on
@@ -913,7 +921,7 @@ export function ActionParamDialog({ state, onOpenChange }: ActionParamDialogProp
913921
aria-busy={submitting || undefined}
914922
>
915923
{submitting && <Loader2 className="mr-2 size-4 animate-spin" aria-hidden="true" />}
916-
{anyUploading ? t('actionDialog.uploading') : t('actionDialog.confirm')}
924+
{anyUploading ? t('actionDialog.uploading') : (state.submitText || t('actionDialog.confirm'))}
917925
</Button>
918926
</DialogFooter>
919927
</DialogContent>

‎ui/packages/app-shell/src/views/RecordDetailView.tsx‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { activityRowToFeedItem, ArrangedRelatedTab, auditEntriesToFeedItems, bod
1414
import { Empty, EmptyTitle, EmptyDescription, Button, PageHeaderActions, PageHeaderTrailingContext, PanelToggles, type PanelToggleItem } from '@object-ui/components';
1515
import { useAuth, createAuthenticatedFetch } from '@object-ui/auth';
1616
import { usePermissions } from '@object-ui/permissions';
17-
import { useDisplayLocale, useLocalization } from '@object-ui/i18n';
17+
import { useDisplayLocale, useLocalization, pickLocalized } from '@object-ui/i18n';
1818
import { ActionProvider, useObjectTranslation, useObjectLabel, useActionTextLocalizer, usePageAssignment, isRecordPageOf, useMetadata, RecordContextProvider, SchemaRenderer, DiscussionContextProvider, HighlightFieldsProvider, InlineEditProvider, resolveApprovalLock, useGlobalUndo, useDataInvalidation, notifyDataChanged, subscribeDataChanges, dataChangeMatches, useRowPredicate, classifyLoadError, extractWriteErrorMessage } from '@object-ui/react';
1919
import { buildExpandFields, captureUpdateUndoData, recordDelete, resolveAffordance, resolveRecordIdParamSeed, userActionPredicates, withoutDeniedFields, type AffordanceGrantPrincipal, type SchemaLike } from '@object-ui/core';
2020
import { toast } from 'sonner';
@@ -772,7 +772,7 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
772772
// The tenant default currency (ADR-0053) a `dynamic` currency diff reads,
773773
// the same `useLocalization().currency` the record page's cells read.
774774
const { currency: tenantCurrency } = useLocalization();
775-
const { objectLabel, objectPluralLabel, viewLabel: _vLabel, sectionLabel, actionParamText, actionParamOptionLabel, actionDescription, actionResultDialog, fieldLabel, fieldOptionLabel } = useObjectLabel();
775+
const { objectLabel, objectPluralLabel, viewLabel: _vLabel, sectionLabel, actionParamText, actionParamOptionLabel, actionDescription, actionSubmitText, actionResultDialog, fieldLabel, fieldOptionLabel } = useObjectLabel();
776776
// label + confirmText + successMessage through ONE call (objectui#4265) —
777777
// the three keys of an `_actions.<name>` bundle entry can no longer be
778778
// localized apart from one another on this surface.
@@ -1354,6 +1354,10 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
13541354
: p.options,
13551355
}));
13561356
const declaredDescription = actionDescription(objForI18n, action?.name, action?.description);
1357+
// The submit button's verb, resolved as `useConsoleActionRuntime`
1358+
// resolves it: the bundle entry first, then the authored `I18nLabel`
1359+
// collapsed to the active language; absent, the dialog says "Confirm".
1360+
const submitText = actionSubmitText(objForI18n, action?.name, pickLocalized(action?.submitText, language) || undefined);
13571361
setParamState({
13581362
open: true,
13591363
params: localized,
@@ -1374,14 +1378,15 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
13741378
// `${...}` holes in the description and each `helpText` are filled in
13751379
// the runner's template scope, as `confirmText` is (objectui#12967).
13761380
description: interpolate && declaredDescription ? interpolate(declaredDescription) : declaredDescription,
1381+
submitText,
13771382
interpolate,
13781383
resolve,
13791384
// The runner's `run`, as `useConsoleActionRuntime` forwards it: a
13801385
// refused run keeps what the user typed (objectui#13161).
13811386
run,
13821387
});
13831388
});
1384-
}, [objectName, objectDef, objects, fieldLabel, fieldOptionLabel, actionParamText, actionParamOptionLabel]);
1389+
}, [objectName, objectDef, objects, fieldLabel, fieldOptionLabel, actionParamText, actionParamOptionLabel, actionSubmitText, language]);
13851390

13861391
// Global undo/redo (Ctrl+Z), backed by the dataSource — the success toast's
13871392
// "Undo" button (for `undoable` actions) restores the record's prior values.

‎ui/packages/core/src/actions/ActionRunner.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ export interface ActionDef {
150150
* it — the two TS2353s the deletion produced repo-wide were both this key.
151151
*/
152152
description?: UIActionSchema['description'];
153+
/**
154+
* Label of the submit button in the param-collection dialog — the verb the
155+
* button performs ("Send", "Log Call"), in place of the dialog's default
156+
* "Confirm". Derived from the spec field: an `I18nLabel`, a string or an
157+
* inline per-locale map. Display copy only — the runner never reads it; the
158+
* console's param-collection handlers resolve it (the translation bundle's
159+
* `_actions.ACTION.submitText` first, then the authored text collapsed to the
160+
* active language) and the param dialog draws it.
161+
*/
162+
submitText?: SpecActionInput['submitText'];
153163
/**
154164
* Confirmation text — shows a confirm dialog before executing. The ONE
155165
* confirm spelling: `@objectstack/spec`'s action surface and the

‎ui/packages/core/src/actions/actionKeys.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ export const ACTION_DEF_KEYS = [
124124
// of an action), forwarded by all four action renderers and read by the
125125
// param-collection dialog, but never declared on `ActionDef`.
126126
'description',
127+
// The param dialog's submit-button label (`ActionSchema.submitText`), derived
128+
// from the spec and drawn by the console's param dialog. Display only: the
129+
// runner never reads it.
130+
'submitText',
127131
'confirmText',
128132
'confirm',
129133
'condition',
@@ -325,8 +329,8 @@ export const SPEC_ACTION_KEYS = [
325329
'requiresMembershipReach',
326330
'resultDialog',
327331
// Added to `ActionSchema` by objectstack#27944: the param dialog's submit
328-
// button label. Listed for this array's contract alone, like `description`
329-
// above; the dialog reading it is the console's own follow-up.
332+
// button label. `ActionDef` declares it (derived), and the console's param
333+
// dialog draws it.
330334
'submitText',
331335
'successMessage',
332336
'target',

‎ui/packages/i18n/src/__tests__/useObjectLabel-identity-5564.test.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,13 @@ describe('useObjectLabel identity (objectui#5564)', () => {
173173
// (the name of an object's list), taking it to 28. objectui#11389 retired
174174
// `widgetSubCaption` with the metric sub-caption (ruling C), taking it to
175175
// 27. objectstack#26619 added `actionDisabledReason` (the reason a greyed
176-
// action gives), taking it to 28. A new resolver must land
176+
// action gives), taking it to 28. objectstack#28158 added
177+
// `actionSubmitText` (the verb on an action's param-dialog submit button),
178+
// taking it to 29. A new resolver must land
177179
// on both paths at once, because there is only one path — and a retired one
178180
// leaves both at once for the same reason, which is what the equality above
179181
// measures and this count anchors to an absolute.
180-
expect(Object.keys(unbound.seen[0])).toHaveLength(28);
182+
expect(Object.keys(unbound.seen[0])).toHaveLength(29);
181183
expect(Object.keys(unbound.seen[0])).not.toContain('widgetSubCaption');
182184
expect(typeof unbound.seen[0].objectLabel).toBe('function');
183185
expect(unbound.seen[0].objectLabel({ name: 'lead', label: 'Lead' })).toBe('Lead');

‎ui/packages/i18n/src/useObjectLabel.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,22 @@ export function useObjectLabel() {
622622
return resolved || undefined;
623623
},
624624

625+
/**
626+
* Resolve the translated label of the submit button in an action's param
627+
* dialog — its declared `submitText` (`@objectstack/spec` `ActionSchema`),
628+
* the verb the button performs ("Send", "Log Call").
629+
* Convention: `{ns}.objects.{objectName}._actions.{actionName}.submitText`;
630+
* with no key object, `{ns}.globalActions.{actionName}.submitText`. Falls
631+
* back to the metadata's literal string; undefined when nothing resolves,
632+
* so the dialog keeps its default "Confirm".
633+
*/
634+
actionSubmitText: (objectName: string | undefined, actionName: string | undefined, fallback?: string) => {
635+
const fb = fallback ?? '';
636+
if (!actionName) return fb || undefined;
637+
const resolved = resolve(actionSuffixes(objectName, actionName, 'submitText'), fb);
638+
return resolved || undefined;
639+
},
640+
625641
/**
626642
* Resolve the translated reason a greyed action gives — its declared
627643
* `disabledReason` (objectstack#26619), shown while its `disabled`

‎ui/packages/types/src/ui-action.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,17 @@ export interface UIActionSchema {
929929

930930
/** Action description */
931931
description?: string;
932-
932+
933+
/**
934+
* The label of the submit button in the dialog the action opens to collect
935+
* its `params` (`ActionSchema.submitText`) — the verb the button performs
936+
* ("Send", "Log Call"), in place of the dialog's default "Confirm". DERIVED
937+
* from the spec: an `I18nLabel`, a string or an inline per-locale map, the
938+
* console collapses to the active language after the translation bundle's
939+
* `_actions.ACTION.submitText` entry.
940+
*/
941+
submitText?: SpecAction['submitText'];
942+
933943
/** Permission required to execute */
934944
permission?: string;
935945

0 commit comments

Comments
 (0)