feat(plugins): plugins trigger search (MIN-221)
Search can be done by query or coordinates. To search, plugins can use the triggerSearch
method in window.minerva.map
object available globally.
If we want to search using a query, we need to provide an object with the following properties as an argument:
- query: this should be the search string.
- perfectSearch: this property indicates whether results should be a perfect match or not. Its value should be a boolean type. This property is optional, and by default, its value is `false`.
- fitBounds: should the map be resized to the rectangle fitting all results. Its value should be a boolean type. This property is optional, and by default, its value is `false`.
Example:
window.minerva.map.triggerSearch({ query: 'NR4A2;SNCA;aspirin', perfectSearch: true });
If we want to search using coordinates, we need to provide an object with the following properties as an argument:
- coordinates: this property should indicate the x and y coordinates on the map. Its value should be an object type with x and y properties
- modelId: this property should indicate submap identifier. Its value should be a number type
- zoom: this property should indicate zoom level at which we want to trigger search. Its value should be a number type
- fitBounds: should the map be resized to the rectangle fitting all results. Its value should be a boolean type. This property is optional, and by default, its value is `false`.
Example:
window.minerva.map.triggerSearch({
coordinates: { x: 1947, y: 5203 },
modelId: 52,
fitBounds: true,
});
Merge request reports
Activity
assigned to @mateusz-winiarczyk
added 7 commits
-
d28be8f3...6a321893 - 6 commits from branch
development
- 44e7028d - Merge remote-tracking branch 'origin/development' into MIN-221-plugins-trigger-search
-
d28be8f3...6a321893 - 6 commits from branch
1 import { handleDataReset } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/handleDataReset'; 2 import { handleSearchResultAction } from '@/components/Map/MapViewer/utils/listeners/mapSingleClick/handleSearchResultAction'; 3 import { SIZE_OF_EMPTY_ARRAY } from '@/constants/common'; 4 import { store } from '@/redux/store'; 5 import { getElementsByPoint } from '@/utils/search/getElementsByCoordinates'; 6 import { Coordinates } from './triggerSearch.types'; 7 8 export const searchByCoordinates = async ( 9 coordinates: Coordinates, 10 modelId: number, 11 ): Promise<void> => { 12 const { dispatch } = store; 13 // side-effect below is to prevent complications with data update - old data may conflict with new data 14 // so we need to reset all the data before updating 15 dispatch(handleDataReset); This information has been moved from onMapSingleClick.ts, with most of the code being transferred from that file. While I haven't encountered these complications yet, I moved this information with caution to maintain consistency, as it represents common functionality for both plugins and the client app. Since it's the same feature for both, any bugs or complications may also arise in plugins.
3 import { searchByCoordinates } from './searchByCoordinates'; 4 5 export async function triggerSearch(params: SearchParams): Promise<void> { 6 if ('query' in params) { 7 if (typeof params.query !== 'string') { 8 throw new Error('Invalid query type. The query should be of string type'); 9 } 10 searchByQuery(params.query, params.perfectSearch); 11 } else { 12 if ( 13 typeof params.coordinates !== 'object' || 14 params.coordinates === null || 15 !('x' in params.coordinates) || 16 !('y' in params.coordinates) || 17 typeof params.coordinates.x !== 'number' || 18 typeof params.coordinates.y !== 'number' changed this line in version 3 of the diff
added 1 commit
- e197407b - refactor(search): extract conditions to separate variables
added 3 commits
-
e197407b...e16099c3 - 2 commits from branch
development
- 7105f345 - Merge remote-tracking branch 'origin/development' into MIN-221-plugins-trigger-search
-
e197407b...e16099c3 - 2 commits from branch
mentioned in commit 2fdb9af4