fix: remoção botão teste
This commit is contained in:
parent
2aa410a96f
commit
d60051d5dc
|
|
@ -624,51 +624,31 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
|
||||||
|
|
||||||
// Filtrar dados baseado nos filtros de coluna
|
// Filtrar dados baseado nos filtros de coluna
|
||||||
const filteredData = React.useMemo(() => {
|
const filteredData = React.useMemo(() => {
|
||||||
console.log('🔍 Debug filteredData - data:', data?.length, 'columnFilters:', columnFilters);
|
if (!data || data.length === 0) return data;
|
||||||
|
|
||||||
if (!data || data.length === 0) {
|
return data.filter((row) => {
|
||||||
console.log('⚠️ No data available');
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
const filtered = data.filter((row) => {
|
|
||||||
return Object.entries(columnFilters).every(([field, filterValues]) => {
|
return Object.entries(columnFilters).every(([field, filterValues]) => {
|
||||||
if (!filterValues || filterValues.length === 0) return true;
|
if (!filterValues || filterValues.length === 0) return true;
|
||||||
|
|
||||||
const cellValue = (row as any)[field];
|
const cellValue = (row as any)[field];
|
||||||
const stringValue = cellValue === null || cellValue === undefined ? "" : String(cellValue);
|
const stringValue = cellValue === null || cellValue === undefined ? "" : String(cellValue);
|
||||||
|
|
||||||
const matches = filterValues.includes(stringValue);
|
return filterValues.includes(stringValue);
|
||||||
if (!matches) {
|
|
||||||
console.log(`❌ Filter mismatch - Field: ${field}, CellValue: ${cellValue}, StringValue: ${stringValue}, FilterValues:`, filterValues);
|
|
||||||
}
|
|
||||||
return matches;
|
|
||||||
});
|
});
|
||||||
}).map((row, index) => ({
|
}).map((row, index) => ({
|
||||||
...row,
|
...row,
|
||||||
id: `filtered-${row.id || row.recnum || index}` // Garantir ID único e estável
|
id: `filtered-${row.id || row.recnum || index}` // Garantir ID único e estável
|
||||||
}));
|
}));
|
||||||
|
|
||||||
console.log('✅ Filtered result:', filtered.length, 'out of', data.length);
|
|
||||||
return filtered;
|
|
||||||
}, [data, columnFilters]);
|
}, [data, columnFilters]);
|
||||||
|
|
||||||
// Ordenar dados baseado na ordenação de coluna
|
// Ordenar dados baseado na ordenação de coluna
|
||||||
const sortedAndFilteredData = React.useMemo(() => {
|
const sortedAndFilteredData = React.useMemo(() => {
|
||||||
console.log('🔍 Debug sortedAndFilteredData - filteredData:', filteredData?.length, 'columnSorts:', columnSorts);
|
if (!filteredData || filteredData.length === 0) return filteredData;
|
||||||
|
|
||||||
if (!filteredData || filteredData.length === 0) {
|
|
||||||
console.log('⚠️ No filtered data available');
|
|
||||||
return filteredData;
|
|
||||||
}
|
|
||||||
|
|
||||||
const sortField = Object.keys(columnSorts).find(field => columnSorts[field] !== null);
|
const sortField = Object.keys(columnSorts).find(field => columnSorts[field] !== null);
|
||||||
if (!sortField || !columnSorts[sortField]) {
|
if (!sortField || !columnSorts[sortField]) return filteredData;
|
||||||
console.log('✅ No sorting applied, returning filtered data as is');
|
|
||||||
return filteredData;
|
|
||||||
}
|
|
||||||
|
|
||||||
const sorted = [...filteredData].sort((a, b) => {
|
return [...filteredData].sort((a, b) => {
|
||||||
const aValue = (a as any)[sortField];
|
const aValue = (a as any)[sortField];
|
||||||
const bValue = (b as any)[sortField];
|
const bValue = (b as any)[sortField];
|
||||||
|
|
||||||
|
|
@ -682,29 +662,8 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
|
||||||
return bString.localeCompare(aString);
|
return bString.localeCompare(aString);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('✅ Sorted result:', sorted.length);
|
|
||||||
return sorted;
|
|
||||||
}, [filteredData, columnSorts]);
|
}, [filteredData, columnSorts]);
|
||||||
|
|
||||||
// Debug useEffect para investigar estado inicial
|
|
||||||
React.useEffect(() => {
|
|
||||||
console.log('🔍 Debug Estado Inicial:');
|
|
||||||
console.log('📊 data:', data?.length);
|
|
||||||
console.log('🔍 columnFilters:', columnFilters);
|
|
||||||
console.log('📈 columnSorts:', columnSorts);
|
|
||||||
console.log('🌐 globalFilter:', globalFilter);
|
|
||||||
console.log('🔗 filtrosExternos:', filtrosExternos);
|
|
||||||
}, [data, columnFilters, columnSorts, globalFilter, filtrosExternos]);
|
|
||||||
|
|
||||||
// Debug useEffect para DataGrid
|
|
||||||
React.useEffect(() => {
|
|
||||||
console.log('🔍 Debug DataGrid - sortedAndFilteredData:', sortedAndFilteredData?.length, 'loading:', loading);
|
|
||||||
if (sortedAndFilteredData && sortedAndFilteredData.length > 0) {
|
|
||||||
console.log('📊 First row sample:', sortedAndFilteredData[0]);
|
|
||||||
}
|
|
||||||
}, [sortedAndFilteredData, loading]);
|
|
||||||
|
|
||||||
// Calcular valor total dos dados filtrados
|
// Calcular valor total dos dados filtrados
|
||||||
const valorTotal = React.useMemo(() => {
|
const valorTotal = React.useMemo(() => {
|
||||||
return sortedAndFilteredData.reduce((sum, item) => sum + (Number(item.valor) || 0), 0);
|
return sortedAndFilteredData.reduce((sum, item) => sum + (Number(item.valor) || 0), 0);
|
||||||
|
|
@ -846,26 +805,6 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
|
||||||
)}
|
)}
|
||||||
{data.length > 0 && (
|
{data.length > 0 && (
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Button
|
|
||||||
onClick={() => {
|
|
||||||
console.log('🧪 Teste - Forçando dados para aparecer');
|
|
||||||
console.log('📊 data atual:', data.length);
|
|
||||||
console.log('🔍 columnFilters atual:', columnFilters);
|
|
||||||
console.log('📈 sortedAndFilteredData atual:', sortedAndFilteredData.length);
|
|
||||||
|
|
||||||
// Limpar todos os filtros
|
|
||||||
setColumnFilters({});
|
|
||||||
setColumnSorts({});
|
|
||||||
setGlobalFilter("");
|
|
||||||
|
|
||||||
console.log('✅ Filtros limpos');
|
|
||||||
}}
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
className="bg-yellow-100 border-yellow-300 text-yellow-800 hover:bg-yellow-200"
|
|
||||||
>
|
|
||||||
🧪 Teste Debug
|
|
||||||
</Button>
|
|
||||||
<Button
|
<Button
|
||||||
onClick={clearAllFilters}
|
onClick={clearAllFilters}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|
@ -936,11 +875,7 @@ export default function AnaliticoComponent({ filtros }: AnaliticoProps) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
getRowId={(row: any) => {
|
getRowId={(row: any) => row.id || `row-${row.recnum || Math.random()}`}
|
||||||
const id = row.id || row.recnum || `row-${Math.random()}`;
|
|
||||||
console.log('🔍 getRowId called for row:', { id, recnum: row.recnum, nome_fornecedor: row.nome_fornecedor });
|
|
||||||
return id;
|
|
||||||
}}
|
|
||||||
sx={{
|
sx={{
|
||||||
"& .MuiDataGrid-columnHeaders": {
|
"& .MuiDataGrid-columnHeaders": {
|
||||||
position: "sticky",
|
position: "sticky",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue