Skip to content
Snippets Groups Projects

feat(plugins): plugins trigger search (MIN-221)

Merged mateusz-winiarczyk requested to merge MIN-221-plugins-trigger-search into development
2 unresolved threads

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,
});

triggerSearch

Edited by mateusz-winiarczyk

Merge request reports

Merge request pipeline #86712 passed

Merge request pipeline passed for 7105f345

Test coverage 91.62% (0.07%) from 1 job
Approval is optional

Merged by mateusz-winiarczykmateusz-winiarczyk 1 year ago (Mar 1, 2024 10:29am UTC)

Merge details

  • Changes merged into development with 2fdb9af4 (commits were squashed).
  • Deleted the source branch.

Pipeline #86713 passed

Pipeline passed for 2fdb9af4 on development

Test coverage 91.62% (0.07%) from 1 job

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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);
  • Comment on lines +13 to +15

    Why it may conflict?

  • 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.

  • Please register or sign in to reply
  • 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'
  • LGTM. Good job!

    please resolve RFC

  • Adrian Orłów approved this merge request

    approved this merge request

  • added 1 commit

    • e197407b - refactor(search): extract conditions to separate variables

    Compare with previous version

  • added 3 commits

    Compare with previous version

  • mentioned in commit 2fdb9af4

  • Please register or sign in to reply
    Loading