Added validation buttons per row in datasheet UI; need to configure correct validations per data field

This commit is contained in:
efarooqui
2020-08-21 09:35:20 -07:00
parent fba74d8e9c
commit 1971128b18
3 changed files with 23 additions and 25 deletions

View File

@@ -58,6 +58,17 @@ export default ({ config, controller }) => {
)
})
// api.get('/:sheet/:tab/:resource/validate', (req, res) => {
// const { sheet, tab, resource } = req.params
// controller
// .retrieve(sheet, tab, resource)
// .then(data => res.json(data))
// .catch(err =>
// res.status(err.status || 404)
// .send({ error: err.message })
// )
// })
// ERROR routes. Note that it is important that these come AFTER routes
// like /update, so that the regex does not greedily match these routes.

View File

@@ -1,4 +1,5 @@
import { fmtObj } from '../lib/util'
import { getColumnValidation } from '../lib/validation'
/**
* Each resource item is an object with values labelled according
@@ -35,7 +36,6 @@ export default (data) => {
}
}
})
// generate the value for deep labels using the structure created
data.forEach((row, idx) => {
if (idx === 0) return
@@ -61,6 +61,8 @@ export default (data) => {
// move values for flat labels over from base
structure.__flat.forEach(label => {
const validatedLabel = getColumnValidation(label, baseRow[label])
console.log(validatedLabel)
deepRow[label] = baseRow[label]
})
if (!Object.keys(deepRow).every(k => deepRow[k] === '')) {

View File

@@ -1,35 +1,20 @@
import moment from 'moment';
const DATE_FORMAT = "MM/DD/YYYY";
const TIME_REGEX = "^([01]\d|2[0-3]):?([0-5]\d)$"
export const validateLongitude = value => {
return isFinite(value) && Math.abs(value) <= 180;
}
export const validateLatitude = value => {
return isFinite(lat) && Math.abs(lat) <= 90;
}
export const validateDate = date => {
return moment(date, DATE_FORMAT, true).isValid();
}
export const validateTime = time => {
return TIME_REGEX.test(time);
}
const TIME_REGEX = new RegExp("^([01]\d|2[0-3]):?([0-5]\d)$")
export const getColumnValidator = colName => {
export const getColumnValidation = (colName, value) => {
switch(colName) {
case 'longitue':
return validateLongitude;
case 'longitude':
return isFinite(value) && Math.abs(value) <= 180;
case 'latitude':
return validateLatitude;
return isFinite(value) && Math.abs(value) <= 90;
case 'date':
return validateDate;
return moment(value, DATE_FORMAT, true).isValid();
case 'time':
return validateTime;
default: () => return true;
return TIME_REGEX.test(value);
default:
return true
}
}