changed models and schemasa
This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user