Merge pull request #776 from jesseduffield/copilot/disable-forced-project-view

Hide project/services panels when not in a docker-compose project directory
This commit is contained in:
Jesse Duffield 2026-04-19 11:55:51 +10:00 committed by GitHub
commit 9134abeefd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 59 additions and 29 deletions

View file

@ -176,7 +176,9 @@ func (gui *Gui) sidePanelChildren(width int, height int) []*boxlayout.Box {
} }
// The project panel is compact (Size: 3) when not focused, but expands // The project panel is compact (Size: 3) when not focused, but expands
// when focused to show the list of projects. // when focused to show the list of projects. This only applies when the
// project panel is actually visible (i.e. we are inside a compose project).
if len(sideWindowNames) > 0 && sideWindowNames[0] == "project" {
projectBox := &boxlayout.Box{ projectBox := &boxlayout.Box{
Window: sideWindowNames[0], Window: sideWindowNames[0],
Size: 3, Size: 3,
@ -193,6 +195,11 @@ func (gui *Gui) sidePanelChildren(width int, height int) []*boxlayout.Box {
}, lo.Map(sideWindowNames[1:], func(window string, _ int) *boxlayout.Box { }, lo.Map(sideWindowNames[1:], func(window string, _ int) *boxlayout.Box {
return accordionBox(&boxlayout.Box{Window: window, Weight: 1}) return accordionBox(&boxlayout.Box{Window: window, Weight: 1})
})...) })...)
}
return lo.Map(sideWindowNames, func(window string, _ int) *boxlayout.Box {
return accordionBox(&boxlayout.Box{Window: window, Weight: 1})
})
} else { } else {
squashedHeight := 1 squashedHeight := 1
if height >= 21 { if height >= 21 {

View file

@ -83,6 +83,20 @@ func (gui *Gui) getContainersPanel() *panels.SideListPanel[*commands.Container]
return sortContainers(a, b, gui.Config.UserConfig.Gui.LegacySortContainers) return sortContainers(a, b, gui.Config.UserConfig.Gui.LegacySortContainers)
}, },
Filter: func(container *commands.Container) bool { Filter: func(container *commands.Container) bool {
if !gui.State.ShowExitedContainers && container.Container.State == "exited" {
return false
}
// Only apply project and standalone filtering when we are inside a
// docker-compose project. Outside of a compose project all
// containers are shown in a flat list regardless of which compose
// project they belong to.
if gui.DockerCommand.InDockerComposeProject {
// This check must be inside the InDockerComposeProject guard:
// outside a compose project, services are still derived from
// container labels, so compose-managed containers from other
// projects would be incorrectly hidden.
//
// Note that this is O(N*M) time complexity where N is the number of services // Note that this is O(N*M) time complexity where N is the number of services
// and M is the number of containers. We expect N to be small but M may be large, // and M is the number of containers. We expect N to be small but M may be large,
// so we will need to keep an eye on this. // so we will need to keep an eye on this.
@ -90,10 +104,6 @@ func (gui *Gui) getContainersPanel() *panels.SideListPanel[*commands.Container]
return false return false
} }
if !gui.State.ShowExitedContainers && container.Container.State == "exited" {
return false
}
// Filter by selected project. Containers with no project (truly // Filter by selected project. Containers with no project (truly
// standalone, not from any compose project) are always shown. // standalone, not from any compose project) are always shown.
selectedProject := gui.getSelectedProjectName() selectedProject := gui.getSelectedProjectName()
@ -103,6 +113,7 @@ func (gui *Gui) getContainersPanel() *panels.SideListPanel[*commands.Container]
if selectedProject != "" && container.ProjectName != "" && container.ProjectName != selectedProject { if selectedProject != "" && container.ProjectName != "" && container.ProjectName != selectedProject {
return false return false
} }
}
return true return true
}, },

View file

@ -58,6 +58,14 @@ func (gui *Gui) getProjectPanel() *panels.SideListPanel[*commands.Project] {
// containers to show only those belonging to the selected project. // containers to show only those belonging to the selected project.
return gui.renderContainersAndServices() return gui.renderContainersAndServices()
}, },
Hide: func() bool {
// Only show the project panel when we are inside a docker-compose
// project directory. When launched outside of a compose project
// there is no meaningful local project to display, so we hide the
// panel and let the containers panel show all containers in a flat
// list (matching the behaviour from before v0.25).
return !gui.DockerCommand.InDockerComposeProject
},
} }
} }

View file

@ -90,8 +90,12 @@ func (gui *Gui) getServicesPanel() *panels.SideListPanel[*commands.Service] {
return presentation.GetServiceDisplayStrings(&gui.Config.UserConfig.Gui, service) return presentation.GetServiceDisplayStrings(&gui.Config.UserConfig.Gui, service)
}, },
Hide: func() bool { Hide: func() bool {
// Show services panel if there are any compose projects (local or discovered) // Only show the services panel when we are inside a docker-compose
return !gui.DockerCommand.InDockerComposeProject && len(gui.Panels.Services.List.GetAllItems()) == 0 // project directory. When launched outside of a compose project
// there is no local project context, so the panel is hidden and
// all containers are shown in a flat list (matching pre-v0.25
// behaviour).
return !gui.DockerCommand.InDockerComposeProject
}, },
} }
} }