Skip to content

Commit 4ac2ac5

Browse files
authored
FIREFLY-1787: Merge PR #1831 from Caltech-IPAC/FIREFLY-1787-tap-col-improvement
FIREFLY-1787: Default filters for Spatial Search Position Columns
2 parents d9a1944 + de1da84 commit 4ac2ac5

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/firefly/js/ui/UploadTableSelector.jsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,30 @@ export const MappedColumnFld = ({cols, fieldKey, name, ...props}) => (
307307
* @param cols {Columns} - all column options for the ColumnFld
308308
* @param colTblId {string} - id of the column selection table that appears in a popup when the search button is clicked on a ColumnFld
309309
* @param ucd {string} - UCD to filter by
310+
* @param operator {string} filter type (like, in, etc.)
310311
*/
311-
export function filterMappedColFldTbl(cols, colTblId, ucd) {
312+
export function filterMappedColFldTbl(cols, colTblId, ucd, operator = 'like') {
312313
onTableLoaded(colTblId).then((tbl) => {
313-
const colsWithUcd = cols.filter((col) => { if (col.ucd) {return col.ucd.includes(ucd);} });
314+
const ucdList = ucd.split(',').map((s) => s.trim()).filter(Boolean);
315+
const colsWithUcd = cols.filter((col) =>
316+
col.ucd && ucdList.some((u) => col.ucd.includes(u))
317+
);
314318
if (colsWithUcd.length > 1) {
315319
if (!tbl) return;
316320
const filterInfo = tbl?.request?.filters;
317321
const filterInfoCls = FilterInfo.parse(filterInfo);
318-
const ucdFilter = `like '%${ucd}%'`;
322+
let ucdFilter;
323+
if (operator === 'like') {
324+
//build LIKE expression: like '%ucd1%' OR like '%ucd2%' ...
325+
ucdFilter = ucdList.map((ucd) => `like '%${ucd}%'`).join(' OR ');
326+
} else if (operator === 'in') {
327+
//build IN expression: in ('ucd1','ucd2','ucd3')
328+
const quoted = ucdList.map((ucd) => `'${ucd}'`).join(', ');
329+
ucdFilter = `in (${quoted})`;
330+
} else {
331+
console.warn(`Unsupported filter type: ${operator}`);
332+
return;
333+
}
319334
filterInfoCls.setFilter('UCD', ucdFilter);
320335
const newRequest = {tbl_id: tbl.tbl_id, filters: filterInfoCls.serialize()};
321336
dispatchTableFilter(newRequest);
@@ -371,11 +386,13 @@ export function UploadTableSelectorPosCol(props) {
371386

372387
export function CenterColumns({lonCol,latCol, sx, cols, lonKey, latKey, openKey,
373388
doQuoteNonAlphanumeric, headerTitle='Position Columns:',
374-
headerPostTitle = '', posDefaultOpenMsg='', setPosDefaultOpenMsg, slotProps}) {
389+
headerPostTitle = '', posDefaultOpenMsg='', setPosDefaultOpenMsg, tableName, slotProps}) {
375390
const columnFields = positionColumnFields(
376-
{fieldKey: lonKey, doQuoteNonAlphanumeric},
377-
{fieldKey: latKey, doQuoteNonAlphanumeric}
378-
);
391+
{fieldKey: lonKey, doQuoteNonAlphanumeric, colTblId: 'posCol'+tableName, onSearchBtnClicked: () =>
392+
filterMappedColFldTbl(cols, 'posCol'+tableName, 'pos.eq.ra, pos.eq.ra;meta.main, pos.galactic.lon, pos.galactic.lon;meta.main, pos.ecliptic.lon, pos.ecliptic.lon;meta.main, pos.eq;meta.main,', 'in')},
393+
{fieldKey: latKey, doQuoteNonAlphanumeric, colTblId: 'posCol'+tableName, onSearchBtnClicked: () =>
394+
filterMappedColFldTbl(cols, 'posCol'+tableName, 'pos.eq.dec, pos.eq.dec;meta.main, pos.galactic.lat, pos.galactic.lat;meta.main, pos.ecliptic.lat, pos.ecliptic.lat;meta.main, pos.eq;meta.main', 'in')}
395+
); //colTblId: posCol+tableName is to give the col select popups for each table a unique tblId, otherwise it may lead to bugs with different tables sharing the same tblId
379396

380397
const customSlotProps = defaultsDeep({openPreMessage: {level: 'body-sm'}}, slotProps, selectorPosColSlotProps.columnMappingPanel.slotProps);
381398

src/firefly/js/ui/tap/SpatialSearch.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, {useContext, useEffect, useState} from 'react';
44
import {ColsShape, getColValidator} from '../../charts/ui/ColumnOrExpression.jsx';
55
import {getAppOptions} from '../../core/AppDataCntlr.js';
66
import {ServerParams} from '../../data/ServerParams.js';
7-
import {getCellValue, getColumn, getColumnIdx} from '../../tables/TableUtil';
7+
import {getColumnIdx} from '../../tables/TableUtil';
88
import {findCenterColumnsByColumnsModel} from '../../voAnalyzer/ColumnsModelInfo.js';
99
import {findTableCenterColumns} from '../../voAnalyzer/TableAnalysis.js';
1010
import {posCol, UCDCoord} from '../../voAnalyzer/VoConst.js';
@@ -291,7 +291,7 @@ export function SpatialSearch({sx, cols, serviceUrl, serviceLabel, serviceId, co
291291
headerTitle:posHeaderTitle, openKey:posOpenKey,
292292
doQuoteNonAlphanumeric:false,
293293
headerPostTitle:'(from the selected table on the right)',
294-
posDefaultOpenMsg, cols, lonKey:CenterLonColumns, latKey:CenterLatColumns, setPosDefaultOpenMsg}} />}
294+
posDefaultOpenMsg, cols, lonKey:CenterLonColumns, latKey:CenterLatColumns, setPosDefaultOpenMsg, tableName}} />}
295295
</ForceFieldGroupValid>
296296
</Stack>
297297
<DebugObsCore {...{constraintResult}}/>

0 commit comments

Comments
 (0)