-
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.
[Maps] direct Discover "visualize" to open Maps application (#58549)
* [Maps] direct Discover visualize to Maps application * pass initial layers to maps app * add functional test * fix parentheses messed up by lint fix * fix i18n expression * move logic into lib * fix typescript errors * use constant for geo_point and geo_shape, more TS noise * use encode_array in an attempt to make TS happy * another round of TS changes * one more thing Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
4696736
commit 2998ec0
Showing
9 changed files
with
210 additions
and
18 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
108 changes: 108 additions & 0 deletions
108
...ugins/kibana/public/discover/np_ready/components/field_chooser/lib/visualize_url_utils.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,108 @@ | ||
/* | ||
* 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 uuid from 'uuid/v4'; | ||
// @ts-ignore | ||
import rison from 'rison-node'; | ||
import { | ||
IFieldType, | ||
IIndexPattern, | ||
KBN_FIELD_TYPES, | ||
} from '../../../../../../../../../plugins/data/public'; | ||
import { AppState } from '../../../angular/context_state'; | ||
import { getServices } from '../../../../kibana_services'; | ||
|
||
function getMapsAppBaseUrl() { | ||
const mapsAppVisAlias = getServices() | ||
.visualizations.types.getAliases() | ||
.find(({ name }) => { | ||
return name === 'maps'; | ||
}); | ||
return mapsAppVisAlias ? mapsAppVisAlias.aliasUrl : null; | ||
} | ||
|
||
export function isMapsAppRegistered() { | ||
return getServices() | ||
.visualizations.types.getAliases() | ||
.some(({ name }) => { | ||
return name === 'maps'; | ||
}); | ||
} | ||
|
||
export function isFieldVisualizable(field: IFieldType) { | ||
if ( | ||
(field.type === KBN_FIELD_TYPES.GEO_POINT || field.type === KBN_FIELD_TYPES.GEO_SHAPE) && | ||
isMapsAppRegistered() | ||
) { | ||
return true; | ||
} | ||
return field.visualizable; | ||
} | ||
|
||
export function getMapsAppUrl( | ||
field: IFieldType, | ||
indexPattern: IIndexPattern, | ||
appState: AppState, | ||
columns: string[] | ||
) { | ||
const mapAppParams = new URLSearchParams(); | ||
|
||
// Copy global state | ||
const locationSplit = window.location.href.split('discover?'); | ||
if (locationSplit.length > 1) { | ||
const discoverParams = new URLSearchParams(locationSplit[1]); | ||
const globalStateUrlValue = discoverParams.get('_g'); | ||
if (globalStateUrlValue) { | ||
mapAppParams.set('_g', globalStateUrlValue); | ||
} | ||
} | ||
|
||
// Copy filters and query in app state | ||
const mapsAppState: any = { | ||
filters: appState.filters || [], | ||
}; | ||
if (appState.query) { | ||
mapsAppState.query = appState.query; | ||
} | ||
// @ts-ignore | ||
mapAppParams.set('_a', rison.encode(mapsAppState)); | ||
|
||
// create initial layer descriptor | ||
const hasColumns = columns && columns.length && columns[0] !== '_source'; | ||
mapAppParams.set( | ||
'initialLayers', | ||
// @ts-ignore | ||
rison.encode_array([ | ||
{ | ||
id: uuid(), | ||
label: indexPattern.title, | ||
sourceDescriptor: { | ||
id: uuid(), | ||
type: 'ES_SEARCH', | ||
geoField: field.name, | ||
tooltipProperties: hasColumns ? columns : [], | ||
indexPatternId: indexPattern.id, | ||
}, | ||
visible: true, | ||
type: 'VECTOR', | ||
}, | ||
]) | ||
); | ||
|
||
return getServices().addBasePath(`${getMapsAppBaseUrl()}?${mapAppParams.toString()}`); | ||
} |
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
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,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
|
||
export default function({ getService, getPageObjects }) { | ||
const queryBar = getService('queryBar'); | ||
const PageObjects = getPageObjects(['common', 'discover', 'header', 'maps', 'timePicker']); | ||
|
||
describe('discover visualize button', () => { | ||
beforeEach(async () => { | ||
await PageObjects.common.navigateToApp('discover'); | ||
}); | ||
|
||
it('should link geo_shape fields to Maps application', async () => { | ||
await PageObjects.discover.selectIndexPattern('geo_shapes*'); | ||
await PageObjects.discover.clickFieldListItem('geometry'); | ||
await PageObjects.discover.clickFieldListItemVisualize('geometry'); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
await PageObjects.maps.waitForLayersToLoad(); | ||
const doesLayerExist = await PageObjects.maps.doesLayerExist('geo_shapes*'); | ||
expect(doesLayerExist).to.equal(true); | ||
const hits = await PageObjects.maps.getHits(); | ||
expect(hits).to.equal('4'); | ||
}); | ||
|
||
it('should link geo_point fields to Maps application with time and query context', async () => { | ||
await PageObjects.discover.selectIndexPattern('logstash-*'); | ||
await PageObjects.timePicker.setAbsoluteRange( | ||
'Sep 22, 2015 @ 00:00:00.000', | ||
'Sep 22, 2015 @ 04:00:00.000' | ||
); | ||
await queryBar.setQuery('machine.os.raw : "ios"'); | ||
await queryBar.submitQuery(); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
|
||
await PageObjects.discover.clickFieldListItem('geo.coordinates'); | ||
await PageObjects.discover.clickFieldListItemVisualize('geo.coordinates'); | ||
await PageObjects.header.waitUntilLoadingHasFinished(); | ||
await PageObjects.maps.waitForLayersToLoad(); | ||
const doesLayerExist = await PageObjects.maps.doesLayerExist('logstash-*'); | ||
expect(doesLayerExist).to.equal(true); | ||
const hits = await PageObjects.maps.getHits(); | ||
expect(hits).to.equal('7'); | ||
}); | ||
}); | ||
} |
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