Skip to content

Commit c3b69a9

Browse files
committed
fix(plugin-list): the sort picker leaves out a field the object marks hidden, as the filter list does
Claude-Session: https://claude.ai/code/session_01Utp6CY1ikAq74XRbNdsyUC Co-authored-by: Claude <noreply@anthropic.com>
1 parent 91cec45 commit c3b69a9

1 file changed

Lines changed: 31 additions & 9 deletions

File tree

‎ui/packages/plugin-list/src/ListView.tsx‎

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,22 @@ function canReadField(
16901690
return !perms?.isLoaded || !objectName || perms.checkField(objectName, field, 'read');
16911691
}
16921692

1693+
/**
1694+
* Whether the object definition marks a field `hidden: true`: the injected
1695+
* system columns `@objectstack/spec` hides from pickers (`organization_id`,
1696+
* `queue`, the `__search` companion). The toolbar's field lists ask this one
1697+
* predicate. The Filter panel's list and the Sort picker's list leave such a
1698+
* field out unless the current filter or sort already names it, so that row
1699+
* is not blank and can be removed; the hide-fields lists never offer one to
1700+
* add. A plain function of the definition's field map, like `canReadField`.
1701+
*/
1702+
function isDeclaredHidden(
1703+
defs: Record<string, { hidden?: unknown } | undefined> | undefined,
1704+
field: string,
1705+
): boolean {
1706+
return defs?.[field]?.hidden === true;
1707+
}
1708+
16931709
/** The item a value none of a picker's options carries is shown by. */
16941710
const OUTSIDE_OPTIONS = 'outside';
16951711

@@ -5173,7 +5189,7 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
51735189
*/
51745190
const filterFields = React.useMemo(() => {
51755191
const defs: Record<string, { hidden?: unknown; system?: boolean } | undefined> | undefined = objectDef?.fields;
5176-
const isHidden = (name: string) => defs?.[name]?.hidden === true;
5192+
const isHidden = (name: string) => isDeclaredHidden(defs, name);
51775193
const held = new Set((currentFilters.conditions ?? []).map((c) => c.field));
51785194
const columnRank = new Map<string, number>();
51795195
for (const column of effectiveFields) {
@@ -5257,14 +5273,19 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
52575273
// field the current sort already names (a stored or URL sort) stays listed,
52585274
// so its row is not blank and can be removed.
52595275
//
5276+
// A field the object definition marks `hidden: true` (`isDeclaredHidden`,
5277+
// the rule the Filter panel's list follows) is withheld the same way as an
5278+
// unreadable one: not offered, no relational hint, and kept by the in-use
5279+
// exception alone.
5280+
//
52605281
// An entry the exception alone keeps is listed REMOVABLE ONLY
52615282
// (objectui#11943): it carries `disabled`, which `SortBuilder` renders as an
52625283
// unavailable option. Its own row still shows its label and can be changed
52635284
// to another field or removed, but no row's dropdown offers it as a choice
52645285
// and "Add sort" never seeds it. That holds for each reason the exception
5265-
// keeps a field: unreadable, relational, or refused by the platform (or by
5266-
// the type read when no projection is served). A field the two rules list
5267-
// anyway carries no flag, whether or not the sort names it.
5286+
// keeps a field: unreadable, hidden, relational, or refused by the platform
5287+
// (or by the type read when no projection is served). A field the two rules
5288+
// list anyway carries no flag, whether or not the sort names it.
52685289
//
52695290
// Both legs below — the list this picker renders, and the sort it emits for
52705291
// a host to persist — read `platformSortability`, the ONE read of the served
@@ -5279,16 +5300,17 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
52795300
// stored ID: said in one line under the rows, only while it is true.
52805301
let picked = false;
52815302
const fields: Array<{ value: string; label: string; disabled?: boolean; type?: string }> = [];
5303+
const defs: Record<string, { hidden?: unknown } | undefined> | undefined = objectDef?.fields;
52825304
for (const field of candidateFields) {
5283-
const readable = canReadField(perms, schema.objectName, field.value);
5284-
if (!readable && !inUse.has(field.value)) continue;
5305+
const offered = canReadField(perms, schema.objectName, field.value) && !isDeclaredHidden(defs, field.value);
5306+
if (!offered && !inUse.has(field.value)) continue;
52855307
const relational = EXPANDABLE_FIELD_TYPES.has(field.type);
52865308
const platformSortable = platformSortability
52875309
? isPlatformSortableField(platformSortability, field.value)
52885310
: !UNMATERIALIZED_FIELD_TYPES.has(field.type);
52895311
// `type` lets the picker name a date's direction as time
52905312
// (objectstack#27520): "Oldest → Newest", not "A → Z".
5291-
if (readable && !relational && platformSortable) {
5313+
if (offered && !relational && platformSortable) {
52925314
fields.push({ value: field.value, label: field.label, type: field.type });
52935315
continue;
52945316
}
@@ -5306,7 +5328,7 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
53065328
if (relational) excluded = true;
53075329
}
53085330
return { sortFields: fields, sortHasRelationalField: excluded, sortPicksRelationalField: picked };
5309-
}, [candidateFields, currentSort, t, platformSortability, perms, schema.objectName]);
5331+
}, [candidateFields, currentSort, t, platformSortability, perms, schema.objectName, objectDef]);
53105332

53115333
/**
53125334
* [#6455] THE persist boundary: what this picker LISTS is not what it
@@ -5670,7 +5692,7 @@ export const ListView = React.forwardRef<ListViewHandle, ListViewProps>(({
56705692
const defs = objectDef.fields as Record<string, { label?: string; hidden?: unknown; system?: boolean } | undefined>;
56715693
const listed = new Set(allFields.map((f) => f.name));
56725694
const candidates = Object.entries(defs).filter(([name, def]) =>
5673-
!listed.has(name) && def?.hidden !== true && canReadField(perms, schema.objectName, name));
5695+
!listed.has(name) && !isDeclaredHidden(defs, name) && canReadField(perms, schema.objectName, name));
56745696
for (const tier of [false, true]) {
56755697
for (const [name, def] of candidates) {
56765698
if (isSystemManagedField(name, def) !== tier) continue;

0 commit comments

Comments
 (0)