Skip to content

Commit 9933950

Browse files
authored
Merge branch 'main' into esm-plugin-tests
2 parents 4664c79 + 97b6127 commit 9933950

File tree

7 files changed

+115
-29
lines changed

7 files changed

+115
-29
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
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React, { useState } from 'react';
2+
import Dialog from '@material-ui/core/Dialog';
3+
import DialogTitle from '@material-ui/core/DialogTitle';
4+
import DialogContent from '@material-ui/core/DialogContent';
5+
import { Button, DialogContentText, TextField } from '@material-ui/core';
6+
import DialogActions from '@material-ui/core/DialogActions';
7+
8+
interface ConfirmDeleteRepoProps {
9+
repoName: string;
10+
open: boolean;
11+
onClose: () => void;
12+
onConfirm: () => void;
13+
}
14+
15+
const DeleteRepoDialog: React.FC<ConfirmDeleteRepoProps> = ({
16+
repoName,
17+
open,
18+
onClose,
19+
onConfirm,
20+
}) => {
21+
const [confirmInput, setConfirmInput] = useState<string>('');
22+
23+
const handleClose = () => {
24+
setConfirmInput('');
25+
onClose();
26+
};
27+
28+
const handleConfirm = () => {
29+
setConfirmInput('');
30+
onConfirm();
31+
onClose();
32+
};
33+
34+
return (
35+
<Dialog open={open} onClose={handleClose} maxWidth='sm' fullWidth>
36+
<DialogTitle>Delete Repository</DialogTitle>
37+
<DialogContent>
38+
<DialogContentText>
39+
This action cannot be undone. This will permanently delete the <strong>{repoName}</strong>{' '}
40+
repository.
41+
</DialogContentText>
42+
<DialogContentText style={{ marginTop: '16px', marginBottom: '8px' }}>
43+
Please type <strong>{repoName}</strong> to confirm:
44+
</DialogContentText>
45+
<TextField
46+
fullWidth
47+
value={confirmInput}
48+
onChange={(e) => setConfirmInput(e.target.value)}
49+
placeholder={repoName}
50+
autoFocus
51+
/>
52+
</DialogContent>
53+
<DialogActions>
54+
<Button variant='outlined' onClick={handleClose}>
55+
Cancel
56+
</Button>
57+
<Button
58+
variant='contained'
59+
color='secondary'
60+
onClick={handleConfirm}
61+
disabled={confirmInput !== repoName}
62+
>
63+
Delete Repository
64+
</Button>
65+
</DialogActions>
66+
</Dialog>
67+
);
68+
};
69+
70+
export default DeleteRepoDialog;

src/ui/views/RepoDetails/RepoDetails.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ 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';
27+
import DeleteRepoDialog from './Components/DeleteRepoDialog';
2628

2729
interface RepoData {
2830
_id: string;
@@ -58,10 +60,11 @@ const RepoDetails: React.FC = () => {
5860
const navigate = useNavigate();
5961
const classes = useStyles();
6062
const [data, setData] = useState<RepoData | null>(null);
61-
const [, setAuth] = useState(true);
62-
const [isLoading, setIsLoading] = useState(true);
63-
const [isError, setIsError] = useState(false);
64-
const [remoteRepoData, setRemoteRepoData] = React.useState<SCMRepositoryMetadata | null>(null);
63+
const [confirmDeleteOpen, setConfirmDeleteOpen] = useState<boolean>(false);
64+
const [, setAuth] = useState<boolean>(true);
65+
const [isLoading, setIsLoading] = useState<boolean>(true);
66+
const [isError, setIsError] = useState<boolean>(false);
67+
const [remoteRepoData, setRemoteRepoData] = useState<SCMRepositoryMetadata | null>(null);
6568
const { user } = useContext<UserContextType>(UserContext);
6669
const { id: repoId } = useParams<{ id: string }>();
6770

@@ -120,7 +123,7 @@ const RepoDetails: React.FC = () => {
120123
variant='contained'
121124
color='secondary'
122125
data-testid='delete-repo-button'
123-
onClick={() => removeRepository(data._id)}
126+
onClick={() => setConfirmDeleteOpen(true)}
124127
>
125128
<Delete />
126129
</Button>
@@ -200,7 +203,7 @@ const RepoDetails: React.FC = () => {
200203
{data.users.canAuthorise.map((row) => (
201204
<TableRow key={row}>
202205
<TableCell align='left'>
203-
<a href={`/dashboard/user/${row}`}>{row}</a>
206+
<UserLink username={row} />
204207
</TableCell>
205208
{user.admin && (
206209
<TableCell align='right' component='th' scope='row'>
@@ -243,7 +246,7 @@ const RepoDetails: React.FC = () => {
243246
{data.users.canPush.map((row) => (
244247
<TableRow key={row}>
245248
<TableCell align='left'>
246-
<a href={`/dashboard/user/${row}`}>{row}</a>
249+
<UserLink username={row} />
247250
</TableCell>
248251
{user.admin && (
249252
<TableCell align='right' component='th' scope='row'>
@@ -266,6 +269,13 @@ const RepoDetails: React.FC = () => {
266269
</CardBody>
267270
</Card>
268271
</GridItem>
272+
273+
<DeleteRepoDialog
274+
repoName={data.name}
275+
open={confirmDeleteOpen}
276+
onClose={() => setConfirmDeleteOpen(false)}
277+
onConfirm={() => removeRepository(data._id)}
278+
/>
269279
</GridContainer>
270280
);
271281
};

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)