added sample tracker on the frontend

This commit is contained in:
GotthardG
2024-12-04 14:45:47 +01:00
parent 1a1a710edf
commit 7b00db3c0d
6 changed files with 200 additions and 2 deletions

View File

@ -35,4 +35,62 @@
to {
transform: rotate(360deg);
}
}
.sample-tracker-container {
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
max-width: 80%; /* Reduce this percentage to fit your needs */
width: auto; /* Auto width for responsiveness */
margin: 0 auto; /* Center the tracker horizontally */
overflow-x: auto; /* Allow horizontal scrolling if necessary */
}
.sample-tracker {
display: flex;
flex-direction: column;
align-items: center;
}
.pucks-container {
display: flex;
flex-wrap: nowrap;
align-items: flex-start;
}
.puck-column {
display: flex;
flex-direction: column;
align-items: center;
margin: 0 10px;
}
.puck-label {
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: center;
height: 100px;
margin-bottom: 5px;
}
.puck-label span {
display: block;
}
.samples {
display: flex;
flex-direction: column;
align-items: center;
gap: 3px;
}
.sample-dot {
width: 15px;
height: 15px;
border-radius: 50%;
display: inline-block;
border: 1px solid lightgray;
}

View File

@ -0,0 +1,95 @@
import React, { useEffect, useState } from 'react';
import { SamplesService } from '../../openapi';
interface Event {
event_type: string;
}
interface Sample {
id: number;
sample_name: string;
position: number;
puck_id: number;
crystalname?: string;
positioninpuck?: number;
events: Event[];
}
interface Puck {
id: number;
puck_name: string;
puck_type: string;
puck_location_in_dewar: number;
dewar_id: number;
samples: Sample[]; // Check that the API returns this attribute
}
const SampleTracker: React.FC = () => {
const [pucks, setPucks] = useState<Puck[]>([]);
useEffect(() => {
const fetchPucks = async () => {
try {
const data: Puck[] = await SamplesService.getAllPucksWithSamplesAndEventsSamplesPucksSamplesGet();
console.log(data); // Log the data to inspect it
setPucks(data);
} catch (error) {
console.error('Error fetching pucks', error);
}
};
fetchPucks();
}, []);
const getSampleColor = (events: Event[] = []) => {
const hasMounted = events.some(e => e.event_type === 'Mounted');
const hasUnmounted = events.some(e => e.event_type === 'Unmounted');
const hasLost = events.some(e => e.event_type === 'Lost');
const hasFailed = events.some(e => e.event_type === 'Failed');
if (hasFailed) return 'red';
if (hasLost) return 'orange';
if (hasMounted && hasUnmounted) return 'green';
return 'gray';
};
return (
<div className="sample-tracker-container">
<div className="sample-tracker">
<h2>All Pucks and Samples</h2>
<div className="pucks-container">
{pucks.map((puck) => (
<div key={puck.id} className="puck-column">
<div className="puck-label">
{puck.puck_name.split('').map((char, i) => (
<span key={i}>{char}</span>
))}
</div>
<div className="samples">
{Array.from({length: 16}).map((_, index) => {
const sample = puck.samples.find(s => s.position === index + 1);
return (
<div
key={index}
className="sample-dot"
style={{
backgroundColor: sample
? getSampleColor(sample.events)
: 'transparent',
border: sample && sample.events.some(e => e.event_type === 'Lost')
? '1px solid red' : '1px solid lightgray',
}}
></div>
);
})}
</div>
</div>
))}
</div>
</div>
</div>
);
};
export default SampleTracker;

View File

@ -1,8 +1,15 @@
// components/ResultView.tsx
import React from 'react';
import SampleTracker from '../components/SampleTracker';
const ResultsView: React.FC = () => {
return <div>Results page</div>;
return (
<div>
<h1>Results Page</h1>
<SampleTracker />
</div>
);
};
export default ResultsView;