From f4d4cd173f4a6c461a3a6f7a92c00183758a039a Mon Sep 17 00:00:00 2001 From: dmolinari Date: Mon, 8 Sep 2025 15:23:18 -0300 Subject: [PATCH] Fix Tabla Columnas --- .../ResultadosRankingMunicipioWidget.tsx | 114 ++++++++++-------- .../ResultadosTablaSeccionWidget.css | 8 +- 2 files changed, 70 insertions(+), 52 deletions(-) diff --git a/Elecciones-Web/frontend/src/components/ResultadosRankingMunicipioWidget.tsx b/Elecciones-Web/frontend/src/components/ResultadosRankingMunicipioWidget.tsx index 8a2c0c6..29c8bd5 100644 --- a/Elecciones-Web/frontend/src/components/ResultadosRankingMunicipioWidget.tsx +++ b/Elecciones-Web/frontend/src/components/ResultadosRankingMunicipioWidget.tsx @@ -3,7 +3,7 @@ import { useQuery } from '@tanstack/react-query'; import Select from 'react-select'; import { getSeccionesElectorales, getRankingMunicipiosPorSeccion } from '../apiService'; import type { MunicipioSimple, ApiResponseRankingMunicipio, RankingPartido } from '../types/types'; -import './ResultadosTablaSeccionWidget.css'; +import './ResultadosTablaSeccionWidget.css'; type DisplayMode = 'porcentaje' | 'votos' | 'ambos'; type DisplayOption = { @@ -18,8 +18,8 @@ const displayModeOptions: readonly DisplayOption[] = [ ]; const customSelectStyles = { - control: (base: any) => ({ ...base, minWidth: '200px', border: '1px solid #ced4da', boxShadow: 'none', '&:hover': { borderColor: '#86b7fe' } }), - menu: (base: any) => ({ ...base, zIndex: 10 }), + control: (base: any) => ({ ...base, minWidth: '200px', border: '1px solid #ced4da', boxShadow: 'none', '&:hover': { borderColor: '#86b7fe' } }), + menu: (base: any) => ({ ...base, zIndex: 10 }), }; const formatPercent = (porcentaje: number) => `${porcentaje.toFixed(2).replace('.', ',')}%`; @@ -50,41 +50,41 @@ const CellRenderer = ({ partido, mode }: { partido?: RankingPartido, mode: Displ export const ResultadosRankingMunicipioWidget = () => { - const [secciones, setSecciones] = useState([]); - const [selectedSeccion, setSelectedSeccion] = useState<{ value: string; label: string } | null>(null); - const [displayMode, setDisplayMode] = useState(displayModeOptions[0]); + const [secciones, setSecciones] = useState([]); + const [selectedSeccion, setSelectedSeccion] = useState<{ value: string; label: string } | null>(null); + const [displayMode, setDisplayMode] = useState(displayModeOptions[0]); - useEffect(() => { - const fetchSecciones = async () => { - const seccionesData = await getSeccionesElectorales(); - if (seccionesData && seccionesData.length > 0) { - const orden = new Map([ - ['Capital', 0], ['Primera', 1], ['Segunda', 2], ['Tercera', 3], - ['Cuarta', 4], ['Quinta', 5], ['Sexta', 6], ['Séptima', 7] - ]); - const getOrden = (nombre: string) => { - const match = nombre.match(/Capital|Primera|Segunda|Tercera|Cuarta|Quinta|Sexta|Séptima/); - return match ? orden.get(match[0]) ?? 99 : 99; + useEffect(() => { + const fetchSecciones = async () => { + const seccionesData = await getSeccionesElectorales(); + if (seccionesData && seccionesData.length > 0) { + const orden = new Map([ + ['Capital', 0], ['Primera', 1], ['Segunda', 2], ['Tercera', 3], + ['Cuarta', 4], ['Quinta', 5], ['Sexta', 6], ['Séptima', 7] + ]); + const getOrden = (nombre: string) => { + const match = nombre.match(/Capital|Primera|Segunda|Tercera|Cuarta|Quinta|Sexta|Séptima/); + return match ? orden.get(match[0]) ?? 99 : 99; + }; + seccionesData.sort((a, b) => getOrden(a.nombre) - getOrden(b.nombre)); + setSecciones(seccionesData); + if (!selectedSeccion) { + setSelectedSeccion({ value: seccionesData[0].id, label: seccionesData[0].nombre }); + } + } }; - seccionesData.sort((a, b) => getOrden(a.nombre) - getOrden(b.nombre)); - setSecciones(seccionesData); - if (!selectedSeccion) { - setSelectedSeccion({ value: seccionesData[0].id, label: seccionesData[0].nombre }); - } - } - }; - fetchSecciones(); - }, [selectedSeccion]); + fetchSecciones(); + }, [selectedSeccion]); - const seccionOptions = useMemo(() => secciones.map(s => ({ value: s.id, label: s.nombre })), [secciones]); + const seccionOptions = useMemo(() => secciones.map(s => ({ value: s.id, label: s.nombre })), [secciones]); - const { data: rankingData, isLoading } = useQuery({ - queryKey: ['rankingMunicipiosPorSeccion', selectedSeccion?.value], - queryFn: () => getRankingMunicipiosPorSeccion(selectedSeccion!.value), - enabled: !!selectedSeccion, - }); + const { data: rankingData, isLoading } = useQuery({ + queryKey: ['rankingMunicipiosPorSeccion', selectedSeccion?.value], + queryFn: () => getRankingMunicipiosPorSeccion(selectedSeccion!.value), + enabled: !!selectedSeccion, + }); - return ( + return (

Resultados por Municipio

@@ -92,11 +92,7 @@ export const ResultadosRankingMunicipioWidget = () => {