diff --git a/db/python/tables/participant.py b/db/python/tables/participant.py index dbe63f21..8ea924e7 100644 --- a/db/python/tables/participant.py +++ b/db/python/tables/participant.py @@ -53,6 +53,7 @@ async def _construct_participant_query( ) -> tuple[str, dict[str, Any]]: """Construct a participant query""" needs_family = False + needs_family_eid = False needs_participant_eid = True # always join, query optimiser can figure it out needs_sample = False needs_sample_eid = False @@ -68,6 +69,7 @@ async def _construct_participant_query( }, exclude=['family', 'sample', 'sequencing_group', 'assay'], ) + wheres = [_wheres] if filter_.family: @@ -75,14 +77,22 @@ async def _construct_participant_query( fwheres, fvalues = filter_.family.to_sql( { 'id': 'f.id', - 'external_id': 'f.external_id', 'meta': 'f.meta', - } + }, + exclude=['external_id'], ) values.update(fvalues) if fwheres: wheres.append(fwheres) + if filter_.family.external_id: + needs_family_eid = True + feid_wheres, feid_values = filter_.family.to_sql( + {'external_id': 'feid.external_id'}, only=['external_id'] + ) + wheres.append(feid_wheres) + values.update(feid_values) + if filter_.sample: needs_sample = True swheres, svalues = filter_.sample.to_sql( @@ -169,6 +179,10 @@ async def _construct_participant_query( 'INNER JOIN family_participant fp ON fp.participant_id = pp.id\n' 'INNER JOIN family f ON f.id = fp.family_id' ) + if needs_family_eid: + query_lines.append( + 'INNER JOIN family_external_id feid ON feid.family_id = f.id' + ) if wheres: query_lines.append('WHERE \n' + ' AND '.join(wheres)) diff --git a/web/src/pages/project/ValueFilter.tsx b/web/src/pages/project/ValueFilter.tsx index 3f8302c8..c213164a 100644 --- a/web/src/pages/project/ValueFilter.tsx +++ b/web/src/pages/project/ValueFilter.tsx @@ -85,22 +85,19 @@ export const ValueFilter: React.FC = ({ // So check if the filterKey starts with 'meta.' to determine if it is a meta key, and // then check the [category].meta object for the value + if (!field.filter_key) return <> + + /* eslint-disable react-hooks/rules-of-hooks*/ const [_defaultFilterType, setDefaultFilterType] = React.useState< ProjectParticipantGridFilterType | undefined >() - - let optionsToCheck = props?.filterValues?.[category] || {} - const name = (field.filter_key ?? '').replace(/^meta\./, '') - - // @ts-ignore - const _value = optionsToCheck?.[name]?.[operator] - const [_tempValue, setTempValue] = React.useState(_value ?? '') - const tempValue = _tempValue ?? _value - - if (!field.filter_key) return <> + /* eslint-enable react-hooks/rules-of-hooks*/ const isMeta = field.filter_key?.startsWith('meta.') // set name to the filterKey without the .meta prefix + const name = field.filter_key.replace(/^meta\./, '') + + let optionsToCheck = props?.filterValues?.[category] || {} if (isMeta) { // get the meta bit from the filterValues @@ -146,6 +143,14 @@ export const ValueFilter: React.FC = ({ operator = getOperatorFromFilterType(queryType) } + // @ts-ignore + const _value = optionsToCheck?.[name]?.[operator] + + /* eslint-disable react-hooks/rules-of-hooks*/ + const [_tempValue, setTempValue] = React.useState(_value ?? '') + /* eslint-enable react-hooks/rules-of-hooks*/ + const tempValue = _tempValue ?? _value + const updateQueryType = (newFilterType: ProjectParticipantGridFilterType) => { setDefaultFilterType(newFilterType) const newOperator = getOperatorFromFilterType(newFilterType)