Add spreadsheet enhancements and default handling

Implemented a toggleable spreadsheet UI component for sample data, added fields such as priority and comments, and improved backend validation. Default values for "directory" are now assigned when missing, with feedback highlighted in green on the front end.
This commit is contained in:
GotthardG
2025-01-06 14:40:02 +01:00
parent 9cb6ffbfb4
commit 54975b5919
12 changed files with 436 additions and 134 deletions

View File

@ -206,7 +206,10 @@ const SpreadsheetTable = ({
const puckNameIdx = fieldToCol['puckname'];
const puckTypeIdx = fieldToCol['pucktype'];
const sampleNameIdx = fieldToCol['crystalname'];
const proteinNameIdx = fieldToCol['proteinname'];
const samplePositionIdx = fieldToCol['positioninpuck'];
const priorityIdx = fieldToCol['priority'];
const commentsIdx = fieldToCol['comments'];
for (let rowIndex = 0; rowIndex < data.length; rowIndex++) {
const row = data[rowIndex];
@ -220,7 +223,10 @@ const SpreadsheetTable = ({
const puckName = row.data[puckNameIdx] !== undefined && row.data[puckNameIdx] !== null ? String(row.data[puckNameIdx]).trim() : null;
const puckType = typeof row.data[puckTypeIdx] === 'string' ? row.data[puckTypeIdx] : 'Unipuck';
const sampleName = typeof row.data[sampleNameIdx] === 'string' ? row.data[sampleNameIdx].trim() : null;
const proteinName = typeof row.data[proteinNameIdx] === 'string' ? row.data[proteinNameIdx].trim() : null;
const samplePosition = row.data[samplePositionIdx] !== undefined && row.data[samplePositionIdx] !== null ? Number(row.data[samplePositionIdx]) : null;
const priority = row?.data?.[priorityIdx] ? Number(row.data[priorityIdx]) : null;
const comments = typeof row.data[commentsIdx] === 'string' ? row.data[commentsIdx].trim() : null;
if (dewarName && puckName) {
let dewar;
@ -263,7 +269,11 @@ const SpreadsheetTable = ({
const sample = {
sample_name: sampleName,
proteinname: proteinName,
position: samplePosition,
priority: priority,
comments: comments,
data_collection_parameters: null,
results: null // Placeholder for results field
};
@ -425,14 +435,28 @@ const SpreadsheetTable = ({
const cellValue = (row.data && row.data[colIndex]) || "";
const editingValue = editingCell[`${rowIndex}-${colIndex}`];
const isReadonly = !isInvalid;
const isDefaultAssigned = colIndex === 7 && row.default_set; // Directory column (index 7) and marked as default_set
return (
<TableCell key={colIndex} align="center">
<TableCell
key={colIndex}
align="center"
style={{
backgroundColor: isDefaultAssigned ? "#e6fbe6" : "transparent", // Light green for default
color: isDefaultAssigned ? "#1b5e20" : "inherit", // Dark green text for default
}}
>
<Tooltip title={errorMessage || ""} arrow disableHoverListener={!isInvalid}>
{isInvalid ? (
<TextField
value={editingValue !== undefined ? editingValue : cellValue}
onChange={(e) => setEditingCell({ ...editingCell, [`${rowIndex}-${colIndex}`]: e.target.value })}
onChange={(e) =>
setEditingCell({
...editingCell,
[`${rowIndex}-${colIndex}`]: e.target.value,
})
}
onKeyDown={(e) => {
if (e.key === "Enter") {
handleCellEdit(rowIndex, colIndex);