more refactoring

This commit is contained in:
Jesse Duffield 2022-10-23 12:48:14 -07:00
parent 751dbef42e
commit dfff845469
3 changed files with 22 additions and 5 deletions

View file

@ -129,11 +129,13 @@ func (gui *Gui) infoSectionChildren(informationStr string, appStatus string) []*
} }
func (gui *Gui) sideViewNames() []string { func (gui *Gui) sideViewNames() []string {
if gui.DockerCommand.InDockerComposeProject { visibleSidePanels := lo.Filter(gui.allSidePanels(), func(panel ISideListPanel, _ int) bool {
return []string{"project", "services", "containers", "images", "volumes"} return !panel.IsHidden()
} else { })
return []string{"project", "containers", "images", "volumes"}
} return lo.Map(visibleSidePanels, func(panel ISideListPanel, _ int) string {
return panel.View().Name()
})
} }
func (gui *Gui) sidePanelChildren(width int, height int) []*boxlayout.Box { func (gui *Gui) sidePanelChildren(width int, height int) []*boxlayout.Box {

View file

@ -76,6 +76,9 @@ type SideListPanel[T comparable] struct {
// set this to true if you don't want to allow manual filtering via '/' // set this to true if you don't want to allow manual filtering via '/'
disableFilter bool disableFilter bool
// This can be nil if you want to always show the panel
hide func() bool
} }
type ISideListPanel interface { type ISideListPanel interface {
@ -85,6 +88,7 @@ type ISideListPanel interface {
Refocus() Refocus()
RerenderList() error RerenderList() error
IsFilterDisabled() bool IsFilterDisabled() bool
IsHidden() bool
OnNextLine() error OnNextLine() error
OnPrevLine() error OnPrevLine() error
OnClick() error OnClick() error
@ -307,3 +311,11 @@ func (self *SideListPanel[T]) SetContextIndex(index int) {
func (self *SideListPanel[T]) IsFilterDisabled() bool { func (self *SideListPanel[T]) IsFilterDisabled() bool {
return self.disableFilter return self.disableFilter
} }
func (self *SideListPanel[T]) IsHidden() bool {
if self.hide == nil {
return false
}
return self.hide()
}

View file

@ -90,6 +90,9 @@ func (gui *Gui) getServicesPanel() *SideListPanel[*commands.Service] {
utils.ColoredString(cont.DisplayPorts(), color.FgYellow), utils.ColoredString(cont.DisplayPorts(), color.FgYellow),
} }
}, },
hide: func() bool {
return !gui.DockerCommand.InDockerComposeProject
},
} }
} }