Skip to content

Commit

Permalink
Firefly-1252: column validator now accepts an error message parameter
Browse files Browse the repository at this point in the history
  - also set the error messages for spatial and temporal
  • Loading branch information
robyww committed Jun 7, 2023
1 parent 907f99e commit 5bbc10a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/firefly/js/charts/ui/ColumnOrExpression.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ function parseSuggestboxContent(text) {
return {token, priorContent};
}

export function getColValidator(cols, required=true, canBeExpression=true) {
const DEFAULT_MSG= 'Can not be empty. Please provide value or expression';

export function getColValidator(cols, required=true, canBeExpression=true, message=DEFAULT_MSG) {
const colNames = cols.map((colVal) => {return colVal.name;});
return (val) => {
let retval = {valid: true, message: ''};
if (!val) {
if (required) {
return {valid: false, message: 'Can not be empty. Please provide value or expression'};
}
if (required) return {valid: false, message};
} else if (colNames.indexOf(val) < 0) {
if (canBeExpression) {
const expr = new Expression(val, colNames);
Expand Down
10 changes: 6 additions & 4 deletions src/firefly/js/ui/tap/SpatialSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,19 @@ export function SpatialSearch({cols, serviceUrl, serviceLabel, columnsModel, tab
const columns = searchParams.uploadInfo.columns;
const centerCols = findTableCenterColumns({tableData:{columns}}) ?? {};
const {lonCol='', latCol=''}= centerCols;
setVal(UploadCenterLonColumns, lonCol, {validator: getColValidator(searchParams.uploadInfo.columns, true, false), valid: true});
setVal(UploadCenterLatColumns, latCol, {validator: getColValidator(searchParams.uploadInfo.columns, true, false), valid: true});
const errMsg= 'Upload tables require identifying spatial columns containing equatorial coordinates. Please provide column names.';
setVal(UploadCenterLonColumns, lonCol, {validator: getColValidator(searchParams.uploadInfo.columns, true, false,errMsg), valid: true});
setVal(UploadCenterLatColumns, latCol, {validator: getColValidator(searchParams.uploadInfo.columns, true, false,errMsg), valid: true});
setUploadInfo(searchParams.uploadInfo);
checkHeaderCtl.setPanelActive(true);
}
}, [searchParams.radiusInArcSec, searchParams.wp, searchParams.corners, searchParams.uploadInfo]);

useEffect(() => {
const {lon,lat} = formCenterColumns(columnsModel);
setVal(CenterLonColumns, lon, {validator: getColValidator(cols, true, false), valid: true});
setVal(CenterLatColumns, lat, {validator: getColValidator(cols, true, false), valid: true});
const errMsg= 'Spatial searches require identifying table columns containing equatorial coordinates. Please provide column names.';
setVal(CenterLonColumns, lon, {validator: getColValidator(cols, true, false, errMsg), valid: true});
setVal(CenterLatColumns, lat, {validator: getColValidator(cols, true, false, errMsg), valid: true});
const noDefaults= !lon || !lat;
setVal(posOpenKey, (noDefaults) ? 'open' : 'closed');
if (noDefaults) checkHeaderCtl.setPanelActive(false);
Expand Down
4 changes: 2 additions & 2 deletions src/firefly/js/ui/tap/TemportalSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ export function TemporalSearch({cols, columnsModel}) {

useEffect(() => {
const timeCol= findTimeColumn(columnsModel) ?? '';
setVal(TemporalColumns, timeCol, {validator: getColValidator(cols, true, false), valid: true});
const errMsg= 'Temporal searches require identifying a table column containing a time in MJD. Please provide a column name.';
setVal(TemporalColumns, timeCol, {validator: getColValidator(cols, true, false, errMsg), valid: true});
checkHeaderCtl.setPanelOpen(Boolean(timeCol));
// checkHeaderCtl.setPanelActive(Boolean(timeCol));
}, [columnsModel]);


Expand Down

0 comments on commit 5bbc10a

Please sign in to comment.