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

fix(core): localize built-in aggregate chart labels via builtinAggregate (#7258) - #7535

Merged
hotlong merged 1 commit into
mainfrom
fix/chart-builtin-aggregate-label-7258
Sep 3, 2026
Merged

hotlong merged 1 commit into
mainfrom
fix/chart-builtin-aggregate-label-7258

Conversation

@hotlong

@hotlong hotlong commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Closes #7258
Part of objectstack-ai/cloud#1841 — the CONSUMER half of maintainer ruling B (2026-09-02); the producer half is objectstack-ai/objectstack#14492.

Depends on objectstack#14492 landing upstream for the field to be populated. Until then the wire carries no builtinAggregate, and every chart renders exactly as today — this PR is inert by construction on the current spec, and stays a draft until the producer merges.

The defect

An AI-built customer dashboard's "customers by status" bar shows three localized category labels (合作中 / 已流失 / 潜在) under an aggregate axis title that reads Count on a zh console. The literal is not minted in this repo: buildChartSeries passes fields[].label through verbatim — correctly, for an author-declared measure (objectui#4106 pins 'Tasks') — and the analytics service hard-codes label: 'Count' on its built-in default measure with no i18n hook. The renderer had no way to tell the two apart, and guessing from the label's text or the field's name (option A) was rejected.

Consumer contract — what this PR reads

  • AnalyticsResult.fields[] gains an OPTIONAL structural discriminator, builtinAggregate, with the closed enum 'count' | 'sum' | 'avg' | 'min' | 'max' | 'count_distinct' (the spec's own measure-aggregate spelling), populated ONLY on the server-side built-in default measures. An author-declared measure never carries it.
  • Read structurally and validated at the lookup: isBuiltinAggregate checks the wire value against the closed vocabulary; a recognised value resolves through the caller's locale map; an unrecognised value (or none) is treated as absent and the field keeps its wire label verbatim, then its name.
  • Never inferred from the field's name or the label's text: a real author measure literally named count and labelled Count, without the discriminator, keeps its own label — pinned at both the pure and the surface level.

How @objectstack/spec is consumed here, and whether a pin bump is needed

  • By npm RANGE, not a workspace link or SHA pin: @object-ui/core declares @objectstack/spec ^17.2.0 (root ^17.0.0), the lockfile resolves 17.2.0. This repo has no .objectstack-sha-style pin.
  • The 17.2.0 AnalyticsResult.fields[] element has no builtinAggregate, and packages/core/src/utils/__tests__/dataset-result-field-spec-parity.test.ts pins keyof ChartResultField as a subset of the spec element's keys at compile time. Adding the key ON ChartResultField turned that pin red (measured: TS2344 at line 121, Extends distributing to boolean). So the key lives BESIDE it as BuiltinAggregateCarrier, and buildChartSeries takes ChartMeasureField[] (ChartResultField intersected with the carrier): a spec-typed DatasetResultField[] flows in unchanged today and carries the key the moment the spec does, with no cast at any call site. The parity suite stays green on 17.2.0.
  • No pin bump in this PR. Follow-up once the spec release carrying the field ships: raise @objectstack/spec to that minor, fold builtinAggregate into ChartResultField as DatasetResultField['builtinAggregate'], retire the carrier, and pin the two closed enums to each other in the parity suite — recorded as TODO(objectstack#14492) in chart-series.ts.

Before / after

wire field session before after
{ name: 'count', label: 'Count', builtinAggregate: 'count' } zh Count 计数
same en Count Count
{ name: 'task_count', label: 'Tasks' } (author, no discriminator) zh Tasks Tasks
{ name: 'count', label: 'Count' } (author, no discriminator) zh Count Count
{ …, builtinAggregate: 'median' } (outside the vocabulary) zh label label
built-in field, provider-less host / map without the entry — Count Count

What changed, and the file-surface note

  • packages/core/src/utils/chart-series.ts — BuiltinAggregateCarrier, ChartMeasureField, BUILTIN_AGGREGATES, BuiltinAggregate, isBuiltinAggregate, BuiltinAggregateLabels, resolveMeasureLabel; ChartSeriesOptions.builtinAggregateLabels; labelOf resolves through resolveMeasureLabel.
  • packages/i18n/src/builtinAggregateLabels.ts (+ index.ts export) — builtinAggregateLabels(tt) resolves the six strings through the existing report.aggregate.* keys (count_distinct maps to the bundle's countDistinct); English fallbacks byte-equal to the en pack.
  • ObjectChart.tsx, DatasetWidget.tsx, DatasetReportRenderer.tsx — pass builtinAggregateLabels(tt) beside nullCategoryLabel.
  • Tests (below) and .changeset/7258-chart-builtin-aggregate-label.md.

The claim's surface was chart-series.ts, the locale bundles, and tests beside it. Three things sit outside it, each necessary for the fix to reach a user rather than stay a seam nothing wires:

  1. The three call sites — one option each. @object-ui/core is React-free and i18n-free (its own doctrine for nullCategoryLabel), so the locale strings MUST be resolved by the layer holding the provider and passed in.
  2. The i18n seam module — the ONE place the six keys are read for this purpose, instead of six tt() calls copied into three renderers. The locale bundles themselves are untouched: all ten packs already carry report.aggregate.{count, countDistinct, sum, avg, min, max} (now pinned per pack).
  3. DatasetWidget.builtinAggregateLabel.test.tsx — the surface pin under a real I18nProvider, on the widget the card was measured on.

Tests

  • core chart-series.builtinAggregate.test.ts (14): zh 计数 / en Count; every enum member; verbatim author label (objectui#4106); authored count keeps Count; unknown discriminator → label / → name; no labels, missing entry, empty string → wire label; pivot branch untouched; resolveMeasureLabel order; isBuiltinAggregate truth table.
  • i18n builtinAggregateLabels-locale-parity-7258.test.ts (15): all ten packs carry a non-empty label for every member; the seam maps exactly the closed vocabulary; per-pack value identity; zh / en literal pins; provider-less fallbacks equal the en pack.
  • dashboard DatasetWidget.builtinAggregateLabel.test.tsx (4): zh 计数 / en Count / verbatim Opportunities / authored count keeps Count, read off the series the widget hands the chart renderer.

Reverse verification (ablation) — at 799c84a27, after the commit

Mutation: labelOf back to the pre-fix field?.label ?? name (on-disk proof: injected marker count 1, removed call count 0). Ran the core + dashboard pins: 4 failed / 14 passed — red exactly where predicted: zh built-in count (core), every-member, multi-measure, zh built-in count (surface). Direction note, recorded rather than fitted: the en pins stayed green under the mutation because the en locale label IS the wire Count — they are controls, not discriminating pins. Restore: git checkout HEAD -- path; git hash-object equals the HEAD blob (bcae7ca08…), git diff HEAD empty, marker count 0. No dist/ is involved in either leg: the root vitest config aliases @object-ui/* to src/ and the core test imports relatively.

Verification — union at 799c84a27 (the final commit)

  • pnpm --filter core / i18n / plugin-charts / plugin-dashboard / plugin-report run type-check (tsc --noEmit && tsc -p tsconfig.test.json): all five Done, exit 0, after pnpm --filter 'plugin-{dashboard,report,charts}^...' build. --listFiles shows each new test file inside its package's test project (1 / 1 / 1), so "type-check clean" covers the new tests.
  • pnpm exec vitest run --maxWorkers=2 over 16 files (the 3 new + every chart-series / dataset-format / spec-parity / label-net sibling + ObjectChart.datasetMeasureLabel + two DatasetWidget label suites): Test Files 16 passed, Tests 256 passed, exit 0.
  • ESLint (root config, --format json) over the 9 .ts / .tsx files this diff touches (the 10th changed file is the changeset, outside files: ['**/*.{ts,tsx}']): exit 0, 0 errors, 74 warnings — 0 on any line this diff added (measured against git diff -U0 hunks; the 74 are pre-existing: ObjectChart.tsx 58, DatasetWidget.tsx 11, DatasetReportRenderer.tsx 5). Narrowing proof: the universe is eslint's own files glob; the count is the JSON output's 9 entries; grep -cE 'projectService|parserOptions|project:' eslint.config.js = 0 (control files:|ignores: = 9), so type-aware linting is off and no untouched file's verdict can move.
  • check-changeset-presence (9 source files of 5 released packages, 1 changeset declared), check-changeset-fixed, check-changeset-no-major, check-changeset-overwrite: exit 0 each.
  • check-control-bytes: OK (6206 tracked files); targeted perl scan over the diff files: 0 hits.
  • check-i18n-call-site-keys: every in-scope key resolves and every positional default matches the en pack; check-i18n-en-drift: no en value changed; check-phantom-dependencies: OK.
  • NOT MEASURED locally: check:readme-exports (257 "type entry not on disk" — 22 packages this worktree never built) and check:spec-floors (12 findings, all no-artifact on those same unbuilt packages; the 19 built ones, including all five touched here, judged 185 subpath/symbol pairs clean). This diff changes no manifest and imports no new spec symbol; CI builds the workspace and measures both.
  • Verify lock: os-verify-lock.sh ran in DECLARED UNLOCKED MODE (no usable flock on this macOS host) — nothing was serialized.

Changeset

.changeset/7258-chart-builtin-aggregate-label.md — core and i18n minor (new exports), plugin-charts / plugin-dashboard / plugin-report patch.

Out of scope, filed

  • objectui-issue 7534 — the same class one seam over: buildDatasetFieldHelpers().headerLabel (KPI caption, table / pivot headers, report metric caption, DatasetPreview) still prints the wire Count; the resolver from this PR makes it a mechanical follow-up across five call sites (including app-shell). It remains open; nothing here addresses it.

Session: session_c5c0ce54-bb9c-478c-9e5b-cf44b80d4569

🤖 Generated with Claude Code

A dataset chart's aggregate axis / legend title read the analytics service's
hard-coded English `Count` on a zh console whose category labels were already
Chinese. `buildChartSeries` passed `fields[].label` through verbatim — right
for an author-declared measure — and had no way to tell the server's built-in
default apart from an author's label.

Consumer half of the objectstack contract that adds an OPTIONAL structural
discriminator, `AnalyticsResult.fields[].builtinAggregate`, populated only on
the server-side built-in defaults:

- core: `buildChartSeries` accepts `ChartMeasureField[]` (`ChartResultField`
  plus the optional `BuiltinAggregateCarrier`, declared beside the renderer
  shape because the spec this tree is built against does not carry the key
  yet); `BUILTIN_AGGREGATES` / `isBuiltinAggregate` / `resolveMeasureLabel`;
  `ChartSeriesOptions.builtinAggregateLabels` carries the locale strings in.
- i18n: `builtinAggregateLabels(tt)` resolves the six strings through the
  existing `report.aggregate.*` keys.
- plugin-charts / plugin-dashboard / plugin-report: pass the resolved map to
  `buildChartSeries`.

A field carrying a recognised discriminator resolves through the map; every
other field keeps its wire label verbatim — never by matching the label's
text or the field's name.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

✅ Console Performance Budget

Metric Value Budget
Eager closure (gzip, 50 chunks) 3182.2 KB 3191.4 KB
Main entry chunk (gzip) 143.2 KB 350 KB
Entry file index-JkRWQ99M.js —
Status PASS —

The eager closure is every chunk the entry reaches through static imports — what the browser fetches and parses before the app renders. The entry chunk on its own is a small fraction of it.


📦 Bundle Size Report

Package Size Gzipped
app-shell (consoleActionDispatch.js) 0.20KB 0.19KB
app-shell (index.js) 15.67KB 5.75KB
app-shell (runtime-config.js) 20.68KB 7.36KB
app-shell (types.js) 0.01KB 0.04KB
app-shell (urlParams.js) 10.06KB 3.86KB
auth (ActiveOrganizationStorage.js) 25.05KB 9.16KB
auth (AuthContext.js) 0.31KB 0.24KB
auth (AuthGuard.js) 2.07KB 1.00KB
auth (AuthProvider.js) 40.18KB 10.59KB
auth (AuthShell.js) 3.49KB 1.40KB
auth (ForgotPasswordForm.js) 12.21KB 3.45KB
auth (LoginForm.js) 18.15KB 5.39KB
auth (PreviewBanner.js) 0.90KB 0.50KB
auth (RegisterForm.js) 6.65KB 2.22KB
auth (SocialSignInButtons.js) 9.61KB 3.89KB
auth (UserMenu.js) 3.41KB 1.23KB
auth (auth-gate-events.js) 1.29KB 0.66KB
auth (authStyles.js) 5.04KB 1.72KB
auth (createAuthClient.js) 40.21KB 10.80KB
auth (createAuthenticatedFetch.js) 8.46KB 3.43KB
auth (index.js) 3.19KB 1.44KB
auth (invitation-status.js) 1.22KB 0.70KB
auth (org-roles.js) 6.66KB 2.78KB
auth (phone-identifier.js) 1.11KB 0.66KB
auth (types.js) 0.59KB 0.35KB
auth (useAuth.js) 5.30KB 1.02KB
auth (useWorkspaceAdminStatus.js) 5.13KB 2.35KB
collaboration (CommentThread.js) 26.08KB 7.56KB
collaboration (LiveCursors.js) 3.17KB 1.27KB
collaboration (PresenceAvatars.js) 6.49KB 2.64KB
collaboration (PresenceProvider.js) 2.79KB 1.13KB
collaboration (index.js) 1.68KB 0.73KB
collaboration (useCollaborationTranslation.js) 6.05KB 2.52KB
collaboration (useCommentSearch.js) 1.98KB 0.88KB
collaboration (useConflictResolution.js) 7.75KB 1.86KB
collaboration (useMentionNotifications.js) 1.81KB 0.68KB
collaboration (usePresence.js) 6.33KB 1.84KB
collaboration (useRealtimeSubscription.js) 7.91KB 2.01KB
components (index.js) 516.19KB 117.80KB
core (index.js) 6.12KB 2.42KB
create-plugin (index.js) 10.08KB 3.26KB
data-objectstack (index.js) 178.20KB 49.60KB
fields (index.js) 242.42KB 61.26KB
i18n (LocalizationContext.js) 1.76KB 0.96KB
i18n (builtinAggregateLabels.js) 0.86KB 0.49KB
i18n (currency.js) 1.22KB 0.64KB
i18n (fallbackInterpolation.js) 6.25KB 2.77KB
i18n (i18n.js) 4.28KB 1.75KB
i18n (index.js) 3.65KB 1.47KB
i18n (pickLocalized.js) 7.62KB 3.26KB
i18n (provider.js) 26.89KB 9.04KB
i18n (useDisplayLocale.js) 2.85KB 1.45KB
i18n (useObjectLabel.js) 34.34KB 9.17KB
i18n (useSafeTranslation.js) 5.60KB 2.33KB
layout (index.js) 38.98KB 10.98KB
mobile (MobileProvider.js) 0.92KB 0.49KB
mobile (ResponsiveContainer.js) 0.94KB 0.38KB
mobile (breakpoints.js) 1.51KB 0.70KB
mobile (createOfflineDataSource.js) 5.61KB 1.75KB
mobile (index.js) 1.55KB 0.62KB
mobile (offlineQueue.js) 3.91KB 1.35KB
mobile (pwa.js) 0.97KB 0.49KB
mobile (serviceWorker.js) 1.48KB 0.62KB
mobile (serviceWorkerSource.js) 3.41KB 1.48KB
mobile (useBreakpoint.js) 1.54KB 0.65KB
mobile (useGesture.js) 6.96KB 1.98KB
mobile (useOfflineSync.js) 1.99KB 0.72KB
mobile (usePullToRefresh.js) 2.53KB 0.85KB
mobile (useResponsive.js) 0.72KB 0.42KB
mobile (useResponsiveConfig.js) 1.37KB 0.63KB
mobile (useSpecGesture.js) 4.32KB 1.64KB
mobile (useTouchTarget.js) 1.01KB 0.54KB
permissions (MePermissionsProvider.js) 11.71KB 4.29KB
permissions (PermissionContext.js) 0.31KB 0.25KB
permissions (PermissionGuard.js) 0.89KB 0.45KB
permissions (PermissionProvider.js) 6.24KB 2.16KB
permissions (discardProofCache.js) 1.04KB 0.55KB
permissions (evaluator.js) 5.12KB 1.74KB
permissions (index.js) 0.93KB 0.41KB
permissions (store.js) 0.91KB 0.42KB
permissions (useFieldPermissions.js) 1.28KB 0.53KB
permissions (usePermissions.js) 4.83KB 2.27KB
plugin-ai (index.js) 15.75KB 3.80KB
plugin-calendar (index.js) 48.15KB 13.35KB
plugin-charts (index.js) 70.94KB 19.75KB
plugin-chatbot (index.js) 196.19KB 46.43KB
plugin-dashboard (index.js) 132.89KB 34.68KB
plugin-designer (index.js) 212.87KB 43.19KB
plugin-detail (index.js) 251.07KB 64.12KB
plugin-editor (index.js) 2.46KB 1.10KB
plugin-form (index.js) 132.87KB 32.66KB
plugin-gantt (index.js) 167.46KB 41.06KB
plugin-grid (index.js) 209.25KB 56.71KB
plugin-kanban (index.js) 52.71KB 14.55KB
plugin-list (index.js) 113.33KB 27.60KB
plugin-map (index.js) 20.55KB 6.80KB
plugin-markdown (index.js) 13.72KB 4.69KB
plugin-report (index.js) 43.57KB 11.96KB
plugin-timeline (index.js) 30.84KB 8.85KB
plugin-tree (index.js) 9.40KB 3.23KB
plugin-view (index.js) 85.22KB 20.93KB
providers (DataSourceProvider.js) 0.75KB 0.39KB
providers (MetadataProvider.js) 1.37KB 0.59KB
providers (ThemeProvider.js) 1.90KB 0.85KB
providers (UploadProvider.js) 11.66KB 3.50KB
providers (index.js) 0.45KB 0.23KB
providers (types.js) 0.01KB 0.04KB
react-runtime (index.js) 5.62KB 2.34KB
react (LazyPluginLoader.js) 4.47KB 1.63KB
react (SchemaRenderer.js) 81.07KB 26.86KB
react (data-invalidation.js) 5.05KB 2.08KB
react (index.js) 4.63KB 2.18KB
react (schema-input.js) 2.32KB 1.24KB
react (spec-input.js) 0.20KB 0.18KB
sdui-parser (codegen.js) 5.41KB 2.34KB
sdui-parser (dashboard-widget-options.js) 3.08KB 1.30KB
sdui-parser (index.js) 4.93KB 2.24KB
sdui-parser (input-type.js) 2.84KB 1.40KB
sdui-parser (parse.js) 20.57KB 5.88KB
sdui-parser (provenance.js) 3.66KB 1.82KB
sdui-parser (types.js) 0.28KB 0.23KB
sdui-parser (validate.js) 10.35KB 3.60KB
types (ai.js) 0.20KB 0.17KB
types (api-types.js) 0.20KB 0.18KB
types (app.js) 2.87KB 0.99KB
types (base.js) 0.20KB 0.18KB
types (blocks.js) 0.20KB 0.18KB
types (complex.js) 2.74KB 1.41KB
types (crud.js) 0.20KB 0.18KB
types (dashboard-filter-alias.js) 6.23KB 2.74KB
types (data-display.js) 3.75KB 1.85KB
types (data-protocol.js) 0.20KB 0.19KB
types (data.js) 0.20KB 0.18KB
types (designer.js) 1.85KB 0.85KB
types (disclosure.js) 0.20KB 0.18KB
types (error-code.js) 1.54KB 0.88KB
types (feedback.js) 0.20KB 0.18KB
types (field-types.js) 0.20KB 0.18KB
types (form.js) 0.20KB 0.18KB
types (http-inflight.js) 8.87KB 3.73KB
types (http-retry.js) 4.32KB 2.02KB
types (icon-key-migration.js) 4.26KB 1.63KB
types (index.js) 4.74KB 2.25KB
types (layout.js) 0.20KB 0.18KB
types (managed-by.js) 0.19KB 0.18KB
types (mobile.js) 2.59KB 1.31KB
types (navigation.js) 0.20KB 0.18KB
types (objectql.js) 0.20KB 0.18KB
types (overlay.js) 0.20KB 0.18KB
types (permissions.js) 0.20KB 0.18KB
types (plugin-scope.js) 0.20KB 0.18KB
types (record-components.js) 0.20KB 0.19KB
types (record-semantics.js) 1.28KB 0.67KB
types (registry.js) 0.20KB 0.18KB
types (reports.js) 0.20KB 0.18KB
types (spec-report.js) 5.05KB 1.93KB
types (spec-ui-namespace.js) 0.20KB 0.19KB
types (system-fields.js) 3.33KB 1.54KB
types (theme.js) 6.28KB 2.87KB
types (ui-action.js) 8.11KB 3.32KB
types (views.js) 0.20KB 0.18KB
types (widget.js) 0.20KB 0.18KB

Size Limits

  • ✅ Core packages should be < 50KB gzipped
  • ✅ Component packages should be < 100KB gzipped
  • ⚠️ Plugin packages should be < 150KB gzipped

@hotlong
hotlong marked this pull request as ready for review September 3, 2026 18:09
@hotlong
hotlong added this pull request to the merge queue Sep 3, 2026
Merged via the queue into main with commit 47547d0 Sep 3, 2026
33 checks passed
@hotlong
hotlong deleted the fix/chart-builtin-aggregate-label-7258 branch September 3, 2026 18:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

仪表盘聚合图表轴标题 "Count" 未本地化(类别标签已本地化)

1 participant