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 all 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
41 changes: 41 additions & 0 deletions cypress/e2e/notes-100/comment-edit.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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()
auth0Login()
})
it('Edit button should be visible', () => {
cy.get(`[data-testid="list-notes"] > :nth-child(3)
> [data-testid="note-card"] > .MuiCardActions-root > .MuiBox-root > [data-testid="editComment"]`)
cy.percySnapshot()
})
it('Comment switches to edit mode', () => {
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', () => {
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()
// eslint-disable-next-line cypress/no-unnecessary-waiting, no-magic-numbers
cy.wait(1000)
cy.percySnapshot()
})
})
})
})
1 change: 1 addition & 0 deletions src/Components/Notes/NoteBodyEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function EditCardBody({handleTextUpdate, value = ''}) {
alignItems="flex-end"
>
<InputBase
variant='edit'
value={value}
onChange={handleTextUpdate}
fullWidth
Expand Down
27 changes: 16 additions & 11 deletions src/Components/Notes/NoteCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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 +72,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 +96,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 +117,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 +132,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 +146,6 @@ export default function NoteCard({
return res
}


/**
* Delete comment from repo and remove from UI
*
Expand All @@ -169,16 +164,25 @@ 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) {
await updateComment(repository, commentId, editBody, accessToken)
setEditMode(false)
}


return (
<Card elevation={1} data-testid='note-card'>
Expand All @@ -203,7 +207,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 +230,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