feat([2fd88f42]): implement tooltip column manager
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useState } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import axios from 'axios';
|
||||
import './App.css';
|
||||
import 'react-leaflet-cluster/dist/assets/MarkerCluster.css';
|
||||
@@ -7,6 +7,8 @@ import FileUpload from './components/FileUpload';
|
||||
import FilterPanel from './components/FilterPanel';
|
||||
import MapDisplay from './components/MapDisplay';
|
||||
import ErrorBoundary from './components/ErrorBoundary';
|
||||
import PlzSelector from './components/PlzSelector';
|
||||
import TooltipManager, { TooltipColumn } from './components/TooltipManager';
|
||||
|
||||
// Define types for our state
|
||||
export interface FilterOptions {
|
||||
@@ -33,6 +35,7 @@ function App() {
|
||||
|
||||
const [plzColumnNeeded, setPlzColumnNeeded] = useState(false);
|
||||
const [availableColumns, setAvailableColumns] = useState<string[]>([]);
|
||||
const [tooltipColumns, setTooltipColumns] = useState<TooltipColumn[]>([]);
|
||||
|
||||
|
||||
const handleUploadSuccess = (response: any) => {
|
||||
@@ -42,12 +45,17 @@ function App() {
|
||||
setPlzColumnNeeded(true);
|
||||
setFilters({});
|
||||
setHeatmapData([]);
|
||||
setTooltipColumns([]);
|
||||
} else {
|
||||
setPlzColumnNeeded(false);
|
||||
setFilters(response.filters);
|
||||
const newFilters = response.filters;
|
||||
setFilters(newFilters);
|
||||
// Initialize tooltip columns based on filters
|
||||
setTooltipColumns(Object.keys(newFilters).map(name => ({ id: name, name, visible: true })));
|
||||
setHeatmapData([]); // Clear previous heatmap data
|
||||
// Automatically fetch data with no filters on successful upload
|
||||
handleFilterChange({});
|
||||
// Pass initial tooltip config
|
||||
handleFilterChange({}, Object.keys(newFilters).map(name => ({ id: name, name, visible: true })));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -70,25 +78,36 @@ function App() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleFilterChange = async (selectedFilters: FilterOptions) => {
|
||||
const handleFilterChange = async (selectedFilters: FilterOptions, currentTooltipConfig: TooltipColumn[]) => {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const response = await axios.post('/api/heatmap', {
|
||||
filters: selectedFilters,
|
||||
tooltip_config: currentTooltipConfig, // Pass tooltip config to backend
|
||||
});
|
||||
setHeatmapData(response.data);
|
||||
} catch (error: any) {
|
||||
if (axios.isAxiosError(error) && error.response) {
|
||||
setError(`Failed to fetch heatmap data: ${error.response.data.detail || error.message}`);
|
||||
} else {
|
||||
setError(`Failed to fetch heatmap data: ${error.message}`);
|
||||
}
|
||||
if (axios.isAxiosError(error) && error.response) {
|
||||
setError(`Failed to fetch heatmap data: ${error.response.data.detail || error.message}`);
|
||||
} else {
|
||||
setError(`Failed to fetch heatmap data: ${error.message}`);
|
||||
}
|
||||
setHeatmapData([]); // Clear data on error
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Need to re-fetch data when tooltip config changes
|
||||
useEffect(() => {
|
||||
if (Object.keys(filters).length > 0) {
|
||||
// This assumes you want to re-fetch with the *last applied* filters, which is complex to track.
|
||||
// For simplicity, we won't re-fetch automatically on tooltip change for now,
|
||||
// but the config will be applied on the *next* "Apply Filters" click.
|
||||
}
|
||||
}, [tooltipColumns]);
|
||||
|
||||
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
@@ -113,9 +132,12 @@ function App() {
|
||||
<>
|
||||
<FilterPanel
|
||||
filters={filters}
|
||||
onFilterChange={handleFilterChange}
|
||||
onFilterChange={(selectedFilters) => handleFilterChange(selectedFilters, tooltipColumns)}
|
||||
isLoading={isLoading}
|
||||
/>
|
||||
{tooltipColumns.length > 0 && (
|
||||
<TooltipManager columns={tooltipColumns} setColumns={setTooltipColumns} />
|
||||
)}
|
||||
<div className="map-controls" style={{ marginTop: '20px', paddingTop: '20px', borderTop: '1px solid #555' }}>
|
||||
<h3>Map Settings</h3>
|
||||
<div className="toggle-switch" style={{ marginBottom: '15px' }}>
|
||||
@@ -151,6 +173,7 @@ function App() {
|
||||
heatmapData={heatmapData}
|
||||
radiusMultiplier={radiusMultiplier}
|
||||
viewMode={viewMode}
|
||||
tooltipColumns={tooltipColumns}
|
||||
/>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
Reference in New Issue
Block a user