Skip to content

Commit 6fc4674

Browse files
updated tablecontroll to better work with i18n
1 parent 4998033 commit 6fc4674

7 files changed

Lines changed: 39 additions & 39 deletions

File tree

ui/tui/helpers/tablecontroll/controll.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var _ BubblesTableRenderer[any] = Controll[any]{}.RenderBubblesTable
1515

1616
type Column[T any] struct {
1717
// column title
18-
Title string
18+
Title func() string
1919

2020
// function to render content of column for each row
2121
View func(v T) string
@@ -59,7 +59,7 @@ func (c Controll[T]) ColumnDimensions(rows [][]string, availableWidth int) ([]in
5959
columnWidths := slicest.MapI(c.Columns, func(i int, column Column[T]) int {
6060
// calculate max width of all cells and the header
6161
columnWidth := max(
62-
len(column.Title),
62+
len(column.Title()),
6363
slicest.Reduce(rows, func(r []string, w int) int { return max(w, len(r[i])) }),
6464
)
6565
// apply column width modifiers
@@ -94,15 +94,15 @@ func (c Controll[T]) RenderBubblesTable(records []T, width int) ([]table.Column,
9494
extraWidth := remainingWidth / (len(c.Columns) - i)
9595
remainingWidth -= extraWidth
9696
return table.Column{
97-
Title: column.Title,
97+
Title: column.Title(),
9898
Width: columnWidths[i] + extraWidth,
9999
}
100100
}), bubblesRows
101101
} else {
102102
// size columns down weighted by their desired width, when not ennough space is available
103103
return slicest.MapI(c.Columns, func(i int, column Column[T]) table.Column {
104104
return table.Column{
105-
Title: column.Title,
105+
Title: column.Title(),
106106
Width: (availableWidth * columnWidths[i]) / totalColumnWidth,
107107
}
108108
}), bubblesRows

ui/tui/views/account/crud.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ func NewCrud(c client.Client, rc router.Controll) *crud.Crud[recordT, recordCrea
172172
},
173173

174174
tablecontroll.New(tablecontroll.Columns[recordT]{
175-
{Title: "Username", View: func(r recordT) string { return r.account.Username }},
176-
{Title: "Host", View: func(r recordT) string { return r.account.Host }},
177-
{Title: "Port", View: func(r recordT) string { return fmt.Sprint(r.account.Port) }},
178-
{Title: "Deploy Method", View: func(r recordT) string { return r.account.DeployMethod }},
179-
{Title: "Dirty", View: func(r recordT) string { return fmt.Sprint(r.isDirty) }},
180-
{Title: "Links (active/total)", View: func(r recordT) string {
175+
{Title: func() string { return "Username" }, View: func(r recordT) string { return r.account.Username }},
176+
{Title: func() string { return "Host" }, View: func(r recordT) string { return r.account.Host }},
177+
{Title: func() string { return "Port" }, View: func(r recordT) string { return fmt.Sprint(r.account.Port) }},
178+
{Title: func() string { return "Deploy Method" }, View: func(r recordT) string { return r.account.DeployMethod }},
179+
{Title: func() string { return "Dirty" }, View: func(r recordT) string { return fmt.Sprint(r.isDirty) }},
180+
{Title: func() string { return "Links (active/total)" }, View: func(r recordT) string {
181181
return fmt.Sprintf("%d/%d", r.activeLinkCount, r.totalLinkCount)
182182
}},
183-
{Title: "Public Keys (active/total)", View: func(r recordT) string {
183+
{Title: func() string { return "Public Keys (active/total)" }, View: func(r recordT) string {
184184
return fmt.Sprintf("%d/%d", r.activeLinkedPublicKeyCount, r.totalLinkedPublicKeyCount)
185185
}},
186186
}).RenderBubblesTable,

ui/tui/views/content/content.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
115115
return messagepopup.Open(messagepopup.Info, "You selected: "+r.String(), nil)
116116
},
117117
tablecontroll.New(tablecontroll.Columns[client.Account]{
118-
{Title: "Username", View: func(r client.Account) string { return r.Username }},
119-
{Title: "Host", View: func(r client.Account) string { return r.Host }},
120-
{Title: "Port", View: func(r client.Account) string { return fmt.Sprint(r.Port) }},
121-
{Title: "Deploy Method", View: func(r client.Account) string { return r.DeployMethod }},
118+
{Title: func() string { return "Username" }, View: func(r client.Account) string { return r.Username }},
119+
{Title: func() string { return "Host" }, View: func(r client.Account) string { return r.Host }},
120+
{Title: func() string { return "Port" }, View: func(r client.Account) string { return fmt.Sprint(r.Port) }},
121+
{Title: func() string { return "Deploy Method" }, View: func(r client.Account) string { return r.DeployMethod }},
122122
}),
123123
)
124124

@@ -132,10 +132,10 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
132132
return messagepopup.Open(messagepopup.Info, "You selected: "+r.String(), nil)
133133
},
134134
tablecontroll.New(tablecontroll.Columns[client.Account]{
135-
{Title: "Username", View: func(r client.Account) string { return r.Username }},
136-
{Title: "Host", View: func(r client.Account) string { return r.Host }},
137-
{Title: "Port", View: func(r client.Account) string { return fmt.Sprint(r.Port) }},
138-
{Title: "Deploy Method", View: func(r client.Account) string { return r.DeployMethod }},
135+
{Title: func() string { return "Username" }, View: func(r client.Account) string { return r.Username }},
136+
{Title: func() string { return "Host" }, View: func(r client.Account) string { return r.Host }},
137+
{Title: func() string { return "Port" }, View: func(r client.Account) string { return fmt.Sprint(r.Port) }},
138+
{Title: func() string { return "Deploy Method" }, View: func(r client.Account) string { return r.DeployMethod }},
139139
}),
140140
selectpopup.WithFilter(func(filter string, records []client.Account) []client.Account {
141141
return slicest.Filter(records, func(record client.Account) bool {

ui/tui/views/dashboard/model.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ func (m Model) View() string {
137137
}
138138

139139
recentActivityControll := tablecontroll.New(tablecontroll.Columns[recentActivityRow]{
140-
{Title: i18n.T("dashboard.log_col_time"), View: func(row recentActivityRow) string { return row.Timestamp }, MaxWidth: 0.18},
141-
{Title: i18n.T("dashboard.log_col_action"), View: func(row recentActivityRow) string { return row.Action }, MaxWidth: 0.24},
142-
{Title: i18n.T("dashboard.log_col_details"), View: func(row recentActivityRow) string { return row.Details }, MaxWidth: 0.58},
140+
{Title: func() string { return i18n.T("dashboard.log_col_time") }, View: func(row recentActivityRow) string { return row.Timestamp }, MaxWidth: 0.18},
141+
{Title: func() string { return i18n.T("dashboard.log_col_action") }, View: func(row recentActivityRow) string { return row.Action }, MaxWidth: 0.24},
142+
{Title: func() string { return i18n.T("dashboard.log_col_details") }, View: func(row recentActivityRow) string { return row.Details }, MaxWidth: 0.58},
143143
})
144144

145145
tableWidth := recentActivityControll.PreferredWidth(recentActivityRows, contentWidth)

ui/tui/views/linkaccount/crud.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ func NewCrud(c client.Client, rc router.Controll, account client.Account) *crud.
132132
},
133133

134134
tablecontroll.New(tablecontroll.Columns[recordT]{
135-
{Title: "Tag Matcher", View: func(r recordT) string { return r.link.TagMatcher }},
136-
{Title: "Expires At", View: func(r recordT) string { return util.StringifyTime(r.link.ExpiresAt) }},
137-
{Title: "Account", View: func(r recordT) string { return account.String() }},
138-
{Title: "Public Keys", View: func(r recordT) string { return fmt.Sprint(r.linkedPublicKeyCount) }},
135+
{Title: func() string { return "Tag Matcher" }, View: func(r recordT) string { return r.link.TagMatcher }},
136+
{Title: func() string { return "Expires At" }, View: func(r recordT) string { return util.StringifyTime(r.link.ExpiresAt) }},
137+
{Title: func() string { return "Account" }, View: func(r recordT) string { return account.String() }},
138+
{Title: func() string { return "Public Keys" }, View: func(r recordT) string { return fmt.Sprint(r.linkedPublicKeyCount) }},
139139
}).RenderBubblesTable,
140140
func(record recordT) recordUpdateT {
141141
return recordUpdateT{

ui/tui/views/linkpublickey/crud.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ func formRows[T comparable](c client.Client) func() []form.FormOpt[T] {
6767
func(r client.Account) tea.Cmd { return returnValue(r) },
6868
// display Accounts
6969
tablecontroll.New(tablecontroll.Columns[client.Account]{
70-
{Title: "Username", View: func(r client.Account) string { return r.Username }},
71-
{Title: "Host", View: func(r client.Account) string { return r.Host }},
72-
{Title: "Port", View: func(r client.Account) string { return fmt.Sprint(r.Port) }},
73-
{Title: "Deploy Method", View: func(r client.Account) string { return r.DeployMethod }},
70+
{Title: func() string { return "Username" }, View: func(r client.Account) string { return r.Username }},
71+
{Title: func() string { return "Host" }, View: func(r client.Account) string { return r.Host }},
72+
{Title: func() string { return "Port" }, View: func(r client.Account) string { return fmt.Sprint(r.Port) }},
73+
{Title: func() string { return "Deploy Method" }, View: func(r client.Account) string { return r.DeployMethod }},
7474
}),
7575
// extra options
7676
selectpopup.WithFilter(func(filter string, records []client.Account) []client.Account {
@@ -179,10 +179,10 @@ func NewCrud(c client.Client, rc router.Controll, publicKey client.PublicKey) *c
179179
},
180180

181181
tablecontroll.New(tablecontroll.Columns[recordT]{
182-
{Title: "Tag Matcher", View: func(r recordT) string { return r.link.TagMatcher }},
183-
{Title: "Expires At", View: func(r recordT) string { return util.StringifyTime(r.link.ExpiresAt) }},
184-
{Title: "Account", View: func(r recordT) string { return r.account.String() }},
185-
{Title: "Public Keys", View: func(r recordT) string { return fmt.Sprint(r.linkedPublicKeyCount) }},
182+
{Title: func() string { return "Tag Matcher" }, View: func(r recordT) string { return r.link.TagMatcher }},
183+
{Title: func() string { return "Expires At" }, View: func(r recordT) string { return util.StringifyTime(r.link.ExpiresAt) }},
184+
{Title: func() string { return "Account" }, View: func(r recordT) string { return r.account.String() }},
185+
{Title: func() string { return "Public Keys" }, View: func(r recordT) string { return fmt.Sprint(r.linkedPublicKeyCount) }},
186186
}).RenderBubblesTable,
187187
func(record recordT) recordUpdateT {
188188
return recordUpdateT{

ui/tui/views/publickey/crud.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ func NewCrud(c client.Client, rc router.Controll) *crud.Crud[recordT, recordCrea
157157
},
158158

159159
tablecontroll.New(tablecontroll.Columns[recordT]{
160-
{Title: "Comment", View: func(r recordT) string { return r.publicKey.Comment }},
161-
{Title: "Tags", View: func(r recordT) string { return r.publicKey.Tags.String() }, MaxWidth: 0.5},
162-
{Title: "Algorithm", View: func(r recordT) string { return r.publicKey.Algorithm }},
163-
{Title: "Links (active/total)", View: func(r recordT) string {
160+
{Title: func() string { return "Comment" }, View: func(r recordT) string { return r.publicKey.Comment }},
161+
{Title: func() string { return "Tags" }, View: func(r recordT) string { return r.publicKey.Tags.String() }, MaxWidth: 0.5},
162+
{Title: func() string { return "Algorithm" }, View: func(r recordT) string { return r.publicKey.Algorithm }},
163+
{Title: func() string { return "Links (active/total)" }, View: func(r recordT) string {
164164
return fmt.Sprintf("%d/%d", r.activeLinkCount, r.totalLinkCount)
165165
}},
166-
{Title: "Accounts (active/total)", View: func(r recordT) string {
166+
{Title: func() string { return "Accounts (active/total)" }, View: func(r recordT) string {
167167
return fmt.Sprintf("%d/%d", r.activeLinkedAccountCount, r.totalLinkedAccountCount)
168168
}},
169169
}).RenderBubblesTable,

0 commit comments

Comments
 (0)