From b041a0130c24608931d8e2c65301a2519b09efb4 Mon Sep 17 00:00:00 2001 From: Vijayan Balasubramanian Date: Wed, 8 Feb 2023 12:50:21 -0800 Subject: [PATCH] Add new ui setting for size Introduce new ui setting for custom vector map's size parameter. The default value is 1000. Users can increase this limit by updating this value in Advanced Settings. Signed-off-by: Vijayan Balasubramanian --- CHANGELOG.md | 1 + .../region_map/common/constants/shared.ts | 1 + src/plugins/region_map/common/index.ts | 8 ++++++-- .../region_map/public/choropleth_layer.js | 19 ++++++++++++++----- .../public/components/map_choice_options.tsx | 2 +- .../public/region_map_visualization.js | 6 ++++-- src/plugins/region_map/public/services.ts | 5 +++-- .../region_map/server/routes/opensearch.ts | 5 +++-- src/plugins/region_map/server/ui_settings.ts | 15 +++++++++++++++ 9 files changed, 48 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 394ec6f5f9b2..f6941bfc1b89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [VisBuilder] Fixes pipeline aggs ([#3137](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3137)) - [Region Maps] Fixes bug that prevents selected join field to be used ([#3213](Fix bug that prevents selected join field to be used)) - [Multi DataSource]Update test connection button text([#3247](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3247)) +- [Region Maps] Add default size for custom vector map([#3399](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3399)) ### 🚞 Infrastructure diff --git a/src/plugins/region_map/common/constants/shared.ts b/src/plugins/region_map/common/constants/shared.ts index 6d82a3a33600..3dc3e6ce6e80 100644 --- a/src/plugins/region_map/common/constants/shared.ts +++ b/src/plugins/region_map/common/constants/shared.ts @@ -5,3 +5,4 @@ export const DEFAULT_MAP_CHOICE = 'default'; export const CUSTOM_MAP_CHOICE = 'custom'; +export const CUSTOM_VECTOR_MAP_MAX_SIZE_SETTING = 'visualization:regionmap:customVectorMapMaxSize'; diff --git a/src/plugins/region_map/common/index.ts b/src/plugins/region_map/common/index.ts index bdda981590ef..f7f2062b4910 100644 --- a/src/plugins/region_map/common/index.ts +++ b/src/plugins/region_map/common/index.ts @@ -3,6 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { DEFAULT_MAP_CHOICE, CUSTOM_MAP_CHOICE } from './constants/shared'; +import { + DEFAULT_MAP_CHOICE, + CUSTOM_MAP_CHOICE, + CUSTOM_VECTOR_MAP_MAX_SIZE_SETTING, +} from './constants/shared'; -export { DEFAULT_MAP_CHOICE, CUSTOM_MAP_CHOICE }; +export { DEFAULT_MAP_CHOICE, CUSTOM_MAP_CHOICE, CUSTOM_VECTOR_MAP_MAX_SIZE_SETTING }; diff --git a/src/plugins/region_map/public/choropleth_layer.js b/src/plugins/region_map/public/choropleth_layer.js index e0213108f64a..8d1051071083 100644 --- a/src/plugins/region_map/public/choropleth_layer.js +++ b/src/plugins/region_map/public/choropleth_layer.js @@ -37,7 +37,11 @@ import { getNotifications } from './opensearch_dashboards_services'; import { colorUtil, OpenSearchDashboardsMapLayer } from '../../maps_legacy/public'; import { truncatedColorMaps } from '../../charts/public'; import { getServices } from './services'; -import { DEFAULT_MAP_CHOICE, CUSTOM_MAP_CHOICE } from '../common'; +import { + DEFAULT_MAP_CHOICE, + CUSTOM_MAP_CHOICE, + CUSTOM_VECTOR_MAP_MAX_SIZE_SETTING, +} from '../common'; const EMPTY_STYLE = { weight: 1, @@ -94,7 +98,8 @@ export class ChoroplethLayer extends OpenSearchDashboardsMapLayer { serviceSettings, leaflet, layerChosenByUser, - http + http, + uiSettings ) { super(); this._serviceSettings = serviceSettings; @@ -112,6 +117,7 @@ export class ChoroplethLayer extends OpenSearchDashboardsMapLayer { this._layerChosenByUser = layerChosenByUser; this._http = http; this._visParams = null; + this._uiSettins = uiSettings; // eslint-disable-next-line no-undef this._leafletLayer = this._leaflet.geoJson(null, { @@ -241,7 +247,8 @@ CORS configuration of the server permits requests from the OpenSearch Dashboards // fetch data from index and transform it to feature collection try { const services = getServices(this._http); - const result = await services.getIndexData(this._layerName); + const indexSize = this._uiSettins.get(CUSTOM_VECTOR_MAP_MAX_SIZE_SETTING); + const result = await services.getIndexData(this._layerName, indexSize); const finalResult = { type: 'FeatureCollection', @@ -337,7 +344,8 @@ CORS configuration of the server permits requests from the OpenSearch Dashboards serviceSettings, leaflet, layerChosenByUser, - http + http, + uiSettings ) { const clonedLayer = new ChoroplethLayer( name, @@ -349,7 +357,8 @@ CORS configuration of the server permits requests from the OpenSearch Dashboards serviceSettings, leaflet, layerChosenByUser, - http + http, + uiSettings ); clonedLayer.setJoinField(this._joinField); clonedLayer.setColorRamp(this._colorRamp); diff --git a/src/plugins/region_map/public/components/map_choice_options.tsx b/src/plugins/region_map/public/components/map_choice_options.tsx index f18cf88b3712..f08f026233a6 100644 --- a/src/plugins/region_map/public/components/map_choice_options.tsx +++ b/src/plugins/region_map/public/components/map_choice_options.tsx @@ -4,7 +4,7 @@ */ import './map_choice_options.scss'; -import React, { useCallback, useMemo, useState } from 'react'; +import React, { useCallback, useMemo } from 'react'; import { EuiPanel, EuiSpacer, diff --git a/src/plugins/region_map/public/region_map_visualization.js b/src/plugins/region_map/public/region_map_visualization.js index 81afee4671ca..69dca0525b89 100644 --- a/src/plugins/region_map/public/region_map_visualization.js +++ b/src/plugins/region_map/public/region_map_visualization.js @@ -230,7 +230,8 @@ export function createRegionMapVisualization({ await getServiceSettings(), (await lazyLoadMapsLegacyModules()).L, this._params.layerChosenByUser, - http + http, + uiSettings ); } else { const { ChoroplethLayer } = await import('./choropleth_layer'); @@ -244,7 +245,8 @@ export function createRegionMapVisualization({ await getServiceSettings(), (await lazyLoadMapsLegacyModules()).L, this._params.layerChosenByUser, - http + http, + uiSettings ); } this._choroplethLayer.setLayerChosenByUser(this._params.layerChosenByUser); diff --git a/src/plugins/region_map/public/services.ts b/src/plugins/region_map/public/services.ts index dd26be3ccd7a..ba182c7aa0fa 100644 --- a/src/plugins/region_map/public/services.ts +++ b/src/plugins/region_map/public/services.ts @@ -7,7 +7,7 @@ import { CoreStart, HttpFetchError } from 'opensearch-dashboards/public'; export interface Services { getCustomIndices: () => Promise; - getIndexData: (indexName: string) => Promise; + getIndexData: (indexName: string, size: number) => Promise; getIndexMapping: (indexName: string) => Promise; } @@ -25,11 +25,12 @@ export function getServices(http: CoreStart['http']): Services { return e; } }, - getIndexData: async (indexName: string) => { + getIndexData: async (indexName: string, size: number) => { try { const response = await http.post('../api/geospatial/_search', { body: JSON.stringify({ index: indexName, + size, }), }); return response; diff --git a/src/plugins/region_map/server/routes/opensearch.ts b/src/plugins/region_map/server/routes/opensearch.ts index 5eebc9a0ffda..dfdcb4a1900d 100644 --- a/src/plugins/region_map/server/routes/opensearch.ts +++ b/src/plugins/region_map/server/routes/opensearch.ts @@ -57,14 +57,15 @@ export function registerGeospatialRoutes(router: IRouter) { validate: { body: schema.object({ index: schema.string(), + size: schema.number(), }), }, }, async (context, req, res) => { const client = context.core.opensearch.client.asCurrentUser; try { - const { index } = req.body; - const params = { index, body: {} }; + const { index, size } = req.body; + const params = { index, body: {}, size }; const results = await client.search(params); return res.ok({ body: { diff --git a/src/plugins/region_map/server/ui_settings.ts b/src/plugins/region_map/server/ui_settings.ts index e5c90f6779b1..356465a3e989 100644 --- a/src/plugins/region_map/server/ui_settings.ts +++ b/src/plugins/region_map/server/ui_settings.ts @@ -31,6 +31,7 @@ import { i18n } from '@osd/i18n'; import { UiSettingsParams } from 'opensearch-dashboards/server'; import { schema } from '@osd/config-schema'; +import { CUSTOM_VECTOR_MAP_MAX_SIZE_SETTING } from '../common'; export function getUiSettings(): Record> { return { @@ -49,5 +50,19 @@ export function getUiSettings(): Record> { schema: schema.boolean(), category: ['visualization'], }, + [CUSTOM_VECTOR_MAP_MAX_SIZE_SETTING]: { + name: i18n.translate('regionMap.advancedSettings.visualization.customVectorMapDefaultSize', { + defaultMessage: 'Custom vector map size', + }), + value: 1000, + description: i18n.translate( + 'regionMap.advancedSettings.visualization.customVectorMapDefaultSizeText', + { + defaultMessage: 'The maximum number of features to load from custom vector map', + } + ), + schema: schema.number(), + category: ['visualization'], + }, }; }