|
3 | 3 | * See the LICENSE file in the repository root folder for details. |
4 | 4 | */ |
5 | 5 |
|
6 | | -import { Box, Link } from '@mui/material'; |
7 | | -import Typography from '@mui/material/Typography'; |
| 6 | +import { Box, Link, Stack, Typography } from '@mui/material'; |
8 | 7 | import { ImplementedChange } from 'shared'; |
9 | | -import { fullNamePipe, datePipe } from '../utils/pipes'; |
| 8 | +import { datePipe, fullNamePipe } from '../utils/pipes'; |
10 | 9 | import { Link as RouterLink } from 'react-router-dom'; |
11 | 10 | import { routes } from '../utils/routes'; |
12 | | -import DynamicTooltip from './DynamicTooltip'; |
13 | 11 |
|
14 | 12 | interface ChangesListProps { |
15 | 13 | changes: ImplementedChange[]; |
16 | 14 | } |
17 | 15 |
|
| 16 | +const URL_REGEX = /(https?:\/\/\S+)/g; |
| 17 | + |
| 18 | +const renderDetailWithLinks = (detail: string) => |
| 19 | + detail.split(URL_REGEX).map((segment, idx) => { |
| 20 | + if (!/^https?:\/\//.test(segment)) return segment; |
| 21 | + const trailing = segment.match(/[.,;:!?)\]"'`]+$/)?.[0] ?? ''; |
| 22 | + const url = trailing ? segment.slice(0, -trailing.length) : segment; |
| 23 | + return ( |
| 24 | + <span key={idx}> |
| 25 | + <Link href={url} target="_blank" rel="noopener noreferrer" underline="hover"> |
| 26 | + {url} |
| 27 | + </Link> |
| 28 | + {trailing} |
| 29 | + </span> |
| 30 | + ); |
| 31 | + }); |
| 32 | + |
18 | 33 | const ChangesList: React.FC<ChangesListProps> = ({ changes }) => { |
19 | 34 | return ( |
20 | | - <Box> |
21 | | - <ul style={{ paddingLeft: '5px', marginBottom: '0em', listStyleType: 'none' }}> |
22 | | - {changes.map((ic, idx) => ( |
23 | | - <li key={idx}> |
24 | | - <Box style={{ display: 'flex', flexDirection: 'row' }}> |
25 | | - <div style={{ marginRight: '4px' }}> |
26 | | - [ |
27 | | - <Link component={RouterLink} to={`${routes.CHANGE_REQUESTS}/${ic.changeRequestId}`}> |
28 | | - #{ic.changeRequestIdentifier} |
29 | | - </Link> |
30 | | - ] |
31 | | - </div> |
32 | | - <DynamicTooltip title={`${fullNamePipe(ic.implementer)} - ${datePipe(ic.dateImplemented)}`}> |
33 | | - <Typography component="span">{ic.detail}</Typography> |
34 | | - </DynamicTooltip> |
35 | | - </Box> |
36 | | - </li> |
37 | | - ))} |
38 | | - </ul> |
39 | | - </Box> |
| 35 | + <Stack component="ul" spacing={0.75} sx={{ p: 0, m: 0, listStyleType: 'none' }}> |
| 36 | + {changes.map((ic, idx) => ( |
| 37 | + <Box |
| 38 | + component="li" |
| 39 | + key={idx} |
| 40 | + sx={{ |
| 41 | + display: 'flex', |
| 42 | + flexDirection: { xs: 'column', sm: 'row' }, |
| 43 | + alignItems: { sm: 'baseline' }, |
| 44 | + gap: 1, |
| 45 | + px: 1.25, |
| 46 | + py: 0.75, |
| 47 | + borderRadius: 1, |
| 48 | + backgroundColor: (theme) => theme.palette.action.hover |
| 49 | + }} |
| 50 | + > |
| 51 | + <Link |
| 52 | + component={RouterLink} |
| 53 | + to={`${routes.CHANGE_REQUESTS}/${ic.changeRequestId}`} |
| 54 | + underline="hover" |
| 55 | + sx={{ fontWeight: 600, flexShrink: 0 }} |
| 56 | + > |
| 57 | + #{ic.changeRequestIdentifier} |
| 58 | + </Link> |
| 59 | + <Typography component="span" sx={{ wordBreak: 'break-word' }}> |
| 60 | + {renderDetailWithLinks(ic.detail)} |
| 61 | + <Typography component="span" sx={{ color: 'text.secondary', ml: 0.75 }}> |
| 62 | + — {fullNamePipe(ic.implementer)} |
| 63 | + </Typography> |
| 64 | + </Typography> |
| 65 | + <Typography variant="caption" sx={{ color: 'text.secondary', whiteSpace: 'nowrap', flexShrink: 0, ml: 'auto' }}> |
| 66 | + {datePipe(ic.dateImplemented)} |
| 67 | + </Typography> |
| 68 | + </Box> |
| 69 | + ))} |
| 70 | + </Stack> |
40 | 71 | ); |
41 | 72 | }; |
42 | 73 |
|
|
0 commit comments