diff --git a/packages/eui/changelogs/upcoming/9253.md b/packages/eui/changelogs/upcoming/9253.md new file mode 100644 index 000000000000..28ab4384a3c9 --- /dev/null +++ b/packages/eui/changelogs/upcoming/9253.md @@ -0,0 +1,2 @@ +- Updated `EuiSearchBarOnChangeArgs` to restore proper type narrowing when checking for `error` (regression from #9142), decoupling `searchFormat="text"` behavior in `EuiInMemoryTable` from `EuiSearchBar` +- Export new `EuiInMemoryTableSearchBarProps` type diff --git a/packages/eui/src/components/basic_table/in_memory_table.tsx b/packages/eui/src/components/basic_table/in_memory_table.tsx index 584a6162f471..95414ce07e37 100644 --- a/packages/eui/src/components/basic_table/in_memory_table.tsx +++ b/packages/eui/src/components/basic_table/in_memory_table.tsx @@ -41,19 +41,25 @@ import { EuiComponentDefaults, } from '../provider/component_defaults'; -interface onChangeArgument { +export interface EuiInMemoryTableSearchBarOnChangeArgs { query: Query | null; queryText: string; error: Error | null; } +// allows `query: null` in the onChange callback when using `searchFormat="text"` +export interface EuiInMemoryTableSearchBarProps + extends Omit { + onChange?: (args: EuiInMemoryTableSearchBarOnChangeArgs) => void | boolean; +} + function isEuiSearchBarProps( x: EuiInMemoryTableProps['search'] -): x is EuiSearchBarProps { +): x is EuiInMemoryTableSearchBarProps { return typeof x !== 'boolean'; } -export type Search = boolean | EuiSearchBarProps; +export type Search = boolean | EuiInMemoryTableSearchBarProps; interface PaginationOptions extends EuiTablePaginationProps { pageSizeOptions?: number[]; @@ -520,7 +526,11 @@ export class EuiInMemoryTable extends Component< }); }; - onQueryChange = ({ query, queryText, error }: onChangeArgument) => { + onQueryChange = ({ + query, + queryText, + error, + }: EuiInMemoryTableSearchBarOnChangeArgs) => { const { search } = this.props; if (isEuiSearchBarProps(search)) { if (search.onChange) { diff --git a/packages/eui/src/components/basic_table/index.ts b/packages/eui/src/components/basic_table/index.ts index 4bf94ae0f56a..7c10db455ad9 100644 --- a/packages/eui/src/components/basic_table/index.ts +++ b/packages/eui/src/components/basic_table/index.ts @@ -13,7 +13,12 @@ export type { CriteriaWithPagination, } from './basic_table'; export { EuiBasicTable } from './basic_table'; -export type { EuiInMemoryTableProps, Search } from './in_memory_table'; +export type { + EuiInMemoryTableProps, + EuiInMemoryTableSearchBarOnChangeArgs, + EuiInMemoryTableSearchBarProps, + Search, +} from './in_memory_table'; export { EuiInMemoryTable } from './in_memory_table'; export type { EuiTableDataType, diff --git a/packages/eui/src/components/search_bar/search_bar.tsx b/packages/eui/src/components/search_bar/search_bar.tsx index c57ce764fd2c..da798a106ddb 100644 --- a/packages/eui/src/components/search_bar/search_bar.tsx +++ b/packages/eui/src/components/search_bar/search_bar.tsx @@ -34,16 +34,6 @@ interface ArgsWithQuery { error: null; } -/** - * When `searchFormat` is 'text', `query` is null and the search is performed - * on the `queryText` directly without EQL parsing - */ -interface ArgsWithPlainText { - query: null; - queryText: string; - error: null; -} - interface ArgsWithError { query: null; queryText: string; @@ -58,10 +48,7 @@ export interface SchemaType { recognizedFields?: string[]; } -export type EuiSearchBarOnChangeArgs = - | ArgsWithQuery - | ArgsWithPlainText - | ArgsWithError; +export type EuiSearchBarOnChangeArgs = ArgsWithQuery | ArgsWithError; type HintPopOverProps = Partial< Pick<