Fixed styling of the other tools
This commit is contained in:
parent
809f9adfea
commit
eadf8d1720
19 changed files with 231 additions and 105 deletions
|
|
@ -129,12 +129,12 @@ func (c *TableReadController) ExportCSV(filename string) tea.Cmd {
|
|||
cw := csv.NewWriter(f)
|
||||
defer cw.Flush()
|
||||
|
||||
columns := resultSet.Columns
|
||||
columns := resultSet.Columns()
|
||||
if err := cw.Write(columns); err != nil {
|
||||
return events.Error(errors.Wrapf(err, "cannot export to '%v'", filename))
|
||||
}
|
||||
|
||||
row := make([]string, len(resultSet.Columns))
|
||||
row := make([]string, len(columns))
|
||||
for _, item := range resultSet.Items() {
|
||||
for i, col := range columns {
|
||||
row[i], _ = item.AttributeValueAsString(col)
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ func (twc *TableWriteController) SetStringValue(idx int, key string) tea.Cmd {
|
|||
twc.state.withResultSet(func(set *models.ResultSet) {
|
||||
set.Items()[idx][key] = &types.AttributeValueMemberS{Value: value}
|
||||
set.SetDirty(idx, true)
|
||||
set.RefreshColumns()
|
||||
})
|
||||
return ResultSetUpdated{}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package models
|
||||
|
||||
import "sort"
|
||||
|
||||
type ResultSet struct {
|
||||
TableInfo *TableInfo
|
||||
Query Queryable
|
||||
Columns []string
|
||||
TableInfo *TableInfo
|
||||
Query Queryable
|
||||
//Columns []string
|
||||
items []Item
|
||||
attributes []ItemAttribute
|
||||
|
||||
columns []string
|
||||
}
|
||||
|
||||
type Queryable interface {
|
||||
|
|
@ -75,3 +79,46 @@ func (rs *ResultSet) MarkedItems() []Item {
|
|||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func (rs *ResultSet) Columns() []string {
|
||||
if rs.columns == nil {
|
||||
rs.RefreshColumns()
|
||||
}
|
||||
return rs.columns
|
||||
}
|
||||
|
||||
func (rs *ResultSet) RefreshColumns() {
|
||||
seenColumns := make(map[string]int)
|
||||
seenColumns[rs.TableInfo.Keys.PartitionKey] = 0
|
||||
if rs.TableInfo.Keys.SortKey != "" {
|
||||
seenColumns[rs.TableInfo.Keys.SortKey] = 1
|
||||
}
|
||||
|
||||
for _, definedAttribute := range rs.TableInfo.DefinedAttributes {
|
||||
if _, seen := seenColumns[definedAttribute]; !seen {
|
||||
seenColumns[definedAttribute] = len(seenColumns)
|
||||
}
|
||||
}
|
||||
|
||||
otherColsRank := len(seenColumns)
|
||||
for _, result := range rs.items {
|
||||
for k := range result {
|
||||
if _, isSeen := seenColumns[k]; !isSeen {
|
||||
seenColumns[k] = otherColsRank
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
columns := make([]string, 0, len(seenColumns))
|
||||
for k := range seenColumns {
|
||||
columns = append(columns, k)
|
||||
}
|
||||
sort.Slice(columns, func(i, j int) bool {
|
||||
if seenColumns[columns[i]] == seenColumns[columns[j]] {
|
||||
return columns[i] < columns[j]
|
||||
}
|
||||
return seenColumns[columns[i]] < seenColumns[columns[j]]
|
||||
})
|
||||
|
||||
rs.columns = columns
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package tables
|
|||
import (
|
||||
"context"
|
||||
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/lmika/awstools/internal/dynamo-browse/models"
|
||||
|
|
@ -55,46 +54,47 @@ func (s *Service) doScan(ctx context.Context, tableInfo *models.TableInfo, expr
|
|||
}
|
||||
|
||||
// Get the columns
|
||||
seenColumns := make(map[string]int)
|
||||
seenColumns[tableInfo.Keys.PartitionKey] = 0
|
||||
if tableInfo.Keys.SortKey != "" {
|
||||
seenColumns[tableInfo.Keys.SortKey] = 1
|
||||
}
|
||||
|
||||
for _, definedAttribute := range tableInfo.DefinedAttributes {
|
||||
if _, seen := seenColumns[definedAttribute]; !seen {
|
||||
seenColumns[definedAttribute] = len(seenColumns)
|
||||
}
|
||||
}
|
||||
|
||||
otherColsRank := len(seenColumns)
|
||||
for _, result := range results {
|
||||
for k := range result {
|
||||
if _, isSeen := seenColumns[k]; !isSeen {
|
||||
seenColumns[k] = otherColsRank
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
columns := make([]string, 0, len(seenColumns))
|
||||
for k := range seenColumns {
|
||||
columns = append(columns, k)
|
||||
}
|
||||
sort.Slice(columns, func(i, j int) bool {
|
||||
if seenColumns[columns[i]] == seenColumns[columns[j]] {
|
||||
return columns[i] < columns[j]
|
||||
}
|
||||
return seenColumns[columns[i]] < seenColumns[columns[j]]
|
||||
})
|
||||
//seenColumns := make(map[string]int)
|
||||
//seenColumns[tableInfo.Keys.PartitionKey] = 0
|
||||
//if tableInfo.Keys.SortKey != "" {
|
||||
// seenColumns[tableInfo.Keys.SortKey] = 1
|
||||
//}
|
||||
//
|
||||
//for _, definedAttribute := range tableInfo.DefinedAttributes {
|
||||
// if _, seen := seenColumns[definedAttribute]; !seen {
|
||||
// seenColumns[definedAttribute] = len(seenColumns)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//otherColsRank := len(seenColumns)
|
||||
//for _, result := range results {
|
||||
// for k := range result {
|
||||
// if _, isSeen := seenColumns[k]; !isSeen {
|
||||
// seenColumns[k] = otherColsRank
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//columns := make([]string, 0, len(seenColumns))
|
||||
//for k := range seenColumns {
|
||||
// columns = append(columns, k)
|
||||
//}
|
||||
//sort.Slice(columns, func(i, j int) bool {
|
||||
// if seenColumns[columns[i]] == seenColumns[columns[j]] {
|
||||
// return columns[i] < columns[j]
|
||||
// }
|
||||
// return seenColumns[columns[i]] < seenColumns[columns[j]]
|
||||
//})
|
||||
|
||||
models.Sort(results, tableInfo)
|
||||
|
||||
resultSet := &models.ResultSet{
|
||||
TableInfo: tableInfo,
|
||||
Query: expr,
|
||||
Columns: columns,
|
||||
//Columns: columns,
|
||||
}
|
||||
resultSet.SetItems(results)
|
||||
resultSet.RefreshColumns()
|
||||
|
||||
return resultSet, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,11 +89,21 @@ func (m *Model) updateViewportToSelectedMessage() {
|
|||
|
||||
viewportContent := &strings.Builder{}
|
||||
tabWriter := tabwriter.NewWriter(viewportContent, 0, 1, 1, ' ', 0)
|
||||
for _, colName := range m.currentResultSet.Columns {
|
||||
|
||||
seenColumns := make(map[string]struct{})
|
||||
for _, colName := range m.currentResultSet.Columns() {
|
||||
seenColumns[colName] = struct{}{}
|
||||
if r := m.selectedItem.Renderer(colName); r != nil {
|
||||
m.renderItem(tabWriter, "", colName, r)
|
||||
}
|
||||
}
|
||||
for k, _ := range m.selectedItem {
|
||||
if _, seen := seenColumns[k]; !seen {
|
||||
if r := m.selectedItem.Renderer(k); r != nil {
|
||||
m.renderItem(tabWriter, "", k, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tabWriter.Flush()
|
||||
m.viewport.Width = m.w
|
||||
|
|
|
|||
|
|
@ -48,11 +48,11 @@ type columnModel struct {
|
|||
}
|
||||
|
||||
func (cm columnModel) Len() int {
|
||||
return len(cm.m.resultSet.Columns[cm.m.colOffset:])
|
||||
return len(cm.m.resultSet.Columns()[cm.m.colOffset:])
|
||||
}
|
||||
|
||||
func (cm columnModel) Header(index int) string {
|
||||
return cm.m.resultSet.Columns[cm.m.colOffset+index]
|
||||
return cm.m.resultSet.Columns()[cm.m.colOffset+index]
|
||||
}
|
||||
|
||||
func New(uiStyles styles.Styles) *Model {
|
||||
|
|
@ -124,8 +124,8 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
func (m *Model) setLeftmostDisplayedColumn(newCol int) {
|
||||
if newCol < 0 {
|
||||
m.colOffset = 0
|
||||
} else if newCol >= len(m.resultSet.Columns) {
|
||||
m.colOffset = len(m.resultSet.Columns) - 1
|
||||
} else if newCol >= len(m.resultSet.Columns()) {
|
||||
m.colOffset = len(m.resultSet.Columns()) - 1
|
||||
} else {
|
||||
m.colOffset = newCol
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ func (mtr itemTableRow) Render(w io.Writer, model table.Model, index int) {
|
|||
metaInfoStyle := style.Copy().Inherit(metaInfoStyle)
|
||||
|
||||
sb := strings.Builder{}
|
||||
for i, colName := range mtr.resultSet.Columns[mtr.model.colOffset:] {
|
||||
for i, colName := range mtr.resultSet.Columns()[mtr.model.colOffset:] {
|
||||
if i > 0 {
|
||||
sb.WriteString(style.Render("\t"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue