From b8d30dca94fed757423f871f099cffef841d6477 Mon Sep 17 00:00:00 2001 From: Willie Hung Date: Wed, 13 Dec 2023 11:16:29 -0600 Subject: [PATCH 1/9] Remove redundant icon component (#5511) Signed-off-by: Willie Hung --- src/plugins/vis_type_markdown/public/markdown_options.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/vis_type_markdown/public/markdown_options.tsx b/src/plugins/vis_type_markdown/public/markdown_options.tsx index e6205786f78c..4c038d2c4a8c 100644 --- a/src/plugins/vis_type_markdown/public/markdown_options.tsx +++ b/src/plugins/vis_type_markdown/public/markdown_options.tsx @@ -73,7 +73,6 @@ function MarkdownOptions({ stateParams, setValue }: VisOptionsProps{' '} - From 478176ab553045e7e8e7b515f6c55b46e2bff2d4 Mon Sep 17 00:00:00 2001 From: Willie Hung Date: Wed, 13 Dec 2023 14:23:31 -0600 Subject: [PATCH 2/9] [Fix] Inactive State on 'Discover' Tab in Side Navigation Menu (#5432) * Fix active background render error * Update CHANGELOG.md * Revise test suit * Add isActive logic * Remove redundant tests and add comment for future reference * Update src/core/public/chrome/ui/header/nav_link.tsx * Seperate special cases from logic && revise test * Update CHANGELOG.md * Update src/core/public/chrome/ui/header/nav_link.tsx Co-authored-by: SuZhou-Joe Signed-off-by: Willie Hung --------- Signed-off-by: Willie Hung Signed-off-by: Josh Romero Co-authored-by: Josh Romero Co-authored-by: SuZhou-Joe --- CHANGELOG.md | 1 + .../public/chrome/ui/header/nav_link.test.tsx | 63 +++++++++++++++++++ src/core/public/chrome/ui/header/nav_link.tsx | 10 ++- 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/core/public/chrome/ui/header/nav_link.test.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c3235a2cca5..64ca3b02bf54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Cleanup unused url ([#3847](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3847)) - [TSVB, Dashboards] Fix inconsistent dark mode code editor themes ([#4609](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4609)) - Fix `maps.proxyOpenSearchMapsServiceInMaps` config definition so it can be set ([#5170](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5170)) +- [Discover] Fix inactive state on 'Discover' tab in side navigation menu ([#5432](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5432)) - [BUG] Add platform "darwin-arm64" to unit test ([#5290](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5290)) - [BUG][Dev Tool] Add dev tool documentation link to dev tool's help menu [#5166](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5166) - Fix missing border for header navigation control on right ([#5450](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5450)) diff --git a/src/core/public/chrome/ui/header/nav_link.test.tsx b/src/core/public/chrome/ui/header/nav_link.test.tsx new file mode 100644 index 000000000000..a89bdc01d5bb --- /dev/null +++ b/src/core/public/chrome/ui/header/nav_link.test.tsx @@ -0,0 +1,63 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { isActiveNavLink, createEuiListItem } from './nav_link'; +import { ChromeNavLink } from '../../..'; +import { httpServiceMock } from '../../../http/http_service.mock'; + +describe('isActiveNavLink', () => { + it('should return true if the appId is "discover" and linkId is "discover"', () => { + expect(isActiveNavLink('discover', 'discover')).toBe(true); + }); + + it('should return true if the appId is "data-explorer" and linkId is "data-explorer"', () => { + expect(isActiveNavLink('data-explorer', 'data-explorer')).toBe(true); + }); + + it('should return true if the appId is "data-explorer" and linkId is "discover"', () => { + expect(isActiveNavLink('data-explorer', 'discover')).toBe(true); + }); + + it('should return false if the appId and linkId do not match', () => { + expect(isActiveNavLink('dashboard', 'discover')).toBe(false); + }); +}); + +const mockBasePath = httpServiceMock.createSetupContract({ basePath: '/test' }).basePath; + +describe('createEuiListItem', () => { + const mockLink: Partial = { + href: 'test', + id: 'test', + title: 'Test App', + disabled: false, + euiIconType: 'inputOutput', + icon: 'testIcon', + tooltip: 'Test App Tooltip', + }; + + const mockProps = { + link: mockLink as ChromeNavLink, + appId: 'test', + basePath: mockBasePath, + dataTestSubj: 'test-subj', + onClick: jest.fn(), + navigateToApp: jest.fn(), + externalLink: false, + }; + + it('creates a list item with the correct properties', () => { + const listItem = createEuiListItem(mockProps); + expect(listItem).toHaveProperty('label', mockProps.link.tooltip); + expect(listItem).toHaveProperty('href', mockProps.link.href); + expect(listItem).toHaveProperty('data-test-subj', mockProps.dataTestSubj); + expect(listItem).toHaveProperty('onClick'); + expect(listItem).toHaveProperty( + 'isActive', + isActiveNavLink(mockProps.appId, mockProps.link.id) + ); + expect(listItem).toHaveProperty('isDisabled', mockProps.link.disabled); + }); +}); diff --git a/src/core/public/chrome/ui/header/nav_link.tsx b/src/core/public/chrome/ui/header/nav_link.tsx index 11ff0b472bd0..38d31dbc09c9 100644 --- a/src/core/public/chrome/ui/header/nav_link.tsx +++ b/src/core/public/chrome/ui/header/nav_link.tsx @@ -39,6 +39,14 @@ import { relativeToAbsolute } from '../../nav_links/to_nav_link'; export const isModifiedOrPrevented = (event: React.MouseEvent) => event.metaKey || event.altKey || event.ctrlKey || event.shiftKey || event.defaultPrevented; +// TODO: replace hard-coded values with a registration function, so that apps can control active nav links similar to breadcrumbs +const aliasedApps: { [key: string]: string[] } = { + discover: ['data-explorer'], +}; + +export const isActiveNavLink = (appId: string | undefined, linkId: string): boolean => + !!(appId === linkId || aliasedApps[linkId]?.includes(appId || '')); + interface Props { link: ChromeNavLink; appId?: string; @@ -82,7 +90,7 @@ export function createEuiListItem({ navigateToApp(id); } }, - isActive: appId === id, + isActive: isActiveNavLink(appId, id), isDisabled: disabled, 'data-test-subj': dataTestSubj, ...(basePath && { From 808591a245da5d2d58ca327c39509b283a56e116 Mon Sep 17 00:00:00 2001 From: Willie Hung Date: Wed, 13 Dec 2023 15:04:08 -0600 Subject: [PATCH 3/9] [Fix] Remove empty suggestion history (#5349) * Add search input filter Signed-off-by: Willie Hung * Add CHANGELOG.md Signed-off-by: Willie Hung * Add tests for empty suggestions Signed-off-by: Willie Hung * Add code comment Signed-off-by: Willie Hung --------- Signed-off-by: Willie Hung Signed-off-by: Josh Romero Signed-off-by: Anan Zhuang Co-authored-by: Josh Romero Co-authored-by: Anan Zhuang --- CHANGELOG.md | 1 + .../typeahead/suggestion_component.test.tsx | 41 +++++++++++++++++++ .../ui/typeahead/suggestion_component.tsx | 7 ++++ 3 files changed, 49 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64ca3b02bf54..aed16fbe88f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fix missing border for header navigation control on right ([#5450](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5450)) - [BUG] Fix filtering issue in data source selector ([5484](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5484)) - [BUG][Data] Support for custom filters with heterogeneous data fields ([5577](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5577)) +- [BUG][Data] Fix empty suggestion history when querying in search bar [#5349](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5349) ### 🚞 Infrastructure diff --git a/src/plugins/data/public/ui/typeahead/suggestion_component.test.tsx b/src/plugins/data/public/ui/typeahead/suggestion_component.test.tsx index 9769e4a19346..f75007444f48 100644 --- a/src/plugins/data/public/ui/typeahead/suggestion_component.test.tsx +++ b/src/plugins/data/public/ui/typeahead/suggestion_component.test.tsx @@ -45,6 +45,14 @@ const mockSuggestion: QuerySuggestion = { type: QuerySuggestionTypes.Value, }; +const mockEmptySuggestion: QuerySuggestion = { + description: '', + end: 0, + start: 0, + text: '', + type: QuerySuggestionTypes.Value, +}; + describe('SuggestionComponent', () => { it('Should display the suggestion and use the provided ariaId', () => { const component = shallow( @@ -135,4 +143,37 @@ describe('SuggestionComponent', () => { component.simulate('mouseenter'); expect(mockHandler).toHaveBeenCalledTimes(1); }); + + it('Should return null for empty suggestion text', () => { + const component = shallow( + + ); + + expect(component.isEmptyRender()).toBeTruthy(); + }); + + it('Should return null for suggestion text with only whitespace', () => { + const whitespaceSuggestion = { ...mockEmptySuggestion, text: ' ' }; + const component = shallow( + + ); + + expect(component.isEmptyRender()).toBeTruthy(); + }); }); diff --git a/src/plugins/data/public/ui/typeahead/suggestion_component.tsx b/src/plugins/data/public/ui/typeahead/suggestion_component.tsx index 7d97f5b58283..67243df6415a 100644 --- a/src/plugins/data/public/ui/typeahead/suggestion_component.tsx +++ b/src/plugins/data/public/ui/typeahead/suggestion_component.tsx @@ -61,6 +61,13 @@ interface Props { } export function SuggestionComponent(props: Props) { + // Removing empty suggestions from the history is for maintaining a clean user experience. + // Empty suggestions, which typically result from inadvertent keystrokes or incomplete queries, + // do not provide value to the user. + if (!props.suggestion.text.trim()) { + return null; + } + return ( // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/interactive-supports-focus
Date: Wed, 13 Dec 2023 18:09:43 -0500 Subject: [PATCH 4/9] [OSCI][ADD] More tests for overview (#5418) * add more tests for overview * add more tests for overview * add to CHANGELOG * change log --------- Signed-off-by: Thanh Le Signed-off-by: Josh Romero Co-authored-by: Josh Romero --- CHANGELOG.md | 2 + .../__snapshots__/overview.test.tsx.snap | 5398 +++++++++++++++-- .../components/overview/overview.test.tsx | 61 +- 3 files changed, 4827 insertions(+), 634 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aed16fbe88f9..102205566e80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### 🔩 Tests +- [Home] Add more unit tests for other complications of overview ([#5418](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5418)) + ## [2.11.1 - 2023-11-21](https://github.com/opensearch-project/OpenSearch-Dashboards/releases/tag/2.11.1) ### 🛡 Security diff --git a/src/plugins/opensearch_dashboards_overview/public/components/overview/__snapshots__/overview.test.tsx.snap b/src/plugins/opensearch_dashboards_overview/public/components/overview/__snapshots__/overview.test.tsx.snap index 6d92c8759243..1619a4fea3ff 100644 --- a/src/plugins/opensearch_dashboards_overview/public/components/overview/__snapshots__/overview.test.tsx.snap +++ b/src/plugins/opensearch_dashboards_overview/public/components/overview/__snapshots__/overview.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Overview renders with solutions and features 1`] = ` +exports[`Overview renders with news without solutions and without features 1`] = `
-
- -

- -

-
- - - - - - } - image="/plugins/opensearchDashboardsOverview/assets/solutions_opensearch_dashboards_light_2x.png" - title="OpenSearch Dashboards" - titleElement="h3" - titleSize="xs" - /> - - - - - - } - image="/plugins/opensearchDashboardsOverview/assets/solutions_solution_2_light_2x.png" - title="Solution two" - titleElement="h3" - titleSize="xs" - /> - - - - - - } - image="/plugins/opensearchDashboardsOverview/assets/solutions_solution_3_light_2x.png" - title="Solution three" - titleElement="h3" - titleSize="xs" - /> - - - - - - } - image="/plugins/opensearchDashboardsOverview/assets/solutions_solution_4_light_2x.png" - title="Solution four" - titleElement="h3" - titleSize="xs" - /> - - - -
- - -
+ +`; + +exports[`Overview renders with news, solutions, and features 1`] = ` +
+ + } + /> +
+
+ +

+ +

+
+ + +
+
+
+`; + +exports[`Overview renders with news, with solutions, and without features 1`] = ` +
+ + } + /> +
+
+ +

+ +

+
+ + +
+
+
+`; + +exports[`Overview renders with news, without solutions, and with features 1`] = ` +
+ + } + /> +
+
+ +

+ +

+
+ + +
+
+
+`; + +exports[`Overview renders without news and features, with solutions 1`] = ` +
+ + } + /> +
+
+ +

+ +

+
+ + +
+
+
+`; + +exports[`Overview renders without news and solutions, with features 1`] = ` +
+ + } + /> +
+
+ +

+ +

+
+ + +
+