Skip to content

Commit ef15d58

Browse files
committed
Merge branch 'main' of https://github.com/finos/git-proxy into 1193-consolidate-ts-types
2 parents 23fbc4e + df6406b commit ef15d58

File tree

14 files changed

+237
-66
lines changed

14 files changed

+237
-66
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 './ui/types';
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
},

src/ui/components/Pagination/Pagination.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.paginationContainer {
22
display: flex;
33
justify-content: center;
4+
align-items: center;
45
padding: 1rem;
56
margin-top: 20px;
67
gap: 10px;
@@ -17,10 +18,18 @@
1718
transition: background-color 0.3s ease;
1819
}
1920

20-
.pageButton:hover {
21+
.pageButton:hover:not(:disabled) {
2122
background-color: #e2e6ea;
2223
}
2324

25+
.pageButton:disabled {
26+
background-color: #e9ecef;
27+
color: #6c757d;
28+
border-color: #dee2e6;
29+
cursor: not-allowed;
30+
opacity: 0.6;
31+
}
32+
2433
.activeButton {
2534
background-color: #007bff;
2635
color: #fff;

src/ui/components/Pagination/Pagination.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ const Pagination: React.FC<PaginationProps> = ({
3232
Previous
3333
</button>
3434

35-
<span>
36-
Page {currentPage} of {totalPages}
37-
</span>
35+
<span>Page {totalPages === 0 ? '0 of 0' : `${currentPage} of ${totalPages}`}</span>
3836

3937
<button
4038
className='pageButton'
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 { PushActionView } from '../../types';
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/${push.attestation.reviewer.username}`}>
202+
<UserLink username={push.attestation.reviewer.username}>
202203
<img
203204
style={{ width: '45px', borderRadius: '20px' }}
204205
src={`https://github.com/${push.attestation.reviewer.gitAccount}.png`}
205206
/>
206-
</a>
207+
</UserLink>
207208
)}
208209
<div>
209210
<p>
210211
{isGitHub && (
211-
<a href={`/dashboard/user/${push.attestation.reviewer.username}`}>
212+
<UserLink username={push.attestation.reviewer.username}>
212213
{push.attestation.reviewer.gitAccount}
213-
</a>
214+
</UserLink>
214215
)}
215-
{!isGitHub && (
216-
<a href={`/dashboard/user/${push.attestation.reviewer.username}`}>
217-
{push.attestation.reviewer.username}
218-
</a>
219-
)}{' '}
216+
{!isGitHub && <UserLink username={push.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
@@ -11,6 +11,7 @@ import Checkbox from '@material-ui/core/Checkbox';
1111
import { withStyles } from '@material-ui/core/styles';
1212
import { green } from '@material-ui/core/colors';
1313
import { setURLShortenerData } from '../../../services/config';
14+
import UserLink from '../../../components/UserLink/UserLink';
1415
import { AttestationFormData } from '../../../types';
1516

1617
export interface AttestationViewProps {
@@ -76,17 +77,15 @@ const AttestationView: React.FC<AttestationViewProps> = ({ attestation, setAttes
7677
<p style={{ fontSize: '15px', paddingLeft: '34px' }}>
7778
Prior to making this code contribution publicly accessible via GitHub, this code
7879
contribution was reviewed and approved by{' '}
79-
<a href={`/dashboard/admin/user/${data.reviewer.username}`}>{data.reviewer.gitAccount}</a>
80-
. As a reviewer, it was their responsibility to confirm that open sourcing this
81-
contribution followed the requirements of the company open source contribution policy.
80+
<UserLink username={data.reviewer.username}>{data.reviewer.gitAccount}</UserLink>. As a
81+
reviewer, it was their responsibility to confirm that open sourcing this contribution
82+
followed the requirements of the company open source contribution policy.
8283
</p>
8384
</span>
8485
<DialogContent>
8586
<p>
8687
<span>
87-
<a href={`/dashboard/admin/user/${data.reviewer.username}`}>
88-
{data.reviewer.gitAccount}
89-
</a>{' '}
88+
<UserLink username={data.reviewer.username}>{data.reviewer.gitAccount}</UserLink>{' '}
9089
approved this contribution{' '}
9190
<Tooltip title={moment(data.timestamp).format('dddd, MMMM Do YYYY, h:mm:ss a')} arrow>
9291
<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: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ import { UserContext } from '../../context';
2222
import CodeActionButton from '../../components/CustomButtons/CodeActionButton';
2323
import { trimTrailingDotGit } from '../../../db/helper';
2424
import { fetchRemoteRepositoryData } from '../../utils';
25+
2526
import { RepoView, SCMRepositoryMetadata } from '../../types';
2627
import { UserContextType } from '../../context';
28+
import UserLink from '../../components/UserLink/UserLink';
29+
import DeleteRepoDialog from './Components/DeleteRepoDialog';
2730

2831
const useStyles = makeStyles((theme) => ({
2932
root: {
@@ -41,10 +44,11 @@ const RepoDetails: React.FC = () => {
4144
const navigate = useNavigate();
4245
const classes = useStyles();
4346
const [repo, setRepo] = useState<RepoView | null>(null);
44-
const [, setAuth] = useState(true);
45-
const [isLoading, setIsLoading] = useState(true);
46-
const [isError, setIsError] = useState(false);
47-
const [remoteRepoData, setRemoteRepoData] = React.useState<SCMRepositoryMetadata | null>(null);
47+
const [confirmDeleteOpen, setConfirmDeleteOpen] = useState<boolean>(false);
48+
const [, setAuth] = useState<boolean>(true);
49+
const [isLoading, setIsLoading] = useState<boolean>(true);
50+
const [isError, setIsError] = useState<boolean>(false);
51+
const [remoteRepoData, setRemoteRepoData] = useState<SCMRepositoryMetadata | null>(null);
4852
const { user } = useContext<UserContextType>(UserContext);
4953
const { id: repoId } = useParams<{ id: string }>();
5054

@@ -103,7 +107,7 @@ const RepoDetails: React.FC = () => {
103107
variant='contained'
104108
color='secondary'
105109
data-testid='delete-repo-button'
106-
onClick={() => removeRepository(repo._id!)}
110+
onClick={() => setConfirmDeleteOpen(true)}
107111
>
108112
<Delete />
109113
</Button>
@@ -183,7 +187,7 @@ const RepoDetails: React.FC = () => {
183187
{repo.users?.canAuthorise?.map((username) => (
184188
<TableRow key={username}>
185189
<TableCell align='left'>
186-
<a href={`/dashboard/user/${username}`}>{username}</a>
190+
<UserLink username={username} />
187191
</TableCell>
188192
{user.admin && (
189193
<TableCell align='right' component='th' scope='row'>
@@ -226,7 +230,7 @@ const RepoDetails: React.FC = () => {
226230
{repo.users?.canPush?.map((username) => (
227231
<TableRow key={username}>
228232
<TableCell align='left'>
229-
<a href={`/dashboard/user/${username}`}>{username}</a>
233+
<UserLink username={username} />
230234
</TableCell>
231235
{user.admin && (
232236
<TableCell align='right' component='th' scope='row'>
@@ -249,6 +253,13 @@ const RepoDetails: React.FC = () => {
249253
</CardBody>
250254
</Card>
251255
</GridItem>
256+
257+
<DeleteRepoDialog
258+
repoName={repo.name}
259+
open={confirmDeleteOpen}
260+
onClose={() => setConfirmDeleteOpen(false)}
261+
onConfirm={() => removeRepository(repo._id!)}
262+
/>
252263
</GridContainer>
253264
);
254265
};

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, setUsers, setAuth, setErrorMessage);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { PushActionPlugin } from '@finos/git-proxy/plugin';
2+
3+
// test default export (ESM syntax)
4+
export default new PushActionPlugin(async (req, action) => {
5+
console.log('Dummy plugin: ', action);
6+
return action;
7+
});

0 commit comments

Comments
 (0)