Skip to content

Commit

Permalink
[8.x] [Discover] Use summary column service name component for servic…
Browse files Browse the repository at this point in the history
…e name… (#196742) (#197228)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Discover] Use summary column service name component for service
name… (#196742)](#196742)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"mohamedhamed-ahmed","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-22T12:33:20Z","message":"[Discover]
Use summary column service name component for service name…
(#196742)\n\ncloses
https://github.com/elastic/kibana/issues/196541\r\n## 📝
Summary\r\n\r\nThis PR updated the `service.name` cell renderer so that
it mimics what\r\nwe have in the `summary` column.\r\nIt now shows a
clickable pill shape for quick filters and navigating to\r\nthe service
page if `APM` is available.\r\n\r\n## 🎥
Demo\r\n\r\n\r\nhttps://github.com/user-attachments/assets/627b39af-f008-487b-82f2-c0ab79aff9a4","sha":"3130492752b622458d521eec228e075916237d74","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:DataDiscovery","Team:obs-ux-logs","Project:OneDiscover","backport:version","v8.17.0"],"title":"[Discover]
Use summary column service name component for service
name…","number":196742,"url":"https://github.com/elastic/kibana/pull/196742","mergeCommit":{"message":"[Discover]
Use summary column service name component for service name…
(#196742)\n\ncloses
https://github.com/elastic/kibana/issues/196541\r\n## 📝
Summary\r\n\r\nThis PR updated the `service.name` cell renderer so that
it mimics what\r\nwe have in the `summary` column.\r\nIt now shows a
clickable pill shape for quick filters and navigating to\r\nthe service
page if `APM` is available.\r\n\r\n## 🎥
Demo\r\n\r\n\r\nhttps://github.com/user-attachments/assets/627b39af-f008-487b-82f2-c0ab79aff9a4","sha":"3130492752b622458d521eec228e075916237d74"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196742","number":196742,"mergeCommit":{"message":"[Discover]
Use summary column service name component for service name…
(#196742)\n\ncloses
https://github.com/elastic/kibana/issues/196541\r\n## 📝
Summary\r\n\r\nThis PR updated the `service.name` cell renderer so that
it mimics what\r\nwe have in the `summary` column.\r\nIt now shows a
clickable pill shape for quick filters and navigating to\r\nthe service
page if `APM` is available.\r\n\r\n## 🎥
Demo\r\n\r\n\r\nhttps://github.com/user-attachments/assets/627b39af-f008-487b-82f2-c0ab79aff9a4","sha":"3130492752b622458d521eec228e075916237d74"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: mohamedhamed-ahmed <[email protected]>
  • Loading branch information
kibanamachine and mohamedhamed-ahmed authored Oct 22, 2024
1 parent 3e6889d commit 2195c28
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,46 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React from 'react';
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 { DataGridDensity, ROWS_HEIGHT_OPTIONS } from '@kbn/unified-data-table';
import { getServiceNameCell } from './service_name_cell';
import { CellRenderersExtensionParams } from '../../../context_awareness';

const core = {
application: {
capabilities: {
apm: {
show: true,
},
},
},
uiSettings: {
get: () => true,
},
};

jest.mock('../../../hooks/use_discover_services', () => {
const originalModule = jest.requireActual('../../../hooks/use_discover_services');
return {
...originalModule,
useDiscoverServices: () => ({ core, share: {} }),
};
});

const renderCell = (serviceNameField: string, record: DataTableRecord) => {
const ServiceNameCell = getServiceNameCell(serviceNameField);
const cellRenderersExtensionParamsMock: CellRenderersExtensionParams = {
actions: {
addFilter: jest.fn(),
},
dataView: dataViewMock,
density: DataGridDensity.COMPACT,
rowHeight: ROWS_HEIGHT_OPTIONS.single,
};
const ServiceNameCell = getServiceNameCell(serviceNameField, cellRenderersExtensionParamsMock);
render(
<ServiceNameCell
rowIndex={0}
Expand All @@ -40,22 +71,12 @@ describe('getServiceNameCell', () => {
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();
expect(screen.getByTestId('dataTableCellActionsPopover_service.name')).toBeInTheDocument();
});

it('does not render if service name is missing', () => {
it('does render empty div 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();
expect(screen.queryByTestId('serviceNameCell-empty')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,46 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui';
import React from 'react';
import { 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 { css } from '@emotion/react';
import { getFieldValue } from '@kbn/discover-utils';
import { euiThemeVars } from '@kbn/ui-theme';
import { CellRenderersExtensionParams } from '../../../context_awareness';
import { AGENT_NAME_FIELD } from '../../../../common/data_types/logs/constants';
import { ServiceNameBadgeWithActions } from './service_name_badge_with_actions';

const dataTestSubj = 'serviceNameCell';
const AgentIcon = dynamic(() => import('@kbn/custom-icons/src/components/agent_icon'));
const dataTestSubj = 'serviceNameCell';
const agentIconStyle = css`
margin-right: ${euiThemeVars.euiSizeXS};
`;

export const getServiceNameCell =
(serviceNameField: string) => (props: DataGridCellValueElementProps) => {
(serviceNameField: string, { actions }: CellRenderersExtensionParams) =>
(props: DataGridCellValueElementProps) => {
const serviceNameValue = getFieldValue(props.row, serviceNameField) as string;
const agentName = getFieldValue(props.row, AGENT_NAME_FIELD) as AgentName;

if (!serviceNameValue) {
return <span data-test-subj={`${dataTestSubj}-empty`}>-</span>;
}

const getIcon = () => (
<EuiToolTip position="left" content={agentName} repositionOnScroll={true}>
<AgentIcon agentName={agentName} size="m" css={agentIconStyle} />
</EuiToolTip>
);

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>
<ServiceNameBadgeWithActions
onFilter={actions.addFilter}
icon={getIcon}
value={serviceNameValue}
property={serviceNameField}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export const getCellRenderers: DataSourceProfileProvider['profile']['getCellRend
...SERVICE_NAME_FIELDS.reduce(
(acc, field) => ({
...acc,
[field]: getServiceNameCell(field),
[`${field}.keyword`]: getServiceNameCell(`${field}.keyword`),
[field]: getServiceNameCell(field, params),
[`${field}.keyword`]: getServiceNameCell(`${field}.keyword`, params),
}),
{}
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0);
const lastCell = await dataGrid.getCellElementExcludingControlColumns(2, 0);
const firstServiceNameCell = await firstCell.findByTestSubject('serviceNameCell-java');
const lastServiceNameCell = await lastCell.findByTestSubject('serviceNameCell-unknown');
const firstServiceNameCell = await firstCell.findByTestSubject(
'dataTableCellActionsPopover_service.name'
);
const lastServiceNameCell = await lastCell.findByTestSubject(
'dataTableCellActionsPopover_service.name'
);
expect(await firstServiceNameCell.getVisibleText()).to.be('product');
expect(await lastServiceNameCell.getVisibleText()).to.be('accounting');
});
Expand All @@ -130,7 +134,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await retry.try(async () => {
const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0);
expect(await firstCell.getVisibleText()).to.be('product');
await testSubjects.missingOrFail('*serviceNameCell*');
await testSubjects.missingOrFail('dataTableCellActionsPopover_service.name');
});
});
});
Expand Down Expand Up @@ -278,8 +282,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await retry.try(async () => {
firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1);
lastCell = await dataGrid.getCellElementExcludingControlColumns(2, 1);
const firstServiceNameCell = await firstCell.findByTestSubject('serviceNameCell-java');
const lastServiceNameCell = await lastCell.findByTestSubject('serviceNameCell-unknown');
const firstServiceNameCell = await firstCell.findByTestSubject(
'dataTableCellActionsPopover_service.name'
);
const lastServiceNameCell = await lastCell.findByTestSubject(
'dataTableCellActionsPopover_service.name'
);
expect(await firstServiceNameCell.getVisibleText()).to.be('product');
expect(await lastServiceNameCell.getVisibleText()).to.be('accounting');
});
Expand Down Expand Up @@ -309,7 +317,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

expect(await firstCell.getVisibleText()).to.be('product');
expect(await lastCell.getVisibleText()).to.be('accounting');
await testSubjects.missingOrFail('*serviceNameCell*');
await testSubjects.missingOrFail('dataTableCellActionsPopover_service.name');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0);
const lastCell = await dataGrid.getCellElementExcludingControlColumns(2, 0);
const firstServiceNameCell = await firstCell.findByTestSubject('serviceNameCell-java');
const lastServiceNameCell = await lastCell.findByTestSubject('serviceNameCell-unknown');
const firstServiceNameCell = await firstCell.findByTestSubject(
'dataTableCellActionsPopover_service.name'
);
const lastServiceNameCell = await lastCell.findByTestSubject(
'dataTableCellActionsPopover_service.name'
);
expect(await firstServiceNameCell.getVisibleText()).to.be('product');
expect(await lastServiceNameCell.getVisibleText()).to.be('accounting');
});
Expand All @@ -130,7 +134,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await retry.try(async () => {
const firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 0);
expect(await firstCell.getVisibleText()).to.be('product');
await testSubjects.missingOrFail('*serviceNameCell*');
await testSubjects.missingOrFail('dataTableCellActionsPopover_service.name');
});
});
});
Expand Down Expand Up @@ -277,8 +281,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await retry.try(async () => {
firstCell = await dataGrid.getCellElementExcludingControlColumns(0, 1);
lastCell = await dataGrid.getCellElementExcludingControlColumns(2, 1);
const firstServiceNameCell = await firstCell.findByTestSubject('serviceNameCell-java');
const lastServiceNameCell = await lastCell.findByTestSubject('serviceNameCell-unknown');
const firstServiceNameCell = await firstCell.findByTestSubject(
'dataTableCellActionsPopover_service.name'
);
const lastServiceNameCell = await lastCell.findByTestSubject(
'dataTableCellActionsPopover_service.name'
);
expect(await firstServiceNameCell.getVisibleText()).to.be('product');
expect(await lastServiceNameCell.getVisibleText()).to.be('accounting');
});
Expand Down Expand Up @@ -308,7 +316,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

expect(await firstCell.getVisibleText()).to.be('product');
expect(await lastCell.getVisibleText()).to.be('accounting');
await testSubjects.missingOrFail('*serviceNameCell*');
await testSubjects.missingOrFail('dataTableCellActionsPopover_service.name');
});
});
});
Expand Down

0 comments on commit 2195c28

Please sign in to comment.