mirror of
https://github.com/lukaszraczylo/kportal.git
synced 2026-07-12 07:41:42 +00:00
fix(ui): edit-mode wizard allows keeping the same local port
Previously, editing a forward and keeping its local port unchanged failed the wizard's port-availability check: the in-config scan found the forward's own entry and reported '✗ Port N already assigned to <self.ID>'. Users had to pick a different port, edit, then change back. checkPortCmd now accepts an excludeID. The wizard passes wizard.originalID when isEditing so the forward being edited is ignored during the in-config conflict scan. The OS-level port check is unchanged (still catches actual port collisions). New regression test: TestCheckPortCmd_ExcludeID_AllowsKeepingOwnPort.
This commit is contained in:
@@ -145,8 +145,11 @@ func validateSelectorCmd(discovery *k8s.Discovery, contextName, namespace, selec
|
||||
}
|
||||
}
|
||||
|
||||
// checkPortCmd checks if a local port is available
|
||||
func checkPortCmd(port int, configPath string) tea.Cmd {
|
||||
// checkPortCmd checks if a local port is available.
|
||||
// excludeID, when non-empty, is the ID of a forward to ignore during the
|
||||
// in-config conflict scan. Used in edit mode so the wizard does not flag the
|
||||
// forward being edited as conflicting with itself.
|
||||
func checkPortCmd(port int, configPath, excludeID string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
// First check if port is already in the configuration
|
||||
cfg, err := config.LoadConfig(configPath)
|
||||
@@ -154,12 +157,16 @@ func checkPortCmd(port int, configPath string) tea.Cmd {
|
||||
// Check all forwards in config for this port
|
||||
allForwards := cfg.GetAllForwards()
|
||||
for _, fwd := range allForwards {
|
||||
if fwd.LocalPort == port {
|
||||
return PortCheckedMsg{
|
||||
port: port,
|
||||
available: false,
|
||||
message: fmt.Sprintf("✗ Port %d already assigned to %s", port, fwd.ID()),
|
||||
}
|
||||
if fwd.LocalPort != port {
|
||||
continue
|
||||
}
|
||||
if excludeID != "" && fwd.ID() == excludeID {
|
||||
continue
|
||||
}
|
||||
return PortCheckedMsg{
|
||||
port: port,
|
||||
available: false,
|
||||
message: fmt.Sprintf("✗ Port %d already assigned to %s", port, fwd.ID()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user