Skip to content

Commit

Permalink
chore: remove the ugly hack columnsKeys in taskstable (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
prgres authored Dec 11, 2023
2 parents 01571d4 + bf74fee commit 1227323
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/bubbles v0.16.1
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/evertras/bubble-table v0.15.4
github.com/evertras/bubble-table v0.15.5
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/kkyr/fig v0.3.2
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/evertras/bubble-table v0.15.4 h1:iqsVVnSKNcbVV0miLJhtME2S8SNHE/O7UL7n2OairJI=
github.com/evertras/bubble-table v0.15.4/go.mod h1:SPOZKbIpyYWPHBNki3fyNpiPBQkvkULAtOT7NTD5fKY=
github.com/evertras/bubble-table v0.15.5 h1:vMsjp0FI7lEyzJG8fT2WRmg0OhVfgMf1a0P7r/ekXPY=
github.com/evertras/bubble-table v0.15.5/go.mod h1:SPOZKbIpyYWPHBNki3fyNpiPBQkvkULAtOT7NTD5fKY=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
Expand Down
17 changes: 10 additions & 7 deletions ui/widgets/tasks-table/taskstable.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type Model struct {
WidgetId common.WidgetId
SelectedTab taskstabs.Tab
requiredColsKeys []string
columnsKeys []string // TODO: ugly hack since table.Column does not expose any Getters. Waits for https://github.com/Evertras/bubble-table/issues/157
columns []table.Column
requiredCols []table.Column
table table.Model
Expand Down Expand Up @@ -138,7 +137,6 @@ func InitialModel(ctx *context.UserContext, logger *log.Logger) Model {
ctx: ctx,
table: t,
columns: columns,
columnsKeys: []string{},
requiredCols: requiredCols,
requiredColsKeys: requiredColsKeys,
tasks: map[string][]clickup.Task{},
Expand All @@ -155,6 +153,15 @@ func (m *Model) RefreshTable() tea.Cmd {
return m.refreshTable()
}

func (m *Model) GetColumnsKey() []string {
r := make([]string, len(m.columns))
for i, c := range m.columns {
r[i] = c.Key()
}

return r
}

func (m *Model) refreshTable() tea.Cmd {
m.log.Info("Synchonizing table...")
tasks := m.getSelectedViewTasks()
Expand All @@ -166,7 +173,7 @@ func (m *Model) refreshTable() tea.Cmd {
return HideTableCmd()
}

items := taskListToRows(tasks, m.columnsKeys)
items := taskListToRows(tasks, m.GetColumnsKey())

m.SelectedTaskIndex = m.table.GetHighlightedRowIndex()

Expand Down Expand Up @@ -238,9 +245,6 @@ func (m Model) Update(msg tea.Msg) (common.Widget, tea.Cmd) {
columns := []table.Column{}
columns = append(columns, m.requiredCols...)

columnsKeys := []string{}
columnsKeys = append(columnsKeys, m.requiredColsKeys...)

// if m.autoColumns {
// tab := viewtabs.Tab(msg)
// for _, field := range view.Columns.Fields {
Expand All @@ -256,7 +260,6 @@ func (m Model) Update(msg tea.Msg) (common.Widget, tea.Cmd) {

m.log.Infof("Columns: %d", len(columns))
m.columns = columns
m.columnsKeys = columnsKeys

m.SelectedTab = tab
tasks := m.tasks[tab.Id]
Expand Down

0 comments on commit 1227323

Please sign in to comment.