fix: correção da expansão do drill
This commit is contained in:
parent
4226fa6c76
commit
362d422fce
|
|
@ -1,6 +1,6 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { LoaderPinwheel, ChevronDown, ChevronRight, Filter } from "lucide-react";
|
import { LoaderPinwheel, ChevronDown, ChevronRight, Filter, Maximize2, Minimize2 } from "lucide-react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import AnaliticoComponent from "./analitico";
|
import AnaliticoComponent from "./analitico";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
@ -103,6 +103,7 @@ export default function Teste() {
|
||||||
linhaSelecionada: "", // Adicionar informação da linha selecionada
|
linhaSelecionada: "", // Adicionar informação da linha selecionada
|
||||||
});
|
});
|
||||||
const [linhaSelecionada, setLinhaSelecionada] = useState<string | null>(null);
|
const [linhaSelecionada, setLinhaSelecionada] = useState<string | null>(null);
|
||||||
|
const [isAllExpanded, setIsAllExpanded] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Carregar períodos disponíveis da API
|
// Carregar períodos disponíveis da API
|
||||||
|
|
@ -350,6 +351,29 @@ export default function Teste() {
|
||||||
setContasSelecionadas([]);
|
setContasSelecionadas([]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toggleExpandAll = () => {
|
||||||
|
if (isAllExpanded) {
|
||||||
|
// Recolher tudo
|
||||||
|
setExpandedGroups(new Set());
|
||||||
|
setExpandedSubgrupos(new Set());
|
||||||
|
setExpandedCentros(new Set());
|
||||||
|
setIsAllExpanded(false);
|
||||||
|
} else {
|
||||||
|
// Expandir todos os grupos usando dados originais
|
||||||
|
const todosGrupos = [...new Set(data.map(item => item.grupo))];
|
||||||
|
setExpandedGroups(new Set(todosGrupos));
|
||||||
|
|
||||||
|
// Expandir todos os subgrupos usando dados originais
|
||||||
|
const todosSubgrupos = [...new Set(data.map(item => `${item.grupo}-${item.subgrupo}`))];
|
||||||
|
setExpandedSubgrupos(new Set(todosSubgrupos));
|
||||||
|
|
||||||
|
// Expandir todos os centros de custo usando dados originais (isso também expande as contas automaticamente)
|
||||||
|
const todosCentros = [...new Set(data.map(item => `${item.grupo}-${item.subgrupo}-${item.centro_custo}`))];
|
||||||
|
setExpandedCentros(new Set(todosCentros));
|
||||||
|
setIsAllExpanded(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const limparFiltros = () => {
|
const limparFiltros = () => {
|
||||||
const agora = new Date();
|
const agora = new Date();
|
||||||
const anoAtual = agora.getFullYear();
|
const anoAtual = agora.getFullYear();
|
||||||
|
|
@ -377,6 +401,7 @@ export default function Teste() {
|
||||||
setDadosFiltrados([]);
|
setDadosFiltrados([]);
|
||||||
setFiltrosAplicados(false);
|
setFiltrosAplicados(false);
|
||||||
setMesesDisponiveis([]);
|
setMesesDisponiveis([]);
|
||||||
|
setIsAllExpanded(false);
|
||||||
|
|
||||||
// Recarregar opções e selecionar todos novamente
|
// Recarregar opções e selecionar todos novamente
|
||||||
carregarPeriodosDisponiveis();
|
carregarPeriodosDisponiveis();
|
||||||
|
|
@ -888,8 +913,31 @@ export default function Teste() {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Botão de Filtro */}
|
{/* Controles */}
|
||||||
<Sheet open={isFilterOpen} onOpenChange={setIsFilterOpen}>
|
<div className="flex items-center gap-2">
|
||||||
|
{/* Botão de Expandir/Recolher */}
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={toggleExpandAll}
|
||||||
|
disabled={!filtrosAplicados || hierarchicalData.length === 0}
|
||||||
|
className="flex items-center gap-2 text-xs h-8 px-3"
|
||||||
|
>
|
||||||
|
{isAllExpanded ? (
|
||||||
|
<>
|
||||||
|
<Minimize2 className="w-4 h-4" />
|
||||||
|
Recolher Tudo
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Maximize2 className="w-4 h-4" />
|
||||||
|
Expandir Tudo
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{/* Botão de Filtro */}
|
||||||
|
<Sheet open={isFilterOpen} onOpenChange={setIsFilterOpen}>
|
||||||
<SheetTrigger asChild>
|
<SheetTrigger asChild>
|
||||||
<Button variant="outline" className="flex items-center gap-2">
|
<Button variant="outline" className="flex items-center gap-2">
|
||||||
<Filter className="w-4 h-4" />
|
<Filter className="w-4 h-4" />
|
||||||
|
|
@ -1043,7 +1091,7 @@ export default function Teste() {
|
||||||
Limpar
|
Limpar
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="max-h-32 overflow-y-auto border rounded-md p-1 space-y-1">
|
<div className="max-h-32 overflow-y-auto border rounded-md p-1 space-y-1">
|
||||||
{opcoesContas.map(conta => (
|
{opcoesContas.map(conta => (
|
||||||
<div key={conta} className="flex items-center space-x-1">
|
<div key={conta} className="flex items-center space-x-1">
|
||||||
|
|
@ -1126,6 +1174,7 @@ export default function Teste() {
|
||||||
</SheetFooter>
|
</SheetFooter>
|
||||||
</SheetContent>
|
</SheetContent>
|
||||||
</Sheet>
|
</Sheet>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -1208,49 +1257,6 @@ export default function Teste() {
|
||||||
))}
|
))}
|
||||||
<div className="flex-1 min-w-[120px] text-right">Total</div>
|
<div className="flex-1 min-w-[120px] text-right">Total</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Botões de controle */}
|
|
||||||
<div className="flex gap-1 ml-4">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => {
|
|
||||||
// Expandir todos os grupos
|
|
||||||
const todosGrupos = hierarchicalData
|
|
||||||
.filter(row => row.type === "grupo")
|
|
||||||
.map(row => row.grupo!);
|
|
||||||
setExpandedGroups(new Set(todosGrupos));
|
|
||||||
|
|
||||||
// Expandir todos os subgrupos
|
|
||||||
const todosSubgrupos = hierarchicalData
|
|
||||||
.filter(row => row.type === "subgrupo")
|
|
||||||
.map(row => `${row.grupo}-${row.subgrupo}`);
|
|
||||||
setExpandedSubgrupos(new Set(todosSubgrupos));
|
|
||||||
|
|
||||||
// Expandir todos os centros de custo
|
|
||||||
const todosCentros = hierarchicalData
|
|
||||||
.filter(row => row.type === "centro_custo")
|
|
||||||
.map(row => `${row.grupo}-${row.subgrupo}-${row.centro_custo}`);
|
|
||||||
setExpandedCentros(new Set(todosCentros));
|
|
||||||
}}
|
|
||||||
className="text-xs h-5 px-2"
|
|
||||||
>
|
|
||||||
Expandir Tudo
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => {
|
|
||||||
// Recolher tudo
|
|
||||||
setExpandedGroups(new Set());
|
|
||||||
setExpandedSubgrupos(new Set());
|
|
||||||
setExpandedCentros(new Set());
|
|
||||||
}}
|
|
||||||
className="text-xs h-5 px-2"
|
|
||||||
>
|
|
||||||
Recolher Tudo
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue