-
Notifications
You must be signed in to change notification settings - Fork 2
/
task_detail.go
94 lines (79 loc) · 2.46 KB
/
task_detail.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package view
import (
"time"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ecs/types"
"github.com/gdamore/tcell/v2"
"github.com/masaushi/ecsplorer/internal/view/ui"
"github.com/rivo/tview"
)
type TaskDetail struct {
task *types.Task
selectAction func(*types.Container)
reloadAction func()
prevPageAction func()
}
func NewTaskDetail(task *types.Task) *TaskDetail {
return &TaskDetail{
task: task,
selectAction: func(*types.Container) {},
reloadAction: func() {},
prevPageAction: func() {},
}
}
func (td *TaskDetail) SetSelectAction(action func(*types.Container)) *TaskDetail {
td.selectAction = action
return td
}
func (td *TaskDetail) SetReloadAction(action func()) *TaskDetail {
td.reloadAction = action
return td
}
func (td *TaskDetail) SetPrevPageAction(action func()) *TaskDetail {
td.prevPageAction = action
return td
}
func (td *TaskDetail) Render() tview.Primitive {
body := tview.NewFlex().
SetDirection(tview.FlexRow).
AddItem(td.header(), 3, 1, false).
AddItem(td.description(), 3, 1, false).
AddItem(td.table(), 0, 1, true)
body.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
//nolint:exhaustive
switch event.Key() {
case tcell.KeyESC:
td.prevPageAction()
default:
}
return event
})
return ui.CreateLayout(body)
}
func (td *TaskDetail) header() *tview.Flex {
return ui.CreateHeader("Task", aws.ToString(td.task.TaskArn))
}
func (td *TaskDetail) description() *tview.Flex {
return tview.NewFlex().
AddItem(ui.CreateDescription("Last Status", aws.ToString(td.task.LastStatus)), 0, 1, false).
AddItem(ui.CreateDescription("Desired Status", aws.ToString(td.task.DesiredStatus)), 0, 1, false).
AddItem(ui.CreateDescription("Health Status", string(td.task.HealthStatus)), 0, 1, false).
AddItem(ui.CreateDescription("Started At", td.task.StartedAt.Format(time.RFC3339)), 0, 1, false)
}
func (td *TaskDetail) table() *tview.Table {
header := []string{"NAME", "STATUS", "HEALTH STATUS", "CPU", "MEMORY"}
rows := make([][]string, len(td.task.Containers))
for i, container := range td.task.Containers {
rows[i] = make([]string, 0, len(header))
rows[i] = append(rows[i],
aws.ToString(container.Name),
aws.ToString(container.LastStatus),
string(container.HealthStatus),
aws.ToString(container.Cpu),
aws.ToString(container.Memory),
)
}
return ui.CreateTable(header, rows, func(row, column int) {
td.selectAction(&td.task.Containers[row-1])
})
}