Skip to content
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

Notes 100: Comment Delete #1191

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
27 changes: 27 additions & 0 deletions cypress/e2e/notes-100/comment-delete.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import '@percy/cypress'
import {
homepageSetup,
returningUserVisitsHomepageWaitForModel,
auth0Login,
} from '../../support/utils'

/** {@link https://github.com/bldrs-ai/Share/issues/1187} */
describe('Notes 100: Comment delete', () => {
beforeEach(homepageSetup)
context('Returning user visits homepage', () => {
beforeEach(returningUserVisitsHomepageWaitForModel)
context('Open Notes > first note', () => {
beforeEach(() => {
cy.get('[data-testid="control-button-notes"]').click()
cy.get('[data-testid="list-notes"] :nth-child(1) > [data-testid="note-body"]').first().click()
})
it('Deleted comment disappears from the list', () => {
auth0Login()
cy.get(`[data-testid="list-notes"] > :nth-child(3)
> [data-testid="note-card"] > .MuiCardActions-root > .MuiBox-root > [data-testid="deleteComment"]`).click()
cy.get('[data-testid="list-notes"] > :nth-child(3) > [data-testid="note-card"]').should('not.contain', 'testComment_1')
cy.percySnapshot()
})
})
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bldrs",
"version": "1.0.1073",
"version": "1.0.1072",
"main": "src/index.jsx",
"license": "AGPL-3.0",
"homepage": "https://github.com/bldrs-ai/Share",
Expand Down
24 changes: 11 additions & 13 deletions src/Components/Notes/NoteCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import {useAuth0} from '../../Auth0/Auth0Proxy'
import {
closeIssue,
updateIssue,
// TODO(pablo): deleteComment as deleteCommentGitHub,
} from '../../net/github/Issues'
import {
deleteComment,
} from '../../net/github/Comments'
import useStore from '../../store/useStore'
import {assertDefined} from '../../utils/assert'
import {getHashParamsFromHashStr, setHashParams} from '../../utils/location'
Expand Down Expand Up @@ -61,9 +63,8 @@ export default function NoteCard({
const notes = useStore((state) => state.notes)
const repository = useStore((state) => state.repository)
const selectedNoteId = useStore((state) => state.selectedNoteId)
// TODO(pablo)
// const comments = useStore((state) => state.comments)
// const setComments = useStore((state) => state.setComments)
const comments = useStore((state) => state.comments)
const setComments = useStore((state) => state.setComments)
const setNotes = useStore((state) => state.setNotes)
const setSelectedNoteId = useStore((state) => state.setSelectedNoteId)
const setSelectedNoteIndex = useStore((state) => state.setSelectedNoteIndex)
Expand Down Expand Up @@ -158,16 +159,12 @@ export default function NoteCard({
* @param {string} accessToken
* @param {number} commentId
*/
// TODO(pablo)
/* async function deleteComment(commentId) {
// TODO(pablo): handle response
await deleteCommentGitHub(repository, commentId, accessToken)
const newComments = comments.map((comment) => ({
...comment,
synched: (comment.id !== commentId) && comment.synched,
}))
async function deleteCommentGithub(commentId) {
// eslint-disable-next-line no-unused-vars
const res = await deleteComment(repository, commentId, accessToken)
const newComments = comments.filter((comment) => comment.id !== commentId)
setComments(newComments)
} */
}


/** Update issue on GH, set read-only */
Expand Down Expand Up @@ -227,6 +224,7 @@ export default function NoteCard({
selectCard={selectCard}
selected={selected}
submitUpdate={submitUpdate}
deleteComment={deleteCommentGithub}
synched={synched}
username={username}
/>
Expand Down
65 changes: 38 additions & 27 deletions src/Components/Notes/NoteFooter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import AddCommentOutlinedIcon from '@mui/icons-material/AddCommentOutlined'
import CheckIcon from '@mui/icons-material/Check'
import ForumOutlinedIcon from '@mui/icons-material/ForumOutlined'
import GitHubIcon from '@mui/icons-material/GitHub'
import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline'
import PhotoCameraIcon from '@mui/icons-material/PhotoCamera'
import CameraIcon from '../../assets/icons/Camera.svg'
import PlaceMarkIcon from '../../assets/icons/PlaceMark.svg'
Expand All @@ -23,6 +24,7 @@ import ShareIcon from '../../assets/icons/Share.svg'
*/
export default function NoteFooter({
accessToken,
deleteComment,
editMode,
embeddedCameras,
id,
Expand Down Expand Up @@ -63,13 +65,14 @@ export default function NoteFooter({
'_blank')
}


return (
<CardActions>
{isNote &&
<TooltipIconButton
title='Open in Github'
size='small'
placement='bottom'
placement='top'
onClick={openGithubIssue}
icon={<GitHubIcon className='icon-share'/>}
aboutInfo={false}
Expand All @@ -80,7 +83,7 @@ export default function NoteFooter({
<TooltipIconButton
title='Show the camera view'
size='small'
placement='bottom'
placement='top'
onClick={onClickCamera}
icon={<CameraIcon className='icon-share'/>}
aboutInfo={false}
Expand All @@ -90,7 +93,7 @@ export default function NoteFooter({
<TooltipIconButton
title='Share'
size='small'
placement='bottom'
placement='top'
onClick={() => {
onClickShare()
setShareIssue(!shareIssue)
Expand All @@ -113,7 +116,7 @@ export default function NoteFooter({
<TooltipIconButton
title='Place Mark'
size='small'
placement='bottom'
placement='top'
onClick={() => {
togglePlaceMarkActive(id)
}}
Expand All @@ -130,48 +133,56 @@ export default function NoteFooter({
<TooltipIconButton
title='Take Screenshot'
size='small'
placement='bottom'
placement='top'
onClick={() => {
setScreenshotUri(viewer.takeScreenshot())
}}
icon={<PhotoCameraIcon className='icon-share'/>}
/>
}

{editMode &&
<TooltipIconButton
title='Save'
placement='left'
icon={<CheckIcon className='icon-share'/>}
onClick={() => submitUpdate(repository, accessToken, id)}
/>
}

{isNote && !selected &&
<TooltipIconButton
title='Add Comment'
size='small'
placement='bottom'
placement='top'
selected={showCreateComment}
onClick={selectCard}
icon={<AddCommentOutlinedIcon className='icon-share'/>}
/>
}

{numberOfComments > 0 && !editMode &&
<Box sx={{marginLeft: 'auto', padding: '0 0.5em'}}>
{!selected &&
<Box sx={{marginLeft: 'auto', padding: '0 0.5em'}}>
{editMode &&
<TooltipIconButton
title='Discussion'
size='small'
placement='bottom'
onClick={selectCard}
icon={<ForumOutlinedIcon className='icon-share'/>}
title='Save'
placement='top'
icon={<CheckIcon className='icon-share'/>}
onClick={() => submitUpdate(repository, accessToken, id)}
/>
}
{!selected && numberOfComments}
</Box>
}
}
{!selected && numberOfComments > 0 && !editMode &&
<>
<TooltipIconButton
title='Discussion'
size='small'
placement='top'
onClick={selectCard}
icon={<ForumOutlinedIcon className='icon-share'/>}
/>
{numberOfComments}
</>
}
{!isNote && user && username === user.nickname &&
<TooltipIconButton
title='Delete'
placement='top'
buttonTestId='deleteComment'
icon={<DeleteOutlineIcon className='icon-share'/>}
onClick={() => deleteComment(id)}
/>
}
</Box>
</CardActions>
)
}
1 change: 0 additions & 1 deletion src/Components/Notes/Notes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export default function Notes() {
const repository = useStore((state) => state.repository)
const selectedNoteId = useStore((state) => state.selectedNoteId)
const setComments = useStore((state) => state.setComments)

const [hasError, setHasError] = useState(false)

const {user} = useAuth0()
Expand Down
11 changes: 6 additions & 5 deletions src/__mocks__/api-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function githubHandlers(githubStore) {

rest.get(`${GH_BASE}/repos/:org/:repo/issues/:issueNumber/comments`, (req, res, ctx) => {
const {org, repo, issueNumber} = req.params

// TODO(oleg) replace org with cypresstester https://github.com/bldrs-ai/Share/issues/1218
if (org !== 'pablo-mayrgundter' || repo !== 'Share' || !issueNumber) {
return res(ctx.status(httpNotFound))
}
Expand Down Expand Up @@ -208,7 +208,7 @@ function githubHandlers(githubStore) {
rest.post(`${GH_BASE}/repos/:org/:repo/issues/:issueNumber/comments`, (req, res, ctx) => {
const {org, repo, issueNumber} = req.params

if (org !== 'pablo-mayrgundter' || repo !== 'Share' || !issueNumber) {
if (org !== 'cypresstester' || repo !== 'Share' || !issueNumber) {
return res(ctx.status(httpNotFound))
}
return res(
Expand All @@ -218,6 +218,7 @@ function githubHandlers(githubStore) {

rest.patch(`${GH_BASE}/repos/:org/:repo/issues/:issueNumber`, (req, res, ctx) => {
const {org, repo} = req.params
// TODO(oleg) add org cypresstester condition https://github.com/bldrs-ai/Share/issues/1218
if (org !== 'pablo-mayrgundter' || repo !== 'Share' ) {
return res(
ctx.status(httpNotFound),
Expand All @@ -233,9 +234,9 @@ function githubHandlers(githubStore) {
}),

rest.delete(`${GH_BASE}/repos/:org/:repo/issues/comments/:commentId`, (req, res, ctx) => {
const {org, repo, commentId} = req.params

if (org !== 'bldrs-ai' || repo !== 'Share' || !commentId) {
const {repo, commentId} = req.params
// TODO(oleg) add org cypresstester condition https://github.com/bldrs-ai/Share/issues/1218
if (repo !== 'Share' || !commentId) {
return res(ctx.status(httpNotFound))
}

Expand Down
4 changes: 2 additions & 2 deletions src/net/github/Comments.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const MOCK_COMMENTS = {
node_id: 'IC_kwDOFwgxOc5EPlQ3',
number: 1,
user: {
login: 'OlegMoshkovich',
login: 'cypresstester',
id: 3433607,
node_id: 'MDQ6VXNlcjM0MzM2MDY=',
avatar_url: 'https://avatars.githubusercontent.com/u/3433606?v=4',
Expand Down Expand Up @@ -56,7 +56,7 @@ export const MOCK_COMMENTS = {
number: 2,
node_id: 'IC_kwDOFwgxOc5EPlQ3',
user: {
login: 'OlegMoshkovich',
login: 'cypresstester',
id: 3433606,
node_id: 'MDQ6VXNlcjM0MzM2MDY=',
avatar_url: 'https://avatars.githubusercontent.com/u/3433606?v=4',
Expand Down
4 changes: 2 additions & 2 deletions src/net/github/Comments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ const httpCreated = 201

describe('net/github/Comments', () => {
it('successfully create comment', async () => {
const res = await createComment({orgName: 'pablo-mayrgundter', name: 'Share'}, 1, {title: 'title', body: 'body'})
const res = await createComment({orgName: 'cypresstester', name: 'Share'}, 1, {title: 'title', body: 'body'})
expect(res.status).toEqual(httpCreated)
})

it('successfully delete comment', async () => {
const res = await deleteComment({orgName: 'bldrs-ai', name: 'Share'}, 1)
const res = await deleteComment({orgName: 'cypresstester', name: 'Share'}, 1)
expect(res.status).toEqual(httpOK)
})
})
Loading