Skip to content

Commit

Permalink
nice improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula committed Aug 18, 2020
1 parent 51bf61b commit dfe1083
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React, { useState, useEffect } from 'react';
import { EuiLink, EuiIconTip, EuiText } from '@elastic/eui';
import { EuiLink, EuiIconTip, EuiText, EuiButton } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { DiscoverFieldBucket } from './discover_field_bucket';
import { getWarnings } from './lib/get_warnings';
Expand All @@ -44,7 +44,7 @@ export function DiscoverFieldDetails({
}: DiscoverFieldDetailsProps) {
const warnings = getWarnings(field);
const [showVisualizeLink, setShowVisualizeLink] = useState<boolean>(false);
const [visualizeLink, setVisualizeLink] = useState<string | undefined>('');
const [visualizeLink, setVisualizeLink] = useState<string>('');

useEffect(() => {
isFieldVisualizable(field, indexPattern.id, details.columns).then(
Expand All @@ -53,7 +53,7 @@ export function DiscoverFieldDetails({
// get href only if Visualize button is enabled
getVisualizeHref(field, indexPattern.id, details.columns).then(
(uri) => {
setVisualizeLink(uri);
if (uri) setVisualizeLink(uri);
},
() => {
setVisualizeLink('');
Expand All @@ -67,12 +67,7 @@ export function DiscoverFieldDetails({
}, [field, indexPattern.id, details.columns]);

const handleVisualizeLinkClick = (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
if (
!event.defaultPrevented && // onClick prevented default
event.button === 0 && // ignore everything but left clicks
(!event.currentTarget.target || event.currentTarget.target === '_self') && // let browser handle "target=_blank" etc.
!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey) // ignore clicks with modifier keys
) {
if (!event.defaultPrevented) {
// regular link click. let the uiActions code handle the navigation and show popup if needed
event.preventDefault();
triggerVisualizeActions(field, indexPattern.id, details.columns);
Expand Down Expand Up @@ -117,7 +112,7 @@ export function DiscoverFieldDetails({

{showVisualizeLink && (
// eslint-disable-next-line @elastic/eui/href-or-on-click
<EuiLink
<EuiButton
onClick={(e) => handleVisualizeLinkClick(e)}
href={visualizeLink}
className="kuiButton kuiButton--secondary kuiButton--small kuiVerticalRhythmSmall"
Expand All @@ -130,7 +125,7 @@ export function DiscoverFieldDetails({
{warnings.length > 0 && (
<EuiIconTip type="alert" color="warning" content={warnings.join(' ')} />
)}
</EuiLink>
</EuiButton>
)}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function getVisualizeHref(
indexPatternId: string | undefined,
contextualFields: string[]
) {
if (!indexPatternId) return '';
if (!indexPatternId) return undefined;
const triggerOptions = {
indexPatternId,
fieldName: field.name,
Expand All @@ -70,7 +70,9 @@ export async function getVisualizeHref(
getTriggerConstant(field.type)
);
// enable the link only if only one action is registered
return compatibleActions.length === 1 ? compatibleActions[0].getHref?.(triggerOptions) : '';
return compatibleActions.length === 1
? compatibleActions[0].getHref?.(triggerOptions)
: undefined;
}

export function triggerVisualizeActions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const visualizeFieldAction = createAction<typeof ACTION_VISUALIZE_FIELD>(
type: ACTION_VISUALIZE_FIELD,
getDisplayName: () =>
i18n.translate('visualize.discover.visualizeFieldLabel', {
defaultMessage: 'Visualize on Vis Editor',
defaultMessage: 'Visualize field',
}),
isCompatible: async () => !!getApplication().capabilities.visualize.show,
getHref: async (context) => {
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/maps/public/url_generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ describe('visualize url generator', () => {
},
},
];
// @ts-ignore
const encodedLayers = rison.encode_array(initialLayers);
const url = await generator.createUrl!({
initialLayers,
Expand Down
3 changes: 3 additions & 0 deletions x-pack/typings/rison_node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ declare module 'rison-node' {

// eslint-disable-next-line @typescript-eslint/naming-convention
export const encode_object: <Input extends RisonObject>(input: Input) => string;

// eslint-disable-next-line @typescript-eslint/naming-convention
export const encode_array: <Input extends RisonArray>(input: Input) => string;
}

0 comments on commit dfe1083

Please sign in to comment.