|
|
@@ -27,6 +27,17 @@ interface OverrideDraft {
|
|
|
parent: string
|
|
|
}
|
|
|
|
|
|
+/** #2179: el parent lo usan attach y facet (obligatorio) y switch (opcional,
|
|
|
+ * para decir de donde cuelga). hypervisor lo deriva de su propio puerto. */
|
|
|
+function parentApplies(kind: TopologyOverrideKind): boolean {
|
|
|
+ return kind === 'attach' || kind === 'facet' || kind === 'switch'
|
|
|
+}
|
|
|
+
|
|
|
+/** Obligatorio solo donde sin padre no hay nada que hacer. */
|
|
|
+function parentRequired(kind: TopologyOverrideKind): boolean {
|
|
|
+ return kind === 'attach' || kind === 'facet'
|
|
|
+}
|
|
|
+
|
|
|
const EMPTY: OverrideDraft = { mac: '', kind: 'hypervisor', name: '', parent: '' }
|
|
|
|
|
|
const KIND_STYLE: Record<TopologyOverrideKind, string> = {
|
|
|
@@ -178,7 +189,7 @@ export function TopologyOverridesManager({ onSaved, initialMac }: Props) {
|
|
|
mac: draft.mac.trim(),
|
|
|
kind: draft.kind,
|
|
|
name: draft.name.trim() || undefined,
|
|
|
- parent: draft.kind === 'attach' || draft.kind === 'facet' ? draft.parent.trim() || undefined : undefined,
|
|
|
+ parent: parentApplies(draft.kind) ? draft.parent.trim() || undefined : undefined,
|
|
|
}),
|
|
|
})
|
|
|
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
|
|
@@ -212,7 +223,7 @@ export function TopologyOverridesManager({ onSaved, initialMac }: Props) {
|
|
|
body: JSON.stringify({
|
|
|
kind: editDraft.kind,
|
|
|
name: editDraft.name.trim() || undefined,
|
|
|
- parent: editDraft.kind === 'attach' || editDraft.kind === 'facet' ? editDraft.parent.trim() || undefined : undefined,
|
|
|
+ parent: parentApplies(editDraft.kind) ? editDraft.parent.trim() || undefined : undefined,
|
|
|
}),
|
|
|
})
|
|
|
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
|
|
@@ -301,7 +312,7 @@ export function TopologyOverridesManager({ onSaved, initialMac }: Props) {
|
|
|
>
|
|
|
{t(`settings.overrides.kind.${o.kind}`)}
|
|
|
</span>
|
|
|
- {(o.kind === 'attach' || o.kind === 'facet') && o.parent && (
|
|
|
+ {parentApplies(o.kind) && o.parent && (
|
|
|
<span className="truncate font-mono text-caption text-text-muted">→ {o.parent}</span>
|
|
|
)}
|
|
|
</div>
|
|
|
@@ -393,8 +404,13 @@ export function TopologyOverridesManager({ onSaved, initialMac }: Props) {
|
|
|
onChange={(v) => setDraft((d) => ({ ...d, kind: v }))}
|
|
|
ariaLabel={t('settings.overrides.kind')}
|
|
|
/>
|
|
|
- {(draft.kind === 'attach' || draft.kind === 'facet') && (
|
|
|
- <ParentPicker value={draft.parent} onChange={(v) => setDraft((d) => ({ ...d, parent: v }))} />
|
|
|
+ {parentApplies(draft.kind) && (
|
|
|
+ <div>
|
|
|
+ <ParentPicker value={draft.parent} onChange={(v) => setDraft((d) => ({ ...d, parent: v }))} />
|
|
|
+ {draft.kind === 'switch' && (
|
|
|
+ <span className="mt-1 block text-caption text-text-muted">{t('settings.overrides.parentSwitchHint')}</span>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
)}
|
|
|
{/* #1982: dos botones "+Add" (el de abrir y el de guardar)
|
|
|
dejaban la duda de cual aplicaba y no habia salida explicita.
|
|
|
@@ -413,7 +429,7 @@ export function TopologyOverridesManager({ onSaved, initialMac }: Props) {
|
|
|
</button>
|
|
|
<button
|
|
|
type="submit"
|
|
|
- disabled={submitting || !draft.mac.trim() || ((draft.kind === 'attach' || draft.kind === 'facet') && !draft.parent.trim())}
|
|
|
+ disabled={submitting || !draft.mac.trim() || (parentRequired(draft.kind) && !draft.parent.trim())}
|
|
|
className="flex items-center gap-2 rounded-lg bg-accent px-4 py-2 text-sm font-medium text-canvas transition-opacity duration-150 hover:opacity-90 disabled:opacity-40"
|
|
|
>
|
|
|
<Check className="h-4 w-4" strokeWidth={2} />
|
|
|
@@ -448,8 +464,13 @@ export function TopologyOverridesManager({ onSaved, initialMac }: Props) {
|
|
|
onChange={(v) => setEditDraft((d) => ({ ...d, kind: v }))}
|
|
|
ariaLabel={t('settings.overrides.kind')}
|
|
|
/>
|
|
|
- {(editDraft.kind === 'attach' || editDraft.kind === 'facet') && (
|
|
|
- <ParentPicker value={editDraft.parent} onChange={(v) => setEditDraft((d) => ({ ...d, parent: v }))} />
|
|
|
+ {parentApplies(editDraft.kind) && (
|
|
|
+ <div>
|
|
|
+ <ParentPicker value={editDraft.parent} onChange={(v) => setEditDraft((d) => ({ ...d, parent: v }))} />
|
|
|
+ {editDraft.kind === 'switch' && (
|
|
|
+ <span className="mt-1 block text-caption text-text-muted">{t('settings.overrides.parentSwitchHint')}</span>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
)}
|
|
|
<div className="flex items-center justify-end gap-2">
|
|
|
<button
|
|
|
@@ -461,7 +482,7 @@ export function TopologyOverridesManager({ onSaved, initialMac }: Props) {
|
|
|
</button>
|
|
|
<button
|
|
|
type="submit"
|
|
|
- disabled={editSubmitting || ((editDraft.kind === 'attach' || editDraft.kind === 'facet') && !editDraft.parent.trim())}
|
|
|
+ disabled={editSubmitting || (parentRequired(editDraft.kind) && !editDraft.parent.trim())}
|
|
|
className="flex items-center gap-2 rounded-lg bg-accent px-4 py-2 text-sm font-medium text-canvas transition-opacity duration-150 hover:opacity-90 disabled:opacity-40"
|
|
|
>
|
|
|
<Pencil className="h-4 w-4" strokeWidth={2} />
|