Skip to content

Commit 9c5fb3e

Browse files
fix(components, plugin-list, i18n): sort directions read by field type — size for numbers on the builder and the phone sheet (#37049)
repo:objectstack#4 · os-justin · session_01QSeKYnagJvGbCtNg2PhvgW Fixes #37027 Clause-②: no Metadata-protocol: none ## 维护者速读 - 列表「全部排序层级」和手机上的排序面板里,数字、百分比、进度、金额、布尔字段的方向选项从「A → Z / Z → A」改为「小 → 大 / 大 → 小」;日期与时间仍按「最早 → 最新」,文本仍按字母序;阿拉伯语的字母序方向不再显示反了。 - 列表页重做专题的里程碑验收发现的显示错误,让排序方向的说法与字段类型一致。 - 出错时只是方向文字不对,排序结果本身不变;可直接撤回。 - 无 ## What changes - `SortBuilder` (`ui/packages/components/src/custom/sort-builder.tsx`) had its own direction table that knew only `date` / `datetime`, so every other type read "A → Z". It now words a level by a module-local `sortWording` + `sortDirectionLabel` (no new package export): date-like types (`FILTER_DATE_LIKE_TYPES`: date, datetime, time) read as time, the spec's numeric family (`FILTER_NUMBER_LIKE_TYPES`: number, currency, percent, rating, slider, progress, summary) plus boolean as size, anything else as the alphabet, over the `listConditions.sort.{time,size,alphabet}_{asc,desc}` rows every locale already carries. No i18n key is added. - The phone sort sheet's levels (`ui/packages/plugin-list/src/phone/PhoneListPanels.tsx`) had the same date-only table over `sortBuilder.*` keys. They now read `sortDirectionLabel` from `plugin-list`'s `conditions/conditionModel.ts` (an internal module, not a package export), with the same rule and the same keys. The list's former `sortWording` / `ListConditionControls.sortDirectionLabel` pair, which had no non-test caller, is folded into that helper. - Trade-off, stated: the rule lives twice, module-local in `@object-ui/components` and in `plugin-list`'s condition model, over the same `@object-ui/types` lists and the same locale rows; each copy carries a comment pointing at its twin. One copy would need a new published export from `@object-ui/components` or `@object-ui/types`, which would make this `Clause-②: yes (widening)`. Both copies are pinned for number, progress, percent, currency, boolean, time, date and text, so the two cannot drift apart unnoticed. - `@object-ui/i18n`, Arabic: `listConditions.sort.alphabet_asc` / `alphabet_desc` read "A ← Z" / "Z ← A". A run of two Latin letters stays left to right on a right-to-left page, so ascending displayed as Z to A; this PR is the first to show those rows, so they now read "A → Z" / "Z → A". The key set is unchanged. - The four `sortBuilder.ascending/descending/oldestFirst/newestFirst` rows are no longer read by either surface (`plugin-list`'s provider-less defaults drop them). The locale rows stay in the published packs: removing them would be a narrowing. A host that overrode them now overrides `listConditions.sort.*`. - Visible wording that moves with the source rows: Japanese and Korean dates read 「古い → 新しい」 / 「오래된 순 → 최신 순」 (were 「古い順」 / 「오래된 순」), Russian dates "Старые → Новые" (was "Сначала старые") and Russian text "А → Я" (was "A → Z"). - `origin/main` merged in (merge commit 597bdd4). ## Tests - `ui/packages/components/src/__tests__/sort-builder-date-direction-duplicates-27520.test.tsx`: number, progress, percent and currency rows offer "Low → High" / "High → Low"; boolean reads as size and time as time; CONTROL: date keeps time and text keeps the alphabet. Under the real `I18nProvider`: zh number and progress rows read 「小 → 大」 / 「大 → 小」, and ar text rows read "A → Z" / "Z → A". These replace the removed plugin-list unit test of the dead helper. - `ui/packages/plugin-list/src/__tests__/ListView.phonePanels-35884.test.tsx`, on the real phone `ListView`: number, progress, percent, currency and boolean levels read "Low → High", a time level reads as time; CONTROL: date as time, text as the alphabet. ## Acceptance notes - Browser check, showcase app, zh-CN, `showcase_task` (Console from `ui/` source via Vite against a private backend): desktop sort builder options for `estimate_hours` and `progress` read `["小 → 大","大 → 小"]` and `due_date` reads `["最早 → 最新","最新 → 最早"]`. At phone width (390 px), a new `estimate_hours` or `progress` level reads 「小 → 大」. ## Verification <details><summary>Head f1c5804: tests, fails-before, ablation, typecheck</summary> - `cd ui && pnpm exec vitest run --maxWorkers=2 packages/plugin-list/src/__tests__/ListView.phonePanels-35884.test.tsx packages/plugin-list/src/conditions packages/components/src/__tests__/sort-builder packages/i18n/src/__tests__/all-locales-key-parity.test.ts`: VERDICT command-exit 0, Test Files 7 passed (7), Tests 167 passed (167). - Fails-before, SortBuilder (`sort-builder.tsx` at origin/main bytes): command-exit 1, the numeric case red; controls green. - Fails-before, phone (`PhoneListPanels.tsx` and `conditionTranslations.ts` at origin/main bytes): command-exit 1, number / progress / percent / currency red; controls green. - Ablation of the Arabic fix (`ar.ts` pair back to "A ← Z" / "Z ← A" through `scripts/ablation-replace.mjs`, landing confirmed injected=1 fixed=0; `@object-ui/i18n` resolves to `src` in the ui vitest config): the ar case is red; restored from HEAD, hash equal, tree clean. - `pnpm --filter @object-ui/plugin-list --filter @object-ui/components --filter @object-ui/i18n run type-check`: command-exit 0, all three Done. </details> <details><summary>Head f1c5804: gates</summary> - `dispatch-gates --ran`: 38 derived families, 38 run, 0 not measured, all exit 0 (including `pnpm --dir ui exec vitest run scripts/`: 172 files passed, 2 skipped). - i18n: `check:i18n-keys` 0, `check:i18n-drift` 0, `check:i18n-dead-keys` 0 (report lists the four unread `sortBuilder.*` direction rows). - overlap-check before the push: VERDICT clean exit 0. - CI check-runs on f1c5804: 45 success, 13 skipped, none failing. </details> --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QSeKYnagJvGbCtNg2PhvgW --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f588898 commit 9c5fb3e

10 files changed

Lines changed: 221 additions & 58 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@object-ui/components': patch
3+
'@object-ui/plugin-list': patch
4+
'@object-ui/i18n': patch
5+
---
6+
7+
fix(components, plugin-list): the sort builder and the phone sort sheet word a number, percent, progress or currency direction as size
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
A sort level on a numeric field read "A → Z" / "Z → A" in the sort builder (the list's "All sort levels" panel) and in the phone sort sheet's levels, while a date read "Oldest → Newest". Numeric, percent, progress, currency, rating and boolean levels now read "Low → High" / "High → Low" (zh: 「小 → 大」 / 「大 → 小」), date, datetime and time levels read as time, and text keeps the alphabet, on both surfaces. The words come from the `listConditions.sort.*` rows every locale already carries.
13+
14+
What else a reader sees change:
15+
16+
- The four `sortBuilder.ascending`, `sortBuilder.descending`, `sortBuilder.oldestFirst` and `sortBuilder.newestFirst` rows are no longer read by either surface; the rows stay in the packs. A host that overrode them to reword a sort direction now overrides `listConditions.sort.alphabet_asc` / `alphabet_desc` / `time_asc` / `time_desc` (and `size_asc` / `size_desc` for numbers) instead.
17+
- Because the words now come from `listConditions.sort.*`, the date and text wording changes in some locales: Japanese and Korean dates read 「古い → 新しい」 / 「오래된 순 → 최신 순」 instead of 「古い順」 / 「오래된 순」, Russian dates read "Старые → Новые" instead of "Сначала старые", and Russian text reads "А → Я" instead of "A → Z".
18+
- Arabic: the `listConditions.sort.alphabet_asc` / `alphabet_desc` pair now reads "A → Z" / "Z → A". A run of two Latin letters stays left to right on a right-to-left page, so the old "A ← Z" showed ascending as Z to A.

‎ui/packages/components/src/__tests__/sort-builder-date-direction-duplicates-27520.test.tsx‎

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
*/
2222
import { describe, it, expect, vi, afterEach } from 'vitest';
2323
import React from 'react';
24-
import { cleanup, render, screen, fireEvent, within } from '@testing-library/react';
24+
import { cleanup, render, screen, fireEvent, within, waitFor } from '@testing-library/react';
2525
import '@testing-library/jest-dom';
26+
import { I18nProvider } from '@object-ui/i18n';
2627
import { SortBuilder, type SortBuilderProps, type SortItem } from '../custom/sort-builder';
2728

2829
type Fields = NonNullable<SortBuilderProps['fields']>;
@@ -139,3 +140,65 @@ describe('SortBuilder keeps one row per field (objectstack#27520 row 7)', () =>
139140
expect(screen.getByRole('button', { name: /add sort/i })).toBeEnabled();
140141
});
141142
});
143+
144+
describe('SortBuilder words a direction by the field\'s type: size, time or the alphabet', () => {
145+
const NUMERIC: Fields = [
146+
{ value: 'title', label: 'Title', type: 'text' },
147+
{ value: 'due_date', label: 'Due Date', type: 'date' },
148+
{ value: 'estimate_hours', label: 'Estimate', type: 'number' },
149+
{ value: 'progress', label: 'Progress', type: 'progress' },
150+
{ value: 'completion', label: 'Completion', type: 'percent' },
151+
{ value: 'budget', label: 'Budget', type: 'currency' },
152+
{ value: 'active', label: 'Active', type: 'boolean' },
153+
{ value: 'starts_at', label: 'Starts At', type: 'time' },
154+
];
155+
const optionLabels = (i: number) => optionsOf(directionTriggers()[i]).map((o) => o.label);
156+
157+
it('number, progress, percent and currency rows read "Low → High" / "High → Low"', () => {
158+
mount([asc('estimate_hours'), asc('progress'), asc('completion'), { field: 'budget', order: 'desc' }], NUMERIC);
159+
for (const i of [0, 1, 2, 3]) expect(optionLabels(i)).toEqual(['Low → High', 'High → Low']);
160+
expect(directionTriggers()[3]).toHaveTextContent('High → Low');
161+
});
162+
163+
it('a boolean row reads as size and a time row as time', () => {
164+
mount([asc('active'), asc('starts_at')], NUMERIC);
165+
expect(optionLabels(0)).toEqual(['Low → High', 'High → Low']);
166+
expect(optionLabels(1)).toEqual(['Oldest → Newest', 'Newest → Oldest']);
167+
});
168+
169+
it('CONTROL: beside them a date keeps time and text keeps the alphabet', () => {
170+
mount([asc('due_date'), asc('title'), asc('estimate_hours')], NUMERIC);
171+
expect(optionLabels(0)).toEqual(['Oldest → Newest', 'Newest → Oldest']);
172+
expect(optionLabels(1)).toEqual(['A → Z', 'Z → A']);
173+
});
174+
});
175+
176+
describe('SortBuilder reads its direction words from the locale pack', () => {
177+
const PACK_FIELDS: Fields = [
178+
{ value: 'title', label: 'Title', type: 'text' },
179+
{ value: 'estimate_hours', label: 'Estimate', type: 'number' },
180+
{ value: 'progress', label: 'Progress', type: 'progress' },
181+
];
182+
const inLanguage = (language: string, initial: Row[]) =>
183+
render(
184+
<I18nProvider config={{ defaultLanguage: language, detectBrowserLanguage: false }} persistLanguage={false}>
185+
<Harness fields={PACK_FIELDS} initial={initial} onChange={() => {}} />
186+
</I18nProvider>,
187+
);
188+
const labelsAt = (i: number) => optionsOf(directionTriggers()[i]).map((o) => o.label);
189+
190+
it('zh: a number and a progress row read 「小 → 大」 / 「大 → 小」', async () => {
191+
inLanguage('zh', [asc('estimate_hours'), asc('progress')]);
192+
await waitFor(() => expect(directionTriggers()[0]).toHaveTextContent('小 → 大'));
193+
expect(labelsAt(0)).toEqual(['小 → 大', '大 → 小']);
194+
expect(labelsAt(1)).toEqual(['小 → 大', '大 → 小']);
195+
});
196+
197+
it('ar: a text row reads the Latin pair left to right, "A → Z" / "Z → A"', async () => {
198+
inLanguage('ar', [asc('title'), asc('estimate_hours')]);
199+
// The Arabic pack is in once the number row reads in Arabic; only then is
200+
// the text row's pair the pack's and not the built-in English default.
201+
await waitFor(() => expect(directionTriggers()[1]).toHaveTextContent('الأصغر ← الأكبر'));
202+
expect(labelsAt(0)).toEqual(['A → Z', 'Z → A']);
203+
});
204+
});

‎ui/packages/components/src/custom/sort-builder.tsx‎

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import * as React from "react"
1010
import { X, Plus, GripVertical } from "lucide-react"
1111
import { createSafeTranslation } from "@object-ui/i18n"
12+
import { FILTER_DATE_LIKE_TYPES, FILTER_NUMBER_LIKE_TYPES } from "@object-ui/types"
1213
import type { SortItem as SpecSortItem } from "@objectstack/spec/shared"
1314

1415
import { cn } from "../lib/utils"
@@ -20,19 +21,59 @@ const useSafeSortTranslation = createSafeTranslation(
2021
'sortBuilder.sortBy': 'Sort by',
2122
'sortBuilder.thenBy': 'Then by',
2223
'sortBuilder.selectField': 'Select field',
23-
'sortBuilder.ascending': 'A → Z',
24-
'sortBuilder.descending': 'Z → A',
25-
'sortBuilder.oldestFirst': 'Oldest → Newest',
26-
'sortBuilder.newestFirst': 'Newest → Oldest',
24+
'listConditions.sort.time_asc': 'Oldest → Newest',
25+
'listConditions.sort.time_desc': 'Newest → Oldest',
26+
'listConditions.sort.size_asc': 'Low → High',
27+
'listConditions.sort.size_desc': 'High → Low',
28+
'listConditions.sort.alphabet_asc': 'A → Z',
29+
'listConditions.sort.alphabet_desc': 'Z → A',
2730
'sortBuilder.addSort': 'Add sort',
2831
'sortBuilder.removeSort': 'Remove sort',
2932
'sortBuilder.reorder': 'Drag to reorder',
3033
},
3134
'sortBuilder.sortBy',
3235
)
3336

34-
/** Field types whose order is time: their direction reads "Oldest → Newest". */
35-
const DATE_SORT_TYPES = new Set(['date', 'datetime'])
37+
/** The direction words a sort level uses, by field type: time, size or the alphabet. */
38+
type SortWording = 'time' | 'size' | 'alphabet'
39+
40+
/** Ordered by time: the filter's date family. */
41+
const TIME_SORT_TYPES: ReadonlySet<string> = new Set<string>(FILTER_DATE_LIKE_TYPES)
42+
/** Ordered by size: the spec's numeric value family, and `boolean` (false < true). */
43+
const SIZE_SORT_TYPES: ReadonlySet<string> = new Set<string>([...FILTER_NUMBER_LIKE_TYPES, 'boolean'])
44+
45+
/**
46+
* Which words name a sort direction on a field of `type`, over the
47+
* `listConditions.sort.*` rows every locale carries. An unknown or absent type
48+
* reads as the alphabet.
49+
*
50+
* Twin: `sortDirectionLabel` in `ui/packages/plugin-list/src/conditions/conditionModel.ts`
51+
* words the phone sort sheet's levels by the same rule over the same rows. It
52+
* is a copy, not an import, because sharing it would add a published export
53+
* to this package; change both together.
54+
*/
55+
function sortWording(type: string | undefined): SortWording {
56+
if (type && TIME_SORT_TYPES.has(type)) return 'time'
57+
if (type && SIZE_SORT_TYPES.has(type)) return 'size'
58+
return 'alphabet'
59+
}
60+
61+
/** The words for one sort direction on a field of `type`: time, size or the alphabet. */
62+
function sortDirectionLabel(
63+
type: string | undefined,
64+
order: 'asc' | 'desc',
65+
t: (key: string) => string,
66+
): string {
67+
// Literal keys, not a template: the locale gates read keys by their text.
68+
switch (sortWording(type)) {
69+
case 'time':
70+
return order === 'asc' ? t('listConditions.sort.time_asc') : t('listConditions.sort.time_desc')
71+
case 'size':
72+
return order === 'asc' ? t('listConditions.sort.size_asc') : t('listConditions.sort.size_desc')
73+
default:
74+
return order === 'asc' ? t('listConditions.sort.alphabet_asc') : t('listConditions.sort.alphabet_desc')
75+
}
76+
}
3677

3778
/**
3879
* One row of the SortBuilder UI: the spec's `SortItem` (`{ field, order }`)
@@ -63,9 +104,10 @@ export interface SortBuilderProps {
63104
*/
64105
disabled?: boolean
65106
/**
66-
* The field's type (objectstack#27520). A `date` or `datetime` row names
67-
* its direction as time ("Oldest → Newest") instead of "A → Z". Absent,
68-
* the row reads "A → Z" as before.
107+
* The field's type (objectstack#27520). A date-like row names its
108+
* direction as time ("Oldest → Newest"), a numeric or boolean row as size
109+
* ("Low → High"), anything else as the alphabet ("A → Z"); see
110+
* {@link sortWording}. Absent, the row reads "A → Z".
69111
*/
70112
type?: string
71113
}>;
@@ -124,12 +166,12 @@ export function SortBuilder({
124166
// already sorts by is not offered again.
125167
const firstChoosable = fields.find((f) => !f.disabled && !heldBy.has(f.value));
126168

127-
// A date's direction is time, not the alphabet (objectstack#27520).
169+
// A date's direction is time and a number's is size, not the alphabet.
128170
const typeOf = new Map(fields.map((f) => [f.value, f.type]));
129-
const directionLabels = (field: string) =>
130-
DATE_SORT_TYPES.has(typeOf.get(field) ?? '')
131-
? { asc: t('sortBuilder.oldestFirst'), desc: t('sortBuilder.newestFirst') }
132-
: { asc: t('sortBuilder.ascending'), desc: t('sortBuilder.descending') };
171+
const directionLabels = (field: string) => ({
172+
asc: sortDirectionLabel(typeOf.get(field), 'asc', t),
173+
desc: sortDirectionLabel(typeOf.get(field), 'desc', t),
174+
});
133175

134176
const addItem = () => {
135177
const newItem: SortItem = {

‎ui/packages/i18n/src/locales/ar.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6102,8 +6102,8 @@ const ar = {
61026102
time_desc: 'الأحدث ← الأقدم',
61036103
size_asc: 'الأصغر ← الأكبر',
61046104
size_desc: 'الأكبر ← الأصغر',
6105-
alphabet_asc: 'A ← Z',
6106-
alphabet_desc: 'Z ← A',
6105+
alphabet_asc: 'A → Z',
6106+
alphabet_desc: 'Z → A',
61076107
},
61086108
chips: {
61096109
region: 'شروط الفرز والتصفية',

‎ui/packages/plugin-list/src/__tests__/ListView.phonePanels-35884.test.tsx‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,16 @@ function stubPhone() {
5757
})));
5858
}
5959

60-
function mount(schema: Partial<ListViewSchema> = {}, props: Record<string, unknown> = {}) {
60+
const OBJECT_FIELDS: Record<string, { type: string; label: string }> = {
61+
name: { type: 'text', label: 'Name' },
62+
stage: { type: 'text', label: 'Stage' },
63+
};
64+
65+
function mount(
66+
schema: Partial<ListViewSchema> = {},
67+
props: Record<string, unknown> = {},
68+
objectFields: Record<string, { type: string; label: string }> = OBJECT_FIELDS,
69+
) {
6170
const dataSource = {
6271
find: vi.fn().mockResolvedValue({ data: RECORDS, total: 1 }),
6372
findOne: vi.fn(),
@@ -66,7 +75,7 @@ function mount(schema: Partial<ListViewSchema> = {}, props: Record<string, unkno
6675
delete: vi.fn(),
6776
getObjectSchema: vi.fn().mockResolvedValue({
6877
name: 'account',
69-
fields: { name: { type: 'text', label: 'Name' }, stage: { type: 'text', label: 'Stage' } },
78+
fields: objectFields,
7079
}),
7180
};
7281
render(
@@ -326,3 +335,42 @@ describe('the phone sort levels (objectstack#35884)', () => {
326335
await waitFor(() => expect(handleOf(0)).toHaveFocus());
327336
});
328337
});
338+
339+
describe('the phone sort levels word a direction by the field\'s type', () => {
340+
const TYPED = {
341+
name: { type: 'text', label: 'Name' },
342+
due: { type: 'date', label: 'Due' },
343+
hours: { type: 'number', label: 'Hours' },
344+
progress: { type: 'progress', label: 'Progress' },
345+
done: { type: 'percent', label: 'Done' },
346+
budget: { type: 'currency', label: 'Budget' },
347+
active: { type: 'boolean', label: 'Active' },
348+
starts: { type: 'time', label: 'Starts' },
349+
};
350+
const directionOf = async (field: string) => {
351+
mount({ fields: Object.keys(TYPED) }, {}, TYPED);
352+
await screen.findByTestId('grid-stub');
353+
await addSortLevel(field);
354+
return screen.getByTestId('sort-builder-row-direction').textContent;
355+
};
356+
357+
for (const field of ['hours', 'progress', 'done', 'budget']) {
358+
it(`a ${TYPED[field as keyof typeof TYPED].type} level reads "Low → High"`, async () => {
359+
expect(await directionOf(field)).toContain('Low → High');
360+
});
361+
}
362+
363+
it('a boolean level reads as size', async () => {
364+
expect(await directionOf('active')).toContain('Low → High');
365+
});
366+
367+
it('a time level reads as time', async () => {
368+
expect(await directionOf('starts')).toContain('Oldest → Newest');
369+
});
370+
371+
it('CONTROL: a date level reads as time, a text level as the alphabet', async () => {
372+
expect(await directionOf('due')).toContain('Oldest → Newest');
373+
cleanup();
374+
expect(await directionOf('name')).toContain('A → Z');
375+
});
376+
});

‎ui/packages/plugin-list/src/conditions/ListConditionControls.tsx‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import {
5959
relationPathOf,
6060
removeCondition,
6161
seedValueFor,
62-
sortWording,
6362
upsertCondition,
6463
type ConditionField,
6564
type ViewConditionChip,
@@ -360,18 +359,6 @@ export function useLookupValueNames(
360359
);
361360
}
362361

363-
/** The words for one sort direction on a field of `type`: time, size or the alphabet. */
364-
export function sortDirectionLabel(type: string | undefined, order: 'asc' | 'desc', t: Translate): string {
365-
switch (sortWording(type)) {
366-
case 'time':
367-
return order === 'asc' ? t('listConditions.sort.time_asc') : t('listConditions.sort.time_desc');
368-
case 'size':
369-
return order === 'asc' ? t('listConditions.sort.size_asc') : t('listConditions.sort.size_desc');
370-
default:
371-
return order === 'asc' ? t('listConditions.sort.alphabet_asc') : t('listConditions.sort.alphabet_desc');
372-
}
373-
}
374-
375362
// ---------------------------------------------------------------------------
376363
// FilterPanel
377364
// ---------------------------------------------------------------------------

‎ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { act, fireEvent, render, screen, within } from '@testing-library/react';
2020
import type { FilterBuilderRowGroup, SortItem } from '@object-ui/components';
2121
import { FieldList, fieldTypeIcon, moveFieldInOrder, orderFieldList } from '../FieldList';
2222
import { FilterValuePanel, quickDateWindowValue } from '../FilterValuePanel';
23-
import { ConditionChipRow, FilterPanel, SortPanel, describeConditionValue, sortDirectionLabel } from '../ListConditionControls';
23+
import { ConditionChipRow, FilterPanel, SortPanel, describeConditionValue } from '../ListConditionControls';
2424
import {
2525
addSortLevel,
2626
chipsAreIndependent,
@@ -596,13 +596,6 @@ describe('SortPanel — the same field list with the direction on top', () => {
596596
render(<SortPanel fields={FIELDS} shownFields={SHOWN} value={[]} onChange={() => {}} />);
597597
expect(screen.queryByTestId('sort-panel-open-advanced')).toBeNull();
598598
});
599-
600-
it('words the direction by type: time for dates, size for numbers, the alphabet for text', () => {
601-
const t = (key: string) => LIST_CONDITION_DEFAULT_TRANSLATIONS[key] ?? key;
602-
expect(sortDirectionLabel('date', 'asc', t as never)).toBe('Oldest → Newest');
603-
expect(sortDirectionLabel('currency', 'desc', t as never)).toBe('High → Low');
604-
expect(sortDirectionLabel('text', 'asc', t as never)).toBe('A → Z');
605-
});
606599
});
607600

608601
describe('ConditionChipRow — the row under the view bar', () => {

‎ui/packages/plugin-list/src/conditions/conditionModel.ts‎

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,29 @@ export function addSortLevel(items: readonly SortItem[], field: string, order: '
163163
return [...items, { id, field, order }];
164164
}
165165

166-
/** The direction words a sort chip uses, by field type: time, size or the alphabet. */
167-
export type SortWording = 'time' | 'size' | 'alphabet';
168-
169-
export function sortWording(type: string | undefined): SortWording {
170-
if (type && DATE_TYPES.has(type)) return 'time';
171-
if (type && (NUMBER_TYPES.has(type) || type === 'boolean')) return 'size';
172-
return 'alphabet';
166+
/**
167+
* The words for one sort direction on a field of `type`: time for the date
168+
* family, size for the numeric family and `boolean`, the alphabet otherwise.
169+
* The phone sort sheet's levels read it.
170+
*
171+
* Twin: `sortWording` / `sortDirectionLabel` in
172+
* `ui/packages/components/src/custom/sort-builder.tsx` word `SortBuilder`'s
173+
* levels by the same three-way rule over the same `listConditions.sort.*`
174+
* rows. That copy stays module-local because sharing it would add a published
175+
* export to `@object-ui/components`; change both together.
176+
*/
177+
export function sortDirectionLabel(
178+
type: string | undefined,
179+
order: 'asc' | 'desc',
180+
t: (key: string) => string,
181+
): string {
182+
if (type && DATE_TYPES.has(type)) {
183+
return order === 'asc' ? t('listConditions.sort.time_asc') : t('listConditions.sort.time_desc');
184+
}
185+
if (type && (NUMBER_TYPES.has(type) || type === 'boolean')) {
186+
return order === 'asc' ? t('listConditions.sort.size_asc') : t('listConditions.sort.size_desc');
187+
}
188+
return order === 'asc' ? t('listConditions.sort.alphabet_asc') : t('listConditions.sort.alphabet_desc');
173189
}
174190

175191
/** One condition of the view's own filter, read for a locked chip. */

‎ui/packages/plugin-list/src/conditions/conditionTranslations.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,9 @@ export const LIST_CONDITION_DEFAULT_TRANSLATIONS: Record<string, string> = {
104104
'dashboard.filters.range.this_week': 'This week',
105105
'dashboard.filters.range.this_month': 'This month',
106106
'dashboard.filters.range.last_30_days': 'Last 30 days',
107-
// The phone sort sheet's level (objectstack#35884), in SortBuilder's words.
107+
// The phone sort sheet's level (objectstack#35884), in SortBuilder's words;
108+
// its direction reads the `listConditions.sort.*` rows above.
108109
'sortBuilder.addSort': 'Add sort',
109-
'sortBuilder.ascending': 'A → Z',
110-
'sortBuilder.descending': 'Z → A',
111-
'sortBuilder.oldestFirst': 'Oldest → Newest',
112-
'sortBuilder.newestFirst': 'Newest → Oldest',
113110
'sortBuilder.reorder': 'Drag to reorder',
114111
'sortBuilder.removeSort': 'Remove sort',
115112
'sortBuilder.levelOptions': 'Options for {{label}}',

0 commit comments

Comments
 (0)