Skip to content

fix(web): prevent long text overflow #1632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 28, 2024
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
5 changes: 5 additions & 0 deletions web/src/components/DisputePreview/Alias.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ const AliasContainer = styled.div`
display: flex;
gap: 8px;
align-items: center;
max-width: 100%;
`;

const TextContainer = styled.div`
display: flex;
flex-wrap: wrap;
max-width: 100%;
> label {
color: ${({ theme }) => theme.primaryText};
font-size: 14px;
word-wrap: break-word;
max-width: 100%;
}
`;

Expand Down
5 changes: 5 additions & 0 deletions web/src/components/DisputePreview/DisputeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import AliasDisplay from "./Alias";

const StyledH1 = styled.h1`
margin: 0;
word-wrap: break-word;
`;

const QuestionAndDescription = styled.div`
display: flex;
flex-direction: column;
word-wrap: break-word;
div:first-child p:first-of-type {
font-size: 16px;
font-weight: 600;
Expand All @@ -47,6 +49,9 @@ const Answer = styled.div`
display: flex;
flex-wrap: wrap;
gap: ${responsiveSize(2, 8)};
> label {
max-width: 100%;
}
`;

const AliasesContainer = styled.div`
Expand Down
15 changes: 13 additions & 2 deletions web/src/components/DisputeView/DisputeInfo/DisputeInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ const RestOfFieldsContainer = styled.div<{ isOverview?: boolean }>`
`};
`;

const StyledField = styled(Field)`
max-width: 100%;
label {
&.value {
margin-left: 8px;
overflow: hidden;
text-overflow: ellipsis;
}
}
`;

type IDisputeInfoCard = { fieldItems: FieldItem[] } & IDisputeInfo;

const DisputeInfoCard: React.FC<IDisputeInfoCard> = ({
Expand All @@ -75,12 +86,12 @@ const DisputeInfoCard: React.FC<IDisputeInfoCard> = ({
<Container>
{court && courtId && isOverview && (
<CourtBranchFieldContainer>
<Field icon={LawBalanceIcon} name="Court Branch" value={courtBranchValue} {...{ isOverview }} />
<StyledField icon={LawBalanceIcon} name="Court Branch" value={courtBranchValue} {...{ isOverview }} />
</CourtBranchFieldContainer>
)}
<RestOfFieldsContainer {...{ isOverview }}>
{fieldItems.map((item) =>
item.display ? <Field key={item.name} {...(item as IField)} {...{ isOverview }} /> : null
item.display ? <StyledField key={item.name} {...(item as IField)} {...{ isOverview }} /> : null
)}
</RestOfFieldsContainer>
{showLabels ? <CardLabel disputeId={disputeID} round={round - 1} /> : null}
Expand Down
30 changes: 24 additions & 6 deletions web/src/components/DisputeView/DisputeInfo/DisputeInfoList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import React from "react";
import React, { useMemo } from "react";
import styled from "styled-components";

import { responsiveSize } from "styles/responsiveSize";

import Field, { IField } from "components/Field";

import CardLabel from "../CardLabels";

import { FieldItem, IDisputeInfo } from ".";

const Container = styled.div<{ isLabel?: boolean }>`
Expand All @@ -29,15 +33,29 @@ const RestOfFieldsContainer = styled.div`
const StyledField = styled(Field)<{ style?: string }>`
${({ style }) => style ?? ""}
`;

const truncateText = (text: string, limit: number) => {
if (text && text.length > limit) {
return text.substring(0, limit) + "...";
}
return text;
};

type IDisputeInfoList = { fieldItems: FieldItem[] } & IDisputeInfo;
const DisputeInfoList: React.FC<IDisputeInfoList> = ({ fieldItems, showLabels, disputeID, round }) => {
const FieldItems = useMemo(
() =>
fieldItems.map((item) =>
item.display ? (
<StyledField key={item.name} {...(item as IField)} value={truncateText(item.value, 20)} displayAsList />
) : null
),
[fieldItems]
);

return (
<Container isLabel={showLabels}>
<RestOfFieldsContainer>
{fieldItems.map((item) =>
item.display ? <StyledField key={item.name} {...(item as IField)} displayAsList /> : null
)}
</RestOfFieldsContainer>
<RestOfFieldsContainer>{FieldItems}</RestOfFieldsContainer>
{showLabels ? <CardLabel disputeId={disputeID} round={round - 1} isList /> : null}
</Container>
);
Expand Down
1 change: 1 addition & 0 deletions web/src/components/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const FieldContainer = styled.div<FieldContainerProps>`
fill: ${({ theme }) => theme.secondaryPurple};
margin-right: 8px;
width: 14px;
flex-shrink: 0;
}

${({ isList }) =>
Expand Down
25 changes: 19 additions & 6 deletions web/src/pages/Cases/CaseDetails/Appeal/OptionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,22 @@ const TopContainer = styled.div`
display: flex;
justify-content: space-between;
height: 50%;
.block {
display: block;
}
`;

const TextContainer = styled.div`
display: flex;
flex-direction: column;
flex-grow: 1;
min-width: 0;
`;

const BlockLabel = styled.label`
display: block;
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 100%;
`;

const LabelContainer = styled.div`
Expand Down Expand Up @@ -82,13 +95,13 @@ const OptionCard: React.FC<IOptionCard> = ({
return (
<StyledCard ref={ref} hover {...props}>
<TopContainer>
<div>
<small className="block">{text}</small>
<TextContainer>
<BlockLabel>{text}</BlockLabel>
<WinnerLabel winner={winner ? true : false}>
<Gavel />
Jury decision - {winner ? "Winner" : "Loser"}
</WinnerLabel>
</div>
</TextContainer>
{canBeSelected && <StyledRadio label="" checked={selected} />}
</TopContainer>
<LabelContainer>
Expand Down
9 changes: 7 additions & 2 deletions web/src/pages/Cases/CaseDetails/Voting/VotingHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const StyledTitle = styled.h1`
margin-bottom: 0;
`;

const StyledReactMarkDown = styled(ReactMarkdown)`
max-width: inherit;
word-wrap: break-word;
`;

const VotingHistory: React.FC<{ arbitrable?: `0x${string}`; isQuestion: boolean }> = ({ arbitrable, isQuestion }) => {
const { id } = useParams();
const { data: votingHistory } = useVotingHistory(id);
Expand Down Expand Up @@ -79,9 +84,9 @@ const VotingHistory: React.FC<{ arbitrable?: `0x${string}`; isQuestion: boolean
{isQuestion && (
<>
{disputeDetails.question ? (
<ReactMarkdown>{disputeDetails.question}</ReactMarkdown>
<StyledReactMarkDown>{disputeDetails.question}</StyledReactMarkDown>
) : (
<ReactMarkdown>{isError ? RPC_ERROR : INVALID_DISPUTE_DATA_ERROR}</ReactMarkdown>
<StyledReactMarkDown>{isError ? RPC_ERROR : INVALID_DISPUTE_DATA_ERROR}</StyledReactMarkDown>
)}
</>
)}
Expand Down
Loading