fix: restricted column long value to 3 line and line clamped (#6056)

* fix: restricted column long value to 3 line and line clamped

* fix: added tooltip prop as prop for generic component and passed style from consumer

* fix: comment resolved

* fix: refactored styles

* fix: updated snapshot

* fix: removed console log
This commit is contained in:
SagarRajput-7 2024-09-30 11:48:48 +05:30 committed by GitHub
parent 794d6fc0ca
commit 5a0a7c2c60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 118 additions and 22 deletions

View File

@ -0,0 +1,5 @@
.long-text-tooltip {
max-width: 500px;
max-height: 500px;
overflow-y: auto;
}

View File

@ -1,3 +1,5 @@
import './GridTableComponent.styles.scss';
import { ExclamationCircleFilled } from '@ant-design/icons'; import { ExclamationCircleFilled } from '@ant-design/icons';
import { Space, Tooltip } from 'antd'; import { Space, Tooltip } from 'antd';
import { getYAxisFormattedValue } from 'components/Graph/yAxisConfig'; import { getYAxisFormattedValue } from 'components/Graph/yAxisConfig';
@ -5,6 +7,7 @@ import { Events } from 'constants/events';
import { QueryTable } from 'container/QueryTable'; import { QueryTable } from 'container/QueryTable';
import { RowData } from 'lib/query/createTableColumnsFromQuery'; import { RowData } from 'lib/query/createTableColumnsFromQuery';
import { cloneDeep, get, isEmpty } from 'lodash-es'; import { cloneDeep, get, isEmpty } from 'lodash-es';
import LineClampedText from 'periscope/components/LineClampedText/LineClampedText';
import { memo, ReactNode, useCallback, useEffect, useMemo } from 'react'; import { memo, ReactNode, useCallback, useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { eventEmitter } from 'utils/getEventEmitter'; import { eventEmitter } from 'utils/getEventEmitter';
@ -116,7 +119,16 @@ function GridTableComponent({
} }
> >
<Space> <Space>
{text} <LineClampedText
text={text}
lines={3}
tooltipProps={{
placement: 'right',
autoAdjustOverflow: true,
overlayClassName: 'long-text-tooltip',
}}
/>
{hasMultipleMatches && ( {hasMultipleMatches && (
<Tooltip title={t('this_value_satisfies_multiple_thresholds')}> <Tooltip title={t('this_value_satisfies_multiple_thresholds')}>
<ExclamationCircleFilled className="value-graph-icon" /> <ExclamationCircleFilled className="value-graph-icon" />
@ -127,7 +139,19 @@ function GridTableComponent({
); );
} }
} }
return <div>{text}</div>; return (
<div>
<LineClampedText
text={text}
lines={3}
tooltipProps={{
placement: 'right',
autoAdjustOverflow: true,
overlayClassName: 'long-text-tooltip',
}}
/>
</div>
);
}, },
})); }));

View File

@ -63,8 +63,7 @@
height: 40px; height: 40px;
justify-content: end; justify-content: end;
padding: 0 8px; padding: 0 8px;
margin-top: 12px; margin: 12px 0 2px;
margin-bottom: 2px;
} }
} }

View File

@ -266,15 +266,23 @@ exports[`Table panel wrappper tests table should render fine with the query resp
class="ant-table-cell" class="ant-table-cell"
> >
<div> <div>
<div
class="line-clamped-text"
>
demo-app demo-app
</div> </div>
</div>
</td> </td>
<td <td
class="ant-table-cell" class="ant-table-cell"
> >
<div> <div>
<div
class="line-clamped-text"
>
4.35 s 4.35 s
</div> </div>
</div>
</td> </td>
</tr> </tr>
<tr <tr
@ -284,15 +292,23 @@ exports[`Table panel wrappper tests table should render fine with the query resp
class="ant-table-cell" class="ant-table-cell"
> >
<div> <div>
<div
class="line-clamped-text"
>
customer customer
</div> </div>
</div>
</td> </td>
<td <td
class="ant-table-cell" class="ant-table-cell"
> >
<div> <div>
<div
class="line-clamped-text"
>
431 ms 431 ms
</div> </div>
</div>
</td> </td>
</tr> </tr>
<tr <tr
@ -302,15 +318,23 @@ exports[`Table panel wrappper tests table should render fine with the query resp
class="ant-table-cell" class="ant-table-cell"
> >
<div> <div>
<div
class="line-clamped-text"
>
mysql mysql
</div> </div>
</div>
</td> </td>
<td <td
class="ant-table-cell" class="ant-table-cell"
> >
<div> <div>
<div
class="line-clamped-text"
>
431 ms 431 ms
</div> </div>
</div>
</td> </td>
</tr> </tr>
<tr <tr
@ -320,15 +344,23 @@ exports[`Table panel wrappper tests table should render fine with the query resp
class="ant-table-cell" class="ant-table-cell"
> >
<div> <div>
<div
class="line-clamped-text"
>
frontend frontend
</div> </div>
</div>
</td> </td>
<td <td
class="ant-table-cell" class="ant-table-cell"
> >
<div> <div>
<div
class="line-clamped-text"
>
287 ms 287 ms
</div> </div>
</div>
</td> </td>
</tr> </tr>
<tr <tr
@ -338,15 +370,23 @@ exports[`Table panel wrappper tests table should render fine with the query resp
class="ant-table-cell" class="ant-table-cell"
> >
<div> <div>
<div
class="line-clamped-text"
>
driver driver
</div> </div>
</div>
</td> </td>
<td <td
class="ant-table-cell" class="ant-table-cell"
> >
<div> <div>
<div
class="line-clamped-text"
>
230 ms 230 ms
</div> </div>
</div>
</td> </td>
</tr> </tr>
<tr <tr
@ -356,15 +396,23 @@ exports[`Table panel wrappper tests table should render fine with the query resp
class="ant-table-cell" class="ant-table-cell"
> >
<div> <div>
<div
class="line-clamped-text"
>
route route
</div> </div>
</div>
</td> </td>
<td <td
class="ant-table-cell" class="ant-table-cell"
> >
<div> <div>
<div
class="line-clamped-text"
>
66.4 ms 66.4 ms
</div> </div>
</div>
</td> </td>
</tr> </tr>
<tr <tr
@ -374,15 +422,23 @@ exports[`Table panel wrappper tests table should render fine with the query resp
class="ant-table-cell" class="ant-table-cell"
> >
<div> <div>
<div
class="line-clamped-text"
>
redis redis
</div> </div>
</div>
</td> </td>
<td <td
class="ant-table-cell" class="ant-table-cell"
> >
<div> <div>
<div
class="line-clamped-text"
>
31.3 ms 31.3 ms
</div> </div>
</div>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@ -52,8 +52,7 @@
height: 40px; height: 40px;
justify-content: end; justify-content: end;
padding: 0 8px; padding: 0 8px;
margin-top: 12px; margin: 12px 0 2px;
margin-bottom: 2px;
} }
} }

View File

@ -1,14 +1,16 @@
import './LineClampedText.styles.scss'; import './LineClampedText.styles.scss';
import { Tooltip } from 'antd'; import { Tooltip, TooltipProps } from 'antd';
import { useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
function LineClampedText({ function LineClampedText({
text, text,
lines, lines,
tooltipProps,
}: { }: {
text: string; text: string;
lines?: number; lines?: number;
tooltipProps?: TooltipProps;
}): JSX.Element { }): JSX.Element {
const [isOverflowing, setIsOverflowing] = useState(false); const [isOverflowing, setIsOverflowing] = useState(false);
const textRef = useRef<HTMLDivElement>(null); const textRef = useRef<HTMLDivElement>(null);
@ -42,11 +44,22 @@ function LineClampedText({
</div> </div>
); );
return isOverflowing ? <Tooltip title={text}>{content}</Tooltip> : content; return isOverflowing ? (
<Tooltip
title={text}
// eslint-disable-next-line react/jsx-props-no-spreading
{...tooltipProps}
>
{content}
</Tooltip>
) : (
content
);
} }
LineClampedText.defaultProps = { LineClampedText.defaultProps = {
lines: 1, lines: 1,
tooltipProps: {},
}; };
export default LineClampedText; export default LineClampedText;