Skip to content

Commit e945fb5

Browse files
committed
🔨 refactor(ObservationCard.tsx): add support for displaying quotes with ellipsis if exceeding max characters limit
1 parent 75c159b commit e945fb5

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

‎src/pages/Insights/Collection/ObservationCard.tsx‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
IconButton,
66
Label,
77
SM,
8+
Span,
89
SpecialCard,
910
Tag,
1011
} from '@appquality/unguess-design-system';
@@ -67,6 +68,7 @@ export const ObservationCard = ({
6768
const { t } = useTranslation();
6869
const [isLightboxOpen, setIsLightboxOpen] = useState(false);
6970
const { values, setFieldValue } = useFormikContext<InsightFormValues>();
71+
const quotesMaxChars = 50;
7072

7173
const severity = observation.tags.find(
7274
(tag) => tag.group.name === 'severity'
@@ -110,6 +112,13 @@ export const ObservationCard = ({
110112
}
111113
};
112114

115+
const getQuotesWithEllipsis = (quotes: string, maxChars: number = 50) => {
116+
if (quotes.length > maxChars) {
117+
return `${quotes.slice(0, maxChars)}...`;
118+
}
119+
return quotes;
120+
};
121+
113122
return (
114123
<FieldArray name="observations">
115124
{(arrayHelpers) => (
@@ -168,7 +177,19 @@ export const ObservationCard = ({
168177
}}
169178
>
170179
<Quotes isChecked={isChecked}>
171-
&quot;{observation.quotes}&quot;
180+
&quot;
181+
{observation.quotes &&
182+
observation.quotes.length > quotesMaxChars ? (
183+
<Span title={observation.quotes}>
184+
{getQuotesWithEllipsis(
185+
observation.quotes,
186+
quotesMaxChars
187+
)}
188+
</Span>
189+
) : (
190+
observation.quotes
191+
)}
192+
&quot;
172193
</Quotes>
173194
</SpecialCard.Header.Title>
174195
<SpecialCard.Header.Text style={{ marginTop: 'auto' }}>

0 commit comments

Comments
 (0)