Skip to content

Commit

Permalink
Merge pull request #983 from populationgenomics/dev
Browse files Browse the repository at this point in the history
Release - Participant grid fixes
  • Loading branch information
dancoates authored Oct 30, 2024
2 parents 0b1e130 + 5c83cd8 commit f3364b5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
18 changes: 16 additions & 2 deletions db/python/tables/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -68,21 +69,30 @@ async def _construct_participant_query(
},
exclude=['family', 'sample', 'sequencing_group', 'assay'],
)

wheres = [_wheres]

if filter_.family:
needs_family = True
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(
Expand Down Expand Up @@ -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))
Expand Down
25 changes: 15 additions & 10 deletions web/src/pages/project/ValueFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,19 @@ export const ValueFilter: React.FC<IValueFilter> = ({
// 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<string | undefined>(_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
Expand Down Expand Up @@ -146,6 +143,14 @@ export const ValueFilter: React.FC<IValueFilter> = ({
operator = getOperatorFromFilterType(queryType)
}

// @ts-ignore
const _value = optionsToCheck?.[name]?.[operator]

/* eslint-disable react-hooks/rules-of-hooks*/
const [_tempValue, setTempValue] = React.useState<string | undefined>(_value ?? '')
/* eslint-enable react-hooks/rules-of-hooks*/
const tempValue = _tempValue ?? _value

const updateQueryType = (newFilterType: ProjectParticipantGridFilterType) => {
setDefaultFilterType(newFilterType)
const newOperator = getOperatorFromFilterType(newFilterType)
Expand Down

0 comments on commit f3364b5

Please sign in to comment.