From 48e5aadf0c6111aa075c5eb0d48fbc1916a7fdc2 Mon Sep 17 00:00:00 2001 From: Yulong Ruan Date: Tue, 20 Dec 2022 17:16:39 +0800 Subject: [PATCH 1/2] feat: display search filters in map layer config panel Adding filters to map layer allows user to do more accurate and customized searches Signed-off-by: Yulong Ruan --- .../document_layer_source.tsx | 35 ++++++++++++++++--- .../layer_control_panel.tsx | 9 ++++- maps_dashboards/public/model/mapLayerType.ts | 3 ++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/maps_dashboards/public/components/layer_config/documents_config/document_layer_source.tsx b/maps_dashboards/public/components/layer_config/documents_config/document_layer_source.tsx index f87cdd5e..adedc01f 100644 --- a/maps_dashboards/public/components/layer_config/documents_config/document_layer_source.tsx +++ b/maps_dashboards/public/components/layer_config/documents_config/document_layer_source.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import { EuiComboBox, EuiFlexItem, @@ -20,11 +20,11 @@ import { } from '@elastic/eui'; import { i18n } from '@osd/i18n'; import { FormattedMessage } from '@osd/i18n/react'; -import { IndexPattern, IndexPatternField } from '../../../../../../src/plugins/data/public'; +import { Filter, IndexPattern, IndexPatternField } from '../../../../../../src/plugins/data/public'; import { useOpenSearchDashboards } from '../../../../../../src/plugins/opensearch_dashboards_react/public'; import { MapServices } from '../../../types'; import { DocumentLayerSpecification } from '../../../model/mapLayerType'; -import _, { Dictionary } from "lodash"; +import _, { Dictionary } from 'lodash'; interface Props { setSelectedLayerConfig: Function; @@ -41,7 +41,7 @@ export const DocumentLayerSource = ({ services: { savedObjects: { client: savedObjectsClient }, data: { - ui: { IndexPatternSelect }, + ui: { IndexPatternSelect, SearchBar }, indexPatterns, }, }, @@ -137,6 +137,16 @@ export const DocumentLayerSource = ({ setSelectedLayerConfig({ ...selectedLayerConfig, source }); }; + const onFiltersUpdated = useCallback( + (filters: Filter[]) => { + setSelectedLayerConfig({ + ...selectedLayerConfig, + source: { ...selectedLayerConfig.source, filters }, + }); + }, + [selectedLayerConfig] + ); + useEffect(() => { const selectIndexPattern = async () => { if (selectedLayerConfig.source.indexPatternId) { @@ -276,6 +286,23 @@ export const DocumentLayerSource = ({ + + + + + + { const { services: { - data: { search }, + data: { search, indexPatterns }, notifications, }, } = useOpenSearchDashboards(); @@ -83,12 +85,17 @@ const LayerControlPanel = memo(({ maplibreRef, setLayers, layers }: Props) => { if (sourceConfig.showTooltips === true && sourceConfig.tooltipFields.length > 0) { sourceFields.push(...sourceConfig.tooltipFields); } + let indexPattern: IndexPattern | undefined = undefined; + if (layer.source.indexPatternId) { + indexPattern = await indexPatterns.get(layer.source.indexPatternId); + } const request = { params: { index: indexPatternRefName, size: layer.source.documentRequestNumber, body: { _source: sourceFields, + query: buildOpenSearchQuery(indexPattern, [], layer.source.filters), }, }, }; diff --git a/maps_dashboards/public/model/mapLayerType.ts b/maps_dashboards/public/model/mapLayerType.ts index b5e47170..54c9eb0c 100644 --- a/maps_dashboards/public/model/mapLayerType.ts +++ b/maps_dashboards/public/model/mapLayerType.ts @@ -3,6 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { Filter } from '../../../../src/plugins/data/public'; + /* eslint @typescript-eslint/consistent-type-definitions: ["error", "type"] */ export type MapLayerSpecification = OSMLayerSpecification | DocumentLayerSpecification; @@ -38,6 +40,7 @@ export type DocumentLayerSpecification = { documentRequestNumber: number; showTooltips: boolean; tooltipFields: string[]; + filters: Filter[]; }; style: { fillColor: string; From 184401b43e481d56cadef0b45a61c298e626fcec Mon Sep 17 00:00:00 2001 From: Yulong Ruan Date: Wed, 21 Dec 2022 08:48:54 +0800 Subject: [PATCH 2/2] chore: no need to initialize an `undefined` variable Co-authored-by: Junqiu Lei Signed-off-by: Yulong Ruan --- .../components/layer_control_panel/layer_control_panel.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maps_dashboards/public/components/layer_control_panel/layer_control_panel.tsx b/maps_dashboards/public/components/layer_control_panel/layer_control_panel.tsx index 813430b7..36fd0336 100644 --- a/maps_dashboards/public/components/layer_control_panel/layer_control_panel.tsx +++ b/maps_dashboards/public/components/layer_control_panel/layer_control_panel.tsx @@ -85,7 +85,7 @@ const LayerControlPanel = memo(({ maplibreRef, setLayers, layers }: Props) => { if (sourceConfig.showTooltips === true && sourceConfig.tooltipFields.length > 0) { sourceFields.push(...sourceConfig.tooltipFields); } - let indexPattern: IndexPattern | undefined = undefined; + let indexPattern: IndexPattern | undefined; if (layer.source.indexPatternId) { indexPattern = await indexPatterns.get(layer.source.indexPatternId); }