mirror of
https://github.com/lukaszraczylo/kportal.git
synced 2026-07-15 07:57:49 +00:00
feat(ui): toggle httpLog per-forward in add/edit wizard
Adds an HTTP-log enable toggle to the wizard's confirmation step so
users can flip httpLog on a forward without editing YAML by hand.
Behaviour:
- 'h' on the confirmation step toggles HTTPLog when not focused on
the alias text input. When focus is on alias, 'h' is treated as
text so users can still type aliases like 'host' or 'http-proxy'.
- The confirmation summary shows '[x] enabled' or '[ ] disabled'.
- New forwards: toggle on -> &HTTPLogSpec{Enabled: true}; off -> nil.
- Edit mode: pre-populates the toggle from the existing forward and
preserves any advanced HTTPLog fields the user had configured in
YAML (logFile, includeHeaders, maxBodySize, filterPath) by copying
the original spec on save. Toggling off discards the advanced
fields (consistent with 'absent in YAML = disabled').
State changes:
- ForwardStatus gains *config.HTTPLogSpec so the wizard can see the
full original spec on edit.
- AddWizardState gains httpLog bool + httpLogOriginal *HTTPLogSpec.
Three new tests:
- TestHandleAddWizardKeys_HToggleHTTPLog
- TestHandleAddWizardKeys_HOnAliasFocusIsTextInput
- TestEditPrefill_PreservesHTTPLog
This commit is contained in:
@@ -119,6 +119,8 @@ func (m model) handleMainViewKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.ui.addWizard.remotePort = selectedForward.RemotePort
|
||||
m.ui.addWizard.localPort = selectedForward.LocalPort
|
||||
m.ui.addWizard.alias = selectedForward.Alias
|
||||
m.ui.addWizard.httpLogOriginal = selectedForward.HTTPLog
|
||||
m.ui.addWizard.httpLog = selectedForward.HTTPLog != nil && selectedForward.HTTPLog.Enabled
|
||||
|
||||
// Determine resource type from the resource string
|
||||
if strings.HasPrefix(selectedForward.Type, "service") {
|
||||
@@ -429,6 +431,29 @@ func (m model) handleAddWizardKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
case "h":
|
||||
// In confirmation step (when not typing into the alias field), 'h'
|
||||
// toggles whether this forward has HTTP traffic logging enabled.
|
||||
// When the alias field is focused, fall through to text input below.
|
||||
if wizard.step == StepConfirmation && wizard.confirmationFocus != FocusAlias {
|
||||
wizard.httpLog = !wizard.httpLog
|
||||
return m, nil
|
||||
}
|
||||
// Otherwise treat as text input (filter or alias).
|
||||
canTypeText := wizard.inputMode == InputModeText ||
|
||||
(wizard.step == StepConfirmation && wizard.confirmationFocus == FocusAlias) ||
|
||||
(wizard.inputMode == InputModeList && isFilterableStep(wizard.step))
|
||||
if canTypeText {
|
||||
if wizard.inputMode == InputModeList && isFilterableStep(wizard.step) {
|
||||
wizard.searchFilter += "h"
|
||||
wizard.cursor = 0
|
||||
wizard.scrollOffset = 0
|
||||
} else {
|
||||
wizard.handleTextInput('h')
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
|
||||
case "enter":
|
||||
return m.handleAddWizardEnter()
|
||||
|
||||
@@ -671,6 +696,20 @@ func (m model) handleAddWizardEnter() (tea.Model, tea.Cmd) {
|
||||
fwd.Resource = "service/" + wizard.resourceValue
|
||||
}
|
||||
|
||||
// HTTPLog: when toggled on, preserve any advanced fields the
|
||||
// user had configured in YAML (logFile, includeHeaders, etc.)
|
||||
// so the wizard does not silently strip them. When toggled
|
||||
// off, leave HTTPLog nil (= absent in YAML = disabled).
|
||||
if wizard.httpLog {
|
||||
if wizard.httpLogOriginal != nil {
|
||||
spec := *wizard.httpLogOriginal
|
||||
spec.Enabled = true
|
||||
fwd.HTTPLog = &spec
|
||||
} else {
|
||||
fwd.HTTPLog = &config.HTTPLogSpec{Enabled: true}
|
||||
}
|
||||
}
|
||||
|
||||
wizard.loading = true
|
||||
|
||||
// If editing, use atomic update operation
|
||||
|
||||
Reference in New Issue
Block a user