Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiInMemoryTable] Allow search prop changes to update internal query state #3371

Merged
merged 11 commits into from
Apr 29, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

**Bug Fixes**

- Fixed EuiInMemoryTable does not update its internal query state after changes to `search` prop ([#3371](https://github.com/elastic/eui/pull/3371))
- Fixed `EuiInMemoryTable` `isClearable` property to initiate reset ([#3328](https://github.com/elastic/eui/pull/3328))
- Fixed `EuiCollapsibleNav` docked states on mobile ([#3330](https://github.com/elastic/eui/pull/3330))
- Fixed `EuiPopover` positioning from being overridden by `style` prop ([#3329](https://github.com/elastic/eui/pull/3329))
Expand Down
30 changes: 29 additions & 1 deletion src/components/basic_table/in_memory_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ interface State<T> {
items: T[];
sortName: ReactNode;
sortDirection?: Direction;
search?: Search | undefined;
ashikmeerankutty marked this conversation as resolved.
Show resolved Hide resolved
};
search?: Search | undefined;
ashikmeerankutty marked this conversation as resolved.
Show resolved Hide resolved
query: Query | null;
pageIndex: number;
pageSize?: number;
Expand All @@ -124,7 +126,21 @@ const getInitialQuery = (search: Search | undefined) => {
if (!search) {
query = '';
} else {
query = (search as EuiSearchBarProps).defaultQuery || '';
query =
(search as EuiSearchBarProps).defaultQuery ||
(search as EuiSearchBarProps).query ||
'';
}

return isString(query) ? EuiSearchBar.Query.parse(query) : query;
};

const getQueryFromSearch = (search: Search | undefined) => {
ashikmeerankutty marked this conversation as resolved.
Show resolved Hide resolved
let query: Query | string;
if (!search) {
query = '';
} else {
query = (search as EuiSearchBarProps).query || '';
}

return isString(query) ? EuiSearchBar.Query.parse(query) : query;
Expand Down Expand Up @@ -258,6 +274,16 @@ export class EuiInMemoryTable<T> extends Component<
sortDirection,
};
}

if (nextProps.search !== prevState.prevProps.search) {
ashikmeerankutty marked this conversation as resolved.
Show resolved Hide resolved
return {
prevProps: {
...prevState.prevProps,
search: nextProps.search,
},
query: getQueryFromSearch(nextProps.search),
};
}
return null;
}

Expand All @@ -278,7 +304,9 @@ export class EuiInMemoryTable<T> extends Component<
items: props.items,
sortName,
sortDirection,
search,
},
search: search,
query: getInitialQuery(search),
pageIndex: pageIndex || 0,
pageSize,
Expand Down