Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uiactions to navigate to visualize or maps #74121

Merged
merged 38 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9c95557
Navigate from discover to visualize with registering into a trigger
stratoula Jul 30, 2020
08fcf5b
Implement the VISUALIZE_FIELD action
stratoula Jul 30, 2020
a3756ff
Implementation of the maps app trigger actions with the isCompatible …
stratoula Jul 31, 2020
a590a5e
clean up discover code and tile map action implementation
stratoula Aug 3, 2020
814d7cc
Add typeIsHidden on mocks
stratoula Aug 3, 2020
e87fa63
Merge with master
stratoula Aug 3, 2020
baf82b0
Retrieve filters and query from url state
stratoula Aug 3, 2020
6ce6216
functional test for oss and tile map
stratoula Aug 3, 2020
8c8b6b4
include geoshape
stratoula Aug 3, 2020
b7ec202
fix functional tests
stratoula Aug 4, 2020
aae1b6c
fix types
stratoula Aug 4, 2020
8c56cf7
remove unecessary dependencies
stratoula Aug 4, 2020
ffc0008
minor fixes
stratoula Aug 4, 2020
f523d7c
Remove tilemaps actios as it is going tobe deprecated
stratoula Aug 5, 2020
4c10387
Add useEffect on discover details and move the map action to a separa…
stratoula Aug 5, 2020
f4f2c0d
Retrieve map tooltips info from context
stratoula Aug 5, 2020
4f5e1e8
Retrieve query and filters from QueryService
stratoula Aug 5, 2020
fda9907
Merge branch 'master' into uiactions-navigate-to-visualize
elasticmachine Aug 5, 2020
18cc4d5
Building urls with urlGenerators
stratoula Aug 6, 2020
9d82a1b
Merge branch 'master' into uiactions-navigate-to-visualize
elasticmachine Aug 6, 2020
b2da2db
replace with constants, fetch initialLayers as array
stratoula Aug 6, 2020
5010fd8
remove irrelevant comments
stratoula Aug 8, 2020
f9abf59
Merge branch 'master' into uiactions-navigate-to-visualize
elasticmachine Aug 10, 2020
f8f01b9
Merge branch 'master' into uiactions-navigate-to-visualize
elasticmachine Aug 12, 2020
4f09d9e
nice improvements
stratoula Aug 12, 2020
cc98e5c
resolve conflicts
stratoula Aug 12, 2020
b1e27bb
Return contextualFields for both triggers
stratoula Aug 13, 2020
0f5b898
Add getHref on actions, move capabilities to isCompatible method per …
stratoula Aug 14, 2020
f7b691e
resolve conflicts
stratoula Aug 14, 2020
86bf980
fix type
stratoula Aug 14, 2020
389fd4c
Fix type incompatibility after merging with master
stratoula Aug 14, 2020
cdfb9fd
Merge branch 'master' into uiactions-navigate-to-visualize
elasticmachine Aug 17, 2020
bde9c73
changes on maps services after merging with master
stratoula Aug 18, 2020
33777d0
fixes on maps plugin file after merge
stratoula Aug 18, 2020
51bf61b
remove unecessary declarations
stratoula Aug 18, 2020
dfe1083
nice improvements
stratoula Aug 18, 2020
c8fd6cc
Refactor maps services code to be inline with master
stratoula Aug 18, 2020
63580ef
resolve conflicts by merging from master
stratoula Aug 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import React, { useState, useEffect } from 'react';
import { EuiLink, EuiIconTip, EuiText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { DiscoverFieldBucket } from './discover_field_bucket';
import { getWarnings } from './lib/get_warnings';
import { triggerVisualizeActions, isFieldVisualizable } from './lib/visualize_trigger_utils';
import { Bucket, FieldDetails } from './types';
import { getServices } from '../../../kibana_services';
import { IndexPatternField, IndexPattern } from '../../../../../data/public';

interface DiscoverFieldDetailsProps {
Expand All @@ -39,6 +39,18 @@ export function DiscoverFieldDetails({
onAddFilter,
}: DiscoverFieldDetailsProps) {
const warnings = getWarnings(field);
const [showVisualizeLink, setShowVisualizeLink] = useState<boolean | undefined>(false);
stratoula marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
isFieldVisualizable(field, indexPattern.id, details.columns).then(
stratoula marked this conversation as resolved.
Show resolved Hide resolved
(flag) => {
setShowVisualizeLink(flag);
},
() => {
setShowVisualizeLink(false);
}
);
}, [field, indexPattern.id, details.columns]);

return (
<div className="dscFieldDetails">
Expand Down Expand Up @@ -76,13 +88,11 @@ export function DiscoverFieldDetails({
</div>
)}

{details.visualizeUrl && (
{showVisualizeLink && (
<>
<EuiLink
onClick={() => {
getServices().core.application.navigateToApp(details.visualizeUrl.app, {
path: details.visualizeUrl.path,
});
triggerVisualizeActions(field, indexPattern.id, details.columns);
stratoula marked this conversation as resolved.
Show resolved Hide resolved
}}
className="kuiButton kuiButton--secondary kuiButton--small kuiVerticalRhythmSmall"
data-test-subj={`fieldVisualize-${field.name}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ export function DiscoverSidebar({
);

const getDetailsByField = useCallback(
(ipField: IndexPatternField) =>
getDetails(ipField, selectedIndexPattern, state, columns, hits, services),
[selectedIndexPattern, state, columns, hits, services]
(ipField: IndexPatternField) => getDetails(ipField, hits, columns),
[hits, columns]
);

const popularLimit = services.uiSettings.get(FIELDS_LIMIT_SETTING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,24 @@
* specific language governing permissions and limitations
* under the License.
*/
import { getVisualizeUrl, isFieldVisualizable } from './visualize_url_utils';
import { AppState } from '../../../angular/discover_state';

// @ts-ignore
import { fieldCalculator } from './field_calculator';
import { IndexPatternField, IndexPattern } from '../../../../../../data/public';
import { DiscoverServices } from '../../../../build_services';
import { IndexPatternField } from '../../../../../../data/public';

export function getDetails(
field: IndexPatternField,
indexPattern: IndexPattern,
state: AppState,
columns: string[],
hits: Array<Record<string, unknown>>,
services: DiscoverServices
columns: string[]
) {
const details = {
visualizeUrl:
services.capabilities.visualize.show && isFieldVisualizable(field, services.visualizations)
? getVisualizeUrl(field, indexPattern, state, columns, services)
: null,
...fieldCalculator.getFieldValueCounts({
hits,
field,
count: 5,
grouped: false,
}),
columns,
};
if (details.buckets) {
for (const bucket of details.buckets) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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,
} from '../../../../../../ui_actions/public';
import { getUiActions, getServices } from '../../../../kibana_services';
import { IndexPatternField, KBN_FIELD_TYPES } from '../../../../../../data/public';
import { DiscoverServices } from '../../../../build_services';

function getTrigger(type: string) {
return type === KBN_FIELD_TYPES.GEO_POINT || type === KBN_FIELD_TYPES.GEO_SHAPE
? VISUALIZE_GEO_FIELD_TRIGGER
: VISUALIZE_FIELD_TRIGGER;
}

async function getCompatibleActions(
fieldName: string,
indexPatternId: string,
contextualFields: string[],
action: typeof VISUALIZE_FIELD_TRIGGER | typeof VISUALIZE_GEO_FIELD_TRIGGER
) {
const compatibleActions = await getUiActions().getTriggerCompatibleActions(action, {
indexPatternId,
fieldName,
contextualFields,
});
return compatibleActions;
}

export function triggerVisualizeActions(
field: IndexPatternField,
indexPatternId: string | undefined,
contextualFields: string[]
) {
if (!indexPatternId) return;
const trigger = getTrigger(field.type);
const triggerOptions = {
indexPatternId,
fieldName: field.name,
contextualFields: trigger === VISUALIZE_GEO_FIELD_TRIGGER ? contextualFields : [],
stratoula marked this conversation as resolved.
Show resolved Hide resolved
};
getUiActions().executeTriggerActions(trigger, triggerOptions);
stratoula marked this conversation as resolved.
Show resolved Hide resolved
}

export async function isFieldVisualizable(
field: IndexPatternField,
indexPatternId: string | undefined,
contextualFields: string[]
) {
if (!indexPatternId) return;
if (field.name === '_id') {
// Else you'd get a 'Fielddata access on the _id field is disallowed' error on ES side.
return false;
}
const trigger = getTrigger(field.type);
const services: DiscoverServices = getServices();
const compatibleActions = await getCompatibleActions(
field.name,
indexPatternId,
contextualFields,
trigger
);
return (
compatibleActions.length > 0 && field.visualizable && !!services.capabilities.visualize.show
stratoula marked this conversation as resolved.
Show resolved Hide resolved
);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ export interface FieldDetails {
exists: number;
total: boolean;
buckets: Bucket[];
visualizeUrl: {
app: string;
path: string;
};
columns: string[];
}

export interface Bucket {
Expand Down
Loading