feat: edit suggestions before accepting worklog
This commit is contained in:
@@ -8,8 +8,8 @@ import (
|
||||
"time"
|
||||
|
||||
"verstak/internal/core/activity"
|
||||
"verstak/internal/core/worklog"
|
||||
syncsvc "verstak/internal/core/sync"
|
||||
"verstak/internal/core/worklog"
|
||||
)
|
||||
|
||||
// GetSuggestions analyzes today's activity and returns conservative suggestions.
|
||||
@@ -126,6 +126,12 @@ func (a *App) AcceptSuggestion(nodeID, summary string, minutes int, date string,
|
||||
// AcceptSuggestionWith creates a worklog entry and links events in a single transaction.
|
||||
// eventIDsJSON is a JSON-serialized string array to avoid Wails v2 []string marshalling issues.
|
||||
func (a *App) AcceptSuggestionWith(nodeID, summary string, minutes int, date string, eventIDsJSON string) (*WorklogDTO, error) {
|
||||
return a.AcceptSuggestionFull(nodeID, summary, "", date, minutes, true, false, eventIDsJSON)
|
||||
}
|
||||
|
||||
// AcceptSuggestionFull creates a worklog entry from an edited suggestion and links events in a single transaction.
|
||||
// eventIDsJSON is a JSON-serialized string array to avoid Wails v2 []string marshalling issues.
|
||||
func (a *App) AcceptSuggestionFull(nodeID, summary, details, date string, minutes int, approximate, billable bool, eventIDsJSON string) (*WorklogDTO, error) {
|
||||
if err := a.requireVault(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -159,7 +165,7 @@ func (a *App) AcceptSuggestionWith(nodeID, summary string, minutes int, date str
|
||||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
entry, err := a.worklog.AddWithSourceTx(tx, nodeID, summary, "", d, minutes, true, false, worklog.SourceSuggestion)
|
||||
entry, err := a.worklog.AddWithSourceTx(tx, nodeID, summary, details, d, minutes, approximate, billable, worklog.SourceSuggestion)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create entry: %w", err)
|
||||
}
|
||||
@@ -190,18 +196,7 @@ func (a *App) AcceptSuggestionWith(nodeID, summary string, minutes int, date str
|
||||
}
|
||||
|
||||
_ = a.sync.RecordOp(syncsvc.EntityWorklog, entry.ID, syncsvc.OpCreate, worklogPayload(entry))
|
||||
mins := 0
|
||||
if entry.Minutes != nil {
|
||||
mins = *entry.Minutes
|
||||
}
|
||||
return &WorklogDTO{
|
||||
ID: entry.ID,
|
||||
NodeID: entry.NodeID,
|
||||
Summary: entry.Summary,
|
||||
Minutes: mins,
|
||||
Date: entry.Date,
|
||||
CreatedAt: entry.CreatedAt.Format("2006-01-02T15:04:05Z"),
|
||||
}, nil
|
||||
return entryToDTO(entry), nil
|
||||
}
|
||||
|
||||
// HideSuggestion marks a suggestion as hidden for the session.
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -16,7 +16,7 @@
|
||||
background: #13131f;
|
||||
}
|
||||
</style>
|
||||
<script type="module" crossorigin src="/assets/main-Cc1HprFt.js"></script>
|
||||
<script type="module" crossorigin src="/assets/main-Cyhj7TEH.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/main-DAyIHTpH.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -392,3 +392,31 @@ func TestApplyRemoteWorklogUpdate(t *testing.T) {
|
||||
t.Fatalf("remote updated minutes/flags = %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAcceptSuggestionFullUsesEditedFields(t *testing.T) {
|
||||
app, _ := setupTestApp(t)
|
||||
|
||||
n, err := app.CreateNodeFromTemplate("", "Edited Suggestion Node", "folder.default")
|
||||
if err != nil {
|
||||
t.Fatalf("create node: %v", err)
|
||||
}
|
||||
eventID := insertTestEvent(t, app, n.ID, activity.TypeFileAdded, "file", "file-1", "Добавлен файл")
|
||||
eventIDsJSON, _ := json.Marshal([]string{eventID})
|
||||
|
||||
dto, err := app.AcceptSuggestionFull(n.ID, "Edited summary", "Edited details", "2026-01-05", 55, false, true, string(eventIDsJSON))
|
||||
if err != nil {
|
||||
t.Fatalf("AcceptSuggestionFull: %v", err)
|
||||
}
|
||||
if dto.Summary != "Edited summary" || dto.Details != "Edited details" || dto.Date != "2026-01-05" {
|
||||
t.Fatalf("dto = %#v", dto)
|
||||
}
|
||||
if dto.Minutes != 55 || dto.Approximate || !dto.Billable {
|
||||
t.Fatalf("dto minutes/flags = %#v", dto)
|
||||
}
|
||||
if dto.Source != worklog.SourceSuggestion {
|
||||
t.Fatalf("dto.Source = %q, want %q", dto.Source, worklog.SourceSuggestion)
|
||||
}
|
||||
if n := countLinked(t, app, dto.ID); n != 1 {
|
||||
t.Fatalf("linked events = %d, want 1", n)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user