Skip to content

Commit 4685776

Browse files
committed
some more cleanup
1 parent e3b5da4 commit 4685776

6 files changed

Lines changed: 43 additions & 35 deletions

File tree

src/firefly/js/ui/ListBoxInputField.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export function ListBoxInputFieldView({value:fieldValue='', onChange, fieldKey,
3333
<Select {...{name: fieldKey, multiple, onChange, placeholder, renderValue, startDecorator,
3434
disabled: readonly, size, value: multiple ? vAry : fieldValue,
3535
...slotProps?.input}}>
36-
{options?.map((({value,label,disabled=false}) => {
36+
{options?.map((({value,label,disabled=false},idx) => {
3737
return (
38-
<Option key={`${value}::${label ?? ''}`} value={value} label={forceLabelToValue ? value : label} disabled={disabled}>
38+
<Option {...{value, key:`k${idx}`, label:forceLabelToValue?value:label, disabled}}>
3939
{isFunction(decorator) ? decorator(label,value) : (label || value)}
4040
</Option>
4141
);

src/firefly/js/ui/tap/Constraints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33

44
export const ConstraintContext = React.createContext({});
55

6-
function hasAdqlConstraint(constraintObj) {
6+
export function hasAdqlConstraint(constraintObj) {
77
return Boolean(
88
constraintObj?.adqlConstraint ||
99
constraintObj?.adqlConstraintsAry?.length

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,19 @@ export function SpatialSearch({sx, cols, serviceUrl, serviceLabel, serviceId, co
241241
const cornerCalcTypeVal = getVal(cornerCalcType);
242242
const closestVal = getVal(Closest);
243243

244+
const isSpatialPanelActive = checkHeaderCtl?.isPanelActive();
245+
244246
const constraintResult = React.useMemo(() => {
247+
248+
//when spatial panel is inactive, it should not contribute constraints or errors
249+
if (!isSpatialPanelActive) {
250+
return {
251+
adqlConstraintsAry: [],
252+
constraintErrors: [],
253+
simpleError: '',
254+
};
255+
}
256+
245257
const constraints = makeSpatialConstraints(
246258
columnsModel, obsCoreEnabled, makeFldObj(fldListAry),
247259
uploadInfo, tableName, canUpload, useSIAv2
@@ -252,7 +264,7 @@ export function SpatialSearch({sx, cols, serviceUrl, serviceLabel, serviceId, co
252264
constraintErrors: [...(constraints.errAry ?? [])],
253265
simpleError: constraints.errAry?.[0] ?? '',
254266
};
255-
}, [columnsModel, obsCoreEnabled, uploadInfo, tableName, canUpload,
267+
}, [isSpatialPanelActive, columnsModel, obsCoreEnabled, uploadInfo, tableName, canUpload,
256268
useSIAv2, targetWp, spatialRegOp, spatialType, spatialMethodVal,
257269
radiusVal, polygonCornersVal, centerLonVal, centerLatVal,
258270
uploadCenterLonVal, uploadCenterLatVal, cornerCalcTypeVal, closestVal,

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

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ function TapSearchPanelImpl({initArgs= {}, titleOn=true, lockService=false, lock
125125
const tapOps = useMemo(() => makeTapServiceOptions(tapConfig.services, tapConfig.additional?.services, userServices),
126126
[tapConfig.services, tapConfig.additional?.services, userServices]);
127127
const tapState= getTapBrowserState();
128+
if (!initArgs?.urlApi?.execute) searchFromAPIOnce(true); //if not execute then mark as done, i.e. disable any auto searching
129+
initApiAddedServiceOnce(initArgs); //only look for the extra service the first time
128130
const {current:clickFuncRef} = useRef({clickFunc:undefined});
129131
const [selectBy, setSelectBy]= useState(() => {
130132
const val= getVal('selectBy');
@@ -135,7 +137,7 @@ function TapSearchPanelImpl({initArgs= {}, titleOn=true, lockService=false, lock
135137
const [servicesShowing, setServicesShowingInternal]= useState(tapState.lastServicesShowing);
136138
const [obsCoreTableModel, setObsCoreTableModel] = useState();
137139
const [serviceUrl, setServiceUrl]= useState(() => getInitServiceUrl(tapState,initArgs,tapOps,lockedServiceUrl,lockedServiceName));
138-
140+
activateInitArgsAdqlOnce(groupKey, tapState,initArgs,setSelectBy);
139141

140142
const setServicesShowing= (showing) => {
141143
setServicesShowingInternal(showing);
@@ -144,10 +146,10 @@ function TapSearchPanelImpl({initArgs= {}, titleOn=true, lockService=false, lock
144146

145147
const obsCoreEnabled = obsCoreTableModel?.tableData?.data?.length > 0;
146148

147-
const onDeleteServiceOption = (deletedValue) => {
149+
const onDeleteServiceOption = (deletedValue, clearServiceOnDelete=false) => {
148150
deleteUserService(deletedValue);
149151

150-
if (serviceUrl === deletedValue) {
152+
if (clearServiceOnDelete) {
151153
setServiceUrl('');
152154
setTapBrowserState({...getTapBrowserState(), serviceUrl: ''});
153155
setVal(ADQL_QUERY_KEY, '');
@@ -156,7 +158,6 @@ function TapSearchPanelImpl({initArgs= {}, titleOn=true, lockService=false, lock
156158
}
157159
};
158160

159-
160161
const onTapServiceOptionSelect= (selectedOption) => {
161162
if (!selectedOption) return;
162163
setVal(ADQL_QUERY_KEY, '');
@@ -167,18 +168,6 @@ function TapSearchPanelImpl({initArgs= {}, titleOn=true, lockService=false, lock
167168
setTapBrowserState({...getTapBrowserState(), serviceUrl: nextServiceUrl});
168169
};
169170

170-
useEffect(() => {
171-
if (!initArgs?.urlApi?.execute) searchFromAPIOnce(true);
172-
}, [initArgs?.urlApi?.execute]);
173-
174-
useEffect(() => {
175-
initApiAddedServiceOnce(initArgs);
176-
}, [initArgs]);
177-
178-
useEffect(() => {
179-
activateInitArgsAdqlOnce(groupKey, tapState,initArgs,setSelectBy);
180-
}, [groupKey, initArgs, setSelectBy, tapState]);
181-
182171
useEffect(() => {
183172
const {serviceUrl:u}= initArgs?.searchParams ?? {};
184173
u && u!==serviceUrl && setServiceUrl(u);
@@ -380,9 +369,9 @@ function Services({serviceUrl, servicesShowing, tapOps, onTapServiceOptionSelect
380369
},
381370
renderValue:
382371
({value}) =>
383-
(<ServiceOpRender {...{ ops: tapOps, value,onDeleteServiceOption}}/>),
372+
(<ServiceOpRender {...{ ops: tapOps, value,onDeleteServiceOption, clearServiceOnDelete: true}}/>),
384373
decorator:
385-
(label,value) => (<ServiceOpRender {...{ ops: tapOps, value,onDeleteServiceOption}}/>),
374+
(label,value) => (<ServiceOpRender {...{ ops: tapOps, value,onDeleteServiceOption,clearServiceOnDelete: value === serviceUrl}}/>),
386375
}} /> )}
387376
<FormHelperText sx={{m: .25}}>
388377
{enterUrl ? 'Type the url of a TAP service & press enter' : 'Choose a TAP service from the list'}
@@ -394,7 +383,7 @@ function Services({serviceUrl, servicesShowing, tapOps, onTapServiceOptionSelect
394383
}
395384

396385

397-
function ServiceOpRender({ops, value, sx, onDeleteServiceOption}) {
386+
function ServiceOpRender({ops, value, sx, onDeleteServiceOption, clearServiceOnDelete=false}) {
398387
const op = ops.find((t) => t.value === value);
399388
if (!op) return 'none';
400389
return (
@@ -409,18 +398,15 @@ function ServiceOpRender({ops, value, sx, onDeleteServiceOption}) {
409398
</Typography>
410399
</Stack>
411400
{ op.userAdded &&
412-
<ChipDelete
413-
component='div'
414-
size='sm'
415-
sx={{zIndex:2}}
401+
<ChipDelete component='div' size='sm' sx={{zIndex:2}}
416402
onMouseDown={(e) => {
417403
e.preventDefault();
418404
e.stopPropagation();
419405
}}
420406
onClick={(e) => {
421407
e.preventDefault();
422408
e.stopPropagation();
423-
onDeleteServiceOption(value);
409+
onDeleteServiceOption(value, clearServiceOnDelete);
424410
}}
425411
/>
426412
}

src/firefly/js/ui/tap/TapSearchSubmit.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
getHelperConstraints,
1010
getTapUploadSchemaEntry,
1111
getUploadServerFile,
12-
getUploadTableName,
12+
getUploadTableName, hasAdqlConstraint,
1313
isTapUpload
1414
} from 'firefly/ui/tap/Constraints';
1515
import {makeTblRequest, setNoCache} from 'firefly/tables/TableRequestUtil';
@@ -105,9 +105,9 @@ export function onTapSearchSubmit({request, serviceUrl, tapBrowserState, additio
105105

106106
function getCutoutType(tapBrowserState) {
107107
const spatial= tapBrowserState?.constraintFragments?.get('spatial');
108-
if (spatial?.adqlConstraint?.length) return spatial.cutoutType;
108+
if (hasAdqlConstraint(spatial)) return spatial.cutoutType;
109109
const location= tapBrowserState?.constraintFragments?.get('location');
110-
if (location?.adqlConstraint?.length) return location.cutoutType;
110+
if (hasAdqlConstraint(location)) return location.cutoutType;
111111
return ROW_POSITION;
112112
}
113113

@@ -129,7 +129,7 @@ export function getAdqlQuery(tapBrowserState, additionalClauses, allowColumnCons
129129
if (isUpload) { //check for more than one upload file (in Spatial and in ObjectID col) - should this be a utility function in constraints.js?
130130
const { constraintFragments } = tapBrowserState;
131131
const entries = [...constraintFragments.values()];
132-
const matchingEntries = entries.filter((c) => Boolean(c.uploadFile && c.TAP_UPLOAD && c.adqlConstraint));
132+
const matchingEntries = entries.filter((c) => Boolean(c.uploadFile && c.TAP_UPLOAD && hasAdqlConstraint(c)));
133133
if (matchingEntries.length > 1) {
134134
if (showErrors) showInfoPopup('We currently do not support searches with more than one uploaded table.', 'Error');
135135
return;

src/firefly/js/ui/tap/TapUtil.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,13 +574,23 @@ export function getTapServices() {
574574
const baseName= 'User Entered';
575575

576576
function getUserServiceAry() {
577-
return [...getPreference(USER_SERVICE_PREFS, [])];
577+
const seen = new Set();
578+
579+
return [...getPreference(USER_SERVICE_PREFS, [])]
580+
.filter((entry) => entry?.value?.trim())
581+
.filter((entry) => {
582+
const key = normalizeTapUrl(entry.value);
583+
if (!key || seen.has(key)) return false;
584+
seen.add(key);
585+
return true;
586+
});
578587
}
579588

589+
580590
export function addUserService(serviceUrl) {
581591
const userServices = getUserServiceAry();
582592
const normalizedServiceUrl = normalizeTapUrl(serviceUrl);
583-
if (getTapServiceByURL(normalizedServiceUrl)) return; // don't add if service already exist
593+
if (getTapServices().some(({value}) => normalizeTapUrl(value) === normalizedServiceUrl)) return; //don't add if service already exists
584594

585595
const usedNumAry = userServices
586596
.map((s) => s.label)
@@ -710,7 +720,7 @@ export const getServiceHiPS= (serviceUrl) => getTapServiceByURL(serviceUrl)?.hip
710720
export const normalizeTapUrl = (url='') => url.trim().replace(/\/+$/, '').toLowerCase();
711721

712722
export function makeTapServiceOptions(baseServices, additionalServices, userServices=[]) {
713-
const startingTapServices= hasElements(baseServices) ? [...baseServices] : getTAPServicesByName();
723+
const startingTapServices= hasElements(baseServices) ? [...baseServices] : makeTAPDefaultServicesByName();
714724
const mergedServices= mergeServices(startingTapServices, additionalServices);
715725
const allServices= [...mergedServices, ...userServices];
716726
const seen = new Set();

0 commit comments

Comments
 (0)