Skip to content

Commit

Permalink
feat: added button to delete tag
Browse files Browse the repository at this point in the history
Signed-off-by: Petu Eusebiu <[email protected]>
  • Loading branch information
eusebiu-constantin-petu-dbk committed Dec 8, 2023
1 parent e97e04e commit 4913b78
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const endpoints = {
authConfig: `/v2/_zot/ext/mgmt`,
openidAuth: `/zot/auth/login`,
logout: `/zot/auth/logout`,
deleteImage: (name, tag) => `/v2/${name}/manifests/${tag}`,
repoList: ({ pageNumber = 1, pageSize = 15 } = {}) =>
`/v2/_zot/ext/search?query={RepoListWithNewestImage(requestedPage: {limit:${pageSize} offset:${
(pageNumber - 1) * pageSize
Expand Down
8 changes: 7 additions & 1 deletion src/components/Repo/RepoDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ const randomImage = () => {
return imageArray[randomIntFromInterval(0, 3)];
};

function useRerender() {
const [, setToggle] = useState(false);
return () => setToggle((toggle) => !toggle && console.log('yeah'));
}

function RepoDetails() {
const rerender = useRerender();
const [repoDetailData, setRepoDetailData] = useState({});
const [tags, setTags] = useState([]);
const placeholderImage = useRef(randomImage());
Expand Down Expand Up @@ -317,7 +323,7 @@ function RepoDetails() {
<Grid item xs={12} md={8} className={classes.tags}>
<Card className={classes.cardRoot}>
<CardContent className={classes.tagsContent}>
<Tags tags={tags} />
<Tags tags={tags} repoName={name} rerender={rerender} />
</CardContent>
</Card>
</Grid>
Expand Down
4 changes: 3 additions & 1 deletion src/components/Repo/Tabs/Tags.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const useStyles = makeStyles(() => ({

export default function Tags(props) {
const classes = useStyles();
const { tags } = props;
const { tags, repoName, rerender } = props;
const [tagsFilter, setTagsFilter] = useState('');
const [sortFilter, setSortFilter] = useState(tagsSortByCriteria.updateTimeDesc.value);

Expand All @@ -59,10 +59,12 @@ export default function Tags(props) {
return (
<TagCard
key={tag.tag}
repoName={repoName}
tag={tag.tag}
lastUpdated={tag.lastUpdated}
vendor={tag.vendor}
manifests={tag.manifests}
rerender={rerender}
/>
);
})
Expand Down
29 changes: 29 additions & 0 deletions src/components/Shared/ConfirmDialog.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';

// components
import { Button, Dialog, DialogTitle, DialogActions } from '@mui/material';

export default function ConfirmDialog(props) {
const { onClose, open, title, onConfirm } = props;

return (
<Dialog onClose={onClose} open={open} color="primary">
<DialogTitle> {title} </DialogTitle>
<DialogActions>
<Button variant="contained" onClick={() => onClose()} color="primary">
No
</Button>
<Button
color="primary"
variant="contained"
onClick={() => {
onConfirm();
onClose();
}}
>
Yes
</Button>
</DialogActions>
</Dialog>
);
}
48 changes: 48 additions & 0 deletions src/components/Shared/DeleteTag.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as React from 'react';
import { Button } from '@mui/material';

// utility
import { api, endpoints } from '../../api';

// components
import ConfirmDialog from 'components/Shared/ConfirmDialog';
import { host } from '../../host';

export default function DeleteTag(props) {
const { repo, tag, rerender } = props;
const [open, setOpen] = React.useState(false);

const handleClickOpen = () => {
setOpen(true);
};

const handleClose = () => {
setOpen(false);
};

const deleteTag = (repo, tag) => {
api
.delete(`${host()}${endpoints.deleteImage(repo, tag)}`)
.then(() => {
console.log('delete successfully');
rerender();
})
.catch((err) => {
console.error(err);
});
};

const onConfirm = () => {
console.log(`repo: ${repo}, tag: ${tag}`);
deleteTag(repo, tag);
};

return (
<div>
<Button variant="outlined" onClick={handleClickOpen}>
Delete tag
</Button>
<ConfirmDialog onClose={handleClose} open={open} title={`Delete ${repo}:${tag} ?`} onConfirm={onConfirm} />
</div>
);
}
20 changes: 15 additions & 5 deletions src/components/Shared/TagCard.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { useState } from 'react';
import { makeStyles } from '@mui/styles';
import { useNavigate } from 'react-router-dom';
import { Box, Card, CardContent, Collapse, Grid, Stack, Tooltip, Typography, Divider } from '@mui/material';
import { Box, Card, CardContent, Collapse, Grid, Stack, IconButton, Tooltip, Typography, Divider } from '@mui/material';
import { Markdown } from 'utilities/MarkdowntojsxWrapper';
import transform from 'utilities/transform';
import { DateTime } from 'luxon';
import { KeyboardArrowDown, KeyboardArrowRight } from '@mui/icons-material';
import DeleteIcon from '@mui/icons-material/Delete';
import DeleteTag from 'components/Shared/DeleteTag';

const useStyles = makeStyles((theme) => ({
card: {
Expand Down Expand Up @@ -78,9 +80,10 @@ const useStyles = makeStyles((theme) => ({
}));

export default function TagCard(props) {
const { repoName, tag, lastUpdated, vendor, manifests } = props;
const { repoName, tag, lastUpdated, vendor, manifests, rerender } = props;

const [open, setOpen] = useState(false);

const classes = useStyles();

const lastDate = lastUpdated
Expand All @@ -99,9 +102,16 @@ export default function TagCard(props) {
return (
<Card className={classes.card} raised>
<CardContent className={classes.content}>
<Typography variant="body1" align="left" className={classes.tagHeading}>
Tag
</Typography>
<Stack direction="row" spacing={2} justifyContent="space-between">
<Typography variant="body1" align="left" className={classes.tagHeading}>
Tag
</Typography>
<DeleteTag repo={repoName} tag={tag} rerender={rerender}>
<IconButton>
<DeleteIcon />
</IconButton>
</DeleteTag>
</Stack>
<Typography variant="body1" align="left" className={classes.tagName} onClick={() => goToTags()}>
{repoName && `${repoName}:`}
{tag}
Expand Down
2 changes: 1 addition & 1 deletion src/host.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const hostConfig = {
auto: true,
auto: false,
default: 'http://localhost:5000'
};

Expand Down

0 comments on commit 4913b78

Please sign in to comment.