Skip to content

Commit

Permalink
Add search bar to Asset Inventory page (elastic#206811)
Browse files Browse the repository at this point in the history
## Summary

Closes elastic#201709.

Add toolbar and search bar to Asset Inventory "All Assets" page.

### Screenshots

#### Before

<img width="1484" alt="Screenshot 2025-01-16 at 17 21 13"
src="https://github.com/user-attachments/assets/01b81d32-d427-4aef-8bd2-1abebd875dc6"
/>

#### After

<img width="1756" alt="Screenshot 2025-01-16 at 17 21 04"
src="https://github.com/user-attachments/assets/71000329-12fe-4c9b-a517-ebce034244ef"
/>

### Definition of done

- [x] Add a header and toolbar to the "Asset Inventory" page.
- [x] Implement a search bar within the toolbar using the
`@kbn/unified-search-plugin`.
- [x] Ensure the search bar is styled according to the [visual
specs](https://www.figma.com/design/9zUqAhhglT1EGYG4LOl1X6/Asset-Management?node-id=2946-19646&t=FuD3BEY4FyxAKV38-4).
- [ ] ~~Integrate the search bar so it can interact with the `logs-*`
Dataview (default).~~ No integration for now. Will come in future PRs

> [!CAUTION]
> `search_bar.tsx` was duplicated from the CSP plugin. We should create
a separate @kbn-package to encapsulate and reuse this type of
functionality across plugins, then reuse it both from CSP and Asset
Inventory.

### Checklist

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [x] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Identify risks

No risks.

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
albertoblaz and elasticmachine authored Jan 20, 2025
1 parent c06d42f commit d18d25b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import React from 'react';
import { css } from '@emotion/react';
import { type EuiThemeComputed, useEuiTheme } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import type { Filter } from '@kbn/es-query';
import { useKibana } from '../../common/lib/kibana';
import { FiltersGlobal } from '../../common/components/filters_global/filters_global';
import { useDataViewContext } from '../hooks/data_view_context';
import type { AssetsBaseURLQuery } from '../hooks/use_asset_inventory_data_table';

type SearchBarQueryProps = Pick<AssetsBaseURLQuery, 'query' | 'filters'>;

interface AssetInventorySearchBarProps {
setQuery(v: Partial<SearchBarQueryProps>): void;
loading: boolean;
placeholder?: string;
query: SearchBarQueryProps;
}

export const AssetInventorySearchBar = ({
loading,
query,
setQuery,
placeholder = i18n.translate(
'xpack.securitySolution.assetInventory.searchBar.searchPlaceholder',
{
defaultMessage: 'Filter your data using KQL syntax',
}
),
}: AssetInventorySearchBarProps) => {
const { euiTheme } = useEuiTheme();
const {
unifiedSearch: {
ui: { SearchBar },
},
} = useKibana().services;

const { dataView } = useDataViewContext();

return (
<FiltersGlobal>
<div css={getContainerStyle(euiTheme)}>
<SearchBar
appName="Asset Inventory"
showFilterBar={true}
showQueryInput={true}
showDatePicker={false}
isLoading={loading}
indexPatterns={[dataView]}
onQuerySubmit={setQuery}
onFiltersUpdated={(value: Filter[]) => setQuery({ filters: value })}
placeholder={placeholder}
query={{
query: query?.query?.query || '',
language: query?.query?.language || 'kuery',
}}
filters={query?.filters || []}
/>
</div>
</FiltersGlobal>
);
};

const getContainerStyle = (theme: EuiThemeComputed) => css`
border-bottom: ${theme.border.thin};
background-color: ${theme.colors.body};
padding: ${theme.size.base};
`;
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { useKibana } from '../../common/lib/kibana';
import { AssetCriticalityBadge } from '../../entity_analytics/components/asset_criticality/asset_criticality_badge';
import { EmptyState } from '../components/empty_state';
import { AdditionalControls } from '../components/additional_controls';
import { AssetInventorySearchBar } from '../components/search_bar';

import { useDataViewContext } from '../hooks/data_view_context';
import { useStyles } from '../hooks/use_styles';
Expand Down Expand Up @@ -366,6 +367,11 @@ const AllAssets = ({

return (
<I18nProvider>
<AssetInventorySearchBar
query={getDefaultQuery({ query: { query: '', language: '' }, filters: [] })}
setQuery={setUrlQuery}
loading={loadingState === DataLoadingState.loading}
/>
<EuiPageTemplate.Section>
<EuiTitle size="l">
<h1>
Expand Down

0 comments on commit d18d25b

Please sign in to comment.