-
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.
- Loading branch information
Showing
2 changed files
with
97 additions
and
62 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
94 changes: 94 additions & 0 deletions
94
...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,94 @@ | ||
/* | ||
* 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'; | ||
import rison from 'rison-node'; | ||
import { IFieldType, IIndexPattern } from 'src/plugins/data/public'; | ||
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 === 'geo_point' || field.type === 'geo_shape') && isMapsAppRegistered()) { | ||
return true; | ||
} | ||
return field.visualizable; | ||
} | ||
|
||
export function getMapsAppUrl( | ||
field: IFieldType, | ||
indexPattern: IIndexPattern, | ||
appState: any, | ||
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]); | ||
mapAppParams.set('_g', discoverParams.get('_g')); | ||
} | ||
|
||
// Copy filters and query in app state | ||
const mapsAppState = { | ||
filters: appState.filters || [], | ||
}; | ||
if (appState.query) { | ||
mapsAppState.query = appState.query; | ||
} | ||
mapAppParams.set('_a', rison.encode(mapsAppState)); | ||
|
||
// create initial layer descriptor | ||
const hasColumns = columns && columns.length && columns[0] !== '_source'; | ||
mapAppParams.set( | ||
'initialLayers', | ||
rison.encode([ | ||
{ | ||
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()}`); | ||
} |