Show connection creation errors in modal
When a connection create fails (e.g. port already in use), the error message now appears as a red alert in the modal instead of silently re-rendering the 'no connection' state. Added Error field to ConnectionModalData and created renderConnectionModalError helper.master
parent
3434d02e78
commit
c56c512764
|
|
@ -144,7 +144,7 @@ func (h *Handlers) ConnectionCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err := h.Store.ConnectionCreate(conn); err != nil {
|
if err := h.Store.ConnectionCreate(conn); err != nil {
|
||||||
if returnPortID != "" {
|
if returnPortID != "" {
|
||||||
h.renderConnectionModal(w, returnPortID)
|
h.renderConnectionModalError(w, returnPortID, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h.redirect(w, r, "/")
|
h.redirect(w, r, "/")
|
||||||
|
|
@ -159,6 +159,14 @@ func (h *Handlers) ConnectionCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handlers) renderConnectionModal(w http.ResponseWriter, returnPortID string) {
|
func (h *Handlers) renderConnectionModal(w http.ResponseWriter, returnPortID string) {
|
||||||
|
h.renderConnectionModalWithError(w, returnPortID, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handlers) renderConnectionModalError(w http.ResponseWriter, returnPortID string, errMsg string) {
|
||||||
|
h.renderConnectionModalWithError(w, returnPortID, errMsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handlers) renderConnectionModalWithError(w http.ResponseWriter, returnPortID string, errMsg string) {
|
||||||
portID, err := strconv.ParseInt(returnPortID, 10, 64)
|
portID, err := strconv.ParseInt(returnPortID, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "invalid port id", http.StatusBadRequest)
|
http.Error(w, "invalid port id", http.StatusBadRequest)
|
||||||
|
|
@ -180,6 +188,7 @@ func (h *Handlers) renderConnectionModal(w http.ResponseWriter, returnPortID str
|
||||||
Trace *services.TraceResult
|
Trace *services.TraceResult
|
||||||
ConnectionTypes []models.ConnectionType
|
ConnectionTypes []models.ConnectionType
|
||||||
PortGroups []PortGroup
|
PortGroups []PortGroup
|
||||||
|
Error string
|
||||||
}
|
}
|
||||||
|
|
||||||
allDevices, _ := h.Store.DeviceGetAllUnracked()
|
allDevices, _ := h.Store.DeviceGetAllUnracked()
|
||||||
|
|
@ -225,13 +234,24 @@ func (h *Handlers) renderConnectionModal(w http.ResponseWriter, returnPortID str
|
||||||
|
|
||||||
var groups []PortGroup
|
var groups []PortGroup
|
||||||
for _, id := range groupOrder {
|
for _, id := range groupOrder {
|
||||||
groups = append(groups, *groupMap[id])
|
grp := *groupMap[id]
|
||||||
|
filtered := grp.Ports[:0]
|
||||||
|
for _, fp := range grp.Ports {
|
||||||
|
if fp.ID != portID {
|
||||||
|
filtered = append(filtered, fp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(filtered) > 0 {
|
||||||
|
grp.Ports = filtered
|
||||||
|
groups = append(groups, grp)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
h.render(w, "connection_modal.html", ConnectionModalData{
|
h.render(w, "connection_modal.html", ConnectionModalData{
|
||||||
Trace: trace,
|
Trace: trace,
|
||||||
ConnectionTypes: connTypes,
|
ConnectionTypes: connTypes,
|
||||||
PortGroups: groups,
|
PortGroups: groups,
|
||||||
|
Error: errMsg,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
<div class="modal-inner">
|
<div class="modal-inner">
|
||||||
<button class="modal-close" onclick="closeModal()">×</button>
|
<button class="modal-close" onclick="closeModal()">×</button>
|
||||||
|
{{if .Error}}<div class="alert alert-error">{{.Error}}</div>{{end}}
|
||||||
{{if not .Trace.HasConnection}}
|
{{if not .Trace.HasConnection}}
|
||||||
<h3>No connection on port {{.Trace.ClickedPortName}} ({{.Trace.ClickedDeviceName}})</h3>
|
<h3>No connection on port {{.Trace.ClickedPortName}} ({{.Trace.ClickedDeviceName}})</h3>
|
||||||
<details>
|
<form method="POST" action="/connections/create" hx-post="/connections/create" hx-target="#modal-content" hx-swap="innerHTML">
|
||||||
<summary>Create Connection</summary>
|
|
||||||
<form method="POST" action="/connections/create" hx-post="/connections/create" hx-target="#modal-content" hx-swap="innerHTML">
|
|
||||||
<input type="hidden" name="return_port_id" value="{{.Trace.ClickedPortID}}">
|
<input type="hidden" name="return_port_id" value="{{.Trace.ClickedPortID}}">
|
||||||
<label>Connection type
|
<label>Connection type
|
||||||
<select name="connection_type_id">
|
<select name="connection_type_id">
|
||||||
|
|
@ -27,7 +26,6 @@
|
||||||
<label>Color <input type="color" name="color" value="#808080"></label>
|
<label>Color <input type="color" name="color" value="#808080"></label>
|
||||||
<button type="submit">Create</button>
|
<button type="submit">Create</button>
|
||||||
</form>
|
</form>
|
||||||
</details>
|
|
||||||
{{else}}
|
{{else}}
|
||||||
<h3>Connection — {{.Trace.ConnectionType}}</h3>
|
<h3>Connection — {{.Trace.ConnectionType}}</h3>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue