diff --git a/.changeset/36462-chip-operator-labels.md b/.changeset/36462-chip-operator-labels.md new file mode 100644 index 00000000000..99d7572041b --- /dev/null +++ b/.changeset/36462-chip-operator-labels.md @@ -0,0 +1,10 @@ +--- +'@object-ui/plugin-list': patch +--- + +fix(plugin-list): a condition chip names an operator only the advanced filter panel writes in that panel's own words, never by its id + +Clause-②: no +Metadata-protocol: none + +A list or drill dialog whose conditions carry `is_not_null`, `is_null`, `greater_than`, `less_than`, `not_equals`, `icontains` or `ends_with` used to show the operator id on its chip ("Deal Value: is_not_null"). The chip, and the quick filter's operator choice, now read the advanced panel's word for it in every language ("Deal Value: Is not null", "金额:不为 null"). Any other operator spelling the chip cannot word is shown as "Condition" instead of its id; a view filter's comparison symbol (`>=`, `=`) still reads as written. A chip with no value no longer ends in a space. diff --git a/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx b/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx index d0d057ee43b..6bc56cca37f 100644 --- a/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx +++ b/ui/packages/plugin-list/src/conditions/ListConditionControls.tsx @@ -114,10 +114,10 @@ export function describeConditionValue( } else { text = list.map(String).join(joiner); } - // 「is any of」 is what a value list means on its own; every other operator is named. - return operator === 'in' || (operator === 'equals' && (family === 'option' || family === 'boolean')) - ? text - : `${opLabel} ${text}`; + // 「is any of」 is what a value list means on its own; every other operator is + // named, and with no value it is the operator alone, never one with a trailing space. + if (operator === 'in' || (operator === 'equals' && (family === 'option' || family === 'boolean'))) return text; + return text ? `${opLabel} ${text}` : opLabel; } function chipText( diff --git a/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx b/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx index 2ef6b2376fc..7bd6f561150 100644 --- a/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx +++ b/ui/packages/plugin-list/src/conditions/__tests__/listConditions.test.tsx @@ -36,7 +36,7 @@ import { readFileSync } from 'node:fs'; import { dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { operatorsForField } from '@object-ui/components'; -import { en as enPack, zh as zhPack } from '@object-ui/i18n/locales'; +import { builtInLocales, en as enPack, zh as zhPack } from '@object-ui/i18n/locales'; import { I18nProvider } from '@object-ui/i18n'; import { parseFilterAST } from '@objectstack/spec/data'; import { convertFilterGroupToAST } from '../../ListView'; @@ -1001,3 +1001,113 @@ describe('ConditionChipRow — a view condition on a related record\'s field (ob expect(ds.getObjectSchema).not.toHaveBeenCalled(); }); }); + +describe('ConditionChipRow — an operator only the advanced panel writes (objectstack#36462)', () => { + // A drill dialog's base filter carries the panel's own operators as view + // triples (`['amount', 'is_not_null', true]`); a reader's filter can carry + // them too, written by the advanced panel. Each chip names the operator in + // the panel's own words, never by its id. + const PANEL_ONLY = ['not_equals', 'greater_than', 'less_than', 'is_null', 'is_not_null', 'icontains', 'ends_with'] as const; + const fieldsIn = (amount: string, stage: string, name: string, lost: string): ConditionField[] => [ + { value: 'amount', label: amount, type: 'currency' }, + { value: 'stage', label: stage, type: 'select', options: [{ value: 'lost', label: lost }] }, + { value: 'name', label: name, type: 'text' }, + ]; + const EN_FIELDS = fieldsIn('Deal Value', 'Stage', 'Name', 'Lost'); + const ZH_FIELDS = fieldsIn('金额', '阶段', '名称', '输单'); + const VIEW_FILTER = [ + ['stage', 'not_equals', 'lost'], + ['amount', 'greater_than', 100], + ['amount', 'less_than', 500], + ['amount', 'is_null', true], + ['amount', 'is_not_null', true], + ['name', 'icontains', 'acme'], + ['name', 'ends_with', 'inc'], + ]; + + function Row(props: Partial>) { + return ( + {}} + renderAdvanced={() =>
} + renderSortLevels={() =>
} + {...props} + /> + ); + } + const chipTexts = () => screen.getAllByTestId('view-condition-chip').map((chip) => chip.textContent); + + it('en: each chip reads the panel\'s word for its operator', () => { + render(); + expect(chipTexts()).toEqual([ + 'Stage: Does not equal Lost', + 'Deal Value: Greater than 100', + 'Deal Value: Less than 500', + 'Deal Value: Is null', + 'Deal Value: Is not null', + 'Name: Contains (ignore case) acme', + 'Name: Ends with inc', + ]); + }); + + it('zh-CN: each chip reads the panel\'s word for its operator', async () => { + render( + + + , + ); + await screen.findAllByTestId('view-condition-chip'); + expect(chipTexts()).toEqual([ + '阶段:不等于 输单', + '金额:大于 100', + '金额:小于 500', + '金额:为 null', + '金额:不为 null', + '名称:包含(忽略大小写) acme', + '名称:以…结尾 inc', + ]); + }); + + it('the reader\'s own filter chip and its operator choice read the same words', () => { + const filters: FilterBuilderRowGroup = { + id: 'root', + logic: 'and', + conditions: [{ id: 'c1', field: 'amount', operator: 'is_not_null', value: undefined }], + }; + render(); + expect(screen.getByTestId('filter-chip-open-amount').textContent).toBe('Deal Value: Is not null'); + }); + + it('every pack words each of them, as the panel does, and never as the id', () => { + for (const [tag, pack] of Object.entries(builtInLocales)) { + const words = pack.filterBuilder.operators as Record; + for (const op of PANEL_ONLY) { + expect(words[op], `${tag} ${op}`).toBeTruthy(); + expect(words[op], `${tag} ${op}`).not.toBe(op); + } + } + }); + + it('an operator nothing words is named as a condition, never by its id, in en and zh-CN', async () => { + const unknown = [['amount', 'nin', [1, 2]], { field: 'amount', operator: 'exists' }]; + const { unmount } = render(); + expect(chipTexts()).toEqual(['Deal Value: Condition 1, 2', 'Deal Value: Condition']); + unmount(); + render( + + + , + ); + await screen.findAllByTestId('view-condition-chip'); + expect(chipTexts()).toEqual(['金额:条件 1、2', '金额:条件']); + }); + + it('CONTROL: a view triple\'s comparison symbol still reads as written', () => { + render(=', 10], ['amount', '!=', 0]]} />); + expect(chipTexts()).toEqual(['Deal Value: >= 10', 'Deal Value: != 0']); + }); +}); diff --git a/ui/packages/plugin-list/src/conditions/conditionTranslations.ts b/ui/packages/plugin-list/src/conditions/conditionTranslations.ts index 47d9eab1292..bb3678c454a 100644 --- a/ui/packages/plugin-list/src/conditions/conditionTranslations.ts +++ b/ui/packages/plugin-list/src/conditions/conditionTranslations.ts @@ -64,6 +64,15 @@ export const LIST_CONDITION_DEFAULT_TRANSLATIONS: Record = { 'listConditions.operators.between': 'between', 'listConditions.operators.before': 'before', 'listConditions.operators.after': 'after', + // The operators only the advanced panel writes, in the panel's own words: + // one key per operator, so a chip and the panel row it came from never differ. + 'filterBuilder.operators.not_equals': 'Does not equal', + 'filterBuilder.operators.greater_than': 'Greater than', + 'filterBuilder.operators.less_than': 'Less than', + 'filterBuilder.operators.is_null': 'Is null', + 'filterBuilder.operators.is_not_null': 'Is not null', + 'filterBuilder.operators.icontains': 'Contains (ignore case)', + 'filterBuilder.operators.ends_with': 'Ends with', 'listConditions.sort.advanced': 'All sort levels', 'listConditions.sort.direction': 'Direction', 'listConditions.sort.ascending': 'Ascending', @@ -130,8 +139,19 @@ export function quickOperatorLabel(operator: string, t: Translate): string { case 'between': return t('listConditions.operators.between'); case 'before': return t('listConditions.operators.before'); case 'after': return t('listConditions.operators.after'); - // An operator only the advanced panel writes keeps its stored id. - default: return operator; + // An operator only the advanced panel writes reads as that panel names it. + case 'not_equals': return t('filterBuilder.operators.not_equals'); + case 'greater_than': return t('filterBuilder.operators.greater_than'); + case 'less_than': return t('filterBuilder.operators.less_than'); + case 'is_null': return t('filterBuilder.operators.is_null'); + case 'is_not_null': return t('filterBuilder.operators.is_not_null'); + case 'icontains': return t('filterBuilder.operators.icontains'); + case 'ends_with': return t('filterBuilder.operators.ends_with'); + // A view triple's comparison symbol (`['amount', '>=', 10]`) already reads + // as a comparison, so it is shown as written. + case '=': case '!=': case '>': case '>=': case '<': case '<=': return operator; + // Any other spelling is named as a condition: a chip never shows a machine name. + default: return t('listConditions.filter.operator'); } }