Skip to content

Commit 9134abe

Browse files
Merge pull request #776 from jesseduffield/copilot/disable-forced-project-view
Hide project/services panels when not in a docker-compose project directory
2 parents 2ebe384 + 8106125 commit 9134abe

4 files changed

Lines changed: 59 additions & 29 deletions

File tree

pkg/gui/arrangement.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,23 +176,30 @@ func (gui *Gui) sidePanelChildren(width int, height int) []*boxlayout.Box {
176176
}
177177

178178
// The project panel is compact (Size: 3) when not focused, but expands
179-
// when focused to show the list of projects.
180-
projectBox := &boxlayout.Box{
181-
Window: sideWindowNames[0],
182-
Size: 3,
183-
}
184-
if currentWindow == sideWindowNames[0] {
185-
projectBox = &boxlayout.Box{
179+
// when focused to show the list of projects. This only applies when the
180+
// project panel is actually visible (i.e. we are inside a compose project).
181+
if len(sideWindowNames) > 0 && sideWindowNames[0] == "project" {
182+
projectBox := &boxlayout.Box{
186183
Window: sideWindowNames[0],
187-
Weight: 2,
184+
Size: 3,
185+
}
186+
if currentWindow == sideWindowNames[0] {
187+
projectBox = &boxlayout.Box{
188+
Window: sideWindowNames[0],
189+
Weight: 2,
190+
}
188191
}
192+
193+
return append([]*boxlayout.Box{
194+
projectBox,
195+
}, lo.Map(sideWindowNames[1:], func(window string, _ int) *boxlayout.Box {
196+
return accordionBox(&boxlayout.Box{Window: window, Weight: 1})
197+
})...)
189198
}
190199

191-
return append([]*boxlayout.Box{
192-
projectBox,
193-
}, lo.Map(sideWindowNames[1:], func(window string, _ int) *boxlayout.Box {
200+
return lo.Map(sideWindowNames, func(window string, _ int) *boxlayout.Box {
194201
return accordionBox(&boxlayout.Box{Window: window, Weight: 1})
195-
})...)
202+
})
196203
} else {
197204
squashedHeight := 1
198205
if height >= 21 {

pkg/gui/containers_panel.go

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,36 @@ func (gui *Gui) getContainersPanel() *panels.SideListPanel[*commands.Container]
8383
return sortContainers(a, b, gui.Config.UserConfig.Gui.LegacySortContainers)
8484
},
8585
Filter: func(container *commands.Container) bool {
86-
// Note that this is O(N*M) time complexity where N is the number of services
87-
// and M is the number of containers. We expect N to be small but M may be large,
88-
// so we will need to keep an eye on this.
89-
if !gui.Config.UserConfig.Gui.ShowAllContainers && !isStandaloneContainer(container) {
90-
return false
91-
}
92-
9386
if !gui.State.ShowExitedContainers && container.Container.State == "exited" {
9487
return false
9588
}
9689

97-
// Filter by selected project. Containers with no project (truly
98-
// standalone, not from any compose project) are always shown.
99-
selectedProject := gui.getSelectedProjectName()
100-
if selectedProject == "" {
101-
selectedProject = gui.DockerCommand.LocalProjectName
102-
}
103-
if selectedProject != "" && container.ProjectName != "" && container.ProjectName != selectedProject {
104-
return false
90+
// Only apply project and standalone filtering when we are inside a
91+
// docker-compose project. Outside of a compose project all
92+
// containers are shown in a flat list regardless of which compose
93+
// project they belong to.
94+
if gui.DockerCommand.InDockerComposeProject {
95+
// This check must be inside the InDockerComposeProject guard:
96+
// outside a compose project, services are still derived from
97+
// container labels, so compose-managed containers from other
98+
// projects would be incorrectly hidden.
99+
//
100+
// Note that this is O(N*M) time complexity where N is the number of services
101+
// and M is the number of containers. We expect N to be small but M may be large,
102+
// so we will need to keep an eye on this.
103+
if !gui.Config.UserConfig.Gui.ShowAllContainers && !isStandaloneContainer(container) {
104+
return false
105+
}
106+
107+
// Filter by selected project. Containers with no project (truly
108+
// standalone, not from any compose project) are always shown.
109+
selectedProject := gui.getSelectedProjectName()
110+
if selectedProject == "" {
111+
selectedProject = gui.DockerCommand.LocalProjectName
112+
}
113+
if selectedProject != "" && container.ProjectName != "" && container.ProjectName != selectedProject {
114+
return false
115+
}
105116
}
106117

107118
return true

pkg/gui/project_panel.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ func (gui *Gui) getProjectPanel() *panels.SideListPanel[*commands.Project] {
5858
// containers to show only those belonging to the selected project.
5959
return gui.renderContainersAndServices()
6060
},
61+
Hide: func() bool {
62+
// Only show the project panel when we are inside a docker-compose
63+
// project directory. When launched outside of a compose project
64+
// there is no meaningful local project to display, so we hide the
65+
// panel and let the containers panel show all containers in a flat
66+
// list (matching the behaviour from before v0.25).
67+
return !gui.DockerCommand.InDockerComposeProject
68+
},
6169
}
6270
}
6371

pkg/gui/services_panel.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ func (gui *Gui) getServicesPanel() *panels.SideListPanel[*commands.Service] {
9090
return presentation.GetServiceDisplayStrings(&gui.Config.UserConfig.Gui, service)
9191
},
9292
Hide: func() bool {
93-
// Show services panel if there are any compose projects (local or discovered)
94-
return !gui.DockerCommand.InDockerComposeProject && len(gui.Panels.Services.List.GetAllItems()) == 0
93+
// Only show the services panel when we are inside a docker-compose
94+
// project directory. When launched outside of a compose project
95+
// there is no local project context, so the panel is hidden and
96+
// all containers are shown in a flat list (matching pre-v0.25
97+
// behaviour).
98+
return !gui.DockerCommand.InDockerComposeProject
9599
},
96100
}
97101
}

0 commit comments

Comments
 (0)