-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add ability to delete specific tag #391
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// react global | ||
import React, { useEffect, useMemo, useRef, useState } from 'react'; | ||
|
||
import { Delete as DeleteIcon } from '@mui/icons-material'; | ||
// external | ||
import { DateTime } from 'luxon'; | ||
import { isEmpty, uniq } from 'lodash'; | ||
|
@@ -242,7 +242,29 @@ | |
: `Timestamp N/A`; | ||
return lastDate; | ||
}; | ||
|
||
const handleDeleteRepo = () => { | ||
const confirmed = window.confirm('Are you sure you want to delete this repo?'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We implemend dialogs using MUI's dialog component, not the native window API, check FilterDialog used in the ExplorePage for example. |
||
if (confirmed) { | ||
const apiUrl = `http://localhost:3000/v2/${name}/manifests/`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We declare our endpoints inside the api.js file. and send requests using axios not fetch. Check the api.js file and usage of api thought the project for examples. |
||
fetch(apiUrl, { | ||
method: 'DELETE' | ||
}) | ||
.then((response) => { | ||
if (response.status === 202) { | ||
// Repo deleted successfully | ||
console.log('Repo deleted successfully'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't leave console logs inside code after finishing implementation |
||
// You may want to navigate to another page or perform other actions as needed | ||
} else { | ||
console.log('Failed to delete the repo'); | ||
// Handle the failure case here | ||
} | ||
}) | ||
.catch((error) => { | ||
console.error('An error occurred:', error); | ||
// Handle any network or request error | ||
}); | ||
} | ||
}; | ||
return ( | ||
<> | ||
{isLoading ? ( | ||
|
@@ -285,6 +307,11 @@ | |
)} | ||
</IconButton> | ||
)} | ||
{isAuthenticated() && ( | ||
<IconButton component="span" onClick={handleDeleteRepo} data-testid="delete-repo-button"> | ||
<DeleteIcon data-testid="delete-icon" /> | ||
</IconButton> | ||
)} | ||
</Stack> | ||
<Typography gutterBottom className={classes.repoTitle}> | ||
{repoDetailData?.title || 'Title not available'} | ||
|
@@ -317,7 +344,7 @@ | |
<Grid item xs={12} md={8} className={classes.tags}> | ||
<Card className={classes.cardRoot}> | ||
<CardContent className={classes.tagsContent}> | ||
<Tags tags={tags} /> | ||
<Tags tags={tags} repoName={repoDetailData?.name} /> | ||
</CardContent> | ||
</Card> | ||
</Grid> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
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, Tooltip, Typography, Divider, IconButton } 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 { KeyboardArrowDown, KeyboardArrowRight, Delete as DeleteIcon } from '@mui/icons-material'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
card: { | ||
|
@@ -79,7 +79,7 @@ | |
|
||
export default function TagCard(props) { | ||
const { repoName, tag, lastUpdated, vendor, manifests } = props; | ||
|
||
console.log(props); | ||
const [open, setOpen] = useState(false); | ||
const classes = useStyles(); | ||
|
||
|
@@ -99,14 +99,53 @@ | |
return ( | ||
<Card className={classes.card} raised> | ||
<CardContent className={classes.content}> | ||
<Typography variant="body1" align="left" className={classes.tagHeading}> | ||
Tag | ||
</Typography> | ||
<div style={{ display: 'flex', alignItems: 'center' }}> | ||
<Typography variant="body1" align="left" className={classes.tagHeading}> | ||
Tag | ||
</Typography> | ||
<IconButton | ||
color="primary" | ||
style={{ marginLeft: 'auto' }} | ||
onClick={() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, if your function is longer than 1 line, you want to declare it outside the JSX. Also, same thing about using the window.confirm api |
||
const confirmed = window.confirm('Are you sure you want to perform this action?'); | ||
if (confirmed) { | ||
console.log('Button clicked and confirmed!'); | ||
console.log(props); | ||
console.log('REPONAME: ', repoName); | ||
const apiUrl = `http://localhost:3000/v2/${repoName}/manifests/${tag}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. api.js for backend requests |
||
fetch(apiUrl, { | ||
method: 'DELETE' | ||
}) | ||
.then((response) => { | ||
if (response.status === 202) { | ||
// Tag deleted successfully | ||
console.log('Tag deleted successfully'); | ||
// You may want to refresh the UI or perform other actions as needed | ||
} else { | ||
console.log('Failed to delete the tag'); | ||
// Handle the failure case here | ||
} | ||
}) | ||
.catch((error) => { | ||
console.error('An error occurred:', error); | ||
// Handle any network or request error | ||
}); | ||
window.location.reload(); | ||
} else { | ||
// User canceled the action | ||
console.log('Button click canceled.'); | ||
} | ||
console.log('Button clicked!'); | ||
//should hold repo name and tag [line 119 and 120] | ||
}} | ||
> | ||
<DeleteIcon /> | ||
</IconButton> | ||
</div> | ||
<Typography variant="body1" align="left" className={classes.tagName} onClick={() => goToTags()}> | ||
{repoName && `${repoName}:`} | ||
{tag} | ||
</Typography> | ||
|
||
<Stack sx={{ display: 'inline' }} direction="row" spacing={0.5}> | ||
<Typography variant="caption" sx={{ fontWeight: '400', fontSize: '0.8125rem' }}> | ||
Created | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
const hostConfig = { | ||
auto: true, | ||
default: 'http://localhost:5000' | ||
auto: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't push this, keep only on local |
||
default: 'http://localhost:8080' | ||
}; | ||
|
||
const host = (manualHost = null) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what this is but it definitely shouldn't be here |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { createProxyMiddleware } = require('http-proxy-middleware'); | ||
|
||
module.exports = function(app) { | ||
app.use( | ||
'/v2', | ||
createProxyMiddleware({ | ||
target: 'http://localhost:8080', | ||
changeOrigin: true, | ||
}) | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't add or change packages unless they are required for the implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just reverted it back, didn't realize i changed it sorry!!