-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[6.7] Share global filters & queries with coordinate maps vis. (#30595)…
… (#31273)
- Loading branch information
1 parent
206f825
commit 14e4da8
Showing
6 changed files
with
152 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export { queryGeohashBounds } from './query_geohash_bounds'; |
98 changes: 98 additions & 0 deletions
98
src/ui/public/visualize/loader/utils/query_geohash_bounds.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { get } from 'lodash'; | ||
import { toastNotifications } from 'ui/notify'; | ||
|
||
import { AggConfig } from 'ui/vis'; | ||
import { Vis } from '../../../vis'; | ||
import { Filters, Query } from '../types'; | ||
|
||
interface QueryGeohashBoundsParams { | ||
filters?: Filters; | ||
query?: Query; | ||
} | ||
|
||
/** | ||
* Coordinate map visualization needs to be able to query for the latest geohash | ||
* bounds when a user clicks the "fit to data" map icon, which requires knowing | ||
* about global filters & queries. This logic has been extracted here so we can | ||
* keep `searchSource` out of the vis, but ultimately we need to design a | ||
* long-term solution for situations like this. | ||
* | ||
* TODO: Remove this as a part of elastic/kibana#30593 | ||
*/ | ||
export async function queryGeohashBounds(vis: Vis, params: QueryGeohashBoundsParams) { | ||
const agg = vis.getAggConfig().find((a: AggConfig) => { | ||
return get(a, 'type.dslName') === 'geohash_grid'; | ||
}); | ||
|
||
if (agg) { | ||
const searchSource = vis.searchSource.createChild(); | ||
searchSource.setField('size', 0); | ||
searchSource.setField('aggs', () => { | ||
const geoBoundsAgg = vis.getAggConfig().createAggConfig( | ||
{ | ||
type: 'geo_bounds', | ||
enabled: true, | ||
params: { | ||
field: agg.getField(), | ||
}, | ||
schema: 'metric', | ||
}, | ||
{ | ||
addToAggConfigs: false, | ||
} | ||
); | ||
return { | ||
'1': geoBoundsAgg.toDsl(), | ||
}; | ||
}); | ||
|
||
const { filters, query } = params; | ||
if (filters) { | ||
searchSource.setField('filter', () => { | ||
const activeFilters = [...filters]; | ||
const indexPattern = agg.getIndexPattern(); | ||
const useTimeFilter = !!indexPattern.timeFieldName; | ||
if (useTimeFilter) { | ||
activeFilters.push(vis.API.timeFilter.createFilter(indexPattern)); | ||
} | ||
return activeFilters; | ||
}); | ||
} | ||
if (query) { | ||
searchSource.setField('query', query); | ||
} | ||
|
||
try { | ||
const esResp = await searchSource.fetch(); | ||
return get(esResp, 'aggregations.1.bounds'); | ||
} catch (error) { | ||
toastNotifications.addDanger({ | ||
title: i18n.translate('common.ui.visualize.queryGeohashBounds.unableToGetBoundErrorTitle', { | ||
defaultMessage: 'Unable to get bounds', | ||
}), | ||
text: `${error.message}`, | ||
}); | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters