diff --git a/src/api.js b/src/api.js index 15b7f794..9bec23f4 100644 --- a/src/api.js +++ b/src/api.js @@ -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 diff --git a/src/components/Repo/RepoDetails.jsx b/src/components/Repo/RepoDetails.jsx index b3df2e9b..0365c250 100644 --- a/src/components/Repo/RepoDetails.jsx +++ b/src/components/Repo/RepoDetails.jsx @@ -197,6 +197,11 @@ function RepoDetails() { }; }, [name]); + const handleDeleteTag = (removed) => { + let newTags = tags.filter((tag) => tag.tag !== removed); + setTags(newTags); + }; + const handlePlatformChipClick = (event) => { const { textContent } = event.target; event.stopPropagation(); @@ -223,7 +228,7 @@ function RepoDetails() { const handleBookmarkClick = () => { api.put(`${host()}${endpoints.bookmarkToggle(name)}`, abortController.signal).then((response) => { - if (response.status === 200) { + if (response && response.status === 200) { setRepoDetailData((prevState) => ({ ...prevState, isBookmarked: !prevState.isBookmarked @@ -341,7 +346,7 @@ function RepoDetails() { - + diff --git a/src/components/Repo/Tabs/Tags.jsx b/src/components/Repo/Tabs/Tags.jsx index 808d55f5..71e93a5d 100644 --- a/src/components/Repo/Tabs/Tags.jsx +++ b/src/components/Repo/Tabs/Tags.jsx @@ -43,7 +43,7 @@ const useStyles = makeStyles(() => ({ export default function Tags(props) { const classes = useStyles(); - const { tags } = props; + const { tags, repoName, handleDeleteTag } = props; const [tagsFilter, setTagsFilter] = useState(''); const [sortFilter, setSortFilter] = useState(tagsSortByCriteria.updateTimeDesc.value); @@ -59,10 +59,12 @@ export default function Tags(props) { return ( ); }) diff --git a/src/components/Shared/ConfirmDialog.jsx b/src/components/Shared/ConfirmDialog.jsx new file mode 100644 index 00000000..1cb49968 --- /dev/null +++ b/src/components/Shared/ConfirmDialog.jsx @@ -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 ( + + {title} + + + + + + ); +} diff --git a/src/components/Shared/DeleteTag.jsx b/src/components/Shared/DeleteTag.jsx new file mode 100644 index 00000000..e54cddad --- /dev/null +++ b/src/components/Shared/DeleteTag.jsx @@ -0,0 +1,49 @@ +import * as React from 'react'; +import { IconButton } from '@mui/material'; +import DeleteIcon from '@mui/icons-material/Delete'; + +// 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, handleDeleteTag } = 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((response) => { + if (response && response.status == 202) { + handleDeleteTag(tag); + } + }) + .catch((err) => { + console.error(err); + }); + }; + + const onConfirm = () => { + deleteTag(repo, tag); + }; + + return ( +
+ + + + +
+ ); +} diff --git a/src/components/Shared/TagCard.jsx b/src/components/Shared/TagCard.jsx index f2eb7624..e69e02db 100644 --- a/src/components/Shared/TagCard.jsx +++ b/src/components/Shared/TagCard.jsx @@ -6,6 +6,7 @@ import { Markdown } from 'utilities/MarkdowntojsxWrapper'; import transform from 'utilities/transform'; import { DateTime } from 'luxon'; import { KeyboardArrowDown, KeyboardArrowRight } from '@mui/icons-material'; +import DeleteTag from 'components/Shared/DeleteTag'; const useStyles = makeStyles((theme) => ({ card: { @@ -78,9 +79,10 @@ const useStyles = makeStyles((theme) => ({ })); export default function TagCard(props) { - const { repoName, tag, lastUpdated, vendor, manifests } = props; + const { repoName, tag, lastUpdated, vendor, manifests, handleDeleteTag } = props; const [open, setOpen] = useState(false); + const classes = useStyles(); const lastDate = lastUpdated @@ -99,9 +101,12 @@ export default function TagCard(props) { return ( - - Tag - + + + Tag + + + goToTags()}> {repoName && `${repoName}:`} {tag} diff --git a/src/host.js b/src/host.js index 582b6ac4..18d5bf52 100644 --- a/src/host.js +++ b/src/host.js @@ -1,5 +1,5 @@ const hostConfig = { - auto: true, + auto: false, default: 'http://localhost:5000' };