An open source design system that's fully customizable and agent ready
TypeScript
Fix PowerSearch operator value menu limits (#5242)
nynexman4464e17d7f077b96
diff --git a/.changeset/powersearch-applies-operator-menu-limit.md b/.changeset/powersearch-applies-operator-menu-limit.mdnew file mode 100644index 0000000000..3322e251e2--- /dev/null+++ b/.changeset/powersearch-applies-operator-menu-limit.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] PowerSearch: `maxOperatorMenuItems` now caps suggestions in string, string-list, and entity-list value typeaheads, including values inside nested filters.++@nynexman4464diff --git a/packages/core/src/PowerSearch/PowerSearch.doc.mjs b/packages/core/src/PowerSearch/PowerSearch.doc.mjsindex 5877453f39..c9d646e7d4 100644--- a/packages/core/src/PowerSearch/PowerSearch.doc.mjs+++ b/packages/core/src/PowerSearch/PowerSearch.doc.mjs@@ -103,6 +103,13 @@ export const docs = {description: 'Max character length for filter value display in tokens.',default: '40',},+ {+ name: 'maxOperatorMenuItems',+ type: 'number',+ description:+ 'Maximum suggestions shown in string and entity value typeaheads. Does not affect the main field search menu or enum value menus.',+ default: '10',+ },{name: 'popoverSaveButtonLabel',type: 'string',@@ -294,6 +301,13 @@ export const docsZh = {description: '令牌中过滤器值显示的最大字符长度。',default: '40',},+ {+ name: 'maxOperatorMenuItems',+ type: 'number',+ description:+ '字符串和实体值预输入菜单中显示的最大建议数。不影响主字段搜索菜单或枚举值菜单。',+ default: '10',+ },{name: 'popoverSaveButtonLabel',type: 'string',@@ -374,6 +388,8 @@ export const docsDense = {startIcon: 'Icon at input start, before filter tokens. Forwarded to internal Tokenizer.',statusVariant: 'How status message is placed: attached overlaps below input; detached floats below w/ spacing.',maxTokenLength: 'Max char length for filter value display in tokens.',+ maxOperatorMenuItems:+ 'Max suggestions in string/entity value typeaheads; excludes main field search + enum menus.',popoverSaveButtonLabel: 'Label for save button in edit popover.',timezoneID: 'Timezone ID for date formatting (e.g. "America/New_York").',handleRef: 'Imperative handle w/ focusTypeahead() + blurTypeahead() methods.',diff --git a/packages/core/src/PowerSearch/PowerSearch.test.tsx b/packages/core/src/PowerSearch/PowerSearch.test.tsxindex e7c8861696..02387aac0d 100644--- a/packages/core/src/PowerSearch/PowerSearch.test.tsx+++ b/packages/core/src/PowerSearch/PowerSearch.test.tsx@@ -11,7 +11,14 @@import {useState} from 'react';import {describe, it, expect, vi, beforeAll, afterAll, afterEach} from 'vitest';-import {render, screen, act, fireEvent, waitFor} from '@testing-library/react';+import {+ render,+ screen,+ act,+ fireEvent,+ waitFor,+ within,+} from '@testing-library/react';import userEvent from '@testing-library/user-event';import {PowerSearch} from './PowerSearch';import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';@@ -492,3 +499,66 @@ describe('PowerSearch statusVariant forwarding', () => {);});});++describe('maxOperatorMenuItems', () => {+ it('caps entity suggestions after selecting a field', async () => {+ const people = Array.from({length: 6}, (_, index) => ({+ id: `person-${index}`,+ label: `Person ${index}`,+ }));+ const config: PowerSearchConfig = {+ name: 'PeopleSearch',+ fields: [+ {+ key: 'person',+ label: 'Person',+ defaultOperator: 'is_any_of',+ operators: [+ {+ key: 'is_any_of',+ label: 'is any of',+ value: {+ type: 'entity_list',+ searchSource: {+ search: query =>+ people.filter(person => person.label.includes(query)),+ bootstrap: () => people,+ },+ },+ },+ ],+ },+ ],+ };+ const user = userEvent.setup();+ render(+ <PowerSearch+ config={config}+ filters={[+ {+ field: 'person',+ operator: 'is_any_of',+ value: {type: 'entity_list', value: [people[0]]},+ },+ ]}+ onChange={() => {}}+ maxOperatorMenuItems={2}+ />,+ );++ await user.click(screen.getByRole('button', {name: 'Person: is any of'}));+ const inputs = screen.getAllByRole('combobox', {hidden: true});+ const valueInput = inputs[inputs.length - 1];+ await user.type(valueInput, 'Person');++ const listboxID = valueInput.getAttribute('aria-controls');+ expect(listboxID).not.toBeNull();+ const listbox = document.getElementById(listboxID!);+ expect(listbox).not.toBeNull();+ await waitFor(() => {+ expect(+ within(listbox!).getAllByRole('option', {hidden: true}),+ ).toHaveLength(2);+ });+ });+});diff --git a/packages/core/src/PowerSearch/PowerSearch.tsx b/packages/core/src/PowerSearch/PowerSearch.tsxindex 463c1d6f08..58faab6fff 100644--- a/packages/core/src/PowerSearch/PowerSearch.tsx+++ b/packages/core/src/PowerSearch/PowerSearch.tsx@@ -406,7 +406,7 @@ export interface PowerSearchProps extends Omit<menuWidth?: number;/** Max display length for filter token values. @default 40 */maxTokenLength?: number;- /** Max items in operator dropdown. */+ /** Max suggestions in string and entity value typeaheads. @default 10 */maxOperatorMenuItems?: number;/** Label for the save button in edit popover. @default 'Apply' */popoverSaveButtonLabel?: string;@@ -548,6 +548,7 @@ export function PowerSearch({status,statusVariant = 'attached',maxTokenLength = 40,+ maxOperatorMenuItems,popoverSaveButtonLabel: popoverSaveButtonLabelFromProps,timezoneID,tokenOverflowBehavior,@@ -967,6 +968,7 @@ export function PowerSearch({onSave={handlePopoverSave}onCancel={handlePopoverCancel}saveButtonLabel={popoverSaveButtonLabel}+ maxMenuItems={maxOperatorMenuItems}isReadOnly={isReadOnly}/>);@@ -979,6 +981,7 @@ export function PowerSearch({handlePopoverSave,handlePopoverCancel,popoverSaveButtonLabel,+ maxOperatorMenuItems,isReadOnly,]);diff --git a/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx b/packages/core/src/PowerSearch/PowerSearchEditPopover.tsxindex c70eb490ff..500af1feed 100644--- a/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx+++ b/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx@@ -105,6 +105,8 @@ export interface PowerSearchEditPopoverProps {onCancel: () => void;/** Label for the save button. @default 'Apply' */saveButtonLabel?: string;+ /** Max suggestions in string and entity value typeaheads. */+ maxMenuItems?: number;/** Whether the filter is read-only. */isReadOnly?: boolean;}@@ -247,6 +249,7 @@ interface NestedSubFilterRowProps {config: InternalConfig;subFilter: EditablePartialFilter;onChange: (subFilter: EditablePartialFilter) => void;+ maxMenuItems?: number;isReadOnly: boolean;}@@ -254,6 +257,7 @@ function NestedSubFilterRow({config,subFilter,onChange,+ maxMenuItems,isReadOnly,}: NestedSubFilterRowProps) {const t = useTranslator();@@ -356,6 +360,7 @@ function NestedSubFilterRow({filterValue={subFilter.value}onChange={handleValueChange}config={config}+ maxMenuItems={maxMenuItems}isDisabled={isReadOnly}/></div>@@ -374,6 +379,7 @@ interface NestedEditorProps {operatorOptions: {value: string; label: string}[];onOperatorChange: (operatorKey: string) => void;onPartialFilterChange: (filter: PartialFilter) => void;+ maxMenuItems?: number;isReadOnly: boolean;}@@ -383,6 +389,7 @@ function NestedEditor({operatorOptions,onOperatorChange,onPartialFilterChange,+ maxMenuItems,isReadOnly,}: NestedEditorProps) {const t = useTranslator();@@ -504,6 +511,7 @@ function NestedEditor({config={config}subFilter={sf}onChange={updated => handleUpdate(itemPath, updated)}+ maxMenuItems={maxMenuItems}isReadOnly={isReadOnly}/>),@@ -530,6 +538,7 @@ function NestedEditor({config={config}subFilter={sf}onChange={updated => handleUpdate(itemPath, updated)}+ maxMenuItems={maxMenuItems}isReadOnly={isReadOnly}/>),@@ -608,6 +617,7 @@ export function PowerSearchEditPopover({onSave,onCancel,saveButtonLabel: saveButtonLabelFromProps,+ maxMenuItems,isReadOnly = false,}: PowerSearchEditPopoverProps) {const t = useTranslator();@@ -777,6 +787,7 @@ export function PowerSearchEditPopover({operatorOptions={operatorOptions}onOperatorChange={handleOperatorChange}onPartialFilterChange={setPartialFilter}+ maxMenuItems={maxMenuItems}isReadOnly={isReadOnly}/></VStack>@@ -850,6 +861,7 @@ export function PowerSearchEditPopover({onChange={handleValueChange}onEnter={handleSave}config={config}+ maxMenuItems={maxMenuItems}isDisabled={isReadOnly}/></div>diff --git a/packages/core/src/PowerSearch/PowerSearchValueEditor.test.tsx b/packages/core/src/PowerSearch/PowerSearchValueEditor.test.tsxindex 8251dbc308..16f023fcc6 100644--- a/packages/core/src/PowerSearch/PowerSearchValueEditor.test.tsx+++ b/packages/core/src/PowerSearch/PowerSearchValueEditor.test.tsx@@ -10,7 +10,11 @@import {describe, it, expect, vi, beforeAll, afterAll} from 'vitest';import {render, screen, fireEvent, act} from '@testing-library/react';import {PowerSearchValueEditor} from './PowerSearchValueEditor';-import type {FilterValueEntityList, PowerSearchEntity} from './types';+import type {+ FilterValueEntityList,+ OperatorValue,+ PowerSearchEntity,+} from './types';import type {InternalConfig} from './useInternalConfig';import type {SearchableItem, SearchSource} from '../Typeahead/types';@@ -404,3 +408,45 @@ describe('StringListEditor (#1107)', () => {expect(screen.getByRole('combobox')).toBeInTheDocument();});});++describe('maxMenuItems', () => {+ const source = createSearchSource(+ Array.from({length: 6}, (_, index) => ({+ id: `option-${index}`,+ label: `Option ${index}`,+ })),+ );++ async function expectCapped(operatorValue: OperatorValue) {+ render(+ <PowerSearchValueEditor+ operatorValue={operatorValue}+ filterValue={undefined}+ onChange={vi.fn()}+ config={stubConfig}+ maxMenuItems={2}+ />,+ );++ await act(async () => {+ fireEvent.change(screen.getByRole('combobox'), {+ target: {value: 'Option'},+ });+ await new Promise(resolve => setTimeout(resolve, 200));+ });++ expect(screen.getAllByRole('option', {hidden: true})).toHaveLength(2);+ }++ it('caps string suggestions', async () => {+ await expectCapped({type: 'string', searchSource: source});+ });++ it('caps string-list suggestions', async () => {+ await expectCapped({type: 'string_list', searchSource: source});+ });++ it('caps entity-list suggestions', async () => {+ await expectCapped({type: 'entity_list', searchSource: source});+ });+});diff --git a/packages/core/src/PowerSearch/PowerSearchValueEditor.tsx b/packages/core/src/PowerSearch/PowerSearchValueEditor.tsxindex 33eae40958..62f6e91740 100644--- a/packages/core/src/PowerSearch/PowerSearchValueEditor.tsx+++ b/packages/core/src/PowerSearch/PowerSearchValueEditor.tsx@@ -40,6 +40,8 @@ export interface PowerSearchValueEditorProps {onChange: (value: FilterValue, shouldSave?: boolean) => void;onEnter?: () => void;config: InternalConfig;+ /** Max suggestions in string and entity value typeaheads. */+ maxMenuItems?: number;isDisabled?: boolean;timezoneID?: string;}@@ -80,11 +82,13 @@ function StringEditor({filterValue,onChange,onEnter: _onEnter,+ maxMenuItems,}: {operatorValue: OperatorValue & {type: 'string'};filterValue: FilterValue | undefined;onChange: (value: FilterValue, shouldSave?: boolean) => void;onEnter?: () => void;+ maxMenuItems?: number;}) {const t = useTranslator();const currentValue = filterValue?.type === 'string' ? filterValue.value : '';@@ -111,6 +115,7 @@ function StringEditor({}}placeholder={t('@astryx.powersearch.valueEditor.searchPlaceholder')}debounceMs={150}+ maxMenuItems={maxMenuItems}/>);}@@ -132,10 +137,12 @@ function StringListEditor({operatorValue,filterValue,onChange,+ maxMenuItems,}: {operatorValue: OperatorValue & {type: 'string_list'};filterValue: FilterValue | undefined;onChange: (value: FilterValue) => void;+ maxMenuItems?: number;}) {const t = useTranslator();const currentValue: SearchableItem[] = useMemo(() => {@@ -176,6 +183,7 @@ function StringListEditor({placeholder={t('@astryx.powersearch.valueEditor.addValuesPlaceholder')}debounceMs={operatorValue.searchSource ? 150 : 0}hasCreate={hasCreate}+ maxMenuItems={maxMenuItems}/>);}@@ -537,10 +545,12 @@ function EntityListEditor({operatorValue,filterValue,onChange,+ maxMenuItems,}: {operatorValue: OperatorValue & {type: 'entity_list'};filterValue: FilterValue | undefined;onChange: (value: FilterValue) => void;+ maxMenuItems?: number;}) {const t = useTranslator();const source = useMemo<SearchSource<SearchableItem>>(() => {@@ -588,6 +598,7 @@ function EntityListEditor({renderItem={operatorValue.renderItem}placeholder={t('@astryx.powersearch.valueEditor.searchPlaceholder')}debounceMs={operatorValue.searchSource ? 150 : 0}+ maxMenuItems={maxMenuItems}/>);}@@ -631,6 +642,7 @@ export function PowerSearchValueEditor({filterValue,onChange,onEnter,+ maxMenuItems,isDisabled,}: PowerSearchValueEditorProps) {switch (operatorValue.type) {@@ -644,6 +656,7 @@ export function PowerSearchValueEditor({filterValue={filterValue}onChange={onChange}onEnter={onEnter}+ maxMenuItems={maxMenuItems}/>);@@ -653,6 +666,7 @@ export function PowerSearchValueEditor({operatorValue={operatorValue}filterValue={filterValue}onChange={onChange}+ maxMenuItems={maxMenuItems}/>);@@ -734,6 +748,7 @@ export function PowerSearchValueEditor({operatorValue={operatorValue}filterValue={filterValue}onChange={onChange}+ maxMenuItems={maxMenuItems}/>);