Skip to content

Commit c99f176

Browse files
committed
fix(plugin-list): unfinished filter rows are not filters, date sorts read Oldest → Newest, one sort row per field, and an empty list says how to start
- A filter-panel row with no value is not counted on the badge, does not make the list "No matching records", and is not handed to the host's onFilterChange (so it is not stored as the user's list state). - SortBuilder reads an optional field type: date/datetime rows name the direction "Oldest → Newest"; a field another row holds is unavailable, "Add sort" seeds the first free field and disables when none is left. - The search-emptied empty state offers "Clear search". - The empty state offers Create whenever the host gives a create path and the user may create; an explicit addRecord.enabled: false still withholds it, and object-view hands no create path when Create is turned off. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgVW2q9rsHS1vCrQ8Q9
1 parent af6ca00 commit c99f176

17 files changed

Lines changed: 539 additions & 21 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@object-ui/plugin-list': patch
3+
'@object-ui/components': patch
4+
'@object-ui/plugin-view': patch
5+
'@object-ui/i18n': patch
6+
---
7+
8+
fix(plugin-list): a filter row with no value is not a filter, a date sort reads Oldest → Newest, a sort keeps one row per field, and an empty list says how to start
9+
10+
Clause-②: yes (widening: `@object-ui/i18n` gains `list.clearSearch`, `sortBuilder.oldestFirst` and `sortBuilder.newestFirst` in all ten locales, and `SortBuilder`'s `fields` entries take an optional `type`; no accept set moves)
11+
Metadata-protocol: none
12+
13+
- **Unfinished filter rows.** A filter-panel row with no value yet is no longer counted on the Filter badge, no longer turns the list into "No matching records", and is no longer handed to the host's `onFilterChange`, so the console does not store it as the user's list state and it does not come back after a reload. The panel still shows the row so it can be finished.
14+
- **Date sort direction.** The sort picker names a `date` or `datetime` field's direction "Oldest → Newest" / "Newest → Oldest" instead of "A → Z" / "Z → A". The list hands the picker each field's type.
15+
- **One sort row per field.** A field another sort row already orders by is unavailable in the other rows, "Add sort" starts on the first field no row holds, and it is disabled once every field has a row.
16+
- **Clear search.** The "No matching records" a search produced offers "Clear search". The clear button inside the search box is now named "Clear search" too.
17+
- **Create on an empty list.** An empty list offers Create whenever the host gives a create path and the user may create, without the view having to declare an inline `addRecord` block. An author's `addRecord: { enabled: false }` or `userActions.addRecordForm: false` still withholds it, and the `object-view` renderer no longer hands its list a create path when the author turned Create off (`showCreate: false` or `operations.create: false`).
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack#27520 row 7, the sort half: `SortBuilder` names a date's
11+
* direction as time, and keeps one row per field.
12+
*
13+
* Observed in the RC walkthrough on the Tasks list toolbar: the direction of a
14+
* datetime sort read "A → Z", and the same field could be added to the sort
15+
* twice. The second key on a field the first already orders by changes
16+
* nothing, so a duplicate row is a control that does nothing.
17+
*
18+
* Every case reads the real `SortBuilder` and its real Radix `Select`, and
19+
* keeps its control beside it: a text field still reads "A → Z", and a field
20+
* no other row holds is still an ordinary option.
21+
*/
22+
import { describe, it, expect, vi, afterEach } from 'vitest';
23+
import React from 'react';
24+
import { cleanup, render, screen, fireEvent, within } from '@testing-library/react';
25+
import '@testing-library/jest-dom';
26+
import { SortBuilder, type SortBuilderProps, type SortItem } from '../custom/sort-builder';
27+
28+
type Fields = NonNullable<SortBuilderProps['fields']>;
29+
type Row = Pick<SortItem, 'field' | 'order'>;
30+
31+
const FIELDS: Fields = [
32+
{ value: 'title', label: 'Title', type: 'text' },
33+
{ value: 'due_date', label: 'Due Date', type: 'date' },
34+
{ value: 'created_at', label: 'Created At', type: 'datetime' },
35+
];
36+
37+
/** Holds the value the way a host does, so a change is rendered back. */
38+
function Harness({ fields, initial, onChange }: { fields: Fields; initial: Row[]; onChange: (rows: Row[]) => void }) {
39+
const [value, setValue] = React.useState<SortItem[]>(() =>
40+
initial.map((row, i) => ({ id: `r${i}`, ...row })),
41+
);
42+
return (
43+
<SortBuilder
44+
fields={fields}
45+
value={value}
46+
onChange={(next) => {
47+
onChange(next.map(({ field, order }) => ({ field, order })));
48+
setValue(next);
49+
}}
50+
/>
51+
);
52+
}
53+
54+
function mount(initial: Row[], fields: Fields = FIELDS) {
55+
const onChange = vi.fn();
56+
render(<Harness fields={fields} initial={initial} onChange={onChange} />);
57+
return onChange;
58+
}
59+
60+
/** Each row is `[field select, direction select]`. */
61+
const fieldTriggers = () => screen.getAllByRole('combobox').filter((_, i) => i % 2 === 0);
62+
const directionTriggers = () => screen.getAllByRole('combobox').filter((_, i) => i % 2 === 1);
63+
64+
/** Open a dropdown and return what it offers, closing it again. */
65+
function optionsOf(trigger: HTMLElement): Array<{ label: string; disabled: boolean }> {
66+
fireEvent.click(trigger);
67+
const listbox = screen.getByRole('listbox');
68+
const options = within(listbox).getAllByRole('option').map((o) => ({
69+
label: o.textContent?.trim() ?? '',
70+
disabled: o.getAttribute('aria-disabled') === 'true',
71+
}));
72+
fireEvent.keyDown(listbox, { key: 'Escape' });
73+
return options;
74+
}
75+
76+
const asc = (field: string): Row => ({ field, order: 'asc' });
77+
78+
afterEach(() => {
79+
cleanup();
80+
});
81+
82+
describe('SortBuilder names a date sort as time (objectstack#27520 row 7)', () => {
83+
it('a date row reads "Oldest → Newest" / "Newest → Oldest"; a datetime row too', () => {
84+
mount([asc('due_date'), { field: 'created_at', order: 'desc' }]);
85+
const [dateDir, datetimeDir] = directionTriggers();
86+
expect(dateDir).toHaveTextContent('Oldest → Newest');
87+
expect(datetimeDir).toHaveTextContent('Newest → Oldest');
88+
expect(optionsOf(dateDir).map((o) => o.label)).toEqual(['Oldest → Newest', 'Newest → Oldest']);
89+
});
90+
91+
it('CONTROL: a text row keeps "A → Z" / "Z → A"', () => {
92+
mount([asc('title')]);
93+
expect(directionTriggers()[0]).toHaveTextContent('A → Z');
94+
expect(optionsOf(directionTriggers()[0]).map((o) => o.label)).toEqual(['A → Z', 'Z → A']);
95+
});
96+
97+
it('the label follows the row when its field changes from text to date', () => {
98+
mount([asc('title')]);
99+
fireEvent.click(fieldTriggers()[0]);
100+
fireEvent.click(within(screen.getByRole('listbox')).getByRole('option', { name: 'Due Date' }));
101+
expect(directionTriggers()[0]).toHaveTextContent('Oldest → Newest');
102+
});
103+
104+
it('CONTROL: a field entry with no type keeps "A → Z"', () => {
105+
mount([asc('due_date')], FIELDS.map(({ value, label }) => ({ value, label })));
106+
expect(directionTriggers()[0]).toHaveTextContent('A → Z');
107+
});
108+
});
109+
110+
describe('SortBuilder keeps one row per field (objectstack#27520 row 7)', () => {
111+
it('a field another row sorts by is unavailable in this row; the row\'s own field and the free ones are not', () => {
112+
mount([asc('title'), asc('due_date')]);
113+
expect(optionsOf(fieldTriggers()[1])).toEqual([
114+
{ label: 'Title', disabled: true },
115+
{ label: 'Due Date', disabled: false },
116+
{ label: 'Created At', disabled: false },
117+
]);
118+
// CONTROL: the first row sees the second row's field the same way.
119+
expect(optionsOf(fieldTriggers()[0])).toEqual([
120+
{ label: 'Title', disabled: false },
121+
{ label: 'Due Date', disabled: true },
122+
{ label: 'Created At', disabled: false },
123+
]);
124+
});
125+
126+
it('"Add sort" seeds the first field no row holds, not the first field', () => {
127+
const onChange = mount([asc('title')]);
128+
fireEvent.click(screen.getByRole('button', { name: /add sort/i }));
129+
expect(onChange).toHaveBeenLastCalledWith([asc('title'), asc('due_date')]);
130+
});
131+
132+
it('"Add sort" is disabled once every field has a row', () => {
133+
mount([asc('title'), asc('due_date'), asc('created_at')]);
134+
expect(screen.getByRole('button', { name: /add sort/i })).toBeDisabled();
135+
});
136+
137+
it('CONTROL: with a field still free, "Add sort" stays enabled', () => {
138+
mount([asc('title'), asc('due_date')]);
139+
expect(screen.getByRole('button', { name: /add sort/i })).toBeEnabled();
140+
});
141+
});

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

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ const useSafeSortTranslation = createSafeTranslation(
2222
'sortBuilder.selectField': 'Select field',
2323
'sortBuilder.ascending': 'A → Z',
2424
'sortBuilder.descending': 'Z → A',
25+
'sortBuilder.oldestFirst': 'Oldest → Newest',
26+
'sortBuilder.newestFirst': 'Newest → Oldest',
2527
'sortBuilder.addSort': 'Add sort',
2628
'sortBuilder.removeSort': 'Remove sort',
2729
},
2830
'sortBuilder.sortBy',
2931
)
3032

33+
/** Field types whose order is time: their direction reads "Oldest → Newest". */
34+
const DATE_SORT_TYPES = new Set(['date', 'datetime'])
35+
3136
/**
3237
* One row of the SortBuilder UI: the spec's `SortItem` (`{ field, order }`)
3338
* plus the React key this list needs.
@@ -56,6 +61,12 @@ export interface SortBuilderProps {
5661
* disabled, and is itself disabled when every entry is.
5762
*/
5863
disabled?: boolean
64+
/**
65+
* The field's type (objectstack#27520). A `date` or `datetime` row names
66+
* its direction as time ("Oldest → Newest") instead of "A → Z". Absent,
67+
* the row reads "A → Z" as before.
68+
*/
69+
type?: string
5970
}>;
6071
value?: SortItem[];
6172
onChange?: (value: SortItem[]) => void;
@@ -97,9 +108,27 @@ export function SortBuilder({
97108
onChange?.(newItems);
98109
};
99110

111+
// One row per field (objectstack#27520): a second key on a field the sort
112+
// already orders by changes nothing, so a field another row holds is not
113+
// offered to this one. A row's own field stays choosable in its dropdown.
114+
const heldBy = new Map<string, string>();
115+
for (const item of items) if (item.field && !heldBy.has(item.field)) heldBy.set(item.field, item.id);
116+
const takenElsewhere = (field: string, rowId: string) => {
117+
const holder = heldBy.get(field);
118+
return holder !== undefined && holder !== rowId;
119+
};
120+
100121
// A new row starts on the first field the user may choose: a disabled
101-
// entry is only there for the row that already names it.
102-
const firstChoosable = fields.find((f) => !f.disabled);
122+
// entry is only there for the row that already names it, and a field a row
123+
// already sorts by is not offered again.
124+
const firstChoosable = fields.find((f) => !f.disabled && !heldBy.has(f.value));
125+
126+
// A date's direction is time, not the alphabet (objectstack#27520).
127+
const typeOf = new Map(fields.map((f) => [f.value, f.type]));
128+
const directionLabels = (field: string) =>
129+
DATE_SORT_TYPES.has(typeOf.get(field) ?? '')
130+
? { asc: t('sortBuilder.oldestFirst'), desc: t('sortBuilder.newestFirst') }
131+
: { asc: t('sortBuilder.ascending'), desc: t('sortBuilder.descending') };
103132

104133
const addItem = () => {
105134
const newItem: SortItem = {
@@ -121,7 +150,9 @@ export function SortBuilder({
121150
return (
122151
<div className={cn("space-y-3", className)}>
123152
<div className="space-y-2">
124-
{items.map((item, index) => (
153+
{items.map((item, index) => {
154+
const direction = directionLabels(item.field);
155+
return (
125156
<div key={item.id} className="flex items-center gap-2">
126157
<span className="text-sm font-medium w-16 text-muted-foreground">
127158
{index === 0 ? t('sortBuilder.sortBy') : t('sortBuilder.thenBy')}
@@ -136,12 +167,18 @@ export function SortBuilder({
136167
</SelectTrigger>
137168
<SelectContent>
138169
{fields.map(f => (
139-
<SelectItem key={f.value} value={f.value} disabled={f.disabled}>{f.label}</SelectItem>
170+
<SelectItem
171+
key={f.value}
172+
value={f.value}
173+
disabled={f.disabled || takenElsewhere(f.value, item.id)}
174+
>
175+
{f.label}
176+
</SelectItem>
140177
))}
141178
</SelectContent>
142179
</Select>
143180
</div>
144-
<div className="w-28">
181+
<div className="w-36">
145182
<Select
146183
value={item.order}
147184
onValueChange={(val) => updateItem(item.id, { order: val as 'asc' | 'desc' })}
@@ -150,8 +187,8 @@ export function SortBuilder({
150187
<SelectValue />
151188
</SelectTrigger>
152189
<SelectContent>
153-
<SelectItem value="asc">{t('sortBuilder.ascending')}</SelectItem>
154-
<SelectItem value="desc">{t('sortBuilder.descending')}</SelectItem>
190+
<SelectItem value="asc">{direction.asc}</SelectItem>
191+
<SelectItem value="desc">{direction.desc}</SelectItem>
155192
</SelectContent>
156193
</Select>
157194
</div>
@@ -165,7 +202,8 @@ export function SortBuilder({
165202
<X className="h-4 w-4" />
166203
</Button>
167204
</div>
168-
))}
205+
);
206+
})}
169207
</div>
170208
<Button
171209
variant="outline"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ const ar = {
849849
firstRunMessage: "أنشئ سجلك الأول للبدء.",
850850
noMatches: "لا توجد سجلات مطابقة",
851851
noMatchesMessage: "لا توجد سجلات تطابق عوامل التصفية أو البحث الحالية. حاول تعديلها أو مسحها.",
852+
clearSearch: "مسح البحث",
852853
viewFilterNoMatchesMessage: "لا توجد سجلات تطابق عامل التصفية لطريقة العرض هذه.",
853854
ownedNoneTitle: "لا يوجد شيء يخصك بعد",
854855
ownedNoneMessage: "تعرض طريقة العرض هذه سجلاتك فقط، وليس لديك أي سجل بعد.",
@@ -5040,6 +5041,8 @@ const ar = {
50405041
selectField: "اختر الحقل",
50415042
ascending: "A → Z",
50425043
descending: "Z → A",
5044+
oldestFirst: "الأقدم → الأحدث",
5045+
newestFirst: "الأحدث → الأقدم",
50435046
addSort: "إضافة ترتيب",
50445047
removeSort: "إزالة الترتيب",
50455048
},

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ const de = {
759759
firstRunMessage: "Legen Sie Ihren ersten Datensatz an, um loszulegen.",
760760
noMatches: "Keine passenden Datensätze",
761761
noMatchesMessage: "Keine Datensätze entsprechen Ihren aktuellen Filtern oder Ihrer Suche. Passen Sie sie an oder setzen Sie sie zurück.",
762+
clearSearch: "Suche löschen",
762763
viewFilterNoMatchesMessage: "Keine Datensätze entsprechen dem Filter dieser Ansicht.",
763764
ownedNoneTitle: "Noch nichts von Ihnen",
764765
ownedNoneMessage: "Diese Ansicht listet nur Ihre eigenen Datensätze auf, und Sie haben noch keine.",
@@ -4587,6 +4588,8 @@ const de = {
45874588
selectField: "Feld auswählen",
45884589
ascending: "A → Z",
45894590
descending: "Z → A",
4591+
oldestFirst: "Älteste → Neueste",
4592+
newestFirst: "Neueste → Älteste",
45904593
addSort: "Sortierung hinzufügen",
45914594
removeSort: "Sortierung entfernen",
45924595
},

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ const en = {
10621062
firstRunMessage: 'Create your first record to get started.',
10631063
noMatches: 'No matching records',
10641064
noMatchesMessage: 'No records match your current filters or search. Try adjusting or clearing them.',
1065+
clearSearch: 'Clear search',
10651066
viewFilterNoMatchesMessage: 'No records match this view’s filter.',
10661067
ownedNoneTitle: 'Nothing of yours yet',
10671068
ownedNoneMessage: 'This view lists only records that are yours, and you don’t have any yet.',
@@ -5248,6 +5249,8 @@ const en = {
52485249
selectField: 'Select field',
52495250
ascending: 'A → Z',
52505251
descending: 'Z → A',
5252+
oldestFirst: 'Oldest → Newest',
5253+
newestFirst: 'Newest → Oldest',
52515254
addSort: 'Add sort',
52525255
removeSort: 'Remove sort',
52535256
},

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ const es = {
785785
firstRunMessage: "Cree su primer registro para empezar.",
786786
noMatches: "No hay registros coincidentes",
787787
noMatchesMessage: "Ningún registro coincide con sus filtros o su búsqueda actuales. Pruebe a ajustarlos o borrarlos.",
788+
clearSearch: "Borrar búsqueda",
788789
viewFilterNoMatchesMessage: "Ningún registro coincide con el filtro de esta vista.",
789790
ownedNoneTitle: "Aún no tiene nada propio",
790791
ownedNoneMessage: "Esta vista solo muestra sus propios registros, y todavía no tiene ninguno.",
@@ -4701,6 +4702,8 @@ const es = {
47014702
selectField: "Seleccionar campo",
47024703
ascending: "A → Z",
47034704
descending: "Z → A",
4705+
oldestFirst: "Más antiguo → Más reciente",
4706+
newestFirst: "Más reciente → Más antiguo",
47044707
addSort: "Agregar orden",
47054708
removeSort: "Quitar orden",
47064709
},

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ const fr = {
780780
firstRunMessage: "Créez votre premier enregistrement pour commencer.",
781781
noMatches: "Aucun enregistrement correspondant",
782782
noMatchesMessage: "Aucun enregistrement ne correspond à vos filtres ou à votre recherche. Essayez de les ajuster ou de les effacer.",
783+
clearSearch: "Effacer la recherche",
783784
viewFilterNoMatchesMessage: "Aucun enregistrement ne correspond au filtre de cette vue.",
784785
ownedNoneTitle: "Rien à vous pour l'instant",
785786
ownedNoneMessage: "Cette vue ne liste que vos propres enregistrements, et vous n'en avez encore aucun.",
@@ -4697,6 +4698,8 @@ const fr = {
46974698
selectField: "Sélectionner un champ",
46984699
ascending: "A → Z",
46994700
descending: "Z → A",
4701+
oldestFirst: "Plus ancien → Plus récent",
4702+
newestFirst: "Plus récent → Plus ancien",
47004703
addSort: "Ajouter un tri",
47014704
removeSort: "Supprimer le tri",
47024705
},

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ const ja = {
759759
firstRunMessage: "最初のレコードを作成して始めましょう。",
760760
noMatches: "該当するレコードがありません",
761761
noMatchesMessage: "現在のフィルターや検索条件に一致するレコードはありません。条件を調整するか解除してください。",
762+
clearSearch: "検索をクリア",
762763
viewFilterNoMatchesMessage: "このビューのフィルターに一致するレコードはありません。",
763764
ownedNoneTitle: "あなたのレコードはまだありません",
764765
ownedNoneMessage: "このビューにはあなたのレコードだけが表示されますが、まだ1件もありません。",
@@ -4589,6 +4590,8 @@ const ja = {
45894590
selectField: "フィールドを選択",
45904591
ascending: "A → Z",
45914592
descending: "Z → A",
4593+
oldestFirst: "古い順",
4594+
newestFirst: "新しい順",
45924595
addSort: "並べ替えを追加",
45934596
removeSort: "並べ替えを削除",
45944597
},

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ const ko = {
759759
firstRunMessage: "첫 레코드를 만들어 시작하세요.",
760760
noMatches: "일치하는 레코드가 없습니다",
761761
noMatchesMessage: "현재 필터나 검색어와 일치하는 레코드가 없습니다. 조건을 조정하거나 지워 보세요.",
762+
clearSearch: "검색 지우기",
762763
viewFilterNoMatchesMessage: "이 뷰의 필터와 일치하는 레코드가 없습니다.",
763764
ownedNoneTitle: "아직 내 레코드가 없습니다",
764765
ownedNoneMessage: "이 뷰에는 내 레코드만 표시되며, 아직 하나도 없습니다.",
@@ -4586,6 +4587,8 @@ const ko = {
45864587
selectField: "필드 선택",
45874588
ascending: "A → Z",
45884589
descending: "Z → A",
4590+
oldestFirst: "오래된 순",
4591+
newestFirst: "최신 순",
45894592
addSort: "정렬 추가",
45904593
removeSort: "정렬 삭제",
45914594
},

0 commit comments

Comments
 (0)