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:
@ -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');
|
||||
|
Reference in New Issue
Block a user