-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
3aad1b7
commit 1be0612
Showing
40 changed files
with
814 additions
and
314 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
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
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
71 changes: 71 additions & 0 deletions
71
...ns/uptime/public/components/overview/kuery_bar/typeahead/search_type/search_type.test.tsx
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,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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { fireEvent } from '@testing-library/react'; | ||
import { render } from '../../../../../lib/helper/rtl_helpers'; | ||
import { SearchType } from './search_type'; | ||
|
||
describe('Kuery bar search type', () => { | ||
it('can change from simple to kq;', () => { | ||
let kqlSyntax = false; | ||
const setKqlSyntax = jest.fn((val: boolean) => { | ||
kqlSyntax = val; | ||
}); | ||
|
||
const { getByTestId } = render( | ||
<SearchType kqlSyntax={kqlSyntax} setKqlSyntax={setKqlSyntax} /> | ||
); | ||
|
||
// open popover to change | ||
fireEvent.click(getByTestId('syntaxChangeToKql')); | ||
|
||
// change syntax | ||
fireEvent.click(getByTestId('toggleKqlSyntax')); | ||
|
||
expect(setKqlSyntax).toHaveBeenCalledWith(true); | ||
expect(setKqlSyntax).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('can change from kql to simple;', () => { | ||
let kqlSyntax = false; | ||
const setKqlSyntax = jest.fn((val: boolean) => { | ||
kqlSyntax = val; | ||
}); | ||
|
||
const { getByTestId } = render( | ||
<SearchType kqlSyntax={kqlSyntax} setKqlSyntax={setKqlSyntax} /> | ||
); | ||
|
||
fireEvent.click(getByTestId('syntaxChangeToKql')); | ||
|
||
fireEvent.click(getByTestId('toggleKqlSyntax')); | ||
|
||
expect(setKqlSyntax).toHaveBeenCalledWith(true); | ||
expect(setKqlSyntax).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('clears the query on change to kql', () => { | ||
const setKqlSyntax = jest.fn(); | ||
|
||
const { history } = render(<SearchType kqlSyntax={true} setKqlSyntax={setKqlSyntax} />, { | ||
url: '/app/uptime?query=test', | ||
}); | ||
|
||
expect(history?.location.search).toBe(''); | ||
}); | ||
|
||
it('clears the search param on change to simple syntax', () => { | ||
const setKqlSyntax = jest.fn(); | ||
|
||
const { history } = render(<SearchType kqlSyntax={false} setKqlSyntax={setKqlSyntax} />, { | ||
url: '/app/uptime?search=test', | ||
}); | ||
|
||
expect(history?.location.search).toBe(''); | ||
}); | ||
}); |
144 changes: 144 additions & 0 deletions
144
...plugins/uptime/public/components/overview/kuery_bar/typeahead/search_type/search_type.tsx
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,144 @@ | ||
/* | ||
* 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, { useEffect, useState } from 'react'; | ||
import { | ||
EuiPopover, | ||
EuiFormRow, | ||
EuiSwitch, | ||
EuiButtonEmpty, | ||
EuiPopoverTitle, | ||
EuiText, | ||
EuiSpacer, | ||
EuiLink, | ||
EuiButtonIcon, | ||
} from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { useKibana } from '../../../../../../../../../src/plugins/kibana_react/public'; | ||
import { euiStyled } from '../../../../../../../../../src/plugins/kibana_react/common'; | ||
import { useUrlParams } from '../../../../../hooks'; | ||
import { | ||
CHANGE_SEARCH_BAR_SYNTAX, | ||
CHANGE_SEARCH_BAR_SYNTAX_SIMPLE, | ||
SYNTAX_OPTIONS_LABEL, | ||
} from '../translations'; | ||
|
||
const BoxesVerticalIcon = euiStyled(EuiButtonIcon)` | ||
padding: 10px 8px 0 8px; | ||
border-radius: 0; | ||
height: 38px; | ||
width: 32px; | ||
background-color: ${(props) => props.theme.eui.euiColorLightestShade}; | ||
padding-top: 8px; | ||
padding-bottom: 8px; | ||
cursor: pointer; | ||
`; | ||
|
||
interface Props { | ||
kqlSyntax: boolean; | ||
setKqlSyntax: (val: boolean) => void; | ||
} | ||
|
||
export const SearchType = ({ kqlSyntax, setKqlSyntax }: Props) => { | ||
const { | ||
services: { docLinks }, | ||
} = useKibana(); | ||
|
||
const [getUrlParams, updateUrlParams] = useUrlParams(); | ||
|
||
const { query, search } = getUrlParams(); | ||
|
||
const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
|
||
const onButtonClick = () => setIsPopoverOpen((prevState) => !prevState); | ||
|
||
const closePopover = () => setIsPopoverOpen(false); | ||
|
||
useEffect(() => { | ||
if (kqlSyntax && query) { | ||
updateUrlParams({ query: '' }); | ||
} | ||
|
||
if (!kqlSyntax && search) { | ||
updateUrlParams({ search: '' }); | ||
} | ||
}, [kqlSyntax, query, search, updateUrlParams]); | ||
|
||
const button = kqlSyntax ? ( | ||
<EuiButtonEmpty | ||
data-test-subj="syntaxChangeToSimple" | ||
onClick={onButtonClick} | ||
aria-label={CHANGE_SEARCH_BAR_SYNTAX_SIMPLE} | ||
title={CHANGE_SEARCH_BAR_SYNTAX_SIMPLE} | ||
> | ||
KQL | ||
</EuiButtonEmpty> | ||
) : ( | ||
<BoxesVerticalIcon | ||
color="text" | ||
iconType="boxesVertical" | ||
onClick={onButtonClick} | ||
data-test-subj="syntaxChangeToKql" | ||
aria-label={CHANGE_SEARCH_BAR_SYNTAX} | ||
title={CHANGE_SEARCH_BAR_SYNTAX} | ||
/> | ||
); | ||
|
||
return ( | ||
<EuiPopover | ||
button={button} | ||
isOpen={isPopoverOpen} | ||
closePopover={closePopover} | ||
ownFocus={true} | ||
anchorPosition="downRight" | ||
> | ||
<div style={{ width: '360px' }}> | ||
<EuiPopoverTitle>{SYNTAX_OPTIONS_LABEL}</EuiPopoverTitle> | ||
<EuiText> | ||
<p> | ||
<KqlDescription href={docLinks!.links.query.kueryQuerySyntax} /> | ||
</p> | ||
</EuiText> | ||
<EuiSpacer /> | ||
<EuiFormRow label={KIBANA_QUERY_LANGUAGE} hasChildLabel={false}> | ||
<EuiSwitch | ||
name="switch" | ||
label={kqlSyntax ? 'On' : 'Off'} | ||
checked={kqlSyntax} | ||
onChange={() => setKqlSyntax(!kqlSyntax)} | ||
data-test-subj="toggleKqlSyntax" | ||
/> | ||
</EuiFormRow> | ||
</div> | ||
</EuiPopover> | ||
); | ||
}; | ||
|
||
const KqlDescription = ({ href }: { href: string }) => { | ||
return ( | ||
<FormattedMessage | ||
id="xpack.uptime.queryBar.syntaxOptionsDescription" | ||
defaultMessage="The {docsLink} (KQL) offers a simplified query | ||
syntax and support for scripted fields. KQL also provides autocomplete if you have | ||
a Basic license or above. If you turn off KQL, Uptime | ||
uses simple wildcard search against {searchField} fields." | ||
values={{ | ||
docsLink: ( | ||
<EuiLink href={href} target="_blank" external> | ||
{KIBANA_QUERY_LANGUAGE} | ||
</EuiLink> | ||
), | ||
searchField: <strong>Monitor Name, ID, Url</strong>, | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
const KIBANA_QUERY_LANGUAGE = i18n.translate('xpack.uptime.query.queryBar.kqlFullLanguageName', { | ||
defaultMessage: 'Kibana Query Language', | ||
}); |
38 changes: 38 additions & 0 deletions
38
x-pack/plugins/uptime/public/components/overview/kuery_bar/typeahead/translations.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,38 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
export const KQL_PLACE_HOLDER = i18n.translate('xpack.uptime.kueryBar.searchPlaceholder.kql', { | ||
defaultMessage: | ||
'Search using kql syntax for monitor IDs, names and type etc (E.g monitor.type: "http" AND tags: "dev")', | ||
}); | ||
|
||
export const SIMPLE_SEARCH_PLACEHOLDER = i18n.translate( | ||
'xpack.uptime.kueryBar.searchPlaceholder.simple', | ||
{ | ||
defaultMessage: 'Search by monitor ID, name, or url (E.g. http:// )', | ||
} | ||
); | ||
|
||
export const CHANGE_SEARCH_BAR_SYNTAX = i18n.translate( | ||
'xpack.uptime.kueryBar.options.syntax.changeLabel', | ||
{ | ||
defaultMessage: 'Change search bar syntax to use Kibana Query Language', | ||
} | ||
); | ||
|
||
export const CHANGE_SEARCH_BAR_SYNTAX_SIMPLE = i18n.translate( | ||
'xpack.uptime.kueryBar.options.syntax.simple', | ||
{ | ||
defaultMessage: 'Change search bar syntax to not use Kibana Query Language', | ||
} | ||
); | ||
|
||
export const SYNTAX_OPTIONS_LABEL = i18n.translate('xpack.uptime.kueryBar.options.syntax', { | ||
defaultMessage: 'SYNTAX OPTIONS', | ||
}); |
44 changes: 44 additions & 0 deletions
44
x-pack/plugins/uptime/public/components/overview/kuery_bar/typeahead/typehead.test.tsx
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,44 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { fireEvent } from '@testing-library/react'; | ||
import { Typeahead } from './typehead'; | ||
import { render } from '../../../../lib/helper/rtl_helpers'; | ||
|
||
describe('Type head', () => { | ||
jest.useFakeTimers(); | ||
|
||
it('it sets initial value', () => { | ||
const { getByTestId, getByDisplayValue, history } = render( | ||
<Typeahead | ||
ariaLabel={'Search for data'} | ||
dataTestSubj={'kueryBar'} | ||
disabled={false} | ||
isLoading={false} | ||
initialValue={'elastic'} | ||
onChange={jest.fn()} | ||
onSubmit={() => {}} | ||
suggestions={[]} | ||
loadMore={() => {}} | ||
queryExample="" | ||
/> | ||
); | ||
|
||
const input = getByTestId('uptimeKueryBarInput'); | ||
|
||
expect(input).toBeInTheDocument(); | ||
expect(getByDisplayValue('elastic')).toBeInTheDocument(); | ||
|
||
fireEvent.change(input, { target: { value: 'kibana' } }); | ||
|
||
// to check if it updateds the query params, needed for debounce wait | ||
jest.advanceTimersByTime(250); | ||
|
||
expect(history.location.search).toBe('?query=kibana'); | ||
}); | ||
}); |
Oops, something went wrong.