From 860271b13f73cf25eaeb75f71c45c3e87e87fbc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alessandro=20Gon=C3=A7aalves?= Date: Mon, 10 Nov 2025 16:49:22 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20corre=C3=A7=C3=A3o=20de=20alinhamento?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/DRE/teste.tsx | 373 +++++++++++++++++++----------------------- 1 file changed, 166 insertions(+), 207 deletions(-) diff --git a/src/app/DRE/teste.tsx b/src/app/DRE/teste.tsx index 7d24854..908c6bd 100644 --- a/src/app/DRE/teste.tsx +++ b/src/app/DRE/teste.tsx @@ -251,19 +251,6 @@ export default function Teste() { }); const [linhaSelecionada, setLinhaSelecionada] = useState(null); const [isAllExpanded, setIsAllExpanded] = useState(false); - - // Refs para sincronizar scroll vertical entre coluna fixa e valores - const descricaoScrollRef = React.useRef(null); - const valoresScrollRef = React.useRef(null); - - // Função para sincronizar scroll vertical - const syncScroll = (source: 'descricao' | 'valores') => { - if (source === 'descricao' && descricaoScrollRef.current && valoresScrollRef.current) { - valoresScrollRef.current.scrollTop = descricaoScrollRef.current.scrollTop; - } else if (source === 'valores' && descricaoScrollRef.current && valoresScrollRef.current) { - descricaoScrollRef.current.scrollTop = valoresScrollRef.current.scrollTop; - } - }; useEffect(() => { // Carregar períodos disponíveis da API @@ -2191,7 +2178,7 @@ export default function Teste() { if (isSelected) { style += - " bg-green-100 shadow-lg"; + " bg-gradient-to-r from-green-100 to-emerald-100 border-l-4 border-green-500 shadow-lg"; } switch (row.type) { @@ -2212,6 +2199,35 @@ export default function Teste() { } }; + // Função para obter o background da célula fixa baseado no tipo de linha + const getFixedCellBackground = (row: HierarchicalRow): string => { + const linhaId = `${row.type}-${row.grupo || ""}-${row.subgrupo || ""}-${ + row.centro_custo || "" + }-${row.codigo_conta || ""}`; + const isSelected = linhaSelecionada === linhaId; + const isCalculado = row.isCalculado === true; + + if (isSelected) { + return "bg-gradient-to-r from-green-100 to-emerald-100"; + } + + switch (row.type) { + case "grupo": + if (isCalculado) { + return "bg-gradient-to-r from-blue-100 to-indigo-100"; + } + return "bg-gradient-to-r from-blue-50 to-indigo-50"; + case "subgrupo": + return "bg-gradient-to-r from-gray-50 to-blue-50"; + case "centro_custo": + return "bg-gradient-to-r from-gray-50 to-gray-100"; + case "conta": + return "bg-white"; + default: + return "bg-white"; + } + }; + const getIndentStyle = (level: number) => { return { paddingLeft: `${level * 20}px` }; }; @@ -2802,206 +2818,149 @@ export default function Teste() { {/* Table Container */} {filtrosAplicados && !loading && !error && (
- {/* Container com coluna fixa e scroll horizontal */} -
- {/* Coluna fixa - Descrição */} -
- {/* Header fixo da descrição */} -
-
- Descrição -
-
- {/* Corpo da descrição com scroll vertical */} -
syncScroll('descricao')} - > - {hierarchicalData.map((row, index) => { - const linhaId = `${row.type}-${row.grupo || ""}-${row.subgrupo || ""}-${row.centro_custo || ""}-${row.codigo_conta || ""}`; - const isSelected = linhaSelecionada === linhaId; - return ( -
handleRowClick(row)} - > -
-
- {renderCellContent(row)} -
-
-
- ); - })} -
-
- - {/* Parte com scroll - Valores */} -
-
syncScroll('valores')} - > - - {/* Table Header */} - - - {mesesDisponiveis.map((mes) => ( - - - - - ))} - + ); + })} + +
- {mes} - - % - - Total + {/* Scroll Container - Apenas um container com scroll */} +
+ {/* Table */} + + {/* Table Header */} + + + + {mesesDisponiveis.map((mes) => ( + + - - - - {/* Table Body */} - - {hierarchicalData.map((row, index) => { - const linhaId = `${row.type}-${row.grupo || ""}-${row.subgrupo || ""}-${row.centro_custo || ""}-${row.codigo_conta || ""}`; - const isSelected = linhaSelecionada === linhaId; - return ( - - {/* Colunas de valores por mês */} - {mesesDisponiveis.map((mes) => ( - - - + + + + + {/* Table Body */} + + {hierarchicalData.map((row, index) => { + const linhaId = `${row.type}-${row.grupo || ""}-${row.subgrupo || ""}-${row.centro_custo || ""}-${row.codigo_conta || ""}`; + const isSelected = linhaSelecionada === linhaId; + return ( + + + + {/* Colunas de valores por mês */} + {mesesDisponiveis.map((mes) => ( + + + - - ))} - - {/* Coluna Total */} - - - {/* Coluna Percentual Total */} - + + ))} + + {/* Coluna Total */} + + + {/* Coluna Percentual Total */} + - - ); - })} - -
+ Descrição + + {mes} %
handleRowClick(row, mes)} - title={ - row.valoresPorMes && row.valoresPorMes[mes] - ? formatCurrency(row.valoresPorMes[mes]) - : "-" - } - > - {row.valoresPorMes && row.valoresPorMes[mes] - ? (() => { - const { formatted, isNegative } = - formatCurrencyWithColor(row.valoresPorMes[mes]); - return ( - - {formatted} - - ); - })() - : "-"} - handleRowClick(row, mes)} - title={ - row.percentuaisPorMes && - row.percentuaisPorMes[mes] !== undefined - ? `${row.percentuaisPorMes[mes].toFixed(1)}%` - : "-" - } - > - {row.percentuaisPorMes && + + ))} + + Total + + % +
handleRowClick(row)} + > +
+ {renderCellContent(row)} +
+
handleRowClick(row, mes)} + title={ + row.valoresPorMes && row.valoresPorMes[mes] + ? formatCurrency(row.valoresPorMes[mes]) + : "-" + } + > + {row.valoresPorMes && row.valoresPorMes[mes] + ? (() => { + const { formatted, isNegative } = + formatCurrencyWithColor(row.valoresPorMes[mes]); + return ( + + {formatted} + + ); + })() + : "-"} + handleRowClick(row, mes)} + title={ + row.percentuaisPorMes && row.percentuaisPorMes[mes] !== undefined ? `${row.percentuaisPorMes[mes].toFixed(1)}%` - : "-"} - handleRowClick(row)} - title={row.total ? formatCurrency(row.total) : "-"} - > - {(() => { - const { formatted, isNegative } = formatCurrencyWithColor( - row.total! - ); - return ( - - {formatted} - - ); - })()} - handleRowClick(row)} - title={ - row.percentualTotal !== undefined - ? `${row.percentualTotal.toFixed(1)}%` - : "-" - } - > - {row.percentualTotal !== undefined + : "-" + } + > + {row.percentuaisPorMes && + row.percentuaisPorMes[mes] !== undefined + ? `${row.percentuaisPorMes[mes].toFixed(1)}%` + : "-"} + handleRowClick(row)} + title={row.total ? formatCurrency(row.total) : "-"} + > + {(() => { + const { formatted, isNegative } = formatCurrencyWithColor( + row.total! + ); + return ( + + {formatted} + + ); + })()} + handleRowClick(row)} + title={ + row.percentualTotal !== undefined ? `${row.percentualTotal.toFixed(1)}%` - : "-"} -
-
- + : "-" + } + > + {row.percentualTotal !== undefined + ? `${row.percentualTotal.toFixed(1)}%` + : "-"} + +
)}