-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Feature: Collaborative Notes Pane for the Editor screen #7563
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
Open
EstoesMoises
wants to merge
29
commits into
decaporg:main
Choose a base branch
from
EstoesMoises:52-notes-pane
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,358
−9
Open
Changes from 17 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
67187bb
feat: added interface for EditorNotesPane
EstoesMoises 1aeff96
feat: crud with Redux complete for EditorNotesPane
EstoesMoises 6c9e475
feat: notes functionality connected to Test Backend
EstoesMoises cdc52aa
feat: notespane now immediately saves the note and it works with prox…
EstoesMoises e04f2f0
feat: notespane now integrated with Github backend
EstoesMoises 51abb33
feat: adding notes to test backend
EstoesMoises be1a1d6
chore: adding english locale to Note toasts
EstoesMoises 8ea8cb2
chore: linting + notes will only work on EditorialWorkflow
EstoesMoises c97975d
feat: notes can be unresolved
EstoesMoises eb9e5c6
fix: removing char limit on notes
EstoesMoises 039e84d
feat: avatar now visible in notes
EstoesMoises 7117c47
fix: now getting author and avatar immediately on note creation + not…
EstoesMoises e2f38db
feat: you can only edit or delete your own notes
EstoesMoises d07a7bf
chore: adding error handling for API calls and fixing colours in Note…
EstoesMoises 9048235
fix: passing tests
EstoesMoises 5a4c192
fix: automated test account for Notes
EstoesMoises 7eb8d07
Merge branch 'main' into 52-notes-pane
martinjagodic 0636dfb
fix: inverted logic for initializing notesVisible
EstoesMoises 706ec59
fix: more robust handleBlur function for notes
EstoesMoises 240091b
feat: notes pane feature is now opt-in depending on config
EstoesMoises 4edb039
chore: changed icon for notesPane to quote
EstoesMoises f3a14ef
feat: notes now use Github issues making notes usable for both publi…
EstoesMoises 9265a4f
fix: removed condition that would loadNotes() twice
EstoesMoises 722cbd5
feat: lifecycle for github issues when publishing/unpublishing entries
EstoesMoises fc8c647
chore: format
EstoesMoises 4b444db
chore: added tests for notes on editorialWorkflow specs
EstoesMoises a143fde
chore: added tests for Notes Github implementation
EstoesMoises 28ed3d2
chore: updated config specification test to account for the editor.no…
EstoesMoises 4ae697f
Merge branch 'main' into 52-notes-pane
EstoesMoises File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ import type { | |
ImplementationFile, | ||
UnpublishedEntryMediaFile, | ||
Entry, | ||
Note, | ||
} from 'decap-cms-lib-util'; | ||
import type { Semaphore } from 'semaphore'; | ||
|
||
|
@@ -716,4 +717,127 @@ export default class GitHub implements Implementation { | |
'Failed to acquire publish entry lock', | ||
); | ||
} | ||
|
||
// Notes implementation, which is an abstraction to Github's PR issue comments. | ||
|
||
/** | ||
* Helper method to get PR info for an entry | ||
*/ | ||
private async getPRInfo(collection: string, slug: string) { | ||
const contentKey = this.api!.generateContentKey(collection, slug); | ||
const branch = branchFromContentKey(contentKey); | ||
const pullRequest = await this.api!.getBranchPullRequest(branch); | ||
|
||
return { | ||
branch, | ||
pullRequest, | ||
hasPR: pullRequest.number !== -1, | ||
}; | ||
} | ||
|
||
async getNotes(collection: string, slug: string): Promise<Note[]> { | ||
if (!this.options.useWorkflow) { | ||
return []; | ||
} | ||
try { | ||
const { pullRequest, hasPR } = await this.getPRInfo(collection, slug); | ||
|
||
if (!hasPR) { | ||
return []; | ||
} | ||
|
||
const notes = await this.api!.getNotesFromPR(pullRequest.number); | ||
return notes.map(note => ({ ...note, entrySlug: slug })); | ||
} catch (error) { | ||
console.error('Failed to get notes:', error); | ||
return []; | ||
} | ||
} | ||
|
||
async addNote(collection: string, slug: string, noteData: Omit<Note, 'id'>): Promise<Note> { | ||
if (!this.options.useWorkflow) { | ||
throw new Error('Notes are only available when workflow is enabled.'); | ||
} | ||
|
||
const { pullRequest, hasPR } = await this.getPRInfo(collection, slug); | ||
|
||
if (!hasPR) { | ||
throw new Error('Cannot add notes to draft entries. Please submit for review first.'); | ||
} | ||
|
||
const currentUser = await this.currentUser({ token: this.token! }); | ||
|
||
const note: Note = { | ||
...noteData, | ||
id: 'temp-' + Date.now(), | ||
author: currentUser.login || currentUser.name, | ||
avatarUrl: currentUser.avatar_url, | ||
entrySlug: slug, | ||
timestamp: noteData.timestamp || new Date().toISOString(), | ||
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. The noteData.timestamp is being used as a fallback, but the Note interface shows timestamp as a required field. Either the interface should mark it as optional or this fallback should be removed to ensure consistency. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
resolved: noteData.resolved || false, | ||
}; | ||
|
||
const commentId = await this.api!.createPRComment(pullRequest.number, note); | ||
return { ...note, id: commentId }; | ||
} | ||
|
||
async updateNote( | ||
collection: string, | ||
slug: string, | ||
noteId: string, | ||
updates: Partial<Note>, | ||
): Promise<Note> { | ||
if (!this.options.useWorkflow) { | ||
throw new Error('Notes are only available when workflow is enabled.'); | ||
} | ||
|
||
const currentNotes = await this.getNotes(collection, slug); | ||
const existingNote = currentNotes.find(note => note.id === noteId); | ||
|
||
if (!existingNote) { | ||
throw new Error(`Note with ID ${noteId} not found`); | ||
} | ||
|
||
const updatedNote: Note = { | ||
...existingNote, | ||
...updates, | ||
id: noteId, | ||
entrySlug: slug, | ||
}; | ||
|
||
await this.api!.updatePRComment(noteId, updatedNote); | ||
return updatedNote; | ||
} | ||
|
||
async deleteNote(collection: string, slug: string, noteId: string): Promise<void> { | ||
if (!this.options.useWorkflow) { | ||
throw new Error('Notes are only available when workflow is enabled.'); | ||
} | ||
|
||
const currentNotes = await this.getNotes(collection, slug); | ||
const noteExists = currentNotes.some(note => note.id === noteId); | ||
|
||
if (!noteExists) { | ||
throw new Error(`Note with ID ${noteId} not found`); | ||
} | ||
|
||
await this.api!.deletePRComment(noteId); | ||
} | ||
|
||
async toggleNoteResolution(collection: string, slug: string, noteId: string): Promise<Note> { | ||
if (!this.options.useWorkflow) { | ||
throw new Error('Notes are only available when workflow is enabled.'); | ||
} | ||
|
||
const currentNotes = await this.getNotes(collection, slug); | ||
const note = currentNotes.find(n => n.id === noteId); | ||
|
||
if (!note) { | ||
throw new Error(`Note with ID ${noteId} not found`); | ||
} | ||
|
||
return this.updateNote(collection, slug, noteId, { | ||
resolved: !note.resolved, | ||
}); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/decap-cms-backend-github/src/types/githubPullRequests.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
type GitHubIssueComment = { | ||
id: number; | ||
node_id: string; | ||
url: string; | ||
html_url: string; | ||
body: string; | ||
user: { | ||
login: string; | ||
id: number; | ||
avatar_url: string; | ||
html_url: string; | ||
}; | ||
created_at: string; | ||
updated_at: string; | ||
author_association: string; | ||
}; | ||
|
||
export type { GitHubIssueComment }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[nitpick] The template literal has trailing spaces after the HTML comment. This could cause inconsistent formatting. Consider removing trailing whitespace or using a more structured approach.
Copilot uses AI. Check for mistakes.