Skip to content

Commit

Permalink
chore: remove the ugly for columnsKeys in table
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Więcek committed Dec 11, 2023
1 parent c0321a7 commit bf74fee
Showing 1 changed file with 10 additions and 7 deletions.
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 bf74fee

Please sign in to comment.