This commit is contained in:
+67
-55
@@ -243,67 +243,79 @@ func driftResolutionAction(selected app.TargetSnapshot, kind app.TargetActionKin
|
||||
return app.TargetAction{Kind: kind}, false
|
||||
}
|
||||
|
||||
func (m Model) updateProfilePicker(key tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
switch key.String() {
|
||||
case "esc":
|
||||
m.picker.close()
|
||||
return m, nil
|
||||
case "enter":
|
||||
selected, ok := m.picker.selected(m.snapshot)
|
||||
if !ok {
|
||||
return m, nil
|
||||
}
|
||||
m.picker.close()
|
||||
return m.beginProfileActivation(app.Intent{Kind: app.ActivateProfile, Name: selected.Name})
|
||||
default:
|
||||
return m, m.picker.update(key, m.snapshot)
|
||||
}
|
||||
}
|
||||
|
||||
func (m Model) updateOperationConfirmation(key tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
switch m.operation.confirmationDialog.update(key.String()) {
|
||||
case confirmationAccepted:
|
||||
confirmed, ok := m.operation.confirmedIntent()
|
||||
if !ok {
|
||||
return m, nil
|
||||
}
|
||||
m.status = ""
|
||||
return m, m.startOperation(confirmed)
|
||||
case confirmationCancelled:
|
||||
m.operation.cancelConfirmation()
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) updateDriftResolution(key tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
switch key.String() {
|
||||
case "enter", "esc", "n", "q":
|
||||
m.driftResolutionTargetID = ""
|
||||
return m, nil
|
||||
case "r", "o":
|
||||
kind := app.ReapplyActiveProfileAction
|
||||
if key.String() == "o" {
|
||||
kind = app.RestoreOriginalAction
|
||||
}
|
||||
selected, ok := newTargetCatalog(m.snapshot, true, m.driftResolutionTargetID).selected(m.driftResolutionTargetID)
|
||||
if !ok {
|
||||
m.driftResolutionTargetID = ""
|
||||
m.operation.status = app.OperationStatus{Kind: app.StatusBlocked, Summary: "Drift Resolution is unavailable because the Target is no longer present"}
|
||||
return m, nil
|
||||
}
|
||||
action, ok := driftResolutionAction(selected, kind)
|
||||
if !ok || !action.Available {
|
||||
reason := action.DisabledReason
|
||||
if reason == "" {
|
||||
reason = "This Drift Resolution action is unavailable"
|
||||
}
|
||||
m.operation.status = app.OperationStatus{Kind: app.StatusBlocked, Summary: reason}
|
||||
return m, nil
|
||||
}
|
||||
intent, _ := kind.Intent(selected.ID)
|
||||
m.driftResolutionTargetID = ""
|
||||
return m, m.startOperation(intent)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) updateMain(key tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
if m.picker.open {
|
||||
switch key.String() {
|
||||
case "esc":
|
||||
m.picker.close()
|
||||
return m, nil
|
||||
case "enter":
|
||||
selected, ok := m.picker.selected(m.snapshot)
|
||||
if !ok {
|
||||
return m, nil
|
||||
}
|
||||
m.picker.close()
|
||||
return m.beginProfileActivation(app.Intent{Kind: app.ActivateProfile, Name: selected.Name})
|
||||
default:
|
||||
return m, m.picker.update(key, m.snapshot)
|
||||
}
|
||||
return m.updateProfilePicker(key)
|
||||
}
|
||||
if m.operation.confirmation != nil {
|
||||
switch m.operation.confirmationDialog.update(key.String()) {
|
||||
case confirmationAccepted:
|
||||
confirmed, ok := m.operation.confirmedIntent()
|
||||
if !ok {
|
||||
return m, nil
|
||||
}
|
||||
m.status = ""
|
||||
return m, m.startOperation(confirmed)
|
||||
case confirmationCancelled:
|
||||
m.operation.cancelConfirmation()
|
||||
}
|
||||
return m, nil
|
||||
return m.updateOperationConfirmation(key)
|
||||
}
|
||||
if m.driftResolutionTargetID != "" {
|
||||
switch key.String() {
|
||||
case "enter", "esc", "n", "q":
|
||||
m.driftResolutionTargetID = ""
|
||||
return m, nil
|
||||
case "r", "o":
|
||||
kind := app.ReapplyActiveProfileAction
|
||||
if key.String() == "o" {
|
||||
kind = app.RestoreOriginalAction
|
||||
}
|
||||
selected, ok := newTargetCatalog(m.snapshot, true, m.driftResolutionTargetID).selected(m.driftResolutionTargetID)
|
||||
if !ok {
|
||||
m.driftResolutionTargetID = ""
|
||||
m.operation.status = app.OperationStatus{Kind: app.StatusBlocked, Summary: "Drift Resolution is unavailable because the Target is no longer present"}
|
||||
return m, nil
|
||||
}
|
||||
action, ok := driftResolutionAction(selected, kind)
|
||||
if !ok || !action.Available {
|
||||
reason := action.DisabledReason
|
||||
if reason == "" {
|
||||
reason = "This Drift Resolution action is unavailable"
|
||||
}
|
||||
m.operation.status = app.OperationStatus{Kind: app.StatusBlocked, Summary: reason}
|
||||
return m, nil
|
||||
}
|
||||
intent, _ := kind.Intent(selected.ID)
|
||||
m.driftResolutionTargetID = ""
|
||||
return m, m.startOperation(intent)
|
||||
}
|
||||
return m, nil
|
||||
return m.updateDriftResolution(key)
|
||||
}
|
||||
if key.String() == "e" && m.operation.currentError != nil {
|
||||
m.operation.errorExpanded = !m.operation.errorExpanded
|
||||
|
||||
Reference in New Issue
Block a user