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/sort-builder-size-wording.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@object-ui/components': patch
'@object-ui/plugin-list': patch
'@object-ui/i18n': patch
---

fix(components, plugin-list): the sort builder and the phone sort sheet word a number, percent, progress or currency direction as size

Clause-②: no
Metadata-protocol: none

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.

What else a reader sees change:

- 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.
- 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".
- 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.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
*/
import { describe, it, expect, vi, afterEach } from 'vitest';
import React from 'react';
import { cleanup, render, screen, fireEvent, within } from '@testing-library/react';
import { cleanup, render, screen, fireEvent, within, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import { I18nProvider } from '@object-ui/i18n';
import { SortBuilder, type SortBuilderProps, type SortItem } from '../custom/sort-builder';

type Fields = NonNullable<SortBuilderProps['fields']>;
Expand Down Expand Up @@ -139,3 +140,65 @@ describe('SortBuilder keeps one row per field (objectstack#27520 row 7)', () =>
expect(screen.getByRole('button', { name: /add sort/i })).toBeEnabled();
});
});

describe('SortBuilder words a direction by the field\'s type: size, time or the alphabet', () => {
const NUMERIC: Fields = [
{ value: 'title', label: 'Title', type: 'text' },
{ value: 'due_date', label: 'Due Date', type: 'date' },
{ value: 'estimate_hours', label: 'Estimate', type: 'number' },
{ value: 'progress', label: 'Progress', type: 'progress' },
{ value: 'completion', label: 'Completion', type: 'percent' },
{ value: 'budget', label: 'Budget', type: 'currency' },
{ value: 'active', label: 'Active', type: 'boolean' },
{ value: 'starts_at', label: 'Starts At', type: 'time' },
];
const optionLabels = (i: number) => optionsOf(directionTriggers()[i]).map((o) => o.label);

it('number, progress, percent and currency rows read "Low → High" / "High → Low"', () => {
mount([asc('estimate_hours'), asc('progress'), asc('completion'), { field: 'budget', order: 'desc' }], NUMERIC);
for (const i of [0, 1, 2, 3]) expect(optionLabels(i)).toEqual(['Low → High', 'High → Low']);
expect(directionTriggers()[3]).toHaveTextContent('High → Low');
});

it('a boolean row reads as size and a time row as time', () => {
mount([asc('active'), asc('starts_at')], NUMERIC);
expect(optionLabels(0)).toEqual(['Low → High', 'High → Low']);
expect(optionLabels(1)).toEqual(['Oldest → Newest', 'Newest → Oldest']);
});

it('CONTROL: beside them a date keeps time and text keeps the alphabet', () => {
mount([asc('due_date'), asc('title'), asc('estimate_hours')], NUMERIC);
expect(optionLabels(0)).toEqual(['Oldest → Newest', 'Newest → Oldest']);
expect(optionLabels(1)).toEqual(['A → Z', 'Z → A']);
});
});

describe('SortBuilder reads its direction words from the locale pack', () => {
const PACK_FIELDS: Fields = [
{ value: 'title', label: 'Title', type: 'text' },
{ value: 'estimate_hours', label: 'Estimate', type: 'number' },
{ value: 'progress', label: 'Progress', type: 'progress' },
];
const inLanguage = (language: string, initial: Row[]) =>
render(
<I18nProvider config={{ defaultLanguage: language, detectBrowserLanguage: false }} persistLanguage={false}>
<Harness fields={PACK_FIELDS} initial={initial} onChange={() => {}} />
</I18nProvider>,
);
const labelsAt = (i: number) => optionsOf(directionTriggers()[i]).map((o) => o.label);

it('zh: a number and a progress row read 「小 → 大」 / 「大 → 小」', async () => {
inLanguage('zh', [asc('estimate_hours'), asc('progress')]);
await waitFor(() => expect(directionTriggers()[0]).toHaveTextContent('小 → 大'));
expect(labelsAt(0)).toEqual(['小 → 大', '大 → 小']);
expect(labelsAt(1)).toEqual(['小 → 大', '大 → 小']);
});

it('ar: a text row reads the Latin pair left to right, "A → Z" / "Z → A"', async () => {
inLanguage('ar', [asc('title'), asc('estimate_hours')]);
// The Arabic pack is in once the number row reads in Arabic; only then is
// the text row's pair the pack's and not the built-in English default.
await waitFor(() => expect(directionTriggers()[1]).toHaveTextContent('الأصغر ← الأكبر'));
expect(labelsAt(0)).toEqual(['A → Z', 'Z → A']);
});
});
70 changes: 56 additions & 14 deletions ui/packages/components/src/custom/sort-builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import * as React from "react"
import { X, Plus, GripVertical } from "lucide-react"
import { createSafeTranslation } from "@object-ui/i18n"
import { FILTER_DATE_LIKE_TYPES, FILTER_NUMBER_LIKE_TYPES } from "@object-ui/types"
import type { SortItem as SpecSortItem } from "@objectstack/spec/shared"

import { cn } from "../lib/utils"
Expand All @@ -20,19 +21,59 @@ const useSafeSortTranslation = createSafeTranslation(
'sortBuilder.sortBy': 'Sort by',
'sortBuilder.thenBy': 'Then by',
'sortBuilder.selectField': 'Select field',
'sortBuilder.ascending': 'A → Z',
'sortBuilder.descending': 'Z → A',
'sortBuilder.oldestFirst': 'Oldest → Newest',
'sortBuilder.newestFirst': 'Newest → Oldest',
'listConditions.sort.time_asc': 'Oldest → Newest',
'listConditions.sort.time_desc': 'Newest → Oldest',
'listConditions.sort.size_asc': 'Low → High',
'listConditions.sort.size_desc': 'High → Low',
'listConditions.sort.alphabet_asc': 'A → Z',
'listConditions.sort.alphabet_desc': 'Z → A',
'sortBuilder.addSort': 'Add sort',
'sortBuilder.removeSort': 'Remove sort',
'sortBuilder.reorder': 'Drag to reorder',
},
'sortBuilder.sortBy',
)

/** Field types whose order is time: their direction reads "Oldest → Newest". */
const DATE_SORT_TYPES = new Set(['date', 'datetime'])
/** The direction words a sort level uses, by field type: time, size or the alphabet. */
type SortWording = 'time' | 'size' | 'alphabet'

/** Ordered by time: the filter's date family. */
const TIME_SORT_TYPES: ReadonlySet<string> = new Set<string>(FILTER_DATE_LIKE_TYPES)
/** Ordered by size: the spec's numeric value family, and `boolean` (false < true). */
const SIZE_SORT_TYPES: ReadonlySet<string> = new Set<string>([...FILTER_NUMBER_LIKE_TYPES, 'boolean'])

/**
* Which words name a sort direction on a field of `type`, over the
* `listConditions.sort.*` rows every locale carries. An unknown or absent type
* reads as the alphabet.
*
* Twin: `sortDirectionLabel` in `ui/packages/plugin-list/src/conditions/conditionModel.ts`
* words the phone sort sheet's levels by the same rule over the same rows. It
* is a copy, not an import, because sharing it would add a published export
* to this package; change both together.
*/
function sortWording(type: string | undefined): SortWording {
if (type && TIME_SORT_TYPES.has(type)) return 'time'
if (type && SIZE_SORT_TYPES.has(type)) return 'size'
return 'alphabet'
}

/** The words for one sort direction on a field of `type`: time, size or the alphabet. */
function sortDirectionLabel(
type: string | undefined,
order: 'asc' | 'desc',
t: (key: string) => string,
): string {
// Literal keys, not a template: the locale gates read keys by their text.
switch (sortWording(type)) {
case 'time':
return order === 'asc' ? t('listConditions.sort.time_asc') : t('listConditions.sort.time_desc')
case 'size':
return order === 'asc' ? t('listConditions.sort.size_asc') : t('listConditions.sort.size_desc')
default:
return order === 'asc' ? t('listConditions.sort.alphabet_asc') : t('listConditions.sort.alphabet_desc')
}
}

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

// A date's direction is time, not the alphabet (objectstack#27520).
// A date's direction is time and a number's is size, not the alphabet.
const typeOf = new Map(fields.map((f) => [f.value, f.type]));
const directionLabels = (field: string) =>
DATE_SORT_TYPES.has(typeOf.get(field) ?? '')
? { asc: t('sortBuilder.oldestFirst'), desc: t('sortBuilder.newestFirst') }
: { asc: t('sortBuilder.ascending'), desc: t('sortBuilder.descending') };
const directionLabels = (field: string) => ({
asc: sortDirectionLabel(typeOf.get(field), 'asc', t),
desc: sortDirectionLabel(typeOf.get(field), 'desc', t),
});

const addItem = () => {
const newItem: SortItem = {
Expand Down
4 changes: 2 additions & 2 deletions ui/packages/i18n/src/locales/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6102,8 +6102,8 @@ const ar = {
time_desc: 'الأحدث ← الأقدم',
size_asc: 'الأصغر ← الأكبر',
size_desc: 'الأكبر ← الأصغر',
alphabet_asc: 'A ← Z',
alphabet_desc: 'Z ← A',
alphabet_asc: 'A → Z',
alphabet_desc: 'Z → A',
},
chips: {
region: 'شروط الفرز والتصفية',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ function stubPhone() {
})));
}

function mount(schema: Partial<ListViewSchema> = {}, props: Record<string, unknown> = {}) {
const OBJECT_FIELDS: Record<string, { type: string; label: string }> = {
name: { type: 'text', label: 'Name' },
stage: { type: 'text', label: 'Stage' },
};

function mount(
schema: Partial<ListViewSchema> = {},
props: Record<string, unknown> = {},
objectFields: Record<string, { type: string; label: string }> = OBJECT_FIELDS,
) {
const dataSource = {
find: vi.fn().mockResolvedValue({ data: RECORDS, total: 1 }),
findOne: vi.fn(),
Expand All @@ -66,7 +75,7 @@ function mount(schema: Partial<ListViewSchema> = {}, props: Record<string, unkno
delete: vi.fn(),
getObjectSchema: vi.fn().mockResolvedValue({
name: 'account',
fields: { name: { type: 'text', label: 'Name' }, stage: { type: 'text', label: 'Stage' } },
fields: objectFields,
}),
};
render(
Expand Down Expand Up @@ -326,3 +335,42 @@ describe('the phone sort levels (objectstack#35884)', () => {
await waitFor(() => expect(handleOf(0)).toHaveFocus());
});
});

describe('the phone sort levels word a direction by the field\'s type', () => {
const TYPED = {
name: { type: 'text', label: 'Name' },
due: { type: 'date', label: 'Due' },
hours: { type: 'number', label: 'Hours' },
progress: { type: 'progress', label: 'Progress' },
done: { type: 'percent', label: 'Done' },
budget: { type: 'currency', label: 'Budget' },
active: { type: 'boolean', label: 'Active' },
starts: { type: 'time', label: 'Starts' },
};
const directionOf = async (field: string) => {
mount({ fields: Object.keys(TYPED) }, {}, TYPED);
await screen.findByTestId('grid-stub');
await addSortLevel(field);
return screen.getByTestId('sort-builder-row-direction').textContent;
};

for (const field of ['hours', 'progress', 'done', 'budget']) {
it(`a ${TYPED[field as keyof typeof TYPED].type} level reads "Low → High"`, async () => {
expect(await directionOf(field)).toContain('Low → High');
});
}

it('a boolean level reads as size', async () => {
expect(await directionOf('active')).toContain('Low → High');
});

it('a time level reads as time', async () => {
expect(await directionOf('starts')).toContain('Oldest → Newest');
});

it('CONTROL: a date level reads as time, a text level as the alphabet', async () => {
expect(await directionOf('due')).toContain('Oldest → Newest');
cleanup();
expect(await directionOf('name')).toContain('A → Z');
});
});
13 changes: 0 additions & 13 deletions ui/packages/plugin-list/src/conditions/ListConditionControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import {
relationPathOf,
removeCondition,
seedValueFor,
sortWording,
upsertCondition,
type ConditionField,
type ViewConditionChip,
Expand Down Expand Up @@ -360,18 +359,6 @@ export function useLookupValueNames(
);
}

/** The words for one sort direction on a field of `type`: time, size or the alphabet. */
export function sortDirectionLabel(type: string | undefined, order: 'asc' | 'desc', t: Translate): string {
switch (sortWording(type)) {
case 'time':
return order === 'asc' ? t('listConditions.sort.time_asc') : t('listConditions.sort.time_desc');
case 'size':
return order === 'asc' ? t('listConditions.sort.size_asc') : t('listConditions.sort.size_desc');
default:
return order === 'asc' ? t('listConditions.sort.alphabet_asc') : t('listConditions.sort.alphabet_desc');
}
}

// ---------------------------------------------------------------------------
// FilterPanel
// ---------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { act, fireEvent, render, screen, within } from '@testing-library/react';
import type { FilterBuilderRowGroup, SortItem } from '@object-ui/components';
import { FieldList, fieldTypeIcon, moveFieldInOrder, orderFieldList } from '../FieldList';
import { FilterValuePanel, quickDateWindowValue } from '../FilterValuePanel';
import { ConditionChipRow, FilterPanel, SortPanel, describeConditionValue, sortDirectionLabel } from '../ListConditionControls';
import { ConditionChipRow, FilterPanel, SortPanel, describeConditionValue } from '../ListConditionControls';
import {
addSortLevel,
chipsAreIndependent,
Expand Down Expand Up @@ -596,13 +596,6 @@ describe('SortPanel — the same field list with the direction on top', () => {
render(<SortPanel fields={FIELDS} shownFields={SHOWN} value={[]} onChange={() => {}} />);
expect(screen.queryByTestId('sort-panel-open-advanced')).toBeNull();
});

it('words the direction by type: time for dates, size for numbers, the alphabet for text', () => {
const t = (key: string) => LIST_CONDITION_DEFAULT_TRANSLATIONS[key] ?? key;
expect(sortDirectionLabel('date', 'asc', t as never)).toBe('Oldest → Newest');
expect(sortDirectionLabel('currency', 'desc', t as never)).toBe('High → Low');
expect(sortDirectionLabel('text', 'asc', t as never)).toBe('A → Z');
});
});

describe('ConditionChipRow — the row under the view bar', () => {
Expand Down
30 changes: 23 additions & 7 deletions ui/packages/plugin-list/src/conditions/conditionModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,29 @@ export function addSortLevel(items: readonly SortItem[], field: string, order: '
return [...items, { id, field, order }];
}

/** The direction words a sort chip uses, by field type: time, size or the alphabet. */
export type SortWording = 'time' | 'size' | 'alphabet';

export function sortWording(type: string | undefined): SortWording {
if (type && DATE_TYPES.has(type)) return 'time';
if (type && (NUMBER_TYPES.has(type) || type === 'boolean')) return 'size';
return 'alphabet';
/**
* The words for one sort direction on a field of `type`: time for the date
* family, size for the numeric family and `boolean`, the alphabet otherwise.
* The phone sort sheet's levels read it.
*
* Twin: `sortWording` / `sortDirectionLabel` in
* `ui/packages/components/src/custom/sort-builder.tsx` word `SortBuilder`'s
* levels by the same three-way rule over the same `listConditions.sort.*`
* rows. That copy stays module-local because sharing it would add a published
* export to `@object-ui/components`; change both together.
*/
export function sortDirectionLabel(
type: string | undefined,
order: 'asc' | 'desc',
t: (key: string) => string,
): string {
if (type && DATE_TYPES.has(type)) {
return order === 'asc' ? t('listConditions.sort.time_asc') : t('listConditions.sort.time_desc');
}
if (type && (NUMBER_TYPES.has(type) || type === 'boolean')) {
return order === 'asc' ? t('listConditions.sort.size_asc') : t('listConditions.sort.size_desc');
}
return order === 'asc' ? t('listConditions.sort.alphabet_asc') : t('listConditions.sort.alphabet_desc');
}

/** One condition of the view's own filter, read for a locked chip. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,9 @@ export const LIST_CONDITION_DEFAULT_TRANSLATIONS: Record<string, string> = {
'dashboard.filters.range.this_week': 'This week',
'dashboard.filters.range.this_month': 'This month',
'dashboard.filters.range.last_30_days': 'Last 30 days',
// The phone sort sheet's level (objectstack#35884), in SortBuilder's words.
// The phone sort sheet's level (objectstack#35884), in SortBuilder's words;
// its direction reads the `listConditions.sort.*` rows above.
'sortBuilder.addSort': 'Add sort',
'sortBuilder.ascending': 'A → Z',
'sortBuilder.descending': 'Z → A',
'sortBuilder.oldestFirst': 'Oldest → Newest',
'sortBuilder.newestFirst': 'Newest → Oldest',
'sortBuilder.reorder': 'Drag to reorder',
'sortBuilder.removeSort': 'Remove sort',
'sortBuilder.levelOptions': 'Options for {{label}}',
Expand Down
Loading
Loading