-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uiactions to navigate to visualize or maps (#74121)
* Navigate from discover to visualize with registering into a trigger * Implement the VISUALIZE_FIELD action * Implementation of the maps app trigger actions with the isCompatible functionality * clean up discover code and tile map action implementation * Add typeIsHidden on mocks * Retrieve filters and query from url state * functional test for oss and tile map * include geoshape * fix functional tests * fix types * remove unecessary dependencies * minor fixes * Remove tilemaps actios as it is going tobe deprecated * Add useEffect on discover details and move the map action to a separate folder * Retrieve map tooltips info from context * Retrieve query and filters from QueryService * Building urls with urlGenerators * replace with constants, fetch initialLayers as array * remove irrelevant comments * nice improvements * Return contextualFields for both triggers * Add getHref on actions, move capabilities to isCompatible method per action and other fixes * fix type * Fix type incompatibility after merging with master * fixes on maps plugin file after merge * remove unecessary declarations * nice improvements * Refactor maps services code to be inline with master Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
68ba483
commit b6c4757
Showing
32 changed files
with
1,017 additions
and
222 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
110 changes: 110 additions & 0 deletions
110
src/plugins/discover/public/application/components/sidebar/lib/visualize_trigger_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,110 @@ | ||
/* | ||
* 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 { | ||
VISUALIZE_FIELD_TRIGGER, | ||
VISUALIZE_GEO_FIELD_TRIGGER, | ||
visualizeFieldTrigger, | ||
visualizeGeoFieldTrigger, | ||
} from '../../../../../../ui_actions/public'; | ||
import { getUiActions } from '../../../../kibana_services'; | ||
import { IndexPatternField, KBN_FIELD_TYPES } from '../../../../../../data/public'; | ||
|
||
function getTriggerConstant(type: string) { | ||
return type === KBN_FIELD_TYPES.GEO_POINT || type === KBN_FIELD_TYPES.GEO_SHAPE | ||
? VISUALIZE_GEO_FIELD_TRIGGER | ||
: VISUALIZE_FIELD_TRIGGER; | ||
} | ||
|
||
function getTrigger(type: string) { | ||
return type === KBN_FIELD_TYPES.GEO_POINT || type === KBN_FIELD_TYPES.GEO_SHAPE | ||
? visualizeGeoFieldTrigger | ||
: visualizeFieldTrigger; | ||
} | ||
|
||
async function getCompatibleActions( | ||
fieldName: string, | ||
indexPatternId: string, | ||
contextualFields: string[], | ||
trigger: typeof VISUALIZE_FIELD_TRIGGER | typeof VISUALIZE_GEO_FIELD_TRIGGER | ||
) { | ||
const compatibleActions = await getUiActions().getTriggerCompatibleActions(trigger, { | ||
indexPatternId, | ||
fieldName, | ||
contextualFields, | ||
}); | ||
return compatibleActions; | ||
} | ||
|
||
export async function getVisualizeHref( | ||
field: IndexPatternField, | ||
indexPatternId: string | undefined, | ||
contextualFields: string[] | ||
) { | ||
if (!indexPatternId) return undefined; | ||
const triggerOptions = { | ||
indexPatternId, | ||
fieldName: field.name, | ||
contextualFields, | ||
trigger: getTrigger(field.type), | ||
}; | ||
const compatibleActions = await getCompatibleActions( | ||
field.name, | ||
indexPatternId, | ||
contextualFields, | ||
getTriggerConstant(field.type) | ||
); | ||
// enable the link only if only one action is registered | ||
return compatibleActions.length === 1 | ||
? compatibleActions[0].getHref?.(triggerOptions) | ||
: undefined; | ||
} | ||
|
||
export function triggerVisualizeActions( | ||
field: IndexPatternField, | ||
indexPatternId: string | undefined, | ||
contextualFields: string[] | ||
) { | ||
if (!indexPatternId) return; | ||
const trigger = getTriggerConstant(field.type); | ||
const triggerOptions = { | ||
indexPatternId, | ||
fieldName: field.name, | ||
contextualFields, | ||
}; | ||
getUiActions().getTrigger(trigger).exec(triggerOptions); | ||
} | ||
|
||
export async function isFieldVisualizable( | ||
field: IndexPatternField, | ||
indexPatternId: string | undefined, | ||
contextualFields: string[] | ||
) { | ||
if (field.name === '_id' || !indexPatternId) { | ||
// for first condition you'd get a 'Fielddata access on the _id field is disallowed' error on ES side. | ||
return false; | ||
} | ||
const trigger = getTriggerConstant(field.type); | ||
const compatibleActions = await getCompatibleActions( | ||
field.name, | ||
indexPatternId, | ||
contextualFields, | ||
trigger | ||
); | ||
return compatibleActions.length > 0 && field.visualizable; | ||
} |
Oops, something went wrong.