Skip to content

Commit

Permalink
Merge branch 'master' into always-add-default-workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Aug 19, 2024
2 parents 73374b5 + 8977e45 commit faf04d3
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 38 deletions.
26 changes: 8 additions & 18 deletions internal/tui/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ func (h *Helpers) WorkspaceName(res resource.Resource) string {
}

func (h *Helpers) ModuleCurrentWorkspace(mod *module.Module) *workspace.Workspace {
if mod.CurrentWorkspaceID == nil {
h.Logger.Error("module does not have a current workspace", "module", mod)
return nil
}
ws, err := h.Workspaces.Get(*mod.CurrentWorkspaceID)
ws, err := h.Workspaces.Get(mod.CurrentWorkspaceID)
if err != nil {
h.Logger.Error("retrieving current workspace for module", "error", err, "module", mod)
return nil
Expand All @@ -72,11 +68,8 @@ func (h *Helpers) Module(res resource.Resource) *module.Module {
return mod
}

func (h *Helpers) CurrentWorkspaceName(workspaceID *resource.ID) string {
if workspaceID == nil {
return "-"
}
ws, err := h.Workspaces.Get(*workspaceID)
func (h *Helpers) CurrentWorkspaceName(workspaceID resource.ID) string {
ws, err := h.Workspaces.Get(workspaceID)
if err != nil {
h.Logger.Error("rendering current workspace name", "error", err)
return ""
Expand All @@ -85,10 +78,7 @@ func (h *Helpers) CurrentWorkspaceName(workspaceID *resource.ID) string {
}

func (h *Helpers) ModuleCurrentResourceCount(mod *module.Module) string {
if mod.CurrentWorkspaceID == nil {
return ""
}
ws, err := h.Workspaces.Get(*mod.CurrentWorkspaceID)
ws, err := h.Workspaces.Get(mod.CurrentWorkspaceID)
if err != nil {
h.Logger.Error("rendering module current workspace resource count", "error", err)
return ""
Expand All @@ -104,7 +94,7 @@ func (h *Helpers) WorkspaceCurrentCheckmark(ws *workspace.Workspace) string {
h.Logger.Error("rendering current workspace checkmark", "error", err)
return ""
}
if mod.CurrentWorkspaceID != nil && *mod.CurrentWorkspaceID == ws.ID {
if mod.CurrentWorkspaceID == ws.ID {
return "✓"
}
return ""
Expand Down Expand Up @@ -276,7 +266,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 +292,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 +304,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
16 changes: 5 additions & 11 deletions internal/tui/module/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ func (m list) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, 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.CurrentWorkspaceID))
if ws := m.helpers.ModuleCurrentWorkspace(row.Value); ws != nil {
return m, tui.NavigateTo(tui.ResourceListKind, tui.WithParent(ws.ID))
}
}
case key.Matches(msg, keys.Common.PlanDestroy):
createPlanOpts.Destroy = true
Expand All @@ -160,11 +162,7 @@ func (m list) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Create specs here, de-selecting any modules where an error is
// returned.
specs, err := m.table.Prune(func(mod *module.Module) (task.Spec, error) {
if workspaceID := mod.CurrentWorkspaceID; workspaceID == nil {
return task.Spec{}, fmt.Errorf("module %s does not have a current workspace", mod)
} else {
return m.Plans.Plan(*workspaceID, createPlanOpts)
}
return m.Plans.Plan(mod.CurrentWorkspaceID, createPlanOpts)
})
if err != nil {
// Modules were de-selected, so report error and give user
Expand All @@ -180,11 +178,7 @@ func (m list) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Create specs here, de-selecting any modules where an error is
// returned.
specs, err := m.table.Prune(func(mod *module.Module) (task.Spec, error) {
if workspaceID := mod.CurrentWorkspaceID; workspaceID == nil {
return task.Spec{}, fmt.Errorf("module %s does not have a current workspace", mod)
} else {
return m.Plans.Apply(*workspaceID, createPlanOpts)
}
return m.Plans.Apply(mod.CurrentWorkspaceID, createPlanOpts)
})
if err != nil {
// Modules were de-selected, so report error and give user
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 faf04d3

Please sign in to comment.