Update SampleTracker to support dynamic activePgroup

Enhanced the `SampleTracker` component to accept and utilize an `activePgroup` prop, allowing dynamic filtering of data based on the current project group. Adjusted related polling and data fetching logic to respond to changes in `activePgroup`. Removed excessive code from the test notebook for cleanup.
This commit is contained in:
GotthardG
2025-02-27 11:20:04 +01:00
parent 2f5cb3032a
commit 548a86678b
4 changed files with 46 additions and 22 deletions

View File

@ -26,35 +26,37 @@ interface Puck {
samples: Sample[];
}
const SampleTracker: React.FC = () => {
interface SampleTrackerProps {
activePgroup: string;
}
const SampleTracker: React.FC<SampleTrackerProps> = ({ activePgroup }) => {
const [pucks, setPucks] = useState<Puck[]>([]);
const [hoveredSample, setHoveredSample] = useState<{ name: string; status: string } | null>(null);
// Fetch latest sample data
const fetchPucks = async () => {
try {
const data: Puck[] = await SamplesService.getAllPucksWithSamplesAndEventsSamplesPucksSamplesGet();
console.log('Fetched Pucks:', data); // Check for dynamic mount_count and unmount_count
const data: Puck[] = await SamplesService.getAllPucksWithSamplesAndEventsSamplesPucksSamplesGet(activePgroup);
console.log('Fetched Pucks:', data);
setPucks(data);
} catch (error) {
console.error('Error fetching pucks', error);
}
};
// Polling logic using a 1-second interval
useEffect(() => {
// Fetch data immediately on component mount
fetchPucks();
// Set up polling every 1 second
const interval = setInterval(() => {
fetchPucks();
}, 100000);
}, 1000);
// Clear interval on component unmount
return () => clearInterval(interval);
}, []);
}, [activePgroup]);
const getSampleColor = (events: Event[] = []) => {
const hasMounted = events.some((e) => e.event_type === 'Mounted');

View File

@ -14,7 +14,7 @@ const ResultsView: React.FC<ResultsViewProps> = ({activePgroup
return (
<div>
<h1>Results Page</h1>
<SampleTracker />
<SampleTracker activePgroup={activePgroup}/>
<ResultGrid activePgroup={activePgroup} />
</div>