From 54276081cc4c72178db048c346115ca0f96fd587 Mon Sep 17 00:00:00 2001 From: Syogo-Suganoya <55225064+Syogo-Suganoya@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:41:45 +0900 Subject: [PATCH] [Feature] Select which fields to search in tables (#13346) * Allow table search to be limited to selected fields - Add 'search_fields' query parameter to InvenTreeSearchFilter - Expose searchable fields (name / label) in the OPTIONS metadata - Add search field selection menu to the table header Co-Authored-By: Claude Fable 5.2 * Add Playwright test for table search fields Co-Authored-By: Claude Opus 5.5 * Add tests for search field restrictions and labels - Check that search_fields cannot be used to search fields which are not exposed for searching by the view - Check that search field labels are translated based on the request language, including a distant related field - Check the displayed labels in the Playwright test, including a distant related field in the BOM table Co-Authored-By: Claude Opus 5.5 * Hide the search field menu for tables with a single search field - Read the searchable fields from the existing table OPTIONS request, and cache them alongside the column names - Only display the search field menu when there is more than one field to choose from Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Fable 5.2 --- .../InvenTree/InvenTree/api_version.py | 6 +- src/backend/InvenTree/InvenTree/filters.py | 27 +++ src/backend/InvenTree/InvenTree/metadata.py | 66 +++++++ src/backend/InvenTree/InvenTree/test_api.py | 175 ++++++++++++++++++ src/frontend/CHANGELOG.md | 1 + src/frontend/lib/states/StoredTableState.tsx | 23 ++- src/frontend/lib/types/Tables.tsx | 9 + .../src/components/tables/InvenTreeTable.tsx | 51 ++++- .../tables/InvenTreeTableHeader.tsx | 32 +++- .../tables/TableSearchFieldSelect.tsx | 95 ++++++++++ src/frontend/tests/pui_tables.spec.ts | 61 ++++++ 11 files changed, 538 insertions(+), 8 deletions(-) create mode 100644 src/frontend/src/components/tables/TableSearchFieldSelect.tsx diff --git a/src/backend/InvenTree/InvenTree/api_version.py b/src/backend/InvenTree/InvenTree/api_version.py index fbffb2d1a8..b63ff031ce 100644 --- a/src/backend/InvenTree/InvenTree/api_version.py +++ b/src/backend/InvenTree/InvenTree/api_version.py @@ -1,11 +1,15 @@ """InvenTree API version information.""" # InvenTree API version -INVENTREE_API_VERSION = 583 +INVENTREE_API_VERSION = 584 """Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" INVENTREE_API_TEXT = """ +v584 -> 2026-11-23 : https://github.com/inventree/InvenTree/pull/13346 + - Adds "search_fields" query parameter to list endpoints, to limit a search to a subset of the searchable fields + - Adds "search_fields" information to the OPTIONS response for list endpoints + v583 -> 2026-11-20 : https://github.com/inventree/InvenTree/issues/12121 - Adds parameter support to the StockLocationType model and API endpoints diff --git a/src/backend/InvenTree/InvenTree/filters.py b/src/backend/InvenTree/InvenTree/filters.py index 51e9063b95..cde016d89f 100644 --- a/src/backend/InvenTree/InvenTree/filters.py +++ b/src/backend/InvenTree/InvenTree/filters.py @@ -35,6 +35,7 @@ class InvenTreeSearchFilter(filters.SearchFilter): The following query params are available to 'augment' the search (in decreasing order of priority) - search_notes: If True, 'notes' is added to the search_fields if it isn't already present + - search_fields: Comma-separated list of field names, limits the search to a subset of the available search_fields - search_regex: If True, search is performed on 'regex' comparison """ from generic.models.modelmixins import InvenTreeNoteMixin @@ -71,6 +72,8 @@ class InvenTreeSearchFilter(filters.SearchFilter): # is returned once per matching note instead of once overall. self._search_notes_fans_out = notes_field == 'notes_list__content' + search_fields = self.limit_search_fields(search_fields, request) + regex = InvenTree.helpers.str2bool( request.query_params.get('search_regex', False) ) @@ -86,6 +89,30 @@ class InvenTreeSearchFilter(filters.SearchFilter): return fields + @staticmethod + def field_name(field: str) -> str: + """Return the 'plain' name of a search field, without any DRF lookup prefix.""" + return field.lstrip(''.join(filters.SearchFilter.lookup_prefixes.keys())) + + def limit_search_fields(self, search_fields, request): + """Limit the search fields to the subset requested by the 'search_fields' query param. + + - Only fields which the view has marked as searchable can be selected + - If no (valid) fields are requested, all search fields are used (default behavior) + """ + requested = request.query_params.get('search_fields', '') + + requested = {name.strip() for name in str(requested).split(',') if name.strip()} + + if not requested or not search_fields: + return search_fields + + limited = [ + field for field in search_fields if self.field_name(field) in requested + ] + + return limited or search_fields + def filter_queryset(self, request, queryset, view): """Apply the search filter, then deduplicate if notes search fanned out the join.""" queryset = super().filter_queryset(request, queryset, view) diff --git a/src/backend/InvenTree/InvenTree/metadata.py b/src/backend/InvenTree/InvenTree/metadata.py index ee65f11392..5f51f0a9a4 100644 --- a/src/backend/InvenTree/InvenTree/metadata.py +++ b/src/backend/InvenTree/InvenTree/metadata.py @@ -161,6 +161,9 @@ class InvenTreeMetadata(SimpleMetadata): if filters := self.get_filter_metadata(request, view): metadata['filters'] = filters + if search_fields := self.get_search_field_metadata(view): + metadata['search_fields'] = search_fields + return metadata @staticmethod @@ -181,6 +184,69 @@ class InvenTreeMetadata(SimpleMetadata): getattr(perm, 'allows_any_authenticated_user', False) ) + def get_search_field_metadata(self, view) -> list[dict]: + """Return information on the fields which can be searched for an API endpoint. + + A client can use this to let the user choose which fields a search applies to, + by passing a subset of the field names in the 'search_fields' query parameter. + + Returns: + list: A list of {'name', 'label'} entries, one for each searchable field + """ + from InvenTree.filters import InvenTreeSearchFilter + + backends = getattr(view, 'filter_backends', None) or [] + + if not any( + isinstance(backend, type) and issubclass(backend, InvenTreeSearchFilter) + for backend in backends + ): + return [] + + try: + model = view.get_serializer_class().Meta.model + except Exception: + model = None + + fields = [] + + for field in getattr(view, 'search_fields', None) or []: + name = InvenTreeSearchFilter.field_name(field) + + fields.append({ + 'name': name, + 'label': self.get_search_field_label(model, name), + }) + + return fields + + def get_search_field_label(self, model, name: str) -> str: + """Construct a human readable label for a (possibly related) search field. + + e.g. 'part__name' -> 'Part / Name' (using the translated field names) + """ + labels = [] + + for part in name.split('__'): + label = None + + if model is not None: + try: + field = model._meta.get_field(part) + label = getattr(field, 'verbose_name', None) + model = getattr(field, 'related_model', None) + except Exception: + # Not a model field (e.g. an annotation) - fall back to the raw name + model = None + + if not label: + label = part.replace('_', ' ') + + label = str(label) + labels.append(label[:1].upper() + label[1:]) + + return ' / '.join(labels) + def get_filter_metadata(self, request, view) -> dict: """Return information on the choice filters available for an API endpoint. diff --git a/src/backend/InvenTree/InvenTree/test_api.py b/src/backend/InvenTree/InvenTree/test_api.py index 564280bdc9..857723ce31 100644 --- a/src/backend/InvenTree/InvenTree/test_api.py +++ b/src/backend/InvenTree/InvenTree/test_api.py @@ -682,6 +682,181 @@ class SearchTests(InvenTreeAPITestCase): # No results again self.assertEqual(response.data['build']['count'], 0) + def test_search_fields(self): + """Test that a search can be limited to a subset of fields via 'search_fields'.""" + from part.models import Part, PartCategory + + TERM = 'zzqxsearchfieldszz' + + category = PartCategory.objects.first() + + by_name = Part.objects.create( + name=f'{TERM} name', description='Nothing to see', category=category + ) + by_desc = Part.objects.create( + name='Unremarkable part', description=f'{TERM} desc', category=category + ) + + url = reverse('api-part-list') + + def search(**kwargs): + response = self.get(url, {'search': TERM, **kwargs}, expected_code=200) + return {part['pk'] for part in response.data} + + # Default behavior: all searchable fields are used + self.assertEqual(search(), {by_name.pk, by_desc.pk}) + + # Limit to a single field + self.assertEqual(search(search_fields='name'), {by_name.pk}) + self.assertEqual(search(search_fields='description'), {by_desc.pk}) + + # Multiple fields (with whitespace) + self.assertEqual( + search(search_fields='name, description'), {by_name.pk, by_desc.pk} + ) + + # Unknown fields are ignored + self.assertEqual(search(search_fields='name,not_a_field'), {by_name.pk}) + + # A field which is not searchable cannot be selected: + # falls back to the default search fields + self.assertEqual( + search(search_fields='creation_user__password'), {by_name.pk, by_desc.pk} + ) + + # Combines with the other search options + self.assertEqual( + search(search_fields='description', search_regex=True), {by_desc.pk} + ) + + def test_search_fields_restricted(self): + """Test that 'search_fields' cannot be used to search fields which are not exposed for searching. + + The parameter can only narrow the set of searchable fields, never expand it. + """ + from part.api import PartList + from part.models import Part, PartCategory + + TERM = 'zzqxrestrictedzz' + + searchable = {name.lstrip('^=@$') for name in PartList.search_fields} + + # Fields which hold the search term below, none of which are searchable + hidden_fields = [ + 'link', + 'units', + 'category__description', + 'creation_user__username', + 'creation_user__email', + ] + + for field in hidden_fields: + self.assertNotIn(field, searchable) + + user = get_user_model().objects.create_user( + username=f'{TERM}user', email=f'{TERM}@example.com', password='abc123' + ) + + category = PartCategory.objects.create( + name='Hidden category', description=f'{TERM} category' + ) + + hidden = Part.objects.create( + name='Hidden part', + description='Nothing to see', + link=f'https://example.com/{TERM}', + units='m', + category=category, + creation_user=user, + ) + + url = reverse('api-part-list') + + def search(term=TERM, **kwargs): + response = self.get(url, {'search': term, **kwargs}, expected_code=200) + return {part['pk'] for part in response.data} + + # The term is not found via the default search fields + self.assertNotIn(hidden.pk, search()) + + # Explicitly requesting a non-searchable field does not search it + for field in hidden_fields: + self.assertNotIn(hidden.pk, search(search_fields=field)) + + # Combined with a valid field: the non-searchable field is ignored + self.assertNotIn(hidden.pk, search(search_fields='name,link')) + + # Lookup prefixes cannot be used to alter the type of lookup performed + for field in ['^name', '=name', '$name', '@name']: + self.assertNotIn(hidden.pk, search(search_fields=f'{field},link')) + + def test_search_fields_metadata(self): + """Test that the searchable fields are exposed via the OPTIONS endpoint.""" + from part.api import PartList + + response = self.options(reverse('api-part-list'), expected_code=200) + + fields = response.data['search_fields'] + names = [field['name'] for field in fields] + + # Lookup prefixes are not exposed + self.assertEqual( + names, [name.lstrip('^=@$') for name in PartList.search_fields] + ) + + labels = {field['name']: field['label'] for field in fields} + + self.assertEqual(labels['name'], 'Name') + self.assertEqual(labels['description'], 'Description') + self.assertEqual(labels['category__name'], 'Category / Name') + + # Labels are translated based on the language of the request + response = self.options( + reverse('api-part-list'), + headers={'Accept-Language': 'de'}, + expected_code=200, + ) + + labels = { + field['name']: field['label'] for field in response.data['search_fields'] + } + + self.assertEqual(labels['description'], 'Beschreibung') + self.assertEqual(labels['category__name'], 'Kategorie / Name') + + # A distant related field, spanning multiple models + labels = { + field['name']: field['label'] + for field in self.options(reverse('api-bom-list'), expected_code=200).data[ + 'search_fields' + ] + } + + self.assertEqual( + labels['sub_part__category__name'], 'Sub part / Category / Name' + ) + + response = self.options( + reverse('api-bom-list'), + headers={'Accept-Language': 'de'}, + expected_code=200, + ) + + labels = { + field['name']: field['label'] for field in response.data['search_fields'] + } + + self.assertEqual( + labels['sub_part__category__name'], + 'Untergeordnetes Teil / Kategorie / Name', + ) + + # A detail endpoint does not provide search information + response = self.options( + reverse('api-part-detail', kwargs={'pk': 1}), expected_code=200 + ) + self.assertNotIn('search_fields', response.data) + def test_search_notes_distinct(self): """Test that search_notes does not return duplicate results for multi-note instances. diff --git a/src/frontend/CHANGELOG.md b/src/frontend/CHANGELOG.md index 77a812074f..998e8b77ae 100644 --- a/src/frontend/CHANGELOG.md +++ b/src/frontend/CHANGELOG.md @@ -8,6 +8,7 @@ This file contains historical changelog information for the InvenTree UI compone - Adds `renderLink` helper function, which renders a validated external URL (`http` / `https` only) as an `` element with a link icon - Adds `sanitizeLinkUrl` helper function, which validates a URL for use as an external link +- Adds `TableSearchField` type, and caches the searchable fields for each table in `useStoredTableState` ([#13346](https://github.com/inventree/InvenTree/pull/13346)) ### 1.7.0 - November 2026 diff --git a/src/frontend/lib/states/StoredTableState.tsx b/src/frontend/lib/states/StoredTableState.tsx index f0e6c40e09..6863ae22f2 100644 --- a/src/frontend/lib/states/StoredTableState.tsx +++ b/src/frontend/lib/states/StoredTableState.tsx @@ -1,6 +1,7 @@ import type { DataTableSortStatus } from 'mantine-datatable'; import { create } from 'zustand'; import { persist } from 'zustand/middleware'; +import type { TableSearchField } from '../types/Tables'; const DEFAULT_PAGE_SIZE: number = 25; @@ -11,6 +12,7 @@ const DEFAULT_PAGE_SIZE: number = 25; * - pageSize: The number of rows to display per page in the table. * - hiddenColumns: An array of column names that are hidden in a given table. * - columnNames: An object mapping table keys to arrays of column names. + * - searchFields: An object mapping table keys to the fields which can be searched. * - sorting: An object mapping table keys to sorting configurations. */ export interface StoredTableStateProps { @@ -27,6 +29,11 @@ export interface StoredTableStateProps { tableKey: string ) => (names: Record) => void; clearTableColumnNames: () => void; + tableSearchFields: Record; + getTableSearchFields: (tableKey: string) => TableSearchField[] | null; + setTableSearchFields: ( + tableKey: string + ) => (fields: TableSearchField[]) => void; hiddenColumns: Record; getHiddenColumns: (tableKey: string) => string[] | null; setHiddenColumns: (tableKey: string) => (columns: string[]) => void; @@ -68,7 +75,21 @@ export const useStoredTableState = create()( }); }, clearTableColumnNames: () => { - set({ tableColumnNames: {} }); + // Search field labels are translated too, so are cleared alongside + set({ tableColumnNames: {}, tableSearchFields: {} }); + }, + tableSearchFields: {}, + getTableSearchFields: (tableKey) => { + return get().tableSearchFields?.[tableKey] ?? null; + }, + setTableSearchFields: (tableKey) => (fields) => { + // Update the searchable fields for the given table + set({ + tableSearchFields: { + ...get().tableSearchFields, + [tableKey]: fields + } + }); }, hiddenColumns: {}, getHiddenColumns: (tableKey) => { diff --git a/src/frontend/lib/types/Tables.tsx b/src/frontend/lib/types/Tables.tsx index 31430b9f78..12691aef81 100644 --- a/src/frontend/lib/types/Tables.tsx +++ b/src/frontend/lib/types/Tables.tsx @@ -70,6 +70,15 @@ export type TableState = { idAccessor?: string; }; +/* + * A field which can be selected to limit a table search + * (as provided by the server via an OPTIONS request) + */ +export type TableSearchField = { + name: string; + label: string; +}; + export type TableColumnFilterType = | string | string[] diff --git a/src/frontend/src/components/tables/InvenTreeTable.tsx b/src/frontend/src/components/tables/InvenTreeTable.tsx index 840434b7eb..dcb0e9eb8d 100644 --- a/src/frontend/src/components/tables/InvenTreeTable.tsx +++ b/src/frontend/src/components/tables/InvenTreeTable.tsx @@ -13,6 +13,7 @@ import type { ApiFormFieldSet } from '@lib/types/Forms'; import type { InvenTreeTableProps, InvenTreeTableRenderProps, + TableSearchField, TableState } from '@lib/types/Tables'; import type { TableColumn } from '@lib/types/Tables'; @@ -128,12 +129,27 @@ export function InvenTreeTableInternal>({ setHiddenColumns, getTableColumnNames, setTableColumnNames, + getTableSearchFields, + setTableSearchFields, getTableSorting, setTableSorting } = useStoredTableState(); const [fieldNames, setFieldNames] = useState>({}); + // Fields which can be searched (as provided by the server) + const [searchFieldOptions, setSearchFieldOptions] = useState< + TableSearchField[] + >([]); + + // Subset of fields to search in (an empty list means "search all fields") + const [searchFields, setSearchFields] = useState([]); + + // The search fields only affect the query while a search term is active + const activeSearchFields: string = useMemo(() => { + return tableState.searchTerm ? searchFields.join(',') : ''; + }, [tableState.searchTerm, searchFields]); + const userSettings = useUserSettingsState(); const showPreviewPanel = useMemo(() => { @@ -228,8 +244,12 @@ export function InvenTreeTableInternal>({ return null; } - // If we already have field names, no need to fetch them again - if (fieldNames && Object.keys(fieldNames).length > 0) { + // If we already have field names (and search fields), no need to fetch them again + if ( + fieldNames && + Object.keys(fieldNames).length > 0 && + getTableSearchFields(cacheKey) != null + ) { return null; } @@ -255,6 +275,13 @@ export function InvenTreeTableInternal>({ setFieldNames(names); setTableColumnNames(cacheKey)(names); + + // Extract the fields which can be searched + const searchFields: TableSearchField[] = + response.data?.search_fields ?? []; + + setSearchFieldOptions(searchFields); + setTableSearchFields(cacheKey)(searchFields); } return null; @@ -271,6 +298,12 @@ export function InvenTreeTableInternal>({ // First check the local cache const cachedNames = getTableColumnNames(cacheKey); + const cachedSearchFields = getTableSearchFields(cacheKey); + + if (cachedSearchFields != null) { + setSearchFieldOptions(cachedSearchFields); + } + if (cachedNames != null) { // Cached names are available - use them! setFieldNames(cachedNames); @@ -567,6 +600,7 @@ export function InvenTreeTableInternal>({ tableState.clearSelectedRecords(); }, [ tableState.searchTerm, + activeSearchFields, tableState.filterSet.activeFilters, tableSearchParams ]); @@ -618,6 +652,11 @@ export function InvenTreeTableInternal>({ // Add custom search term if (tableState.searchTerm) { queryParams.search = tableState.searchTerm; + + // Limit the search to the selected fields (if any) + if (activeSearchFields) { + queryParams.search_fields = activeSearchFields; + } } // Pagination @@ -646,6 +685,7 @@ export function InvenTreeTableInternal>({ tableState.filterSet.activeFilters, tableSearchParams, tableState.searchTerm, + activeSearchFields, getOrderingTerm ] ); @@ -810,7 +850,8 @@ export function InvenTreeTableInternal>({ sortStatus.direction, tableState.tableKey, tableState.filterSet.activeFilters, - tableState.searchTerm + tableState.searchTerm, + activeSearchFields ], retry: 5, retryDelay: (attempt: number) => (1 + attempt) * 250, @@ -884,6 +925,7 @@ export function InvenTreeTableInternal>({ sortStatus, tableState.page, tableState.searchTerm, + activeSearchFields, tableState.tableKey, tableState.filterSet.activeFilters, tableSearchParams @@ -1294,6 +1336,9 @@ export function InvenTreeTableInternal>({ void; toggleColumn: (column: string) => void; + searchFieldOptions: TableSearchField[]; + searchFields: string[]; + setSearchFields: (fields: string[]) => void; }>) { // Filter list visibility const [filtersVisible, setFiltersVisible] = useState(false); @@ -93,8 +100,19 @@ export default function InvenTreeTableHeader({ } } + // Limit the search to the selected fields (if any) + if (tableState.searchTerm && searchFields.length > 0) { + filters.search_fields = searchFields.join(','); + } + return filters; - }, [tableProps.params, tableState.filterSet, queryFilters]); + }, [ + tableProps.params, + tableState.filterSet, + tableState.searchTerm, + queryFilters, + searchFields + ]); const exportModal = useDataExport({ url: tableUrl ?? '', @@ -271,6 +289,14 @@ export default function InvenTreeTableHeader({ searchCallback={(term: string) => tableState.setSearchTerm(term)} /> )} + {tableProps.enableSearch && ( + + )} {tableProps.enableRefresh && ( diff --git a/src/frontend/src/components/tables/TableSearchFieldSelect.tsx b/src/frontend/src/components/tables/TableSearchFieldSelect.tsx new file mode 100644 index 0000000000..0b5846e163 --- /dev/null +++ b/src/frontend/src/components/tables/TableSearchFieldSelect.tsx @@ -0,0 +1,95 @@ +import type { TableSearchField } from '@lib/types/Tables'; +import { t } from '@lingui/core/macro'; +import { + ActionIcon, + Checkbox, + Divider, + Indicator, + Menu, + Tooltip +} from '@mantine/core'; +import { IconListSearch } from '@tabler/icons-react'; +import { useCallback } from 'react'; + +/** + * Menu which allows the user to limit a table search to a subset of the searchable fields. + * + * The available fields are provided by the server (via the OPTIONS request for the table), + * and the menu is only displayed if there is more than one field to choose from. + * + * An empty selection means "search all fields" (default behavior). + */ +export function TableSearchFieldSelect({ + fields, + disabled, + selectedFields, + onChange +}: Readonly<{ + fields: TableSearchField[]; + disabled?: boolean; + selectedFields: string[]; + onChange: (fields: string[]) => void; +}>) { + const toggleField = useCallback( + (name: string) => { + if (selectedFields.includes(name)) { + onChange(selectedFields.filter((field) => field != name)); + } else { + onChange([...selectedFields, name]); + } + }, + [selectedFields, onChange] + ); + + // Selecting from a single field is the same as searching all fields + if (fields.length <= 1) { + return null; + } + + return ( + + + + + + + + + + + {t`Search in fields`} + + + onChange([])} + radius='sm' + /> + + + {fields.map((field) => ( + + toggleField(field.name)} + radius='sm' + /> + + ))} + + + + ); +} diff --git a/src/frontend/tests/pui_tables.spec.ts b/src/frontend/tests/pui_tables.spec.ts index faaaef71e7..e0cc7dd0f1 100644 --- a/src/frontend/tests/pui_tables.spec.ts +++ b/src/frontend/tests/pui_tables.spec.ts @@ -338,3 +338,64 @@ test('Tables - Sorting', async ({ browser }) => { await toggleColumnSorting(page, 'Order Status'); await toggleColumnSorting(page, 'Line Items'); }); + +test('Tables - Search Fields', async ({ browser }) => { + const page = await doCachedLogin(browser, { + url: 'part/category/index/parts' + }); + + await clearTableFilters(page); + + // Search across all fields (default): matches on the description too + await page.getByLabel('table-search-input').fill('paint'); + await page.getByRole('cell', { name: 'Blue Square Table' }).waitFor(); + + // Limit the search to the part name + await page.getByLabel('table-select-search-fields').click(); + + // Fields are displayed with human readable labels + for (const [name, label] of [ + ['name', 'Name'], + ['description', 'Description'], + ['category__name', 'Category / Name'] + ]) { + await expect( + page.getByRole('menuitem').filter({ + has: page.getByLabel(`search-field-${name}`, { exact: true }) + }) + ).toHaveText(label); + } + + await page.getByLabel('search-field-name', { exact: true }).click(); + await page.keyboard.press('Escape'); + + await page.getByRole('cell', { name: 'Blue Paint' }).first().waitFor(); + await expect( + page.getByRole('cell', { name: 'Blue Square Table' }) + ).toHaveCount(0); + + // Search all fields again + await page.getByLabel('table-select-search-fields').click(); + await page.getByLabel('search-field-all').click(); + await page.keyboard.press('Escape'); + + await page.getByRole('cell', { name: 'Blue Square Table' }).waitFor(); + + // A distant related field (spanning multiple models) in the BOM table + await navigate(page, 'part/87/bom'); + await page.getByLabel('table-select-search-fields').click(); + + await expect( + page.getByRole('menuitem').filter({ + has: page.getByLabel('search-field-sub_part__category__name', { + exact: true + }) + }) + ).toHaveText('Sub part / Category / Name'); + + // The menu is hidden for a table with only a single searchable field + await navigate(page, 'core/index/groups'); + await page.getByRole('cell', { name: 'all access' }).waitFor(); + await page.getByLabel('table-search-input').waitFor(); + await expect(page.getByLabel('table-select-search-fields')).toHaveCount(0); +});