-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[One Discover] Custom Service Name Cell (#192381)
closes #190456 ## π Summary This PR adds the agent icon as a prefix to the service name if an agent name is available. ## π₯ Demo https://github.com/user-attachments/assets/4fad743a-6806-4440-91eb-fdfa35785a19 --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
4797dc4
commit 7b3fa3a
Showing
11 changed files
with
625 additions
and
227 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
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
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
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
61 changes: 61 additions & 0 deletions
61
src/plugins/discover/public/components/data_types/logs/service_name_cell.test.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,61 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { buildDataTableRecord, DataTableRecord } from '@kbn/discover-utils'; | ||
import { dataViewMock } from '@kbn/discover-utils/src/__mocks__'; | ||
import { fieldFormatsMock } from '@kbn/field-formats-plugin/common/mocks'; | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { getServiceNameCell } from './service_name_cell'; | ||
|
||
const renderCell = (serviceNameField: string, record: DataTableRecord) => { | ||
const ServiceNameCell = getServiceNameCell(serviceNameField); | ||
render( | ||
<ServiceNameCell | ||
rowIndex={0} | ||
colIndex={0} | ||
columnId="service.name" | ||
isExpandable={false} | ||
isExpanded={false} | ||
isDetails={false} | ||
row={record} | ||
dataView={dataViewMock} | ||
fieldFormats={fieldFormatsMock} | ||
setCellProps={() => {}} | ||
closePopover={() => {}} | ||
/> | ||
); | ||
}; | ||
|
||
describe('getServiceNameCell', () => { | ||
it('renders icon if agent name is recognized', () => { | ||
const record = buildDataTableRecord( | ||
{ fields: { 'service.name': 'test-service', 'agent.name': 'nodejs' } }, | ||
dataViewMock | ||
); | ||
renderCell('service.name', record); | ||
expect(screen.getByTestId('serviceNameCell-nodejs')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders default icon with unknwon test subject if agent name is missing', () => { | ||
const record = buildDataTableRecord( | ||
{ fields: { 'service.name': 'test-service' } }, | ||
dataViewMock | ||
); | ||
renderCell('service.name', record); | ||
expect(screen.getByTestId('serviceNameCell-unknown')).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not render if service name is missing', () => { | ||
const record = buildDataTableRecord({ fields: { 'agent.name': 'nodejs' } }, dataViewMock); | ||
renderCell('service.name', record); | ||
expect(screen.queryByTestId('serviceNameCell-nodejs')).not.toBeInTheDocument(); | ||
expect(screen.queryByTestId('serviceNameCell-unknown')).not.toBeInTheDocument(); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
src/plugins/discover/public/components/data_types/logs/service_name_cell.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,45 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui'; | ||
import type { AgentName } from '@kbn/elastic-agent-utils'; | ||
import { dynamic } from '@kbn/shared-ux-utility'; | ||
import type { DataGridCellValueElementProps } from '@kbn/unified-data-table'; | ||
import React from 'react'; | ||
import { getFieldValue } from '@kbn/discover-utils'; | ||
import { AGENT_NAME_FIELD } from '../../../../common/data_types/logs/constants'; | ||
|
||
const dataTestSubj = 'serviceNameCell'; | ||
const AgentIcon = dynamic(() => import('@kbn/custom-icons/src/components/agent_icon')); | ||
|
||
export const getServiceNameCell = | ||
(serviceNameField: string) => (props: DataGridCellValueElementProps) => { | ||
const serviceNameValue = getFieldValue(props.row, serviceNameField); | ||
const agentName = getFieldValue(props.row, AGENT_NAME_FIELD) as AgentName; | ||
|
||
if (!serviceNameValue) { | ||
return <span data-test-subj={`${dataTestSubj}-empty`}>-</span>; | ||
} | ||
|
||
return ( | ||
<EuiFlexGroup | ||
gutterSize="xs" | ||
data-test-subj={`${dataTestSubj}-${agentName || 'unknown'}`} | ||
responsive={false} | ||
alignItems="center" | ||
> | ||
<EuiFlexItem grow={false}> | ||
<EuiToolTip position="left" content={agentName} repositionOnScroll={true}> | ||
<AgentIcon agentName={agentName} size="m" /> | ||
</EuiToolTip> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}>{serviceNameValue}</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; |
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
Oops, something went wrong.