2026-11-05 15:01:39 +01:00
import { useEffect , useRef , useState } from "react" ;
import {
2026-11-05 15:29:22 +01:00
ActionIcon , Badge , Button , Card , Grid , Group , Loader , NativeSelect , SegmentedControl , Stack , Text , Textarea , TextInput , Title , Tooltip ,
useComputedColorScheme ,
2026-11-05 15:01:39 +01:00
} from "@mantine/core" ;
import { IconPlus , IconX } from "@tabler/icons-react" ;
import { appel , Selecteur } from "../commun.jsx" ;
2026-11-05 15:29:22 +01:00
import { ImagesDe } from "./Images.jsx" ;
2026-11-05 15:01:39 +01:00
// Data, le visualiseur de courbes (et l'étiquetage de labeling/labeling.py) : un plot au départ, d'autres à ajouter ou enlever,
2026-11-05 15:29:22 +01:00
// tous alignés sur le temps ; sous eux les étiquettes : LLM (labeling/auto/, l'étiqueteur), Detectors (les événements du journal,
// en lecture seule) ou Manual (labeling/manual/) ; glisser sur leur barre sélectionne une plage, un clic ouvre une étiquette et
// la met en évidence. À droite, les images de la station (la page Images).
2026-11-05 15:01:39 +01:00
const FAMILLES = { "Visibility" : "#8ec5e8" , "Obstruction" : "#f0b072" , "Thermal displacement" : "#f08a7e" , "Displacement" : "#b39ddb" ,
"Target issue" : "#e6d46a" , "No data" : "#c4c4be" , "None" : "#a8d5a2" };
const NOM_FAMILLE = f => ( f === "None" ? "None (courbes intactes)" : f );
const CHOIX_FAMILLE = [{ value : "" , label : "(sans famille)" }, ... Object . keys ( FAMILLES ). map ( f => ({ value : f , label : NOM_FAMILLE ( f ) }))];
2026-11-05 15:29:22 +01:00
const SOURCES = [{ value : "auto" , label : "LLM" }, { value : "detecteurs" , label : "Detectors" }, { value : "manual" , label : "Manual" }];
const GRIS = "#b0b0aa" , BLEU = "#2a78d6" , VOIE = 26 , HAUT = 330 ; // VOIE : px par rangée d'étiquettes ; HAUT : d'un plot
2026-11-05 15:01:39 +01:00
const couleur = l => FAMILLES [ l . categorie ] || GRIS ;
const lisible = s => s . slice ( 0 , 16 ). replace ( "T" , " " );
const marge = () => ({ l : 60 , r : 20 , t : 10 , b : 30 });
// L'habillage, aux couleurs de Mantine (dark.0 à dark.7 en sombre, gray en clair)
2026-11-05 15:29:22 +01:00
const COULEURS = { clair : { texte : "#495057" , faible : "#868e96" , grille : "#eef0f2" , axe : "#dee2e6" , fond : "#f1f3f5" , bulle : "#ffffff" , zone : 0.05 },
sombre : { texte : "#c9c9c9" , faible : "#828282" , grille : "#2e2e2e" , axe : "#424242" , fond : "#3b3b3b" , bulle : "#242424" , zone : 0.07 } };
2026-11-05 15:01:39 +01:00
const POLICE = "Roboto, sans-serif" ;
const habillage = c => ({ paper_bgcolor : "rgba(0,0,0,0)" , plot_bgcolor : "rgba(0,0,0,0)" , font : { family : POLICE , size : 11 , color : c . texte },
hoverlabel : { bgcolor : c . bulle , bordercolor : c . axe , align : "left" , font : { family : POLICE , size : 12 , color : c . texte } },
modebar : { bgcolor : "rgba(0,0,0,0)" , color : c . faible , activecolor : "#5383ff" } });
const axe = c => ({ gridcolor : c . grille , linecolor : c . axe , showline : true , zeroline : false , ticks : "" });
const OUTILS = { responsive : true , doubleClick : "reset" , displaylogo : false , showTips : false ,
modeBarButtonsToRemove : [ "lasso2d" , "select2d" , "autoScale2d" , "zoomIn2d" , "zoomOut2d" , "hoverClosestCartesian" , "hoverCompareCartesian" , "toggleSpikelines" ] };
const date = v => Date . parse ( String ( v ). replace ( " " , "T" ). replace ( /Z?$/ , "Z" )); // une date Plotly ou d'étiquette -> ms UTC
const coupe = s => s . replace ( /(.{1,80})(\s|$)/g , "$1<br>" ); // la bulle : des lignes de 80 caractères au plus
export default function Data ({ selection , choisir }) {
const [ donnees , setDonnees ] = useState ( null ), [ charge , setCharge ] = useState ( false );
const { station , du , au } = selection ;
useEffect (() => {
setDonnees ( null );
if ( ! station ) return ;
setCharge ( true );
appel ( `/api/courbes? ${ new URLSearchParams ({ station , du , au } )}` ). then ( d => { setDonnees ( d ); setCharge ( false ); });
}, [ station , du , au ]);
return (
2026-11-05 15:29:22 +01:00
< Grid gutter = "lg" >
< Grid.Col span = {{ base : 12 , lg : 8 }}>
< Stack gap = "lg" >
< div >
< Title order = { 2 }> Data </ Title >
< Text c = "dimmed" > Les courbes d 'une station, un plot ou plusieurs ; sous eux les étiquettes : un clic sur l' une la met en évidence et
l 'ouvre.</Text>
</div>
<Selecteur selection={selection} choisir={choisir} />
{charge && <Loader />}
{donnees && <Courbes key={`${station}${du}${au}`} selection={selection} d={donnees} />}
</Stack>
</Grid.Col>
<Grid.Col span={{ base: 12, lg: 4 }}>
<div className="colle"><ImagesDe selection={selection} compacte /></div>
</Grid.Col>
</Grid>
2026-11-05 15:01:39 +01:00
);
}
2026-11-05 15:29:22 +01:00
function Courbes({ selection: { station, du, au }, d }) {
2026-11-05 15:01:39 +01:00
const { A, B, T, plots: PLOTS } = d;
const indice = (titre, sinon) => { const i = PLOTS.findIndex(p => p.titre === titre); return i < 0 ? sinon : i; };
const [Plotly, setPlotly] = useState(null), [pret, setPret] = useState(false);
const [vues, setVues] = useState([{ id: 1, m: indice("Relative Corrected Horizontal Shift", 0) }]); // les plots affichés
const [source, setSource] = useState("auto"), [labels, setLabels] = useState([]), [choix, setChoix] = useState(null);
const [ajout, setAjout] = useState({ categorie: "", texte: "" });
const [ouverte, setOuverte] = useState(null), [edit, setEdit] = useState(null), [note, setNote] = useState("");
2026-11-05 15:29:22 +01:00
const [toutes, setToutes] = useState([]), [lecture, setLecture] = useState(true), sombre = useComputedColorScheme("light") === "dark";
const lecteur = source === "detecteurs"; // les événements des détecteurs se lisent, ils ne s' écrivent pas
2026-11-05 15:01:39 +01:00
// figs : id -> div du plot ; dessines : id -> plot qu'il montre ; vue : la plage et la largeur où le texte des étiquettes a été tronqué
const figs = useRef ({}), dessines = useRef ({}), prochain = useRef ( 2 ), barre = useRef (), tries = useRef ([]), vue = useRef ( "" ), courant = useRef ({});
2026-11-05 15:29:22 +01:00
courant . current = { vues , labels , choix , ouverte , ouvrir , c : COULEURS [ sombre ? "sombre" : "clair" ] }; // ce que lisent les événements Plotly
2026-11-05 15:01:39 +01:00
useEffect (() => { import ( "plotly.js-dist-min" ). then ( m => setPlotly (() => m . default )); }, []);
const liste = () => courant . current . vues . map ( v => figs . current [ v . id ]). filter ( g => g ? . _fullLayout );
2026-11-05 15:29:22 +01:00
// Les zones des étiquettes, la plage choisie, et l'étiquette ouverte : plus marquée, entourée
2026-11-05 15:01:39 +01:00
function zones () {
2026-11-05 15:29:22 +01:00
const { labels , choix , ouverte , c } = courant . current ;
const z = ( a , b , f , o , ligne = { width : 0 }, couche = "below" ) => ({ type : "rect" , xref : "x" , yref : "paper" , x0 : lisible ( a ), x1 : lisible ( b ),
y0 : 0 , y1 : 1 , fillcolor : f , opacity : o , line : ligne , layer : couche });
return labels . map ( l => z ( l . debut , l . fin , couleur ( l ), c . zone )). concat ( choix ? [ z ( choix [ 0 ], choix [ 1 ], BLEU , 0.25 )] : [])
. concat ( ouverte ? [ z ( ouverte . debut , ouverte . fin , couleur ( ouverte ), 0.3 ),
z ( ouverte . debut , ouverte . fin , "rgba(0,0,0,0)" , 1 , { color : c . texte , width : 1.5 , dash : "dot" }, "above" )] : []);
2026-11-05 15:01:39 +01:00
}
2026-11-05 15:29:22 +01:00
// Le contour des barres : épais pour l'étiquette ouverte
const contour = t => {
const { ouverte , c } = courant . current ;
return { color : t . map ( l => ( l === ouverte ? c . texte : c . fond )), width : t . map ( l => ( l === ouverte ? 3 : 1 )) };
};
2026-11-05 15:01:39 +01:00
// Les plots et la barre partagent plage et marges : celui qui change impose les siens aux autres (rien si déjà alignés,
// sinon le relayout appelle aligne en boucle).
function aligne ( src ) {
const gs = liste (), b = barre . current ;
if ( ! b ? . _fullLayout || ! gs . length ) return ;
const rg = ( src ? . _fullLayout ? src : gs [ 0 ]). _fullLayout . xaxis . range . slice ();
const l = Math . max (... gs . map ( g => g . _fullLayout . _size . l )), r = Math . max (... gs . map ( g => g . _fullLayout . _size . r ));
return Promise . all ([... gs , b ]. map ( g => {
const m = g . _fullLayout . margin , x = g . _fullLayout . xaxis . range ;
if ( m . l === l && m . r === r && date ( x [ 0 ]) === date ( rg [ 0 ]) && date ( x [ 1 ]) === date ( rg [ 1 ])) return ;
return Plotly . relayout ( g , { "xaxis.range" : rg , "margin.l" : l , "margin.r" : r });
})). then (() => { // le texte des étiquettes suit le zoom et la largeur
const v = ` ${ rg } | ${ b . _fullLayout . _size . w } ` ;
if ( v !== vue . current ) { vue . current = v ; return Plotly . restyle ( b , { text : [ textes ( tries . current , b . _fullLayout )] }); }
});
}
// Le texte de chaque étiquette, tronqué à la largeur visible de sa barre (~6 px par caractère en 11 px)
function textes ( t , L ) {
const [ r0 , r1 ] = L . xaxis . range . map ( date ), w = L . _size . w ;
return t . map ( l => {
const px = ( Math . min ( date ( l . fin ), r1 ) - Math . max ( date ( l . debut ), r0 )) / ( r1 - r0 ) * w , n = Math . floor (( px - 10 ) / 6 );
return n < 3 ? "" : l . description . length <= n ? l . description : l . description . slice ( 0 , n - 1 ) + "…" ;
});
}
function dessineFig ( g , m ) {
const p = PLOTS [ m ], { c } = courant . current , b = barre . current ? . _fullLayout ;
2026-11-05 15:29:22 +01:00
g . style . height = ` ${ HAUT } px` ; // responsive : Plotly reprend la hauteur du div à chaque restyle, il lui en faut une
2026-11-05 15:01:39 +01:00
// uirevision : le zoom et les capteurs cachés restent quand on change de plot ; l'ordonnée, propre à chaque plot, se recale.
2026-11-05 15:29:22 +01:00
// Un nouveau plot prend la plage déjà affichée. t : la place du menu du plot (à gauche) et de la barre d'outils (à droite).
2026-11-05 15:01:39 +01:00
return Plotly . react ( g , p . traces . map ( t => ({ type : "scatter" , mode : t . mode || "lines" , marker : { size : 4 }, x : T [ t . t ], y : t . y , name : t . name ,
uid : t . name . replace ( /\W/g , "_" ), line : t . line ,
hovertemplate : ` ${ t . name } : %{y}<br>%{x|%Y-%m-%d %H:%M} UTC<extra></extra>` })),
2026-11-05 15:29:22 +01:00
{ ... habillage ( c ), height : HAUT , hovermode : "closest" , margin : { ... marge (), t : 32 , b : 36 }, uirevision : 1 , shapes : zones (),
2026-11-05 15:01:39 +01:00
legend : { x : 1.01 , y : 1 , itemwidth : 30 , font : { size : 11 } },
xaxis : { type : "date" , range : b ? b . xaxis . range . slice () : [ lisible ( A ), lisible ( B )], ... axe ( c ) },
yaxis : { title : { text : p . titre , font : { size : 11 , color : c . faible } }, uirevision : p . titre , ... axe ( c ) } },
OUTILS ). then (() => {
if ( ! g . suivi ) { g . suivi = true ; g . on ( "plotly_relayout" , () => aligne ( g )); }
return aligne ( g );
});
}
// Les plots nouveaux ou changés (tous : au changement de thème)
function dessinePlots ( tous ) {
return Promise . all ( courant . current . vues . filter ( v => tous || dessines . current [ v . id ] !== v . m )
. map ( v => { dessines . current [ v . id ] = v . m ; return dessineFig ( figs . current [ v . id ], v . m ); }));
}
function dessineBarre () {
const t = [... courant . current . labels ]. sort (( a , b ) => ( a . debut < b . debut ? - 1 : 1 ));
tries . current = t ;
const voies = [], voie = t . map ( l => { // la première rangée libre, sinon une nouvelle
const r = voies . findIndex ( f => f <= l . debut ), i = r < 0 ? voies . length : r ;
voies [ i ] = l . fin ;
return i ;
});
const n = Math . max ( 1 , voies . length ), gs = liste (), f = gs [ 0 ]. _fullLayout , { c } = courant . current ;
vue . current = "" ;
2026-11-05 15:29:22 +01:00
barre . current . style . height = ` ${ 40 + VOIE * n } px` ; // comme les plots
2026-11-05 15:01:39 +01:00
return Plotly . react ( barre . current , [{ type : "bar" , orientation : "h" , y : voie , base : t . map ( l => lisible ( l . debut )),
x : t . map ( l => Date . parse ( l . fin ) - Date . parse ( l . debut )), width : 0.8 ,
2026-11-05 15:29:22 +01:00
marker : { color : t . map ( couleur ), cornerradius : 4 , line : contour ( t ) },
2026-11-05 15:01:39 +01:00
text : textes ( t , barre . current . _fullLayout || f ), textposition : "inside" , insidetextanchor : "start" , textangle : 0 ,
textfont : { family : POLICE , size : 11 , color : "#1a1b1e" },
unselected : { marker : { opacity : 1 } }, // sinon une sélection les pâlit
// la bulle : la famille et tout le texte, que la barre tronque
customdata : t . map ( l => ( l . categorie ? `<b> ${ NOM_FAMILLE ( l . categorie ) } </b><br>` : "" ) + coupe ( l . description )),
hovertemplate : "%{customdata}<extra></extra>" }],
{ ... habillage ( c ), height : 40 + VOIE * n , dragmode : "select" , selectdirection : "h" , hovermode : "closest" , plot_bgcolor : c . fond , showlegend : false ,
margin : { ... marge (), l : Math . max (... gs . map ( g => g . _fullLayout . _size . l )), r : Math . max (... gs . map ( g => g . _fullLayout . _size . r )) },
xaxis : { type : "date" , range : f . xaxis . range . slice (), showgrid : false , ticks : "" , color : c . texte },
yaxis : { range : [ n - 0.5 , - 0.5 ], fixedrange : true , showticklabels : false , showgrid : false , zeroline : false },
newselection : { line : { color : BLEU , width : 1 } }, activeselection : { fillcolor : BLEU , opacity : 0.25 } },
{ responsive : true , displayModeBar : false , doubleClick : false });
}
// Le premier dessin, puis les événements de la barre, une fois
useEffect (() => {
if ( ! Plotly ) return ;
dessinePlots (). then ( dessineBarre ). then (() => aligne ()). then (() => {
barre . current . on ( "plotly_selected" , ev => {
const r = ev ? . range ? . x ;
if ( r ) setChoix ( r . map ( v => String ( v ). slice ( 0 , 16 ). replace ( " " , "T" ) + "Z" ));
});
barre . current . on ( "plotly_deselect" , () => setChoix ( null ));
barre . current . on ( "plotly_click" , ev => courant . current . ouvrir ( tries . current [ ev . points [ 0 ]. pointIndex ]));
setPret ( true );
});
return () => [... Object . values ( figs . current ), barre . current ]. forEach ( g => g && Plotly . purge ( g ));
}, [ Plotly ]);
useEffect (() => { if ( pret ) dessinePlots (). then (() => aligne ( barre . current )); }, [ vues ]);
useEffect (() => { if ( pret ) dessineBarre (); }, [ pret , labels ]);
useEffect (() => { if ( pret ) dessinePlots ( true ). then ( dessineBarre ); }, [ sombre ]);
2026-11-05 15:29:22 +01:00
useEffect (() => { if ( pret ) liste (). forEach ( g => Plotly . relayout ( g , { shapes : zones () })); }, [ pret , labels , choix , ouverte ]);
useEffect (() => {
if ( ! pret || ! barre . current . _fullLayout ) return ;
const k = contour ( tries . current );
Plotly . restyle ( barre . current , { "marker.line.color" : [ k . color ], "marker.line.width" : [ k . width ] });
}, [ ouverte ]);
2026-11-05 15:01:39 +01:00
2026-11-05 15:29:22 +01:00
// Lues à chaque chargement et à chaque changement de source : la page montre toujours le fichier ; les détecteurs tournent
// sur la plage la première fois (une minute ou plus), le serveur garde leur résultat
2026-11-05 15:01:39 +01:00
useEffect (() => {
2026-11-05 15:29:22 +01:00
let vivant = true ;
setLecture ( true );
const url = source === "detecteurs" ? `/api/detecteurs? ${ new URLSearchParams ({ station , du , au } )}`
: `/api/etiquettes? ${ new URLSearchParams ({ station , dossier : source } )}` ;
appel ( url ). then ( l => {
if ( ! vivant ) return ; // une autre source a été choisie entre-temps
setLecture ( false ); setToutes ( l || []); setLabels ( l ? l . filter ( x => x . debut < B && x . fin > A ) : []);
});
return () => { vivant = false ; };
2026-11-05 15:01:39 +01:00
}, [ source ]);
// Un plot de plus : le premier que la page ne montre pas encore, déplacement vertical d'abord
function ajouterPlot () {
const pris = vues . map ( v => v . m ), id = prochain . current ++ ;
const m = [ indice ( "Relative Corrected Vertical Shift" , 0 ), ... PLOTS . keys ()]. find ( i => ! pris . includes ( i )) ?? 0 ;
setVues ([... vues , { id , m }]);
}
function enleverPlot ( id ) {
Plotly . purge ( figs . current [ id ]);
delete figs . current [ id ]; delete dessines . current [ id ];
setVues ( vues . filter ( v => v . id !== id ));
}
const modifiee = () => ouverte && edit && ( edit . texte . trim () !== ouverte . description || edit . categorie !== ( ouverte . categorie || "" )
|| edit . debut + "Z" !== ouverte . debut || edit . fin + "Z" !== ouverte . fin );
// l : l'étiquette à afficher, null pour fermer -> false si Marc garde ses changements non enregistrés
function ouvrir ( l ) {
if ( modifiee () && ! confirm ( "Abandonner les changements de cette étiquette ?" )) return false ;
setOuverte ( l ); setNote ( "" );
2026-11-05 15:29:22 +01:00
setEdit ( l && ! lecteur ? { debut : l . debut . slice ( 0 , 16 ), fin : l . fin . slice ( 0 , 16 ), categorie : l . categorie || "" , texte : l . description } : null );
2026-11-05 15:01:39 +01:00
return true ;
}
async function ajouter () {
const l = await appel ( "/api/etiquettes" , "POST" , { station , dossier : source , debut : choix [ 0 ], fin : choix [ 1 ],
categorie : ajout . categorie , description : ajout . texte . trim () });
if ( ! l ) return ; // rien n'est perdu : le texte et la plage restent dans la page
setLabels ( ls => [... ls , l ]);
setAjout ({ categorie : "" , texte : "" });
await Plotly . relayout ( barre . current , { selections : [] });
setChoix ( null );
}
async function enregistrer () {
const l = await appel ( "/api/etiquettes" , "PUT" , { station , dossier : source , avant : ouverte , debut : edit . debut + "Z" , fin : edit . fin + "Z" ,
categorie : edit . categorie , description : edit . texte . trim () });
if ( ! l ) return ; // rien n'est perdu : le texte et les bornes restent dans la fenêtre
setLabels ( ls => ls . map ( x => ( x === ouverte ? l : x )));
setOuverte ( l ); setNote ( "Enregistrée" );
}
async function supprimer () {
if ( ! confirm ( "Supprimer cette étiquette ?" )) return ;
if ( await appel ( "/api/etiquettes" , "DELETE" , { station , dossier : source , avant : ouverte }) === null ) return ;
setLabels ( ls => ls . filter ( x => x !== ouverte ));
setOuverte ( null ); setEdit ( null );
}
const options = PLOTS . map (( p , i ) => ({ value : String ( i ), label : p . titre }));
const peutEnregistrer = modifiee () && edit . texte . trim () && edit . debut && edit . fin && edit . debut < edit . fin ;
2026-11-05 15:29:22 +01:00
const bornes = ( champ , plus ) => lisible ( toutes . reduce (( m , l ) => ( plus ( l [ champ ], m ) ? l [ champ ] : m ), toutes [ 0 ][ champ ]));
2026-11-05 15:01:39 +01:00
return (
< Card shadow = "sm" withBorder >
< Stack gap = "sm" >
2026-11-05 15:29:22 +01:00
< div >
{ vues . map ( v => (
< div key = { v . id } className = "plot" >
< div ref = { el => { if ( el ) figs . current [ v . id ] = el ; }} />
< Group gap = { 4 } wrap = "nowrap" className = "plot-menu" >
< NativeSelect size = "xs" aria - label = "Plot" data = { options } value = { String ( v . m )} w = { 300 }
onChange = { e => { const m = + e . currentTarget . value ; setVues ( vues . map ( x => ( x . id === v . id ? { ... x , m } : x ))); }} />
{ vues . length > 1 && (
< Tooltip label = "Enlever ce plot" >
< ActionIcon variant = "subtle" color = "gray" aria - label = "Enlever ce plot" onClick = {() => enleverPlot ( v . id )}>< IconX size = { 16 } /></ ActionIcon >
</ Tooltip >
)}
</ Group >
</ div >
))}
2026-11-05 15:01:39 +01:00
{ ! pret && < Loader size = "sm" />}
2026-11-05 15:29:22 +01:00
</ div >
< Group justify = "space-between" gap = "sm" >
< Group gap = "sm" >
< SegmentedControl size = "xs" data = { SOURCES } value = { source } onChange = { v => { if ( ouvrir ( null )) { setSource ( v ); setChoix ( null ); } }} />
{ lecture && < Group gap = { 6 }>< Loader size = "xs" />< Text size = "xs" c = "dimmed" >{ lecteur ? "Les détecteurs tournent sur la plage…" : "Lecture…" }</ Text ></ Group >}
</ Group >
< Button size = "xs" variant = "light" leftSection = {< IconPlus size = { 14 } />} onClick = { ajouterPlot } disabled = { ! pret }> Ajouter un plot </ Button >
2026-11-05 15:01:39 +01:00
</ Group >
< div ref = { barre } />
2026-11-05 15:29:22 +01:00
{ pret && ! lecture && ! labels . length && ( // sinon une barre vide ne dit pas pourquoi
< Text size = "sm" c = "orange" >{ lecteur ? "Les détecteurs ne trouvent aucun événement sur cette plage."
: toutes . length ? `Aucune étiquette ${ source } sur cette plage : celles de ${ station } vont du ${ bornes ( "debut" , ( a , b ) => a < b ) } au ${ bornes ( "fin" , ( a , b ) => a > b ) } UTC.`
2026-11-05 15:01:39 +01:00
: ` ${ station } n'a aucune étiquette dans labeling/ ${ source } /.` }</ Text >
)}
2026-11-05 15:29:22 +01:00
{ ouverte && lecteur && (
< Card withBorder bg = "var(--mantine-color-default-hover)" >
< Stack gap = { 6 }>
< Group gap = "xs" >
< Badge color = { couleur ( ouverte )} c = "#1a1b1e" >{ ouverte . categorie }</ Badge >
< Text size = "sm" fw = { 500 }>{ ouverte . sorte }</ Text >
{ ouverte . ignore && < Badge variant = "outline" color = "gray" > grisé au journal </ Badge >}
</ Group >
< Text size = "sm" >{ lisible ( ouverte . debut )} → { lisible ( ouverte . fin )} UTC · { ouverte . capteurs . length
? ` ${ ouverte . capteurs . length } capteur ${ ouverte . capteurs . length > 1 ? "s" : "" } : ${ ouverte . capteurs . join ( ", " ) } ` : "tous les capteurs" }</ Text >
< Text size = "sm" >{ ouverte . description }</ Text >
< Group >< Button size = "xs" variant = "default" onClick = {() => ouvrir ( null )}> Fermer </ Button ></ Group >
</ Stack >
</ Card >
)}
2026-11-05 15:01:39 +01:00
{ ouverte && edit && (
< Card withBorder bg = "var(--mantine-color-default-hover)" >
< Stack gap = "xs" >
< Group gap = "sm" align = "flex-end" >
< TextInput label = "Du (UTC)" type = "datetime-local" step = { 60 } value = { edit . debut } onChange = { e => setEdit ({ ... edit , debut : e . currentTarget . value })} />
< TextInput label = "Au (UTC)" type = "datetime-local" step = { 60 } value = { edit . fin } onChange = { e => setEdit ({ ... edit , fin : e . currentTarget . value })} />
< NativeSelect label = "Famille" data = { CHOIX_FAMILLE } value = { edit . categorie } onChange = { e => setEdit ({ ... edit , categorie : e . currentTarget . value })} />
</ Group >
< Textarea autosize minRows = { 3 } value = { edit . texte } onChange = { e => setEdit ({ ... edit , texte : e . currentTarget . value })} />
< Group gap = "sm" >
< Button onClick = { enregistrer } disabled = { ! peutEnregistrer }> Enregistrer </ Button >
< Button variant = "default" onClick = {() => ouvrir ( null )}> Fermer </ Button >
< Text size = "sm" c = "teal" >{ note }</ Text >
< Button color = "red" variant = "light" ml = "auto" onClick = { supprimer }> Supprimer </ Button >
</ Group >
</ Stack >
</ Card >
)}
2026-11-05 15:29:22 +01:00
{ ! lecteur && <>
< Text size = "sm" >{ choix ? ` ${ lisible ( choix [ 0 ]) } → ${ lisible ( choix [ 1 ]) } UTC` : "Glisser sur la barre des étiquettes pour sélectionner une plage." }</ Text >
< NativeSelect label = "Famille" data = { CHOIX_FAMILLE } value = { ajout . categorie } onChange = { e => setAjout ({ ... ajout , categorie : e . currentTarget . value })} maw = { 300 } />
< Textarea autosize minRows = { 3 } placeholder = "Que voit-on sur cette plage ?" value = { ajout . texte }
onChange = { e => setAjout ({ ... ajout , texte : e . currentTarget . value })} />
< Group >< Button onClick = { ajouter } disabled = { ! ( choix && choix [ 0 ] < choix [ 1 ] && ajout . texte . trim ())}> Ajouter </ Button ></ Group >
</>}
2026-11-05 15:01:39 +01:00
</ Stack >
</ Card >
);
}