diff --git a/packages/synapse-react-client/src/components/FullTextSearch.tsx b/packages/synapse-react-client/src/components/FullTextSearch.tsx index 6678dab7e1..4338287cc2 100644 --- a/packages/synapse-react-client/src/components/FullTextSearch.tsx +++ b/packages/synapse-react-client/src/components/FullTextSearch.tsx @@ -3,7 +3,6 @@ import React, { ChangeEvent, useRef, useState } from 'react' import { ColumnSingleValueFilterOperator, ColumnSingleValueQueryFilter, - ColumnTypeEnum, TextMatchesQueryFilter, } from '@sage-bionetworks/synapse-types' import { useQueryContext } from './QueryContext' @@ -12,6 +11,9 @@ import { HelpPopover } from './HelpPopover/HelpPopover' import IconSvg from './IconSvg/IconSvg' import { IconSvgButton } from './IconSvgButton' import { SYNAPSE_ENTITY_ID_REGEX } from '../utils/functions/RegularExpressions' +import { useAtomValue } from 'jotai' +import { tableQueryDataAtom } from './QueryWrapper/QueryWrapper' +import { getFileColumnModelId } from './SynapseTable/SynapseTableUtils' // See PLFM-7011 const MIN_SEARCH_QUERY_LENGTH = 3 @@ -25,7 +27,9 @@ export const FullTextSearch: React.FunctionComponent = ({ helpMessage = 'This search bar is powered by MySQL Full Text Search.', helpUrl, }: FullTextSearchProps) => { - const { executeQueryRequest, getColumnModel } = useQueryContext() + const { executeQueryRequest } = useQueryContext() + const data = useAtomValue(tableQueryDataAtom) + const columnModels = data?.columnModels const { showSearchBar } = useQueryVisualizationContext() const [searchText, setSearchText] = useState('') const searchInputRef = useRef(null) @@ -42,17 +46,16 @@ export const FullTextSearch: React.FunctionComponent = ({ } else { executeQueryRequest(request => { const { additionalFilters = [] } = request.query - const idColumnModel = getColumnModel('id') + const synIdColumnModelId = getFileColumnModelId(columnModels) const isSynapseID = searchText.match(SYNAPSE_ENTITY_ID_REGEX) - if ( - isSynapseID && - idColumnModel && - idColumnModel.columnType == ColumnTypeEnum.ENTITYID - ) { + if (isSynapseID && synIdColumnModelId) { + const idColumnModel = columnModels?.filter( + el => el.id === synIdColumnModelId, + ) const singleValueQueryFilter: ColumnSingleValueQueryFilter = { concreteType: 'org.sagebionetworks.repo.model.table.ColumnSingleValueQueryFilter', - columnName: 'id', + columnName: idColumnModel![0].name, operator: ColumnSingleValueFilterOperator.IN, values: [searchText], } diff --git a/packages/synapse-react-client/test/containers/FullTextSearch.test.tsx b/packages/synapse-react-client/test/containers/FullTextSearch.test.tsx index 8dc3ff3ef6..b8a22044cd 100644 --- a/packages/synapse-react-client/test/containers/FullTextSearch.test.tsx +++ b/packages/synapse-react-client/test/containers/FullTextSearch.test.tsx @@ -16,6 +16,16 @@ import { ColumnSingleValueFilterOperator, ColumnTypeEnum, } from '@sage-bionetworks/synapse-types' +import { useSetAtom } from 'jotai' +import { tableQueryDataAtom } from '../../src/components/QueryWrapper/QueryWrapper' +import { mockQueryResultBundle } from '../../src/mocks/mockFileViewQuery' + +let setQueryData: ReturnType | undefined + +function ContextReceiver(props: React.PropsWithChildren) { + setQueryData = useSetAtom(tableQueryDataAtom) + return <>{props.children} +} const renderComponent = ( queryContext: Partial, @@ -26,7 +36,9 @@ const renderComponent = ( - + + + , { @@ -37,12 +49,10 @@ const renderComponent = ( const mockExecuteQueryRequest = jest.fn() const mockGetLastQueryRequest = jest.fn() -const mockGetColumnModel = jest.fn() const queryContext: Partial = { executeQueryRequest: mockExecuteQueryRequest, getCurrentQueryRequest: mockGetLastQueryRequest, - getColumnModel: mockGetColumnModel, } const queryVisualizationContext: Partial = { @@ -98,12 +108,7 @@ describe('FullTextSearch tests', () => { }) it('adds the appropriate QueryFilter when searching for Synapse ID', async () => { - const idColModel: ColumnModel = { - name: 'id', - columnType: ColumnTypeEnum.ENTITYID, - id: '1', - } - mockGetColumnModel.mockReturnValue(idColModel) + setQueryData!(mockQueryResultBundle) renderComponent(queryContext, queryVisualizationContext) const searchBox = screen.getByRole('textbox')