feat: color identidad por modulo en indice sam.devops con asignacion autoritaria

This commit is contained in:
Nurfog committed 2026-09-16 16:36:56 -03:00
1 parent f9e0887f10
commit 6fd9e8a615
5 files changed
+304 -8

No files matched your search

+66
View File
@@ -4,9 +4,11 @@ import { useState } from "react";
import SamShell from "@/components/SamShell";
import { refreshModules, useModules, useMe } from "@/lib/store"
import {
assignColorsForModules,
displayName,
envOf,
getModuleMeta,
isValidHexColor,
itMenu,
} from "@/lib/sam";
@@ -65,6 +67,47 @@ export default function Actualizar() {
}
};
// Rellena el color de los módulos ya importados que aún no lo tienen
// guardado: lo genera de forma autoritaria y lo persiste en el deployer.
const missingColor = modules.filter((m) => !isValidHexColor(m.color));
const backfillColors = async () => {
if (missingColor.length === 0) return;
setBusy("color:backfill");
setMsg(null);
try {
const assigned = assignColorsForModules(modules);
let ok = 0;
const failed: string[] = [];
for (const m of missingColor) {
try {
const res = await fetch(
`/api/deployer/modules/${encodeURIComponent(m.name)}`,
{
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ color: assigned[m.name] }),
cache: "no-store",
}
);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
ok++;
} catch {
failed.push(m.name);
}
}
refreshModules();
setMsg({
ok: failed.length === 0,
text:
failed.length === 0
? `Colores generados y guardados en ${ok} módulo${ok !== 1 ? "s" : ""}.`
: `Guardados ${ok}, fallaron: ${failed.join(", ")}.`,
});
} finally {
setBusy(null);
}
};
return (
<SamShell
brand="IT"
@@ -87,6 +130,29 @@ export default function Actualizar() {
)}
<div className="app-card p-3">
{missingColor.length > 0 && (
<div className="alert alert-info py-2 d-flex align-items-center justify-content-between flex-wrap gap-2">
<span className="small">
<i className="bx bx-palette me-1" />
Hay {missingColor.length} módulo{missingColor.length !== 1 ? "s" : ""} sin
color guardado ({missingColor.map((m) => m.name).join(", ")}).
</span>
<button
className="btn btn-sm btn-primary"
disabled={busy !== null}
onClick={backfillColors}
>
{busy === "color:backfill" ? (
<span className="spinner-border spinner-border-sm" />
) : (
<>
<i className="bx bx-palette me-1" />
Generar colores
</>
)}
</button>
</div>
)}
<div className="table-responsive">
<table className="table table-hover align-middle mb-0">
<thead>