Skip to content

Commit

Permalink
use footer for pagination info
Browse files Browse the repository at this point in the history
  • Loading branch information
jakedoublev committed Dec 4, 2024
1 parent 9a859ce commit 40b5085
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 53 deletions.
6 changes: 2 additions & 4 deletions cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,12 @@ func getMetadataUpdateBehavior() common.MetadataUpdateEnum {
}

// HandleSuccess prints a success message according to the configured format (styled table or JSON)
func HandleSuccess(command *cobra.Command, id string, t table.Model, policyObject interface{}, joinable ...table.Model) {
func HandleSuccess(command *cobra.Command, id string, t table.Model, policyObject interface{}) {
c := cli.New(command, []string{})
if OtdfctlCfg.Output.Format == config.OutputJSON || configFlagOverrides.OutputFormatJSON {
c.ExitWithJSON(policyObject)
}
tables := []table.Model{t}
tables = append(tables, joinable...)
cli.PrintSuccessTable(command, id, tables...)
cli.PrintSuccessTable(command, id, t)
}

// Adds reusable create/update label flags to a Policy command and the optional force-replace-labels flag for updates only
Expand Down
5 changes: 2 additions & 3 deletions cmd/policy-attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ func policy_listAttributes(cmd *cobra.Command, args []string) {
}))
}
t = t.WithRows(rows)
footer := cli.WithListPaginationFooter(t, page)
HandleSuccess(cmd, "", t, attrs, footer)
// cli.WithListPaginationFooter(t, page)
t = cli.WithListPaginationFooter(t, page)
HandleSuccess(cmd, "", t, attrs)
}

func policy_deactivateAttribute(cmd *cobra.Command, args []string) {
Expand Down
35 changes: 0 additions & 35 deletions pkg/cli/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,8 @@ func WithListPaginationFooter(t table.Model, p *policy.PageResponse) table.Model
info = append(info, fmt.Sprintf("Next Offset: %d", p.GetNextOffset()))
}

columns := []table.Column{}
for _, c := range info {
columns = append(columns, table.NewFlexColumn(c, c, FlexColumnWidthOne))
}

content := strings.Join(info, " | ")
// content := table.New(columns).
// WithBaseStyle(styleTable).
// BorderRounded().
// WithTargetWidth(len(info) * 20).
// WithNoPagination().View()

leftAligned := lipgloss.NewStyle().Align(lipgloss.Left)
return t.WithStaticFooter(content).WithBaseStyle(leftAligned)
}

// func WithListPaginationFooter(t table.Model, p *policy.PageResponse) table.Model {
// info := []string{
// fmt.Sprintf("Total: %d", p.GetTotal()),
// fmt.Sprintf("Current Offset: %d", p.GetCurrentOffset()),
// }
// if p.GetNextOffset() > 0 {
// info = append(info, fmt.Sprintf("Next Offset: %d", p.GetNextOffset()))
// }

// columns := []table.Column{}
// for _, c := range info {
// columns = append(columns, table.NewFlexColumn(c, c, FlexColumnWidthOne))
// }

// // content := strings.Join(info, " | ")
// content := table.New(columns).
// WithBaseStyle(styleTable).
// BorderRounded().
// WithTargetWidth(len(info) * 20).
// WithNoPagination()

// // fmt.Println(lipgloss.JoinVertical(lipgloss.Left, t.View(), content.View()))
// return content
// }
15 changes: 4 additions & 11 deletions pkg/cli/tabular.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func getJSONHelper(command string) string {
return fmt.Sprintf("Use '%s --json' to see all properties", command)
}

func PrintSuccessTable(cmd *cobra.Command, id string, joinableTables ...table.Model) {
func PrintSuccessTable(cmd *cobra.Command, id string, t table.Model) {
parent := cmd.Parent()
resourceShort := parent.Use
resource := parent.Use
Expand Down Expand Up @@ -88,18 +88,11 @@ func PrintSuccessTable(cmd *cobra.Command, id string, joinableTables ...table.Mo
successMessage := SuccessMessage(msg.verb)
jsonDirections := FooterMessage(msg.helper)

if len(joinableTables) == 0 {
ts := t.View()
if ts == "" {
fmt.Println(lipgloss.JoinVertical(lipgloss.Top, successMessage, jsonDirections))
return
}

printable := []string{
successMessage,
}
for _, t := range joinableTables {
printable = append(printable, t.View())
}
printable = append(printable, jsonDirections)

fmt.Println(lipgloss.JoinVertical(lipgloss.Top, printable...))
fmt.Println(lipgloss.JoinVertical(lipgloss.Top, successMessage, ts, jsonDirections))
}

0 comments on commit 40b5085

Please sign in to comment.