Fixed styling of the other tools

This commit is contained in:
Leon Mika 2022-06-27 16:05:59 +10:00
parent 809f9adfea
commit eadf8d1720
19 changed files with 231 additions and 105 deletions

View file

@ -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
}