From a3a620421f413a0d462a1bd968fffa6ff9df1822 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 27 Jan 2025 10:03:59 +0800 Subject: [PATCH] [Workspace]fix: recent item links are not correctly constructed (#9275) (#9276) * fix: recent item links are not correctly constructed * Changeset file for PR #9275 created/updated --------- (cherry picked from commit 1ac056a36ec6c243a514323c8b1cc711ec16749b) Signed-off-by: SuZhou-Joe Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> --- changelogs/fragments/9275.yml | 2 ++ src/core/public/chrome/ui/header/header.tsx | 1 + .../chrome/ui/header/recent_items.test.tsx | 23 +++++++++++++++++++ .../public/chrome/ui/header/recent_items.tsx | 8 ++++++- 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/9275.yml diff --git a/changelogs/fragments/9275.yml b/changelogs/fragments/9275.yml new file mode 100644 index 00000000000..73e8ae02961 --- /dev/null +++ b/changelogs/fragments/9275.yml @@ -0,0 +1,2 @@ +fix: +- Recent item links are not correctly constructed ([#9275](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9275)) \ No newline at end of file diff --git a/src/core/public/chrome/ui/header/header.tsx b/src/core/public/chrome/ui/header/header.tsx index 7b5ea93a550..9e07d953908 100644 --- a/src/core/public/chrome/ui/header/header.tsx +++ b/src/core/public/chrome/ui/header/header.tsx @@ -502,6 +502,7 @@ export function Header({ renderBreadcrumbs={renderBreadcrumbs(true, true)} buttonSize={useApplicationHeader ? 's' : 'xs'} loadingCount$={observables.loadingCount$} + workspaceEnabled={application.capabilities.workspaces.enabled} /> ); diff --git a/src/core/public/chrome/ui/header/recent_items.test.tsx b/src/core/public/chrome/ui/header/recent_items.test.tsx index 28bae880fcf..7e9eb12a2be 100644 --- a/src/core/public/chrome/ui/header/recent_items.test.tsx +++ b/src/core/public/chrome/ui/header/recent_items.test.tsx @@ -9,6 +9,7 @@ import { BehaviorSubject } from 'rxjs'; import { applicationServiceMock, httpServiceMock } from '../../../mocks'; import { SavedObjectWithMetadata } from './recent_items'; import { RecentItems } from './recent_items'; +import { createRecentNavLink } from './nav_link'; jest.mock('./nav_link', () => ({ createRecentNavLink: jest.fn().mockImplementation(() => { @@ -171,4 +172,26 @@ describe('Recent items', () => { render(); expect(screen.queryByText('visualizeMock')).not.toBeInTheDocument(); }); + + it('workspace feature flag should be passed to createRecentNavLink correctly', async () => { + jest.clearAllMocks(); + const { getByTestId, findByText, getByText } = render( + + ); + fireEvent.click(getByTestId('recentItemsSectionButton')); + await findByText('Recent assets'); + fireEvent.click(getByText('visualizeMock')); + expect(createRecentNavLink).toBeCalledWith( + expect.anything(), + expect.anything(), + expect.anything(), + expect.anything(), + true + ); + }); }); diff --git a/src/core/public/chrome/ui/header/recent_items.tsx b/src/core/public/chrome/ui/header/recent_items.tsx index 76dc3bcb341..5b4e88d0d40 100644 --- a/src/core/public/chrome/ui/header/recent_items.tsx +++ b/src/core/public/chrome/ui/header/recent_items.tsx @@ -45,6 +45,7 @@ export interface Props { buttonSize?: EuiHeaderSectionItemButtonProps['size']; http: HttpStart; loadingCount$: Rx.Observable; + workspaceEnabled?: boolean; } interface SavedObjectMetadata { @@ -112,6 +113,7 @@ export const RecentItems = ({ buttonSize = 's', http, loadingCount$, + workspaceEnabled, }: Props) => { const [isPopoverOpen, setIsPopoverOpen] = useState(false); const [isPreferencesPopoverOpen, setIsPreferencesPopoverOpen] = useState(false); @@ -143,6 +145,9 @@ export const RecentItems = ({ }} iconType="managementApp" data-test-subj="preferencesSettingButton" + aria-label={i18n.translate('core.header.recent.preferences.buttonAriaLabel', { + defaultMessage: 'Preferences setting', + })} /> } isOpen={isPreferencesPopoverOpen} @@ -296,7 +301,8 @@ export const RecentItems = ({ item, navLinks.filter((link) => !link.hidden), basePath, - navigateToUrl + navigateToUrl, + !!workspaceEnabled ).href ) }