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 Edit #1196

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions cypress/e2e/notes-100/comment-edit.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import '@percy/cypress'
import {
homepageSetup,
returningUserVisitsHomepageWaitForModel,
auth0Login,
} from '../../support/utils'

/** {@link https://github.com/bldrs-ai/Share/issues/1186} */
describe('Notes 100: Comment edit', () => {
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('Comment switches to edit mode', () => {
auth0Login()
cy.get(`[data-testid="list-notes"] > :nth-child(3)
> [data-testid="note-card"] > .MuiCardActions-root > .MuiBox-root > [data-testid="editComment"]`).click()
cy.get('[data-testid="Save"]')
cy.percySnapshot()
})
it('Comment displays updated body', () => {
auth0Login()
cy.get(`[data-testid="list-notes"] > :nth-child(3)
> [data-testid="note-card"] > .MuiCardActions-root > .MuiBox-root > [data-testid="editComment"]`).click()
cy.get('[placeholder="Note body"]').click().type(' updated body')
cy.get('[data-testid="Save"]').click()
cy.percySnapshot()
})
})
})
})
29 changes: 18 additions & 11 deletions src/Components/Notes/NoteCard.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import React, {ReactElement, useState, useEffect} from 'react'
import Avatar from '@mui/material/Avatar'
import Card from '@mui/material/Card'
Expand All @@ -9,6 +10,7 @@ import {
updateIssue,
// TODO(pablo): deleteComment as deleteCommentGitHub,
} from '../../net/github/Issues'
import {updateComment} from '../../net/github/Comments'
import useStore from '../../store/useStore'
import {assertDefined} from '../../utils/assert'
import {getHashParamsFromHashStr, setHashParams} from '../../utils/location'
Expand Down Expand Up @@ -71,7 +73,6 @@ export default function NoteCard({
const setSnackMessage = useStore((state) => state.setSnackMessage)
const [showCreateComment, setShowCreateComment] = useState(false)


const [editMode, setEditMode] = useState(false)
const [editBody, setEditBody] = useState(body)

Expand All @@ -96,14 +97,12 @@ export default function NoteCard({
setEditBody(body)
}, [selectedNoteId, body])


useEffect(() => {
if (selected && firstCamera) {
setCameraFromParams(firstCamera, cameraControls)
}
}, [selected, firstCamera, cameraControls])


/** Selecting a card move the notes to the replies/comments thread. */
function selectCard() {
let selectedNote = null
Expand All @@ -119,7 +118,6 @@ export default function NoteCard({
setHashParams(window.location, HASH_PREFIX_NOTES, {id: id})
}


/** Moves the camera to the position specified in the url attached to the issue/comment */
function showCameraView() {
setCameraFromParams(firstCamera, cameraControls)
Expand All @@ -135,7 +133,6 @@ export default function NoteCard({
setSnackMessage({text: 'The url path is copied to the clipboard', autoDismiss: true})
}


/**
* Closes the issue. TODO(pablo): this isn't a delete
*
Expand All @@ -150,7 +147,6 @@ export default function NoteCard({
return res
}


/**
* Delete comment from repo and remove from UI
*
Expand All @@ -169,16 +165,26 @@ export default function NoteCard({
setComments(newComments)
} */


/** Update issue on GH, set read-only */
async function submitUpdate() {
async function updateIssueGithub() {
const res = await updateIssue(repository, noteNumber, title, editBody, accessToken)
const editedNote = notes.find((note) => note.id === id)
editedNote.body = res.data.body
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix this? #1201

Copy link
Member Author

@OlegMoshkovich OlegMoshkovich Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is related to the issues, i will do it in a separate PR.
Will keep this PR on comments

setNotes(notes)
setEditMode(false)
}

/**
* Update comment in github
*
* @param {number} commentId
*/
async function updateCommentGithub(commentId) {
const updatedComment = await updateComment(repository, commentId, editBody, accessToken)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix this? #1201

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes WIP

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit more involved.
It was captured in a separate ticket, so I will take care of it in s separate PR.

console.log('updated comment', updatedComment)
setEditMode(false)
}


return (
<Card elevation={1} data-testid='note-card'>
Expand All @@ -203,7 +209,7 @@ export default function NoteCard({
{isNote && !editMode && !selected &&
<NoteBody selectCard={selectCard} markdownContent={editBody}/>}
{selected && !editMode && <NoteContent markdownContent={editBody}/>}
{!isNote && <NoteContent markdownContent={editBody}/>}
{!isNote && !editMode && <NoteContent markdownContent={editBody}/>}
{editMode &&
<NoteBodyEdit
handleTextUpdate={(event) => setEditBody(event.target.value)}
Expand All @@ -226,8 +232,9 @@ export default function NoteCard({
onClickShare={shareIssue}
selectCard={selectCard}
selected={selected}
submitUpdate={submitUpdate}
synched={synched}
setEditMode={setEditMode}
submitNoteUpdate={updateIssueGithub}
submitCommentUpdate={updateCommentGithub}
username={username}
/>
</Card>
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Notes/NoteCardCreate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ export default function NoteCardCreate({
justifyContent='flex-end'
alignContent='flex-end'
direction='row'
sx={{width: '100%'}}
sx={{width: '100%', padding: '0 0.5em'}}
>
{isNote ?
{isNote ?
<TooltipIconButton
title='Submit'
onClick={createNote}
Expand Down
Loading
Loading