feat: add contextual Target actions
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"proxyctl/internal/app"
|
||||
"proxyctl/internal/probe"
|
||||
"proxyctl/internal/profile"
|
||||
"proxyctl/internal/target"
|
||||
)
|
||||
|
||||
type recordingModule struct {
|
||||
@@ -19,43 +18,10 @@ type recordingModule struct {
|
||||
intents []app.Intent
|
||||
}
|
||||
|
||||
func withTestTargetActions(snapshot app.Snapshot) app.Snapshot {
|
||||
for i := range snapshot.Targets {
|
||||
item := &snapshot.Targets[i]
|
||||
if item.PrimaryAction.Kind != 0 {
|
||||
continue
|
||||
}
|
||||
switch item.State {
|
||||
case target.Disabled:
|
||||
item.PrimaryAction.Kind = app.EnableTargetAction
|
||||
case target.Enabled:
|
||||
item.PrimaryAction.Kind = app.DisableTargetAction
|
||||
case target.External:
|
||||
item.PrimaryAction.Kind = app.ApplyProfileTargetAction
|
||||
case target.Drifted:
|
||||
item.PrimaryAction.Kind = app.ResolveDriftTargetAction
|
||||
item.DriftResolutionActions = []app.TargetAction{{Kind: app.ReapplyActiveProfileAction, Available: snapshot.ActiveProfile != ""}, {Kind: app.RestoreOriginalAction, Available: true}}
|
||||
}
|
||||
item.PrimaryAction.Available = item.Available && item.DetectionPhase == app.TargetReady
|
||||
if item.PrimaryAction.Available && (item.State == target.Disabled || item.State == target.External) && snapshot.ActiveProfile == "" {
|
||||
item.PrimaryAction.Available = false
|
||||
item.PrimaryAction.DisabledReason = "Target mutation is disabled because there is no Active Profile; open Profile management first"
|
||||
}
|
||||
if item.DetectionPhase == app.TargetChecking {
|
||||
item.PrimaryAction.DisabledReason = "Target mutation is disabled while this Target is still being checked"
|
||||
} else if item.DetectionPhase == app.TargetDetectionFailed {
|
||||
item.PrimaryAction.DisabledReason = "Target mutation is disabled because this Target check failed; refresh Targets to retry"
|
||||
} else if !item.Available {
|
||||
item.PrimaryAction.DisabledReason = "Target mutation is disabled because this Target is unavailable"
|
||||
}
|
||||
}
|
||||
return snapshot
|
||||
}
|
||||
|
||||
func (m *recordingModule) Snapshot() app.Snapshot { return withTestTargetActions(m.snapshot) }
|
||||
func (m *recordingModule) Snapshot() app.Snapshot { return m.snapshot }
|
||||
func (m *recordingModule) Dispatch(intent app.Intent) app.Result {
|
||||
m.intents = append(m.intents, intent)
|
||||
return app.Result{Snapshot: withTestTargetActions(m.snapshot), Notice: "done"}
|
||||
return app.Result{Snapshot: m.snapshot, Notice: "done"}
|
||||
}
|
||||
func (m *recordingModule) StartOperation(intent app.Intent) app.OperationStream {
|
||||
result := m.Dispatch(intent)
|
||||
|
||||
Reference in New Issue
Block a user