feat(alerts): enhance alert handling and client data enrichment in dashboard (#16)
Some checks failed
Aduanasoft/PANEL_BASES_ANEXO24/pipeline/head There was a failure building this commit
Some checks failed
Aduanasoft/PANEL_BASES_ANEXO24/pipeline/head There was a failure building this commit
- Updated the alert handling logic to include a 'notFound' flag for databases that are not found on the server, allowing for clearer UI representation. - Enriched alert data with client contact information by integrating the `lookupAlertClientData` function, ensuring alerts display relevant client details. - Improved the display of alert dates in the UI to reflect the new 'notFound' status, enhancing user experience and clarity. This update improves the accuracy and usability of the dashboard alerts. Reviewed-on: #16 Co-authored-by: AlexeerCT <acazares@aduanasoft.com.mx> Co-committed-by: AlexeerCT <acazares@aduanasoft.com.mx>
This commit is contained in:
@@ -342,18 +342,17 @@ export function matchNodeRowFromBackupStem(stem: string, nodes: any[]): any | nu
|
||||
|
||||
/** Datos de contacto para alertas (equivalente a la consulta previa sobre Usuarios/BasesDeDatos). */
|
||||
export async function lookupAlertClientData(nodoName: string): Promise<any | null> {
|
||||
// El "Cliente" de la alerta es el nombre de la tabla de bases de datos
|
||||
// (database_nodes.legal_name), NO el full_name del usuario del portal. Se resuelve el nodo por
|
||||
// database_name o node_subnode_key; así también funciona para bases sin usuario asociado.
|
||||
const sql = `
|
||||
SELECT
|
||||
pu.is_authority_client AS "ClienteAutoridad",
|
||||
pu.full_name AS "Nombre",
|
||||
pu.username AS "Usuario",
|
||||
dn.legal_name AS "Nombre",
|
||||
dn.notification_email AS "CorreoNotificacion",
|
||||
dn.node_subnode_key AS "NodoSubNodo"
|
||||
FROM ${qUsers()} pu
|
||||
LEFT JOIN ${qNodes()} dn ON pu.database_node_id = dn.id
|
||||
WHERE pu.username = $1
|
||||
OR dn.database_name = $1
|
||||
OR dn.node_subnode_key = $1
|
||||
FROM ${qNodes()} dn
|
||||
WHERE LOWER(TRIM(dn.database_name)) = LOWER(TRIM($1::text))
|
||||
OR LOWER(TRIM(dn.node_subnode_key)) = LOWER(TRIM($1::text))
|
||||
LIMIT 1
|
||||
`;
|
||||
const r = await pgPool.query(sql, [nodoName]);
|
||||
|
||||
@@ -463,7 +463,9 @@ export async function loadSqlDashboardFromNodes(nodes: CatalogNodeRow[]): Promis
|
||||
queryDatabaseAlertRow(pool, dbn),
|
||||
queryRestoreHistoryForDatabase(pool, dbn)
|
||||
]);
|
||||
if (!row) return null;
|
||||
// Conexión al servidor OK pero la base no existe en él: se marca como alerta
|
||||
// "no encontrada" (sin métricas ni días sin sincronizar), no se descarta el nodo.
|
||||
if (!row) return { node, dbn, row: null, notFound: true, alertRow: null, hist: [] };
|
||||
return { node, dbn, row, alertRow, hist };
|
||||
} catch (e) {
|
||||
console.error(
|
||||
@@ -480,6 +482,17 @@ export async function loadSqlDashboardFromNodes(nodes: CatalogNodeRow[]): Promis
|
||||
if (!res) continue;
|
||||
const { node, dbn, row, alertRow, hist } = res;
|
||||
|
||||
// Base no encontrada en el servidor: solo alerta (sin fila de métricas ni tamaño).
|
||||
// last_restore_date en null => la UI muestra los días sin sincronizar como N/D.
|
||||
if ((res as any).notFound) {
|
||||
alertsData.push({
|
||||
visible_name: dbn,
|
||||
last_restore_date: null,
|
||||
not_found: true
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
const visible = String(row.visible_name ?? dbn);
|
||||
const keyLower = visible.toLowerCase();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user