Skip to content

Commit

Permalink
fix: Delete custom resource panel. (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
elfgzp authored Nov 27, 2020
1 parent 83a07dd commit 854a277
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
13 changes: 8 additions & 5 deletions pkg/app/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ var (
return nil
},
DimensionFunc: guilib.BeneathView(
serviceViewName,
func(*guilib.Gui, *guilib.View) string {
return serviceViewName
},
reactiveHeight,
migrateTopFunc,
),
Expand Down Expand Up @@ -192,7 +194,7 @@ var (
},
FgColor: gocui.ColorDefault,
DimensionFunc: guilib.BeneathView(
clusterInfoViewName,
aboveViewNameFunc,
reactiveHeight,
migrateTopFunc,
),
Expand Down Expand Up @@ -236,7 +238,7 @@ var (
},
FgColor: gocui.ColorDefault,
DimensionFunc: guilib.BeneathView(
deploymentViewName,
aboveViewNameFunc,
reactiveHeight,
migrateTopFunc,
),
Expand Down Expand Up @@ -291,7 +293,7 @@ var (
return nil
},
DimensionFunc: guilib.BeneathView(
namespaceViewName,
aboveViewNameFunc,
reactiveHeight,
migrateTopFunc,
),
Expand Down Expand Up @@ -339,7 +341,7 @@ func newCustomResourcePanel(resource string) *guilib.View {
return nil
},
DimensionFunc: guilib.BeneathView(
functionViews[len(functionViews)-1],
aboveViewNameFunc,
reactiveHeight,
migrateTopFunc,
),
Expand Down Expand Up @@ -462,6 +464,7 @@ func deleteCustomResourcePanel(gui *guilib.Gui, viewName string) error {
}
}

// Delete navigation options of namespace panel
for index, option := range viewNavigationMap[namespaceViewName] {
if option == customResourcePanel.Title {
viewNavigationMap[namespaceViewName] = append(
Expand Down
12 changes: 10 additions & 2 deletions pkg/app/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ var (
migrateTopCache = map[string]int{}
)

func aboveViewNameFunc(_ *guilib.Gui, view *guilib.View) string {
for index, viewName := range functionViews {
if viewName == view.Name && index != 0 {
return functionViews[index-1]
}
}
return ""
}

func resizeableView(viewName string) bool {
for _, resizeableView := range resizeableViews {
if resizeableView == viewName {
Expand Down Expand Up @@ -58,7 +67,6 @@ func resizePanelHeight(gui *guilib.Gui) error {
return nil
}

// Todo: cache result
func reactiveHeight(gui *guilib.Gui, view *guilib.View) int {
var currentViewName string
currentView := gui.CurrentView()
Expand All @@ -72,7 +80,7 @@ func reactiveHeight(gui *guilib.Gui, view *guilib.View) int {
}

func cacheAbleReactiveHeight(maxHeight int, resizeableViews []string, currentViewName, previousViewName, viewName string) int {
key := fmt.Sprintf("%d,%s,%s,%s,%s", maxHeight, strings.Join(resizeableViews, ","), currentViewName, previousViewName, viewName)
key := fmt.Sprintf("%d,[%s],%s,%s,%s", maxHeight, strings.Join(resizeableViews, ","), currentViewName, previousViewName, viewName)
cacheVal, ok := reactiveHeightCache[key]
if ok {
return cacheVal
Expand Down
3 changes: 2 additions & 1 deletion pkg/gui/dimension.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package gui

// BeneathView BeneathView
func BeneathView(aboveViewName string, heightFunc func(*Gui, *View) int, marginTopFunc func(*Gui, *View) int) func(gui *Gui, view *View) (int, int, int, int) {
func BeneathView(aboveViewNameFunc func(*Gui, *View) string, heightFunc func(*Gui, *View) int, marginTopFunc func(*Gui, *View) int) func(gui *Gui, view *View) (int, int, int, int) {
return func(gui *Gui, view *View) (int, int, int, int) {
aboveViewName := aboveViewNameFunc(gui, view)
aboveX0, _, aboveX1, aboveY1, err := gui.g.ViewPosition(aboveViewName)
if err != nil {
return 0, 0, 0, 0
Expand Down

0 comments on commit 854a277

Please sign in to comment.