diff --git a/web-v2/src/features/assets/AssetHistoryPanel.tsx b/web-v2/src/features/assets/AssetHistoryPanel.tsx index c3096ab..99be492 100644 --- a/web-v2/src/features/assets/AssetHistoryPanel.tsx +++ b/web-v2/src/features/assets/AssetHistoryPanel.tsx @@ -2,6 +2,7 @@ import { useEffect, useState } from 'react'; import { Alert, LoadingBlock, errorMessage } from '../../components/Feedback'; import { Icon } from '../../components/Icon'; import { + getAsset, getAssetVersion, listAssetVersionTimeline, } from '../../lib/api'; @@ -11,11 +12,26 @@ import type { } 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, @@ -29,14 +45,19 @@ export function AssetHistoryPanel({ const [error, setError] = useState(''); const [detail, setDetail] = useState(null); const [detailLoading, setDetailLoading] = useState(false); + const [functionEligible, setFunctionEligible] = useState(false); useEffect(() => { setLoading(true); setError(''); - listAssetVersionTimeline(assetId, { pageSize: 10 }) - .then((response) => { + 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)); @@ -55,12 +76,15 @@ export function AssetHistoryPanel({ } }; - return
-
TRAZABILIDAD TEMPORAL

Historial del registro

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

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

- {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)} />} -
; + 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)} />} +
+
; }