Skip to content

Commit

Permalink
chore: navigation message only needs an ID
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Aug 19, 2024
1 parent 2208eff commit 8977e45
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions internal/tui/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (h *Helpers) CreateTasks(fn task.SpecFunc, ids ...resource.ID) tea.Cmd {
if err != nil {
return ReportError(fmt.Errorf("creating task: %w", err))
}
return NewNavigationMsg(TaskKind, WithParent(task))
return NewNavigationMsg(TaskKind, WithParent(task.ID))
default:
specs := make([]task.Spec, 0, len(ids))
for _, id := range ids {
Expand All @@ -302,7 +302,7 @@ func (h *Helpers) CreateTasksWithSpecs(specs ...task.Spec) tea.Cmd {
if err != nil {
return ReportError(fmt.Errorf("creating task: %w", err))
}
return NewNavigationMsg(TaskKind, WithParent(task))
return NewNavigationMsg(TaskKind, WithParent(task.ID))
default:
return h.createTaskGroup(specs...)
}
Expand All @@ -314,7 +314,7 @@ func (h *Helpers) createTaskGroup(specs ...task.Spec) tea.Msg {
if err != nil {
return ReportError(fmt.Errorf("creating task group: %w", err))
}
return NewNavigationMsg(TaskGroupKind, WithParent(group))
return NewNavigationMsg(TaskGroupKind, WithParent(group.ID))
}

func (h *Helpers) Move(workspaceID resource.ID, from state.ResourceAddress) tea.Cmd {
Expand Down
2 changes: 1 addition & 1 deletion internal/tui/logs/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (m list) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch {
case key.Matches(msg, keys.Global.Enter):
if row, ok := m.table.CurrentRow(); ok {
return m, tui.NavigateTo(tui.LogKind, tui.WithParent(row.Value))
return m, tui.NavigateTo(tui.LogKind, tui.WithParent(row.ID))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/tui/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func NewNavigationMsg(kind Kind, opts ...NavigateOption) NavigationMsg {

type NavigateOption func(msg *NavigationMsg)

func WithParent(parent resource.Resource) NavigateOption {
func WithParent(parent resource.ID) NavigateOption {
return func(msg *NavigationMsg) {
msg.Page.ID = parent.GetID()
msg.Page.ID = parent
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/tui/module/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (m list) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, keys.Common.State):
if row, ok := m.table.CurrentRow(); ok {
if ws := m.helpers.ModuleCurrentWorkspace(row.Value); ws != nil {
return m, tui.NavigateTo(tui.ResourceListKind, tui.WithParent(ws))
return m, tui.NavigateTo(tui.ResourceListKind, tui.WithParent(ws.ID))
}
}
case key.Matches(msg, keys.Common.PlanDestroy):
Expand Down
2 changes: 1 addition & 1 deletion internal/tui/task/group_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (m groupList) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch {
case key.Matches(msg, keys.Global.Enter):
if row, ok := m.table.CurrentRow(); ok {
return m, tui.NavigateTo(tui.TaskGroupKind, tui.WithParent(row.Value))
return m, tui.NavigateTo(tui.TaskGroupKind, tui.WithParent(row.ID))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/tui/task/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (m List) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, cancel(m.tasks, taskIDs...)
case key.Matches(msg, keys.Global.Enter):
if row, ok := m.Table.CurrentRow(); ok {
return m, tui.NavigateTo(tui.TaskKind, tui.WithParent(row.Value))
return m, tui.NavigateTo(tui.TaskKind, tui.WithParent(row.ID))
}
case key.Matches(msg, keys.Common.Apply):
specs, err := m.Table.Prune(func(t *task.Task) (task.Spec, error) {
Expand All @@ -153,7 +153,7 @@ func (m List) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case key.Matches(msg, keys.Common.State):
if row, ok := m.Table.CurrentRow(); ok {
if ws, ok := m.helpers.TaskWorkspace(row.Value); ok {
return m, tui.NavigateTo(tui.ResourceListKind, tui.WithParent(ws))
return m, tui.NavigateTo(tui.ResourceListKind, tui.WithParent(ws.GetID()))
} else {
return m, tui.ReportError(errors.New("task not associated with a workspace"))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/tui/task/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
)
case key.Matches(msg, keys.Common.State):
if ws, ok := m.helpers.TaskWorkspace(m.task); ok {
return m, tui.NavigateTo(tui.ResourceListKind, tui.WithParent(ws))
return m, tui.NavigateTo(tui.ResourceListKind, tui.WithParent(ws.GetID()))
} else {
return m, tui.ReportError(errors.New("task not associated with a workspace"))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/tui/workspace/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (m list) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
)
case key.Matches(msg, keys.Common.State):
if row, ok := m.table.CurrentRow(); ok {
return m, tui.NavigateTo(tui.ResourceListKind, tui.WithParent(row.Value))
return m, tui.NavigateTo(tui.ResourceListKind, tui.WithParent(row.ID))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/tui/workspace/resource_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (m resourceList) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch {
case key.Matches(msg, keys.Global.Enter):
if row, ok := m.Table.CurrentRow(); ok {
return m, tui.NavigateTo(tui.ResourceKind, tui.WithParent(row.Value))
return m, tui.NavigateTo(tui.ResourceKind, tui.WithParent(row.ID))
}
case key.Matches(msg, resourcesKeys.Reload):
if m.reloading {
Expand Down

0 comments on commit 8977e45

Please sign in to comment.