Conversation
66d3735 to
4685776
Compare
4685776 to
6ff9f62
Compare
robyww
left a comment
There was a problem hiding this comment.
This is good work and good analysis. I like your big solution of useMemo I just want you to make it more reusable.
| return Boolean( | ||
| constraintObj?.adqlConstraint || | ||
| constraintObj?.adqlConstraintsAry?.length | ||
| ); | ||
| } | ||
|
|
||
| function getAdqlConstraintsList(constraintObj) { | ||
| if (constraintObj?.adqlConstraintsAry?.length) return constraintObj.adqlConstraintsAry; | ||
| if (constraintObj?.adqlConstraint) return [constraintObj.adqlConstraint]; | ||
| return []; | ||
| } |
There was a problem hiding this comment.
good! getAdqlConstraintsList is a real improvement.
There was a problem hiding this comment.
You should add some sort of hasErrors to work with constraintObj.constraintErrors?.length or call is isContraintsValid
| const spacialType = useFieldGroupValue(SPATIAL_TYPE)[0]() ?? SINGLE; | ||
| const spatialMethod = useFieldGroupValue(SpatialMethod)[0]() ?? CONE_CHOICE_KEY; | ||
| const closest = useFieldGroupValue(Closest)[0]() ?? ''; | ||
| const cornerCalcTypeValue = useFieldGroupValue(cornerCalcType)[0]() ?? 'image'; | ||
| const spatialRegOpValue = useFieldGroupValue(SpatialRegOp)[0]() ?? SpatialRegOpType.CONTAINS_POINT; |
There was a problem hiding this comment.
good. I think I went down the wrong path using getVal here.
| radiusVal, polygonCornersVal, centerLonVal, centerLatVal, | ||
| uploadCenterLonVal, uploadCenterLatVal, cornerCalcTypeVal, closestVal, | ||
| ]); | ||
|
|
There was a problem hiding this comment.
I really like this approach. It is much clean and easier to follow. However, I think it is to verbose and hard to consistently reuse. So here are a couple of ideas.
this will help a lot
fldListAry.mapIdea 1
define in TableSearchHelpers.js
function makeConstrainstHelper(active, make) {
if (!active) return { adqlConstraintsAry: [], constraintErrors: [], simpleError: '', };
const constraints = make();
return {
...constraints,
constraintErrors: [...(constraints.errAry ?? [])],
simpleError: constraints.errAry?.[0] ?? '',
};
}then your use Memo function
const constraintResult = React.useMemo(() => {
return doContrains(
isSpatialPanelActive,
() => makeSpatialConstraints( columnsModel, obsCoreEnabled, makeFldObj(fldListAry),
uploadInfo, tableName, canUpload, useSIAv2)
);
}, [...fldListAry.map((v)=> getVal(v)) ]);Idea 2
define in TableSearchHelpers.js the short functions makeEmptyConstrains() and a makeConstrainstEntry(constraints)
then
const constraintResult1 = React.useMemo(() => {
if (!isSpatialPanelActive) return makeEmptyConstrains();
const constraints = makeSpatialConstraints(
columnsModel, obsCoreEnabled, makeFldObj(fldListAry),
uploadInfo, tableName, canUpload, useSIAv2
);
return makeConstrainstEntry(constraints);
}, [...fldListAry.map((v)=> getVal(v)) ]);
jaladh-singhal
left a comment
There was a problem hiding this comment.
Code looks improved, left some minor comments.
Regarding testing, the spatial constraints are working now but other constraints like spectral constraints no longer get added to constraint fragment list.
- SIA: make a search with location constraints, check job/table info -> job url, you will see
POSparam in URL query string. Now make another search with same location constraints and with some spectral coverage constraints, check job url, you will not seeBANDparam in URL query string. Do this same search again, BAND will now appear. - Spectral Image aka SPHEREx ObsTAP: same as above check wavelength params and inspect ADQL query in job info, the constraint on em_min, em_max columns won't appear in the WHERE clause. Same for time constraints
| const closest= getVal(Closest)??''; | ||
| const cornerCalcTypeValue= getVal(cornerCalcType)??'image'; | ||
| const spatialRegOpValue= getVal(SpatialRegOp) ?? SpatialRegOpType.CONTAINS_POINT; | ||
| const spacialType = useFieldGroupValue(SPATIAL_TYPE)[0]() ?? SINGLE; |
There was a problem hiding this comment.
This maybe just preference issue, I find useStoreConnector cleaner for these cases. I consider useFieldGroupValue more for cases where I want a getter function that I'll call later.
| const spacialType = useFieldGroupValue(SPATIAL_TYPE)[0]() ?? SINGLE; | |
| const spacialType = useStoreConnector(() => getFieldVal(groupKey, SPATIAL_TYPE, SINGLE)); |
You can get groupKey by doing const {groupKey} = useContext(FieldGroupCtx);
There was a problem hiding this comment.
I would prefer to stay consistent with useFieldGroupValue. Maybe we should make is support a default
There was a problem hiding this comment.
You could defined this in SimpleComponent. I think it would work. There are many uses.
export function useFieldValueOnly(fieldKey, def, gk) {
return useFieldGroupValue(fieldKey,gk)[0]() ?? def;
}| radiusVal, polygonCornersVal, centerLonVal, centerLatVal, | ||
| uploadCenterLonVal, uploadCenterLatVal, cornerCalcTypeVal, closestVal, | ||
| ]); | ||
|
|
Ticket: https://jira.ipac.caltech.edu/browse/FIREFLY-1943
Fixes bugs introduced in code after enabling react compiler. See ticket for list of bugs.
Reason for most bugs: before react compiler, incidental re-renders would make some of the logic work, but with react compiler enabled, state renders became more obvious (and would happen only when necessary), often leading to stale values and exposing existing bugs (or rather bad code, because everything still worked fine).
Bug 1: SIA Search:
constraintsis probably related tomakePanelStatusUpdater. The way we update constraints here is really complicated, andconstraintswere not updated properly after enabling react compiler and led to stale values.constraintResult.makePanelStatusUpdaterin the new compiler ticket (see note below for other bugs found for this ticket). It's used inObjectIDSearch,ObsCore, and a few other components.makePanelStatusUpdaterflow.Bug 2: Spherex TAP Search:
constraints. By the time we calledgetAdqlQuery, the spatial constraint fragment was missing (after enabling react compiler). The above fix (stopped relying onmakePanelStatusUpdater) and directly computing and updatedconstraintResultfrom the values it depends on fixed this as welluseMemohelps make sure we use the previous constraintResult value of none of the spatial inputs it relies on change, kind of similar tomakePanelStatusUpdaterlogic of checking if new/old values differ)Bug 3: fixed by Trey in a previous PR
Note: I found 2 more bugs: The TAP service dropdown and moving between Single and Multi-Object in Spatial Search. The fix for both is likely the same (in
TapSearchRootPanelandTapUtil). I attempted fixing them in this PR, but the changes were a bit complex & out of scope for this PR. I will address those 2 in a new React Compiler ticket.I will turn off React Compiler before merging.
Testing:
Firefly, Euclid and Spherex