[Infrastructure UI] Add unified search to hosts table#143850
[Infrastructure UI] Add unified search to hosts table#143850crespocarlos merged 6 commits intoelastic:mainfrom
Conversation
93b6689 to
31d9d16
Compare
| onClearSavedQuery={onClearSavedQuery} | ||
| showSaveQuery | ||
| showQueryInput | ||
| // @ts-expect-error onFiltersUpdated is a valid prop on SearchBar |
|
Pinging @elastic/infra-monitoring-ui (Team:Infra Monitoring UI) |
jennypavlova
left a comment
There was a problem hiding this comment.
Well done! Everything works fine. I left some minor comments.
Also, I have one question regarding the no data case - I compare it with inventory and metrics explorer and on the hosts page, there is a bigger gap between the search bar and the no data message:

Do you remember if it was like that before? If it was like that we can just fix that in a separate issue.
|
|
||
| const saveQuery = useCallback( | ||
| (newSavedQuery: SavedQuery) => { | ||
| const savedQueryFilters = newSavedQuery.attributes.filters || []; |
There was a problem hiding this comment.
nit: Here we can use ??
| const savedQueryFilters = newSavedQuery.attributes.filters || []; | |
| const savedQueryFilters = newSavedQuery.attributes.filters ?? []; |
There was a problem hiding this comment.
Good catch! Absolutely! ?? is the right way.
| const { metricsDataView, isDataViewLoading, hasFailedLoadingDataView } = | ||
| useMetricsDataViewContext(); | ||
|
|
||
| return isDataViewLoading ? ( |
There was a problem hiding this comment.
nit: I think here we can do an early return if isDataViewLoading is true so it's easier to follow the conditions, something like this:
if (isDataViewLoading) {
return (
<InfraLoadingPanel
height="100%"
width="auto"
text={i18n.translate('xpack.infra.waffle.loadingDataText', {
defaultMessage: 'Loading data',
})}
/>
);
}
return hasFailedLoadingDataView || !metricsDataView ? null : (
<>
<UnifiedSearchBar dataView={metricsDataView} />
<EuiSpacer />
<HostsTable />
</>
);
What do you think?
There was a problem hiding this comment.
Sure! It's easier to read
| const DEFAULT_FROM_MINUTES_VALUE = 15; | ||
|
|
||
| export const useUnifiedSearch = () => { | ||
| const [, forceUpdate] = useReducer((x: number) => x + 1, 0); |
There was a problem hiding this comment.
Here I think we can simplify it to const [, forceUpdate] = useState({}); and use forceUpdate({}) ( I saw a similar pattern in other places in the code but probably I am missing something here 🤔) What do you think?
There was a problem hiding this comment.
This is what react recommends https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate. But this is temporary. I think the URL state ticket will force the component to update instead of this.
There was a problem hiding this comment.
Thanks for the explanation! We can keep it, you are right that when we update the url state and set the query/filters/time range it should be fine without it but we will probably still need to force the update when saving the query for example.
There was a problem hiding this comment.
Perhaps we don't even need that forceUpdate in the saveQuery function. It's not supposed to trigger a new search. Let me double check that.
Not really, we currently need to call the forceUpdate. Let's see what we can do if we still need this hack after we implement the URL state management. We might want to look at alternatives for this hack.
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
History
To update your PR or re-run it, just comment with: |
jennypavlova
left a comment
There was a problem hiding this comment.
LGTM! 🚀 Thank you for the changes/fixes! 🙇
| hasFailedCreatingDataView, | ||
| hasFailedFetchingDataView, | ||
| isDataViewLoading, | ||
| hasFailedLoadingDataView, |
There was a problem hiding this comment.
thanks for improving this hook!
Summary
Closes #139594
This PR integrates the unified search component with the hosts table.
How to test this PR
systemmodule andadd_host_metadataprocessor enabledInfrastructure Hosts viewin Advanced SettingsIt should be possible to:
Screenshots