import { useEffect, useState } from 'react'; import { Alert, LoadingBlock, errorMessage } from '../../components/Feedback'; import { Icon } from '../../components/Icon'; import { getAsset, getAssetVersion, listAssetVersionTimeline, } from '../../lib/api'; import type { AssetVersionDetail, AssetVersionSummary, } from '../../lib/api'; import { formatDate } from '../../lib/format'; import { AssetVersionDrawer } from './AssetVersionDrawer'; import { InventoryFunctionPanel } from './InventoryFunctionPanel'; import { assetVersionChangeLabel, assetVersionFieldLabel, } from './assetVersionPresentation'; function normalized(value: string): string { return value .normalize('NFD') .replace(/[\u0300-\u036f]/g, '') .toLowerCase() .replace(/[^a-z0-9]+/g, ' ') .trim(); } function supportsFunctionChange(code: string, name: string): boolean { const value = `${normalized(code)} ${normalized(name)}`; return value.split(' ').some((part) => part === 'estacion' || part === 'subestacion'); } export function AssetHistoryPanel({ assetId, refreshKey = 0, }: { assetId: string; refreshKey?: number; }) { const [versions, setVersions] = useState([]); const [total, setTotal] = useState(0); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); const [detail, setDetail] = useState(null); const [detailLoading, setDetailLoading] = useState(false); const [functionEligible, setFunctionEligible] = useState(false); useEffect(() => { setLoading(true); setError(''); Promise.all([ listAssetVersionTimeline(assetId, { pageSize: 10 }), getAsset(assetId), ]) .then(([response, asset]) => { setVersions(response.data); setTotal(response.meta.total); setFunctionEligible(supportsFunctionChange(asset.type.code, asset.type.name)); }) .catch((requestError) => setError(errorMessage(requestError))) .finally(() => setLoading(false)); }, [assetId, refreshKey]); const open = async (version: AssetVersionSummary) => { setDetail(null); setDetailLoading(true); setError(''); try { setDetail(await getAssetVersion(version.assetId, version.versionNumber)); } catch (requestError) { setError(errorMessage(requestError)); } finally { setDetailLoading(false); } }; return
{functionEligible && }
TRAZABILIDAD TEMPORAL

Historial del registro

{total} versión{total === 1 ? '' : 'es'}

Cada cambio conserva una copia completa e inmutable del registro, sus atributos, su ubicación y, cuando corresponde, su función operativa.

{error && {error}} {loading ? :
{versions.map((version) => )}
} {!loading && total > versions.length &&

Se muestran las 10 versiones más recientes. El historial completo está disponible en la sección Historial.

} {(detailLoading || detail) && setDetail(null)} />}
; }