-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Uptime] Search made easy #88581
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
Merged
Merged
[Uptime] Search made easy #88581
Changes from all commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
9256c19
Refactor overview list
shahzad31 e8dfad2
update snapshots
shahzad31 c7dea64
update
shahzad31 c7ac254
WIP
shahzad31 1b17f80
WIP
shahzad31 5cfd386
Merge branch 'master' into uptime-overview-overhaul
shahzad31 f69f184
update
shahzad31 ccde474
Fix monitor list down histogram
shahzad31 a8d741b
snapshots
shahzad31 f2c1c09
UP
shahzad31 118cc48
UP
shahzad31 797abfb
Merge branch 'master' into uptime-overview-overhaul
shahzad31 4bd38d2
Merge branch 'fix-monitor-down-histogram' into uptime-overview-overhaul
shahzad31 073b2a4
fix type
shahzad31 88f9a12
Snapshots
shahzad31 417b0a4
fix tests
shahzad31 88c62a2
update i18n
shahzad31 6145462
fix type
shahzad31 dd2a31c
fix test
shahzad31 4b35924
Merge branch 'master' into uptime-overview-overhaul
shahzad31 4f11724
PR feedback
shahzad31 343532c
Merge branch 'master' into uptime-overview-overhaul
shahzad31 c56318a
PR feedback
shahzad31 539b280
Merge branch 'master' into uptime-overview-overhaul
shahzad31 b6b1f20
center align status badge
shahzad31 5d1deae
fix types
shahzad31 022f7af
Merge branch 'master' into search-box
shahzad31 9ace208
Merge branch 'master' into uptime-overview-overhaul
kibanamachine 3f30a6b
Merge branch 'master' into uptime-overview-overhaul
shahzad31 a6b7a47
fix table exapnd arrow alignment
shahzad31 9278338
update snaps
shahzad31 d49910a
Merge branch 'uptime-overview-overhaul' of https://github.com/shahzad…
shahzad31 d6e1931
Merge branch 'master' into uptime-overview-overhaul
shahzad31 9acf417
PR feedback
shahzad31 825535b
update snaps
shahzad31 a1bd12a
Merge branch 'master' into search-box
shahzad31 637ee2f
Merge branch 'uptime-overview-overhaul' into search-box
shahzad31 d7791c4
up
shahzad31 3a2d165
Merge branch 'master' into search-box
shahzad31 9811415
update ping and snapshot api
shahzad31 3f31b65
Merge branch 'master' into search-box
shahzad31 d1f3f04
wip
shahzad31 2811ac3
wip
shahzad31 5b9ccb5
wip
shahzad31 c4e9649
Merge branch 'master' into search-box
shahzad31 e2501e2
update tests
shahzad31 09acaa1
Merge branch 'master' into search-box
shahzad31 4ea9ce6
Merge branch 'master' into search-box
shahzad31 7e9254a
fix types
shahzad31 a4c736e
Merge branch 'master' into search-box
shahzad31 30a5f24
fix types
shahzad31 cb13f95
Merge branch 'master' into search-box
shahzad31 2ddc54a
fix i18n
shahzad31 b0f3fc9
update and added functional test
shahzad31 d4b8d96
Merge branch 'master' into search-box
kibanamachine 85f78f4
Merge branch 'master' into search-box
shahzad31 98dabe5
fix dependencies
shahzad31 277876a
Merge branch 'search-box' of https://github.com/shahzad31/kibana into…
shahzad31 8fde9ea
formatting
shahzad31 bb4b89c
Merge branch 'master' into search-box
kibanamachine e574bba
Merge branch 'master' into search-box
shahzad31 3af405c
fix key events
shahzad31 1ea2b78
Merge branch 'search-box' of https://github.com/shahzad31/kibana into…
shahzad31 206566f
update side effect
shahzad31 5238f2f
make button tabble
shahzad31 4c74803
update side effect
shahzad31 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||
shahzad31 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </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 hidden or 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', { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know we mentioned adding our translations below the component. How would you feel about that in this case? Or do you think this is too much text and will bloat the component file? |
||
| 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.