forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Inventory][ECO] Entities table (elastic#193272)
Real data: <img width="1237" alt="Screenshot 2024-09-18 at 14 23 17" src="https://github.com/user-attachments/assets/ecc496aa-1c43-4c3c-9ac8-d6e4e6cb8aad"> Storybook: <img width="1256" alt="Screenshot 2024-09-18 at 14 23 22" src="https://github.com/user-attachments/assets/03d9f940-7b3f-4aea-9221-42b1c07119d1"> Tooltips: <img width="1250" alt="Screenshot 2024-09-18 at 13 49 19" src="https://github.com/user-attachments/assets/dc99b4cc-4eba-4815-8892-8e3fe7a041bb"> - Use ESQL to fetch the top 500 entities sorted by last seen property. - Display 20 entities per page. - Sorting is handles by the server and saved on the URL - Current page is saved on the URL - Filter entities types `service`, `host` or `container` - Filter only entities from the built in definition - LIMITATION: The EuiGrid doesn't have an embedded loading state, for now, I'm switching the entire view to display a loading spinner while data is being fetched. - PLUS: Storybook created with mock data. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit e3f3c68)
- Loading branch information
1 parent
9672d81
commit 54751cf
Showing
13 changed files
with
3,501 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
x-pack/packages/observability/observability_utils/es/utils/esql_result_to_plain_objects.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* 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 type { ESQLSearchResponse } from '@kbn/es-types'; | ||
|
||
export function esqlResultToPlainObjects<T extends Record<string, any>>( | ||
result: ESQLSearchResponse | ||
): T[] { | ||
return result.values.map((row) => { | ||
return row.reduce<Record<string, unknown>>((acc, value, index) => { | ||
const column = result.columns[index]; | ||
acc[column.name] = value; | ||
return acc; | ||
}, {}); | ||
}) as T[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
x-pack/plugins/observability_solution/inventory/common/es_fields/entities.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export const ENTITY_LAST_SEEN = 'entity.lastSeenTimestamp'; | ||
export const ENTITY_ID = 'entity.id'; | ||
export const ENTITY_TYPE = 'entity.type'; | ||
export const ENTITY_DISPLAY_NAME = 'entity.displayName'; | ||
export const ENTITY_DEFINITION_ID = 'entity.definitionId'; |
65 changes: 65 additions & 0 deletions
65
...bservability_solution/inventory/public/components/entities_grid/entities_grid.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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 { EuiDataGridSorting } from '@elastic/eui'; | ||
import { Meta, Story } from '@storybook/react'; | ||
import React, { useMemo, useState } from 'react'; | ||
import { orderBy } from 'lodash'; | ||
import { EntitiesGrid } from '.'; | ||
import { ENTITY_LAST_SEEN } from '../../../common/es_fields/entities'; | ||
import { entitiesMock } from './mock/entities_mock'; | ||
|
||
const stories: Meta<{}> = { | ||
title: 'app/inventory/entities_grid', | ||
component: EntitiesGrid, | ||
}; | ||
export default stories; | ||
|
||
export const Example: Story<{}> = () => { | ||
const [pageIndex, setPageIndex] = useState(0); | ||
const [sort, setSort] = useState<EuiDataGridSorting['columns'][0]>({ | ||
id: ENTITY_LAST_SEEN, | ||
direction: 'desc', | ||
}); | ||
|
||
const sortedItems = useMemo( | ||
() => orderBy(entitiesMock, sort.id, sort.direction), | ||
[sort.direction, sort.id] | ||
); | ||
|
||
return ( | ||
<EntitiesGrid | ||
entities={sortedItems} | ||
loading={false} | ||
sortDirection={sort.direction} | ||
sortField={sort.id} | ||
onChangePage={setPageIndex} | ||
onChangeSort={setSort} | ||
pageIndex={pageIndex} | ||
/> | ||
); | ||
}; | ||
|
||
export const EmptyGridExample: Story<{}> = () => { | ||
const [pageIndex, setPageIndex] = useState(0); | ||
const [sort, setSort] = useState<EuiDataGridSorting['columns'][0]>({ | ||
id: ENTITY_LAST_SEEN, | ||
direction: 'desc', | ||
}); | ||
|
||
return ( | ||
<EntitiesGrid | ||
entities={[]} | ||
loading={false} | ||
sortDirection={sort.direction} | ||
sortField={sort.id} | ||
onChangePage={setPageIndex} | ||
onChangeSort={setSort} | ||
pageIndex={pageIndex} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.