Skip to content

Commit ab37342

Browse files
committed
fix: group tasks by section
1 parent 4e741bf commit ab37342

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

internal/cli/list.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,19 @@ func groupTasksBySection(items []*tasks.Task, filter string) (map[string][]taskR
7373
sectionIDs := map[string]string{}
7474
sectionNames := map[string]bool{}
7575

76-
for i, item := range items {
76+
for _, item := range items {
7777
if _, ok := metadata.Extract(item.Notes, "justdoit_section"); ok {
7878
sectionIDs[item.Id] = item.Title
7979
if !sectionNames[item.Title] {
8080
order = append(order, item.Title)
8181
sectionNames[item.Title] = true
8282
}
83+
}
84+
}
85+
for i, item := range items {
86+
if _, ok := metadata.Extract(item.Notes, "justdoit_section"); ok {
8387
continue
8488
}
85-
8689
sectionName := "General"
8790
if parent, ok := sectionIDs[item.Parent]; ok {
8891
sectionName = parent

internal/cli/list_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cli
2+
3+
import (
4+
"testing"
5+
6+
"google.golang.org/api/tasks/v1"
7+
)
8+
9+
func TestGroupTasksBySectionBuildsSectionIndexFirst(t *testing.T) {
10+
sectionID := "section-1"
11+
items := []*tasks.Task{
12+
{Id: "task-1", Title: "Follow up", Parent: sectionID},
13+
{Id: sectionID, Title: "Recurrentes", Notes: "justdoit_section=1"},
14+
}
15+
16+
sections, order := groupTasksBySection(items, "")
17+
if len(sections) == 0 {
18+
t.Fatalf("expected sections, got none")
19+
}
20+
tasks := sections["Recurrentes"]
21+
if len(tasks) != 1 || tasks[0].Title != "Follow up" {
22+
t.Fatalf("expected task under section, got %#v", sections)
23+
}
24+
if len(order) == 0 || order[0] != "Recurrentes" {
25+
t.Fatalf("expected section order to include Recurrentes, got %#v", order)
26+
}
27+
}

0 commit comments

Comments
 (0)