-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Logs UI] Add helper hooks with search strategy request cancellation #83906
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
weltenwort
merged 30 commits into
elastic:master
from
weltenwort:logs-ui-cancel-log-entry-request
Dec 11, 2020
Merged
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
b6fe013
WIP
weltenwort 17db20a
WIP
weltenwort 617f822
WIP
weltenwort 67d721e
wire up log entry data source
weltenwort 0d54ad4
start refactoring the log entry flyout (WIP)
weltenwort 18d9c77
Clean up LogEntryFlyout component structure
weltenwort 5a0c827
Remove fake delay inserted for testing
weltenwort 189a5fe
Add unit test for search strategy cancellation
weltenwort 57ec9fe
Properly align loading and error content (WIP)
weltenwort 25731fd
Show cancelable loading progress and errors
weltenwort eb0aa90
Factor out search request error callout
weltenwort cabd9b7
Handle abort errors separately
weltenwort 10e41af
WIP: add unit tests for data search hooks
weltenwort 7775846
Avoid resubscription on projection change
weltenwort b4b4ff9
Add tests for search response hook
weltenwort a622a94
Tweak error copy in response to design feedback
weltenwort 9f8bd2c
Remove unused import
weltenwort 37260d9
Merge branch 'master' into logs-ui-cancel-log-entry-request
weltenwort de45829
Remove unused code
weltenwort 218a3c4
Start adding mdx docs
weltenwort 7fac8bc
Extend documentation
weltenwort c1e3974
Merge branch 'master' into logs-ui-cancel-log-entry-request
weltenwort b68def7
Merge branch 'master' into logs-ui-cancel-log-entry-request
weltenwort de25acc
Make `onCloseFlyout` prop required
weltenwort e338a64
Merge branch 'master' into logs-ui-cancel-log-entry-request
weltenwort a124a50
Use the "generic" error case as the fallback
weltenwort 4acb795
Render field table actions in separate column
weltenwort 8f62d8c
Factor our request factory type as per review feedback
weltenwort acf0ceb
Split utility hooks into several files
weltenwort f54b1f9
Remove unused imports
weltenwort 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
25 changes: 25 additions & 0 deletions
25
x-pack/plugins/infra/public/components/centered_flyout_body.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,25 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { EuiFlyoutBody } from '@elastic/eui'; | ||
| import { euiStyled } from '../../../observability/public'; | ||
|
|
||
| export const CenteredEuiFlyoutBody = euiStyled(EuiFlyoutBody)` | ||
| & .euiFlyoutBody__overflow { | ||
| display: flex; | ||
| flex-direction: column; | ||
| } | ||
|
|
||
| & .euiFlyoutBody__overflowContent { | ||
| align-items: center; | ||
| align-self: stretch; | ||
| display: flex; | ||
| flex-direction: column; | ||
| flex-grow: 1; | ||
| justify-content: center; | ||
| overflow: hidden; | ||
| } | ||
| `; |
86 changes: 86 additions & 0 deletions
86
x-pack/plugins/infra/public/components/data_search_error_callout.stories.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,86 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { PropsOf } from '@elastic/eui'; | ||
| import { Meta, Story } from '@storybook/react/types-6-0'; | ||
| import React from 'react'; | ||
| import { EuiThemeProvider } from '../../../observability/public'; | ||
| import { DataSearchErrorCallout } from './data_search_error_callout'; | ||
|
|
||
| export default { | ||
| title: 'infra/dataSearch/DataSearchErrorCallout', | ||
| decorators: [ | ||
| (wrappedStory) => ( | ||
| <EuiThemeProvider> | ||
| <div style={{ width: 600 }}>{wrappedStory()}</div> | ||
| </EuiThemeProvider> | ||
| ), | ||
| ], | ||
| parameters: { | ||
| layout: 'padded', | ||
| }, | ||
| argTypes: { | ||
| errors: { | ||
| control: { | ||
| type: 'object', | ||
| }, | ||
| }, | ||
| }, | ||
| } as Meta; | ||
|
|
||
| type DataSearchErrorCalloutProps = PropsOf<typeof DataSearchErrorCallout>; | ||
|
|
||
| const DataSearchErrorCalloutTemplate: Story<DataSearchErrorCalloutProps> = (args) => ( | ||
| <DataSearchErrorCallout {...args} /> | ||
| ); | ||
|
|
||
| const commonArgs = { | ||
| title: 'Failed to load data', | ||
| errors: [ | ||
| { | ||
| type: 'generic' as const, | ||
| message: 'A generic error message', | ||
| }, | ||
| { | ||
| type: 'shardFailure' as const, | ||
| shardInfo: { | ||
| index: 'filebeat-7.9.3-2020.12.01-000003', | ||
| node: 'a45hJUm3Tba4U8MkvkCU_g', | ||
| shard: 0, | ||
| }, | ||
| message: 'No mapping found for [@timestamp] in order to sort on', | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| export const ErrorCallout = DataSearchErrorCalloutTemplate.bind({}); | ||
|
|
||
| ErrorCallout.args = { | ||
| ...commonArgs, | ||
| }; | ||
|
|
||
| export const ErrorCalloutWithRetry = DataSearchErrorCalloutTemplate.bind({}); | ||
|
|
||
| ErrorCalloutWithRetry.args = { | ||
| ...commonArgs, | ||
| }; | ||
| ErrorCalloutWithRetry.argTypes = { | ||
| onRetry: { action: 'retrying' }, | ||
| }; | ||
|
|
||
| export const AbortedErrorCallout = DataSearchErrorCalloutTemplate.bind({}); | ||
|
|
||
| AbortedErrorCallout.args = { | ||
| ...commonArgs, | ||
| errors: [ | ||
| { | ||
| type: 'aborted', | ||
| }, | ||
| ], | ||
| }; | ||
| AbortedErrorCallout.argTypes = { | ||
| onRetry: { action: 'retrying' }, | ||
| }; |
78 changes: 78 additions & 0 deletions
78
x-pack/plugins/infra/public/components/data_search_error_callout.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,78 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { EuiButton, EuiCallOut } from '@elastic/eui'; | ||
| import { FormattedMessage } from '@kbn/i18n/react'; | ||
| import React from 'react'; | ||
| import { | ||
| AbortedRequestSearchStrategyError, | ||
| GenericSearchStrategyError, | ||
| SearchStrategyError, | ||
| ShardFailureSearchStrategyError, | ||
| } from '../../common/search_strategies/common/errors'; | ||
|
|
||
| export const DataSearchErrorCallout: React.FC<{ | ||
| title: React.ReactNode; | ||
| errors: SearchStrategyError[]; | ||
| onRetry?: () => void; | ||
| }> = ({ errors, onRetry, title }) => { | ||
| const calloutColor = errors.some((error) => error.type !== 'aborted') ? 'danger' : 'warning'; | ||
|
|
||
| return ( | ||
| <EuiCallOut color={calloutColor} iconType="alert" title={title}> | ||
| {errors?.map((error, errorIndex) => ( | ||
| <DataSearchErrorMessage key={errorIndex} error={error} /> | ||
| ))} | ||
| {onRetry ? ( | ||
| <EuiButton color={calloutColor} size="s" onClick={onRetry}> | ||
| <FormattedMessage | ||
| id="xpack.infra.dataSearch.loadingErrorRetryButtonLabel" | ||
| defaultMessage="Retry" | ||
| /> | ||
| </EuiButton> | ||
| ) : null} | ||
| </EuiCallOut> | ||
| ); | ||
| }; | ||
|
|
||
| const DataSearchErrorMessage: React.FC<{ error: SearchStrategyError }> = ({ error }) => { | ||
| if (error.type === 'aborted') { | ||
| return <AbortedRequestErrorMessage error={error} />; | ||
| } else if (error.type === 'generic') { | ||
| return <GenericErrorMessage error={error} />; | ||
| } else if (error.type === 'shardFailure') { | ||
| return <ShardFailureErrorMessage error={error} />; | ||
| } | ||
| return <p>{`${error}`}</p>; | ||
| }; | ||
|
|
||
| const AbortedRequestErrorMessage: React.FC<{ | ||
| error?: AbortedRequestSearchStrategyError; | ||
| }> = ({}) => ( | ||
| <FormattedMessage | ||
| tagName="p" | ||
| id="xpack.infra.dataSearch.abortedRequestErrorMessage" | ||
| defaultMessage="The request was aborted." | ||
| /> | ||
| ); | ||
|
|
||
| const GenericErrorMessage: React.FC<{ error: GenericSearchStrategyError }> = ({ error }) => ( | ||
| <p>{error.message}</p> | ||
| ); | ||
|
|
||
| const ShardFailureErrorMessage: React.FC<{ error: ShardFailureSearchStrategyError }> = ({ | ||
| error, | ||
| }) => ( | ||
| <FormattedMessage | ||
| tagName="p" | ||
| id="xpack.infra.dataSearch.shardFailureErrorMessage" | ||
| defaultMessage="Index {indexName}: {errorMessage}" | ||
| values={{ | ||
| indexName: error.shardInfo.index, | ||
| errorMessage: error.message, | ||
| }} | ||
| /> | ||
| ); | ||
52 changes: 52 additions & 0 deletions
52
x-pack/plugins/infra/public/components/data_search_progress.stories.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,52 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { PropsOf } from '@elastic/eui'; | ||
| import { Meta, Story } from '@storybook/react/types-6-0'; | ||
| import React from 'react'; | ||
| import { EuiThemeProvider } from '../../../observability/public'; | ||
| import { DataSearchProgress } from './data_search_progress'; | ||
|
|
||
| export default { | ||
| title: 'infra/dataSearch/DataSearchProgress', | ||
| decorators: [ | ||
| (wrappedStory) => ( | ||
| <EuiThemeProvider> | ||
| <div style={{ width: 400 }}>{wrappedStory()}</div> | ||
| </EuiThemeProvider> | ||
| ), | ||
| ], | ||
| parameters: { | ||
| layout: 'padded', | ||
| }, | ||
| } as Meta; | ||
|
|
||
| type DataSearchProgressProps = PropsOf<typeof DataSearchProgress>; | ||
|
|
||
| const DataSearchProgressTemplate: Story<DataSearchProgressProps> = (args) => ( | ||
| <DataSearchProgress {...args} /> | ||
| ); | ||
|
|
||
| export const UndeterminedProgress = DataSearchProgressTemplate.bind({}); | ||
|
|
||
| export const DeterminedProgress = DataSearchProgressTemplate.bind({}); | ||
|
|
||
| DeterminedProgress.args = { | ||
| label: 'Searching', | ||
| maxValue: 10, | ||
| value: 3, | ||
| }; | ||
|
|
||
| export const CancelableDeterminedProgress = DataSearchProgressTemplate.bind({}); | ||
|
|
||
| CancelableDeterminedProgress.args = { | ||
| label: 'Searching', | ||
| maxValue: 10, | ||
| value: 3, | ||
| }; | ||
| CancelableDeterminedProgress.argTypes = { | ||
| onCancel: { action: 'canceled' }, | ||
| }; |
45 changes: 45 additions & 0 deletions
45
x-pack/plugins/infra/public/components/data_search_progress.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,45 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { EuiButtonIcon, EuiFlexGroup, EuiFlexItem, EuiProgress } from '@elastic/eui'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import React, { useMemo } from 'react'; | ||
|
|
||
| export const DataSearchProgress: React.FC<{ | ||
| label?: React.ReactNode; | ||
| maxValue?: number; | ||
| onCancel?: () => void; | ||
| value?: number; | ||
| }> = ({ label, maxValue, onCancel, value }) => { | ||
| const valueText = useMemo( | ||
| () => | ||
| Number.isFinite(maxValue) && Number.isFinite(value) ? `${value} / ${maxValue}` : undefined, | ||
| [value, maxValue] | ||
| ); | ||
|
|
||
| return ( | ||
| <EuiFlexGroup alignItems="center"> | ||
| <EuiFlexItem> | ||
| <EuiProgress label={label} size="s" max={maxValue} value={value} valueText={valueText} /> | ||
| </EuiFlexItem> | ||
| {onCancel ? ( | ||
| <EuiFlexItem grow={false}> | ||
| <EuiButtonIcon | ||
| color="danger" | ||
| iconType="cross" | ||
| onClick={onCancel} | ||
| title={cancelButtonLabel} | ||
| aria-label={cancelButtonLabel} | ||
| /> | ||
| </EuiFlexItem> | ||
| ) : null} | ||
| </EuiFlexGroup> | ||
| ); | ||
| }; | ||
|
|
||
| const cancelButtonLabel = i18n.translate('xpack.infra.dataSearch.cancelButtonLabel', { | ||
| defaultMessage: 'Cancel request', | ||
| }); |
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.