Skip to content

Commit

Permalink
add volume search
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestopigma committed Jul 4, 2023
1 parent 3ef3ff1 commit aa3428b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions models/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (

MVolumeList
MVolumeDetail
MVolumeSearch
)

type model struct {
Expand All @@ -59,6 +60,7 @@ type model struct {
networkOptions NetworkOptions
volumeList VolumeList
volumeDetail viewport.Model
volumeSearch VolumeSearch
ready bool
currentModel currentModel
ContainerID string
Expand All @@ -74,6 +76,7 @@ func NewModel(dockerClient *docker.Docker, version string) *model {
containerSearch: NewContainerSearch(),
imageSearch: NewImageSearch(),
networkSearch: NewNetworkSearch(),
volumeSearch: NewVolumeSearch(),
currentModel: MContainerList,
dockerVersion: version,
}
Expand Down Expand Up @@ -177,6 +180,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

m.volumeList.table, _ = m.volumeList.Update(msg, &m)
m.volumeDetail, _ = m.volumeDetail.Update(msg)
m.volumeSearch, _ = m.volumeSearch.Update(msg, &m)

cmds = append(cmds, cmd)
return m, tea.Batch(cmds...)
Expand Down Expand Up @@ -237,6 +241,8 @@ func (m model) View() string {
return m.volumeList.View(commands, m.dockerVersion)
case MVolumeDetail:
return m.volumeDetail.View()
case MVolumeSearch:
return m.volumeSearch.View()

default:
return ""
Expand Down
3 changes: 3 additions & 0 deletions models/volume_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func (vl VolumeList) Update(msg tea.Msg, m *model) (table.Model, tea.Cmd) {
}
m.volumeDetail = vd
m.currentModel = MVolumeDetail
case "ctrl+f":
m.volumeSearch.textInput.SetValue("")
m.currentModel = MVolumeSearch
}
}

Expand Down
44 changes: 44 additions & 0 deletions models/volume_search.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package models

import (
"fmt"

tea "github.com/charmbracelet/bubbletea"
)

type VolumeSearch struct {
Search
}

func NewVolumeSearch() VolumeSearch {
return VolumeSearch{
NewSearch(),
}
}

func (vs VolumeSearch) View() string {
return fmt.Sprintf(
"Search volume by name\n\n%s\n\n%s",
vs.textInput.View(),
"(esc to back)",
) + "\n"
}

func (vs VolumeSearch) Update(msg tea.Msg, m *model) (VolumeSearch, tea.Cmd) {
if m.currentModel != MVolumeSearch {
return vs, nil
}

switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "enter":
value := vs.textInput.Value()
m.volumeList = NewVolumeList(m.dockerClient.Volumes, value)
m.currentModel = MVolumeList
}
}

vs.textInput, _ = vs.textInput.Update(msg)
return vs, nil
}

0 comments on commit aa3428b

Please sign in to comment.