Add column type mapping and enhance validation
Introduced a backend mapping for column expected types, improving validation and error handling. Updated UI to highlight default and corrected values, with additional detailed validation for data collection parameters.
This commit is contained in:
@ -122,23 +122,22 @@ const SpreadsheetTable = ({
|
||||
|
||||
if (response && response.is_valid !== undefined) {
|
||||
if (response.is_valid) {
|
||||
// Handle validation success (remove error)
|
||||
// If valid, update the value (and use corrected_value if returned)
|
||||
const correctedValue = response.corrected_value ?? newValue;
|
||||
currentRow.data[colIndex] = correctedValue;
|
||||
updatedRawData[rowIndex] = currentRow;
|
||||
|
||||
setRawData(updatedRawData); // Update table data
|
||||
setRawData(updatedRawData);
|
||||
|
||||
// Remove error associated with this cell
|
||||
// Remove the error and mark as non-editable
|
||||
const updatedErrors = localErrors.filter(
|
||||
(error) => !(error.row === currentRow.row_num && error.cell === colIndex)
|
||||
);
|
||||
setLocalErrors(updatedErrors);
|
||||
setLocalErrors(updatedErrors); // Update error list
|
||||
|
||||
// Update non-editable state
|
||||
setNonEditableCells((prev) => new Set([...prev, `${rowIndex}-${colIndex}`]));
|
||||
} else {
|
||||
// Handle validation failure (add error)
|
||||
// If not valid, don't add to nonEditableCells and update the error list
|
||||
const errorMessage = response.message || "Invalid value.";
|
||||
const newError = {
|
||||
row: currentRow.row_num,
|
||||
@ -147,10 +146,18 @@ const SpreadsheetTable = ({
|
||||
};
|
||||
|
||||
const updatedErrors = [
|
||||
...localErrors.filter((error) => !(error.row === newError.row && error.cell === newError.cell)), // Avoid duplicates
|
||||
...localErrors.filter(
|
||||
(error) => !(error.row === newError.row && error.cell === newError.cell)
|
||||
),
|
||||
newError,
|
||||
];
|
||||
setLocalErrors(updatedErrors);
|
||||
|
||||
setNonEditableCells((prev) => {
|
||||
const updatedSet = new Set(prev);
|
||||
updatedSet.delete(`${rowIndex}-${colIndex}`); // Ensure it stays editable
|
||||
return updatedSet;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.error("Unexpected response from backend:", response);
|
||||
|
Reference in New Issue
Block a user