From d54e0ad7dc62182fdd393d239e295ac0e470f3e2 Mon Sep 17 00:00:00 2001 From: tygao Date: Wed, 3 May 2023 18:44:39 +0800 Subject: [PATCH 1/4] feat: update aggregation config Signed-off-by: tygao --- .../common/search/aggs/buckets/geo_hash.ts | 3 +- .../common/search/aggs/buckets/geo_tile.ts | 2 +- .../public/components/agg_params_map.ts | 3 ++ .../components/controls/use_geocentroid.tsx | 51 +++++++++++++++---- 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/plugins/data/common/search/aggs/buckets/geo_hash.ts b/src/plugins/data/common/search/aggs/buckets/geo_hash.ts index 712f5f6b0df7..4e1280ee457e 100644 --- a/src/plugins/data/common/search/aggs/buckets/geo_hash.ts +++ b/src/plugins/data/common/search/aggs/buckets/geo_hash.ts @@ -64,7 +64,7 @@ export const getGeoHashBucketAgg = () => { name: 'field', type: 'field', - filterFieldTypes: OSD_FIELD_TYPES.GEO_POINT, + filterFieldTypes: [OSD_FIELD_TYPES.GEO_POINT, OSD_FIELD_TYPES.GEO_SHAPE], }, { name: 'autoPrecision', @@ -94,6 +94,7 @@ export const getGeoHashBucketAgg = () => write: () => {}, }, ], + //!!! getRequestAggs(agg) { const aggs = []; const params = agg.params; diff --git a/src/plugins/data/common/search/aggs/buckets/geo_tile.ts b/src/plugins/data/common/search/aggs/buckets/geo_tile.ts index 87c082905799..cfea744dba2f 100644 --- a/src/plugins/data/common/search/aggs/buckets/geo_tile.ts +++ b/src/plugins/data/common/search/aggs/buckets/geo_tile.ts @@ -55,7 +55,7 @@ export const getGeoTitleBucketAgg = () => { name: 'field', type: 'field', - filterFieldTypes: OSD_FIELD_TYPES.GEO_POINT, + filterFieldTypes: [OSD_FIELD_TYPES.GEO_POINT, OSD_FIELD_TYPES.GEO_SHAPE], }, { name: 'useGeocentroid', diff --git a/src/plugins/vis_default_editor/public/components/agg_params_map.ts b/src/plugins/vis_default_editor/public/components/agg_params_map.ts index bbfcb11e37a1..4680e436e71a 100644 --- a/src/plugins/vis_default_editor/public/components/agg_params_map.ts +++ b/src/plugins/vis_default_editor/public/components/agg_params_map.ts @@ -46,6 +46,9 @@ const buckets = { [BUCKET_TYPES.FILTERS]: { filters: controls.FiltersParamEditor, }, + [BUCKET_TYPES.GEOTILE_GRID]: { + useGeocentroid: controls.UseGeocentroidParamEditor, + }, [BUCKET_TYPES.GEOHASH_GRID]: { autoPrecision: controls.AutoPrecisionParamEditor, precision: controls.PrecisionParamEditor, diff --git a/src/plugins/vis_default_editor/public/components/controls/use_geocentroid.tsx b/src/plugins/vis_default_editor/public/components/controls/use_geocentroid.tsx index 17973636ab15..f4e7f897efc0 100644 --- a/src/plugins/vis_default_editor/public/components/controls/use_geocentroid.tsx +++ b/src/plugins/vis_default_editor/public/components/controls/use_geocentroid.tsx @@ -28,24 +28,57 @@ * under the License. */ -import React from 'react'; -import { EuiSwitch, EuiFormRow } from '@elastic/eui'; +import React, { useState, useEffect } from 'react'; +import { EuiSwitch, EuiFormRow, EuiToolTip } from '@elastic/eui'; import { i18n } from '@osd/i18n'; import { AggParamEditorProps } from '../agg_param_props'; +import { OSD_FIELD_TYPES } from '../../../../../plugins/data/common'; + +function UseGeocentroidParamEditor({ agg, value = false, setValue }: AggParamEditorProps) { + const [disabled, setDisabled] = useState(false); -function UseGeocentroidParamEditor({ value = false, setValue }: AggParamEditorProps) { const label = i18n.translate('visDefaultEditor.controls.placeMarkersOffGridLabel', { defaultMessage: 'Place markers off grid (use geocentroid)', }); + const tooltipLabel = i18n.translate( + 'visDefaultEditor.controls.placeMarkersOffGridLabelUnsupport', + { + defaultMessage: 'Currently geo_shape type field does not support centroid aggregation.', + } + ); + + useEffect(() => { + //geo_shape type field does not support centroid aggregation + if (agg?.params?.field?.type === OSD_FIELD_TYPES.GEO_SHAPE) { + setDisabled(true); + setValue(false); + } else { + setDisabled(false); + } + }, [agg]); + return ( - setValue(ev.target.checked)} - /> + {disabled ? ( + + setValue(ev.target.checked)} + /> + + ) : ( + setValue(ev.target.checked)} + /> + )} ); } From 82ebd286d0948cfc87a07418b0a110e14d2ae873 Mon Sep 17 00:00:00 2001 From: tygao Date: Wed, 3 May 2023 18:57:45 +0800 Subject: [PATCH 2/4] chore: remove redundant comments Signed-off-by: tygao --- src/plugins/data/common/search/aggs/buckets/geo_hash.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/data/common/search/aggs/buckets/geo_hash.ts b/src/plugins/data/common/search/aggs/buckets/geo_hash.ts index 4e1280ee457e..301a3361aedf 100644 --- a/src/plugins/data/common/search/aggs/buckets/geo_hash.ts +++ b/src/plugins/data/common/search/aggs/buckets/geo_hash.ts @@ -94,7 +94,6 @@ export const getGeoHashBucketAgg = () => write: () => {}, }, ], - //!!! getRequestAggs(agg) { const aggs = []; const params = agg.params; From 1f2d652f855f588f6674118c633255bc2f750985 Mon Sep 17 00:00:00 2001 From: tygao Date: Wed, 3 May 2023 19:20:02 +0800 Subject: [PATCH 3/4] chore: update hook dependency Signed-off-by: tygao --- .../public/components/controls/use_geocentroid.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/vis_default_editor/public/components/controls/use_geocentroid.tsx b/src/plugins/vis_default_editor/public/components/controls/use_geocentroid.tsx index f4e7f897efc0..a494ccce3151 100644 --- a/src/plugins/vis_default_editor/public/components/controls/use_geocentroid.tsx +++ b/src/plugins/vis_default_editor/public/components/controls/use_geocentroid.tsx @@ -49,14 +49,14 @@ function UseGeocentroidParamEditor({ agg, value = false, setValue }: AggParamEdi ); useEffect(() => { - //geo_shape type field does not support centroid aggregation + // geo_shape type field does not support centroid aggregation if (agg?.params?.field?.type === OSD_FIELD_TYPES.GEO_SHAPE) { setDisabled(true); setValue(false); } else { setDisabled(false); } - }, [agg]); + }, [agg, setValue]); return ( From 38ad5517357c7942cf00e129ee25769b837f5a76 Mon Sep 17 00:00:00 2001 From: tygao Date: Wed, 3 May 2023 20:24:46 +0800 Subject: [PATCH 4/4] doc: update changelog Signed-off-by: tygao --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2924cdc1c11..d3d795778eb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,6 +85,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Add satisfaction survey link to help menu ([#3676] (https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3676)) - [Vis Builder] Add persistence to visualizations inner state ([#3751](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3751)) - [Table Visualization] Move format table, consolidate types and add unit tests ([#3397](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3397)) +- [Data] Add geo_shape type field support in geo_tile and geo_hash aggregation ([#3974](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3974)) ### 🐛 Bug Fixes