From e6e73d20614ffa7858f275ccb406f7bd0e1191d0 Mon Sep 17 00:00:00 2001 From: Mateo Ivankovic Date: Tue, 9 Jul 2024 15:36:11 +0200 Subject: [PATCH] feat: marker for edited notes (#4277) --- server/src/api/notes.go | 15 +++++------ server/src/common/dto/notes.go | 8 ++++-- server/src/common/dto/votings.go | 2 +- server/src/database/boards.go | 18 ++++++------- .../sql/15_add_edited_notes_marker.down.sql | 1 + .../sql/15_add_edited_notes_marker.up.sql | 1 + server/src/database/notes.go | 4 ++- server/src/services/boards/boards.go | 1 + server/src/services/notes/notes.go | 3 +++ server/src/services/notes/notes_test.go | 2 ++ .../__snapshots__/Column.test.tsx.snap | 23 +++++++++++++--- src/components/Note/Note.scss | 26 ++++++++++++------- src/components/Note/Note.tsx | 9 ++++--- src/components/Note/__tests__/Note.test.tsx | 8 ++++++ .../NoteDialogNoteContent.scss | 12 ++++++--- .../NoteDialogNoteContent.tsx | 9 +++++-- .../NoteInput/__tests__/NoteInput.test.tsx | 2 +- src/i18n/de/translation.json | 3 ++- src/i18n/en/translation.json | 3 ++- src/types/note.ts | 1 + src/utils/test/getTestApplicationState.ts | 3 +++ src/utils/test/getTestNote.ts | 1 + 22 files changed, 110 insertions(+), 45 deletions(-) create mode 100644 server/src/database/migrations/sql/15_add_edited_notes_marker.down.sql create mode 100644 server/src/database/migrations/sql/15_add_edited_notes_marker.up.sql diff --git a/server/src/api/notes.go b/server/src/api/notes.go index c40e2ddf14..a23f5e8649 100644 --- a/server/src/api/notes.go +++ b/server/src/api/notes.go @@ -2,13 +2,12 @@ package api import ( "fmt" - "net/http" - "scrumlr.io/server/identifiers" - "github.com/go-chi/render" "github.com/google/uuid" + "net/http" "scrumlr.io/server/common" "scrumlr.io/server/common/dto" + "scrumlr.io/server/identifiers" ) // createNote creates a new note @@ -69,17 +68,17 @@ func (s *Server) getNotes(w http.ResponseWriter, r *http.Request) { // updateNote updates a note func (s *Server) updateNote(w http.ResponseWriter, r *http.Request) { - board := r.Context().Value(identifiers.BoardIdentifier).(uuid.UUID) - noteId := r.Context().Value(identifiers.NoteIdentifier).(uuid.UUID) + boardID := r.Context().Value(identifiers.BoardIdentifier).(uuid.UUID) + noteID := r.Context().Value(identifiers.NoteIdentifier).(uuid.UUID) + var body dto.NoteUpdateRequest if err := render.Decode(r, &body); err != nil { common.Throw(w, r, common.BadRequestError(err)) return } - body.ID = noteId - body.Board = board - + body.ID = noteID + body.Board = boardID note, err := s.notes.Update(r.Context(), body) if err != nil { common.Throw(w, r, err) diff --git a/server/src/common/dto/notes.go b/server/src/common/dto/notes.go index 7d3b6fb226..d64a2ed42c 100644 --- a/server/src/common/dto/notes.go +++ b/server/src/common/dto/notes.go @@ -30,6 +30,8 @@ type Note struct { // The text of the note. Text string `json:"text"` + Edited bool `json:"edited"` + // The position of the note. Position NotePosition `json:"position"` } @@ -43,6 +45,7 @@ func (n *Note) From(note database.Note) *Note { Stack: note.Stack, Rank: note.Rank, } + n.Edited = note.Edited return n } @@ -83,8 +86,9 @@ type NoteUpdateRequest struct { // The position of the note Position *NotePosition `json:"position"` - ID uuid.UUID `json:"-"` - Board uuid.UUID `json:"-"` + Edited bool `json:"-"` + ID uuid.UUID `json:"-"` + Board uuid.UUID `json:"-"` } // NoteDeleteRequest represents the request to delete a note. diff --git a/server/src/common/dto/votings.go b/server/src/common/dto/votings.go index 0b7982bd76..c018963cf4 100644 --- a/server/src/common/dto/votings.go +++ b/server/src/common/dto/votings.go @@ -66,7 +66,7 @@ type VotingCreateRequest struct { ShowVotesOfOthers bool `json:"showVotesOfOthers"` } -// VotingUpdateRequest represents the request to update a voting session. +// VotingUpdateRequest represents the request to u pdate a voting session. type VotingUpdateRequest struct { ID uuid.UUID `json:"-"` Board uuid.UUID `json:"-"` diff --git a/server/src/database/boards.go b/server/src/database/boards.go index 5968bf0d97..109e99df48 100644 --- a/server/src/database/boards.go +++ b/server/src/database/boards.go @@ -1,15 +1,15 @@ package database import ( - "context" - "errors" - "scrumlr.io/server/identifiers" - "time" - - "github.com/google/uuid" - "github.com/uptrace/bun" - "scrumlr.io/server/common" - "scrumlr.io/server/database/types" + "context" + "errors" + "scrumlr.io/server/identifiers" + "time" + + "github.com/google/uuid" + "github.com/uptrace/bun" + "scrumlr.io/server/common" + "scrumlr.io/server/database/types" ) type Board struct { diff --git a/server/src/database/migrations/sql/15_add_edited_notes_marker.down.sql b/server/src/database/migrations/sql/15_add_edited_notes_marker.down.sql new file mode 100644 index 0000000000..78dd9057b3 --- /dev/null +++ b/server/src/database/migrations/sql/15_add_edited_notes_marker.down.sql @@ -0,0 +1 @@ +ALTER TABLE IF EXISTS notes DROP COLUMN IF EXISTS edited ; diff --git a/server/src/database/migrations/sql/15_add_edited_notes_marker.up.sql b/server/src/database/migrations/sql/15_add_edited_notes_marker.up.sql new file mode 100644 index 0000000000..ec1380c363 --- /dev/null +++ b/server/src/database/migrations/sql/15_add_edited_notes_marker.up.sql @@ -0,0 +1 @@ +ALTER TABLE IF EXISTS notes ADD COLUMN edited BOOL DEFAULT FALSE; diff --git a/server/src/database/notes.go b/server/src/database/notes.go index 0bb9c1714b..ba97598448 100644 --- a/server/src/database/notes.go +++ b/server/src/database/notes.go @@ -22,6 +22,7 @@ type Note struct { Text string Stack uuid.NullUUID Rank int + Edited bool } type NoteInsert struct { @@ -44,6 +45,7 @@ type NoteUpdate struct { Board uuid.UUID Text *string Position *NoteUpdatePosition `bun:"embed"` + Edited bool } func (d *Database) CreateNote(insert NoteInsert) (Note, error) { @@ -123,7 +125,7 @@ func (d *Database) UpdateNote(caller uuid.UUID, update NoteUpdate) (Note, error) func (d *Database) updateNoteText(update NoteUpdate) (Note, error) { var note Note - _, err := d.db.NewUpdate().Model(&update).Column("text").Where("id = ?", update.ID).Where("board = ?", update.Board).Where("id = ?", update.ID).Returning("*").Exec(common.ContextWithValues(context.Background(), "Database", d, identifiers.BoardIdentifier, update.Board), ¬e) + _, err := d.db.NewUpdate().Model(&update).Column("text", "edited").Where("id = ?", update.ID).Where("board = ?", update.Board).Where("id = ?", update.ID).Returning("*").Exec(common.ContextWithValues(context.Background(), "Database", d, identifiers.BoardIdentifier, update.Board), ¬e) if err != nil { return note, err } diff --git a/server/src/services/boards/boards.go b/server/src/services/boards/boards.go index a6e9effa80..d3b523f17b 100644 --- a/server/src/services/boards/boards.go +++ b/server/src/services/boards/boards.go @@ -88,6 +88,7 @@ func (s *BoardService) Create(ctx context.Context, body dto.CreateBoardRequest) log.Errorw("unable to create board", "owner", body.Owner, "policy", body.AccessPolicy, "error", err) return nil, err } + return new(dto.Board).From(b), nil } diff --git a/server/src/services/notes/notes.go b/server/src/services/notes/notes.go index 0ad271a6ea..b6ee6ad950 100644 --- a/server/src/services/notes/notes.go +++ b/server/src/services/notes/notes.go @@ -78,6 +78,7 @@ func (s *NoteService) List(ctx context.Context, boardID uuid.UUID) ([]*dto.Note, func (s *NoteService) Update(ctx context.Context, body dto.NoteUpdateRequest) (*dto.Note, error) { log := logger.FromContext(ctx) var positionUpdate *database.NoteUpdatePosition + edited := body.Text != nil if body.Position != nil { positionUpdate = &database.NoteUpdatePosition{ Column: body.Position.Column, @@ -85,11 +86,13 @@ func (s *NoteService) Update(ctx context.Context, body dto.NoteUpdateRequest) (* Stack: body.Position.Stack, } } + note, err := s.database.UpdateNote(ctx.Value(identifiers.UserIdentifier).(uuid.UUID), database.NoteUpdate{ ID: body.ID, Board: body.Board, Text: body.Text, Position: positionUpdate, + Edited: edited, }) if err != nil { log.Errorw("unable to update note", "error", err, "note", body.ID) diff --git a/server/src/services/notes/notes_test.go b/server/src/services/notes/notes_test.go index 1c67ed8760..6a2474d7e4 100644 --- a/server/src/services/notes/notes_test.go +++ b/server/src/services/notes/notes_test.go @@ -202,6 +202,7 @@ func (suite *NoteServiceTestSuite) TestUpdateNote() { Board: boardID, Text: &txt, Position: &posUpdate, + Edited: true, }).Return(database.Note{}, nil) _, err := s.Update(ctx, dto.NoteUpdateRequest{ @@ -209,6 +210,7 @@ func (suite *NoteServiceTestSuite) TestUpdateNote() { ID: noteID, Board: boardID, Position: &pos, + Edited: true, }) assert.NoError(suite.T(), err) mock.AssertExpectations(suite.T()) diff --git a/src/components/Column/__tests__/__snapshots__/Column.test.tsx.snap b/src/components/Column/__tests__/__snapshots__/Column.test.tsx.snap index f795d73ecc..b6d9cacae1 100644 --- a/src/components/Column/__tests__/__snapshots__/Column.test.tsx.snap +++ b/src/components/Column/__tests__/__snapshots__/Column.test.tsx.snap @@ -591,9 +591,20 @@ exports[`Column should have correct style show column with correct style 1`] = `
- Lorem Ipsum +
+ Lorem Ipsum +
+
+ ( + edited + ) +