diff --git a/.changeset/37034-date-condition-chips.md b/.changeset/37034-date-condition-chips.md new file mode 100644 index 00000000000..ce295142791 --- /dev/null +++ b/.changeset/37034-date-condition-chips.md @@ -0,0 +1,18 @@ +--- +'@object-ui/plugin-list': patch +--- + +fix(plugin-list): a date condition's value reads as a date in the viewer's language + +Clause-②: no +Metadata-protocol: none + +A list condition chip on a date field printed the stored value as written, so a +drilled dashboard bucket read 「创建时间:≥ 2026-10-01T00:00:00.000Z」 in a zh-CN +session. Every condition row (the reader's chips and the view's locked chips) now +formats a date-family value by the field's type through the console's one date +display path (`formatDate` / `formatDateTime` from `@object-ui/core`), in the +display locale: a `date` field shows the day with its year (an instant at UTC +midnight shows that calendar day in every zone), a `datetime` field shows the +date and time in the display zone, and a `time` field or an unreadable value is +shown as written. The filter the list sends is unchanged. diff --git a/examples/app-showcase/src/system/translations/index.ts b/examples/app-showcase/src/system/translations/index.ts index d5b892212c4..0d69ab6dc49 100644 --- a/examples/app-showcase/src/system/translations/index.ts +++ b/examples/app-showcase/src/system/translations/index.ts @@ -624,6 +624,10 @@ export const ShowcaseTranslationBundle = { billing_email: { label: '账单邮箱' }, support_config: { label: '支持配置' }, churn_reason: { label: '流失原因' }, + // The account side of the Revenue Pulse region filter + // (`filterBindings: { region: 'sales_region' }`), worded as the + // dataset's dimension describes it (销售区域). + sales_region: { label: '销售区域', options: { amer: '美洲', emea: '欧洲、中东和非洲', apac: '亚太' } }, }, // The zh-CN mirror of the `en` `_validations` block — see the note // there. Vocabulary is the one this bundle already established: @@ -758,6 +762,10 @@ export const ShowcaseTranslationBundle = { owner: { label: '负责人邮箱' }, status: { label: '状态' }, issued_on: { label: '开具日期' }, + // The Revenue Pulse dashboard's region filter lands on this field, so + // a drilled list's chip names it: the same words as the dashboard's + // own filter label and options (`dashboards.showcase_revenue_pulse`). + region: { label: '区域', options: { amer: '美洲', emea: '欧洲、中东和非洲', apac: '亚太' } }, tax_rate: { label: '税率 (%)' }, paid_on: { label: '付款日期' }, total: { label: '小计' }, diff --git a/scripts/i18n-coverage-baseline.json b/scripts/i18n-coverage-baseline.json index 758b553f2e7..dd6dfbfd4f5 100644 --- a/scripts/i18n-coverage-baseline.json +++ b/scripts/i18n-coverage-baseline.json @@ -1,7 +1,7 @@ { "examples/app-crm/objectstack.config.ts": 0, "examples/app-multi-package/objectstack.config.ts": 0, - "examples/app-showcase/objectstack.config.ts": 449, + "examples/app-showcase/objectstack.config.ts": 441, "examples/app-todo/objectstack.config.ts": 136, "packages/platform-objects/scripts/i18n-extract.config.ts": 0, "packages/plugins/plugin-approvals/scripts/i18n-extract.config.ts": 0, diff --git a/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts b/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts index 97801cb4790..543adb416f1 100644 --- a/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts +++ b/ui/packages/plugin-dashboard/src/__tests__/drillConditions-36256.test.ts @@ -57,6 +57,23 @@ describe('drillListConditions', () => { ]); }); + it("writes a dataset month bucket's range as two date rows that compare exactly what the bucket counted (objectstack#37034)", () => { + // The dataset answer's drill range for 2026-10: `{ $gte, $lt }`, ISO + // instants (core's dataset-format). The list's chip reads each bound as a + // date (plugin-list `formatConditionDate`); the value stays the one the + // query compares. No date-family operator says "on or after", and `after` + // (>) would drop the records at the bound, so the lower bound keeps `>=`. + const { chips, rest } = drillListConditions( + { issued_on: { $gte: '2026-10-01T00:00:00.000Z', $lt: '2026-11-01T00:00:00.000Z' } }, + { dateFields: new Set(['issued_on']) }, + ); + expect(rest).toBeUndefined(); + expect(chips.conditions.map((c) => [c.field, c.operator, c.value])).toEqual([ + ['issued_on', 'greater_than_or_equal', '2026-10-01T00:00:00.000Z'], + ['issued_on', 'before', '2026-11-01T00:00:00.000Z'], + ]); + }); + it("lowers a page block's rule array, and an AST node, to chips", () => { // HotCRM's 销售主页 KPI tile: the spec's rule-array form, handed as written. expect(drillListConditions([{ field: 'stage', operator: 'equals', value: 'closed_won' }]).chips.conditions diff --git a/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx b/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx index c454953b494..50a65181763 100644 --- a/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx +++ b/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx @@ -43,8 +43,9 @@ import { type SortItem, } from '@object-ui/components'; import { referencedRecordTitle } from '@object-ui/core'; +import { formatConditionDate } from './conditionDates'; import type { DataSource } from '@object-ui/types'; -import { useSafeFieldLabel } from '@object-ui/i18n'; +import { useDisplayLocale, useSafeFieldLabel } from '@object-ui/i18n'; import { ArrowDown, ArrowUp, ArrowUpDown, ListFilter, Lock, Plus, RotateCcw, SlidersHorizontal, X } from 'lucide-react'; import { FieldList, type FieldListItem } from './FieldList'; import { FilterValuePanel, isQuickRowApplied, quickDateWindowOf } from './FilterValuePanel'; @@ -84,14 +85,17 @@ export type LookupValueName = (field: string, id: string) => string | undefined; /** * The value half of a chip: 「Negotiation, Proposal」, 「≥ 100」, 「Today」. * A lookup's value is the referenced record's name when `nameOf` has it, and - * its id only when the name cannot be read. + * its id only when the name cannot be read. A date field's value reads as a + * date in `locale` (`formatConditionDate`), never as the stored ISO string. */ export function describeConditionValue( field: ConditionField | undefined, operator: string, value: unknown, t: Translate, - nameOf?: LookupValueName, + nameOf: LookupValueName | undefined, + // Required, so no caller formats a date in the runtime's default locale by omission. + locale: string, ): string { const opLabel = quickOperatorLabel(operator, t); if (isValuelessOperator(operator)) return opLabel; @@ -102,16 +106,17 @@ export function describeConditionValue( // A named window says what it is on its own: 「Today」, not 「between Today」. const window = family === 'date' && operator === 'between' ? quickDateWindowOf(value as FilterBuilderRow['value']) : undefined; if (window) return quickDateWindowLabel(window, t); + const shown = family === 'date' ? (v: unknown) => formatConditionDate(v, field?.type, locale) : String; if (family === 'boolean') { text = list.map((v) => (v === true || v === 'true' ? t('listConditions.filter.yes') : t('listConditions.filter.no'))).join(joiner); } else if (operator === 'between') { - text = list.map(String).join(' – '); + text = list.map(shown).join(' – '); } else if (family === 'option') { text = list.map((v) => optionLabel(field, v)).join(joiner); } else if (family === 'lookup' && field && nameOf) { text = list.map((v) => nameOf(field.value, String(v)) ?? String(v)).join(joiner); } else { - text = list.map(String).join(joiner); + text = list.map(shown).join(joiner); } // 「is any of」 is what a value list means on its own; every other operator is // named, and with no value it is the operator alone, never one with a trailing space. @@ -125,11 +130,12 @@ function chipText( operator: string, value: unknown, t: Translate, - nameOf?: LookupValueName, + nameOf: LookupValueName | undefined, + locale: string, ) { return t('listConditions.chips.pattern', { field: field?.label ?? fieldName ?? '', - value: describeConditionValue(field, operator, value, t, nameOf), + value: describeConditionValue(field, operator, value, t, nameOf, locale), }); } @@ -137,11 +143,12 @@ function viewChipText( chip: ViewConditionChip, fields: ReadonlyArray, t: Translate, - nameOf?: LookupValueName, - relatedFieldOf?: RelatedFieldOf, + nameOf: LookupValueName | undefined, + relatedFieldOf: RelatedFieldOf | undefined, + locale: string, ): string { if (chip.anyOf) { - return chip.anyOf.map((member) => viewChipText(member, fields, t, nameOf, relatedFieldOf)).join(t('listConditions.chips.or')); + return chip.anyOf.map((member) => viewChipText(member, fields, t, nameOf, relatedFieldOf, locale)).join(t('listConditions.chips.or')); } if (!chip.field || !chip.operator) return t('listConditions.chips.viewFilter'); const path = relationPathOf(chip.field); @@ -156,11 +163,11 @@ function viewChipText( }); return t('listConditions.chips.pattern', { field: label, - value: describeConditionValue(related, chip.operator, chip.value, t), + value: describeConditionValue(related, chip.operator, chip.value, t, undefined, locale), }); } const field = fields.find((f) => f.value === chip.field); - return chipText(field, chip.field, chip.operator, chip.value, t, nameOf); + return chipText(field, chip.field, chip.operator, chip.value, t, nameOf, locale); } // --------------------------------------------------------------------------- @@ -659,6 +666,7 @@ export function ConditionChipRow({ className, }: ConditionChipRowProps) { const { t } = useListConditionTranslation(); + const locale = useDisplayLocale(); const [openChip, setOpenChip] = React.useState(null); // Keyed on the names, not on the array the host may rebuild every render. @@ -773,7 +781,7 @@ export function ConditionChipRow({ )} {viewChips.map((chip) => { - const text = viewChipText(chip, filterFields, t, nameOf, relatedFieldOf); + const text = viewChipText(chip, filterFields, t, nameOf, relatedFieldOf, locale); return ( { const field = fieldOf(filterFields, row.field); - const text = chipText(field, row.field, row.operator, row.value, t, nameOf); + const text = chipText(field, row.field, row.operator, row.value, t, nameOf, locale); return ( ; expect(MULTI_OFFER.map((op) => enQuick[op])).toEqual(['contains', 'does not contain', 'is empty', 'is not empty']); const t = (key: string) => LIST_CONDITION_DEFAULT_TRANSLATIONS[key] ?? key; - expect(describeConditionValue(MULTI_VALUE[0], 'contains', 'quality_lead', t as never)).toBe('contains Quality lead'); + expect(describeConditionValue(MULTI_VALUE[0], 'contains', 'quality_lead', t as never, undefined, 'en-US')).toBe('contains Quality lead'); }); }); @@ -763,10 +765,10 @@ describe('condition model', () => { it('describes a chip value by operator: a bare list for 「is any of」, the operator named otherwise', () => { const t = (key: string, o?: Record) => (LIST_CONDITION_DEFAULT_TRANSLATIONS[key] ?? key).replace(/\{\{(\w+)\}\}/g, (_, k) => String(o?.[k] ?? '')); - expect(describeConditionValue(STAGE, 'in', ['proposal', 'negotiation'], t as never)).toBe('Proposal, Negotiation'); - expect(describeConditionValue(FIELDS[2], 'greater_than_or_equal', 100, t as never)).toBe('≥ 100'); - expect(describeConditionValue(FIELDS[3], 'between', quickDateWindowValue('today'), t as never)).toBe('Today'); - expect(describeConditionValue(STAGE, 'is_empty', undefined, t as never)).toBe('is empty'); + expect(describeConditionValue(STAGE, 'in', ['proposal', 'negotiation'], t as never, undefined, 'en-US')).toBe('Proposal, Negotiation'); + expect(describeConditionValue(FIELDS[2], 'greater_than_or_equal', 100, t as never, undefined, 'en-US')).toBe('≥ 100'); + expect(describeConditionValue(FIELDS[3], 'between', quickDateWindowValue('today'), t as never, undefined, 'en-US')).toBe('Today'); + expect(describeConditionValue(STAGE, 'is_empty', undefined, t as never, undefined, 'en-US')).toBe('is empty'); }); }); @@ -1104,3 +1106,102 @@ describe('ConditionChipRow — an operator only the advanced panel writes (objec expect(chipTexts()).toEqual(['Deal Value: >= 10', 'Deal Value: != 0']); }); }); + +// objectstack#37034 — a date condition's value reads as a date in the viewer's +// language, by the field's type, on every condition row (the desktop chips and +// the phone filter sheet's rows). On the wire a `date` bound is `YYYY-MM-DD` +// and a `datetime` bound an ISO instant: the card's sighting was a drilled +// month bucket on `created_at`, 「创建时间:≥ 2026-10-01T00:00:00.000Z」. +// The display zone is pinned to UTC, so an instant's day and time do not +// depend on the zone the runner sits in. +describe('date condition values read as dates (objectstack#37034)', () => { + beforeAll(() => setDisplayTimeZone('UTC')); + afterAll(() => setDisplayTimeZone(undefined)); + + const ISSUED_ON: ConditionField = { value: 'issued_on', label: '开具日期', type: 'date' }; + const CREATED_AT: ConditionField = { value: 'created_at', label: '创建时间', type: 'datetime' }; + const STARTS_AT: ConditionField = { value: 'starts_at', label: 'Starts at', type: 'time' }; + const rows = (conditions: Array<[string, string, unknown]>): FilterBuilderRowGroup => ({ + id: 'root', + logic: 'and', + conditions: conditions.map(([field, operator, value], i) => ({ id: `r${i}`, field, operator, value }) as FilterBuilderRow), + }); + const inZh = (node: React.ReactNode) => ( + {node} + ); + function zhChips(filters: FilterBuilderRowGroup, field: string): string[] { + render(inZh( + {}} + filters={filters} + filterFields={[ISSUED_ON, CREATED_AT]} + onFiltersChange={() => {}} + renderAdvanced={() =>
} + renderSortLevels={() =>
} + />, + )); + return screen.getAllByTestId(`filter-chip-open-${field}`).map((b) => b.textContent ?? ''); + } + const NOT_ISO = /T\d\d:\d\d|\d{4}-\d{2}-\d{2}/; + + it('the sighting: a drilled month bucket on a datetime field reads as two localized date-times, not ISO', () => { + const chips = zhChips(rows([ + ['created_at', 'greater_than_or_equal', '2026-10-01T00:00:00.000Z'], + ['created_at', 'before', '2026-11-01T00:00:00.000Z'], + ]), 'created_at'); + expect(chips).toHaveLength(2); + expect(chips[0]).toMatch(/^创建时间:≥ 2026年10月1日.*00:00$/); + expect(chips[1]).toMatch(/^创建时间:.*2026年11月1日.*00:00$/); + for (const chip of chips) expect(chip).not.toMatch(NOT_ISO); + }); + + it('a date field bound, as the wire writes it (YYYY-MM-DD), reads as its day', () => { + const chips = zhChips(rows([ + ['issued_on', 'greater_than_or_equal', '2026-10-01'], + ['issued_on', 'before', '2026-11-01'], + ]), 'issued_on'); + expect(chips).toHaveLength(2); + expect(chips[0]).toBe('开具日期:≥ 2026年10月1日'); + expect(chips[1]).toContain('2026年11月1日'); + for (const chip of chips) expect(chip).not.toMatch(NOT_ISO); + }); + + it('a date field compared with an instant at UTC midnight reads as that day', () => { + const [chip] = zhChips(rows([['issued_on', 'greater_than_or_equal', '2026-10-01T00:00:00.000Z']]), 'issued_on'); + expect(chip).toBe('开具日期:≥ 2026年10月1日'); + }); + + it('a datetime reads in the display zone', () => { + const [chip] = zhChips(rows([['created_at', 'greater_than_or_equal', '2026-10-15T12:00:00.000Z']]), 'created_at'); + expect(chip).toMatch(/^创建时间:≥ 2026年10月15日.*12:00$/); + }); + + it('a date between reads both ends as dates', () => { + const [chip] = zhChips(rows([['issued_on', 'between', ['2026-10-01', '2026-10-31']]]), 'issued_on'); + expect(chip).toContain('2026年10月1日 – 2026年10月31日'); + }); + + it("the phone filter sheet's row reads the date in the viewer's language, not the runtime default", () => { + // The runtime's own locale here is English: a row that left the locale out + // would read 「Oct 1, 2026」 on a zh-CN session. + expect(new Intl.DateTimeFormat().resolvedOptions().locale).toMatch(/^en/); + render(inZh( + {}} + fields={[ISSUED_ON, CREATED_AT]} + value={rows([['issued_on', 'greater_than_or_equal', '2026-10-01']])} + onApply={() => {}} + />, + )); + expect(screen.getByTestId('phone-filter-item-condition').textContent).toBe('≥ 2026年10月1日'); + }); + + it('CONTROL: a time field and an unreadable value are shown as written', () => { + const { t } = { t: (k: string) => LIST_CONDITION_DEFAULT_TRANSLATIONS[k] ?? k }; + expect(describeConditionValue(STARTS_AT, 'after', '09:30', t as never, undefined, 'zh-CN')).toBe('after 09:30'); + expect(describeConditionValue(ISSUED_ON, 'after', 'not a date', t as never, undefined, 'zh-CN')).toBe('after not a date'); + }); +}); diff --git a/ui/packages/plugin-list/src/conditions/conditionDates.ts b/ui/packages/plugin-list/src/conditions/conditionDates.ts new file mode 100644 index 00000000000..841fee19338 --- /dev/null +++ b/ui/packages/plugin-list/src/conditions/conditionDates.ts @@ -0,0 +1,57 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * How a date condition's value reads on a condition row (objectstack#37034). + * + * A row holds the value the query compares, written on the wire the way the + * field's type stores it: a `date` field's bound is a calendar day + * (`2026-10-01`), and a `datetime` field's bound is an ISO instant + * (`2026-10-01T00:00:00.000Z`; a dataset bucket's drill writes its month's + * bounds that way on a `created_at`). The row printed the value as written, so + * a zh-CN chip read 「创建时间:≥ 2026-10-01T00:00:00.000Z」. It reads as a + * date now, in the viewer's display locale, through the console's ONE date + * display path (`formatDate` / `formatDateTime` in `@object-ui/core`'s + * `date-display`): ⛔ no second formatter is written here. + * + * The field's type decides the face: + * + * - `date` names a calendar day, so the day is shown, with its year (a + * condition's bounds are read side by side). A `YYYY-MM-DD` value is that + * day in every zone. A date field compared with an instant at UTC midnight + * (an authored filter may write one) names the same day, so its leading + * `YYYY-MM-DD` is what is shown: read as an instant it would name the + * previous day west of UTC. + * - `datetime` is an instant: the date and the time in the display zone + * (`setDisplayTimeZone`, else the viewer's own). + * - `time` and anything else are shown as written. + * + * A value the display path cannot read (it answers `—`) is shown as written, + * so a row never hides what it compares. + */ + +import { formatDate, formatDateTime } from '@object-ui/core'; + +/** An instant at UTC midnight, captured as its calendar day. */ +const UTC_MIDNIGHT = /^(\d{4}-\d{2}-\d{2})T00:00(?::00(?:\.0+)?)?(?:Z|[+-]00:?00)$/; + +/** A date condition value as the row shows it: see the file header. */ +export function formatConditionDate(value: unknown, fieldType: string | undefined, locale: string | undefined): string { + if (typeof value !== 'string' && typeof value !== 'number') return String(value); + if (value === '') return value; + let shown: string; + if (fieldType === 'date') { + const day = typeof value === 'string' ? UTC_MIDNIGHT.exec(value)?.[1] ?? value : value; + shown = formatDate(day, undefined, { locale, alwaysShowYear: true }); + } else if (fieldType === 'datetime') { + shown = formatDateTime(value, { locale }); + } else { + return String(value); + } + return shown === '—' ? String(value) : shown; +} diff --git a/ui/packages/plugin-list/src/phone/PhoneListPanels.tsx b/ui/packages/plugin-list/src/phone/PhoneListPanels.tsx index 21f2cbfa7df..0b70cd730ed 100644 --- a/ui/packages/plugin-list/src/phone/PhoneListPanels.tsx +++ b/ui/packages/plugin-list/src/phone/PhoneListPanels.tsx @@ -48,6 +48,7 @@ import { type SortItem, } from '@object-ui/components'; import type { DataSource } from '@object-ui/types'; +import { useDisplayLocale } from '@object-ui/i18n'; import { ArrowUpDown, Check, ChevronLeft, GripVertical, Info, ListFilter, MoreHorizontal, Plus, X } from 'lucide-react'; import { FieldList } from '../conditions/FieldList'; import { isQuickRowApplied } from '../conditions/FilterValuePanel'; @@ -574,6 +575,8 @@ export function PhoneFilterSheet({ open, onOpenChange, fields, shownFields, valu const [staged, setStaged, step, setStep] = useStaged(open, value, { kind: 'list' }); const applied = (staged.conditions ?? []).filter(isQuickRowApplied); const nameOf = useLookupValueNames(dataSource, fields, applied); + // A date condition reads in the viewer's display locale, as the desktop chips do. + const locale = useDisplayLocale(); const independent = chipsAreIndependent(staged); const toList = () => setStep({ kind: 'list' }); @@ -626,7 +629,7 @@ export function PhoneFilterSheet({ open, onOpenChange, fields, shownFields, valu