changed models and schemasa
This commit is contained in:
@ -42,6 +42,8 @@ const DewarDetails: React.FC<DewarDetailsProps> = ({
|
||||
const [changesMade, setChangesMade] = useState(false);
|
||||
const [feedbackMessage, setFeedbackMessage] = useState('');
|
||||
const [openSnackbar, setOpenSnackbar] = useState(false);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
const setInitialContactPerson = () => {
|
||||
@ -92,22 +94,33 @@ const DewarDetails: React.FC<DewarDetailsProps> = ({
|
||||
|
||||
useEffect(() => {
|
||||
const fetchSamples = async () => {
|
||||
if (dewar.id && Array.isArray(dewar.pucks)) {
|
||||
if (dewar.id) {
|
||||
try {
|
||||
const samples = await ShipmentsService.getSamplesInDewarShipmentsShipmentIdDewarsDewarIdSamplesGet(shipmentId, dewar.id);
|
||||
const fetchedSamples = await ShipmentsService.getSamplesInDewarShipmentsShipmentsShipmentIdDewarsDewarIdSamplesGet(shipmentId, dewar.id);
|
||||
console.log("Fetched Samples: ", fetchedSamples);
|
||||
|
||||
const updatedPuckStatuses = dewar.pucks.map(puck => {
|
||||
if (!Array.isArray(puck.positions)) return [];
|
||||
return puck.positions.map(position => {
|
||||
const isOccupied = samples.some(sample => sample.id === position.id);
|
||||
return isOccupied ? 'filled' : 'empty';
|
||||
// Filter samples for the current puck
|
||||
const puckSamples = fetchedSamples.filter(sample => sample.puck_id === puck.id);
|
||||
|
||||
// Initialize positions as 'empty'
|
||||
const statusArray = Array(16).fill('empty');
|
||||
|
||||
// Update positions based on puckSamples' positions
|
||||
puckSamples.forEach(sample => {
|
||||
if (sample.position >= 1 && sample.position <= 16) {
|
||||
statusArray[sample.position - 1] = 'filled'; // Adjust for 0-based index
|
||||
}
|
||||
});
|
||||
|
||||
return statusArray;
|
||||
});
|
||||
|
||||
setPuckStatuses(updatedPuckStatuses);
|
||||
} catch (error) {
|
||||
setFeedbackMessage('Failed to load samples. Please try again later.');
|
||||
setOpenSnackbar(true);
|
||||
setError('Failed to load samples. Please try again later.');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -190,6 +190,7 @@ const ShipmentPanel: React.FC<ShipmentPanelProps> = ({
|
||||
<UploadDialog
|
||||
open={uploadDialogOpen}
|
||||
onClose={closeUploadDialog}
|
||||
selectedShipment={selectedShipment} // <-- Pass selectedShipment here
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
|
@ -13,11 +13,19 @@ import {
|
||||
Button,
|
||||
Box
|
||||
} from '@mui/material';
|
||||
import { SpreadsheetService } from '../../openapi';
|
||||
import { SpreadsheetService, ShipmentsService } from '../../openapi';
|
||||
import * as ExcelJS from 'exceljs';
|
||||
import { saveAs } from 'file-saver';
|
||||
|
||||
const SpreadsheetTable = ({ raw_data, errors, headers, setRawData, onCancel, fileBlob }) => {
|
||||
const SpreadsheetTable = ({
|
||||
raw_data,
|
||||
errors,
|
||||
headers,
|
||||
setRawData,
|
||||
onCancel,
|
||||
fileBlob,
|
||||
shipmentId // Accept the shipmentId
|
||||
}) => {
|
||||
const [localErrors, setLocalErrors] = useState(errors || []);
|
||||
const [editingCell, setEditingCell] = useState({});
|
||||
const [nonEditableCells, setNonEditableCells] = useState(new Set());
|
||||
@ -25,7 +33,7 @@ const SpreadsheetTable = ({ raw_data, errors, headers, setRawData, onCancel, fil
|
||||
const generateErrorMap = (errorsList) => {
|
||||
const errorMap = new Map();
|
||||
if (Array.isArray(errorsList)) {
|
||||
errorsList.forEach(error => {
|
||||
errorsList.forEach((error) => {
|
||||
const key = `${error.row}-${headers[error.cell]}`;
|
||||
errorMap.set(key, error.message);
|
||||
});
|
||||
@ -64,7 +72,7 @@ const SpreadsheetTable = ({ raw_data, errors, headers, setRawData, onCancel, fil
|
||||
|
||||
currentRow.data[colIndex] = newValue;
|
||||
|
||||
setEditingCell(prev => {
|
||||
setEditingCell((prev) => {
|
||||
const updated = { ...prev };
|
||||
delete updated[`${rowIndex}-${colIndex}`];
|
||||
return updated;
|
||||
@ -80,10 +88,10 @@ const SpreadsheetTable = ({ raw_data, errors, headers, setRawData, onCancel, fil
|
||||
if (response.is_valid !== undefined) {
|
||||
if (response.is_valid) {
|
||||
const updatedErrors = localErrors.filter(
|
||||
error => !(error.row === currentRow.row_num && error.cell === colIndex)
|
||||
(error) => !(error.row === currentRow.row_num && error.cell === colIndex)
|
||||
);
|
||||
setLocalErrors(updatedErrors);
|
||||
setNonEditableCells(prev => new Set([...prev, `${rowIndex}-${colIndex}`]));
|
||||
setNonEditableCells((prev) => new Set([...prev, `${rowIndex}-${colIndex}`]));
|
||||
} else {
|
||||
const updatedErrors = [
|
||||
...localErrors,
|
||||
@ -107,11 +115,75 @@ const SpreadsheetTable = ({ raw_data, errors, headers, setRawData, onCancel, fil
|
||||
const handleSubmit = async () => {
|
||||
if (allCellsValid()) {
|
||||
console.log('All data is valid. Proceeding with submission...');
|
||||
const processedData = createPayload(raw_data);
|
||||
|
||||
try {
|
||||
const response = await ShipmentsService.addDewarPuckSampleToShipmentShipmentsShipmentIdAddDewarPuckSamplePost(shipmentId, processedData);
|
||||
console.log('Shipment processed successfully:', response);
|
||||
|
||||
// Handle success actions, e.g., display notification, reset state, etc.
|
||||
} catch (error) {
|
||||
console.error('Error processing shipment:', error);
|
||||
// Handle error actions, e.g., display notification, etc.
|
||||
}
|
||||
} else {
|
||||
console.log('There are validation errors in the dataset. Please correct them before submission.');
|
||||
}
|
||||
};
|
||||
|
||||
const createPayload = (data) => {
|
||||
const allowedFields = [
|
||||
'priority', 'comments', 'directory', 'proteinname', 'oscillation', 'aperture',
|
||||
'exposure', 'totalrange', 'transmission', 'dose', 'targetresolution', 'datacollectiontype',
|
||||
'processingpipeline', 'spacegroupnumber', 'cellparameters', 'rescutkey', 'rescutvalue',
|
||||
'userresolution', 'pdbid', 'autoprocfull', 'procfull', 'adpenabled', 'noano',
|
||||
'ffcscampaign', 'trustedhigh', 'autoprocextraparams', 'chiphiangles'
|
||||
];
|
||||
|
||||
let dewars = {};
|
||||
|
||||
data.forEach((row) => {
|
||||
const dewarname = row.data[headers.indexOf('dewarname')];
|
||||
const puckname = row.data[headers.indexOf('puckname')];
|
||||
const crystalname = row.data[headers.indexOf('crystalname')];
|
||||
const positioninpuck = row.data[headers.indexOf('positioninpuck')];
|
||||
|
||||
if (!dewars[dewarname]) {
|
||||
dewars[dewarname] = {
|
||||
dewarname: dewarname,
|
||||
pucks: {}
|
||||
};
|
||||
}
|
||||
|
||||
if (!dewars[dewarname].pucks[puckname]) {
|
||||
dewars[dewarname].pucks[puckname] = {
|
||||
puckname: puckname,
|
||||
samples: []
|
||||
};
|
||||
}
|
||||
|
||||
const dataCollectionParams = {};
|
||||
headers.forEach((header, index) => {
|
||||
if (allowedFields.includes(header)) {
|
||||
dataCollectionParams[header] = row.data[index];
|
||||
}
|
||||
});
|
||||
|
||||
dewars[dewarname].pucks[puckname].samples.push({
|
||||
crystalname: crystalname,
|
||||
positioninpuck: positioninpuck,
|
||||
data_collection_parameters: dataCollectionParams
|
||||
});
|
||||
});
|
||||
|
||||
const dewarsList = Object.values(dewars).map(dewar => ({
|
||||
dewarname: dewar.dewarname,
|
||||
pucks: Object.values(dewar.pucks)
|
||||
}));
|
||||
|
||||
return { dewars: dewarsList };
|
||||
};
|
||||
|
||||
const downloadCorrectedSpreadsheet = async () => {
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
await workbook.xlsx.load(fileBlob);
|
||||
|
@ -8,11 +8,8 @@ interface UnipuckProps {
|
||||
|
||||
const Unipuck: React.FC<UnipuckProps> = ({ pucks, samples }) => {
|
||||
const renderPuck = (sampleStatus: string[]) => {
|
||||
if (!sampleStatus) {
|
||||
sampleStatus = Array(16).fill('empty');
|
||||
}
|
||||
|
||||
const puckSVG = (
|
||||
sampleStatus = sampleStatus || Array(16).fill('empty'); // Ensure no null status array
|
||||
return (
|
||||
<svg width="100" height="100" viewBox="0 0 100 100">
|
||||
<circle cx="50" cy="50" r="45" stroke="black" strokeWidth="2" fill="none" />
|
||||
{[...Array(11)].map((_, index) => {
|
||||
@ -29,7 +26,6 @@ const Unipuck: React.FC<UnipuckProps> = ({ pucks, samples }) => {
|
||||
})}
|
||||
</svg>
|
||||
);
|
||||
return puckSVG;
|
||||
};
|
||||
|
||||
if (pucks === 0) {
|
||||
|
@ -23,9 +23,10 @@ import * as ExcelJS from 'exceljs';
|
||||
interface UploadDialogProps {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
selectedShipment: any; // Adjust the type based on your implementation
|
||||
}
|
||||
|
||||
const UploadDialog: React.FC<UploadDialogProps> = ({ open, onClose }) => {
|
||||
const UploadDialog: React.FC<UploadDialogProps> = ({ open, onClose, selectedShipment }) => {
|
||||
const [uploadError, setUploadError] = useState<string | null>(null);
|
||||
const [fileSummary, setFileSummary] = useState<{
|
||||
data: any[];
|
||||
@ -37,7 +38,7 @@ const UploadDialog: React.FC<UploadDialogProps> = ({ open, onClose }) => {
|
||||
pucks: string[];
|
||||
samples_count: number;
|
||||
samples: string[];
|
||||
headers: string[]; // Headers must be part of this object
|
||||
headers: string[];
|
||||
} | null>(null);
|
||||
const [fileBlob, setFileBlob] = useState<Blob | null>(null); // New state to store the file blob
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
@ -165,6 +166,7 @@ const UploadDialog: React.FC<UploadDialogProps> = ({ open, onClose }) => {
|
||||
setRawData={(newRawData) => setFileSummary((prevSummary) => ({ ...prevSummary, raw_data: newRawData }))}
|
||||
onCancel={handleCancel}
|
||||
fileBlob={fileBlob} // Pass the original file blob
|
||||
shipmentId={selectedShipment?.id} // Pass the selected shipment ID
|
||||
/>
|
||||
</Modal>
|
||||
)}
|
||||
|
Reference in New Issue
Block a user