From 1cf76c6356821b3f91ec32698e2696cb57e3013d Mon Sep 17 00:00:00 2001 From: Kyriakos Akriotis Date: Wed, 30 Sep 2026 14:25:12 +0200 Subject: [PATCH] support command status labels for in-tree and plugin resources #77 --- internal/plugins/resource.go | 2 ++ internal/resource/commands.go | 2 ++ internal/resource/resource.go | 1 + internal/ui/app.go | 5 +++++ internal/ui/commands.go | 18 +++++++++++++----- pluginsdk/grpc_client.go | 2 ++ pluginsdk/grpc_server.go | 2 ++ pluginsdk/plugin.go | 1 + pluginsdk/proto/plugin.pb.go | 13 +++++++++++-- pluginsdk/proto/plugin.proto | 1 + 10 files changed, 40 insertions(+), 7 deletions(-) diff --git a/internal/plugins/resource.go b/internal/plugins/resource.go index e4cc527..55b02b1 100644 --- a/internal/plugins/resource.go +++ b/internal/plugins/resource.go @@ -60,6 +60,7 @@ func (r *pluginResource) Commands() []resource.Command { Key: command.Key, Description: command.Description, Default: command.Default, + StatusLabel: command.StatusLabel, }) } @@ -92,6 +93,7 @@ func (r *pluginResource) Execute(command resource.Command, row resource.Row) tea Key: command.Key, Description: command.Description, Default: command.Default, + StatusLabel: command.StatusLabel, }, pluginsdk.Row{ ID: row.ID, Fields: row.Fields, diff --git a/internal/resource/commands.go b/internal/resource/commands.go index d2e0971..9d90c1b 100644 --- a/internal/resource/commands.go +++ b/internal/resource/commands.go @@ -31,3 +31,5 @@ type NavigateScopedMsg struct { type ErrorMsg struct { Err error } + +type CommandCompletedMsg struct{} diff --git a/internal/resource/resource.go b/internal/resource/resource.go index 99930b7..4e78198 100644 --- a/internal/resource/resource.go +++ b/internal/resource/resource.go @@ -22,6 +22,7 @@ type Command struct { Key string Description string Default bool + StatusLabel string } type Resource interface { diff --git a/internal/ui/app.go b/internal/ui/app.go index c13ad40..ccedb07 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -536,6 +536,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil + case resource.CommandCompletedMsg: + m.showLoading = false + m.loadingLabel = "" + return m, nil + } var cmd tea.Cmd diff --git a/internal/ui/commands.go b/internal/ui/commands.go index f8e7f02..8e80444 100644 --- a/internal/ui/commands.go +++ b/internal/ui/commands.go @@ -104,18 +104,26 @@ func (m *Model) executeResourceCommand(key string) tea.Cmd { if command.Key == key { row := m.resourceRows[cursor] + m.showLoading = true + m.loadingLabel = command.StatusLabel + if m.loadingLabel == "" { + m.loadingLabel = "Loading..." + } + if m.resource.Kind() == "contexts" && key == "a" { m.activatingContext = true m.showLoading = true m.loadingLabel = "Connecting to " + row.ID + "..." } - if key == "s" { - m.showLoading = true - m.loadingLabel = "Loading..." - } + cmd := m.resource.Execute(command, row) - return m.resource.Execute(command, row) + return tea.Sequence( + cmd, + func() tea.Msg { + return resource.CommandCompletedMsg{} + }, + ) } } diff --git a/pluginsdk/grpc_client.go b/pluginsdk/grpc_client.go index 567ff32..e3e68e5 100644 --- a/pluginsdk/grpc_client.go +++ b/pluginsdk/grpc_client.go @@ -85,6 +85,7 @@ func (r *grpcResource) Commands() []Command { Key: command.Key, Description: command.Description, Default: command.Default, + StatusLabel: command.StatusLabel, }) } @@ -119,6 +120,7 @@ func (r *grpcResource) Execute(ctx context.Context, command Command, row Row) (R Key: command.Key, Description: command.Description, Default: command.Default, + StatusLabel: command.StatusLabel, }, Row: &pb.Row{ Id: row.ID, diff --git a/pluginsdk/grpc_server.go b/pluginsdk/grpc_server.go index 293e1eb..7015df7 100644 --- a/pluginsdk/grpc_server.go +++ b/pluginsdk/grpc_server.go @@ -63,6 +63,7 @@ func (s *grpcServer) GetResources(context.Context, *pb.Empty) (*pb.Resources, er Key: command.Key, Description: command.Description, Default: command.Default, + StatusLabel: command.StatusLabel, }) } @@ -124,6 +125,7 @@ func (s *grpcServer) Execute(ctx context.Context, request *pb.ExecuteRequest) (* Key: request.Command.Key, Description: request.Command.Description, Default: request.Command.Default, + StatusLabel: request.Command.StatusLabel, }, Row{ ID: request.Row.Id, Fields: request.Row.Fields, diff --git a/pluginsdk/plugin.go b/pluginsdk/plugin.go index c171ad6..f74fc0b 100644 --- a/pluginsdk/plugin.go +++ b/pluginsdk/plugin.go @@ -49,6 +49,7 @@ type Command struct { Key string Description string Default bool + StatusLabel string } type Resource interface { diff --git a/pluginsdk/proto/plugin.pb.go b/pluginsdk/proto/plugin.pb.go index 9d71750..207433b 100644 --- a/pluginsdk/proto/plugin.pb.go +++ b/pluginsdk/proto/plugin.pb.go @@ -430,6 +430,7 @@ type Command struct { Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` Default bool `protobuf:"varint,3,opt,name=default,proto3" json:"default,omitempty"` + StatusLabel string `protobuf:"bytes,4,opt,name=status_label,json=statusLabel,proto3" json:"status_label,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -485,6 +486,13 @@ func (x *Command) GetDefault() bool { return false } +func (x *Command) GetStatusLabel() string { + if x != nil { + return x.StatusLabel + } + return "" +} + type Row struct { state protoimpl.MessageState `protogen:"open.v1"` Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` @@ -958,11 +966,12 @@ const file_plugin_proto_rawDesc = "" + "\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" + "\x05title\x18\x02 \x01(\tR\x05title\x12\x1b\n" + "\tmin_width\x18\x03 \x01(\x05R\bminWidth\x12\x12\n" + - "\x04flex\x18\x04 \x01(\x05R\x04flex\"W\n" + + "\x04flex\x18\x04 \x01(\x05R\x04flex\"z\n" + "\aCommand\x12\x10\n" + "\x03key\x18\x01 \x01(\tR\x03key\x12 \n" + "\vdescription\x18\x02 \x01(\tR\vdescription\x12\x18\n" + - "\adefault\x18\x03 \x01(\bR\adefault\"\x88\x01\n" + + "\adefault\x18\x03 \x01(\bR\adefault\x12!\n" + + "\fstatus_label\x18\x04 \x01(\tR\vstatusLabel\"\x88\x01\n" + "\x03Row\x12\x0e\n" + "\x02id\x18\x01 \x01(\tR\x02id\x126\n" + "\x06fields\x18\x02 \x03(\v2\x1e.o7k.plugin.v1.Row.FieldsEntryR\x06fields\x1a9\n" + diff --git a/pluginsdk/proto/plugin.proto b/pluginsdk/proto/plugin.proto index 8ab6d70..6027b76 100644 --- a/pluginsdk/proto/plugin.proto +++ b/pluginsdk/proto/plugin.proto @@ -59,6 +59,7 @@ message Command { string key = 1; string description = 2; bool default = 3; + string status_label = 4; } message Row {