From e97f27a222305b82087555dab8e91ca0f04b02de Mon Sep 17 00:00:00 2001 From: nreese Date: Mon, 23 Oct 2023 13:48:49 -0600 Subject: [PATCH 01/53] Update incomplete data messaging --- .../kbn-search-response-warnings/index.ts | 1 + .../i18n_utils.test.ts | 136 ++++++++++++++++++ .../search_response_warnings/i18n_utils.ts | 59 ++++++++ .../search_response_warnings/index.ts | 2 + .../search_response_warnings_callout.tsx | 64 +++++++++ .../view_details_popover.tsx | 76 ++++++++++ .../src/extract_warnings.ts | 1 + .../kbn-search-response-warnings/src/types.ts | 4 + .../components/layout/discover_documents.tsx | 15 +- 9 files changed, 350 insertions(+), 8 deletions(-) create mode 100644 packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts create mode 100644 packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts create mode 100644 packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx create mode 100644 packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx diff --git a/packages/kbn-search-response-warnings/index.ts b/packages/kbn-search-response-warnings/index.ts index 413e8594bd839..cd8ce556a2435 100644 --- a/packages/kbn-search-response-warnings/index.ts +++ b/packages/kbn-search-response-warnings/index.ts @@ -11,6 +11,7 @@ export type { SearchResponseWarning, WarningHandlerCallback } from './src/types' export { SearchResponseWarnings, type SearchResponseWarningsProps, + SearchResponseWarningsCallout, } from './src/components/search_response_warnings'; export { ViewWarningButton } from './src/components/view_warning_button'; diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts new file mode 100644 index 0000000000000..dcf29d5453829 --- /dev/null +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts @@ -0,0 +1,136 @@ +/* + * 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 { getWarningsTitle, getWarningsDescription } from './i18n_utils'; + +describe('getWarningsTitle', () => { + test('Should show title for single non-successful cluster', () => { + const warnings = [ + { + type: 'incomplete', + clusters: { + 'remote1': { + status: 'partial', + indices: '', + timed_out: false, + }, + }, + openInInspector: () => {}, + }, + ]; + expect(getWarningsTitle(warnings)).toEqual('Problem with 1 cluster'); + }); + + test('Should show title for multiple non-successful cluster', () => { + const warnings = [ + { + type: 'incomplete', + clusters: { + 'remote1': { + status: 'partial', + indices: '', + timed_out: false, + }, + 'remote2': { + status: 'skipped', + indices: '', + timed_out: false, + }, + }, + openInInspector: () => {}, + }, + ]; + expect(getWarningsTitle(warnings)).toEqual('Problem with 2 clusters'); + }); + + test('Should show title for multiple requests', () => { + const warnings = [ + { + type: 'incomplete', + clusters: { + 'remote1': { + status: 'partial', + indices: '', + timed_out: false, + }, + }, + openInInspector: () => {}, + }, + { + type: 'incomplete', + clusters: { + 'remote1': { + status: 'partial', + indices: '', + timed_out: false, + }, + }, + openInInspector: () => {}, + }, + ]; + expect(getWarningsTitle(warnings)).toEqual('Problem with 1 cluster in 2 requests'); + }); +}); + +describe('getWarningsDescription', () => { + test('Should show description for single non-successful cluster', () => { + const warnings = [ + { + type: 'incomplete', + clusters: { + 'remote1': { + status: 'partial', + indices: '', + timed_out: false, + }, + }, + openInInspector: () => {}, + }, + ]; + expect(getWarningsDescription(warnings)).toEqual('This cluster had issues returning results. This might result in an incomplete visualization.'); + }); + + test('Should show description for multiple non-successful cluster', () => { + const warnings = [ + { + type: 'incomplete', + clusters: { + 'remote1': { + status: 'partial', + indices: '', + timed_out: false, + }, + 'remote2': { + status: 'skipped', + indices: '', + timed_out: false, + }, + }, + openInInspector: () => {}, + }, + ]; + expect(getWarningsDescription(warnings)).toEqual('These clusters had issues returning results. This might result in an incomplete visualization.'); + }); + + test('Should show custom visualization label', () => { + const warnings = [ + { + type: 'incomplete', + clusters: { + 'remote1': { + status: 'partial', + indices: '', + timed_out: false, + }, + }, + openInInspector: () => {}, + }, + ]; + expect(getWarningsDescription(warnings, 'table')).toEqual('This cluster had issues returning results. This might result in an incomplete table.'); + }); +}); \ No newline at end of file diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts new file mode 100644 index 0000000000000..62f21dc3d1158 --- /dev/null +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts @@ -0,0 +1,59 @@ +/* + * 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 { i18n } from '@kbn/i18n'; + +export const viewDetailsLabel = i18n.translate('searchResponseWarnings.viewDetailsButtonLabel', { + defaultMessage: 'View details', + description: "View warning details button label" +}); + +function getNonSuccessfulClusters(warnings: SearchResponseWarning[]) { + const nonSuccessfulClusters = new Set(); + warnings.forEach(warning => { + Object.keys(warning.clusters).forEach(clusterName => { + if (warning.clusters[clusterName].status !== 'successful') { + nonSuccessfulClusters.add(clusterName); + } + }); + }); + return nonSuccessfulClusters; +} + +export function getWarningsTitle(warnings: SearchResponseWarning[]) { + const nonSuccessfulClusters = getNonSuccessfulClusters(warnings); + const clustersClause = i18n.translate('searchResponseWarnings.title.clustersClause', { + defaultMessage: 'Problem with {nonSuccessfulClustersCount} {nonSuccessfulClustersCount, plural, one {cluster} other {clusters}}', + values: { nonSuccessfulClustersCount: nonSuccessfulClusters.size } + }); + + return warnings.length <= 1 + ? clustersClause + : i18n.translate('searchResponseWarnings.title.ClustersClauseAndRequestsClause', { + defaultMessage: '{clustersClause} in {requestsCount} requests', + values: { + clustersClause, + requestsCount: warnings.length, + } + }) +} + +export function getWarningsDescription(warnings: SearchResponseWarning[], visualizationLabel?: string) { + const nonSuccessfulClusters = getNonSuccessfulClusters(warnings); + return i18n.translate('searchResponseWarnings.description', { + defaultMessage: '{nonSuccessfulClustersCount, plural, one {This cluster} other {These clusters}} had issues returning results. This might result in an incomplete {visualizationLabel}.', + values: { + nonSuccessfulClustersCount: nonSuccessfulClusters.size, + visualizationLabel: visualizationLabel + ? visualizationLabel + : i18n.translate('searchResponseWarnings.description.defaultVisualizationLabel', { + defaultMessage: 'visualization', + }), + } + }); +} \ No newline at end of file diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts index 8a3ed6d05600e..1474c6be5d6a2 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts @@ -10,3 +10,5 @@ export { SearchResponseWarnings, type SearchResponseWarningsProps, } from './search_response_warnings'; + +export { SearchResponseWarningsCallout } from './search_response_warnings_callout'; diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx new file mode 100644 index 0000000000000..2c0d4a91d6d3f --- /dev/null +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx @@ -0,0 +1,64 @@ +/* + * 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 { + EuiCallOut, + EuiText, + EuiFlexGroup, + EuiFlexItem, +} from '@elastic/eui'; +import { css } from '@emotion/react'; +import { ViewDetailsPopover } from './view_details_popover'; +import { getWarningsDescription, getWarningsTitle } from './i18n_utils'; +import type { SearchResponseWarning } from '../../types'; + +interface Props { + visualizationLabel?; string; + warnings: SearchResponseWarning[]; +} + +export const SearchResponseWarningsCallout = (props: Props) => { + if (!props.warnings.length) { + return null; + } + + return ( + + + + {getWarningsTitle(props.warnings)} + + + + +

{getWarningsDescription(props.warnings, props.visualizationLabel)}

+
+
+ + + + + } + color="warning" + iconType="warning" + size="s" + css={css` + .euiTitle { + display: flex; + align-items: center; + } + `} + data-test-subj="searchResponseWarningsCallout" + /> + ); +}; \ No newline at end of file diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx new file mode 100644 index 0000000000000..25516d69aff1d --- /dev/null +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx @@ -0,0 +1,76 @@ +/* + * 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, { useState } from 'react'; +import { + EuiButtonEmpty, + EuiContextMenu, + EuiContextMenuPanelDescriptor, + EuiPopover, +} from '@elastic/eui'; +import { viewDetailsLabel } from './i18n_utils'; +import type { SearchResponseWarning } from '../../types'; + +interface Props { + warnings: SearchResponseWarning[]; +} + +export const ViewDetailsPopover = (props: Props) => { + const [isPopoverOpen, setIsPopoverOpen] = useState(false); + + if (!props.warnings.length) { + return null; + } + + if (props.warnings.length === 1) { + return ( + + {viewDetailsLabel} + + ); + } + + const panels: EuiContextMenuPanelDescriptor[] = [ + { + id: 0, + items: props.warnings.map((warning) => { + return { + name: warning.requestName, + onClick: () => { warning.openInInspector(); }, + }; + }), + }, + ]; + + return ( + setIsPopoverOpen(true)} + > + {viewDetailsLabel} + + } + isOpen={isPopoverOpen} + closePopover={() => setIsPopoverOpen(false)} + panelPaddingSize="none" + anchorPosition="downCenter" + > + + + ); +}; \ No newline at end of file diff --git a/packages/kbn-search-response-warnings/src/extract_warnings.ts b/packages/kbn-search-response-warnings/src/extract_warnings.ts index 2bab91525609b..d6ada1998c4cd 100644 --- a/packages/kbn-search-response-warnings/src/extract_warnings.ts +++ b/packages/kbn-search-response-warnings/src/extract_warnings.ts @@ -35,6 +35,7 @@ export function extractWarnings( if (isPartial) { warnings.push({ type: 'incomplete', + requestName: 'my request', message: i18n.translate('searchResponseWarnings.incompleteResultsMessage', { defaultMessage: 'Results are partial and may be incomplete.', }), diff --git a/packages/kbn-search-response-warnings/src/types.ts b/packages/kbn-search-response-warnings/src/types.ts index d7df71b40d71d..52460fdbdf9fb 100644 --- a/packages/kbn-search-response-warnings/src/types.ts +++ b/packages/kbn-search-response-warnings/src/types.ts @@ -28,6 +28,10 @@ export interface SearchResponseIncompleteWarning { * message: human-friendly message */ message: string; + /** + * requestName: human-friendly request name + */ + requestName: string; /** * clusters: cluster details. */ diff --git a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx index 774d47d577a6d..4803f1145ef1c 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx @@ -20,7 +20,7 @@ import { DataView } from '@kbn/data-views-plugin/public'; import { SortOrder } from '@kbn/saved-search-plugin/public'; import { CellActionsProvider } from '@kbn/cell-actions'; import type { DataTableRecord } from '@kbn/discover-utils/types'; -import { SearchResponseWarnings } from '@kbn/search-response-warnings'; +import { SearchResponseWarningsCallout } from '@kbn/search-response-warnings'; import { DataLoadingState, useColumns, @@ -277,13 +277,12 @@ function DiscoverDocumentsComponent({ textBasedQueryColumns={documents?.textBasedQueryColumns} selectedColumns={currentColumns} /> - {!!documentState.interceptedWarnings?.length && ( - - )} + ), [ From 3fe0b3ca07affb7ea4d4e62c060722a3f38c0b7e Mon Sep 17 00:00:00 2001 From: nreese Date: Mon, 23 Oct 2023 14:21:04 -0600 Subject: [PATCH 02/53] fix console log errors by having div elements in callout title --- .../search_response_warnings/i18n_utils.ts | 2 +- .../search_response_warnings_callout.tsx | 39 +++++++------------ .../view_details_popover.tsx | 19 +++++---- .../context/context_app_content.tsx | 16 ++++---- 4 files changed, 34 insertions(+), 42 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts index 62f21dc3d1158..6a4834e1789f1 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts @@ -34,7 +34,7 @@ export function getWarningsTitle(warnings: SearchResponseWarning[]) { return warnings.length <= 1 ? clustersClause - : i18n.translate('searchResponseWarnings.title.ClustersClauseAndRequestsClause', { + : i18n.translate('searchResponseWarnings.title.clustersClauseAndRequestsClause', { defaultMessage: '{clustersClause} in {requestsCount} requests', values: { clustersClause, diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx index 2c0d4a91d6d3f..90b9d440c7b50 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx @@ -30,35 +30,22 @@ export const SearchResponseWarningsCallout = (props: Props) => { return ( - - - {getWarningsTitle(props.warnings)} - - - - -

{getWarningsDescription(props.warnings, props.visualizationLabel)}

-
-
- - - - - } + title={getWarningsTitle(props.warnings)} color="warning" iconType="warning" size="s" - css={css` - .euiTitle { - display: flex; - align-items: center; - } - `} data-test-subj="searchResponseWarningsCallout" - /> + > + + + {getWarningsDescription(props.warnings, props.visualizationLabel)} + + + + + +
); }; \ No newline at end of file diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx index 25516d69aff1d..5581f7187e733 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx @@ -8,7 +8,8 @@ import React, { useState } from 'react'; import { - EuiButtonEmpty, + EuiIcon, + EuiLink, EuiContextMenu, EuiContextMenuPanelDescriptor, EuiPopover, @@ -29,13 +30,13 @@ export const ViewDetailsPopover = (props: Props) => { if (props.warnings.length === 1) { return ( - {viewDetailsLabel} - + ); } @@ -55,15 +56,17 @@ export const ViewDetailsPopover = (props: Props) => { setIsPopoverOpen(true)} > - {viewDetailsLabel} - + <> + {viewDetailsLabel} + {' '} + + + } isOpen={isPopoverOpen} closePopover={() => setIsPopoverOpen(false)} diff --git a/src/plugins/discover/public/application/context/context_app_content.tsx b/src/plugins/discover/public/application/context/context_app_content.tsx index e1ccf1606d07e..7ec3d855db09e 100644 --- a/src/plugins/discover/public/application/context/context_app_content.tsx +++ b/src/plugins/discover/public/application/context/context_app_content.tsx @@ -7,6 +7,7 @@ */ import React, { Fragment, useCallback, useMemo, useState } from 'react'; +import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { EuiSpacer, EuiText, useEuiPaddingSize } from '@elastic/eui'; import { css } from '@emotion/react'; @@ -15,7 +16,7 @@ import { SortDirection } from '@kbn/data-plugin/public'; import type { SortOrder } from '@kbn/saved-search-plugin/public'; import { CellActionsProvider } from '@kbn/cell-actions'; import type { DataTableRecord } from '@kbn/discover-utils/types'; -import { type SearchResponseWarning, SearchResponseWarnings } from '@kbn/search-response-warnings'; +import { type SearchResponseWarning, SearchResponseWarningsCallout } from '@kbn/search-response-warnings'; import { CONTEXT_STEP_SETTING, DOC_HIDE_TIME_COLUMN_SETTING, @@ -50,7 +51,7 @@ export interface ContextAppContentProps { anchorStatus: LoadingStatus; predecessorsStatus: LoadingStatus; successorsStatus: LoadingStatus; - interceptedWarnings: SearchResponseWarning[] | undefined; + interceptedWarnings: SearchResponseWarning[]; useNewFieldsApi: boolean; isLegacy: boolean; setAppState: (newState: Partial) => void; @@ -148,12 +149,13 @@ export function ContextAppContent({ return ( - {!!interceptedWarnings?.length && ( + {interceptedWarnings.length && ( <> - From 1c480e9b744676d52112a557bdc24abb35f33834 Mon Sep 17 00:00:00 2001 From: nreese Date: Mon, 23 Oct 2023 14:23:52 -0600 Subject: [PATCH 03/53] replace first 'results' with 'data' --- .../components/search_response_warnings/i18n_utils.test.ts | 6 +++--- .../src/components/search_response_warnings/i18n_utils.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts index dcf29d5453829..41ad6e671e456 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts @@ -92,7 +92,7 @@ describe('getWarningsDescription', () => { openInInspector: () => {}, }, ]; - expect(getWarningsDescription(warnings)).toEqual('This cluster had issues returning results. This might result in an incomplete visualization.'); + expect(getWarningsDescription(warnings)).toEqual('This cluster had issues returning data. This might result in an incomplete visualization.'); }); test('Should show description for multiple non-successful cluster', () => { @@ -114,7 +114,7 @@ describe('getWarningsDescription', () => { openInInspector: () => {}, }, ]; - expect(getWarningsDescription(warnings)).toEqual('These clusters had issues returning results. This might result in an incomplete visualization.'); + expect(getWarningsDescription(warnings)).toEqual('These clusters had issues returning data. This might result in an incomplete visualization.'); }); test('Should show custom visualization label', () => { @@ -131,6 +131,6 @@ describe('getWarningsDescription', () => { openInInspector: () => {}, }, ]; - expect(getWarningsDescription(warnings, 'table')).toEqual('This cluster had issues returning results. This might result in an incomplete table.'); + expect(getWarningsDescription(warnings, 'table')).toEqual('This cluster had issues returning data. This might result in an incomplete table.'); }); }); \ No newline at end of file diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts index 6a4834e1789f1..5ea1a5fc65842 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts @@ -46,7 +46,7 @@ export function getWarningsTitle(warnings: SearchResponseWarning[]) { export function getWarningsDescription(warnings: SearchResponseWarning[], visualizationLabel?: string) { const nonSuccessfulClusters = getNonSuccessfulClusters(warnings); return i18n.translate('searchResponseWarnings.description', { - defaultMessage: '{nonSuccessfulClustersCount, plural, one {This cluster} other {These clusters}} had issues returning results. This might result in an incomplete {visualizationLabel}.', + defaultMessage: '{nonSuccessfulClustersCount, plural, one {This cluster} other {These clusters}} had issues returning data. This might result in an incomplete {visualizationLabel}.', values: { nonSuccessfulClustersCount: nonSuccessfulClusters.size, visualizationLabel: visualizationLabel From e07554c95d4bcaa1aa21f3a381767e37782a0a59 Mon Sep 17 00:00:00 2001 From: nreese Date: Mon, 23 Oct 2023 14:26:31 -0600 Subject: [PATCH 04/53] toggle popover on button click --- .../search_response_warnings/view_details_popover.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx index 5581f7187e733..841ef5b17f5ac 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx @@ -59,7 +59,7 @@ export const ViewDetailsPopover = (props: Props) => { setIsPopoverOpen(true)} + onClick={() => setIsPopoverOpen(!isPopoverOpen)} > <> {viewDetailsLabel} From b0d03408e3c362296e4e6d3bb4698f15736e0f87 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 23 Oct 2023 20:34:30 +0000 Subject: [PATCH 05/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../view_details_popover.tsx | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx index 841ef5b17f5ac..5a913b51c04cf 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx @@ -30,11 +30,7 @@ export const ViewDetailsPopover = (props: Props) => { if (props.warnings.length === 1) { return ( - + {viewDetailsLabel} ); @@ -46,7 +42,9 @@ export const ViewDetailsPopover = (props: Props) => { items: props.warnings.map((warning) => { return { name: warning.requestName, - onClick: () => { warning.openInInspector(); }, + onClick: () => { + warning.openInInspector(); + }, }; }), }, @@ -56,15 +54,9 @@ export const ViewDetailsPopover = (props: Props) => { setIsPopoverOpen(!isPopoverOpen)} - > + setIsPopoverOpen(!isPopoverOpen)}> <> - {viewDetailsLabel} - {' '} - + {viewDetailsLabel} } @@ -76,4 +68,4 @@ export const ViewDetailsPopover = (props: Props) => { ); -}; \ No newline at end of file +}; From 67a6ae5ee21e28188e2bcb2979bb70d5d93a8af0 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 23 Oct 2023 21:10:45 +0000 Subject: [PATCH 06/53] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../i18n_utils.test.ts | 32 +++++++++++-------- .../search_response_warnings/i18n_utils.ts | 29 ++++++++++------- .../search_response_warnings_callout.tsx | 17 +++------- .../context/context_app_content.tsx | 5 ++- 4 files changed, 45 insertions(+), 38 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts index 41ad6e671e456..0bf748408904d 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts @@ -14,7 +14,7 @@ describe('getWarningsTitle', () => { { type: 'incomplete', clusters: { - 'remote1': { + remote1: { status: 'partial', indices: '', timed_out: false, @@ -31,12 +31,12 @@ describe('getWarningsTitle', () => { { type: 'incomplete', clusters: { - 'remote1': { + remote1: { status: 'partial', indices: '', timed_out: false, }, - 'remote2': { + remote2: { status: 'skipped', indices: '', timed_out: false, @@ -53,7 +53,7 @@ describe('getWarningsTitle', () => { { type: 'incomplete', clusters: { - 'remote1': { + remote1: { status: 'partial', indices: '', timed_out: false, @@ -64,7 +64,7 @@ describe('getWarningsTitle', () => { { type: 'incomplete', clusters: { - 'remote1': { + remote1: { status: 'partial', indices: '', timed_out: false, @@ -83,7 +83,7 @@ describe('getWarningsDescription', () => { { type: 'incomplete', clusters: { - 'remote1': { + remote1: { status: 'partial', indices: '', timed_out: false, @@ -92,7 +92,9 @@ describe('getWarningsDescription', () => { openInInspector: () => {}, }, ]; - expect(getWarningsDescription(warnings)).toEqual('This cluster had issues returning data. This might result in an incomplete visualization.'); + expect(getWarningsDescription(warnings)).toEqual( + 'This cluster had issues returning data. This might result in an incomplete visualization.' + ); }); test('Should show description for multiple non-successful cluster', () => { @@ -100,12 +102,12 @@ describe('getWarningsDescription', () => { { type: 'incomplete', clusters: { - 'remote1': { + remote1: { status: 'partial', indices: '', timed_out: false, }, - 'remote2': { + remote2: { status: 'skipped', indices: '', timed_out: false, @@ -114,7 +116,9 @@ describe('getWarningsDescription', () => { openInInspector: () => {}, }, ]; - expect(getWarningsDescription(warnings)).toEqual('These clusters had issues returning data. This might result in an incomplete visualization.'); + expect(getWarningsDescription(warnings)).toEqual( + 'These clusters had issues returning data. This might result in an incomplete visualization.' + ); }); test('Should show custom visualization label', () => { @@ -122,7 +126,7 @@ describe('getWarningsDescription', () => { { type: 'incomplete', clusters: { - 'remote1': { + remote1: { status: 'partial', indices: '', timed_out: false, @@ -131,6 +135,8 @@ describe('getWarningsDescription', () => { openInInspector: () => {}, }, ]; - expect(getWarningsDescription(warnings, 'table')).toEqual('This cluster had issues returning data. This might result in an incomplete table.'); + expect(getWarningsDescription(warnings, 'table')).toEqual( + 'This cluster had issues returning data. This might result in an incomplete table.' + ); }); -}); \ No newline at end of file +}); diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts index 5ea1a5fc65842..af7db8deb7d02 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts @@ -10,13 +10,13 @@ import { i18n } from '@kbn/i18n'; export const viewDetailsLabel = i18n.translate('searchResponseWarnings.viewDetailsButtonLabel', { defaultMessage: 'View details', - description: "View warning details button label" + description: 'View warning details button label', }); function getNonSuccessfulClusters(warnings: SearchResponseWarning[]) { const nonSuccessfulClusters = new Set(); - warnings.forEach(warning => { - Object.keys(warning.clusters).forEach(clusterName => { + warnings.forEach((warning) => { + Object.keys(warning.clusters).forEach((clusterName) => { if (warning.clusters[clusterName].status !== 'successful') { nonSuccessfulClusters.add(clusterName); } @@ -28,8 +28,9 @@ function getNonSuccessfulClusters(warnings: SearchResponseWarning[]) { export function getWarningsTitle(warnings: SearchResponseWarning[]) { const nonSuccessfulClusters = getNonSuccessfulClusters(warnings); const clustersClause = i18n.translate('searchResponseWarnings.title.clustersClause', { - defaultMessage: 'Problem with {nonSuccessfulClustersCount} {nonSuccessfulClustersCount, plural, one {cluster} other {clusters}}', - values: { nonSuccessfulClustersCount: nonSuccessfulClusters.size } + defaultMessage: + 'Problem with {nonSuccessfulClustersCount} {nonSuccessfulClustersCount, plural, one {cluster} other {clusters}}', + values: { nonSuccessfulClustersCount: nonSuccessfulClusters.size }, }); return warnings.length <= 1 @@ -39,21 +40,25 @@ export function getWarningsTitle(warnings: SearchResponseWarning[]) { values: { clustersClause, requestsCount: warnings.length, - } - }) + }, + }); } -export function getWarningsDescription(warnings: SearchResponseWarning[], visualizationLabel?: string) { +export function getWarningsDescription( + warnings: SearchResponseWarning[], + visualizationLabel?: string +) { const nonSuccessfulClusters = getNonSuccessfulClusters(warnings); return i18n.translate('searchResponseWarnings.description', { - defaultMessage: '{nonSuccessfulClustersCount, plural, one {This cluster} other {These clusters}} had issues returning data. This might result in an incomplete {visualizationLabel}.', - values: { + defaultMessage: + '{nonSuccessfulClustersCount, plural, one {This cluster} other {These clusters}} had issues returning data. This might result in an incomplete {visualizationLabel}.', + values: { nonSuccessfulClustersCount: nonSuccessfulClusters.size, visualizationLabel: visualizationLabel ? visualizationLabel : i18n.translate('searchResponseWarnings.description.defaultVisualizationLabel', { defaultMessage: 'visualization', }), - } + }, }); -} \ No newline at end of file +} diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx index 90b9d440c7b50..4ec17fc8b02d4 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx @@ -7,19 +7,14 @@ */ import React from 'react'; -import { - EuiCallOut, - EuiText, - EuiFlexGroup, - EuiFlexItem, -} from '@elastic/eui'; -import { css } from '@emotion/react'; +import { EuiCallOut, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { ViewDetailsPopover } from './view_details_popover'; import { getWarningsDescription, getWarningsTitle } from './i18n_utils'; import type { SearchResponseWarning } from '../../types'; interface Props { - visualizationLabel?; string; + visualizationLabel?; + string; warnings: SearchResponseWarning[]; } @@ -41,11 +36,9 @@ export const SearchResponseWarningsCallout = (props: Props) => { {getWarningsDescription(props.warnings, props.visualizationLabel)} - +
); -}; \ No newline at end of file +}; diff --git a/src/plugins/discover/public/application/context/context_app_content.tsx b/src/plugins/discover/public/application/context/context_app_content.tsx index 7ec3d855db09e..34a4a92d965f3 100644 --- a/src/plugins/discover/public/application/context/context_app_content.tsx +++ b/src/plugins/discover/public/application/context/context_app_content.tsx @@ -16,7 +16,10 @@ import { SortDirection } from '@kbn/data-plugin/public'; import type { SortOrder } from '@kbn/saved-search-plugin/public'; import { CellActionsProvider } from '@kbn/cell-actions'; import type { DataTableRecord } from '@kbn/discover-utils/types'; -import { type SearchResponseWarning, SearchResponseWarningsCallout } from '@kbn/search-response-warnings'; +import { + type SearchResponseWarning, + SearchResponseWarningsCallout, +} from '@kbn/search-response-warnings'; import { CONTEXT_STEP_SETTING, DOC_HIDE_TIME_COLUMN_SETTING, From 417af987632aee1d0fc1e109db10ebfb5867a7cc Mon Sep 17 00:00:00 2001 From: nreese Date: Mon, 23 Oct 2023 16:37:10 -0600 Subject: [PATCH 07/53] pass request name extractWarnings --- .../search_response_warnings/view_details_popover.tsx | 1 + .../src/extract_warnings.ts | 3 ++- .../src/handle_warnings.tsx | 4 +++- src/plugins/data/public/search/search_service.ts | 11 ++++++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx index 5a913b51c04cf..93009a73f60fd 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx @@ -43,6 +43,7 @@ export const ViewDetailsPopover = (props: Props) => { return { name: warning.requestName, onClick: () => { + setIsPopoverOpen(false); warning.openInInspector(); }, }; diff --git a/packages/kbn-search-response-warnings/src/extract_warnings.ts b/packages/kbn-search-response-warnings/src/extract_warnings.ts index d6ada1998c4cd..a76f9fc8b26bf 100644 --- a/packages/kbn-search-response-warnings/src/extract_warnings.ts +++ b/packages/kbn-search-response-warnings/src/extract_warnings.ts @@ -19,6 +19,7 @@ export function extractWarnings( rawResponse: estypes.SearchResponse, inspectorService: InspectorStartContract, requestAdapter: RequestAdapter, + requestName: string, requestId?: string ): SearchResponseWarning[] { const warnings: SearchResponseWarning[] = []; @@ -35,7 +36,7 @@ export function extractWarnings( if (isPartial) { warnings.push({ type: 'incomplete', - requestName: 'my request', + requestName, message: i18n.translate('searchResponseWarnings.incompleteResultsMessage', { defaultMessage: 'Results are partial and may be incomplete.', }), diff --git a/packages/kbn-search-response-warnings/src/handle_warnings.tsx b/packages/kbn-search-response-warnings/src/handle_warnings.tsx index 343db1c4a789f..3e7a35b88187e 100644 --- a/packages/kbn-search-response-warnings/src/handle_warnings.tsx +++ b/packages/kbn-search-response-warnings/src/handle_warnings.tsx @@ -36,6 +36,7 @@ export function handleWarnings({ callback, request, requestId, + requestName, requestAdapter, response, services, @@ -44,10 +45,11 @@ export function handleWarnings({ request: estypes.SearchRequest; requestAdapter: RequestAdapter; requestId?: string; + requestName: string; response: estypes.SearchResponse; services: Services; }) { - const warnings = extractWarnings(response, services.inspector, requestAdapter, requestId); + const warnings = extractWarnings(response, services.inspector, requestAdapter, requestName, requestId); if (warnings.length === 0) { return; } diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index d70d553ae05c1..27c81bbd36d7b 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -257,14 +257,17 @@ export class SearchService implements Plugin { if (!options.disableWarningToasts) { const { rawResponse } = response; + const requestName = options.inspector?.title + ? options.inspector.title + : i18n.translate('data.searchService.anonymousRequestTitle', { + defaultMessage: 'Request', + }); const requestAdapter = options.inspector?.adapter ? options.inspector?.adapter : new RequestAdapter(); if (!options.inspector?.adapter) { const requestResponder = requestAdapter.start( - i18n.translate('data.searchService.anonymousRequestTitle', { - defaultMessage: 'Request', - }), + requestName, { id: request.id, } @@ -277,6 +280,7 @@ export class SearchService implements Plugin { request: request.body as estypes.SearchRequest, requestAdapter, requestId: request.id, + requestName, response: rawResponse, services: warningsServices, }); @@ -325,6 +329,7 @@ export class SearchService implements Plugin { request: request.json as estypes.SearchRequest, requestAdapter: adapter, requestId: request.id, + requestName: request.name, response: rawResponse, services: warningsServices, }); From 1ab8ac4cb603becb730c376220c807d50f29791b Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 23 Oct 2023 22:43:29 +0000 Subject: [PATCH 08/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../src/handle_warnings.tsx | 8 +++++++- src/plugins/data/public/search/search_service.ts | 11 ++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/handle_warnings.tsx b/packages/kbn-search-response-warnings/src/handle_warnings.tsx index 3e7a35b88187e..7ed1143351915 100644 --- a/packages/kbn-search-response-warnings/src/handle_warnings.tsx +++ b/packages/kbn-search-response-warnings/src/handle_warnings.tsx @@ -49,7 +49,13 @@ export function handleWarnings({ response: estypes.SearchResponse; services: Services; }) { - const warnings = extractWarnings(response, services.inspector, requestAdapter, requestName, requestId); + const warnings = extractWarnings( + response, + services.inspector, + requestAdapter, + requestName, + requestId + ); if (warnings.length === 0) { return; } diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index 27c81bbd36d7b..f336096468606 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -257,7 +257,7 @@ export class SearchService implements Plugin { if (!options.disableWarningToasts) { const { rawResponse } = response; - const requestName = options.inspector?.title + const requestName = options.inspector?.title ? options.inspector.title : i18n.translate('data.searchService.anonymousRequestTitle', { defaultMessage: 'Request', @@ -266,12 +266,9 @@ export class SearchService implements Plugin { ? options.inspector?.adapter : new RequestAdapter(); if (!options.inspector?.adapter) { - const requestResponder = requestAdapter.start( - requestName, - { - id: request.id, - } - ); + const requestResponder = requestAdapter.start(requestName, { + id: request.id, + }); requestResponder.json(request.body); requestResponder.ok({ json: response }); } From 7f9316a2c0514e78dd147ef6908b5aefd443953a Mon Sep 17 00:00:00 2001 From: nreese Date: Tue, 24 Oct 2023 08:17:20 -0600 Subject: [PATCH 09/53] empty_prompt --- .../kbn-search-response-warnings/index.ts | 1 + .../search_response_warnings.test.tsx.snap | 176 ------------------ ...ponse_warnings_callout.tsx => callout.tsx} | 3 +- .../search_response_warnings/empty_prompt.tsx | 51 +++++ .../search_response_warnings/index.ts | 3 +- .../search_response_warnings.test.tsx | 49 ----- .../search_response_warnings.tsx | 103 ---------- .../main/components/no_results/no_results.tsx | 8 +- 8 files changed, 58 insertions(+), 336 deletions(-) delete mode 100644 packages/kbn-search-response-warnings/src/components/search_response_warnings/__snapshots__/search_response_warnings.test.tsx.snap rename packages/kbn-search-response-warnings/src/components/search_response_warnings/{search_response_warnings_callout.tsx => callout.tsx} (97%) create mode 100644 packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx delete mode 100644 packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.test.tsx diff --git a/packages/kbn-search-response-warnings/index.ts b/packages/kbn-search-response-warnings/index.ts index cd8ce556a2435..25ea5c60d5201 100644 --- a/packages/kbn-search-response-warnings/index.ts +++ b/packages/kbn-search-response-warnings/index.ts @@ -12,6 +12,7 @@ export { SearchResponseWarnings, type SearchResponseWarningsProps, SearchResponseWarningsCallout, + SearchResponseWarningsEmptyPrompt, } from './src/components/search_response_warnings'; export { ViewWarningButton } from './src/components/view_warning_button'; diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/__snapshots__/search_response_warnings.test.tsx.snap b/packages/kbn-search-response-warnings/src/components/search_response_warnings/__snapshots__/search_response_warnings.test.tsx.snap deleted file mode 100644 index d12cef130de2d..0000000000000 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/__snapshots__/search_response_warnings.test.tsx.snap +++ /dev/null @@ -1,176 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`SearchResponseWarnings renders "badge" correctly 1`] = ` -
-
- - - -
-
-`; - -exports[`SearchResponseWarnings renders "callout" correctly 1`] = ` -
-
    -
  • -
    -

    -

    -
    -
    -
    -
    -
    - The data might be incomplete or wrong. -
    -
    -
    -
    -
    -
    -
    -
    - -
    -
    -

    -

    -
  • -
-
-`; - -exports[`SearchResponseWarnings renders "empty_prompt" correctly 1`] = ` -
-
-
- -
-
-
-

- No results found -

-
-
-
    -
  • -
    -
    -
    - The data might be incomplete or wrong. -
    -
    -
    - -
    -
    -
  • -
-
-
-
-
-
-`; diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/callout.tsx similarity index 97% rename from packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx rename to packages/kbn-search-response-warnings/src/components/search_response_warnings/callout.tsx index 4ec17fc8b02d4..9c843052ba46a 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings_callout.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/callout.tsx @@ -13,8 +13,7 @@ import { getWarningsDescription, getWarningsTitle } from './i18n_utils'; import type { SearchResponseWarning } from '../../types'; interface Props { - visualizationLabel?; - string; + visualizationLabel?: string; warnings: SearchResponseWarning[]; } diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx new file mode 100644 index 0000000000000..977b96e9e836e --- /dev/null +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx @@ -0,0 +1,51 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { EuiEmptyPrompt, EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui'; +import { ViewDetailsPopover } from './view_details_popover'; +import { getWarningsDescription, getWarningsTitle } from './i18n_utils'; +import type { SearchResponseWarning } from '../../types'; + +interface Props { + warnings: SearchResponseWarning[]; +} + +export const SearchResponseWarningsEmptyPrompt = (props: Props) => { + if (!props.warnings.length) { + return null; + } + + return ( + + {i18n.translate('searchResponseWarnings.noResultsTitle', { + defaultMessage: 'No results found', + })} + + } + body={ + + + {getWarningsTitle(props.warnings)} + +

+ {getWarningsDescription(props.warnings, i18n.translate('searchResponseWarnings.description.pageLabel', { + defaultMessage: 'page', + }))} +

+ +
+ } + /> + ); +}; diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts index 1474c6be5d6a2..dcfbb7e917ff6 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts @@ -11,4 +11,5 @@ export { type SearchResponseWarningsProps, } from './search_response_warnings'; -export { SearchResponseWarningsCallout } from './search_response_warnings_callout'; +export { SearchResponseWarningsCallout } from './callout'; +export { SearchResponseWarningsEmptyPrompt } from './empty_prompt'; diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.test.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.test.tsx deleted file mode 100644 index aa4e4ba163681..0000000000000 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.test.tsx +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 { mountWithIntl } from '@kbn/test-jest-helpers'; -import { SearchResponseWarnings } from './search_response_warnings'; -import { searchResponseIncompleteWarningLocalCluster } from '../../__mocks__/search_response_warnings'; - -const interceptedWarnings = [searchResponseIncompleteWarningLocalCluster]; - -describe('SearchResponseWarnings', () => { - it('renders "callout" correctly', () => { - const component = mountWithIntl( - - ); - expect(component.render()).toMatchSnapshot(); - }); - - it('renders "badge" correctly', () => { - const component = mountWithIntl( - - ); - expect(component.render()).toMatchSnapshot(); - }); - - it('renders "empty_prompt" correctly', () => { - const component = mountWithIntl( - - ); - expect(component.render()).toMatchSnapshot(); - }); -}); diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.tsx index baa45b9c0a93b..cb3cc15b0bfee 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.tsx @@ -62,115 +62,12 @@ export const SearchResponseWarnings = ({ }: SearchResponseWarningsProps) => { const { euiTheme } = useEuiTheme(); const xsFontSize = useEuiFontSize('xs').fontSize; - const [isCalloutVisibleMap, setIsCalloutVisibleMap] = useState>({}); const [isPopoverOpen, setIsPopoverOpen] = useState(false); - useEffect(() => { - setIsCalloutVisibleMap({}); - }, [interceptedWarnings, setIsCalloutVisibleMap]); - if (!interceptedWarnings?.length) { return null; } - if (variant === 'callout') { - return ( -
-
    - {interceptedWarnings.map((warning, index) => { - if (isCalloutVisibleMap[index] === false) { - return null; - } - return ( -
  • - - setIsCalloutVisibleMap((prev) => ({ ...prev, [index]: false })) - } - > - - - } - color="warning" - iconType="warning" - size="s" - css={css` - .euiTitle { - display: flex; - align-items: center; - } - `} - data-test-subj={dataTestSubj} - /> -
  • - ); - })} -
-
- ); - } - - if (variant === 'empty_prompt') { - return ( - - {i18n.translate('searchResponseWarnings.noResultsTitle', { - defaultMessage: 'No results found', - })} - - } - body={ -
    - {interceptedWarnings.map((warning, index) => ( -
  • - -
  • - ))} -
- } - /> - ); - } - if (variant === 'badge') { const warningCount = interceptedWarnings.length; const buttonLabel = i18n.translate('searchResponseWarnings.badgeButtonLabel', { diff --git a/src/plugins/discover/public/application/main/components/no_results/no_results.tsx b/src/plugins/discover/public/application/main/components/no_results/no_results.tsx index 86f73e18ca4d0..c169b363bf9f4 100644 --- a/src/plugins/discover/public/application/main/components/no_results/no_results.tsx +++ b/src/plugins/discover/public/application/main/components/no_results/no_results.tsx @@ -10,7 +10,7 @@ import React from 'react'; import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import type { DataView } from '@kbn/data-views-plugin/common'; import type { AggregateQuery, Filter, Query } from '@kbn/es-query'; -import { SearchResponseWarnings } from '@kbn/search-response-warnings'; +import { SearchResponseWarningsEmptyPrompt } from '@kbn/search-response-warnings'; import { NoResultsSuggestions } from './no_results_suggestions'; import type { DiscoverStateContainer } from '../../services/discover_state'; import { useDataState } from '../../hooks/use_data_state'; @@ -38,10 +38,8 @@ export function DiscoverNoResults({ if (interceptedWarnings?.length) { return ( - ); } From 68ae8cbe9a04b76811610ffeca6fe0bf5e4b568b Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 24 Oct 2023 14:24:23 +0000 Subject: [PATCH 10/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../search_response_warnings/empty_prompt.tsx | 15 ++++++++------- .../search_response_warnings.tsx | 4 +--- .../main/components/no_results/no_results.tsx | 6 +----- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx index 977b96e9e836e..69499c12c5f7c 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; -import { EuiEmptyPrompt, EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui'; +import { EuiEmptyPrompt, EuiText } from '@elastic/eui'; import { ViewDetailsPopover } from './view_details_popover'; import { getWarningsDescription, getWarningsTitle } from './i18n_utils'; import type { SearchResponseWarning } from '../../types'; @@ -35,13 +35,14 @@ export const SearchResponseWarningsEmptyPrompt = (props: Props) => { } body={ - - {getWarningsTitle(props.warnings)} - + {getWarningsTitle(props.warnings)}

- {getWarningsDescription(props.warnings, i18n.translate('searchResponseWarnings.description.pageLabel', { - defaultMessage: 'page', - }))} + {getWarningsDescription( + props.warnings, + i18n.translate('searchResponseWarnings.description.pageLabel', { + defaultMessage: 'page', + }) + )}

diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.tsx index cb3cc15b0bfee..89ac3e8055a59 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.tsx @@ -6,10 +6,8 @@ * Side Public License, v 1. */ -import React, { PropsWithChildren, useEffect, useState } from 'react'; +import React, { PropsWithChildren, useState } from 'react'; import { - EuiCallOut, - EuiEmptyPrompt, EuiText, EuiTextProps, EuiFlexGroup, diff --git a/src/plugins/discover/public/application/main/components/no_results/no_results.tsx b/src/plugins/discover/public/application/main/components/no_results/no_results.tsx index c169b363bf9f4..cf20a679d9568 100644 --- a/src/plugins/discover/public/application/main/components/no_results/no_results.tsx +++ b/src/plugins/discover/public/application/main/components/no_results/no_results.tsx @@ -37,11 +37,7 @@ export function DiscoverNoResults({ const interceptedWarnings = useDataState(documents$).interceptedWarnings; if (interceptedWarnings?.length) { - return ( - - ); + return ; } return ( From 95add4626f10649317347ac4de94dd8434d14791 Mon Sep 17 00:00:00 2001 From: nreese Date: Tue, 24 Oct 2023 08:43:43 -0600 Subject: [PATCH 11/53] move button to actions --- .../search_response_warnings/empty_prompt.tsx | 27 ++++++++----------- .../search_response_warnings/i18n_utils.ts | 2 +- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx index 69499c12c5f7c..9588562e2cca0 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx @@ -10,7 +10,7 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { EuiEmptyPrompt, EuiText } from '@elastic/eui'; import { ViewDetailsPopover } from './view_details_popover'; -import { getWarningsDescription, getWarningsTitle } from './i18n_utils'; +import { getNonSuccessfulClusters } from './i18n_utils'; import type { SearchResponseWarning } from '../../types'; interface Props { @@ -18,9 +18,7 @@ interface Props { } export const SearchResponseWarningsEmptyPrompt = (props: Props) => { - if (!props.warnings.length) { - return null; - } + const nonSuccessfulClusters = getNonSuccessfulClusters(props.warnings); return ( { } body={ - - {getWarningsTitle(props.warnings)} -

- {getWarningsDescription( - props.warnings, - i18n.translate('searchResponseWarnings.description.pageLabel', { - defaultMessage: 'page', - }) - )} -

- -
+ i18n.translate('searchResponseWarnings.emptyPromptBody', { + defaultMessage: '{nonSuccessfulClustersCount} {nonSuccessfulClustersCount, plural, one {cluster} other {clusters}} had issues returning data. This might result in incomplete data.', + values: { + nonSuccessfulClustersCount: nonSuccessfulClusters.size, + } + }) + } + actions={ + } /> ); diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts index af7db8deb7d02..34dfca179aa9e 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts @@ -13,7 +13,7 @@ export const viewDetailsLabel = i18n.translate('searchResponseWarnings.viewDetai description: 'View warning details button label', }); -function getNonSuccessfulClusters(warnings: SearchResponseWarning[]) { +export function getNonSuccessfulClusters(warnings: SearchResponseWarning[]) { const nonSuccessfulClusters = new Set(); warnings.forEach((warning) => { Object.keys(warning.clusters).forEach((clusterName) => { From 0872c8029974624ccc5f3957ab39ab8b23d720b8 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 24 Oct 2023 14:50:33 +0000 Subject: [PATCH 12/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../search_response_warnings/empty_prompt.tsx | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx index 9588562e2cca0..bd6504f07c68c 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; -import { EuiEmptyPrompt, EuiText } from '@elastic/eui'; +import { EuiEmptyPrompt } from '@elastic/eui'; import { ViewDetailsPopover } from './view_details_popover'; import { getNonSuccessfulClusters } from './i18n_utils'; import type { SearchResponseWarning } from '../../types'; @@ -31,17 +31,14 @@ export const SearchResponseWarningsEmptyPrompt = (props: Props) => { })} } - body={ - i18n.translate('searchResponseWarnings.emptyPromptBody', { - defaultMessage: '{nonSuccessfulClustersCount} {nonSuccessfulClustersCount, plural, one {cluster} other {clusters}} had issues returning data. This might result in incomplete data.', - values: { - nonSuccessfulClustersCount: nonSuccessfulClusters.size, - } - }) - } - actions={ - - } + body={i18n.translate('searchResponseWarnings.emptyPromptBody', { + defaultMessage: + '{nonSuccessfulClustersCount} {nonSuccessfulClustersCount, plural, one {cluster} other {clusters}} had issues returning data. This might result in incomplete data.', + values: { + nonSuccessfulClustersCount: nonSuccessfulClusters.size, + }, + })} + actions={} /> ); }; From 852594ed31c03e56fb6316d7bb418e9668b7e220 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 24 Oct 2023 14:59:47 +0000 Subject: [PATCH 13/53] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- packages/kbn-search-response-warnings/tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/kbn-search-response-warnings/tsconfig.json b/packages/kbn-search-response-warnings/tsconfig.json index 26819b76e3e52..3de59617bae30 100644 --- a/packages/kbn-search-response-warnings/tsconfig.json +++ b/packages/kbn-search-response-warnings/tsconfig.json @@ -5,7 +5,6 @@ }, "include": ["*.ts", "src/**/*", "__mocks__/**/*.ts"], "kbn_references": [ - "@kbn/test-jest-helpers", "@kbn/i18n", "@kbn/inspector-plugin", "@kbn/core", From 32c212b7ec78bce5c22170ef51e997fbfac5871b Mon Sep 17 00:00:00 2001 From: nreese Date: Tue, 24 Oct 2023 12:59:20 -0600 Subject: [PATCH 14/53] bagde --- .../kbn-search-response-warnings/index.ts | 3 +- .../search_response_warnings/badge.tsx | 84 +++++++ .../badge_popover_content.tsx | 73 ++++++ .../search_response_warnings/index.ts | 6 +- .../search_response_warnings.tsx | 208 ------------------ .../saved_search_embeddable_base.tsx | 12 +- 6 files changed, 166 insertions(+), 220 deletions(-) create mode 100644 packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx create mode 100644 packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx delete mode 100644 packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.tsx diff --git a/packages/kbn-search-response-warnings/index.ts b/packages/kbn-search-response-warnings/index.ts index 25ea5c60d5201..1ecb9d2d2a158 100644 --- a/packages/kbn-search-response-warnings/index.ts +++ b/packages/kbn-search-response-warnings/index.ts @@ -9,8 +9,7 @@ export type { SearchResponseWarning, WarningHandlerCallback } from './src/types'; export { - SearchResponseWarnings, - type SearchResponseWarningsProps, + SearchResponseWarningsBadge, SearchResponseWarningsCallout, SearchResponseWarningsEmptyPrompt, } from './src/components/search_response_warnings'; diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx new file mode 100644 index 0000000000000..50be03d99f9c4 --- /dev/null +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx @@ -0,0 +1,84 @@ +/* + * 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, { useState } from 'react'; +import { i18n } from '@kbn/i18n'; +import { css } from '@emotion/react'; +import { + EuiButton, + EuiIcon, + EuiPopover, + useEuiTheme, + useEuiFontSize, +} from '@elastic/eui'; +import { SearchResponseWarningsBadgePopoverContent } from './badge_popover_content'; +import type { SearchResponseWarning } from '../../types'; + +interface Props { + visualizationLabel?: string; + warnings: SearchResponseWarning[]; +} + +export const SearchResponseWarningsBadge = (props: Props) => { + if (!props.warnings.length) { + return null; + } + + const [isPopoverOpen, setIsPopoverOpen] = useState(false); + const { euiTheme } = useEuiTheme(); + const xsFontSize = useEuiFontSize('xs').fontSize; + + const buttonLabel = i18n.translate('searchResponseWarnings.badgeButtonLabel', { + defaultMessage: '{warningCount} {warningCount, plural, one {warning} other {warnings}}', + values: { + warningCount: props.warnings.length, + }, + }); + + return ( + setIsPopoverOpen(!isPopoverOpen)} + data-test-subj="searchResponseWarningsBadgeToogleButton" + title={buttonLabel} + css={css` + block-size: ${euiTheme.size.l}; + font-size: ${xsFontSize}; + padding: 0 ${euiTheme.size.xs}; + & > * { + gap: ${euiTheme.size.xs}; + } + `} + > + + {props.warnings.length} + + } + isOpen={isPopoverOpen} + closePopover={() => setIsPopoverOpen(false)} + > + { + setIsPopoverOpen(false) + }} + visualizationLabel={props.visualizationLabel} + warnings={props.warnings} + /> + + ); +}; diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx new file mode 100644 index 0000000000000..d74082fc37433 --- /dev/null +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx @@ -0,0 +1,73 @@ +/* + * 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, { useState } from 'react'; +import { + EuiButtonEmpty, + EuiContextMenuItem, + EuiContextMenuPanel, + EuiPanel, + EuiText, +} from '@elastic/eui'; +import { getWarningsDescription, getWarningsTitle, viewDetailsLabel } from './i18n_utils'; +import type { SearchResponseWarning } from '../../types'; + +const WARNING_PANEL_ID = 0; +const VIEW_DETAILS_PANEL_ID = 1; + +interface Props { + onViewDetailsClick?: () => void; + visualizationLabel?: string; + warnings: SearchResponseWarning[]; +} + +export const SearchResponseWarningsBadgePopoverContent = (props: Props) => { + const [openPanel, setOpenPanel] = useState(WARNING_PANEL_ID); + return openPanel === VIEW_DETAILS_PANEL_ID + ? { + return ( + { + props.onViewDetailsClick?.(); + warning.openInInspector(); + }} + > + {warning.requestName} + + ); + })} + onClose={() => { + setOpenPanel(WARNING_PANEL_ID); + }} + title={viewDetailsLabel} + /> + : + + + {getWarningsDescription(props.warnings, props.visualizationLabel)} + + 1 ? "right" : undefined} + iconType={props.warnings.length > 1 ? "arrowRight" : undefined} + onClick={() => { + if (props.warnings.length > 1) { + setOpenPanel(VIEW_DETAILS_PANEL_ID); + } else { + props?.onViewDetailsClick(); + props.warnings[0].openInInspector(); + } + }} + > + {viewDetailsLabel} + + + ; +}; diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts index dcfbb7e917ff6..229e336132674 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts @@ -6,10 +6,6 @@ * Side Public License, v 1. */ -export { - SearchResponseWarnings, - type SearchResponseWarningsProps, -} from './search_response_warnings'; - +export { SearchResponseWarningsBadge } from './badge'; export { SearchResponseWarningsCallout } from './callout'; export { SearchResponseWarningsEmptyPrompt } from './empty_prompt'; diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.tsx deleted file mode 100644 index 89ac3e8055a59..0000000000000 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/search_response_warnings.tsx +++ /dev/null @@ -1,208 +0,0 @@ -/* - * 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, { PropsWithChildren, useState } from 'react'; -import { - EuiText, - EuiTextProps, - EuiFlexGroup, - EuiFlexGroupProps, - EuiFlexItem, - EuiToolTip, - EuiButton, - EuiIcon, - EuiPopover, - useEuiTheme, - useEuiFontSize, - EuiButtonIcon, -} from '@elastic/eui'; -import { css } from '@emotion/react'; -import { i18n } from '@kbn/i18n'; -import { ViewWarningButton } from '../view_warning_button'; -import type { SearchResponseWarning } from '../../types'; - -/** - * SearchResponseWarnings component props - */ -export interface SearchResponseWarningsProps { - /** - * An array of warnings - */ - interceptedWarnings?: SearchResponseWarning[]; - - /** - * View variant - */ - variant: 'callout' | 'badge' | 'empty_prompt'; - - /** - * Custom data-test-subj value - */ - 'data-test-subj': string; -} - -/** - * SearchResponseWarnings component - * @param interceptedWarnings - * @param variant - * @param dataTestSubj - * @constructor - */ -export const SearchResponseWarnings = ({ - interceptedWarnings, - variant, - 'data-test-subj': dataTestSubj, -}: SearchResponseWarningsProps) => { - const { euiTheme } = useEuiTheme(); - const xsFontSize = useEuiFontSize('xs').fontSize; - const [isPopoverOpen, setIsPopoverOpen] = useState(false); - - if (!interceptedWarnings?.length) { - return null; - } - - if (variant === 'badge') { - const warningCount = interceptedWarnings.length; - const buttonLabel = i18n.translate('searchResponseWarnings.badgeButtonLabel', { - defaultMessage: '{warningCount} {warningCount, plural, one {warning} other {warnings}}', - values: { - warningCount, - }, - }); - - return ( - - setIsPopoverOpen(true)} - data-test-subj={`${dataTestSubj}_trigger`} - title={buttonLabel} - css={css` - block-size: ${euiTheme.size.l}; - font-size: ${xsFontSize}; - padding: 0 ${euiTheme.size.xs}; - & > * { - gap: ${euiTheme.size.xs}; - } - `} - > - - {warningCount} - - - } - isOpen={isPopoverOpen} - closePopover={() => setIsPopoverOpen(false)} - > -
    - {interceptedWarnings.map((warning, index) => ( -
  • - - - - - - - - -
  • - ))} -
-
- ); - } - - return null; -}; - -function WarningContent({ - warning, - textSize = 's', - groupStyles, - 'data-test-subj': dataTestSubj, -}: { - warning: SearchResponseWarning; - textSize?: EuiTextProps['size']; - groupStyles?: Partial; - 'data-test-subj': string; -}) { - return ( - - - - {warning.message} - - - - - - - ); -} - -function CalloutTitleWrapper({ - children, - onCloseCallout, -}: PropsWithChildren<{ onCloseCallout: () => void }>) { - return ( - - {children} - - - - - ); -} diff --git a/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx b/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx index 7edeb04ca5e08..b1cf3e6b9773e 100644 --- a/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx +++ b/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx @@ -7,9 +7,10 @@ */ import React from 'react'; +import { i18n } from '@kbn/i18n'; import { css } from '@emotion/react'; import { EuiFlexGroup, EuiFlexItem, EuiProgress } from '@elastic/eui'; -import { type SearchResponseWarning, SearchResponseWarnings } from '@kbn/search-response-warnings'; +import { type SearchResponseWarning, SearchResponseWarningsBadge } from '@kbn/search-response-warnings'; import { TotalDocuments } from '../application/main/components/total_documents/total_documents'; const containerStyles = css` @@ -71,10 +72,11 @@ export const SavedSearchEmbeddableBase: React.FC {Boolean(interceptedWarnings?.length) && (
-
)} From 819588fcbb178f516ece9bd138e6a545aa4dea92 Mon Sep 17 00:00:00 2001 From: nreese Date: Tue, 24 Oct 2023 13:01:31 -0600 Subject: [PATCH 15/53] clean up --- .../search_response_warnings/badge_popover_content.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx index d74082fc37433..47200e6fdfd46 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx @@ -61,7 +61,7 @@ export const SearchResponseWarningsBadgePopoverContent = (props: Props) => { if (props.warnings.length > 1) { setOpenPanel(VIEW_DETAILS_PANEL_ID); } else { - props?.onViewDetailsClick(); + props.onViewDetailsClick?.(); props.warnings[0].openInInspector(); } }} From b0d06b48867df223fb2468798e2a1c1af7bae0d9 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 24 Oct 2023 19:06:43 +0000 Subject: [PATCH 16/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../badge_popover_content.tsx | 80 ++++++++++--------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx index 47200e6fdfd46..802c71b3cd513 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx @@ -28,46 +28,48 @@ interface Props { export const SearchResponseWarningsBadgePopoverContent = (props: Props) => { const [openPanel, setOpenPanel] = useState(WARNING_PANEL_ID); - return openPanel === VIEW_DETAILS_PANEL_ID - ? { - return ( - { - props.onViewDetailsClick?.(); - warning.openInInspector(); - }} - > - {warning.requestName} - - ); - })} - onClose={() => { - setOpenPanel(WARNING_PANEL_ID); - }} - title={viewDetailsLabel} - /> - : - - - {getWarningsDescription(props.warnings, props.visualizationLabel)} - - 1 ? "right" : undefined} - iconType={props.warnings.length > 1 ? "arrowRight" : undefined} + return openPanel === VIEW_DETAILS_PANEL_ID ? ( + { + return ( + { - if (props.warnings.length > 1) { - setOpenPanel(VIEW_DETAILS_PANEL_ID); - } else { - props.onViewDetailsClick?.(); - props.warnings[0].openInInspector(); - } + props.onViewDetailsClick?.(); + warning.openInInspector(); }} > - {viewDetailsLabel} - - - ; + {warning.requestName} + + ); + })} + onClose={() => { + setOpenPanel(WARNING_PANEL_ID); + }} + title={viewDetailsLabel} + /> + ) : ( + + + + {getWarningsDescription(props.warnings, props.visualizationLabel)} + + 1 ? 'right' : undefined} + iconType={props.warnings.length > 1 ? 'arrowRight' : undefined} + onClick={() => { + if (props.warnings.length > 1) { + setOpenPanel(VIEW_DETAILS_PANEL_ID); + } else { + props.onViewDetailsClick?.(); + props.warnings[0].openInInspector(); + } + }} + > + {viewDetailsLabel} + + + + ); }; From 17d2f1ba32493acde9a4f0a92fed072c90d7d73f Mon Sep 17 00:00:00 2001 From: nreese Date: Tue, 24 Oct 2023 14:22:46 -0600 Subject: [PATCH 17/53] update lens to use SearchResponseWarningsBadgePopoverContent --- .../kbn-search-response-warnings/index.ts | 1 + .../badge_popover_content.tsx | 1 + .../search_response_warnings/index.ts | 1 + .../public/datasources/form_based/utils.tsx | 19 +++-------- .../workspace_panel/message_list.scss | 6 ++-- .../workspace_panel/message_list.tsx | 33 ++++++++++--------- 6 files changed, 29 insertions(+), 32 deletions(-) diff --git a/packages/kbn-search-response-warnings/index.ts b/packages/kbn-search-response-warnings/index.ts index 1ecb9d2d2a158..a026efbf40ac4 100644 --- a/packages/kbn-search-response-warnings/index.ts +++ b/packages/kbn-search-response-warnings/index.ts @@ -10,6 +10,7 @@ export type { SearchResponseWarning, WarningHandlerCallback } from './src/types' export { SearchResponseWarningsBadge, + SearchResponseWarningsBadgePopoverContent, SearchResponseWarningsCallout, SearchResponseWarningsEmptyPrompt, } from './src/components/search_response_warnings'; diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx index 802c71b3cd513..88410bce77066 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx @@ -56,6 +56,7 @@ export const SearchResponseWarningsBadgePopoverContent = (props: Props) => { 1 ? 'right' : undefined} iconType={props.warnings.length > 1 ? 'arrowRight' : undefined} onClick={() => { diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts index 229e336132674..06c2b2c18e31a 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/index.ts @@ -7,5 +7,6 @@ */ export { SearchResponseWarningsBadge } from './badge'; +export { SearchResponseWarningsBadgePopoverContent } from './badge_popover_content'; export { SearchResponseWarningsCallout } from './callout'; export { SearchResponseWarningsEmptyPrompt } from './empty_prompt'; diff --git a/x-pack/plugins/lens/public/datasources/form_based/utils.tsx b/x-pack/plugins/lens/public/datasources/form_based/utils.tsx index f9aecd4726fb9..5114277301560 100644 --- a/x-pack/plugins/lens/public/datasources/form_based/utils.tsx +++ b/x-pack/plugins/lens/public/datasources/form_based/utils.tsx @@ -19,7 +19,7 @@ import { groupBy, escape, uniq, uniqBy } from 'lodash'; import type { Query } from '@kbn/data-plugin/common'; import { SearchRequest } from '@kbn/data-plugin/common'; -import { type SearchResponseWarning, ViewWarningButton } from '@kbn/search-response-warnings'; +import { type SearchResponseWarning, SearchResponseWarningsBadgePopoverContent } from '@kbn/search-response-warnings'; import { estypes } from '@elastic/elasticsearch'; import { isQueryValid } from '@kbn/visualization-ui-components'; @@ -307,19 +307,10 @@ export function getSearchWarningMessages( displayLocations: [{ id: 'toolbar' }, { id: 'embeddableBadge' }], shortMessage: '', longMessage: (closePopover) => ( - <> - {warning.message} - - { - closePopover(); - warning.openInInspector(); - }} - size="m" - color="primary" - isButtonEmpty={true} - /> - + ), } as UserMessage, ]; diff --git a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/message_list.scss b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/message_list.scss index 88ecee001dab1..3b7dd8049757a 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/message_list.scss +++ b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/message_list.scss @@ -11,13 +11,15 @@ } .lnsWorkspaceWarningList__item { - padding: $euiSize; - & + & { border-top: $euiBorderThin; } } +.lnsWorkspaceWarningList__textItem { + padding: $euiSize; +} + .lnsWorkspaceWarningList__description { overflow-wrap: break-word; min-width: 0; diff --git a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/message_list.tsx b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/message_list.tsx index af4eabda5ffc1..8dc3bc0e4bc2b 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/message_list.tsx +++ b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/message_list.tsx @@ -113,22 +113,23 @@ export const MessageList = ({ className="lnsWorkspaceWarningList__item" data-test-subj={`lens-message-list-${message.severity}`} > - - - {message.severity === 'error' ? ( - - ) : ( - - )} - - - - {typeof message.longMessage === 'function' - ? message.longMessage(closePopover) - : message.longMessage} - - - + {typeof message.longMessage === 'function' + ? message.longMessage(closePopover) + : + + {message.severity === 'error' ? ( + + ) : ( + + )} + + + + {message.longMessage} + + + + } ))} From f9a8a388295bc00e73e2f93fc2710d049038c376 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 24 Oct 2023 20:29:26 +0000 Subject: [PATCH 18/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../public/datasources/form_based/utils.tsx | 7 +++- .../workspace_panel/message_list.tsx | 37 ++++++++++--------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/lens/public/datasources/form_based/utils.tsx b/x-pack/plugins/lens/public/datasources/form_based/utils.tsx index 5114277301560..16c4dbdc047fb 100644 --- a/x-pack/plugins/lens/public/datasources/form_based/utils.tsx +++ b/x-pack/plugins/lens/public/datasources/form_based/utils.tsx @@ -12,14 +12,17 @@ import type { DocLinksStart, ThemeServiceStart } from '@kbn/core/public'; import { hasUnsupportedDownsampledAggregationFailure } from '@kbn/search-response-warnings'; import type { DatatableUtilitiesService } from '@kbn/data-plugin/common'; import { TimeRange } from '@kbn/es-query'; -import { EuiLink, EuiSpacer, EuiText } from '@elastic/eui'; +import { EuiLink, EuiSpacer } from '@elastic/eui'; import type { DatatableColumn } from '@kbn/expressions-plugin/common'; import { groupBy, escape, uniq, uniqBy } from 'lodash'; import type { Query } from '@kbn/data-plugin/common'; import { SearchRequest } from '@kbn/data-plugin/common'; -import { type SearchResponseWarning, SearchResponseWarningsBadgePopoverContent } from '@kbn/search-response-warnings'; +import { + type SearchResponseWarning, + SearchResponseWarningsBadgePopoverContent, +} from '@kbn/search-response-warnings'; import { estypes } from '@elastic/elasticsearch'; import { isQueryValid } from '@kbn/visualization-ui-components'; diff --git a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/message_list.tsx b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/message_list.tsx index 8dc3bc0e4bc2b..091944b660181 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/message_list.tsx +++ b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/message_list.tsx @@ -113,23 +113,26 @@ export const MessageList = ({ className="lnsWorkspaceWarningList__item" data-test-subj={`lens-message-list-${message.severity}`} > - {typeof message.longMessage === 'function' - ? message.longMessage(closePopover) - : - - {message.severity === 'error' ? ( - - ) : ( - - )} - - - - {message.longMessage} - - - - } + {typeof message.longMessage === 'function' ? ( + message.longMessage(closePopover) + ) : ( + + + {message.severity === 'error' ? ( + + ) : ( + + )} + + + {message.longMessage} + + + )} ))} From 8e1530e7aada674a600a9588f9d5a932d4d9769b Mon Sep 17 00:00:00 2001 From: nreese Date: Tue, 24 Oct 2023 14:54:28 -0600 Subject: [PATCH 19/53] toast --- .../components/view_warning_button/index.tsx | 19 --------- .../view_warning_button.tsx | 39 ------------------- .../src/handle_warnings.tsx | 22 ++++++++--- 3 files changed, 17 insertions(+), 63 deletions(-) delete mode 100644 packages/kbn-search-response-warnings/src/components/view_warning_button/index.tsx delete mode 100644 packages/kbn-search-response-warnings/src/components/view_warning_button/view_warning_button.tsx diff --git a/packages/kbn-search-response-warnings/src/components/view_warning_button/index.tsx b/packages/kbn-search-response-warnings/src/components/view_warning_button/index.tsx deleted file mode 100644 index 4df4d1fa98104..0000000000000 --- a/packages/kbn-search-response-warnings/src/components/view_warning_button/index.tsx +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 type { Props } from './view_warning_button'; - -const Fallback = () =>
; - -const LazyViewWarningButton = React.lazy(() => import('./view_warning_button')); -export const ViewWarningButton = (props: Props) => ( - }> - - -); diff --git a/packages/kbn-search-response-warnings/src/components/view_warning_button/view_warning_button.tsx b/packages/kbn-search-response-warnings/src/components/view_warning_button/view_warning_button.tsx deleted file mode 100644 index bd0e717d9c76d..0000000000000 --- a/packages/kbn-search-response-warnings/src/components/view_warning_button/view_warning_button.tsx +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 { FormattedMessage } from '@kbn/i18n-react'; -import { EuiLink, EuiButton, EuiButtonProps } from '@elastic/eui'; - -export interface Props { - onClick: () => void; - size?: EuiButtonProps['size']; - color?: EuiButtonProps['color']; - isButtonEmpty?: boolean; -} - -// Needed for React.lazy -// eslint-disable-next-line import/no-default-export -export default function ViewWarningButton({ - onClick, - size = 's', - color = 'warning', - isButtonEmpty = false, -}: Props) { - const Component = isButtonEmpty ? EuiLink : EuiButton; - - return ( - - - - ); -} diff --git a/packages/kbn-search-response-warnings/src/handle_warnings.tsx b/packages/kbn-search-response-warnings/src/handle_warnings.tsx index 7ed1143351915..ee6744e0c737b 100644 --- a/packages/kbn-search-response-warnings/src/handle_warnings.tsx +++ b/packages/kbn-search-response-warnings/src/handle_warnings.tsx @@ -7,7 +7,7 @@ */ import React from 'react'; -import { EuiTextAlign } from '@elastic/eui'; +import { EuiButtonEmpty, EuiText } from '@elastic/eui'; import { estypes } from '@elastic/elasticsearch'; import type { NotificationsStart, ThemeServiceStart } from '@kbn/core/public'; import { toMountPoint } from '@kbn/react-kibana-mount'; @@ -20,6 +20,7 @@ import { } from './types'; import { extractWarnings } from './extract_warnings'; import { ViewWarningButton } from './components/view_warning_button'; +import { getWarningsDescription, getWarningsTitle, viewDetailsLabel } from './components/search_response_warnings/i18n_utils'; interface Services { i18n: I18nStart; @@ -75,11 +76,22 @@ export function handleWarnings({ const [incompleteWarning] = incompleteWarnings as SearchResponseIncompleteWarning[]; services.notifications.toasts.addWarning({ - title: incompleteWarning.message, + title: getWarningsTitle([incompleteWarning]), text: toMountPoint( - - - , + <> + + {getWarningsDescription([incompleteWarning])} + + { + incompleteWarning.openInInspector(); + }} + > + {viewDetailsLabel} + + , { theme: services.theme, i18n: services.i18n } ), }); From 6e9c091827d6e4e3291df463267f00381524a9ed Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 24 Oct 2023 21:02:08 +0000 Subject: [PATCH 20/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../src/handle_warnings.tsx | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/handle_warnings.tsx b/packages/kbn-search-response-warnings/src/handle_warnings.tsx index ee6744e0c737b..de151f4e29119 100644 --- a/packages/kbn-search-response-warnings/src/handle_warnings.tsx +++ b/packages/kbn-search-response-warnings/src/handle_warnings.tsx @@ -19,8 +19,11 @@ import { WarningHandlerCallback, } from './types'; import { extractWarnings } from './extract_warnings'; -import { ViewWarningButton } from './components/view_warning_button'; -import { getWarningsDescription, getWarningsTitle, viewDetailsLabel } from './components/search_response_warnings/i18n_utils'; +import { + getWarningsDescription, + getWarningsTitle, + viewDetailsLabel, +} from './components/search_response_warnings/i18n_utils'; interface Services { i18n: I18nStart; @@ -78,20 +81,18 @@ export function handleWarnings({ services.notifications.toasts.addWarning({ title: getWarningsTitle([incompleteWarning]), text: toMountPoint( - <> - - {getWarningsDescription([incompleteWarning])} - - { - incompleteWarning.openInInspector(); - }} - > - {viewDetailsLabel} - - , + <> + {getWarningsDescription([incompleteWarning])} + { + incompleteWarning.openInInspector(); + }} + > + {viewDetailsLabel} + + , { theme: services.theme, i18n: services.i18n } ), }); From af40b7a82c971ed79808ff6c3de1c1ec698adc23 Mon Sep 17 00:00:00 2001 From: nreese Date: Tue, 24 Oct 2023 15:29:03 -0600 Subject: [PATCH 21/53] remove message field from warning --- packages/kbn-search-response-warnings/src/extract_warnings.ts | 3 --- packages/kbn-search-response-warnings/src/types.ts | 4 ---- 2 files changed, 7 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/extract_warnings.ts b/packages/kbn-search-response-warnings/src/extract_warnings.ts index a76f9fc8b26bf..96088b10cb16d 100644 --- a/packages/kbn-search-response-warnings/src/extract_warnings.ts +++ b/packages/kbn-search-response-warnings/src/extract_warnings.ts @@ -37,9 +37,6 @@ export function extractWarnings( warnings.push({ type: 'incomplete', requestName, - message: i18n.translate('searchResponseWarnings.incompleteResultsMessage', { - defaultMessage: 'Results are partial and may be incomplete.', - }), clusters: rawResponse._clusters ? ( rawResponse._clusters as estypes.ClusterStatistics & { diff --git a/packages/kbn-search-response-warnings/src/types.ts b/packages/kbn-search-response-warnings/src/types.ts index 52460fdbdf9fb..df55e012ff7ae 100644 --- a/packages/kbn-search-response-warnings/src/types.ts +++ b/packages/kbn-search-response-warnings/src/types.ts @@ -24,10 +24,6 @@ export interface SearchResponseIncompleteWarning { * type: for sorting out incomplete warnings */ type: 'incomplete'; - /** - * message: human-friendly message - */ - message: string; /** * requestName: human-friendly request name */ From e204e90587eff75548a1c48e6d65c72af7717679 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 24 Oct 2023 21:35:28 +0000 Subject: [PATCH 22/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- packages/kbn-search-response-warnings/src/extract_warnings.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/kbn-search-response-warnings/src/extract_warnings.ts b/packages/kbn-search-response-warnings/src/extract_warnings.ts index 96088b10cb16d..f11b424694ec1 100644 --- a/packages/kbn-search-response-warnings/src/extract_warnings.ts +++ b/packages/kbn-search-response-warnings/src/extract_warnings.ts @@ -7,7 +7,6 @@ */ import { estypes } from '@elastic/elasticsearch'; -import { i18n } from '@kbn/i18n'; import type { ClusterDetails } from '@kbn/es-types'; import type { Start as InspectorStartContract, RequestAdapter } from '@kbn/inspector-plugin/public'; import type { SearchResponseWarning } from './types'; From 331ca613e97db23d149c107eba8ddb8e62a2927d Mon Sep 17 00:00:00 2001 From: nreese Date: Tue, 24 Oct 2023 15:47:58 -0600 Subject: [PATCH 23/53] tslint --- .../kbn-search-response-warnings/index.ts | 1 - .../src/__mocks__/search_response_warnings.ts | 2 +- .../i18n_utils.test.ts | 22 +++++++++++++------ .../search_response_warnings/i18n_utils.ts | 1 + .../view_details_popover.tsx | 4 ++-- .../src/extract_warnings.test.ts | 22 ++++++++++--------- .../src/handle_warnings.test.ts | 4 ++++ ...ed_downsampled_aggregation_failure.test.ts | 4 ++-- 8 files changed, 37 insertions(+), 23 deletions(-) diff --git a/packages/kbn-search-response-warnings/index.ts b/packages/kbn-search-response-warnings/index.ts index a026efbf40ac4..88b61320b99f7 100644 --- a/packages/kbn-search-response-warnings/index.ts +++ b/packages/kbn-search-response-warnings/index.ts @@ -14,7 +14,6 @@ export { SearchResponseWarningsCallout, SearchResponseWarningsEmptyPrompt, } from './src/components/search_response_warnings'; -export { ViewWarningButton } from './src/components/view_warning_button'; export { handleWarnings } from './src/handle_warnings'; export { hasUnsupportedDownsampledAggregationFailure } from './src/has_unsupported_downsampled_aggregation_failure'; diff --git a/packages/kbn-search-response-warnings/src/__mocks__/search_response_warnings.ts b/packages/kbn-search-response-warnings/src/__mocks__/search_response_warnings.ts index 6162ac1742f69..a2a9bbb134c05 100644 --- a/packages/kbn-search-response-warnings/src/__mocks__/search_response_warnings.ts +++ b/packages/kbn-search-response-warnings/src/__mocks__/search_response_warnings.ts @@ -10,7 +10,7 @@ import type { SearchResponseWarning } from '../types'; export const searchResponseIncompleteWarningLocalCluster: SearchResponseWarning = { type: 'incomplete', - message: 'The data might be incomplete or wrong.', + requestName: 'My request', clusters: { '(local)': { status: 'partial', diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts index 0bf748408904d..c62f40fc494b9 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts @@ -7,12 +7,14 @@ */ import { getWarningsTitle, getWarningsDescription } from './i18n_utils'; +import type { SearchResponseWarning } from '../../types'; describe('getWarningsTitle', () => { test('Should show title for single non-successful cluster', () => { const warnings = [ { type: 'incomplete', + requestName: 'My request', clusters: { remote1: { status: 'partial', @@ -21,7 +23,7 @@ describe('getWarningsTitle', () => { }, }, openInInspector: () => {}, - }, + } as SearchResponseWarning, ]; expect(getWarningsTitle(warnings)).toEqual('Problem with 1 cluster'); }); @@ -30,6 +32,7 @@ describe('getWarningsTitle', () => { const warnings = [ { type: 'incomplete', + requestName: 'My request', clusters: { remote1: { status: 'partial', @@ -43,7 +46,7 @@ describe('getWarningsTitle', () => { }, }, openInInspector: () => {}, - }, + } as SearchResponseWarning, ]; expect(getWarningsTitle(warnings)).toEqual('Problem with 2 clusters'); }); @@ -52,6 +55,7 @@ describe('getWarningsTitle', () => { const warnings = [ { type: 'incomplete', + requestName: 'My request', clusters: { remote1: { status: 'partial', @@ -60,9 +64,10 @@ describe('getWarningsTitle', () => { }, }, openInInspector: () => {}, - }, + } as SearchResponseWarning, { type: 'incomplete', + requestName: 'My request', clusters: { remote1: { status: 'partial', @@ -71,7 +76,7 @@ describe('getWarningsTitle', () => { }, }, openInInspector: () => {}, - }, + } as SearchResponseWarning, ]; expect(getWarningsTitle(warnings)).toEqual('Problem with 1 cluster in 2 requests'); }); @@ -82,6 +87,7 @@ describe('getWarningsDescription', () => { const warnings = [ { type: 'incomplete', + requestName: 'My request', clusters: { remote1: { status: 'partial', @@ -90,7 +96,7 @@ describe('getWarningsDescription', () => { }, }, openInInspector: () => {}, - }, + } as SearchResponseWarning, ]; expect(getWarningsDescription(warnings)).toEqual( 'This cluster had issues returning data. This might result in an incomplete visualization.' @@ -101,6 +107,7 @@ describe('getWarningsDescription', () => { const warnings = [ { type: 'incomplete', + requestName: 'My request', clusters: { remote1: { status: 'partial', @@ -114,7 +121,7 @@ describe('getWarningsDescription', () => { }, }, openInInspector: () => {}, - }, + } as SearchResponseWarning, ]; expect(getWarningsDescription(warnings)).toEqual( 'These clusters had issues returning data. This might result in an incomplete visualization.' @@ -125,6 +132,7 @@ describe('getWarningsDescription', () => { const warnings = [ { type: 'incomplete', + requestName: 'My request', clusters: { remote1: { status: 'partial', @@ -133,7 +141,7 @@ describe('getWarningsDescription', () => { }, }, openInInspector: () => {}, - }, + } as SearchResponseWarning, ]; expect(getWarningsDescription(warnings, 'table')).toEqual( 'This cluster had issues returning data. This might result in an incomplete table.' diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts index 34dfca179aa9e..11d2c93d654b0 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts @@ -7,6 +7,7 @@ */ import { i18n } from '@kbn/i18n'; +import type { SearchResponseWarning } from '../../types'; export const viewDetailsLabel = i18n.translate('searchResponseWarnings.viewDetailsButtonLabel', { defaultMessage: 'View details', diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx index 93009a73f60fd..fb29b55345c9a 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx @@ -30,7 +30,7 @@ export const ViewDetailsPopover = (props: Props) => { if (props.warnings.length === 1) { return ( - + {viewDetailsLabel} ); @@ -55,7 +55,7 @@ export const ViewDetailsPopover = (props: Props) => { setIsPopoverOpen(!isPopoverOpen)}> + setIsPopoverOpen(!isPopoverOpen)}> <> {viewDetailsLabel} diff --git a/packages/kbn-search-response-warnings/src/extract_warnings.test.ts b/packages/kbn-search-response-warnings/src/extract_warnings.test.ts index f2a2e9f63d29b..4211c5728d581 100644 --- a/packages/kbn-search-response-warnings/src/extract_warnings.test.ts +++ b/packages/kbn-search-response-warnings/src/extract_warnings.test.ts @@ -42,10 +42,10 @@ describe('extract search response warnings', () => { aggregations: {}, }; - expect(extractWarnings(response, mockInspectorService, mockRequestAdapter)).toEqual([ + expect(extractWarnings(response, mockInspectorService, mockRequestAdapter, 'My request')).toEqual([ { type: 'incomplete', - message: 'Results are partial and may be incomplete.', + requestName: 'My request', clusters: { '(local)': { status: 'partial', @@ -68,10 +68,10 @@ describe('extract search response warnings', () => { _shards: {} as estypes.ShardStatistics, hits: { hits: [] }, }; - expect(extractWarnings(response, mockInspectorService, mockRequestAdapter)).toEqual([ + expect(extractWarnings(response, mockInspectorService, mockRequestAdapter, 'My request')).toEqual([ { type: 'incomplete', - message: 'Results are partial and may be incomplete.', + requestName: 'My request', clusters: { '(local)': { status: 'partial', @@ -97,7 +97,8 @@ describe('extract search response warnings', () => { }, } as estypes.SearchResponse, mockInspectorService, - mockRequestAdapter + mockRequestAdapter, + 'My request', ); expect(warnings).toEqual([]); @@ -188,10 +189,10 @@ describe('extract search response warnings', () => { aggregations: {}, }; - expect(extractWarnings(response, mockInspectorService, mockRequestAdapter)).toEqual([ + expect(extractWarnings(response, mockInspectorService, mockRequestAdapter, 'My request')).toEqual([ { type: 'incomplete', - message: 'Results are partial and may be incomplete.', + requestName: 'My request', clusters: response._clusters.details, openInInspector: expect.any(Function), }, @@ -242,10 +243,10 @@ describe('extract search response warnings', () => { }, hits: { hits: [] }, }; - expect(extractWarnings(response, mockInspectorService, mockRequestAdapter)).toEqual([ + expect(extractWarnings(response, mockInspectorService, mockRequestAdapter, 'My request')).toEqual([ { type: 'incomplete', - message: 'Results are partial and may be incomplete.', + requestName: 'My request', clusters: response._clusters.details, openInInspector: expect.any(Function), }, @@ -297,7 +298,8 @@ describe('extract search response warnings', () => { hits: { hits: [] }, } as estypes.SearchResponse, mockInspectorService, - mockRequestAdapter + mockRequestAdapter, + 'My request', ); expect(warnings).toEqual([]); diff --git a/packages/kbn-search-response-warnings/src/handle_warnings.test.ts b/packages/kbn-search-response-warnings/src/handle_warnings.test.ts index 0ec94c4d8ebbf..ad9dff53fdf5e 100644 --- a/packages/kbn-search-response-warnings/src/handle_warnings.test.ts +++ b/packages/kbn-search-response-warnings/src/handle_warnings.test.ts @@ -25,6 +25,7 @@ describe('handleWarnings', () => { request: {} as unknown as estypes.SearchRequest, requestAdapter: {} as unknown as RequestAdapter, requestId: '1234', + requestName: 'My request', response: { timed_out: false, _shards: { @@ -48,6 +49,7 @@ describe('handleWarnings', () => { request: {} as unknown as estypes.SearchRequest, requestAdapter: {} as unknown as RequestAdapter, requestId: '1234', + requestName: 'My request', response: { took: 999, timed_out: true, @@ -72,6 +74,7 @@ describe('handleWarnings', () => { request: {} as unknown as estypes.SearchRequest, requestAdapter: {} as unknown as RequestAdapter, requestId: '1234', + requestName: 'My request', response: { took: 999, timed_out: true, @@ -97,6 +100,7 @@ describe('handleWarnings', () => { request: {} as unknown as estypes.SearchRequest, requestAdapter: {} as unknown as RequestAdapter, requestId: '1234', + requestName: 'My request', response: { took: 999, timed_out: true, diff --git a/packages/kbn-search-response-warnings/src/has_unsupported_downsampled_aggregation_failure.test.ts b/packages/kbn-search-response-warnings/src/has_unsupported_downsampled_aggregation_failure.test.ts index ec99f9ba8822b..42362965a7799 100644 --- a/packages/kbn-search-response-warnings/src/has_unsupported_downsampled_aggregation_failure.test.ts +++ b/packages/kbn-search-response-warnings/src/has_unsupported_downsampled_aggregation_failure.test.ts @@ -13,7 +13,7 @@ describe('hasUnsupportedDownsampledAggregationFailure', () => { expect( hasUnsupportedDownsampledAggregationFailure({ type: 'incomplete', - message: 'The data might be incomplete or wrong.', + requestName: 'My request', clusters: { '(local)': { status: 'partial', @@ -49,7 +49,7 @@ describe('hasUnsupportedDownsampledAggregationFailure', () => { expect( hasUnsupportedDownsampledAggregationFailure({ type: 'incomplete', - message: 'The data might be incomplete or wrong.', + requestName: 'My request', clusters: { '(local)': { status: 'partial', From 8410a96b71bc0ff5e91d464a9bb5b69ab9807ddc Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 24 Oct 2023 21:54:26 +0000 Subject: [PATCH 24/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../src/extract_warnings.test.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/extract_warnings.test.ts b/packages/kbn-search-response-warnings/src/extract_warnings.test.ts index 4211c5728d581..e0f3388d5f68c 100644 --- a/packages/kbn-search-response-warnings/src/extract_warnings.test.ts +++ b/packages/kbn-search-response-warnings/src/extract_warnings.test.ts @@ -42,7 +42,9 @@ describe('extract search response warnings', () => { aggregations: {}, }; - expect(extractWarnings(response, mockInspectorService, mockRequestAdapter, 'My request')).toEqual([ + expect( + extractWarnings(response, mockInspectorService, mockRequestAdapter, 'My request') + ).toEqual([ { type: 'incomplete', requestName: 'My request', @@ -68,7 +70,9 @@ describe('extract search response warnings', () => { _shards: {} as estypes.ShardStatistics, hits: { hits: [] }, }; - expect(extractWarnings(response, mockInspectorService, mockRequestAdapter, 'My request')).toEqual([ + expect( + extractWarnings(response, mockInspectorService, mockRequestAdapter, 'My request') + ).toEqual([ { type: 'incomplete', requestName: 'My request', @@ -98,7 +102,7 @@ describe('extract search response warnings', () => { } as estypes.SearchResponse, mockInspectorService, mockRequestAdapter, - 'My request', + 'My request' ); expect(warnings).toEqual([]); @@ -189,7 +193,9 @@ describe('extract search response warnings', () => { aggregations: {}, }; - expect(extractWarnings(response, mockInspectorService, mockRequestAdapter, 'My request')).toEqual([ + expect( + extractWarnings(response, mockInspectorService, mockRequestAdapter, 'My request') + ).toEqual([ { type: 'incomplete', requestName: 'My request', @@ -243,7 +249,9 @@ describe('extract search response warnings', () => { }, hits: { hits: [] }, }; - expect(extractWarnings(response, mockInspectorService, mockRequestAdapter, 'My request')).toEqual([ + expect( + extractWarnings(response, mockInspectorService, mockRequestAdapter, 'My request') + ).toEqual([ { type: 'incomplete', requestName: 'My request', @@ -299,7 +307,7 @@ describe('extract search response warnings', () => { } as estypes.SearchResponse, mockInspectorService, mockRequestAdapter, - 'My request', + 'My request' ); expect(warnings).toEqual([]); From ca293fcccd95ce75cc3215be916e9b8db5b387dd Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 24 Oct 2023 22:00:41 +0000 Subject: [PATCH 25/53] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- packages/kbn-search-response-warnings/tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/kbn-search-response-warnings/tsconfig.json b/packages/kbn-search-response-warnings/tsconfig.json index 3de59617bae30..963dff502604f 100644 --- a/packages/kbn-search-response-warnings/tsconfig.json +++ b/packages/kbn-search-response-warnings/tsconfig.json @@ -8,7 +8,6 @@ "@kbn/i18n", "@kbn/inspector-plugin", "@kbn/core", - "@kbn/i18n-react", "@kbn/es-types", "@kbn/react-kibana-mount", "@kbn/core-i18n-browser", From df755a4352dc6200fca4bfab87f91d772e40bc0b Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 24 Oct 2023 22:35:23 +0000 Subject: [PATCH 26/53] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../src/components/search_response_warnings/badge.tsx | 10 ++-------- .../public/embeddable/saved_search_embeddable_base.tsx | 5 ++++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx index 50be03d99f9c4..8460f141a54e5 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx @@ -9,13 +9,7 @@ import React, { useState } from 'react'; import { i18n } from '@kbn/i18n'; import { css } from '@emotion/react'; -import { - EuiButton, - EuiIcon, - EuiPopover, - useEuiTheme, - useEuiFontSize, -} from '@elastic/eui'; +import { EuiButton, EuiIcon, EuiPopover, useEuiTheme, useEuiFontSize } from '@elastic/eui'; import { SearchResponseWarningsBadgePopoverContent } from './badge_popover_content'; import type { SearchResponseWarning } from '../../types'; @@ -74,7 +68,7 @@ export const SearchResponseWarningsBadge = (props: Props) => { > { - setIsPopoverOpen(false) + setIsPopoverOpen(false); }} visualizationLabel={props.visualizationLabel} warnings={props.warnings} diff --git a/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx b/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx index b1cf3e6b9773e..cea48ffd687d8 100644 --- a/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx +++ b/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx @@ -10,7 +10,10 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { css } from '@emotion/react'; import { EuiFlexGroup, EuiFlexItem, EuiProgress } from '@elastic/eui'; -import { type SearchResponseWarning, SearchResponseWarningsBadge } from '@kbn/search-response-warnings'; +import { + type SearchResponseWarning, + SearchResponseWarningsBadge, +} from '@kbn/search-response-warnings'; import { TotalDocuments } from '../application/main/components/total_documents/total_documents'; const containerStyles = css` From ed11c2d3116c7d3367e8b35b98d8c50fb90149d6 Mon Sep 17 00:00:00 2001 From: nreese Date: Wed, 25 Oct 2023 07:45:22 -0600 Subject: [PATCH 27/53] tslint --- .../components/layout/discover_documents.tsx | 2 +- .../embeddable/saved_search_embeddable_base.tsx | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx index 4803f1145ef1c..bc08ebe843147 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx @@ -281,7 +281,7 @@ function DiscoverDocumentsComponent({ visualizationLabel={i18n.translate('discover.documentsVisualizationLabel', { defaultMessage: 'table', })} - warnings={documentState.interceptedWarnings} + warnings={documentState.interceptedWarnings ?? []} /> ), diff --git a/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx b/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx index cea48ffd687d8..ca4823e4bcf59 100644 --- a/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx +++ b/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx @@ -73,16 +73,12 @@ export const SavedSearchEmbeddableBase: React.FC {Boolean(append) && {append}} - {Boolean(interceptedWarnings?.length) && ( -
- -
- )} + ); }; From 3d3d0f542d16c376c6eaa0c5ddd4a7f027991ccd Mon Sep 17 00:00:00 2001 From: nreese Date: Wed, 25 Oct 2023 08:45:42 -0600 Subject: [PATCH 28/53] add unit test for ViewDetailsPopover --- .../view_details_popover.test.tsx | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx new file mode 100644 index 0000000000000..ba6485148fa12 --- /dev/null +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx @@ -0,0 +1,82 @@ +/* + * 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 { render, screen, fireEvent } from '@testing-library/react'; +import { ViewDetailsPopover } from './view_details_popover'; +import type { SearchResponseWarning } from '../../types'; + +describe('ViewDetailsPopover', () => { + describe('single warning', () => { + test('Clicking "view details" should open warning details', () => { + mockOpenInInspector = jest.fn(); + const warnings = [ + { + type: 'incomplete', + requestName: 'My request', + clusters: { + remote1: { + status: 'partial', + indices: '', + timed_out: false, + }, + }, + openInInspector: mockOpenInInspector, + } as SearchResponseWarning, + ]; + render(); + const viewDetailsButton = screen.getByRole('button'); + fireEvent.click(viewDetailsButton); + expect(mockOpenInInspector).toHaveBeenCalled(); + }); + }); + + describe('multiple warnings', () => { + test('Clicking "view details" should open popover with buttons to view details for each warning', () => { + request1MockOpenInInspector = jest.fn(); + request2MockOpenInInspector = jest.fn(); + const warnings = [ + { + type: 'incomplete', + requestName: 'My first request', + clusters: { + remote1: { + status: 'partial', + indices: '', + timed_out: false, + }, + }, + openInInspector: request1MockOpenInInspector, + } as SearchResponseWarning, + { + type: 'incomplete', + requestName: 'My second request', + clusters: { + remote1: { + status: 'partial', + indices: '', + timed_out: false, + }, + }, + openInInspector: request2MockOpenInInspector, + } as SearchResponseWarning, + ]; + render(); + const viewDetailsButton = screen.getByRole('button'); + fireEvent.click(viewDetailsButton); + expect(request1MockOpenInInspector).not.toHaveBeenCalled(); + expect(request2MockOpenInInspector).not.toHaveBeenCalled(); + + const openRequest1Button = screen.getByRole('button', { name: 'My first request' }); + fireEvent.click(openRequest1Button); + expect(request1MockOpenInInspector).toHaveBeenCalled(); + expect(request2MockOpenInInspector).not.toHaveBeenCalled(); + }); + }) + +}); \ No newline at end of file From 77b3255a9260270346032f30756763b8eb2db26a Mon Sep 17 00:00:00 2001 From: nreese Date: Wed, 25 Oct 2023 08:57:09 -0600 Subject: [PATCH 29/53] fix context_app_content.test --- .../search_response_warnings/view_details_popover.test.tsx | 2 +- .../public/application/context/context_app_content.test.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx index ba6485148fa12..887891186b7a5 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx @@ -37,7 +37,7 @@ describe('ViewDetailsPopover', () => { }); describe('multiple warnings', () => { - test('Clicking "view details" should open popover with buttons to view details for each warning', () => { + test('Clicking "view details" should open popover with button to view details for each warning', () => { request1MockOpenInInspector = jest.fn(); request2MockOpenInInspector = jest.fn(); const warnings = [ diff --git a/src/plugins/discover/public/application/context/context_app_content.test.tsx b/src/plugins/discover/public/application/context/context_app_content.test.tsx index f6c87772ec913..f55fdd448df52 100644 --- a/src/plugins/discover/public/application/context/context_app_content.test.tsx +++ b/src/plugins/discover/public/application/context/context_app_content.test.tsx @@ -72,6 +72,7 @@ describe('ContextAppContent test', () => { isLegacy: isLegacy ?? true, setAppState: () => {}, addFilter: () => {}, + interceptedWarnings: [], } as unknown as ContextAppContentProps; const component = mountWithIntl( From e7fe7600aed95a3ae89cbf8330ece6a8c668c0b2 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:04:43 +0000 Subject: [PATCH 30/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../search_response_warnings/view_details_popover.test.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx index 887891186b7a5..fd0beb94882fe 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx @@ -77,6 +77,5 @@ describe('ViewDetailsPopover', () => { expect(request1MockOpenInInspector).toHaveBeenCalled(); expect(request2MockOpenInInspector).not.toHaveBeenCalled(); }); - }) - -}); \ No newline at end of file + }); +}); From 1772e7296f491fa35b6fb0afb9288115633a34a0 Mon Sep 17 00:00:00 2001 From: nreese Date: Wed, 25 Oct 2023 09:26:40 -0600 Subject: [PATCH 31/53] tslint --- .../search_response_warnings/view_details_popover.test.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx index fd0beb94882fe..55eeb08657ad7 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx @@ -14,7 +14,7 @@ import type { SearchResponseWarning } from '../../types'; describe('ViewDetailsPopover', () => { describe('single warning', () => { test('Clicking "view details" should open warning details', () => { - mockOpenInInspector = jest.fn(); + const mockOpenInInspector = jest.fn(); const warnings = [ { type: 'incomplete', @@ -38,8 +38,8 @@ describe('ViewDetailsPopover', () => { describe('multiple warnings', () => { test('Clicking "view details" should open popover with button to view details for each warning', () => { - request1MockOpenInInspector = jest.fn(); - request2MockOpenInInspector = jest.fn(); + const request1MockOpenInInspector = jest.fn(); + const request2MockOpenInInspector = jest.fn(); const warnings = [ { type: 'incomplete', From 17642a687be1129a2bca70fd70790e175a8d7025 Mon Sep 17 00:00:00 2001 From: nreese Date: Wed, 25 Oct 2023 10:47:33 -0600 Subject: [PATCH 32/53] fix functional test --- .../search_response_warnings/empty_prompt.tsx | 1 + .../functional/apps/discover/async_scripted_fields.js | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx index bd6504f07c68c..417f5619dc69d 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx @@ -39,6 +39,7 @@ export const SearchResponseWarningsEmptyPrompt = (props: Props) => { }, })} actions={} + data-test-subj="searchResponseWarningsEmptyPrompt" /> ); }; diff --git a/x-pack/test/functional/apps/discover/async_scripted_fields.js b/x-pack/test/functional/apps/discover/async_scripted_fields.js index 5810830aec3a6..03806b54bd60b 100644 --- a/x-pack/test/functional/apps/discover/async_scripted_fields.js +++ b/x-pack/test/functional/apps/discover/async_scripted_fields.js @@ -74,14 +74,10 @@ export default function ({ getService, getPageObjects }) { await PageObjects.common.navigateToApp('discover'); await PageObjects.discover.selectIndexPattern('logsta*'); + await PageObjects.header.waitUntilLoadingHasFinished(); - await retry.tryForTime(20000, async function () { - // wait for shards failed message - const shardMessage = await testSubjects.getVisibleText( - 'dscNoResultsInterceptedWarningsCallout_warningTitle' - ); - log.debug(shardMessage); - expect(shardMessage).to.be('Results are partial and may be incomplete.'); + await retry.try(async function () { + await testSubjects.existOrFail('searchResponseWarningsEmptyPrompt'); }); }); From 2bfd4b1f3eba646b0d7c5bbcb627e8cab4e6bff9 Mon Sep 17 00:00:00 2001 From: nreese Date: Wed, 25 Oct 2023 10:52:21 -0600 Subject: [PATCH 33/53] more test clean up --- .../test/functional/apps/discover/async_scripted_fields.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/x-pack/test/functional/apps/discover/async_scripted_fields.js b/x-pack/test/functional/apps/discover/async_scripted_fields.js index 03806b54bd60b..f3ae63dd427aa 100644 --- a/x-pack/test/functional/apps/discover/async_scripted_fields.js +++ b/x-pack/test/functional/apps/discover/async_scripted_fields.js @@ -74,7 +74,6 @@ export default function ({ getService, getPageObjects }) { await PageObjects.common.navigateToApp('discover'); await PageObjects.discover.selectIndexPattern('logsta*'); - await PageObjects.header.waitUntilLoadingHasFinished(); await retry.try(async function () { await testSubjects.existOrFail('searchResponseWarningsEmptyPrompt'); @@ -100,9 +99,8 @@ export default function ({ getService, getPageObjects }) { await dashboardAddPanel.addSavedSearch('search with warning'); await PageObjects.header.waitUntilLoadingHasFinished(); - await retry.tryForTime(20000, async function () { - // wait for shards failed message - await testSubjects.existOrFail('savedSearchEmbeddableWarningsCallout_trigger'); + await retry.try(async function () { + await testSubjects.existOrFail('searchResponseWarningsBadgeToogleButton'); }); }); From b1f72809d365c9fed2c23715ab91d168f3147067 Mon Sep 17 00:00:00 2001 From: nreese Date: Wed, 25 Oct 2023 11:05:50 -0600 Subject: [PATCH 34/53] badge_popover_content unit test --- .../badge_popover_content.test.tsx | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx new file mode 100644 index 0000000000000..fbbf14e4fe5fe --- /dev/null +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx @@ -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 + * 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 { render, screen, fireEvent } from '@testing-library/react'; +import { SearchResponseWarningsBadgePopoverContent } from './badge_popover_content'; +import type { SearchResponseWarning } from '../../types'; + +describe('SearchResponseWarningsBadgePopoverContent', () => { + describe('single warning', () => { + test('Clicking "view details" should open warning details', () => { + const mockOpenInInspector = jest.fn(); + const mockOnViewDetailsClick = jest.fn(); + const warnings = [ + { + type: 'incomplete', + requestName: 'My request', + clusters: { + remote1: { + status: 'partial', + indices: '', + timed_out: false, + }, + }, + openInInspector: mockOpenInInspector, + } as SearchResponseWarning, + ]; + render(); + const viewDetailsButton = screen.getByRole('button'); + fireEvent.click(viewDetailsButton); + expect(mockOpenInInspector).toHaveBeenCalled(); + expect(mockOnViewDetailsClick).toHaveBeenCalled(); + }); + }); + + describe('multiple warnings', () => { + test('Clicking "view details" should open content panel with button to view details for each warning', () => { + const request1MockOpenInInspector = jest.fn(); + const request2MockOpenInInspector = jest.fn(); + const mockOnViewDetailsClick = jest.fn(); + const warnings = [ + { + type: 'incomplete', + requestName: 'My first request', + clusters: { + remote1: { + status: 'partial', + indices: '', + timed_out: false, + }, + }, + openInInspector: request1MockOpenInInspector, + } as SearchResponseWarning, + { + type: 'incomplete', + requestName: 'My second request', + clusters: { + remote1: { + status: 'partial', + indices: '', + timed_out: false, + }, + }, + openInInspector: request2MockOpenInInspector, + } as SearchResponseWarning, + ]; + render(); + const viewDetailsButton = screen.getByRole('button'); + fireEvent.click(viewDetailsButton); + expect(request1MockOpenInInspector).not.toHaveBeenCalled(); + expect(request2MockOpenInInspector).not.toHaveBeenCalled(); + expect(mockOnViewDetailsClick).not.toHaveBeenCalled(); + + const openRequest1Button = screen.getByRole('button', { name: 'My first request' }); + fireEvent.click(openRequest1Button); + expect(request1MockOpenInInspector).toHaveBeenCalled(); + expect(mockOnViewDetailsClick).toHaveBeenCalled(); + expect(request2MockOpenInInspector).not.toHaveBeenCalled(); + }); + }); +}); \ No newline at end of file From a84131b5174b73603d024661fe293d62f408a592 Mon Sep 17 00:00:00 2001 From: nreese Date: Wed, 25 Oct 2023 11:08:01 -0600 Subject: [PATCH 35/53] clean up --- .../components/search_response_warnings/badge.tsx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx index 8460f141a54e5..92bdc6bc3f1c4 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx @@ -27,13 +27,6 @@ export const SearchResponseWarningsBadge = (props: Props) => { const { euiTheme } = useEuiTheme(); const xsFontSize = useEuiFontSize('xs').fontSize; - const buttonLabel = i18n.translate('searchResponseWarnings.badgeButtonLabel', { - defaultMessage: '{warningCount} {warningCount, plural, one {warning} other {warnings}}', - values: { - warningCount: props.warnings.length, - }, - }); - return ( { color="warning" onClick={() => setIsPopoverOpen(!isPopoverOpen)} data-test-subj="searchResponseWarningsBadgeToogleButton" - title={buttonLabel} + title={i18n.translate('searchResponseWarnings.badgeButtonLabel', { + defaultMessage: '{warningCount} {warningCount, plural, one {warning} other {warnings}}', + values: { + warningCount: props.warnings.length, + }, + })} css={css` block-size: ${euiTheme.size.l}; font-size: ${xsFontSize}; From 4fbb2672fe29b69a5af7c491cd9f2dcf3c1a0068 Mon Sep 17 00:00:00 2001 From: nreese Date: Wed, 25 Oct 2023 11:17:42 -0600 Subject: [PATCH 36/53] move hooks to top of component --- .../src/components/search_response_warnings/badge.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx index 92bdc6bc3f1c4..ceb02e3adcfd4 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx @@ -19,14 +19,14 @@ interface Props { } export const SearchResponseWarningsBadge = (props: Props) => { - if (!props.warnings.length) { - return null; - } - const [isPopoverOpen, setIsPopoverOpen] = useState(false); const { euiTheme } = useEuiTheme(); const xsFontSize = useEuiFontSize('xs').fontSize; + if (!props.warnings.length) { + return null; + } + return ( Date: Wed, 25 Oct 2023 17:52:53 +0000 Subject: [PATCH 37/53] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../badge_popover_content.test.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx index fbbf14e4fe5fe..ff0fdbbc28a1f 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx @@ -30,7 +30,12 @@ describe('SearchResponseWarningsBadgePopoverContent', () => { openInInspector: mockOpenInInspector, } as SearchResponseWarning, ]; - render(); + render( + + ); const viewDetailsButton = screen.getByRole('button'); fireEvent.click(viewDetailsButton); expect(mockOpenInInspector).toHaveBeenCalled(); @@ -69,7 +74,12 @@ describe('SearchResponseWarningsBadgePopoverContent', () => { openInInspector: request2MockOpenInInspector, } as SearchResponseWarning, ]; - render(); + render( + + ); const viewDetailsButton = screen.getByRole('button'); fireEvent.click(viewDetailsButton); expect(request1MockOpenInInspector).not.toHaveBeenCalled(); @@ -83,4 +93,4 @@ describe('SearchResponseWarningsBadgePopoverContent', () => { expect(request2MockOpenInInspector).not.toHaveBeenCalled(); }); }); -}); \ No newline at end of file +}); From 163a1ab61afa781b5b005f3eac2d885bd8b38078 Mon Sep 17 00:00:00 2001 From: nreese Date: Wed, 25 Oct 2023 12:37:07 -0600 Subject: [PATCH 38/53] fix search source examples functional test --- .../src/handle_warnings.tsx | 1 + test/examples/search/warnings.ts | 13 +------------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/handle_warnings.tsx b/packages/kbn-search-response-warnings/src/handle_warnings.tsx index de151f4e29119..1ff5cb0eafab4 100644 --- a/packages/kbn-search-response-warnings/src/handle_warnings.tsx +++ b/packages/kbn-search-response-warnings/src/handle_warnings.tsx @@ -89,6 +89,7 @@ export function handleWarnings({ onClick={() => { incompleteWarning.openInInspector(); }} + data-test-subj="viewWarningBtn" > {viewDetailsLabel} diff --git a/test/examples/search/warnings.ts b/test/examples/search/warnings.ts index 267a49de08bc7..ef8eb0cd0231e 100644 --- a/test/examples/search/warnings.ts +++ b/test/examples/search/warnings.ts @@ -107,16 +107,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await retry.try(async () => { const toasts = await find.allByCssSelector(toastsSelector); expect(toasts.length).to.be(2); - const expects = ['Results are partial and may be incomplete.', 'Query result']; - await asyncForEach(toasts, async (t, index) => { - expect(await t.getVisibleText()).to.eql(expects[index]); - }); + await testSubjects.click('viewWarningBtn'); }); - // click "see full error" button in the toast - const [openShardModalButton] = await testSubjects.findAll('viewWarningBtn'); - await openShardModalButton.click(); - // request await retry.try(async () => { await testSubjects.click('inspectorRequestDetailRequest'); @@ -164,10 +157,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await retry.try(async () => { toasts = await find.allByCssSelector(toastsSelector); expect(toasts.length).to.be(2); - const expects = ['Results are partial and may be incomplete.', 'Query result']; - await asyncForEach(toasts, async (t, index) => { - expect(await t.getVisibleText()).to.eql(expects[index]); - }); }); // warnings tab From a8bca8c8e27241f4265d58b14fc4360ff207fcd7 Mon Sep 17 00:00:00 2001 From: nreese Date: Wed, 25 Oct 2023 12:38:17 -0600 Subject: [PATCH 39/53] fix search source example serverless tests --- .../test_suites/common/examples/search/warnings.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/x-pack/test_serverless/functional/test_suites/common/examples/search/warnings.ts b/x-pack/test_serverless/functional/test_suites/common/examples/search/warnings.ts index ff24321f11348..f64ab71a6cfbd 100644 --- a/x-pack/test_serverless/functional/test_suites/common/examples/search/warnings.ts +++ b/x-pack/test_serverless/functional/test_suites/common/examples/search/warnings.ts @@ -107,10 +107,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await retry.try(async () => { const toasts = await find.allByCssSelector(toastsSelector); expect(toasts.length).to.be(2); - const expects = ['Results are partial and may be incomplete.', 'Query result']; - await asyncForEach(toasts, async (t, index) => { - expect(await t.getVisibleText()).to.eql(expects[index]); - }); + await testSubjects.click('viewWarningBtn'); }); // click "see full error" button in the toast @@ -164,10 +161,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await retry.try(async () => { toasts = await find.allByCssSelector(toastsSelector); expect(toasts.length).to.be(2); - const expects = ['Results are partial and may be incomplete.', 'Query result']; - await asyncForEach(toasts, async (t, index) => { - expect(await t.getVisibleText()).to.eql(expects[index]); - }); }); // warnings tab From adb88946b1956c10f7e64b2ace40bebc7dd75732 Mon Sep 17 00:00:00 2001 From: nreese Date: Wed, 25 Oct 2023 12:41:39 -0600 Subject: [PATCH 40/53] remove extra click --- .../functional/test_suites/common/examples/search/warnings.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/x-pack/test_serverless/functional/test_suites/common/examples/search/warnings.ts b/x-pack/test_serverless/functional/test_suites/common/examples/search/warnings.ts index f64ab71a6cfbd..029684a0b70dd 100644 --- a/x-pack/test_serverless/functional/test_suites/common/examples/search/warnings.ts +++ b/x-pack/test_serverless/functional/test_suites/common/examples/search/warnings.ts @@ -110,10 +110,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await testSubjects.click('viewWarningBtn'); }); - // click "see full error" button in the toast - const [openShardModalButton] = await testSubjects.findAll('viewWarningBtn'); - await openShardModalButton.click(); - // request await retry.try(async () => { await testSubjects.click('inspectorRequestDetailRequest'); From 1abff1570f67e68bebc78f9c488fd9640cced685 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 25 Oct 2023 18:48:23 +0000 Subject: [PATCH 41/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../functional/test_suites/common/examples/search/warnings.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/test_serverless/functional/test_suites/common/examples/search/warnings.ts b/x-pack/test_serverless/functional/test_suites/common/examples/search/warnings.ts index 029684a0b70dd..a254cb753c864 100644 --- a/x-pack/test_serverless/functional/test_suites/common/examples/search/warnings.ts +++ b/x-pack/test_serverless/functional/test_suites/common/examples/search/warnings.ts @@ -7,7 +7,6 @@ import type { estypes } from '@elastic/elasticsearch'; import expect from '@kbn/expect'; -import { asyncForEach } from '@kbn/std'; import assert from 'assert'; import type { WebElementWrapper } from '../../../../../../../test/functional/services/lib/web_element_wrapper'; import type { FtrProviderContext } from '../../../../ftr_provider_context'; From 72066e0de6c03aa4934cd6cb93eb5f212abf0f71 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 25 Oct 2023 18:56:35 +0000 Subject: [PATCH 42/53] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- x-pack/test_serverless/tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/test_serverless/tsconfig.json b/x-pack/test_serverless/tsconfig.json index 21ca495a87eaf..e587356636d61 100644 --- a/x-pack/test_serverless/tsconfig.json +++ b/x-pack/test_serverless/tsconfig.json @@ -56,7 +56,6 @@ "@kbn/es-archiver", "@kbn/rule-data-utils", "@kbn/rison", - "@kbn/std", "@kbn/serverless-common-settings", "@kbn/serverless-observability-settings", "@kbn/serverless-search-settings", From b0d95157e167047a90a7d788736a8bbfbdbdc876 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 25 Oct 2023 19:31:33 +0000 Subject: [PATCH 43/53] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- test/examples/search/warnings.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/examples/search/warnings.ts b/test/examples/search/warnings.ts index ef8eb0cd0231e..3a923b4a2ae60 100644 --- a/test/examples/search/warnings.ts +++ b/test/examples/search/warnings.ts @@ -8,7 +8,6 @@ import type { estypes } from '@elastic/elasticsearch'; import expect from '@kbn/expect'; -import { asyncForEach } from '@kbn/std'; import assert from 'assert'; import type { FtrProviderContext } from '../../functional/ftr_provider_context'; import type { WebElementWrapper } from '../../functional/services/lib/web_element_wrapper'; From ea2a25c3ea39a97d38e2684e821f9b75c2e19cc2 Mon Sep 17 00:00:00 2001 From: nreese Date: Thu, 26 Oct 2023 09:15:51 -0600 Subject: [PATCH 44/53] review feedback --- .../badge_popover_content.tsx | 92 ++++++++++--------- .../search_response_warnings/i18n_utils.ts | 14 ++- 2 files changed, 60 insertions(+), 46 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx index 88410bce77066..754eb639b777d 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx @@ -28,49 +28,55 @@ interface Props { export const SearchResponseWarningsBadgePopoverContent = (props: Props) => { const [openPanel, setOpenPanel] = useState(WARNING_PANEL_ID); - return openPanel === VIEW_DETAILS_PANEL_ID ? ( - { - return ( - { - props.onViewDetailsClick?.(); - warning.openInInspector(); - }} - > - {warning.requestName} - - ); - })} - onClose={() => { - setOpenPanel(WARNING_PANEL_ID); - }} - title={viewDetailsLabel} - /> - ) : ( - - - - {getWarningsDescription(props.warnings, props.visualizationLabel)} - - 1 ? 'right' : undefined} - iconType={props.warnings.length > 1 ? 'arrowRight' : undefined} - onClick={() => { - if (props.warnings.length > 1) { - setOpenPanel(VIEW_DETAILS_PANEL_ID); - } else { - props.onViewDetailsClick?.(); - props.warnings[0].openInInspector(); - } + + return ( +
+ {openPanel === VIEW_DETAILS_PANEL_ID ? ( + { + return ( + { + props.onViewDetailsClick?.(); + warning.openInInspector(); + }} + > + {warning.requestName} + + ); + })} + onClose={() => { + setOpenPanel(WARNING_PANEL_ID); }} - > - {viewDetailsLabel} - - - + title={viewDetailsLabel} + /> + ) : ( + + + + {getWarningsDescription(props.warnings, props.visualizationLabel)} + + 1 ? 'right' : undefined} + iconType={props.warnings.length > 1 ? 'arrowRight' : undefined} + onClick={() => { + if (props.warnings.length > 1) { + setOpenPanel(VIEW_DETAILS_PANEL_ID); + } else { + props.onViewDetailsClick?.(); + props.warnings[0].openInInspector(); + } + }} + > + {viewDetailsLabel} + + + + ) + } +
); }; diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts index 11d2c93d654b0..165af60b2ea27 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts @@ -50,11 +50,19 @@ export function getWarningsDescription( visualizationLabel?: string ) { const nonSuccessfulClusters = getNonSuccessfulClusters(warnings); - return i18n.translate('searchResponseWarnings.description', { + const clusterStatement = nonSuccessfulClusters.size <= 1 + ? i18n.translate('searchResponseWarnings.description.clusterStatement.singleCluster', { + defaultMessage: + 'This cluster had issues returning data.', + }) + : i18n.translate('searchResponseWarnings.description.clusterStatement.multipleClusters', { + defaultMessage: + 'These clusters had issues returning data.', + }); + return clusterStatement + ' ' + i18n.translate('searchResponseWarnings.description.consequenceStatement', { defaultMessage: - '{nonSuccessfulClustersCount, plural, one {This cluster} other {These clusters}} had issues returning data. This might result in an incomplete {visualizationLabel}.', + 'This might result in an incomplete {visualizationLabel}.', values: { - nonSuccessfulClustersCount: nonSuccessfulClusters.size, visualizationLabel: visualizationLabel ? visualizationLabel : i18n.translate('searchResponseWarnings.description.defaultVisualizationLabel', { From d6aaece9e498af6f861a9a9b81fe4d009942d2ba Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 26 Oct 2023 15:22:19 +0000 Subject: [PATCH 45/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../badge_popover_content.tsx | 3 +- .../search_response_warnings/i18n_utils.ts | 42 ++++++++++--------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx index 754eb639b777d..6c5a97a7c4491 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx @@ -75,8 +75,7 @@ export const SearchResponseWarningsBadgePopoverContent = (props: Props) => {
- ) - } + )}
); }; diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts index 165af60b2ea27..7f07c1e6a9b04 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts @@ -50,24 +50,26 @@ export function getWarningsDescription( visualizationLabel?: string ) { const nonSuccessfulClusters = getNonSuccessfulClusters(warnings); - const clusterStatement = nonSuccessfulClusters.size <= 1 - ? i18n.translate('searchResponseWarnings.description.clusterStatement.singleCluster', { - defaultMessage: - 'This cluster had issues returning data.', - }) - : i18n.translate('searchResponseWarnings.description.clusterStatement.multipleClusters', { - defaultMessage: - 'These clusters had issues returning data.', - }); - return clusterStatement + ' ' + i18n.translate('searchResponseWarnings.description.consequenceStatement', { - defaultMessage: - 'This might result in an incomplete {visualizationLabel}.', - values: { - visualizationLabel: visualizationLabel - ? visualizationLabel - : i18n.translate('searchResponseWarnings.description.defaultVisualizationLabel', { - defaultMessage: 'visualization', - }), - }, - }); + const clusterStatement = + nonSuccessfulClusters.size <= 1 + ? i18n.translate('searchResponseWarnings.description.clusterStatement.singleCluster', { + defaultMessage: 'This cluster had issues returning data.', + }) + : i18n.translate('searchResponseWarnings.description.clusterStatement.multipleClusters', { + defaultMessage: 'These clusters had issues returning data.', + }); + return ( + clusterStatement + + ' ' + + i18n.translate('searchResponseWarnings.description.consequenceStatement', { + defaultMessage: 'This might result in an incomplete {visualizationLabel}.', + values: { + visualizationLabel: visualizationLabel + ? visualizationLabel + : i18n.translate('searchResponseWarnings.description.defaultVisualizationLabel', { + defaultMessage: 'visualization', + }), + }, + }) + ); } From e15b99b48bc7f82a54073bca396550a7b3e9591e Mon Sep 17 00:00:00 2001 From: nreese Date: Thu, 26 Oct 2023 13:54:20 -0600 Subject: [PATCH 46/53] copy update --- .../search_response_warnings/badge.tsx | 2 -- .../badge_popover_content.tsx | 3 +- .../search_response_warnings/callout.tsx | 3 +- .../search_response_warnings/empty_prompt.tsx | 12 ++------ .../i18n_utils.test.ts | 24 ++------------- .../search_response_warnings/i18n_utils.ts | 30 +++++-------------- .../context/context_app_content.tsx | 4 --- .../components/layout/discover_documents.tsx | 3 -- .../saved_search_embeddable_base.tsx | 4 --- 9 files changed, 13 insertions(+), 72 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx index ceb02e3adcfd4..5ae148c35a7ac 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge.tsx @@ -14,7 +14,6 @@ import { SearchResponseWarningsBadgePopoverContent } from './badge_popover_conte import type { SearchResponseWarning } from '../../types'; interface Props { - visualizationLabel?: string; warnings: SearchResponseWarning[]; } @@ -68,7 +67,6 @@ export const SearchResponseWarningsBadge = (props: Props) => { onViewDetailsClick={() => { setIsPopoverOpen(false); }} - visualizationLabel={props.visualizationLabel} warnings={props.warnings} /> diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx index 6c5a97a7c4491..588765c856c27 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx @@ -22,7 +22,6 @@ const VIEW_DETAILS_PANEL_ID = 1; interface Props { onViewDetailsClick?: () => void; - visualizationLabel?: string; warnings: SearchResponseWarning[]; } @@ -55,7 +54,7 @@ export const SearchResponseWarningsBadgePopoverContent = (props: Props) => { - {getWarningsDescription(props.warnings, props.visualizationLabel)} + {getWarningsDescription(props.warnings)} { > - {getWarningsDescription(props.warnings, props.visualizationLabel)} + {getWarningsDescription(props.warnings)} diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx index 417f5619dc69d..097cc7a314cf9 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx @@ -10,7 +10,7 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { EuiEmptyPrompt } from '@elastic/eui'; import { ViewDetailsPopover } from './view_details_popover'; -import { getNonSuccessfulClusters } from './i18n_utils'; +import { getWarningsDescription } from './i18n_utils'; import type { SearchResponseWarning } from '../../types'; interface Props { @@ -18,8 +18,6 @@ interface Props { } export const SearchResponseWarningsEmptyPrompt = (props: Props) => { - const nonSuccessfulClusters = getNonSuccessfulClusters(props.warnings); - return ( { })} } - body={i18n.translate('searchResponseWarnings.emptyPromptBody', { - defaultMessage: - '{nonSuccessfulClustersCount} {nonSuccessfulClustersCount, plural, one {cluster} other {clusters}} had issues returning data. This might result in incomplete data.', - values: { - nonSuccessfulClustersCount: nonSuccessfulClusters.size, - }, - })} + body={getWarningsDescription(props.warnings)} actions={} data-test-subj="searchResponseWarningsEmptyPrompt" /> diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts index c62f40fc494b9..ed8c26135185a 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.test.ts @@ -99,7 +99,7 @@ describe('getWarningsDescription', () => { } as SearchResponseWarning, ]; expect(getWarningsDescription(warnings)).toEqual( - 'This cluster had issues returning data. This might result in an incomplete visualization.' + 'This cluster had issues returning data and results might be incomplete.' ); }); @@ -124,27 +124,7 @@ describe('getWarningsDescription', () => { } as SearchResponseWarning, ]; expect(getWarningsDescription(warnings)).toEqual( - 'These clusters had issues returning data. This might result in an incomplete visualization.' - ); - }); - - test('Should show custom visualization label', () => { - const warnings = [ - { - type: 'incomplete', - requestName: 'My request', - clusters: { - remote1: { - status: 'partial', - indices: '', - timed_out: false, - }, - }, - openInInspector: () => {}, - } as SearchResponseWarning, - ]; - expect(getWarningsDescription(warnings, 'table')).toEqual( - 'This cluster had issues returning data. This might result in an incomplete table.' + 'These clusters had issues returning data and results might be incomplete.' ); }); }); diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts index 7f07c1e6a9b04..d1f8018ad6632 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts @@ -47,29 +47,13 @@ export function getWarningsTitle(warnings: SearchResponseWarning[]) { export function getWarningsDescription( warnings: SearchResponseWarning[], - visualizationLabel?: string ) { const nonSuccessfulClusters = getNonSuccessfulClusters(warnings); - const clusterStatement = - nonSuccessfulClusters.size <= 1 - ? i18n.translate('searchResponseWarnings.description.clusterStatement.singleCluster', { - defaultMessage: 'This cluster had issues returning data.', - }) - : i18n.translate('searchResponseWarnings.description.clusterStatement.multipleClusters', { - defaultMessage: 'These clusters had issues returning data.', - }); - return ( - clusterStatement + - ' ' + - i18n.translate('searchResponseWarnings.description.consequenceStatement', { - defaultMessage: 'This might result in an incomplete {visualizationLabel}.', - values: { - visualizationLabel: visualizationLabel - ? visualizationLabel - : i18n.translate('searchResponseWarnings.description.defaultVisualizationLabel', { - defaultMessage: 'visualization', - }), - }, - }) - ); + return nonSuccessfulClusters.size <= 1 + ? i18n.translate('searchResponseWarnings.description.singleCluster', { + defaultMessage: 'This cluster had issues returning data and results might be incomplete.', + }) + : i18n.translate('searchResponseWarnings.description.multipleClusters', { + defaultMessage: 'These clusters had issues returning data and results might be incomplete.', + }); } diff --git a/src/plugins/discover/public/application/context/context_app_content.tsx b/src/plugins/discover/public/application/context/context_app_content.tsx index 34a4a92d965f3..07bf8a86b021b 100644 --- a/src/plugins/discover/public/application/context/context_app_content.tsx +++ b/src/plugins/discover/public/application/context/context_app_content.tsx @@ -7,7 +7,6 @@ */ import React, { Fragment, useCallback, useMemo, useState } from 'react'; -import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { EuiSpacer, EuiText, useEuiPaddingSize } from '@elastic/eui'; import { css } from '@emotion/react'; @@ -155,9 +154,6 @@ export function ContextAppContent({ {interceptedWarnings.length && ( <> diff --git a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx index bc08ebe843147..11f9c8992bdf6 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx @@ -278,9 +278,6 @@ function DiscoverDocumentsComponent({ selectedColumns={currentColumns} /> diff --git a/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx b/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx index ca4823e4bcf59..2d2e3dd30da4e 100644 --- a/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx +++ b/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx @@ -7,7 +7,6 @@ */ import React from 'react'; -import { i18n } from '@kbn/i18n'; import { css } from '@emotion/react'; import { EuiFlexGroup, EuiFlexItem, EuiProgress } from '@elastic/eui'; import { @@ -74,9 +73,6 @@ export const SavedSearchEmbeddableBase: React.FC {Boolean(append) && {append}} From ed41860e9ac92f684bc3b05b6954a3c0497ab994 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 26 Oct 2023 20:00:11 +0000 Subject: [PATCH 47/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../search_response_warnings/badge_popover_content.tsx | 4 +--- .../src/components/search_response_warnings/callout.tsx | 4 +--- .../src/components/search_response_warnings/i18n_utils.ts | 4 +--- .../public/application/context/context_app_content.tsx | 4 +--- .../application/main/components/layout/discover_documents.tsx | 4 +--- .../public/embeddable/saved_search_embeddable_base.tsx | 4 +--- 6 files changed, 6 insertions(+), 18 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx index 588765c856c27..86c6e87ced64a 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx @@ -53,9 +53,7 @@ export const SearchResponseWarningsBadgePopoverContent = (props: Props) => { ) : ( - - {getWarningsDescription(props.warnings)} - + {getWarningsDescription(props.warnings)} { data-test-subj="searchResponseWarningsCallout" > - - {getWarningsDescription(props.warnings)} - + {getWarningsDescription(props.warnings)} diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts index d1f8018ad6632..7a7ebd196097b 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/i18n_utils.ts @@ -45,9 +45,7 @@ export function getWarningsTitle(warnings: SearchResponseWarning[]) { }); } -export function getWarningsDescription( - warnings: SearchResponseWarning[], -) { +export function getWarningsDescription(warnings: SearchResponseWarning[]) { const nonSuccessfulClusters = getNonSuccessfulClusters(warnings); return nonSuccessfulClusters.size <= 1 ? i18n.translate('searchResponseWarnings.description.singleCluster', { diff --git a/src/plugins/discover/public/application/context/context_app_content.tsx b/src/plugins/discover/public/application/context/context_app_content.tsx index 07bf8a86b021b..098f789be1a6f 100644 --- a/src/plugins/discover/public/application/context/context_app_content.tsx +++ b/src/plugins/discover/public/application/context/context_app_content.tsx @@ -153,9 +153,7 @@ export function ContextAppContent({ {interceptedWarnings.length && ( <> - + )} diff --git a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx index 11f9c8992bdf6..bf01e2a7b6669 100644 --- a/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx +++ b/src/plugins/discover/public/application/main/components/layout/discover_documents.tsx @@ -277,9 +277,7 @@ function DiscoverDocumentsComponent({ textBasedQueryColumns={documents?.textBasedQueryColumns} selectedColumns={currentColumns} /> - + ), [ diff --git a/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx b/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx index 2d2e3dd30da4e..2e883198076dd 100644 --- a/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx +++ b/src/plugins/discover/public/embeddable/saved_search_embeddable_base.tsx @@ -72,9 +72,7 @@ export const SavedSearchEmbeddableBase: React.FC {Boolean(append) && {append}} - + ); }; From d03388ac2a64216971a083e183aad21cd3d46eec Mon Sep 17 00:00:00 2001 From: nreese Date: Thu, 26 Oct 2023 14:13:07 -0600 Subject: [PATCH 48/53] display 'View details' action as button in empty prompt --- .../components/search_response_warnings/callout.tsx | 2 +- .../search_response_warnings/empty_prompt.tsx | 2 +- .../view_details_popover.test.tsx | 4 ++-- .../view_details_popover.tsx | 12 ++++++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/callout.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/callout.tsx index 4319be6fb9949..448d08fd5bdfc 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/callout.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/callout.tsx @@ -32,7 +32,7 @@ export const SearchResponseWarningsCallout = (props: Props) => { {getWarningsDescription(props.warnings)} - + diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx index 097cc7a314cf9..9cced725de41e 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx @@ -30,7 +30,7 @@ export const SearchResponseWarningsEmptyPrompt = (props: Props) => { } body={getWarningsDescription(props.warnings)} - actions={} + actions={} data-test-subj="searchResponseWarningsEmptyPrompt" /> ); diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx index 55eeb08657ad7..538b77f5fee00 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx @@ -29,7 +29,7 @@ describe('ViewDetailsPopover', () => { openInInspector: mockOpenInInspector, } as SearchResponseWarning, ]; - render(); + render(); const viewDetailsButton = screen.getByRole('button'); fireEvent.click(viewDetailsButton); expect(mockOpenInInspector).toHaveBeenCalled(); @@ -66,7 +66,7 @@ describe('ViewDetailsPopover', () => { openInInspector: request2MockOpenInInspector, } as SearchResponseWarning, ]; - render(); + render(); const viewDetailsButton = screen.getByRole('button'); fireEvent.click(viewDetailsButton); expect(request1MockOpenInInspector).not.toHaveBeenCalled(); diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx index fb29b55345c9a..67d05897fc418 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx @@ -8,6 +8,7 @@ import React, { useState } from 'react'; import { + EuiButton, EuiIcon, EuiLink, EuiContextMenu, @@ -18,21 +19,24 @@ import { viewDetailsLabel } from './i18n_utils'; import type { SearchResponseWarning } from '../../types'; interface Props { + displayAsLink: boolean; warnings: SearchResponseWarning[]; } export const ViewDetailsPopover = (props: Props) => { const [isPopoverOpen, setIsPopoverOpen] = useState(false); + const ActionComponent = props.displayAsLink ? EuiLink : EuiButton; + if (!props.warnings.length) { return null; } if (props.warnings.length === 1) { return ( - + {viewDetailsLabel} - + ); } @@ -55,11 +59,11 @@ export const ViewDetailsPopover = (props: Props) => { setIsPopoverOpen(!isPopoverOpen)}> + setIsPopoverOpen(!isPopoverOpen)}> <> {viewDetailsLabel} - + } isOpen={isPopoverOpen} closePopover={() => setIsPopoverOpen(false)} From f0a6f431feb1ce1334739e9b90972011644ecd05 Mon Sep 17 00:00:00 2001 From: nreese Date: Thu, 26 Oct 2023 14:31:53 -0600 Subject: [PATCH 49/53] refactor ViewDetailsPopover --- .../search_response_warnings/empty_prompt.tsx | 2 +- .../view_details_popover.test.tsx | 118 +++++++++++------- .../view_details_popover.tsx | 38 ++++-- 3 files changed, 100 insertions(+), 58 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx index 9cced725de41e..097cc7a314cf9 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/empty_prompt.tsx @@ -30,7 +30,7 @@ export const SearchResponseWarningsEmptyPrompt = (props: Props) => { } body={getWarningsDescription(props.warnings)} - actions={} + actions={} data-test-subj="searchResponseWarningsEmptyPrompt" /> ); diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx index 538b77f5fee00..087f90cd1ab85 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx @@ -13,23 +13,35 @@ import type { SearchResponseWarning } from '../../types'; describe('ViewDetailsPopover', () => { describe('single warning', () => { - test('Clicking "view details" should open warning details', () => { - const mockOpenInInspector = jest.fn(); - const warnings = [ - { - type: 'incomplete', - requestName: 'My request', - clusters: { - remote1: { - status: 'partial', - indices: '', - timed_out: false, - }, + const mockOpenInInspector = jest.fn(); + const warnings = [ + { + type: 'incomplete', + requestName: 'My request', + clusters: { + remote1: { + status: 'partial', + indices: '', + timed_out: false, }, - openInInspector: mockOpenInInspector, - } as SearchResponseWarning, - ]; - render(); + }, + openInInspector: mockOpenInInspector, + } as SearchResponseWarning, + ]; + + beforeEach(() => { + mockOpenInInspector.mockReset(); + }); + + test('Clicking "view details" button should open warning details', () => { + render(); + const viewDetailsButton = screen.getByRole('button'); + fireEvent.click(viewDetailsButton); + expect(mockOpenInInspector).toHaveBeenCalled(); + }); + + test('Clicking "view details" link should open warning details', () => { + render(); const viewDetailsButton = screen.getByRole('button'); fireEvent.click(viewDetailsButton); expect(mockOpenInInspector).toHaveBeenCalled(); @@ -37,36 +49,54 @@ describe('ViewDetailsPopover', () => { }); describe('multiple warnings', () => { - test('Clicking "view details" should open popover with button to view details for each warning', () => { - const request1MockOpenInInspector = jest.fn(); - const request2MockOpenInInspector = jest.fn(); - const warnings = [ - { - type: 'incomplete', - requestName: 'My first request', - clusters: { - remote1: { - status: 'partial', - indices: '', - timed_out: false, - }, + const request1MockOpenInInspector = jest.fn(); + const request2MockOpenInInspector = jest.fn(); + const warnings = [ + { + type: 'incomplete', + requestName: 'My first request', + clusters: { + remote1: { + status: 'partial', + indices: '', + timed_out: false, }, - openInInspector: request1MockOpenInInspector, - } as SearchResponseWarning, - { - type: 'incomplete', - requestName: 'My second request', - clusters: { - remote1: { - status: 'partial', - indices: '', - timed_out: false, - }, + }, + openInInspector: request1MockOpenInInspector, + } as SearchResponseWarning, + { + type: 'incomplete', + requestName: 'My second request', + clusters: { + remote1: { + status: 'partial', + indices: '', + timed_out: false, }, - openInInspector: request2MockOpenInInspector, - } as SearchResponseWarning, - ]; - render(); + }, + openInInspector: request2MockOpenInInspector, + } as SearchResponseWarning, + ]; + beforeEach(() => { + request1MockOpenInInspector.mockReset(); + request2MockOpenInInspector.mockReset(); + }); + + test('Clicking "view details" button should open popover with button to view details for each warning', () => { + render(); + const viewDetailsButton = screen.getByRole('button'); + fireEvent.click(viewDetailsButton); + expect(request1MockOpenInInspector).not.toHaveBeenCalled(); + expect(request2MockOpenInInspector).not.toHaveBeenCalled(); + + const openRequest1Button = screen.getByRole('button', { name: 'My first request' }); + fireEvent.click(openRequest1Button); + expect(request1MockOpenInInspector).toHaveBeenCalled(); + expect(request2MockOpenInInspector).not.toHaveBeenCalled(); + }); + + test('Clicking "view details" link should open popover with button to view details for each warning', () => { + render(); const viewDetailsButton = screen.getByRole('button'); fireEvent.click(viewDetailsButton); expect(request1MockOpenInInspector).not.toHaveBeenCalled(); diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx index 67d05897fc418..3dc67ab11d28c 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx @@ -19,25 +19,29 @@ import { viewDetailsLabel } from './i18n_utils'; import type { SearchResponseWarning } from '../../types'; interface Props { - displayAsLink: boolean; + displayAsLink?: boolean; warnings: SearchResponseWarning[]; } export const ViewDetailsPopover = (props: Props) => { const [isPopoverOpen, setIsPopoverOpen] = useState(false); - const ActionComponent = props.displayAsLink ? EuiLink : EuiButton; - if (!props.warnings.length) { return null; } if (props.warnings.length === 1) { - return ( - - {viewDetailsLabel} - - ); + return props.displayAsLink + ? ( + + {viewDetailsLabel} + + ) + : ( + + {viewDetailsLabel} + + ); } const panels: EuiContextMenuPanelDescriptor[] = [ @@ -59,11 +63,19 @@ export const ViewDetailsPopover = (props: Props) => { setIsPopoverOpen(!isPopoverOpen)}> - <> - {viewDetailsLabel} - - + props.displayAsLink + ? ( + setIsPopoverOpen(!isPopoverOpen)}> + <> + {viewDetailsLabel} + + + ) + : ( + setIsPopoverOpen(!isPopoverOpen)} iconSide="right" iconType="arrowRight"> + {viewDetailsLabel} + + ) } isOpen={isPopoverOpen} closePopover={() => setIsPopoverOpen(false)} From 8e751f542f872223c66083a5e230d84abb994993 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 26 Oct 2023 20:37:23 +0000 Subject: [PATCH 50/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../view_details_popover.tsx | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx index 3dc67ab11d28c..d56d88e67985c 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx @@ -31,17 +31,15 @@ export const ViewDetailsPopover = (props: Props) => { } if (props.warnings.length === 1) { - return props.displayAsLink - ? ( - - {viewDetailsLabel} - - ) - : ( - - {viewDetailsLabel} - - ); + return props.displayAsLink ? ( + + {viewDetailsLabel} + + ) : ( + + {viewDetailsLabel} + + ); } const panels: EuiContextMenuPanelDescriptor[] = [ @@ -63,19 +61,22 @@ export const ViewDetailsPopover = (props: Props) => { setIsPopoverOpen(!isPopoverOpen)}> - <> - {viewDetailsLabel} - - - ) - : ( - setIsPopoverOpen(!isPopoverOpen)} iconSide="right" iconType="arrowRight"> - {viewDetailsLabel} - - ) + props.displayAsLink ? ( + setIsPopoverOpen(!isPopoverOpen)}> + <> + {viewDetailsLabel} + + + ) : ( + setIsPopoverOpen(!isPopoverOpen)} + iconSide="right" + iconType="arrowRight" + > + {viewDetailsLabel} + + ) } isOpen={isPopoverOpen} closePopover={() => setIsPopoverOpen(false)} From a081be437aef8f7f1e6f0576e77c03293191f399 Mon Sep 17 00:00:00 2001 From: nreese Date: Thu, 26 Oct 2023 16:32:05 -0600 Subject: [PATCH 51/53] esnure unique request name --- .../badge_popover_content.test.tsx | 81 ++++++++++++------- .../badge_popover_content.tsx | 12 ++- .../view_details_popover.test.tsx | 15 ++++ .../view_details_popover.tsx | 10 ++- 4 files changed, 87 insertions(+), 31 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx index ff0fdbbc28a1f..cab4ebfcb4c4e 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx @@ -44,36 +44,42 @@ describe('SearchResponseWarningsBadgePopoverContent', () => { }); describe('multiple warnings', () => { - test('Clicking "view details" should open content panel with button to view details for each warning', () => { - const request1MockOpenInInspector = jest.fn(); - const request2MockOpenInInspector = jest.fn(); - const mockOnViewDetailsClick = jest.fn(); - const warnings = [ - { - type: 'incomplete', - requestName: 'My first request', - clusters: { - remote1: { - status: 'partial', - indices: '', - timed_out: false, - }, + const request1MockOpenInInspector = jest.fn(); + const request2MockOpenInInspector = jest.fn(); + const warnings = [ + { + type: 'incomplete', + requestName: 'My first request', + clusters: { + remote1: { + status: 'partial', + indices: '', + timed_out: false, }, - openInInspector: request1MockOpenInInspector, - } as SearchResponseWarning, - { - type: 'incomplete', - requestName: 'My second request', - clusters: { - remote1: { - status: 'partial', - indices: '', - timed_out: false, - }, + }, + openInInspector: request1MockOpenInInspector, + } as SearchResponseWarning, + { + type: 'incomplete', + requestName: 'My second request', + clusters: { + remote1: { + status: 'partial', + indices: '', + timed_out: false, }, - openInInspector: request2MockOpenInInspector, - } as SearchResponseWarning, - ]; + }, + openInInspector: request2MockOpenInInspector, + } as SearchResponseWarning, + ]; + + beforeEach(() => { + request1MockOpenInInspector.mockReset(); + request2MockOpenInInspector.mockReset(); + }); + + test('Clicking "view details" should open content panel with button to view details for each warning', () => { + const mockOnViewDetailsClick = jest.fn(); render( { expect(mockOnViewDetailsClick).toHaveBeenCalled(); expect(request2MockOpenInInspector).not.toHaveBeenCalled(); }); + + test('Should ensure unique request names by numbering duplicate request names', () => { + const warningsWithDuplicateRequestNames = warnings.map(warning => { + return { + ...warning, + requestName: "Request" + }; + }); + render( + + ); + const viewDetailsButton = screen.getByRole('button'); + fireEvent.click(viewDetailsButton); + + screen.getByRole('button', { name: 'Request' }); + screen.getByRole('button', { name: 'Request (2)' }); + }); }); }); diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx index 86c6e87ced64a..3b58bb9ff214b 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx @@ -28,20 +28,28 @@ interface Props { export const SearchResponseWarningsBadgePopoverContent = (props: Props) => { const [openPanel, setOpenPanel] = useState(WARNING_PANEL_ID); + const requestNameMap = new Map(); return (
{openPanel === VIEW_DETAILS_PANEL_ID ? ( { + const count = requestNameMap.has(warning.requestName) + ? requestNameMap.get(warning.requestName) + 1 + : 1; + const uniqueRequestName = count > 1 + ? `${warning.requestName} (${count})` + : warning.requestName + requestNameMap.set(warning.requestName, count); return ( { props.onViewDetailsClick?.(); warning.openInInspector(); }} > - {warning.requestName} + {uniqueRequestName} ); })} diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx index 087f90cd1ab85..8c2141b7846a7 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.test.tsx @@ -107,5 +107,20 @@ describe('ViewDetailsPopover', () => { expect(request1MockOpenInInspector).toHaveBeenCalled(); expect(request2MockOpenInInspector).not.toHaveBeenCalled(); }); + + test('Should ensure unique request names by numbering duplicate request names', () => { + const warningsWithDuplicateRequestNames = warnings.map(warning => { + return { + ...warning, + requestName: "Request" + }; + }); + render(); + const viewDetailsButton = screen.getByRole('button'); + fireEvent.click(viewDetailsButton); + + screen.getByRole('button', { name: 'Request' }); + screen.getByRole('button', { name: 'Request (2)' }); + }); }); }); diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx index d56d88e67985c..913ae303b2d15 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx @@ -42,12 +42,20 @@ export const ViewDetailsPopover = (props: Props) => { ); } + const requestNameMap = new Map(); const panels: EuiContextMenuPanelDescriptor[] = [ { id: 0, items: props.warnings.map((warning) => { + const count = requestNameMap.has(warning.requestName) + ? requestNameMap.get(warning.requestName) + 1 + : 1; + const uniqueRequestName = count > 1 + ? `${warning.requestName} (${count})` + : warning.requestName + requestNameMap.set(warning.requestName, count); return { - name: warning.requestName, + name: uniqueRequestName, onClick: () => { setIsPopoverOpen(false); warning.openInInspector(); From dca584560d2b343b6add7a487bc9ad3bd62f6d90 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 26 Oct 2023 22:37:09 +0000 Subject: [PATCH 52/53] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../badge_popover_content.test.tsx | 10 ++++------ .../search_response_warnings/badge_popover_content.tsx | 5 ++--- .../view_details_popover.test.tsx | 10 ++++++---- .../search_response_warnings/view_details_popover.tsx | 5 ++--- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx index cab4ebfcb4c4e..9bc9cd5cef027 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.test.tsx @@ -100,21 +100,19 @@ describe('SearchResponseWarningsBadgePopoverContent', () => { }); test('Should ensure unique request names by numbering duplicate request names', () => { - const warningsWithDuplicateRequestNames = warnings.map(warning => { + const warningsWithDuplicateRequestNames = warnings.map((warning) => { return { ...warning, - requestName: "Request" + requestName: 'Request', }; }); render( - + ); const viewDetailsButton = screen.getByRole('button'); fireEvent.click(viewDetailsButton); - screen.getByRole('button', { name: 'Request' }); + screen.getByRole('button', { name: 'Request' }); screen.getByRole('button', { name: 'Request (2)' }); }); }); diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx index 3b58bb9ff214b..a555defb92e10 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx @@ -37,9 +37,8 @@ export const SearchResponseWarningsBadgePopoverContent = (props: Props) => { const count = requestNameMap.has(warning.requestName) ? requestNameMap.get(warning.requestName) + 1 : 1; - const uniqueRequestName = count > 1 - ? `${warning.requestName} (${count})` - : warning.requestName + const uniqueRequestName = + count > 1 ? `${warning.requestName} (${count})` : warning.requestName; requestNameMap.set(warning.requestName, count); return ( { }); test('Should ensure unique request names by numbering duplicate request names', () => { - const warningsWithDuplicateRequestNames = warnings.map(warning => { + const warningsWithDuplicateRequestNames = warnings.map((warning) => { return { ...warning, - requestName: "Request" + requestName: 'Request', }; }); - render(); + render( + + ); const viewDetailsButton = screen.getByRole('button'); fireEvent.click(viewDetailsButton); - screen.getByRole('button', { name: 'Request' }); + screen.getByRole('button', { name: 'Request' }); screen.getByRole('button', { name: 'Request (2)' }); }); }); diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx index 913ae303b2d15..36268809212af 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx @@ -50,9 +50,8 @@ export const ViewDetailsPopover = (props: Props) => { const count = requestNameMap.has(warning.requestName) ? requestNameMap.get(warning.requestName) + 1 : 1; - const uniqueRequestName = count > 1 - ? `${warning.requestName} (${count})` - : warning.requestName + const uniqueRequestName = + count > 1 ? `${warning.requestName} (${count})` : warning.requestName; requestNameMap.set(warning.requestName, count); return { name: uniqueRequestName, From 18d8b085b9d6a51d919f879b3ee239e52bd227aa Mon Sep 17 00:00:00 2001 From: nreese Date: Thu, 26 Oct 2023 17:05:48 -0600 Subject: [PATCH 53/53] tslint --- .../search_response_warnings/badge_popover_content.tsx | 2 +- .../search_response_warnings/view_details_popover.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx index a555defb92e10..1c7537cfb64a1 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/badge_popover_content.tsx @@ -35,7 +35,7 @@ export const SearchResponseWarningsBadgePopoverContent = (props: Props) => { { const count = requestNameMap.has(warning.requestName) - ? requestNameMap.get(warning.requestName) + 1 + ? requestNameMap.get(warning.requestName)! + 1 : 1; const uniqueRequestName = count > 1 ? `${warning.requestName} (${count})` : warning.requestName; diff --git a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx index 36268809212af..98c5a08f9b2d8 100644 --- a/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx +++ b/packages/kbn-search-response-warnings/src/components/search_response_warnings/view_details_popover.tsx @@ -48,7 +48,7 @@ export const ViewDetailsPopover = (props: Props) => { id: 0, items: props.warnings.map((warning) => { const count = requestNameMap.has(warning.requestName) - ? requestNameMap.get(warning.requestName) + 1 + ? requestNameMap.get(warning.requestName)! + 1 : 1; const uniqueRequestName = count > 1 ? `${warning.requestName} (${count})` : warning.requestName;