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

[Lens] visualize in maps button #98677

Merged
merged 28 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ebded20
[Lens] visualize in maps button
nreese Apr 28, 2021
ae91101
Merge branch 'master' into lens_link_to_maps
kibanamachine Apr 29, 2021
8762935
clean up dependency injection as suggested
nreese Apr 29, 2021
a707d1b
add custom workspace render for geo fields
nreese Apr 30, 2021
c97fa4b
Merge branch 'master' into lens_link_to_maps
kibanamachine May 3, 2021
1ebfdea
tslint and finish drag and drop for geo field
nreese May 3, 2021
c4fc65c
convert react class to function component
nreese May 3, 2021
76313c5
prevent page reload when clicking visualize in maps button
nreese May 3, 2021
dab538d
filter allFields instead of using condition to populate fieldTypeName…
nreese May 4, 2021
9dd3d02
clean up UI
nreese May 4, 2021
5702835
fix jest test
nreese May 4, 2021
a59bef7
globe illustration
nreese May 4, 2021
c4f9207
Merge branch 'master' into lens_link_to_maps
kibanamachine May 5, 2021
68a3b54
UI cleanup
nreese May 5, 2021
1ecc000
functional test
nreese May 5, 2021
873294c
Update x-pack/plugins/lens/public/editor_frame_service/editor_frame/w…
nreese May 10, 2021
21d16a6
Update x-pack/plugins/lens/public/editor_frame_service/editor_frame/w…
nreese May 10, 2021
5fffe4b
Update x-pack/plugins/lens/public/editor_frame_service/editor_frame/w…
nreese May 10, 2021
05f6b5d
Update x-pack/plugins/lens/public/editor_frame_service/editor_frame/w…
nreese May 10, 2021
db3ba29
Update x-pack/plugins/lens/public/editor_frame_service/editor_frame/w…
nreese May 10, 2021
ae91b07
Update x-pack/plugins/lens/public/indexpattern_datasource/field_item.tsx
nreese May 10, 2021
e2f1b3d
Merge branch 'master' into lens_link_to_maps
kibanamachine May 10, 2021
050080b
updated globe svg
nreese May 10, 2021
e5a118a
remove unused
nreese May 10, 2021
6c50c4e
better message for drop zone screen reader
nreese May 10, 2021
73b4549
Update x-pack/plugins/lens/public/editor_frame_service/editor_frame/w…
nreese May 10, 2021
2eb13d5
tslint
nreese May 10, 2021
b6af7e4
Merge branch 'master' into lens_link_to_maps
kibanamachine May 12, 2021
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
14 changes: 14 additions & 0 deletions x-pack/plugins/lens/public/indexpattern_datasource/datapanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import { fieldExists } from './pure_helpers';
import { Loader } from '../loader';
import { esQuery, IIndexPattern } from '../../../../../src/plugins/data/public';
import { IndexPatternFieldEditorStart } from '../../../../../src/plugins/index_pattern_field_editor/public';
import { getUiActions } from '../kibana_services';
import { VISUALIZE_GEO_FIELD_TRIGGER } from '../../../../../src/plugins/ui_actions/public';

export type Props = Omit<DatasourceDataPanelProps<IndexPatternPrivateState>, 'core'> & {
data: DataPublicPluginStart;
Expand Down Expand Up @@ -85,6 +87,18 @@ const fieldTypeNames: Record<DataType, string> = {
histogram: i18n.translate('xpack.lens.datatypes.histogram', { defaultMessage: 'histogram' }),
};

const visualizeGeoFieldTrigger = getUiActions().getTrigger(VISUALIZE_GEO_FIELD_TRIGGER);
if (visualizeGeoFieldTrigger) {
fieldTypeNames.geo_point = i18n.translate('xpack.lens.datatypes.geoPoint', {
defaultMessage: 'geo_point',
});
fieldTypeNames.geo_shape = i18n.translate('xpack.lens.datatypes.geoShape', {
defaultMessage: 'geo_shape',
});
supportedFieldTypes.add('geo_point');
supportedFieldTypes.add('geo_shape');
}

// Wrapper around esQuery.buildEsQuery, handling errors (e.g. because a query can't be parsed) by
// returning a query dsl object not matching anything
function buildSafeEsQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { BucketedAggregation, FieldStatsResponse } from '../../common';
import { IndexPattern, IndexPatternField, DraggedField } from './types';
import { LensFieldIcon } from './lens_field_icon';
import { trackUiEvent } from '../lens_ui_telemetry';
import { VisualizeGeoFieldButton } from './visualize_geo_field_button';

import { debouncedComponent } from '../debounced_component';

Expand Down Expand Up @@ -149,7 +150,13 @@ export const InnerFieldItem = function InnerFieldItem(props: FieldItemProps) {

function fetchData() {
// Range types don't have any useful stats we can show
if (state.isLoading || field.type === 'document' || field.type.includes('range')) {
if (
state.isLoading ||
field.type === 'document' ||
field.type.includes('range') ||
field.type === 'geo_point' ||
field.type === 'geo_shape'
) {
return;
}

Expand Down Expand Up @@ -467,6 +474,21 @@ function FieldItemPopoverContents(props: State & FieldItemProps) {
</EuiText>
</>
);
} else if (field.type === 'geo_point' || field.type === 'geo_shape') {
return (
<>
<EuiPopoverTitle>{panelHeader}</EuiPopoverTitle>

<EuiText size="s">
{i18n.translate('xpack.lens.indexPattern.fieldStatsLimited', {
defaultMessage: `Lens cannot visualize {fieldType} fields.`,
values: { fieldType: field.type },
})}
</EuiText>

<VisualizeGeoFieldButton indexPatternId={indexPattern.id} fieldName={field.name} />
</>
);
} else if (
(!props.histogram || props.histogram.buckets.length === 0) &&
(!props.topValues || props.topValues.buckets.length === 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React, { Component, MouseEvent } from 'react';
import { EuiButton } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { getUiActions } from '../kibana_services';
import {
visualizeGeoFieldTrigger,
VISUALIZE_GEO_FIELD_TRIGGER,
} from '../../../../../src/plugins/ui_actions/public';

interface Props {
indexPatternId: string;
fieldName: string;
}

interface State {
hasLoadedHref: boolean;
href: string | null;
}

export class VisualizeGeoFieldButton extends Component<Props, State> {
private _isMounted = false;
state: State = {
hasLoadedHref: false,
href: null,
};

componentWillUnmount() {
this._isMounted = false;
}

componentDidMount() {
this._isMounted = true;
this.loadHref();
}

async loadHref() {
const actions = await getUiActions().getTriggerCompatibleActions(VISUALIZE_GEO_FIELD_TRIGGER, {
indexPatternId: this.props.indexPatternId,
fieldName: this.props.fieldName,
});
if (!this._isMounted) {
return;
}

const href = actions.length
? await actions[0].getHref?.({
indexPatternId: this.props.indexPatternId,
fieldName: this.props.fieldName,
trigger: visualizeGeoFieldTrigger,
})
: null;

this.setState({
hasLoadedHref: true,
href,
});
}

onClick = (event: MouseEvent<HTMLAnchorElement, MouseEvent>) => {
getUiActions().getTrigger(visualizeGeoFieldTrigger).exec({
indexPatternId: this.props.indexPatternId,
fieldName: this.props.fieldName,
});
};

render() {
return (
<>
{/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
<EuiButton
onClick={this.onClick}
href={this.state.href}
size="s"
isLoading={!this.state.hasLoadedHref}
isDisabled={this.state.href === null}
data-test-subj={`lensGeoFieldVisualize-${this.props.fieldName}`}
>
<FormattedMessage
id="xpack.lens.indexPattern.fieldItem.visualizeGeoFieldLinkText"
defaultMessage="Visualize in Maps"
/>
</EuiButton>
</>
);
}
}
18 changes: 18 additions & 0 deletions x-pack/plugins/lens/public/kibana_services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { CoreStart } from 'kibana/public';
import type { LensPluginStartDependencies } from './plugin';

let coreStart: CoreStart;
let pluginsStart: LensPluginStartDependencies;
export function setStartServices(core: CoreStart, plugins: LensPluginStartDependencies) {
coreStart = core;
pluginsStart = plugins;
}

export const getUiActions = () => pluginsStart.uiActions;
2 changes: 2 additions & 0 deletions x-pack/plugins/lens/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
EmbeddableComponentProps,
getEmbeddableComponent,
} from './editor_frame_service/embeddable/embeddable_component';
import { setStartServices } from './kibana_services';

export interface LensPluginSetupDependencies {
urlForwarding: UrlForwardingSetup;
Expand Down Expand Up @@ -234,6 +235,7 @@ export class LensPlugin {
}

start(core: CoreStart, startDependencies: LensPluginStartDependencies): LensPublicStart {
setStartServices(core, startDependencies);
const frameStart = this.editorFrameService.start(core, startDependencies);
this.createEditorFrame = frameStart.createInstance;
// unregisters the Visualize action and registers the lens one
Expand Down