Skip to content

Commit

Permalink
Merge pull request #81 from IntersectMBO/pre-prod
Browse files Browse the repository at this point in the history
From Pre prod to Main
  • Loading branch information
nebojsact authored Jan 28, 2025
2 parents fea539f + 445053e commit f0af2e4
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 91 deletions.
5 changes: 5 additions & 0 deletions pdf-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

As a minor extension, we also keep a semantic version for the `UNRELEASED`
changes.

## [v0.5.9](https://www.npmjs.com/package/@intersect.mbo/pdf-ui/v/0.5.9) 2025-01-28
### Fixed
- Added "Read More" on proposal page if Character Count is bigger den 500 [Issue #2649](https://github.com/IntersectMBO/govtool/issues/2649)

## [v0.5.8](https://www.npmjs.com/package/@intersect.mbo/pdf-ui/v/0.5.8) 2025-01-27
### Added -
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pdf-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pdf-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@intersect.mbo/pdf-ui",
"version": "0.5.8",
"version": "0.5.9",
"description": "Proposal discussion ui",
"main": "./src/index.js",
"exports": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,19 @@ const SingleGovernanceAction = ({ id }) => {
const handleShareClick = (event) => {
setShareAnchorEl(event.currentTarget);
};

// Read More / Read Less logic
const [showFullText, setShowFullText] = useState(false);
const [truncatedText, setTruncatedText] = useState('');
const [totalCharLength, setTotalCharLength] = useState(0);
const [AbstractMarkdownText, setAbstractMarkdownText] = useState('');
const maxLength = 500;
useEffect(() => {
if (maxLength && AbstractMarkdownText.length > maxLength) {
setTruncatedText(AbstractMarkdownText.slice(0, maxLength) + '...');
} else {
setTruncatedText(AbstractMarkdownText);
}
}, [AbstractMarkdownText, maxLength]);
const handleShareClose = () => {
setShareAnchorEl(null);
};
Expand Down Expand Up @@ -189,6 +201,12 @@ const SingleGovernanceAction = ({ id }) => {
return navigate('/proposal_discussion');
}
setProposal(response);

if(response?.attributes?.content?.attributes?.prop_abstract.length + response?.attributes?.content?.attributes?.prop_motivation.length + response?.attributes?.content?.attributes?.prop_rationale.length > 500)
{
setTotalCharLength(response?.attributes?.content?.attributes?.prop_abstract.length + response?.attributes?.content?.attributes?.prop_motivation.length + response?.attributes?.content?.attributes?.prop_rationale.length);
setAbstractMarkdownText(response?.attributes?.content?.attributes?.prop_abstract);
}
} catch (error) {
if (
error?.response?.data?.error?.details ===
Expand Down Expand Up @@ -1029,96 +1047,111 @@ const SingleGovernanceAction = ({ id }) => {
>
Abstract
</Typography>
<ReactMarkdown
components={{
p(props) {
const { children } = props;
return (
<Typography
variant='body2'
data-testid='abstract-content'
style={{
wordWrap:
'break-word',
}}
>
{children}
</Typography>
);
},
}}
>
{proposal?.attributes?.content
?.attributes?.prop_abstract || ''}
</ReactMarkdown>
</Box>
<Box mt={4}>
<Typography
variant='caption'
sx={{
color: (theme) =>
theme?.palette?.text?.grey,
}}
>
Motivation
</Typography>
<ReactMarkdown
components={{
p(props) {
const { children } = props;
return (
<Typography
variant='body2'
data-testid='motivation-content'
style={{
wordWrap:
'break-word',
}}
>
{children}
</Typography>
);
},
}}
>
{proposal?.attributes?.content
?.attributes?.prop_motivation || ''}
</ReactMarkdown>
</Box>
<Box mt={4}>
<Typography
variant='caption'
sx={{
color: (theme) =>
theme?.palette?.text?.grey,
}}
>
Rationale
</Typography>
<ReactMarkdown
components={{
p(props) {
const { children } = props;
return (
<Typography
variant='body2'
data-testid='rationale-content'
style={{
wordWrap:
'break-word',
}}
>
{children}
</Typography>
);
},
}}
>
{proposal?.attributes?.content
?.attributes?.prop_rationale || ''}
<ReactMarkdown>
{showFullText || !maxLength ? AbstractMarkdownText : truncatedText}


</ReactMarkdown>
{!showFullText && maxLength && totalCharLength > maxLength && (
<Button
variant="text"
onClick={() => setShowFullText(!showFullText)}
sx={{
textTransform: 'none',
padding: '0',
marginTop: '8px',
color: 'primary.main',
fontWeight: 'bold',
'&:hover': {
backgroundColor: 'transparent',
},
}}
>
{showFullText ? 'Read less' : 'Read more'}
</Button>)}
</Box>

{showFullText && (
<>
<Box mt={4}>
<Typography
variant='caption'
sx={{
color: (theme) => theme?.palette?.text?.grey,
}}
>
Motivation
</Typography>
<ReactMarkdown
components={{
p(props) {
const { children } = props;
return (
<Typography
variant='body2'
data-testid='motivation-content'
style={{
wordWrap: 'break-word',
}}
>
{children}
</Typography>
);
},
}}
>
{proposal?.attributes?.content
?.attributes?.prop_motivation || ''}
</ReactMarkdown>
</Box>
<Box mt={4}>
<Typography
variant='caption'
sx={{
color: (theme) => theme?.palette?.text?.grey,
}}
>
Rationale
</Typography>
<ReactMarkdown
components={{
p(props) {
const { children } = props;
return (
<Typography
variant='body2'
data-testid='rationale-content'
style={{
wordWrap: 'break-word',
}}
>
{children}
</Typography>
);
},
}}
>
{proposal?.attributes?.content
?.attributes?.prop_rationale || ''}
</ReactMarkdown>
</Box>
<Button
variant="text"
onClick={() => setShowFullText(!showFullText)}
sx={{
textTransform: 'none',
padding: '0',
marginTop: '8px',
color: 'primary.main',
fontWeight: 'bold',
'&:hover': {
backgroundColor: 'transparent',
},
}}
>
{showFullText ? 'Read less' : 'Read more'}
</Button>
</>
)}
{proposal?.attributes?.content?.attributes
?.proposal_links?.length > 0 && (
<Box mt={4}>
Expand Down

0 comments on commit f0af2e4

Please sign in to comment.