Skip to content

Commit 97b6127

Browse files
authored
Merge pull request #1268 from andypols/fix-broken-user-links
fix: broken user links
2 parents 6dc22e9 + c445266 commit 97b6127

File tree

6 files changed

+31
-24
lines changed

6 files changed

+31
-24
lines changed

src/routes.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import RepoList from './ui/views/RepoList/RepoList';
2828
import SettingsView from './ui/views/Settings/Settings';
2929

3030
import { RepoIcon } from '@primer/octicons-react';
31-
import { Group, AccountCircle, Dashboard, Settings } from '@material-ui/icons';
31+
import { AccountCircle, Dashboard, Group, Settings } from '@material-ui/icons';
3232

3333
import { Route } from './types/models';
3434

@@ -90,12 +90,10 @@ const dashboardRoutes: Route[] = [
9090
visible: true,
9191
},
9292
{
93-
path: '/admin/user/:id',
93+
path: '/user/:id',
9494
name: 'User',
9595
icon: Person,
96-
component: (props) => (
97-
<RouteGuard component={User} fullRoutePath={`/dashboard/admin/user/:id`} />
98-
),
96+
component: (props) => <RouteGuard component={User} fullRoutePath={`/dashboard/user/:id`} />,
9997
layout: '/dashboard',
10098
visible: false,
10199
},
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
import { Link } from 'react-router-dom';
3+
4+
interface UserLinkProps {
5+
username: string;
6+
children?: React.ReactNode;
7+
}
8+
9+
const UserLink: React.FC<UserLinkProps> = ({ username, children }) => {
10+
return <Link to={`/dashboard/user/${username}`}>{children || username}</Link>;
11+
};
12+
13+
export default UserLink;

src/ui/views/PushDetails/PushDetails.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Tooltip from '@material-ui/core/Tooltip';
2525
import { PushData } from '../../../types/models';
2626
import { trimPrefixRefsHeads, trimTrailingDotGit } from '../../../db/helper';
2727
import { generateEmailLink, getGitProvider } from '../../utils';
28+
import UserLink from '../../components/UserLink/UserLink';
2829

2930
const Dashboard: React.FC = () => {
3031
const { id } = useParams<{ id: string }>();
@@ -198,25 +199,21 @@ const Dashboard: React.FC = () => {
198199
) : (
199200
<>
200201
{isGitHub && (
201-
<a href={`/dashboard/user/${data.attestation.reviewer.username}`}>
202+
<UserLink username={data.attestation.reviewer.username}>
202203
<img
203204
style={{ width: '45px', borderRadius: '20px' }}
204205
src={`https://github.com/${data.attestation.reviewer.gitAccount}.png`}
205206
/>
206-
</a>
207+
</UserLink>
207208
)}
208209
<div>
209210
<p>
210211
{isGitHub && (
211-
<a href={`/dashboard/user/${data.attestation.reviewer.username}`}>
212+
<UserLink username={data.attestation.reviewer.username}>
212213
{data.attestation.reviewer.gitAccount}
213-
</a>
214+
</UserLink>
214215
)}
215-
{!isGitHub && (
216-
<a href={`/dashboard/user/${data.attestation.reviewer.username}`}>
217-
{data.attestation.reviewer.username}
218-
</a>
219-
)}{' '}
216+
{!isGitHub && <UserLink username={data.attestation.reviewer.username} />}{' '}
220217
approved this contribution
221218
</p>
222219
</div>

src/ui/views/PushDetails/components/AttestationView.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { withStyles } from '@material-ui/core/styles';
1212
import { green } from '@material-ui/core/colors';
1313
import { setURLShortenerData } from '../../../services/config';
1414
import { AttestationViewProps } from '../attestation.types';
15+
import UserLink from '../../../components/UserLink/UserLink';
1516

1617
const StyledFormControlLabel = withStyles({
1718
root: {
@@ -70,17 +71,15 @@ const AttestationView: React.FC<AttestationViewProps> = ({ attestation, setAttes
7071
<p style={{ fontSize: '15px', paddingLeft: '34px' }}>
7172
Prior to making this code contribution publicly accessible via GitHub, this code
7273
contribution was reviewed and approved by{' '}
73-
<a href={`/dashboard/admin/user/${data.reviewer.username}`}>{data.reviewer.gitAccount}</a>
74-
. As a reviewer, it was their responsibility to confirm that open sourcing this
75-
contribution followed the requirements of the company open source contribution policy.
74+
<UserLink username={data.reviewer.username}>{data.reviewer.gitAccount}</UserLink>. As a
75+
reviewer, it was their responsibility to confirm that open sourcing this contribution
76+
followed the requirements of the company open source contribution policy.
7677
</p>
7778
</span>
7879
<DialogContent>
7980
<p>
8081
<span>
81-
<a href={`/dashboard/admin/user/${data.reviewer.username}`}>
82-
{data.reviewer.gitAccount}
83-
</a>{' '}
82+
<UserLink username={data.reviewer.username}>{data.reviewer.gitAccount}</UserLink>{' '}
8483
approved this contribution{' '}
8584
<Tooltip title={moment(data.timestamp).format('dddd, MMMM Do YYYY, h:mm:ss a')} arrow>
8685
<kbd

src/ui/views/RepoDetails/RepoDetails.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import CodeActionButton from '../../components/CustomButtons/CodeActionButton';
2323
import { trimTrailingDotGit } from '../../../db/helper';
2424
import { fetchRemoteRepositoryData } from '../../utils';
2525
import { SCMRepositoryMetadata } from '../../../types/models';
26+
import UserLink from '../../components/UserLink/UserLink';
2627
import DeleteRepoDialog from './Components/DeleteRepoDialog';
2728

2829
interface RepoData {
@@ -202,7 +203,7 @@ const RepoDetails: React.FC = () => {
202203
{data.users.canAuthorise.map((row) => (
203204
<TableRow key={row}>
204205
<TableCell align='left'>
205-
<a href={`/dashboard/user/${row}`}>{row}</a>
206+
<UserLink username={row} />
206207
</TableCell>
207208
{user.admin && (
208209
<TableCell align='right' component='th' scope='row'>
@@ -245,7 +246,7 @@ const RepoDetails: React.FC = () => {
245246
{data.users.canPush.map((row) => (
246247
<TableRow key={row}>
247248
<TableCell align='left'>
248-
<a href={`/dashboard/user/${row}`}>{row}</a>
249+
<UserLink username={row} />
249250
</TableCell>
250251
{user.admin && (
251252
<TableCell align='right' component='th' scope='row'>

src/ui/views/UserList/Components/UserList.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ const UserList: React.FC = () => {
3232
const itemsPerPage = 5;
3333
const [searchQuery, setSearchQuery] = useState<string>('');
3434

35-
const openUser = (username: string) =>
36-
navigate(`/dashboard/admin/user/${username}`, { replace: true });
35+
const openUser = (username: string) => navigate(`/dashboard/user/${username}`, { replace: true });
3736

3837
useEffect(() => {
3938
getUsers(setIsLoading, setData, setAuth, setErrorMessage);

0 commit comments

Comments
 (0)