-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Query rules create mode #223613
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
Query rules create mode #223613
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a8d000e
Add create mode for Query Ruleset
efegurkan c7031bd
Make create ruleset work as a template until first save
efegurkan 08dc163
Add tests
efegurkan 20f9588
Split components into smaller testable pieces
efegurkan 5128608
Split query rule flyout state and add tests
efegurkan 08c66f1
Merge branch 'main' into query-rules-create-mode
elasticmachine de456f1
Review changes
efegurkan 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
63 changes: 63 additions & 0 deletions
63
...plugins/search_query_rules/public/components/empty_prompt/ruleset_detail_empty_prompt.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,63 @@ | ||
| /* | ||
| * 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 { | ||
| EuiFlexGroup, | ||
| EuiFlexItem, | ||
| EuiPanel, | ||
| EuiSpacer, | ||
| EuiText, | ||
| transparentize, | ||
| useEuiTheme, | ||
| } from '@elastic/eui'; | ||
| import { css } from '@emotion/react'; | ||
| import { FormattedMessage } from '@kbn/i18n-react'; | ||
| import queryRulesImg from '../../assets/query-rules-context-alt.svg'; | ||
|
|
||
| export const RulesetDetailEmptyPrompt = () => { | ||
| const { euiTheme } = useEuiTheme(); | ||
| const positionRelative = css({ | ||
| position: 'relative', | ||
| }); | ||
| const imgProps = css({ | ||
| width: '100%', | ||
| height: '100%', | ||
| objectFit: 'cover', | ||
| }); | ||
| const gradientOverlay = css({ | ||
| background: `linear-gradient(180deg, ${transparentize( | ||
| euiTheme.colors.backgroundBasePlain, | ||
| 0 | ||
| )}, ${transparentize(euiTheme.colors.backgroundBasePlain, 1)} 100%)`, | ||
| position: 'absolute', | ||
| bottom: 0, | ||
| height: '30px', | ||
| width: '100%', | ||
| }); | ||
|
|
||
| return ( | ||
| <EuiPanel hasShadow={false} hasBorder={false} paddingSize="l"> | ||
|
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. Why use a panel here vs EuiEmptyPrompt |
||
| <EuiSpacer size="l" /> | ||
| <EuiFlexGroup alignItems="center" justifyContent="center" direction="column"> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiText textAlign="center" size="s" color="subdued"> | ||
| <FormattedMessage | ||
| id="xpack.searchQueryRules.rulesetDetailEmptyPrompt.title" | ||
| defaultMessage="Add your first rule" | ||
| /> | ||
| </EuiText> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem grow css={positionRelative}> | ||
| <img src={queryRulesImg} alt="Query Rules" css={imgProps} /> | ||
| <div css={gradientOverlay}> </div> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </EuiPanel> | ||
| ); | ||
| }; | ||
49 changes: 49 additions & 0 deletions
49
...ns/search/plugins/search_query_rules/public/components/error_prompt/error_prompt.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,49 @@ | ||
| /* | ||
| * 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 { ErrorPrompt } from './error_prompt'; | ||
| import { render } from '@testing-library/react'; | ||
| import { I18nProvider } from '@kbn/i18n-react'; | ||
|
|
||
| const Wrapper = ({ children }: { children?: React.ReactNode }) => ( | ||
| <I18nProvider>{children}</I18nProvider> | ||
| ); | ||
| describe('ErrorPrompt', () => { | ||
| it("renders 'notFound' error type", () => { | ||
| const { getByText } = render(<ErrorPrompt errorType="notFound" />, { wrapper: Wrapper }); | ||
|
|
||
| expect(getByText('Not found')).toBeInTheDocument(); | ||
| expect( | ||
| getByText('Requested resource was not found. Check if the URL is correct.') | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders 'generic' error type", () => { | ||
| const { getByText } = render(<ErrorPrompt errorType="generic" />, { wrapper: Wrapper }); | ||
|
|
||
| expect(getByText('An error occurred')).toBeInTheDocument(); | ||
| expect( | ||
| getByText( | ||
| 'An error occurred while fetching query rules. Check Kibana logs for more information.' | ||
| ) | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders 'missingPermissions' error type", () => { | ||
| const { getByText } = render(<ErrorPrompt errorType="missingPermissions" />, { | ||
| wrapper: Wrapper, | ||
| }); | ||
|
|
||
| expect(getByText('Missing permissions')).toBeInTheDocument(); | ||
| expect( | ||
| getByText( | ||
| 'You do not have the necessary permissions to manage query rules. Contact your system administrator.' | ||
| ) | ||
| ).toBeInTheDocument(); | ||
| }); | ||
| }); |
145 changes: 145 additions & 0 deletions
145
...earch/plugins/search_query_rules/public/components/overview/create_ruleset_modal.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,145 @@ | ||
| /* | ||
| * 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 { I18nProvider } from '@kbn/i18n-react'; | ||
| import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'; | ||
| import React from 'react'; | ||
| import { CreateRulesetModal } from './create_ruleset_modal'; | ||
| import { useFetchQueryRulesetExist } from '../../hooks/use_fetch_ruleset_exists'; | ||
| import { useKibana } from '../../hooks/use_kibana'; | ||
|
|
||
| const Wrapper = ({ children }: { children: React.ReactNode }) => { | ||
| return <I18nProvider>{children}</I18nProvider>; | ||
| }; | ||
|
|
||
| const TEST_IDS = { | ||
| ModalHeaderTitle: 'searchRulesetCreateRulesetModalHeader', | ||
| NameInput: 'searchRulesetCreateRulesetModalFieldText', | ||
| CreateButton: 'searchRulesetCreateRulesetModalCreateButton', | ||
| CloseButton: 'searchRulesetCreateRulesetModalCancelButton', | ||
| EditLink: 'searchRulesetCreateRulesetModalEditLink', | ||
| }; | ||
|
|
||
| const ACTIONS = { | ||
| PressCloseButton: () => { | ||
| act(() => { | ||
| fireEvent.click(screen.getByTestId(TEST_IDS.CloseButton)); | ||
| }); | ||
| }, | ||
| TypeName: (name: string) => { | ||
| const nameInput = screen.getByTestId(TEST_IDS.NameInput) as HTMLInputElement; | ||
| act(() => { | ||
| fireEvent.change(nameInput, { target: { value: name } }); | ||
| }); | ||
| }, | ||
| PressEditLink: () => { | ||
| act(() => { | ||
| fireEvent.click(screen.getByTestId(TEST_IDS.EditLink)); | ||
| }); | ||
| }, | ||
| }; | ||
|
|
||
| const mockOnClose = jest.fn(); | ||
|
|
||
| const mockUseFetchQueryRulesetExist = useFetchQueryRulesetExist as jest.Mock; | ||
| jest.mock('../../hooks/use_fetch_ruleset_exists', () => ({ | ||
| useFetchQueryRulesetExist: jest.fn().mockImplementation(() => ({ | ||
| data: undefined, | ||
| isLoading: false, | ||
| isError: false, | ||
| })), | ||
| })); | ||
|
|
||
| jest.mock('../../hooks/use_kibana', () => ({ | ||
| useKibana: () => ({ | ||
| services: { | ||
| http: { | ||
| basePath: { | ||
| prepend: (path: string) => path, | ||
| }, | ||
| }, | ||
| application: { | ||
| navigateToUrl: jest.fn(), | ||
| }, | ||
| }, | ||
| }), | ||
| })); | ||
|
|
||
| describe('CreateRulesetModal', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
| it('renders', () => { | ||
| render(<CreateRulesetModal onClose={mockOnClose} />, { wrapper: Wrapper }); | ||
|
|
||
| expect(screen.getByTestId(TEST_IDS.ModalHeaderTitle).textContent).toBe('Create ruleset'); | ||
|
|
||
| expect(screen.getByTestId(TEST_IDS.NameInput)).toBeInTheDocument(); | ||
|
|
||
| expect(screen.getByTestId(TEST_IDS.CreateButton).textContent).toBe('Create ruleset'); | ||
| }); | ||
|
|
||
| it('calls onClose when modal is closed', () => { | ||
| render(<CreateRulesetModal onClose={mockOnClose} />, { wrapper: Wrapper }); | ||
|
|
||
| ACTIONS.PressCloseButton(); | ||
|
|
||
| expect(mockOnClose).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should show conflict error when ruleset name already exists', () => { | ||
| mockUseFetchQueryRulesetExist.mockReturnValue({ | ||
| data: { exists: true }, | ||
| isLoading: false, | ||
| isError: false, | ||
| }); | ||
| render(<CreateRulesetModal onClose={mockOnClose} />, { wrapper: Wrapper }); | ||
|
|
||
| ACTIONS.TypeName('existing-ruleset'); | ||
| act(() => { | ||
| mockUseFetchQueryRulesetExist.mock.calls[0][2]('existing-ruleset'); | ||
| }); | ||
|
|
||
| waitFor(() => { | ||
| expect(screen.getByText('Ruleset name already exists')).toBeInTheDocument(); | ||
| }); | ||
| waitFor(() => { | ||
| expect(screen.getByTestId(TEST_IDS.CreateButton)).toBeDisabled(); | ||
| }); | ||
| waitFor(() => { | ||
| expect(screen.getByTestId(TEST_IDS.EditLink)).toHaveAttribute( | ||
| 'href', | ||
| '/app/search_query_rules/ruleset/existing-ruleset/edit' | ||
| ); | ||
| }); | ||
|
|
||
| ACTIONS.PressEditLink(); | ||
| waitFor(() => { | ||
| expect(useKibana().services.application.navigateToUrl).toHaveBeenCalledWith( | ||
| '/app/search_query_rules/ruleset/existing-ruleset/edit' | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| it('should redirect user to create endpoint with given name', () => { | ||
| const mockNavigateToUrl = jest.fn(); | ||
| useKibana().services.application.navigateToUrl = mockNavigateToUrl; | ||
|
|
||
| render(<CreateRulesetModal onClose={mockOnClose} />, { wrapper: Wrapper }); | ||
|
|
||
| ACTIONS.TypeName('new-ruleset'); | ||
| act(() => { | ||
| mockUseFetchQueryRulesetExist.mock.calls[0][1]('new-ruleset'); | ||
| }); | ||
|
|
||
| waitFor(() => { | ||
| expect(mockNavigateToUrl).toHaveBeenCalledWith( | ||
| '/app/search_query_rules/ruleset/new-ruleset/create' | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
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.