Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/resources/identity/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package catalog

import (
"context"
"slices"
"strings"

"github.com/akyriako/o7k/internal/openstack"
"github.com/akyriako/o7k/internal/resource"
Expand Down Expand Up @@ -43,6 +45,7 @@ func (r *Resource) Commands() []resource.Command {
{Key: "shift-s", Description: "Service"},
}
}

func (r *Resource) List(_ context.Context) ([]resource.Row, error) {
catalog, err := r.context.ServiceCatalog()
if err != nil {
Expand All @@ -66,6 +69,9 @@ func (r *Resource) List(_ context.Context) ([]resource.Row, error) {
}
}

slices.SortFunc(rows, func(a, b resource.Row) int {
return strings.Compare(a.Fields["url"], b.Fields["url"])
})
return rows, nil
}

Expand Down
5 changes: 5 additions & 0 deletions internal/resources/identity/endpoints/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package endpoints
import (
"context"
"fmt"
"slices"
"strconv"
"strings"

"github.com/akyriako/o7k/internal/openstack"
"github.com/akyriako/o7k/internal/resource"
Expand Down Expand Up @@ -80,6 +82,9 @@ func (r *Resource) List(ctx context.Context) ([]resource.Row, error) {
})
}

slices.SortFunc(rows, func(a, b resource.Row) int {
return strings.Compare(a.Fields["url"], b.Fields["url"])
})
return rows, nil
}

Expand Down
5 changes: 5 additions & 0 deletions internal/resources/identity/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package services
import (
"context"
"fmt"
"slices"
"strconv"
"strings"

"github.com/akyriako/o7k/internal/openstack"
"github.com/akyriako/o7k/internal/resource"
Expand Down Expand Up @@ -78,6 +80,9 @@ func (r *Resource) List(ctx context.Context) ([]resource.Row, error) {
})
}

slices.SortFunc(rows, func(a, b resource.Row) int {
return strings.Compare(a.Fields["type"], b.Fields["type"])
})
return rows, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func New(context *openstack.Context) *Resource {
}

func (r *Resource) Title() string {
return "Share Access Rules"
return "Manila Share Access Rules"
}

func (r *Resource) Kind() string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func New(context *openstack.Context) *Resource {
}

func (r *Resource) Title() string {
return "Share Export Locations"
return "Manila Share Export Locations"
}

func (r *Resource) Kind() string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func New(context *openstack.Context) *Resource {
}

func (r *Resource) Title() string {
return "Share Types"
return "Manila Share Types"
}

func (r *Resource) Kind() string {
Expand Down
4 changes: 4 additions & 0 deletions internal/ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
id: m.resourceRows[cursor].ID,
filter: m.filter,
scope: m.scope,
rows: m.resourceRows,
})
}

Expand All @@ -479,6 +480,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
id: m.resourceRows[cursor].ID,
filter: m.filter,
scope: m.scope,
rows: m.resourceRows,
})
}

Expand All @@ -499,6 +501,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
id: m.resourceRows[cursor].ID,
filter: m.filter,
scope: m.scope,
rows: m.resourceRows,
})
}

Expand All @@ -517,6 +520,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
id: m.resourceRows[cursor].ID,
filter: m.filter,
scope: m.scope,
rows: m.resourceRows,
})
}

Expand Down
52 changes: 41 additions & 11 deletions internal/ui/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/akyriako/o7k/internal/resource"
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
"golang.design/x/clipboard"
)
Expand Down Expand Up @@ -41,6 +42,7 @@ type navigationEntry struct {
id string
filter *resourceFilter
scope resourceScope
rows []resource.Row
}

type resourceFilter struct {
Expand Down Expand Up @@ -225,24 +227,52 @@ func (m *Model) navigateBack() tea.Cmd {
last := len(m.navigation) - 1
entry := m.navigation[last]

r, ok := m.registry.Get(entry.resource)
if !ok {
return nil
}

// I have to clear rows before switching resource schema.
// Resize() will bring the new-old resource's columns in correct dimensions.
m.table.SetRows(nil)

m.navigation = m.navigation[:last]
m.navigateID = entry.id
m.resource = r
m.filter = entry.filter
m.scope = entry.scope
m.resourceRows = entry.rows
m.itemCount = len(entry.rows)

navigation := m.navigation
navigateID := m.navigateID
filter := m.filter
scope := m.scope
m.Resize()

cmd := m.switchResource(entry.resource, entry.scope)
columns := m.resource.Columns()
rows := make([]table.Row, 0, len(entry.rows))
cursor := 0

m.navigation = navigation
m.navigateID = navigateID
m.filter = filter
m.scope = scope
for i, row := range entry.rows {
values := make(table.Row, 0, len(columns))

return cmd
for _, column := range columns {
values = append(values, row.Fields[column.Key])
}

rows = append(rows, values)

if row.ID == entry.id {
cursor = i
}
}

m.table.SetRows(rows)
m.table.SetCursor(cursor)
m.tableXOffset = 0

m.err = nil
m.status = ""
m.loading = false
m.showLoading = false

return nil
}

func filterResourceRows(rows []resource.Row, filter *resourceFilter) []resource.Row {
Expand Down
Loading