Skip to content

Commit d9d84a7

Browse files
author
Idan Attias
committed
feat(tui): enhance deletion confirmation modal
Update the deletion confirmation modal to display the full GCS URI (gs://bucket/path) for the target resource. Increased the modal width and padding to improve readability for long paths. Added a new snapshot test and updated existing tests to verify the UI changes. This change helps users verify the exact resource they are about to delete by showing the canonical GCS path.
1 parent 6bf2c1d commit d9d84a7

File tree

4 files changed

+99
-6
lines changed

4 files changed

+99
-6
lines changed

internal/tui/views.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,11 +1175,11 @@ func (m *Model) deleteConfirmView() string {
11751175

11761176
var target string
11771177
if m.pendingDeleteIsBucket {
1178-
target = fmt.Sprintf("bucket: %s", m.pendingDeleteBucket)
1178+
target = fmt.Sprintf("gs://%s", m.pendingDeleteBucket)
11791179
} else if m.pendingDeletePrefix != "" {
1180-
target = fmt.Sprintf("directory: %s recursively", m.pendingDeletePrefix)
1180+
target = fmt.Sprintf("gs://%s/%s", m.pendingDeleteBucket, m.pendingDeletePrefix)
11811181
} else {
1182-
target = fmt.Sprintf("object: %s", m.pendingDeleteObject)
1182+
target = fmt.Sprintf("gs://%s/%s", m.pendingDeleteBucket, m.pendingDeleteObject)
11831183
}
11841184

11851185
fmt.Fprintf(&s, "Are you sure you want to delete %s?\n", lipgloss.NewStyle().Bold(true).Render(target))
@@ -1188,9 +1188,18 @@ func (m *Model) deleteConfirmView() string {
11881188
keyStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#CBA6F7")).Bold(true)
11891189
fmt.Fprintf(&s, "%s delete %s cancel", keyStyle.Render("y"), keyStyle.Render("n/esc"))
11901190

1191+
modalWidth := m.width - 20
1192+
if modalWidth < 60 {
1193+
modalWidth = 60
1194+
}
1195+
if modalWidth > 120 {
1196+
modalWidth = 120
1197+
}
1198+
11911199
return lipgloss.NewStyle().
11921200
Border(lipgloss.RoundedBorder()).
11931201
BorderForeground(lipgloss.Color("#F38BA8")).
1194-
Padding(1, 2).
1202+
Padding(1, 4).
1203+
Width(modalWidth).
11951204
Render(s.String())
11961205
}

tests/snapshot_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,49 @@ func TestSnapshot_MessagesView(t *testing.T) {
281281

282282
teatest.RequireEqualOutput(t, []byte(tm.FinalModel(t).View()))
283283
}
284+
285+
func TestSnapshot_DeleteConfirmation(t *testing.T) {
286+
objects := []fakestorage.Object{
287+
{
288+
ObjectAttrs: fakestorage.ObjectAttrs{
289+
BucketName: "assets",
290+
Name: "file_to_delete.txt",
291+
},
292+
Content: []byte("delete me"),
293+
},
294+
}
295+
296+
tm, _ := testutil.SetupTestApp(t, objects, 0, []string{"prod-project"}, t.TempDir())
297+
298+
// Wait for buckets to load
299+
teatest.WaitFor(t, tm.Output(), func(bts []byte) bool {
300+
return strings.Contains(string(bts), "assets")
301+
}, teatest.WithDuration(3*time.Second))
302+
303+
tm.Send(tea.WindowSizeMsg{Width: 100, Height: 30})
304+
305+
// Enter bucket 'assets'
306+
tm.Type("j")
307+
tm.Type("l")
308+
309+
// Wait for file_to_delete.txt to appear
310+
teatest.WaitFor(t, tm.Output(), func(bts []byte) bool {
311+
return strings.Contains(string(bts), "file_to_delete.txt")
312+
}, teatest.WithDuration(3*time.Second))
313+
314+
// Move to file_to_delete.txt
315+
tm.Type("j")
316+
317+
// Press 'x' to delete
318+
tm.Type("x")
319+
320+
// Wait for confirmation prompt
321+
teatest.WaitFor(t, tm.Output(), func(bts []byte) bool {
322+
return strings.Contains(string(bts), "DELETE CONFIRMATION")
323+
}, teatest.WithDuration(3*time.Second))
324+
325+
// Trigger quit
326+
_ = tm.Quit()
327+
328+
teatest.RequireEqualOutput(t, []byte(tm.FinalModel(t).View()))
329+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
_Ga=d,d=A\ gs://  ❯  assets 
2+
3+
╭───────────────────────╮╭────────────────────────────╮╭───────────────────────────────────────────╮
4+
│ Buckets ││ ││  │
5+
│  ││ ││ │
6+
│ ▼ prod-project  ││ ││ │
7+
│ ● 📦 assets  ││ ││ │
8+
│  ││ ││ │
9+
│ ││ ││ │
10+
│ ││ ││ │
11+
│ ││ ││ │
12+
│ ││ ││ │
13+
│ ││ ││ │
14+
│ ││ ││ │
15+
│ ││ ││ │
16+
│ ││ ││ │
17+
│ ││ ││ │
18+
│ ││ ││ │
19+
│ ││ ││ │
20+
│ ││ ││ │
21+
│ ││ ││ │
22+
│ ││ ││ │
23+
│ ││ ││ │
24+
│ ││ ││ │
25+
│ ││ ││ │
26+
│ ││ ││ │
27+
│ ││ ││ │
28+
╰───────────────────────╯╰────────────────────────────╯╰───────────────────────────────────────────╯
29+
╭────────────────────────────────────────────────────────────────────────────────╮
30+
│ │
31+
│ DELETE CONFIRMATION │
32+
│ │
33+
│ Are you sure you want to delete gs://assets/file_to_delete.txt? │
34+
│ This action cannot be undone. │
35+
│ │
36+
│ y delete n/esc cancel │
37+
│ │
38+
╰────────────────────────────────────────────────────────────────────────────────╯

tests/tui_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ func TestDeleteObject(t *testing.T) {
878878
// Wait for confirmation prompt
879879
teatest.WaitFor(t, tm.Output(), func(bts []byte) bool {
880880
return strings.Contains(string(bts), "DELETE CONFIRMATION") &&
881-
strings.Contains(string(bts), "file_to_delete.txt")
881+
strings.Contains(string(bts), "gs://delete-bucket/file_to_delete.txt")
882882
}, teatest.WithDuration(2*time.Second))
883883

884884
// Confirm deletion
@@ -939,7 +939,7 @@ func TestDeleteBucket(t *testing.T) {
939939
// Wait for confirmation prompt
940940
teatest.WaitFor(t, tm.Output(), func(bts []byte) bool {
941941
return strings.Contains(string(bts), "DELETE CONFIRMATION") &&
942-
strings.Contains(string(bts), "bucket: bucket-to-delete")
942+
strings.Contains(string(bts), "gs://bucket-to-delete")
943943
}, teatest.WithDuration(2*time.Second))
944944

945945
// Confirm deletion

0 commit comments

Comments
 (0)