Skip to content

Commit 7e3842f

Browse files
fix(*): minor improvements
1 parent f33dd3a commit 7e3842f

File tree

6 files changed

+36
-45
lines changed

6 files changed

+36
-45
lines changed

Diff for: app/client/client.go

+27-30
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ type client struct {
6464
config commander.Config
6565
timeout time.Duration
6666

67-
resources commander.ResourceMap
68-
factory util.Factory
67+
factory util.Factory
6968
}
7069

7170
func (c client) CurrentNamespace() (string, error) {
@@ -103,37 +102,35 @@ func (c client) NewRequest(resource *commander.Resource) (*rest.Request, error)
103102
}
104103

105104
func (c client) Resources() (commander.ResourceMap, error) {
106-
if c.resources == nil {
107-
discoveryClient, err := c.factory.ToDiscoveryClient()
108-
if err != nil {
109-
return nil, err
110-
}
111-
lists, err := discoveryClient.ServerPreferredResources()
112-
if err != nil {
113-
return nil, err
114-
}
115-
resources := make(commander.ResourceMap)
116-
117-
for _, list := range lists {
118-
for _, res := range list.APIResources {
119-
gv, err := schema.ParseGroupVersion(list.GroupVersion)
120-
if err != nil {
121-
return nil, err
122-
}
123-
124-
gk := schema.GroupKind{Group: gv.Group, Kind: res.Kind}
125-
resources[gk] = &commander.Resource{
126-
Namespaced: res.Namespaced,
127-
Resource: res.Name,
128-
Gk: gk,
129-
Gvk: schema.GroupVersionKind{Group: gv.Group, Version: gv.Version, Kind: res.Kind},
130-
Verbs: res.Verbs,
131-
}
105+
discoveryClient, err := c.factory.ToDiscoveryClient()
106+
if err != nil {
107+
return nil, err
108+
}
109+
lists, err := discoveryClient.ServerPreferredResources()
110+
if err != nil {
111+
return nil, err
112+
}
113+
resources := make(commander.ResourceMap)
114+
115+
for _, list := range lists {
116+
for _, res := range list.APIResources {
117+
gv, err := schema.ParseGroupVersion(list.GroupVersion)
118+
if err != nil {
119+
return nil, err
120+
}
121+
122+
gk := schema.GroupKind{Group: gv.Group, Kind: res.Kind}
123+
resources[gk] = &commander.Resource{
124+
Namespaced: res.Namespaced,
125+
Resource: res.Name,
126+
Gk: gk,
127+
Gvk: schema.GroupVersionKind{Group: gv.Group, Version: gv.Version, Kind: res.Kind},
128+
Verbs: res.Verbs,
132129
}
133130
}
134-
c.resources = resources
135131
}
136-
return c.resources, nil
132+
133+
return resources, nil
137134
}
138135

139136
func (c client) Get(ctx context.Context, resource *commander.Resource, namespace string, name string, out runtime.Object) error {

Diff for: app/ui/resourceMenu/resource_menu.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ func NewResourcesMenu(workspace commander.Workspace, onSelect SelectFunc, select
149149
}
150150

151151
func (r *ResourceMenu) UpdateMenu(items []*pb.Resource) ([]commander.Operation, error) {
152-
r.Lock()
153-
defer r.Unlock()
154152
var ops []commander.Operation
155153

156154
ops = append(ops,
@@ -162,6 +160,8 @@ func (r *ResourceMenu) UpdateMenu(items []*pb.Resource) ([]commander.Operation,
162160
if err != nil {
163161
return nil, err
164162
}
163+
r.Lock()
164+
defer r.Unlock()
165165
r.items = []*resourceItem{}
166166
r.clusterItems = 0
167167
var clusterItems, namespacedItems []*resourceItem
@@ -245,6 +245,7 @@ func (r *ResourceMenu) OnKeyPress(row commander.Row, event *tcell.EventKey) bool
245245
}
246246
}
247247
r.saveItems()
248+
r.workspace.Status().Info("Deleted.")
248249
} else {
249250
r.workspace.Status().Info("Cancelled.")
250251
}
@@ -272,7 +273,7 @@ func (r *ResourceMenu) OnKeyPress(row commander.Row, event *tcell.EventKey) bool
272273
r.items = append(r.items, add)
273274
} else {
274275
newItems := append(r.items[:r.clusterItems], add)
275-
newItems = append(newItems, r.items[r.clusterItems:]...)
276+
newItems = append(newItems, r.items[r.clusterItems+1:]...)
276277
r.items = newItems
277278
}
278279
r.saveItems()

Diff for: app/ui/resourceMenu/resource_picker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func newResourcePicker(container commander.ResourceContainer, f GroupKindFunc) (
3838
}, true))
3939
resMap[res.Gk.String()] = res
4040
}
41-
lt := listTable.NewStaticListTable(columns, rows, listTable.NoHorizontalScroll|listTable.WithFilter|listTable.WithHeaders, container.ScreenHandler())
41+
lt := listTable.NewStaticListTable(columns, rows, listTable.NoHorizontalScroll|listTable.WithFilter|listTable.WithHeaders|listTable.StartFilter, container.ScreenHandler())
4242
lt.BindOnKeyPress(func(row commander.Row, event *tcell.EventKey) bool {
4343
if row == nil {
4444
return false

Diff for: app/ui/resources/namespace/namespace_picker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func PickNamespace(workspace commander.Workspace, resource *commander.Resource,
2222
}
2323

2424
func NewNamespacePicker(container commander.ResourceContainer, resource *commander.Resource, f NamespaceFunc) (*listTable.ResourceListTable, error) {
25-
rlt := listTable.NewResourceListTable(container, resource, listTable.NameOnly|listTable.NoActions|listTable.NoWatch)
25+
rlt := listTable.NewResourceListTable(container, resource, listTable.NameOnly|listTable.NoActions|listTable.NoWatch|listTable.WithFilter|listTable.StartFilter)
2626
rlt.BindOnKeyPress(func(row commander.Row, event *tcell.EventKey) bool {
2727
if event.Key() == tcell.KeyEnter {
2828
go func() {

Diff for: app/ui/widgets/listTable/listTable.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545
NoActions
4646
NoWatch
4747
WithFilter
48+
StartFilter
4849
)
4950

5051
func (tf TableFormat) Has(flag TableFormat) bool {
@@ -102,6 +103,7 @@ func NewListTable(prov commander.RowProvider, format TableFormat, screen command
102103
preloader: NewPreloader(screen),
103104
rowProvider: prov,
104105
screen: screen,
106+
filterMode: format.Has(StartFilter),
105107
}
106108
lt.Render()
107109
return lt
@@ -292,7 +294,7 @@ func (lt *ListTable) BindOnChange(rowFunc RowFunc) {
292294
}
293295

294296
func (lt *ListTable) resetFilter() {
295-
lt.filterMode = false
297+
lt.filterMode = lt.format.Has(StartFilter)
296298
lt.filter = ""
297299
lt.Render()
298300
lt.reindexSelection()

Diff for: app/ui/workspace/workspace.go

-9
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,6 @@ func (w *workspace) HandleEvent(e tcell.Event) bool {
151151
switch ev.Key() {
152152
case tcell.KeyCtrlN, tcell.KeyF2:
153153
namespace.PickNamespace(w, w.namespaceResource, w.SwitchNamespace)
154-
case tcell.KeyCtrlP:
155-
w.focus.Focus(w.menu)
156-
w.menu.SelectItem(schema.GroupKind{Kind: "Pod"}.String())
157-
case tcell.KeyCtrlD:
158-
w.focus.Focus(w.menu)
159-
w.menu.SelectItem(schema.GroupKind{Kind: "Deployment", Group: "apps"}.String())
160-
case tcell.KeyCtrlI:
161-
w.focus.Focus(w.menu)
162-
w.menu.SelectItem(schema.GroupKind{Kind: "Ingress", Group: "networking.k8s.io"}.String())
163154
default:
164155
if ev.Rune() == '?' {
165156
help.ShowHelpPopup(w)

0 commit comments

Comments
 (0)