Refactor spreadsheet handling to track corrections and defaults

Improved the backend's value cleaning to differentiate between corrections and defaults, logging metadata for clearer traceability. Updated frontend to display corrected/defaulted fields with visual cues and tooltips for better user feedback. Enhanced data models and response structures to support this richer metadata.
This commit is contained in:
GotthardG
2025-01-14 21:46:11 +01:00
parent f6c19cc4da
commit c0951292d0
5 changed files with 213 additions and 94 deletions

View File

@ -29,7 +29,8 @@ const SpreadsheetTable = ({
setRawData,
onCancel,
fileBlob,
selectedShipment
selectedShipment,
addinfo,
}) => {
const [localErrors, setLocalErrors] = useState(errors || []);
const [editingCell, setEditingCell] = useState({});
@ -38,7 +39,23 @@ const SpreadsheetTable = ({
const [showUpdateDialog, setShowUpdateDialog] = useState(false);
const [dewarsToReplace, setDewarsToReplace] = useState([]);
const [dewarsToCreate, setDewarsToCreate] = useState(new Map());
const [correctionMetadata, setCorrectionMetadata] = useState(addinfo || []); // Store addinfo
const enhancedRawData = raw_data.map((row) => {
const metadata = correctionMetadata.find((info) => info.row_num === row.row_num) || {};
// Combine original row data with metadata
return {
...row,
corrected_columns: metadata.corrected_columns || [], // Columns corrected
default_set_columns: metadata.default_set || [], // Specific columns default-assigned
};
});
useEffect(() => {
console.log("Correction Metadata:", correctionMetadata);
console.log("Addinfo:", addinfo);
}, [correctionMetadata, addinfo]);
const initialNewDewarState = {
number_of_pucks: 0,
number_of_samples: 0,
@ -461,6 +478,14 @@ const SpreadsheetTable = ({
return (
<TableContainer component={Paper}>
<Box display="flex" justifyContent="space-between" mb={2}>
<Typography variant="body2" style={{ backgroundColor: "#e6fbe6", padding: "4px 8px", borderRadius: "4px" }}>
Default Assigned (Light Green)
</Typography>
<Typography variant="body2" style={{ backgroundColor: "#fff8e1", padding: "4px 8px", borderRadius: "4px" }}>
Corrected (Light Yellow)
</Typography>
</Box>
<Table>
<TableHead>
<TableRow>
@ -483,7 +508,7 @@ const SpreadsheetTable = ({
</Button>
</Box>
<TableBody>
{raw_data.map((row, rowIndex) => (
{enhancedRawData.map((row, rowIndex) => (
<TableRow key={rowIndex}>
{headers.map((header, colIndex) => {
const key = `${row.row_num}-${header}`;
@ -491,37 +516,30 @@ const SpreadsheetTable = ({
const isInvalid = !!errorMessage;
const cellValue = row.data[colIndex];
const editingValue = editingCell[`${rowIndex}-${colIndex}`];
const isCellCorrected = row.corrected_columns?.includes(header); // Check if this column is marked as corrected
const isDefaultAssigned = colIndex === 7 && row.default_set; // Default-assigned field exists and is true
// Dynamic styles for corrected cells
const cellStyle = {
backgroundColor:
isDefaultAssigned
? "#e6fbe6" // Light green for default values
: isCellCorrected
? "#fff8e1" // Light yellow for corrected values
: "transparent", // Default for others
color: isDefaultAssigned
? "#1b5e20" // Dark green for default values
: "inherit", // Default for others
fontWeight: (isCellCorrected || isDefaultAssigned) ? "bold" : "normal", // Bold text for any change
cursor: isInvalid ? "pointer" : "default", // Mouse pointer indicates interactive error cells
};
const isCellCorrected = row.corrected_columns?.includes(header); // Use corrected metadata
const isDefaultAssigned = row.default_set_columns?.includes(header); // Dynamically match header name
return (
<TableCell
key={colIndex}
align="center"
style={cellStyle}
style={{
backgroundColor: isDefaultAssigned
? "#e6fbe6" // Light green
: isCellCorrected
? "#fff8e1" // Light yellow
: "transparent",
color: isDefaultAssigned ? "#1b5e20" : "inherit",
fontWeight: isCellCorrected || isDefaultAssigned ? "bold" : "normal",
cursor: isInvalid ? "pointer" : "default",
}}
>
<Tooltip
title={
isDefaultAssigned
? "This value was automatically assigned by the system as a default."
? "This value was automatically assigned as a default."
: isCellCorrected
? "Value corrected automatically by the system."
? `Field "${header}" was auto-corrected.`
: errorMessage || ""
}
arrow

View File

@ -180,6 +180,7 @@ const UploadDialog: React.FC<UploadDialogProps> = ({ open, onClose, selectedShip
onCancel={handleCancel}
fileBlob={fileBlob}
selectedShipment={selectedShipment}
addinfo={fileSummary.addinfo}
/>
</Modal>
)}