Skip to content

Commit

Permalink
Merge branch 'master' into lens/escape-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jun 23, 2021
2 parents 1cf3c70 + 12895d8 commit 55341cb
Show file tree
Hide file tree
Showing 117 changed files with 1,458 additions and 936 deletions.
1 change: 1 addition & 0 deletions src/core/public/rendering/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@mixin kbnAffordForHeader($headerHeight) {
@include euiHeaderAffordForFixed($headerHeight);

#securitySolutionStickyKQL,
#app-fixed-viewport {
top: $headerHeight;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React from 'react';
import { EuiSelectable } from '@elastic/eui';
import { ShallowWrapper } from 'enzyme';
import { act } from 'react-dom/test-utils';
import { shallowWithIntl } from '@kbn/test/jest';
import { ChangeIndexPattern } from './change_indexpattern';
import { indexPatternMock } from '../../../../../__mocks__/index_pattern';
import { indexPatternWithTimefieldMock } from '../../../../../__mocks__/index_pattern_with_timefield';
import { IndexPatternRef } from './types';

function getProps() {
return {
indexPatternId: indexPatternMock.id,
indexPatternRefs: [
indexPatternMock as IndexPatternRef,
indexPatternWithTimefieldMock as IndexPatternRef,
],
onChangeIndexPattern: jest.fn(),
trigger: {
label: indexPatternMock.title,
title: indexPatternMock.title,
'data-test-subj': 'indexPattern-switch-link',
},
};
}

function getIndexPatternPickerList(instance: ShallowWrapper) {
return instance.find(EuiSelectable).first();
}

function getIndexPatternPickerOptions(instance: ShallowWrapper) {
return getIndexPatternPickerList(instance).prop('options');
}

export function selectIndexPatternPickerOption(instance: ShallowWrapper, selectedLabel: string) {
const options: Array<{ label: string; checked?: 'on' | 'off' }> = getIndexPatternPickerOptions(
instance
).map((option: { label: string }) =>
option.label === selectedLabel
? { ...option, checked: 'on' }
: { ...option, checked: undefined }
);
return getIndexPatternPickerList(instance).prop('onChange')!(options);
}

describe('ChangeIndexPattern', () => {
test('switching index pattern to the same index pattern does not trigger onChangeIndexPattern', async () => {
const props = getProps();
const comp = shallowWithIntl(<ChangeIndexPattern {...props} />);
await act(async () => {
selectIndexPatternPickerOption(comp, indexPatternMock.title);
});
expect(props.onChangeIndexPattern).toHaveBeenCalledTimes(0);
});
test('switching index pattern to a different index pattern triggers onChangeIndexPattern', async () => {
const props = getProps();
const comp = shallowWithIntl(<ChangeIndexPattern {...props} />);
await act(async () => {
selectIndexPatternPickerOption(comp, indexPatternWithTimefieldMock.title);
});
expect(props.onChangeIndexPattern).toHaveBeenCalledTimes(1);
expect(props.onChangeIndexPattern).toHaveBeenCalledWith(indexPatternWithTimefieldMock.id);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ export type ChangeIndexPatternTriggerProps = EuiButtonProps & {
// TODO: refactor to shared component with ../../../../../../../../x-pack/legacy/plugins/lens/public/indexpattern_plugin/change_indexpattern

export function ChangeIndexPattern({
indexPatternRefs,
indexPatternId,
indexPatternRefs,
onChangeIndexPattern,
trigger,
selectableProps,
trigger,
}: {
trigger: ChangeIndexPatternTriggerProps;
indexPatternId?: string;
indexPatternRefs: IndexPatternRef[];
onChangeIndexPattern: (newId: string) => void;
indexPatternId?: string;
selectableProps?: EuiSelectableProps<{ value: string }>;
trigger: ChangeIndexPatternTriggerProps;
}) {
const [isPopoverOpen, setPopoverIsOpen] = useState(false);

Expand Down Expand Up @@ -86,7 +86,9 @@ export function ChangeIndexPattern({
const choice = (choices.find(({ checked }) => checked) as unknown) as {
value: string;
};
onChangeIndexPattern(choice.value);
if (choice.value !== indexPatternId) {
onChangeIndexPattern(choice.value);
}
setPopoverIsOpen(false);
}}
searchProps={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
*/

import React, { useCallback, useState } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiButton, EuiButtonEmpty, EuiToolTip } from '@elastic/eui';
import {
EuiFlexGroup,
EuiFlexItem,
EuiButton,
EuiButtonEmpty,
EuiToolTip,
EuiIconTip,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import useDebounce from 'react-use/lib/useDebounce';
Expand Down Expand Up @@ -84,19 +91,32 @@ function DefaultEditorControls({
</EuiButton>
</EuiToolTip>
) : (
<EuiButton
data-test-subj="visualizeEditorRenderButton"
disabled={!isDirty}
fill
iconType="play"
onClick={applyChanges}
size="s"
>
<FormattedMessage
id="visDefaultEditor.sidebar.updateChartButtonLabel"
defaultMessage="Update"
/>
</EuiButton>
<EuiFlexGroup alignItems="center" gutterSize="s" responsive={false}>
<EuiFlexItem grow={false}>
<EuiIconTip
content={i18n.translate('visDefaultEditor.sidebar.updateInfoTooltip', {
defaultMessage: 'CTRL + Enter is a shortcut for Update.',
})}
type="keyboardShortcut"
color="subdued"
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="visualizeEditorRenderButton"
disabled={!isDirty}
fill
iconType="play"
onClick={applyChanges}
size="s"
>
<FormattedMessage
id="visDefaultEditor.sidebar.updateChartButtonLabel"
defaultMessage="Update"
/>
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
)}
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function FieldSelect({
selectedOptions = [{ label: value!, id: 'INVALID_FIELD' }];
}
} else {
if (value && !selectedOptions.length) {
if (value && fields[fieldsSelector] && !selectedOptions.length) {
onChange([]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

export const reorder = (list, startIndex, endIndex) => {
export const reorder = (list: unknown[], startIndex: number, endIndex: number) => {
const result = Array.from(list);
const [removed] = result.splice(startIndex, 1);
result.splice(endIndex, 0, removed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,30 @@
* Side Public License, v 1.
*/

import _ from 'lodash';
import handlebars from 'handlebars/dist/handlebars';
import { emptyLabel } from '../../../../common/empty_label';
import handlebars from 'handlebars';
import { i18n } from '@kbn/i18n';
import { emptyLabel } from '../../../../common/empty_label';

type CompileOptions = Parameters<typeof handlebars.compile>[1];

export function replaceVars(str, args = {}, vars = {}) {
export function replaceVars(
str: string,
args: Record<string, unknown> = {},
vars: Record<string, unknown> = {},
compileOptions: Partial<CompileOptions> = {}
) {
try {
// we need add '[]' for emptyLabel because this value contains special characters. (https://handlebarsjs.com/guide/expressions.html#literal-segments)
/** we need add '[]' for emptyLabel because this value contains special characters.
* @see (https://handlebarsjs.com/guide/expressions.html#literal-segments) **/
const template = handlebars.compile(str.split(emptyLabel).join(`[${emptyLabel}]`), {
strict: true,
knownHelpersOnly: true,
...compileOptions,
});
const string = template({
...vars,
args,
});

const string = template(_.assign({}, vars, { args }));

return string;
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Side Public License, v 1.
*/

import handlebars from 'handlebars/dist/handlebars';
import { isNumber } from 'lodash';
import handlebars from 'handlebars';
import { isEmptyValue, DISPLAY_EMPTY_VALUE } from '../../../../common/last_value_utils';
import { inputFormats, outputFormats, isDuration } from '../lib/durations';
import { getFieldFormats } from '../../../services';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class TimeseriesVisualization extends Component {
};

applyDocTo = (template) => (doc) => {
const vars = replaceVars(template, null, doc);
const vars = replaceVars(template, null, doc, {
noEscape: true,
});

if (vars instanceof Error) {
this.showToastNotification = vars.error.caused_by;
Expand Down
6 changes: 4 additions & 2 deletions test/functional/apps/discover/_data_grid_doc_navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await rowActions[0].click();
});

const hasDocHit = await testSubjects.exists('doc-hit');
expect(hasDocHit).to.be(true);
await retry.waitFor('hit loaded', async () => {
const hasDocHit = await testSubjects.exists('doc-hit');
return !!hasDocHit;
});
});

// no longer relevant as null field won't be returned in the Fields API response
Expand Down
9 changes: 5 additions & 4 deletions test/functional/apps/discover/_discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});
});

// FLAKY: https://github.com/elastic/kibana/issues/89550
describe.skip('query #2, which has an empty time range', () => {
describe('query #2, which has an empty time range', () => {
const fromTime = 'Jun 11, 1999 @ 09:22:11.000';
const toTime = 'Jun 12, 1999 @ 11:21:04.000';

Expand All @@ -193,8 +192,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

it('should show "no results"', async () => {
const isVisible = await PageObjects.discover.hasNoResults();
expect(isVisible).to.be(true);
await retry.waitFor('no results screen is displayed', async function () {
const isVisible = await PageObjects.discover.hasNoResults();
return isVisible === true;
});
});

it('should suggest a new time range is picked', async () => {
Expand Down
6 changes: 4 additions & 2 deletions test/functional/apps/discover/_doc_navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await rowActions[1].click();
});

const hasDocHit = await testSubjects.exists('doc-hit');
expect(hasDocHit).to.be(true);
await retry.waitFor('hit loaded', async () => {
const hasDocHit = await testSubjects.exists('doc-hit');
return !!hasDocHit;
});
});

// no longer relevant as null field won't be returned in the Fields API response
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/public/components/panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { EuiPanel } from '@elastic/eui';
* Ref: https://www.styled-components.com/docs/faqs#why-am-i-getting-html-attribute-warnings
* Ref: https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html
*/
export const Panel = styled(({ loading, ...props }) => <EuiPanel {...props} />)`
export const Panel = styled(({ loading, ...props }) => <EuiPanel {...props} hasBorder />)`
position: relative;
${({ loading }) =>
loading &&
Expand Down
11 changes: 5 additions & 6 deletions x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ export const KBN_IS_CENTROID_FEATURE = '__kbn_is_centroid_feature__';

export const MVT_TOKEN_PARAM_NAME = 'token';

const MAP_BASE_URL = `/${MAPS_APP_PATH}/${MAP_PATH}`;
export function getNewMapPath() {
return MAP_BASE_URL;
return `/${MAPS_APP_PATH}/${MAP_PATH}`;
}
export function getExistingMapPath(id: string) {
return `${MAP_BASE_URL}/${id}`;
export function getFullPath(id: string | undefined) {
return `/${MAPS_APP_PATH}${getEditPath(id)}`;
}
export function getEditPath(id: string) {
return `/${MAP_PATH}/${id}`;
export function getEditPath(id: string | undefined) {
return id ? `/${MAP_PATH}/${id}` : `/${MAP_PATH}`;
}

export enum LAYER_TYPE {
Expand Down
Loading

0 comments on commit 55341cb

Please sign in to comment.