feat: add contextual Target actions
This commit is contained in:
+4
-23
@@ -242,8 +242,6 @@ type mutationAvailability struct {
|
||||
// action from Target state or display text.
|
||||
func targetMutationAvailability(selected app.TargetSnapshot, selectedOK bool, operationBlocked bool) mutationAvailability {
|
||||
switch {
|
||||
case operationBlocked:
|
||||
return mutationAvailability{reason: "Wait for the current mutation to finish before starting another modification", compactReason: "mutation in progress"}
|
||||
case !selectedOK:
|
||||
return mutationAvailability{reason: "Target mutation is disabled because no Target is selected", compactReason: "no Target selected"}
|
||||
case !selected.PrimaryAction.Available:
|
||||
@@ -252,6 +250,8 @@ func targetMutationAvailability(selected app.TargetSnapshot, selectedOK bool, op
|
||||
reason = "This Target action is unavailable"
|
||||
}
|
||||
return mutationAvailability{reason: reason, compactReason: "unavailable"}
|
||||
case operationBlocked:
|
||||
return mutationAvailability{reason: "Wait for the current mutation to finish before starting another modification", compactReason: "mutation in progress"}
|
||||
default:
|
||||
return mutationAvailability{available: true}
|
||||
}
|
||||
@@ -266,25 +266,6 @@ func driftResolutionAction(selected app.TargetSnapshot, kind app.TargetActionKin
|
||||
return app.TargetAction{Kind: kind}, false
|
||||
}
|
||||
|
||||
func targetIntent(kind app.TargetActionKind, targetID string) (app.Intent, bool) {
|
||||
intent := app.Intent{TargetID: targetID}
|
||||
switch kind {
|
||||
case app.EnableTargetAction:
|
||||
intent.Kind = app.EnableTarget
|
||||
case app.DisableTargetAction:
|
||||
intent.Kind = app.DisableTarget
|
||||
case app.ApplyProfileTargetAction:
|
||||
intent.Kind = app.ApplyProfileToTarget
|
||||
case app.ReapplyActiveProfileAction:
|
||||
intent.Kind = app.ReapplyActiveProfile
|
||||
case app.RestoreOriginalAction:
|
||||
intent.Kind = app.RestoreOriginal
|
||||
default:
|
||||
return app.Intent{}, false
|
||||
}
|
||||
return intent, true
|
||||
}
|
||||
|
||||
func (m Model) updateMain(key tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
if m.operation.confirmation != nil {
|
||||
switch key.String() {
|
||||
@@ -325,7 +306,7 @@ func (m Model) updateMain(key tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.operation.status = app.OperationStatus{Kind: app.StatusBlocked, Summary: reason}
|
||||
return m, nil
|
||||
}
|
||||
intent, _ := targetIntent(kind, selected.ID)
|
||||
intent, _ := kind.Intent(selected.ID)
|
||||
m.driftResolutionTargetID = ""
|
||||
return m, m.startOperation(intent)
|
||||
}
|
||||
@@ -423,7 +404,7 @@ func (m Model) updateMain(key tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.driftResolutionTargetID = selected.ID
|
||||
break
|
||||
}
|
||||
intent, ok := targetIntent(selected.PrimaryAction.Kind, selected.ID)
|
||||
intent, ok := selected.PrimaryAction.Kind.Intent(selected.ID)
|
||||
if !ok {
|
||||
m.operation.status = app.OperationStatus{Kind: app.StatusBlocked, Summary: "This Target action is unavailable"}
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user