Skip to content
Closed
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
2 changes: 2 additions & 0 deletions packages/eui/changelogs/upcoming/9253.md
Original file line number Diff line number Diff line change
@@ -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`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imho, we should an entry for the updated search prop type that uses EuiInMemoryTableSearchBarProps now.
And considering that this will require updates to implementations due to an API change (though small), I'd even mark it as breaking.

- Export new `EuiInMemoryTableSearchBarProps` type
18 changes: 14 additions & 4 deletions packages/eui/src/components/basic_table/in_memory_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<EuiSearchBarProps, 'onChange'> {
onChange?: (args: EuiInMemoryTableSearchBarOnChangeArgs) => void | boolean;
}

function isEuiSearchBarProps<T extends object>(
x: EuiInMemoryTableProps<T>['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[];
Expand Down Expand Up @@ -520,7 +526,11 @@ export class EuiInMemoryTable<T extends object = object> extends Component<
});
};

onQueryChange = ({ query, queryText, error }: onChangeArgument) => {
onQueryChange = ({
query,
queryText,
error,
}: EuiInMemoryTableSearchBarOnChangeArgs) => {
const { search } = this.props;
if (isEuiSearchBarProps(search)) {
if (search.onChange) {
Expand Down
7 changes: 6 additions & 1 deletion packages/eui/src/components/basic_table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 1 addition & 14 deletions packages/eui/src/components/search_bar/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -58,10 +48,7 @@ export interface SchemaType {
recognizedFields?: string[];
}

export type EuiSearchBarOnChangeArgs =
| ArgsWithQuery
| ArgsWithPlainText
| ArgsWithError;
export type EuiSearchBarOnChangeArgs = ArgsWithQuery | ArgsWithError;

type HintPopOverProps = Partial<
Pick<
Expand Down