Skip to content

Commit a42dab6

Browse files
authored
Merge pull request #2264 from broadinstitute/ew-robust-pathway-autocomplete
Robustify search autocomplete to misformated pathways (SCP-6012)
2 parents 925f27d + 66de532 commit a42dab6

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

app/javascript/components/explore/StudyGeneField.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,9 @@ export default function StudyGeneField({
362362
}
363363

364364
/** Last filtering applied before showing selectable autocomplete options */
365-
function finalFilterOptions(option, rawInput) {
365+
export function finalFilterOptions(option, rawInput) {
366366
const input = rawInput.toLowerCase()
367-
const label = 'label' in option ? option.label.toLowerCase() : option.toLowerCase()
367+
const label = 'label' in option ? option.label?.toLowerCase() : option.toLowerCase()
368368
const isPathway = option.data.isGene === false
369369
return isPathway || label.includes(input) // partial match
370370
}

app/javascript/lib/search-utils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ function getPathwayIdsByName() {
3939

4040
const pathwayCache = window.Ideogram.interactionCache
4141

42-
// Lower-quality pathways
43-
const omittedPathways = ['WP1984', 'WP615', 'WP5096']
42+
// Lower-quality or buggy pathways
43+
const omittedPathways = [
44+
'WP1984', 'WP615', 'WP5096',
45+
'WP5520', 'WP5522', 'WP5523'
46+
]
4447

4548
const pathwayIdsByName = {}
4649
const pathwayEntries = Object.entries(pathwayCache)

test/js/explore/study-gene-keyword.test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import React from 'react'
33
import { render, waitFor, screen, fireEvent } from '@testing-library/react'
44
import '@testing-library/jest-dom/extend-expect'
55

6-
import StudyGeneField, { getIsInvalidQuery, getIsEligibleForPathwayExplore } from 'components/explore/StudyGeneField'
6+
import StudyGeneField, {
7+
getIsInvalidQuery, getIsEligibleForPathwayExplore, finalFilterOptions
8+
} from 'components/explore/StudyGeneField'
79
import * as UserProvider from '~/providers/UserProvider'
810
import { logStudyGeneSearch } from '~/lib/search-metrics'
911
import * as MetricsApi from '~/lib/metrics-api'
@@ -152,5 +154,22 @@ describe('Search query display text', () => {
152154
)
153155

154156
})
157+
158+
it('handles unexpected pathway data structures', () => {
159+
// This tests pathway autocomplete handling for edge-case issues in
160+
// upstreams WikiPathway data, which can occur upon upgrading Ideogram.js library
161+
// to a new version that updates interactions cache data. The resulting bug
162+
// breaks the Explore page when the search box autocompletes an affected gene
163+
// (e.g. TCF4) -- a low incidence, high severity bug.
164+
165+
const rawInput = 'TCF4'
166+
const option = {
167+
label: undefined,
168+
value: 'WP5523',
169+
data: { value: 'WP5523', isGene: false }
170+
}
171+
const isPathway = finalFilterOptions(option, rawInput)
172+
expect(isPathway).toBe(true)
173+
})
155174
})
156175

0 commit comments

Comments
 (0)