From 0b7951b1d910a9d22c5dde0bcfac3e0b886b0064 Mon Sep 17 00:00:00 2001 From: Kyriakos Akriotis Date: Sun, 4 Oct 2026 12:12:20 +0200 Subject: [PATCH 1/2] replace navigate back and entries to hold parent resource rows #91 --- .../accessrules/accessrules.go | 2 +- .../exportlocations/exportlocations.go | 2 +- .../sharedfilesystem/sharetypes/sharetypes.go | 2 +- internal/ui/app.go | 4 ++ internal/ui/commands.go | 52 +++++++++++++++---- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/internal/resources/sharedfilesystem/accessrules/accessrules.go b/internal/resources/sharedfilesystem/accessrules/accessrules.go index d3484f0..6126e95 100644 --- a/internal/resources/sharedfilesystem/accessrules/accessrules.go +++ b/internal/resources/sharedfilesystem/accessrules/accessrules.go @@ -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 { diff --git a/internal/resources/sharedfilesystem/exportlocations/exportlocations.go b/internal/resources/sharedfilesystem/exportlocations/exportlocations.go index eb66cf5..6560b90 100644 --- a/internal/resources/sharedfilesystem/exportlocations/exportlocations.go +++ b/internal/resources/sharedfilesystem/exportlocations/exportlocations.go @@ -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 { diff --git a/internal/resources/sharedfilesystem/sharetypes/sharetypes.go b/internal/resources/sharedfilesystem/sharetypes/sharetypes.go index 24a5e64..1e2c0f7 100644 --- a/internal/resources/sharedfilesystem/sharetypes/sharetypes.go +++ b/internal/resources/sharedfilesystem/sharetypes/sharetypes.go @@ -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 { diff --git a/internal/ui/app.go b/internal/ui/app.go index 474da51..fbbd98c 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -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, }) } @@ -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, }) } @@ -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, }) } @@ -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, }) } diff --git a/internal/ui/commands.go b/internal/ui/commands.go index ab11d2e..48366e7 100644 --- a/internal/ui/commands.go +++ b/internal/ui/commands.go @@ -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" ) @@ -41,6 +42,7 @@ type navigationEntry struct { id string filter *resourceFilter scope resourceScope + rows []resource.Row } type resourceFilter struct { @@ -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 { From b51e72d8ae81d0543869a41008116a3a308a1bee Mon Sep 17 00:00:00 2001 From: Kyriakos Akriotis Date: Sun, 4 Oct 2026 12:34:34 +0200 Subject: [PATCH 2/2] add sorting to keystone catalog, svc and endpoints #91 --- internal/resources/identity/catalog/catalog.go | 6 ++++++ internal/resources/identity/endpoints/endpoints.go | 5 +++++ internal/resources/identity/services/services.go | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/internal/resources/identity/catalog/catalog.go b/internal/resources/identity/catalog/catalog.go index ecaf953..6499542 100644 --- a/internal/resources/identity/catalog/catalog.go +++ b/internal/resources/identity/catalog/catalog.go @@ -2,6 +2,8 @@ package catalog import ( "context" + "slices" + "strings" "github.com/akyriako/o7k/internal/openstack" "github.com/akyriako/o7k/internal/resource" @@ -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 { @@ -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 } diff --git a/internal/resources/identity/endpoints/endpoints.go b/internal/resources/identity/endpoints/endpoints.go index 7dc8025..ed09d45 100644 --- a/internal/resources/identity/endpoints/endpoints.go +++ b/internal/resources/identity/endpoints/endpoints.go @@ -3,7 +3,9 @@ package endpoints import ( "context" "fmt" + "slices" "strconv" + "strings" "github.com/akyriako/o7k/internal/openstack" "github.com/akyriako/o7k/internal/resource" @@ -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 } diff --git a/internal/resources/identity/services/services.go b/internal/resources/identity/services/services.go index 4b40205..e5b8cbe 100644 --- a/internal/resources/identity/services/services.go +++ b/internal/resources/identity/services/services.go @@ -3,7 +3,9 @@ package services import ( "context" "fmt" + "slices" "strconv" + "strings" "github.com/akyriako/o7k/internal/openstack" "github.com/akyriako/o7k/internal/resource" @@ -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 }