Skip to content

Commit 3d4e5c9

Browse files
committed
Offer no undo after restoring a project
unarchive also restores from the trash, and archiving a project it brought back from there would not put it back. archive still offers unarchive.
1 parent 4451495 commit 3d4e5c9

2 files changed

Lines changed: 29 additions & 21 deletions

File tree

‎internal/commands/projects.go‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,15 @@ account is already at that limit.`,
467467
Example: " $ basecamp projects unarchive 12345",
468468
Args: cobra.MaximumNArgs(1),
469469
RunE: func(cmd *cobra.Command, args []string) error {
470-
return runProjectStatusChange(cmd, args, (*basecamp.ProjectsService).Unarchive, "active", "Project restored", "archive", "Archive the project")
470+
return runProjectStatusChange(cmd, args, (*basecamp.ProjectsService).Unarchive, "active", "Project restored", "", "")
471471
},
472472
}
473473
}
474474

475475
// runProjectStatusChange makes the change, which answers with no body, and
476-
// reports the status it set, with the command that undoes it as a follow-up.
476+
// reports the status it set. inverse names the command that undoes it, offered
477+
// as a follow-up; unarchive has none, since a project it restored may have
478+
// come from the trash rather than the archive.
477479
func runProjectStatusChange(cmd *cobra.Command, args []string, change func(*basecamp.ProjectsService, context.Context, int64) error, status, summary, inverse, inverseDescription string) error {
478480
if len(args) == 0 {
479481
return missingArg(cmd, "<id>")
@@ -499,23 +501,24 @@ func runProjectStatusChange(cmd *cobra.Command, args []string, change func(*base
499501
}
500502

501503
scopeArgs := scope.args(app.Config.AccountID)
504+
crumbs := []output.Breadcrumb{{
505+
Action: "show",
506+
Cmd: fmt.Sprintf("basecamp projects show %d", projectID) + scopeArgs,
507+
Description: "View the project",
508+
}}
509+
if inverse != "" {
510+
crumbs = append(crumbs, output.Breadcrumb{
511+
Action: inverse,
512+
Cmd: fmt.Sprintf("basecamp projects %s %d", inverse, projectID) + scopeArgs,
513+
Description: inverseDescription,
514+
})
515+
}
502516
return app.OK(map[string]any{
503517
"id": projectID,
504518
"status": status,
505519
},
506520
output.WithSummary(summary),
507-
output.WithBreadcrumbs(
508-
output.Breadcrumb{
509-
Action: "show",
510-
Cmd: fmt.Sprintf("basecamp projects show %d", projectID) + scopeArgs,
511-
Description: "View the project",
512-
},
513-
output.Breadcrumb{
514-
Action: inverse,
515-
Cmd: fmt.Sprintf("basecamp projects %s %d", inverse, projectID) + scopeArgs,
516-
Description: inverseDescription,
517-
},
518-
),
521+
output.WithBreadcrumbs(crumbs...),
519522
)
520523
}
521524

‎internal/commands/projects_archive_test.go‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,19 @@ func projectStatusServer(t *testing.T, path string, status int, body string) (*h
3232
}
3333

3434
func TestProjectsArchiveAndUnarchive(t *testing.T) {
35+
// unarchive offers no undo: the project it restored may have come from
36+
// the trash, and archiving it would not put it back there.
3537
for _, tc := range []struct {
36-
action, path, status, summary, inverse string
38+
action, path, status, summary string
39+
follow map[string]string
3740
}{
38-
{"archive", "/99999/projects/123/status/archived.json", "archived", "Project archived", "unarchive"},
39-
{"unarchive", "/99999/projects/123/status/active.json", "active", "Project restored", "archive"},
41+
{"archive", "/99999/projects/123/status/archived.json", "archived", "Project archived", map[string]string{
42+
"show": "basecamp projects show 123",
43+
"unarchive": "basecamp projects unarchive 123",
44+
}},
45+
{"unarchive", "/99999/projects/123/status/active.json", "active", "Project restored", map[string]string{
46+
"show": "basecamp projects show 123",
47+
}},
4048
} {
4149
t.Run(tc.action, func(t *testing.T) {
4250
server, calls := projectStatusServer(t, tc.path, http.StatusNoContent, "")
@@ -54,10 +62,7 @@ func TestProjectsArchiveAndUnarchive(t *testing.T) {
5462
for _, crumb := range env.Breadcrumbs {
5563
got[crumb.Action] = crumb.Cmd
5664
}
57-
assert.Equal(t, map[string]string{
58-
"show": "basecamp projects show 123",
59-
tc.inverse: "basecamp projects " + tc.inverse + " 123",
60-
}, got)
65+
assert.Equal(t, tc.follow, got)
6166
})
6267
}
6368
}

0 commit comments

Comments
 (0)