mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Asset Inventory] Removing Static data from the DataGrid (#208438)
## Summary This closes https://github.com/elastic/security-team/issues/11687 This PR removes the static generated data from the Asset Inventory page Datagrid to avoid any potential confusion when enabling the `assetInventoryUXEnabled` Feature Flag on Kibana 9.0. It also adds a Technical Preview badge and add a custom `useDataView` hook since the DataView per space is not yet supported on Asset Inventory. ## Screenshots **Before** (Datagrid with random generated data)  **After** (Datagrid with empty state) 
This commit is contained in:
parent
32e9a990a9
commit
4d00374e04
3 changed files with 63 additions and 26 deletions
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* 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 { useKibana } from '@kbn/kibana-react-plugin/public';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
|
||||
|
||||
/**
|
||||
* Temporary hook to get the data view for a given index pattern
|
||||
* TODO: use @kbn/cloud-security-posture/src/hooks/use_data_view once
|
||||
* Asset Inventory is ready to create data views per space
|
||||
*/
|
||||
export const useDataView = (indexPattern: string) => {
|
||||
const {
|
||||
data: { dataViews },
|
||||
} = useKibana<{ data: DataPublicPluginStart }>().services;
|
||||
|
||||
return useQuery(['useDataView', indexPattern], async () => {
|
||||
const [dataView] = await dataViews.find(indexPattern);
|
||||
|
||||
if (!dataView) {
|
||||
throw new Error(`Data view not found [${indexPattern}]`);
|
||||
}
|
||||
|
||||
return dataView;
|
||||
});
|
||||
};
|
|
@ -30,17 +30,19 @@ import {
|
|||
EuiPageTemplate,
|
||||
EuiTitle,
|
||||
EuiButtonIcon,
|
||||
EuiBetaBadge,
|
||||
useEuiTheme,
|
||||
} from '@elastic/eui';
|
||||
import { type AddFieldFilterHandler } from '@kbn/unified-field-list';
|
||||
import { generateFilters } from '@kbn/data-plugin/public';
|
||||
import { type DocViewFilterFn } from '@kbn/unified-doc-viewer/types';
|
||||
import useLocalStorage from 'react-use/lib/useLocalStorage';
|
||||
import { css } from '@emotion/react';
|
||||
|
||||
import { type CriticalityLevelWithUnassigned } from '../../../common/entity_analytics/asset_criticality/types';
|
||||
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 { RiskBadge } from '../components/risk_badge';
|
||||
|
@ -152,6 +154,7 @@ const AllAssets = ({
|
|||
flyoutComponent,
|
||||
...rest
|
||||
}: AllAssetsProps) => {
|
||||
const { euiTheme } = useEuiTheme();
|
||||
const assetInventoryDataTable = useAssetInventoryDataTable({
|
||||
paginationLocalStorageKey: LOCAL_STORAGE_DATA_TABLE_PAGE_SIZE_KEY,
|
||||
columnsLocalStorageKey,
|
||||
|
@ -165,7 +168,6 @@ const AllAssets = ({
|
|||
onChangeItemsPerPage,
|
||||
setUrlQuery,
|
||||
onSort,
|
||||
onResetFilters,
|
||||
filters,
|
||||
sort,
|
||||
} = assetInventoryDataTable;
|
||||
|
@ -361,18 +363,15 @@ const AllAssets = ({
|
|||
? DataLoadingState.loading
|
||||
: DataLoadingState.loaded;
|
||||
|
||||
// TODO Improve this loading - prevent race condition fetching rows and dataView
|
||||
if (loadingState === DataLoadingState.loaded && !rows.length && !!dataView) {
|
||||
return <EmptyState onResetFilters={onResetFilters} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<I18nProvider>
|
||||
<AssetInventorySearchBar
|
||||
query={getDefaultQuery({ query: { query: '', language: '' }, filters: [] })}
|
||||
setQuery={setUrlQuery}
|
||||
loading={loadingState === DataLoadingState.loading}
|
||||
/>
|
||||
{!dataView ? null : (
|
||||
<AssetInventorySearchBar
|
||||
query={getDefaultQuery({ query: { query: '', language: '' }, filters: [] })}
|
||||
setQuery={setUrlQuery}
|
||||
loading={loadingState === DataLoadingState.loading}
|
||||
/>
|
||||
)}
|
||||
<EuiPageTemplate.Section>
|
||||
<EuiTitle size="l" data-test-subj="all-assets-title">
|
||||
<h1>
|
||||
|
@ -380,6 +379,23 @@ const AllAssets = ({
|
|||
id="xpack.securitySolution.assetInventory.allAssets"
|
||||
defaultMessage="All Assets"
|
||||
/>
|
||||
<EuiBetaBadge
|
||||
css={css`
|
||||
margin-left: ${euiTheme.size.s};
|
||||
`}
|
||||
label={i18n.translate('xpack.securitySolution.assetInventory.technicalPreviewLabel', {
|
||||
defaultMessage: 'Technical Preview',
|
||||
})}
|
||||
size="s"
|
||||
color="subdued"
|
||||
tooltipContent={i18n.translate(
|
||||
'xpack.securitySolution.assetInventory.technicalPreviewTooltip',
|
||||
{
|
||||
defaultMessage:
|
||||
'This functionality is experimental and not supported. It may change or be removed at any time.',
|
||||
}
|
||||
)}
|
||||
/>
|
||||
</h1>
|
||||
</EuiTitle>
|
||||
<CellActionsProvider getTriggerCompatibleActions={uiActions.getTriggerCompatibleActions}>
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
import React, { lazy, Suspense } from 'react';
|
||||
import { EuiLoadingSpinner } from '@elastic/eui';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { useDataView } from '@kbn/cloud-security-posture/src/hooks/use_data_view';
|
||||
import type { SecuritySubPluginRoutes } from '../app/types';
|
||||
import { SecurityPageName } from '../app/types';
|
||||
import { ASSET_INVENTORY_PATH } from '../../common/constants';
|
||||
|
@ -16,20 +15,10 @@ import { SecuritySolutionPageWrapper } from '../common/components/page_wrapper';
|
|||
import { PluginTemplateWrapper } from '../common/components/plugin_template_wrapper';
|
||||
import { SecurityRoutePageWrapper } from '../common/components/security_route_page_wrapper';
|
||||
import { DataViewContext } from './hooks/data_view_context';
|
||||
import { mockData } from './sample_data';
|
||||
import { useDataView } from './hooks/use_asset_inventory_data_table/use_data_view';
|
||||
|
||||
const AllAssetsLazy = lazy(() => import('./pages/all_assets'));
|
||||
|
||||
const rows = [
|
||||
...mockData,
|
||||
...mockData,
|
||||
...mockData,
|
||||
...mockData,
|
||||
...mockData,
|
||||
...mockData,
|
||||
...mockData,
|
||||
] as typeof mockData;
|
||||
|
||||
// Initializing react-query
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
|
@ -41,8 +30,10 @@ const queryClient = new QueryClient({
|
|||
},
|
||||
});
|
||||
|
||||
const ASSET_INVENTORY_INDEX_PATTERN = 'logs-cloud_asset_inventory.asset_inventory-*';
|
||||
|
||||
export const AssetInventoryRoutes = () => {
|
||||
const dataViewQuery = useDataView('asset-inventory-logs');
|
||||
const dataViewQuery = useDataView(ASSET_INVENTORY_INDEX_PATTERN);
|
||||
|
||||
const dataViewContextValue = {
|
||||
dataView: dataViewQuery.data!, // eslint-disable-line @typescript-eslint/no-non-null-assertion
|
||||
|
@ -59,7 +50,7 @@ export const AssetInventoryRoutes = () => {
|
|||
<SecuritySolutionPageWrapper noPadding>
|
||||
<Suspense fallback={<EuiLoadingSpinner />}>
|
||||
<AllAssetsLazy
|
||||
rows={rows}
|
||||
rows={[]}
|
||||
isLoading={false}
|
||||
loadMore={() => {}}
|
||||
flyoutComponent={() => <></>}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue