Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

import React from 'react';
import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import type { Alert } from '@kbn/alerting-types';
import { BasicCellRenderer } from './basic_cell_renderer';
import { BASIC_CELL_RENDERER_TRUNCATE_TEST_ID, BasicCellRenderer } from './basic_cell_renderer';
import { TestProviders } from '../../../../common/mock';
import { getEmptyValue } from '../../../../common/components/empty_value';

Expand Down Expand Up @@ -131,4 +131,24 @@ describe('BasicCellRenderer', () => {

expect(getByText('[object Object]')).toBeInTheDocument();
});

it('should truncate long values and show tooltip', async () => {
const alert: Alert = {
_id: '_id',
_index: '_index',
field1: 'value1',
};
const field = 'field1';

render(
<TestProviders>
<BasicCellRenderer alert={alert} field={field} />
</TestProviders>
);

const cell = screen.getByTestId(BASIC_CELL_RENDERER_TRUNCATE_TEST_ID);

expect(cell).toBeInTheDocument();
expect(cell.firstChild).toHaveClass('euiToolTipAnchor');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@

import React, { memo, useMemo } from 'react';
import type { Alert } from '@kbn/alerting-types';
import { EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui';
import { getOrEmptyTagFromValue } from '../../../../common/components/empty_value';
import { TruncatableText } from '../../../../common/components/truncatable_text';
import { getAlertFieldValueAsStringOrNull } from '../../../utils/type_utils';

export const BASIC_CELL_RENDERER_TRUNCATE_TEST_ID =
'alert-summary-table-basic-call-rendered-truncate';

export interface BasicCellRendererProps {
/**
* Alert data passed from the renderCellValue callback via the AlertWithLegacyFormats interface
Expand All @@ -31,7 +36,25 @@ export const BasicCellRenderer = memo(({ alert, field }: BasicCellRendererProps)
[alert, field]
);

return <>{getOrEmptyTagFromValue(displayValue)}</>;
return (
<TruncatableText dataTestSubj={BASIC_CELL_RENDERER_TRUNCATE_TEST_ID}>
<EuiToolTip
Copy link
Copy Markdown
Contributor

@christineweng christineweng Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there is a tooltipContent prop in TruncateableText, you can probably reuse that here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried and something is actually funky if you use the tooltipContent from the TruncateableText component.
Here's how it looks:

Screenshot 2025-04-28 at 3 24 41 PM

And here's with the current code

Screenshot 2025-04-28 at 3 25 11 PM

I wonder if that's why it was used like this in our current alerts table (which is where I stole the code from).

I'm going to keep the code I have for now. I don't want to make a change to the TruncateableText component as it's being used in a few places and some of them do use the tooltipContent prop....

position="bottom"
content={
<EuiFlexGroup direction="column" gutterSize="none">
<EuiFlexItem grow={false}>
<span>{field}</span>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<span>{displayValue}</span>
</EuiFlexItem>
</EuiFlexGroup>
}
>
<span>{getOrEmptyTagFromValue(displayValue)}</span>
</EuiToolTip>
</TruncatableText>
);
});

BasicCellRenderer.displayName = 'BasicCellRenderer';