Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getFilterName ignores cohort tvs #2627

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions client/mds3/filterName.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ not specific to mds3, may move to client/filter/ or even shared/ in case backend
*/

export function getFilterName(f) {
if (f.lst.length == 0) {
// this is possible when user has deleted the only tvs
return 'No filter'
}
if (!Array.isArray(f?.lst)) return 'Invalid filter'
// for a ds using subcohorts, a filter may contain cohort tvs and is not informative to display. thus derive new tvs array by skipping it
const lst = f.lst.filter(i => i.tag != 'cohortFilter')
if (lst.length == 0) return 'No filter' // this is possible when user has deleted the only tvs

if (f.lst.length == 1 && f.lst[0].type == 'tvs') {
if (lst.length == 1 && lst[0].type == 'tvs') {
// has only one tvs
const tvs = f.lst[0].tvs
const tvs = lst[0].tvs
if (!tvs) throw 'f.lst[0].tvs{} missing'
const ttype = tvs?.term?.type
if (ttype == 'categorical') {
Expand Down Expand Up @@ -52,7 +52,7 @@ export function getFilterName(f) {
}
// more than 1 tvs, not able to generate a short name
// TODO count total tvs from nested list
return 'Filter (' + f.lst.length + ')'
return 'Filter (' + lst.length + ')'
}

/*
Expand Down
48 changes: 40 additions & 8 deletions client/mds3/test/filterName.unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ tape('\n', test => {
test.end()
})

// TODO multivalue

const catTerm = { type: 'categorical', name: 'TermA', values: { A: { label: 'Aname' } } }
const cohortTvs = {
tag: 'cohortFilter',
type: 'tvs',
tvs: {
term: { name: 'Cohort', type: 'multivalue', id: 'subcohort', isleaf: false, groupsetting: { disabled: true } },
values: [{ key: 'ABC', label: 'ABC' }]
}
}

const fCat = {
lst: [
Expand All @@ -20,6 +30,21 @@ const fCat = {
]
}

const fCohort = { lst: [cohortTvs] }

const fCatCohort = {
lst: [
cohortTvs,
{
type: 'tvs',
tvs: {
term: catTerm,
values: [{ key: 'A' }]
}
}
]
}

const fInt = {
lst: [
{
Expand Down Expand Up @@ -47,21 +72,28 @@ tape('getFilterName', test => {
test.timeoutAfter(100)
//test.plan(3)

// combined string is short enough for term name to be included
test.equal(getFilterName(fCat), catTerm.name + ': Aname')
test.equal(getFilterName(fCohort), 'No filter', 'filter with just cohortFilter is shown as empty')

test.equal(
getFilterName(fCat),
catTerm.name + ': Aname',
'combined string is short enough for term name to be included'
)

catTerm.name = 'Term11111112222222'
test.equal(getFilterName(fCat), 'Aname', 'combined name is too long thus only show category name')

catTerm.name = 'Term11111112222222' // name too long and it no longer appears
test.equal(getFilterName(fCat), 'Aname')
test.equal(getFilterName(fCatCohort), 'Aname', 'tvs with tag=cohortFilter is ignored')

test.equal(getFilterName(fInt), '10<x<20')

test.equal(getFilterName(fFloat), '1.1<x<2.6')

fFloat.lst[0].tvs.term.type = 'geneExpression' // pretend the floating range filter is gene exp
test.equal(getFilterName(fFloat), '1.1<x<2.6') // and it's treated same as float
fFloat.lst[0].tvs.term.type = 'geneExpression'
test.equal(getFilterName(fFloat), '1.1<x<2.6', 'geneExpression tvs')

fFloat.lst[0].tvs.term.type = 'metaboliteIntensity' // pretend the floating range filter is metabolite
test.equal(getFilterName(fFloat), '1.1<x<2.6') // and it's treated same as float
fFloat.lst[0].tvs.term.type = 'metaboliteIntensity'
test.equal(getFilterName(fFloat), '1.1<x<2.6', 'metaboliteIntensity tvs')

test.end()
})
3 changes: 2 additions & 1 deletion release.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

Fixes:
- getFilterName ignores cohort tvs
Loading