Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/37034-date-condition-chips.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions examples/app-showcase/src/system/translations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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: '小计' },
Expand Down
2 changes: 1 addition & 1 deletion scripts/i18n-coverage-baseline.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 22 additions & 14 deletions ui/packages/plugin-list/src/conditions/ListConditionControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -125,23 +130,25 @@ 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),
});
}

function viewChipText(
chip: ViewConditionChip,
fields: ReadonlyArray<ConditionField>,
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);
Expand All @@ -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);
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -659,6 +666,7 @@ export function ConditionChipRow({
className,
}: ConditionChipRowProps) {
const { t } = useListConditionTranslation();
const locale = useDisplayLocale();
const [openChip, setOpenChip] = React.useState<string | null>(null);

// Keyed on the names, not on the array the host may rebuild every render.
Expand Down Expand Up @@ -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 (
<span
key={chip.key}
Expand All @@ -793,7 +801,7 @@ export function ConditionChipRow({
{independent
? appliedRows.map((row) => {
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 (
<span
key={row.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* which the host owns: one click is spent before any of these panels mounts.
*/

import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect, vi, beforeAll, afterAll } from 'vitest';
import * as React from 'react';
import { act, fireEvent, render, screen, within } from '@testing-library/react';
import type { FilterBuilderRowGroup, SortItem } from '@object-ui/components';
Expand All @@ -40,6 +40,8 @@ import { builtInLocales, en as enPack, zh as zhPack } from '@object-ui/i18n/loca
import { I18nProvider } from '@object-ui/i18n';
import { parseFilterAST } from '@objectstack/spec/data';
import { convertFilterGroupToAST } from '../../ListView';
import { PhoneFilterSheet } from '../../phone/PhoneListPanels';
import { setDisplayTimeZone } from '@object-ui/core';

// The server's JSON-column refusal set, read from the module every server face
// imports it from (`@objectstack/core`, which no UI package depends on): the
Expand Down Expand Up @@ -550,7 +552,7 @@ describe('multi-value fields — the quick filter and the advanced panel offer o
const enQuick = enPack.listConditions.operators as Record<string, string>;
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');
});
});

Expand Down Expand Up @@ -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<string, unknown>) =>
(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');
});
});

Expand Down Expand Up @@ -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) => (
<I18nProvider config={{ defaultLanguage: 'zh-CN', detectBrowserLanguage: false }} persistLanguage={false}>{node}</I18nProvider>
);
function zhChips(filters: FilterBuilderRowGroup, field: string): string[] {
render(inZh(
<ConditionChipRow
sort={[]}
sortFields={[ISSUED_ON, CREATED_AT]}
onSortChange={() => {}}
filters={filters}
filterFields={[ISSUED_ON, CREATED_AT]}
onFiltersChange={() => {}}
renderAdvanced={() => <div />}
renderSortLevels={() => <div />}
/>,
));
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(
<PhoneFilterSheet
open
onOpenChange={() => {}}
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');
});
});
Loading
Loading