From e9ad10ffb22f358e05d883f9ad8998e169e45fd0 Mon Sep 17 00:00:00 2001 From: Anan Zhuang Date: Wed, 30 Aug 2023 18:50:19 -0700 Subject: [PATCH] [Data Explorer][Discover 2.0] Append popout icon to oui link for doc viewer links (#4855) * [Data Explorer][Discover 2.0] Append popout icon to oui link for doc viewer links Issue Resolve https://github.com/opensearch-project/OpenSearch-Dashboards/issues/4825 Signed-off-by: ananzh * fix all failed ut Signed-off-by: ananzh --------- Signed-off-by: ananzh --- .../data_grid_table_columns.test.tsx | 72 ++++++++++++------- .../doc_viewer_links.test.tsx.snap | 34 +++++---- .../doc_viewer_links/doc_viewer_links.tsx | 8 ++- .../utils/state_management/common.test.ts | 10 +-- .../state_management/discover_slice.test.tsx | 2 +- 5 files changed, 74 insertions(+), 52 deletions(-) diff --git a/src/plugins/discover/public/application/components/data_grid/data_grid_table_columns.test.tsx b/src/plugins/discover/public/application/components/data_grid/data_grid_table_columns.test.tsx index 9a53bff57e16..3123b0a1a210 100644 --- a/src/plugins/discover/public/application/components/data_grid/data_grid_table_columns.test.tsx +++ b/src/plugins/discover/public/application/components/data_grid/data_grid_table_columns.test.tsx @@ -57,9 +57,12 @@ describe('Testing buildDataGridColumns function ', () => { Array [ Object { "actions": Object { - "showHide": true, - "showMoveLeft": false, - "showMoveRight": false, + "showHide": Object { + "iconType": "cross", + "label": "Remove column", + }, + "showMoveLeft": true, + "showMoveRight": true, }, "cellActions": undefined, "display": undefined, @@ -69,9 +72,12 @@ describe('Testing buildDataGridColumns function ', () => { }, Object { "actions": Object { - "showHide": true, - "showMoveLeft": false, - "showMoveRight": false, + "showHide": Object { + "iconType": "cross", + "label": "Remove column", + }, + "showMoveLeft": true, + "showMoveRight": true, }, "cellActions": undefined, "display": undefined, @@ -98,9 +104,9 @@ describe('Testing buildDataGridColumns function ', () => { Array [ Object { "actions": Object { - "showHide": true, - "showMoveLeft": false, - "showMoveRight": false, + "showHide": false, + "showMoveLeft": true, + "showMoveRight": true, }, "cellActions": undefined, "display": "Time (order_date)", @@ -111,9 +117,12 @@ describe('Testing buildDataGridColumns function ', () => { }, Object { "actions": Object { - "showHide": true, - "showMoveLeft": false, - "showMoveRight": false, + "showHide": Object { + "iconType": "cross", + "label": "Remove column", + }, + "showMoveLeft": true, + "showMoveRight": true, }, "cellActions": undefined, "display": undefined, @@ -123,9 +132,12 @@ describe('Testing buildDataGridColumns function ', () => { }, Object { "actions": Object { - "showHide": true, - "showMoveLeft": false, - "showMoveRight": false, + "showHide": Object { + "iconType": "cross", + "label": "Remove column", + }, + "showMoveLeft": true, + "showMoveRight": true, }, "cellActions": undefined, "display": undefined, @@ -135,9 +147,9 @@ describe('Testing buildDataGridColumns function ', () => { }, Object { "actions": Object { - "showHide": true, - "showMoveLeft": false, - "showMoveRight": false, + "showHide": false, + "showMoveLeft": true, + "showMoveRight": true, }, "cellActions": undefined, "display": "Source", @@ -162,9 +174,12 @@ describe('Testing buildDataGridColumns function ', () => { Array [ Object { "actions": Object { - "showHide": true, - "showMoveLeft": false, - "showMoveRight": false, + "showHide": Object { + "iconType": "cross", + "label": "Remove column", + }, + "showMoveLeft": true, + "showMoveRight": true, }, "cellActions": undefined, "display": undefined, @@ -174,9 +189,12 @@ describe('Testing buildDataGridColumns function ', () => { }, Object { "actions": Object { - "showHide": true, - "showMoveLeft": false, - "showMoveRight": false, + "showHide": Object { + "iconType": "cross", + "label": "Remove column", + }, + "showMoveLeft": true, + "showMoveRight": true, }, "cellActions": undefined, "display": undefined, @@ -186,9 +204,9 @@ describe('Testing buildDataGridColumns function ', () => { }, Object { "actions": Object { - "showHide": true, - "showMoveLeft": false, - "showMoveRight": false, + "showHide": false, + "showMoveLeft": true, + "showMoveRight": true, }, "cellActions": undefined, "display": "Time (order_date)", diff --git a/src/plugins/discover/public/application/components/doc_viewer_links/__snapshots__/doc_viewer_links.test.tsx.snap b/src/plugins/discover/public/application/components/doc_viewer_links/__snapshots__/doc_viewer_links.test.tsx.snap index 2a3b5a3aa998..075cafd37471 100644 --- a/src/plugins/discover/public/application/components/doc_viewer_links/__snapshots__/doc_viewer_links.test.tsx.snap +++ b/src/plugins/discover/public/application/components/doc_viewer_links/__snapshots__/doc_viewer_links.test.tsx.snap @@ -2,37 +2,47 @@ exports[`Dont Render if generateCb.hide 1`] = ` `; exports[`Render with 2 different links 1`] = ` - + style={ + Object { + "fontWeight": "normal", + } + } + target="_blank" + > + generateCb link + - + style={ + Object { + "fontWeight": "normal", + } + } + target="_blank" + > + href link + `; diff --git a/src/plugins/discover/public/application/components/doc_viewer_links/doc_viewer_links.tsx b/src/plugins/discover/public/application/components/doc_viewer_links/doc_viewer_links.tsx index f529273991a0..ea4262814bb4 100644 --- a/src/plugins/discover/public/application/components/doc_viewer_links/doc_viewer_links.tsx +++ b/src/plugins/discover/public/application/components/doc_viewer_links/doc_viewer_links.tsx @@ -4,7 +4,7 @@ */ import React from 'react'; -import { EuiFlexGroup, EuiFlexItem, EuiListGroupItem, EuiListGroupItemProps } from '@elastic/eui'; +import { EuiFlexGroup, EuiFlexItem, EuiListGroupItemProps, EuiLink } from '@elastic/eui'; import { getDocViewsLinksRegistry } from '../../../opensearch_dashboards_services'; import { DocViewLinkRenderProps } from '../../doc_views_links/doc_views_links_types'; @@ -24,10 +24,12 @@ export function DocViewerLinks(renderProps: DocViewLinkRenderProps) { }); return ( - + {listItems.map((item, index) => ( - + + {item.label} + ))} diff --git a/src/plugins/discover/public/application/utils/state_management/common.test.ts b/src/plugins/discover/public/application/utils/state_management/common.test.ts index c1190f891648..64a2dba99dd4 100644 --- a/src/plugins/discover/public/application/utils/state_management/common.test.ts +++ b/src/plugins/discover/public/application/utils/state_management/common.test.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { addColumn, removeColumn, reorderColumn, setColumns } from './common'; +import { addColumn, removeColumn, reorderColumn } from './common'; describe('commonUtils', () => { it('should handle addColumn', () => { @@ -22,12 +22,4 @@ describe('commonUtils', () => { 'column1', ]); }); - - it('should handle setColumns', () => { - expect(setColumns('timeField', ['timeField', 'column1', 'column2'])).toEqual([ - 'column1', - 'column2', - ]); - expect(setColumns(undefined, ['column1', 'column2'])).toEqual(['column1', 'column2']); - }); }); diff --git a/src/plugins/discover/public/application/utils/state_management/discover_slice.test.tsx b/src/plugins/discover/public/application/utils/state_management/discover_slice.test.tsx index 1e2e4ab46a55..cbfc9c3769b0 100644 --- a/src/plugins/discover/public/application/utils/state_management/discover_slice.test.tsx +++ b/src/plugins/discover/public/application/utils/state_management/discover_slice.test.tsx @@ -58,7 +58,7 @@ describe('discoverSlice', () => { it('should handle setColumns', () => { const action = { type: 'discover/setColumns', - payload: { timeField: 'timeField', columns: ['timeField', 'column1', 'column2'] }, + payload: { columns: ['column1', 'column2'] }, }; const result = discoverSlice.reducer(initialState, action); expect(result.columns).toEqual(['column1', 'column2']);