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/36507-drill-relation-chip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@object-ui/plugin-list': patch
'@object-ui/i18n': patch
---

fix(plugin-list): a list's locked chip for a condition on a related record's field names the field and the value, instead of reading `[object Object]`

Clause-②: no
Metadata-protocol: none

A view filter that compares one field of a related record, the nested-relation form `{ crm_account: { industry: 'technology' } }`, now reads as one locked chip on the path `crm_account.industry`: 「Account › Industry: Technology」. The form is read as written and as lowered to `['crm_account', '=', { industry: 'technology' }]`, the shape a dashboard or report drill on a relationship-path dimension hands its list. Before, that chip read the lookup's label and `[object Object]`.

- The lookup's name is its label in the list's own field list. The related field's name and its option labels come from the related object's definition, translated as the list translates its own fields (`fields.<object>.<field>`, `fieldOptions.<object>.<field>.<value>`). Where a label is missing, the raw name shows.
- The row reads the related object's definition once per related object, only while such a chip is shown, through the host's data source.
- A nested condition the chip cannot say as one equality (several fields, an operator, a deeper relation) reads as the view's own condition (「View filter」), never as `[object Object]`.
- Every console locale gains `listConditions.chips.relationPath`.

The chip stays locked: the list cannot edit a related-record condition.
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5855,6 +5855,7 @@ const ar = {
dragSort: 'اسحب لتغيير أولوية الفرز',
viewOwn: 'جزء من طريقة العرض هذه؛ لا يمكن إزالته هنا',
viewFilter: 'تصفية طريقة العرض',
relationPath: '{{field}} ({{lookup}})',
},
},
sortBuilder: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5237,6 +5237,7 @@ const de = {
dragSort: 'Ziehen, um die Sortierpriorität zu ändern',
viewOwn: 'Teil dieser Ansicht; hier nicht entfernbar',
viewFilter: 'Ansichtsfilter',
relationPath: '{{lookup}} › {{field}}',
},
},
sortBuilder: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6002,6 +6002,7 @@ const en = {
dragSort: 'Drag to change the sort priority',
viewOwn: 'Part of this view; it cannot be removed here',
viewFilter: 'View filter',
relationPath: '{{lookup}} › {{field}}',
},
},
sortBuilder: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5392,6 +5392,7 @@ const es = {
dragSort: 'Arrastra para cambiar la prioridad del orden',
viewOwn: 'Forma parte de esta vista; no se puede quitar aquí',
viewFilter: 'Filtro de la vista',
relationPath: '{{lookup}} › {{field}}',
},
},
sortBuilder: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5388,6 +5388,7 @@ const fr = {
dragSort: 'Faire glisser pour changer la priorité du tri',
viewOwn: 'Fait partie de cette vue ; impossible à retirer ici',
viewFilter: 'Filtre de la vue',
relationPath: '{{lookup}} › {{field}}',
},
},
sortBuilder: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5239,6 +5239,7 @@ const ja = {
dragSort: 'ドラッグして並べ替えの優先順位を変更',
viewOwn: 'このビューの条件のため、ここでは削除できません',
viewFilter: 'ビューのフィルター',
relationPath: '{{lookup}}の{{field}}',
},
},
sortBuilder: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5236,6 +5236,7 @@ const ko = {
dragSort: '드래그하여 정렬 우선순위 변경',
viewOwn: '이 보기의 조건이므로 여기서 제거할 수 없음',
viewFilter: '보기 필터',
relationPath: '{{lookup}}의 {{field}}',
},
},
sortBuilder: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5387,6 +5387,7 @@ const pt = {
dragSort: 'Arraste para mudar a prioridade da ordenação',
viewOwn: 'Faz parte desta visualização; não pode ser removido aqui',
viewFilter: 'Filtro da visualização',
relationPath: '{{lookup}} › {{field}}',
},
},
sortBuilder: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5556,6 +5556,7 @@ const ru = {
dragSort: 'Перетащите, чтобы изменить приоритет сортировки',
viewOwn: 'Условие этого представления; удалить здесь нельзя',
viewFilter: 'Фильтр представления',
relationPath: '{{field}} ({{lookup}})',
},
},
sortBuilder: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/zh-Hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5296,6 +5296,7 @@ const zh = {
dragSort: '拖动以调整排序优先级',
viewOwn: '视图自带的条件,不能在这里删除',
viewFilter: '视图筛选',
relationPath: '{{lookup}}的{{field}}',
},
},
sortBuilder: {
Expand Down
1 change: 1 addition & 0 deletions ui/packages/i18n/src/locales/zh-Hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5296,6 +5296,7 @@ const zhHant = {
dragSort: '拖動以調整排序優先順序',
viewOwn: '檢視自帶的條件,不能在這裡刪除',
viewFilter: '檢視篩選',
relationPath: '{{lookup}}的{{field}}',
},
},
sortBuilder: {
Expand Down
131 changes: 125 additions & 6 deletions ui/packages/plugin-list/src/conditions/ListConditionControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
*
* All three are controlled: they read the host's filter group and sort array
* and hand back the next one. Nothing here stores anything or changes what a
* filter row or a sort entry looks like. The one read the row makes is the
* names of the records a lookup condition points at, through the host's data
* source (`useLookupValueNames`), so a chip says 「Account: Globex」, not the
* record's id.
* filter row or a sort entry looks like. The row makes two reads, both
* through the host's data source: the names of the records a lookup condition
* points at (`useLookupValueNames`), so a chip says 「Account: Globex」, not
* the record's id; and the definition of the object a view condition on a
* related record's field reaches (`useRelatedConditionFields`), so that chip
* says 「Account › Industry: Technology」.
*/

import * as React from 'react';
Expand All @@ -42,6 +44,7 @@ import {
} from '@object-ui/components';
import { referencedRecordTitle } from '@object-ui/core';
import type { DataSource } from '@object-ui/types';
import { 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 All @@ -53,6 +56,7 @@ import {
newConditionId,
quickFilterFamily,
readViewConditions,
relationPathOf,
removeCondition,
seedValueFor,
sortWording,
Expand Down Expand Up @@ -135,13 +139,127 @@ function viewChipText(
fields: ReadonlyArray<ConditionField>,
t: Translate,
nameOf?: LookupValueName,
relatedFieldOf?: RelatedFieldOf,
): string {
if (chip.anyOf) return chip.anyOf.map((member) => viewChipText(member, fields, t, nameOf)).join(t('listConditions.chips.or'));
if (chip.anyOf) {
return chip.anyOf.map((member) => viewChipText(member, fields, t, nameOf, relatedFieldOf)).join(t('listConditions.chips.or'));
}
if (!chip.field || !chip.operator) return t('listConditions.chips.viewFilter');
const path = relationPathOf(chip.field);
if (path) {
// A related record's field: 「Account › Industry: Technology」, each name
// its label where one is known and its raw name where none is. No record
// name is read for it (`nameOf` names the list's own lookups only).
const related = relatedFieldOf?.(chip.field);
const label = t('listConditions.chips.relationPath', {
lookup: fields.find((f) => f.value === path.lookup)?.label ?? path.lookup,
field: related?.label ?? path.field,
});
return t('listConditions.chips.pattern', {
field: label,
value: describeConditionValue(related, chip.operator, chip.value, t),
});
}
const field = fields.find((f) => f.value === chip.field);
return chipText(field, chip.field, chip.operator, chip.value, t, nameOf);
}

// ---------------------------------------------------------------------------
// Related fields
// ---------------------------------------------------------------------------

/** A related record's field, by its chip path `<lookup>.<field>`, or `undefined` while it is not read. */
export type RelatedFieldOf = (path: string) => ConditionField | undefined;

/** The value of a declared option (an array of `{ value, label }` or a keyed object) and its declared label. */
function declaredOptions(raw: unknown): Array<{ value: string; label: string }> | undefined {
if (!raw || typeof raw !== 'object') return undefined;
if (Array.isArray(raw)) {
return raw.map((o) => {
const value = o && typeof o === 'object' ? (o as { value?: unknown }).value : o;
const label = o && typeof o === 'object' ? (o as { label?: unknown }).label : undefined;
return { value: String(value), label: typeof label === 'string' && label ? label : String(value) };
});
}
return Object.entries(raw as Record<string, unknown>).map(([value, meta]) => {
const label = meta && typeof meta === 'object' ? (meta as { label?: unknown }).label : undefined;
return { value, label: typeof label === 'string' && label ? label : value };
});
}

/**
* The related fields the view's relation-path chips name (`<lookup>.<field>`),
* read from the definition of the object each lookup points at
* (`referenceTo`) through the host's data source: one definition read per
* target, again only when the targets change. The field's label and its
* options' labels are translated as the list translates its own fields
* (`fields.<object>.<field>`, `fieldOptions.<object>.<field>.<value>`), with
* the declared label, then the raw name, as the fallback.
*
* Keyed on the targets it reads, never on the identity of the arrays the host
* rebuilds every render (`ui/AGENTS.md` #10). A read that fails answers
* `undefined`: the chip keeps the raw names.
*/
export function useRelatedConditionFields(
dataSource: Pick<DataSource, 'getObjectSchema'> | null | undefined,
fields: ReadonlyArray<ConditionField>,
conditions: ReadonlyArray<NamedCondition>,
): RelatedFieldOf {
const { fieldLabel, translateOptions } = useSafeFieldLabel();
const wanted = new Set<string>();
for (const condition of conditions) {
const path = relationPathOf(condition.field);
const target = path ? fields.find((f) => f.value === path.lookup)?.referenceTo : undefined;
if (target) wanted.add(target);
}
const readKey = JSON.stringify([...wanted].sort());

const [read, setRead] = React.useState<{ key: string; defs: ReadonlyMap<string, unknown> } | null>(null);

React.useEffect(() => {
const targets = JSON.parse(readKey) as string[];
if (targets.length === 0 || !dataSource || typeof dataSource.getObjectSchema !== 'function') return;
let cancelled = false;
void Promise.all(
targets.map(async (target) => {
try {
return [target, await dataSource.getObjectSchema(target)] as const;
} catch {
// The chip keeps the raw names: the labels are a courtesy, the condition still filters.
return [target, undefined] as const;
}
}),
).then((answers) => {
if (!cancelled) setRead({ key: readKey, defs: new Map(answers) });
});
return () => {
cancelled = true;
};
}, [dataSource, readKey]);

const defs = read?.key === readKey ? read.defs : undefined;
return React.useCallback<RelatedFieldOf>(
(chipField) => {
const path = relationPathOf(chipField);
const target = path ? fields.find((f) => f.value === path.lookup)?.referenceTo : undefined;
if (!path || !target) return undefined;
const def = defs?.get(target) as { fields?: Record<string, { label?: unknown; type?: unknown; multiple?: unknown; options?: unknown }> } | undefined;
const declared = def?.fields?.[path.field];
if (!declared) return undefined;
const label = typeof declared.label === 'string' && declared.label ? declared.label : path.field;
const options = declaredOptions(declared.options);
return {
value: path.field,
label: fieldLabel(target, path.field, label),
type: typeof declared.type === 'string' ? declared.type : 'text',
multiple: declared.multiple === true,
...(options ? { options: translateOptions(target, path.field, options) } : {}),
};
},
[defs, fields, fieldLabel, translateOptions],
);
}

// ---------------------------------------------------------------------------
// Lookup names
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -568,6 +686,7 @@ export function ConditionChipRow({
...appliedRows,
];
const nameOf = useLookupValueNames(dataSource, filterFields, namedConditions);
const relatedFieldOf = useRelatedConditionFields(dataSource, filterFields, namedConditions);
const independent = chipsAreIndependent(filters);
// Nothing to show and nothing to offer: the row the host reserves stays empty.
if (!renderSortPanel && !filterOffered && !end && !trailing && sort.length === 0 && viewChips.length === 0 && appliedRows.length === 0) {
Expand Down Expand Up @@ -667,7 +786,7 @@ export function ConditionChipRow({
)}

{viewChips.map((chip) => {
const text = viewChipText(chip, filterFields, t, nameOf);
const text = viewChipText(chip, filterFields, t, nameOf, relatedFieldOf);
return (
<span
key={chip.key}
Expand Down
Loading
Loading