Skip to content

Commit

Permalink
[Workspace]fix: recent item links are not correctly constructed (#9275)
Browse files Browse the repository at this point in the history
* fix: recent item links are not correctly constructed

Signed-off-by: SuZhou-Joe <[email protected]>

* Changeset file for PR #9275 created/updated

---------

Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
1 parent c91df47 commit 1ac056a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/9275.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Recent item links are not correctly constructed ([#9275](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9275))
1 change: 1 addition & 0 deletions src/core/public/chrome/ui/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ export function Header({
renderBreadcrumbs={renderBreadcrumbs(true, true)}
buttonSize={useApplicationHeader ? 's' : 'xs'}
loadingCount$={observables.loadingCount$}
workspaceEnabled={application.capabilities.workspaces.enabled}
/>
</EuiHeaderSectionItem>
);
Expand Down
23 changes: 23 additions & 0 deletions src/core/public/chrome/ui/header/recent_items.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -171,4 +172,26 @@ describe('Recent items', () => {
render(<RecentItems {...defaultMockProps} recentlyAccessed$={mockRecentlyAccessed$} />);
expect(screen.queryByText('visualizeMock')).not.toBeInTheDocument();
});

it('workspace feature flag should be passed to createRecentNavLink correctly', async () => {
jest.clearAllMocks();
const { getByTestId, findByText, getByText } = render(
<RecentItems
{...defaultMockProps}
workspaceEnabled
recentlyAccessed$={mockRecentlyAccessed$}
workspaceList$={mockWorkspaceList$}
/>
);
fireEvent.click(getByTestId('recentItemsSectionButton'));
await findByText('Recent assets');
fireEvent.click(getByText('visualizeMock'));
expect(createRecentNavLink).toBeCalledWith(
expect.anything(),
expect.anything(),
expect.anything(),
expect.anything(),
true
);
});
});
8 changes: 7 additions & 1 deletion src/core/public/chrome/ui/header/recent_items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface Props {
buttonSize?: EuiHeaderSectionItemButtonProps['size'];
http: HttpStart;
loadingCount$: Rx.Observable<number>;
workspaceEnabled?: boolean;
}

interface SavedObjectMetadata {
Expand Down Expand Up @@ -112,6 +113,7 @@ export const RecentItems = ({
buttonSize = 's',
http,
loadingCount$,
workspaceEnabled,
}: Props) => {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const [isPreferencesPopoverOpen, setIsPreferencesPopoverOpen] = useState(false);
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -296,7 +301,8 @@ export const RecentItems = ({
item,
navLinks.filter((link) => !link.hidden),
basePath,
navigateToUrl
navigateToUrl,
!!workspaceEnabled
).href
)
}
Expand Down

0 comments on commit 1ac056a

Please sign in to comment.