Skip to content

Commit 9ea71a5

Browse files
authored
Merge pull request #1632 from kleros/fix(web)-prevent-long-text-overflow
fix(web): prevent long text overflow
2 parents a8e8699 + 3a41d0b commit 9ea71a5

File tree

7 files changed

+74
-16
lines changed

7 files changed

+74
-16
lines changed

web/src/components/DisputePreview/Alias.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ const AliasContainer = styled.div`
1212
display: flex;
1313
gap: 8px;
1414
align-items: center;
15+
max-width: 100%;
1516
`;
1617

1718
const TextContainer = styled.div`
1819
display: flex;
20+
flex-wrap: wrap;
21+
max-width: 100%;
1922
> label {
2023
color: ${({ theme }) => theme.primaryText};
2124
font-size: 14px;
25+
word-wrap: break-word;
26+
max-width: 100%;
2227
}
2328
`;
2429

web/src/components/DisputePreview/DisputeContext.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import AliasDisplay from "./Alias";
1616

1717
const StyledH1 = styled.h1`
1818
margin: 0;
19+
word-wrap: break-word;
1920
`;
2021

2122
const QuestionAndDescription = styled.div`
2223
display: flex;
2324
flex-direction: column;
25+
word-wrap: break-word;
2426
div:first-child p:first-of-type {
2527
font-size: 16px;
2628
font-weight: 600;
@@ -47,6 +49,9 @@ const Answer = styled.div`
4749
display: flex;
4850
flex-wrap: wrap;
4951
gap: ${responsiveSize(2, 8)};
52+
> label {
53+
max-width: 100%;
54+
}
5055
`;
5156

5257
const AliasesContainer = styled.div`

web/src/components/DisputeView/DisputeInfo/DisputeInfoCard.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ const RestOfFieldsContainer = styled.div<{ isOverview?: boolean }>`
5252
`};
5353
`;
5454

55+
const StyledField = styled(Field)`
56+
max-width: 100%;
57+
label {
58+
&.value {
59+
margin-left: 8px;
60+
overflow: hidden;
61+
text-overflow: ellipsis;
62+
}
63+
}
64+
`;
65+
5566
type IDisputeInfoCard = { fieldItems: FieldItem[] } & IDisputeInfo;
5667

5768
const DisputeInfoCard: React.FC<IDisputeInfoCard> = ({
@@ -75,12 +86,12 @@ const DisputeInfoCard: React.FC<IDisputeInfoCard> = ({
7586
<Container>
7687
{court && courtId && isOverview && (
7788
<CourtBranchFieldContainer>
78-
<Field icon={LawBalanceIcon} name="Court Branch" value={courtBranchValue} {...{ isOverview }} />
89+
<StyledField icon={LawBalanceIcon} name="Court Branch" value={courtBranchValue} {...{ isOverview }} />
7990
</CourtBranchFieldContainer>
8091
)}
8192
<RestOfFieldsContainer {...{ isOverview }}>
8293
{fieldItems.map((item) =>
83-
item.display ? <Field key={item.name} {...(item as IField)} {...{ isOverview }} /> : null
94+
item.display ? <StyledField key={item.name} {...(item as IField)} {...{ isOverview }} /> : null
8495
)}
8596
</RestOfFieldsContainer>
8697
{showLabels ? <CardLabel disputeId={disputeID} round={round - 1} /> : null}

web/src/components/DisputeView/DisputeInfo/DisputeInfoList.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import React from "react";
1+
import React, { useMemo } from "react";
22
import styled from "styled-components";
3+
34
import { responsiveSize } from "styles/responsiveSize";
5+
46
import Field, { IField } from "components/Field";
7+
58
import CardLabel from "../CardLabels";
9+
610
import { FieldItem, IDisputeInfo } from ".";
711

812
const Container = styled.div<{ isLabel?: boolean }>`
@@ -29,15 +33,29 @@ const RestOfFieldsContainer = styled.div`
2933
const StyledField = styled(Field)<{ style?: string }>`
3034
${({ style }) => style ?? ""}
3135
`;
36+
37+
const truncateText = (text: string, limit: number) => {
38+
if (text && text.length > limit) {
39+
return text.substring(0, limit) + "...";
40+
}
41+
return text;
42+
};
43+
3244
type IDisputeInfoList = { fieldItems: FieldItem[] } & IDisputeInfo;
3345
const DisputeInfoList: React.FC<IDisputeInfoList> = ({ fieldItems, showLabels, disputeID, round }) => {
46+
const FieldItems = useMemo(
47+
() =>
48+
fieldItems.map((item) =>
49+
item.display ? (
50+
<StyledField key={item.name} {...(item as IField)} value={truncateText(item.value, 20)} displayAsList />
51+
) : null
52+
),
53+
[fieldItems]
54+
);
55+
3456
return (
3557
<Container isLabel={showLabels}>
36-
<RestOfFieldsContainer>
37-
{fieldItems.map((item) =>
38-
item.display ? <StyledField key={item.name} {...(item as IField)} displayAsList /> : null
39-
)}
40-
</RestOfFieldsContainer>
58+
<RestOfFieldsContainer>{FieldItems}</RestOfFieldsContainer>
4159
{showLabels ? <CardLabel disputeId={disputeID} round={round - 1} isList /> : null}
4260
</Container>
4361
);

web/src/components/Field.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const FieldContainer = styled.div<FieldContainerProps>`
2121
fill: ${({ theme }) => theme.secondaryPurple};
2222
margin-right: 8px;
2323
width: 14px;
24+
flex-shrink: 0;
2425
}
2526
2627
${({ isList }) =>

web/src/pages/Cases/CaseDetails/Appeal/OptionCard.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,22 @@ const TopContainer = styled.div`
3838
display: flex;
3939
justify-content: space-between;
4040
height: 50%;
41-
.block {
42-
display: block;
43-
}
41+
`;
42+
43+
const TextContainer = styled.div`
44+
display: flex;
45+
flex-direction: column;
46+
flex-grow: 1;
47+
min-width: 0;
48+
`;
49+
50+
const BlockLabel = styled.label`
51+
display: block;
52+
font-weight: 600;
53+
overflow: hidden;
54+
text-overflow: ellipsis;
55+
white-space: nowrap;
56+
max-width: 100%;
4457
`;
4558

4659
const LabelContainer = styled.div`
@@ -82,13 +95,13 @@ const OptionCard: React.FC<IOptionCard> = ({
8295
return (
8396
<StyledCard ref={ref} hover {...props}>
8497
<TopContainer>
85-
<div>
86-
<small className="block">{text}</small>
98+
<TextContainer>
99+
<BlockLabel>{text}</BlockLabel>
87100
<WinnerLabel winner={winner ? true : false}>
88101
<Gavel />
89102
Jury decision - {winner ? "Winner" : "Loser"}
90103
</WinnerLabel>
91-
</div>
104+
</TextContainer>
92105
{canBeSelected && <StyledRadio label="" checked={selected} />}
93106
</TopContainer>
94107
<LabelContainer>

web/src/pages/Cases/CaseDetails/Voting/VotingHistory.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ const StyledTitle = styled.h1`
4545
margin-bottom: 0;
4646
`;
4747

48+
const StyledReactMarkDown = styled(ReactMarkdown)`
49+
max-width: inherit;
50+
word-wrap: break-word;
51+
`;
52+
4853
const VotingHistory: React.FC<{ arbitrable?: `0x${string}`; isQuestion: boolean }> = ({ arbitrable, isQuestion }) => {
4954
const { id } = useParams();
5055
const { data: votingHistory } = useVotingHistory(id);
@@ -79,9 +84,9 @@ const VotingHistory: React.FC<{ arbitrable?: `0x${string}`; isQuestion: boolean
7984
{isQuestion && (
8085
<>
8186
{disputeDetails.question ? (
82-
<ReactMarkdown>{disputeDetails.question}</ReactMarkdown>
87+
<StyledReactMarkDown>{disputeDetails.question}</StyledReactMarkDown>
8388
) : (
84-
<ReactMarkdown>{isError ? RPC_ERROR : INVALID_DISPUTE_DATA_ERROR}</ReactMarkdown>
89+
<StyledReactMarkDown>{isError ? RPC_ERROR : INVALID_DISPUTE_DATA_ERROR}</StyledReactMarkDown>
8590
)}
8691
</>
8792
)}

0 commit comments

Comments
 (0)