From 4707faca061d196fe962907c4074590d757df97d Mon Sep 17 00:00:00 2001 From: Kapian1234 Date: Wed, 11 Sep 2024 16:25:20 +0800 Subject: [PATCH 01/13] Hide global objects in recent assets when workspace enabled, and jump to the global for workspace objects hwen workspace disabled Signed-off-by: Kapian1234 --- src/core/public/chrome/ui/header/nav_link.tsx | 12 ++++++++---- .../public/management_section/recent_work.tsx | 7 ++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/core/public/chrome/ui/header/nav_link.tsx b/src/core/public/chrome/ui/header/nav_link.tsx index a80ce86507aa..f83671fbec02 100644 --- a/src/core/public/chrome/ui/header/nav_link.tsx +++ b/src/core/public/chrome/ui/header/nav_link.tsx @@ -125,13 +125,17 @@ export function createRecentNavLink( recentLink: ChromeRecentlyAccessedHistoryItem, navLinks: ChromeNavLink[], basePath: HttpStart['basePath'], - navigateToUrl: InternalApplicationStart['navigateToUrl'] + navigateToUrl: InternalApplicationStart['navigateToUrl'], + workspaceEnabled: boolean = true ): RecentNavLink { const { link, label, workspaceId } = recentLink; const href = relativeToAbsolute( - basePath.prepend(formatUrlWithWorkspaceId(link, workspaceId || '', basePath), { - withoutClientBasePath: true, - }) + basePath.prepend( + formatUrlWithWorkspaceId(link, workspaceEnabled ? workspaceId || '' : '', basePath), + { + withoutClientBasePath: true, + } + ) ); const navLink = navLinks.find((nl) => href.startsWith(nl.baseUrl)); let titleAndAriaLabel = label; diff --git a/src/plugins/saved_objects_management/public/management_section/recent_work.tsx b/src/plugins/saved_objects_management/public/management_section/recent_work.tsx index 88cdfc142af4..54b36f053293 100644 --- a/src/plugins/saved_objects_management/public/management_section/recent_work.tsx +++ b/src/plugins/saved_objects_management/public/management_section/recent_work.tsx @@ -124,10 +124,11 @@ export const RecentWork = (props: { core: CoreStart; workspaceEnabled?: boolean .filter((item) => !item.error) .sort(sortBy(sortKeyMap[selectedSort])); return sortedResult.filter((item: SavedObject & ChromeRecentlyAccessedHistoryItem) => { + if (workspaceEnabled && !item.workspaces) return false; if (selectedType === allOption) return true; return item.type === selectedType; }); - }, [detailedSavedObjects, selectedSort, selectedType]); + }, [detailedSavedObjects, selectedSort, selectedType, workspaceEnabled]); useEffect(() => { const savedObjects = recentAccessed @@ -232,9 +233,9 @@ export const RecentWork = (props: { core: CoreStart; workspaceEnabled?: boolean recentAccessItem, navLinks, core.http.basePath, - core.application.navigateToUrl + core.application.navigateToUrl, + workspaceEnabled ? true : false ); - content = ( Date: Wed, 11 Sep 2024 08:38:16 +0000 Subject: [PATCH 02/13] Changeset file for PR #8136 created/updated --- changelogs/fragments/8136.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/8136.yml diff --git a/changelogs/fragments/8136.yml b/changelogs/fragments/8136.yml new file mode 100644 index 000000000000..430f5df387aa --- /dev/null +++ b/changelogs/fragments/8136.yml @@ -0,0 +1,2 @@ +fix: +- Fix the display and jump logic for recent assets ([#8136](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8136)) \ No newline at end of file From 5a07c113cec2e8099e399f8e5e30f7e85c1e71bd Mon Sep 17 00:00:00 2001 From: Kapian1234 Date: Thu, 12 Sep 2024 10:33:31 +0800 Subject: [PATCH 03/13] Update recently-accessed-service Signed-off-by: Kapian1234 --- src/core/public/chrome/chrome_service.tsx | 2 +- .../recently_accessed_service.ts | 17 +++++++++++++---- .../public/management_section/recent_work.tsx | 5 ++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/core/public/chrome/chrome_service.tsx b/src/core/public/chrome/chrome_service.tsx index e737ecec2891..ffca246df884 100644 --- a/src/core/public/chrome/chrome_service.tsx +++ b/src/core/public/chrome/chrome_service.tsx @@ -246,7 +246,7 @@ export class ChromeService { const navControls = this.navControls.start(); const navLinks = this.navLinks.start({ application, http }); - const recentlyAccessed = await this.recentlyAccessed.start({ http, workspaces }); + const recentlyAccessed = await this.recentlyAccessed.start({ http, workspaces, application }); const docTitle = this.docTitle.start({ document: window.document }); const navGroup = await this.navGroup.start({ navLinks, diff --git a/src/core/public/chrome/recently_accessed/recently_accessed_service.ts b/src/core/public/chrome/recently_accessed/recently_accessed_service.ts index 99ca61513855..3e3a4507a825 100644 --- a/src/core/public/chrome/recently_accessed/recently_accessed_service.ts +++ b/src/core/public/chrome/recently_accessed/recently_accessed_service.ts @@ -29,11 +29,12 @@ */ import { Observable } from 'rxjs'; - +import { map } from 'rxjs/operators'; import { PersistedLog } from './persisted_log'; import { createLogKey } from './create_log_key'; import { HttpSetup } from '../../http'; import { WorkspacesStart } from '../../workspace'; +import { InternalApplicationStart } from '../../application'; /** @public */ export interface ChromeRecentlyAccessedHistoryItem { @@ -50,16 +51,18 @@ export interface ChromeRecentlyAccessedHistoryItem { interface StartDeps { http: HttpSetup; workspaces: WorkspacesStart; + application: InternalApplicationStart; } /** @internal */ export class RecentlyAccessedService { - async start({ http, workspaces }: StartDeps): Promise { + async start({ http, workspaces, application }: StartDeps): Promise { const logKey = await createLogKey('recentlyAccessed', http.basePath.getBasePath()); const history = new PersistedLog(logKey, { maxLength: 20, isEqual: (oldItem, newItem) => oldItem.id === newItem.id, }); + const workspaceEnabled = application.capabilities.workspaces.enabled; return { /** Adds a new item to the history. */ @@ -81,10 +84,16 @@ export class RecentlyAccessedService { }, /** Gets the current array of history items. */ - get: () => history.get(), + get: () => history.get().filter((item) => item.workspaceId), /** Gets an observable of the current array of history items. */ - get$: () => history.get$(), + get$: () => { + return history.get$().pipe( + map((items) => { + return items.filter((item) => (workspaceEnabled ? !!item.workspaceId : true)); + }) + ); + }, }; } } diff --git a/src/plugins/saved_objects_management/public/management_section/recent_work.tsx b/src/plugins/saved_objects_management/public/management_section/recent_work.tsx index 54b36f053293..b529894f5b57 100644 --- a/src/plugins/saved_objects_management/public/management_section/recent_work.tsx +++ b/src/plugins/saved_objects_management/public/management_section/recent_work.tsx @@ -124,11 +124,10 @@ export const RecentWork = (props: { core: CoreStart; workspaceEnabled?: boolean .filter((item) => !item.error) .sort(sortBy(sortKeyMap[selectedSort])); return sortedResult.filter((item: SavedObject & ChromeRecentlyAccessedHistoryItem) => { - if (workspaceEnabled && !item.workspaces) return false; if (selectedType === allOption) return true; return item.type === selectedType; }); - }, [detailedSavedObjects, selectedSort, selectedType, workspaceEnabled]); + }, [detailedSavedObjects, selectedSort, selectedType]); useEffect(() => { const savedObjects = recentAccessed @@ -234,7 +233,7 @@ export const RecentWork = (props: { core: CoreStart; workspaceEnabled?: boolean navLinks, core.http.basePath, core.application.navigateToUrl, - workspaceEnabled ? true : false + !!workspaceEnabled ); content = ( Date: Thu, 12 Sep 2024 10:41:59 +0800 Subject: [PATCH 04/13] fix the boolean value Signed-off-by: Kapian1234 --- .../chrome/recently_accessed/recently_accessed_service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/public/chrome/recently_accessed/recently_accessed_service.ts b/src/core/public/chrome/recently_accessed/recently_accessed_service.ts index 3e3a4507a825..53b6ffbcde6e 100644 --- a/src/core/public/chrome/recently_accessed/recently_accessed_service.ts +++ b/src/core/public/chrome/recently_accessed/recently_accessed_service.ts @@ -84,7 +84,7 @@ export class RecentlyAccessedService { }, /** Gets the current array of history items. */ - get: () => history.get().filter((item) => item.workspaceId), + get: () => history.get().filter((item) => !!item.workspaceId), /** Gets an observable of the current array of history items. */ get$: () => { From 3340ea8f14ccf3c72aa7387450c92b154c374cb8 Mon Sep 17 00:00:00 2001 From: Kapian1234 Date: Thu, 12 Sep 2024 13:07:14 +0800 Subject: [PATCH 05/13] add unit test and fix some bugs Signed-off-by: Kapian1234 --- .../recently_accessed_service.test.ts | 34 ++++++++++++++++++- .../recently_accessed_service.ts | 2 +- src/core/public/chrome/ui/header/nav_link.tsx | 2 +- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/core/public/chrome/recently_accessed/recently_accessed_service.test.ts b/src/core/public/chrome/recently_accessed/recently_accessed_service.test.ts index 9dba64ec5657..9a44d3abb201 100644 --- a/src/core/public/chrome/recently_accessed/recently_accessed_service.test.ts +++ b/src/core/public/chrome/recently_accessed/recently_accessed_service.test.ts @@ -65,6 +65,7 @@ class LocalStorageMock implements Storage { describe('RecentlyAccessed#start()', () => { let originalLocalStorage: Storage; + let workspaceEnabled = false; beforeAll(() => { originalLocalStorage = window.localStorage; @@ -78,7 +79,19 @@ describe('RecentlyAccessed#start()', () => { const getStart = async () => { const http = httpServiceMock.createStartContract(); const workspaces = workspacesServiceMock.createStartContract(); - const recentlyAccessed = await new RecentlyAccessedService().start({ http, workspaces }); + const application = { + ...jest.requireActual('../../application'), + capabilities: { + workspaces: { + enabled: workspaceEnabled, + }, + }, + }; + const recentlyAccessed = await new RecentlyAccessedService().start({ + http, + workspaces, + application, + }); return { http, recentlyAccessed, workspaces }; }; @@ -160,4 +173,23 @@ Array [ { link: '/app/item1', label: 'Item 1', id: 'item1', workspaceId: 'foo' }, ]); }); + + it('should not show global objects when workspace enabled', async () => { + workspaceEnabled = true; + + const { recentlyAccessed } = await getStart(); + recentlyAccessed.add('/app/item1', 'Item 1', 'item1'); + expect(recentlyAccessed.get()).toEqual([]); + }); + + it('should show global objects when workspace enabled', async () => { + workspaceEnabled = true; + + const { recentlyAccessed, workspaces } = await getStart(); + workspaces.currentWorkspaceId$.next('foo'); + recentlyAccessed.add('/app/item1', 'Item 1', 'item1'); + expect(recentlyAccessed.get()).toEqual([ + { link: '/app/item1', label: 'Item 1', id: 'item1', workspaceId: 'foo' }, + ]); + }); }); diff --git a/src/core/public/chrome/recently_accessed/recently_accessed_service.ts b/src/core/public/chrome/recently_accessed/recently_accessed_service.ts index 53b6ffbcde6e..3b0ccbb157ab 100644 --- a/src/core/public/chrome/recently_accessed/recently_accessed_service.ts +++ b/src/core/public/chrome/recently_accessed/recently_accessed_service.ts @@ -84,7 +84,7 @@ export class RecentlyAccessedService { }, /** Gets the current array of history items. */ - get: () => history.get().filter((item) => !!item.workspaceId), + get: () => history.get().filter((item) => (workspaceEnabled ? !!item.workspaceId : true)), /** Gets an observable of the current array of history items. */ get$: () => { diff --git a/src/core/public/chrome/ui/header/nav_link.tsx b/src/core/public/chrome/ui/header/nav_link.tsx index f83671fbec02..d032fe89072c 100644 --- a/src/core/public/chrome/ui/header/nav_link.tsx +++ b/src/core/public/chrome/ui/header/nav_link.tsx @@ -131,7 +131,7 @@ export function createRecentNavLink( const { link, label, workspaceId } = recentLink; const href = relativeToAbsolute( basePath.prepend( - formatUrlWithWorkspaceId(link, workspaceEnabled ? workspaceId || '' : '', basePath), + workspaceEnabled ? formatUrlWithWorkspaceId(link, workspaceId || '', basePath) : link, { withoutClientBasePath: true, } From 41a1ca48b39fa77969a7ac776b8480675a6558b9 Mon Sep 17 00:00:00 2001 From: Kapian1234 Date: Thu, 12 Sep 2024 13:54:18 +0800 Subject: [PATCH 06/13] rename test cases Signed-off-by: Kapian1234 --- .../recently_accessed/recently_accessed_service.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/public/chrome/recently_accessed/recently_accessed_service.test.ts b/src/core/public/chrome/recently_accessed/recently_accessed_service.test.ts index 9a44d3abb201..c484ef219622 100644 --- a/src/core/public/chrome/recently_accessed/recently_accessed_service.test.ts +++ b/src/core/public/chrome/recently_accessed/recently_accessed_service.test.ts @@ -174,7 +174,7 @@ Array [ ]); }); - it('should not show global objects when workspace enabled', async () => { + it('should not get objects without related workspace when workspace enabled', async () => { workspaceEnabled = true; const { recentlyAccessed } = await getStart(); @@ -182,7 +182,7 @@ Array [ expect(recentlyAccessed.get()).toEqual([]); }); - it('should show global objects when workspace enabled', async () => { + it('should get objects with related workspace when workspace enabled', async () => { workspaceEnabled = true; const { recentlyAccessed, workspaces } = await getStart(); From 37db1579a9545662a4aede7194bf4288b95b8029 Mon Sep 17 00:00:00 2001 From: Kapian1234 Date: Mon, 30 Sep 2024 12:07:31 +0800 Subject: [PATCH 07/13] Pass workspaceEnabled to createRecentNavLink Signed-off-by: Kapian1234 --- src/core/public/chrome/ui/header/collapsible_nav.tsx | 5 ++++- src/core/public/chrome/ui/header/header.tsx | 2 ++ src/core/public/chrome/ui/header/nav_link.tsx | 2 +- src/core/public/chrome/ui/header/recent_items.tsx | 11 ++++++++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/core/public/chrome/ui/header/collapsible_nav.tsx b/src/core/public/chrome/ui/header/collapsible_nav.tsx index 9c9223aa501b..4d4efb8195d8 100644 --- a/src/core/public/chrome/ui/header/collapsible_nav.tsx +++ b/src/core/public/chrome/ui/header/collapsible_nav.tsx @@ -103,6 +103,7 @@ interface Props { navigateToUrl: InternalApplicationStart['navigateToUrl']; customNavLink$: Rx.Observable; logos: Logos; + workspaceEnabled: boolean | undefined; } export function CollapsibleNav({ @@ -118,6 +119,7 @@ export function CollapsibleNav({ navigateToApp, navigateToUrl, logos, + workspaceEnabled, ...observables }: Props) { const navLinks = useObservable(observables.navLinks$, []).filter((link) => !link.hidden); @@ -206,7 +208,8 @@ export function CollapsibleNav({ link, navLinks, basePath, - navigateToUrl + navigateToUrl, + !!workspaceEnabled ); return { diff --git a/src/core/public/chrome/ui/header/header.tsx b/src/core/public/chrome/ui/header/header.tsx index 72d9ba6be3fc..7a4758131174 100644 --- a/src/core/public/chrome/ui/header/header.tsx +++ b/src/core/public/chrome/ui/header/header.tsx @@ -392,6 +392,7 @@ export function Header({ navigateToUrl={application.navigateToUrl} renderBreadcrumbs={renderBreadcrumbs(true, false)} buttonSize={useApplicationHeader ? 's' : 'xs'} + workspaceEnabled={application.capabilities.workspaces.enabled} /> ); @@ -554,6 +555,7 @@ export function Header({ }} customNavLink$={observables.customNavLink$} logos={logos} + workspaceEnabled={application.capabilities.workspaces.enabled} /> )} diff --git a/src/core/public/chrome/ui/header/nav_link.tsx b/src/core/public/chrome/ui/header/nav_link.tsx index d032fe89072c..dc6fa7fdaf35 100644 --- a/src/core/public/chrome/ui/header/nav_link.tsx +++ b/src/core/public/chrome/ui/header/nav_link.tsx @@ -126,7 +126,7 @@ export function createRecentNavLink( navLinks: ChromeNavLink[], basePath: HttpStart['basePath'], navigateToUrl: InternalApplicationStart['navigateToUrl'], - workspaceEnabled: boolean = true + workspaceEnabled: boolean = false ): RecentNavLink { const { link, label, workspaceId } = recentLink; const href = relativeToAbsolute( diff --git a/src/core/public/chrome/ui/header/recent_items.tsx b/src/core/public/chrome/ui/header/recent_items.tsx index 153193780a21..6d7ae4efe886 100644 --- a/src/core/public/chrome/ui/header/recent_items.tsx +++ b/src/core/public/chrome/ui/header/recent_items.tsx @@ -43,6 +43,7 @@ export interface Props { renderBreadcrumbs: React.JSX.Element; buttonSize?: EuiHeaderSectionItemButtonProps['size']; http: HttpStart; + workspaceEnabled: boolean | undefined; } interface SavedObjectMetadata { @@ -109,6 +110,7 @@ export const RecentItems = ({ renderBreadcrumbs, buttonSize = 's', http, + workspaceEnabled, }: Props) => { const [isPopoverOpen, setIsPopoverOpen] = useState(false); const [isPreferencesPopoverOpen, setIsPreferencesPopoverOpen] = useState(false); @@ -213,7 +215,13 @@ export const RecentItems = ({ ...recentAccessItem.meta, updatedAt: moment(obj?.updated_at).valueOf(), workspaceName: findWorkspace?.name, - link: createRecentNavLink(recentAccessItem, navLinks, basePath, navigateToUrl).href, + link: createRecentNavLink( + recentAccessItem, + navLinks, + basePath, + navigateToUrl, + !!workspaceEnabled + ).href, }; }); // here I write this argument to avoid Unnecessary re-rendering @@ -230,6 +238,7 @@ export const RecentItems = ({ http, workspaceList, detailedSavedObjects, + workspaceEnabled, ]); const selectedRecentsItems = useMemo(() => { From 0d046b919d5c54405917b71018f873965d91c821 Mon Sep 17 00:00:00 2001 From: Kapian1234 Date: Mon, 4 Nov 2024 10:13:59 +0800 Subject: [PATCH 08/13] Update unit tests Signed-off-by: Kapian1234 --- .../collapsible_nav.test.tsx.snap | 36 +++++++++---------- .../header/__snapshots__/header.test.tsx.snap | 6 ++-- .../public/chrome/ui/header/nav_link.test.tsx | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/core/public/chrome/ui/header/__snapshots__/collapsible_nav.test.tsx.snap b/src/core/public/chrome/ui/header/__snapshots__/collapsible_nav.test.tsx.snap index 1108d8184df4..607e854572a0 100644 --- a/src/core/public/chrome/ui/header/__snapshots__/collapsible_nav.test.tsx.snap +++ b/src/core/public/chrome/ui/header/__snapshots__/collapsible_nav.test.tsx.snap @@ -697,7 +697,7 @@ exports[`CollapsibleNav renders links grouped by category 1`] = ` Object { "aria-label": "recent 1", "data-test-subj": "collapsibleNavAppLink--recent", - "href": "http://localhost/test/recent%201", + "href": "http://localhost/recent%201", "label": "recent 1", "onClick": [Function], "title": "recent 1", @@ -705,7 +705,7 @@ exports[`CollapsibleNav renders links grouped by category 1`] = ` Object { "aria-label": "recent 2", "data-test-subj": "collapsibleNavAppLink--recent", - "href": "http://localhost/test/recent%202", + "href": "http://localhost/recent%202", "label": "recent 2", "onClick": [Function], "title": "recent 2", @@ -728,7 +728,7 @@ exports[`CollapsibleNav renders links grouped by category 1`] = ` aria-label="recent 1" color="subdued" data-test-subj="collapsibleNavAppLink--recent" - href="http://localhost/test/recent%201" + href="http://localhost/recent%201" key="title-0" label="recent 1" onClick={[Function]} @@ -744,7 +744,7 @@ exports[`CollapsibleNav renders links grouped by category 1`] = ` aria-label="recent 1" className="euiListGroupItem__button" data-test-subj="collapsibleNavAppLink--recent" - href="http://localhost/test/recent%201" + href="http://localhost/recent%201" onClick={[Function]} rel="noreferrer" title="recent 1" @@ -762,7 +762,7 @@ exports[`CollapsibleNav renders links grouped by category 1`] = ` aria-label="recent 2" color="subdued" data-test-subj="collapsibleNavAppLink--recent" - href="http://localhost/test/recent%202" + href="http://localhost/recent%202" key="title-1" label="recent 2" onClick={[Function]} @@ -778,7 +778,7 @@ exports[`CollapsibleNav renders links grouped by category 1`] = ` aria-label="recent 2" className="euiListGroupItem__button" data-test-subj="collapsibleNavAppLink--recent" - href="http://localhost/test/recent%202" + href="http://localhost/recent%202" onClick={[Function]} rel="noreferrer" title="recent 2" @@ -3669,7 +3669,7 @@ exports[`CollapsibleNav with custom branding renders the nav bar in dark mode 1` Object { "aria-label": "recent", "data-test-subj": "collapsibleNavAppLink--recent", - "href": "http://localhost/test/recent", + "href": "http://localhost/recent", "label": "recent", "onClick": [Function], "title": "recent", @@ -3692,7 +3692,7 @@ exports[`CollapsibleNav with custom branding renders the nav bar in dark mode 1` aria-label="recent" color="subdued" data-test-subj="collapsibleNavAppLink--recent" - href="http://localhost/test/recent" + href="http://localhost/recent" key="title-0" label="recent" onClick={[Function]} @@ -3708,7 +3708,7 @@ exports[`CollapsibleNav with custom branding renders the nav bar in dark mode 1` aria-label="recent" className="euiListGroupItem__button" data-test-subj="collapsibleNavAppLink--recent" - href="http://localhost/test/recent" + href="http://localhost/recent" onClick={[Function]} rel="noreferrer" title="recent" @@ -4787,7 +4787,7 @@ exports[`CollapsibleNav with custom branding renders the nav bar in default mode Object { "aria-label": "recent", "data-test-subj": "collapsibleNavAppLink--recent", - "href": "http://localhost/test/recent", + "href": "http://localhost/recent", "label": "recent", "onClick": [Function], "title": "recent", @@ -4810,7 +4810,7 @@ exports[`CollapsibleNav with custom branding renders the nav bar in default mode aria-label="recent" color="subdued" data-test-subj="collapsibleNavAppLink--recent" - href="http://localhost/test/recent" + href="http://localhost/recent" key="title-0" label="recent" onClick={[Function]} @@ -4826,7 +4826,7 @@ exports[`CollapsibleNav with custom branding renders the nav bar in default mode aria-label="recent" className="euiListGroupItem__button" data-test-subj="collapsibleNavAppLink--recent" - href="http://localhost/test/recent" + href="http://localhost/recent" onClick={[Function]} rel="noreferrer" title="recent" @@ -5898,7 +5898,7 @@ exports[`CollapsibleNav without custom branding renders the nav bar in dark mode Object { "aria-label": "recent", "data-test-subj": "collapsibleNavAppLink--recent", - "href": "http://localhost/test/recent", + "href": "http://localhost/recent", "label": "recent", "onClick": [Function], "title": "recent", @@ -5921,7 +5921,7 @@ exports[`CollapsibleNav without custom branding renders the nav bar in dark mode aria-label="recent" color="subdued" data-test-subj="collapsibleNavAppLink--recent" - href="http://localhost/test/recent" + href="http://localhost/recent" key="title-0" label="recent" onClick={[Function]} @@ -5937,7 +5937,7 @@ exports[`CollapsibleNav without custom branding renders the nav bar in dark mode aria-label="recent" className="euiListGroupItem__button" data-test-subj="collapsibleNavAppLink--recent" - href="http://localhost/test/recent" + href="http://localhost/recent" onClick={[Function]} rel="noreferrer" title="recent" @@ -7005,7 +7005,7 @@ exports[`CollapsibleNav without custom branding renders the nav bar in default m Object { "aria-label": "recent", "data-test-subj": "collapsibleNavAppLink--recent", - "href": "http://localhost/test/recent", + "href": "http://localhost/recent", "label": "recent", "onClick": [Function], "title": "recent", @@ -7028,7 +7028,7 @@ exports[`CollapsibleNav without custom branding renders the nav bar in default m aria-label="recent" color="subdued" data-test-subj="collapsibleNavAppLink--recent" - href="http://localhost/test/recent" + href="http://localhost/recent" key="title-0" label="recent" onClick={[Function]} @@ -7044,7 +7044,7 @@ exports[`CollapsibleNav without custom branding renders the nav bar in default m aria-label="recent" className="euiListGroupItem__button" data-test-subj="collapsibleNavAppLink--recent" - href="http://localhost/test/recent" + href="http://localhost/recent" onClick={[Function]} rel="noreferrer" title="recent" diff --git a/src/core/public/chrome/ui/header/__snapshots__/header.test.tsx.snap b/src/core/public/chrome/ui/header/__snapshots__/header.test.tsx.snap index da288014a02c..423902e326cf 100644 --- a/src/core/public/chrome/ui/header/__snapshots__/header.test.tsx.snap +++ b/src/core/public/chrome/ui/header/__snapshots__/header.test.tsx.snap @@ -8005,7 +8005,7 @@ exports[`Header handles visibility and lock changes 1`] = ` Object { "aria-label": "dashboard, type: opensearchDashboards", "data-test-subj": "collapsibleNavAppLink--recent", - "href": "http://localhost/test/", + "href": "http://localhost/", "label": "dashboard", "onClick": [Function], "title": "dashboard, type: opensearchDashboards", @@ -8028,7 +8028,7 @@ exports[`Header handles visibility and lock changes 1`] = ` aria-label="dashboard, type: opensearchDashboards" color="subdued" data-test-subj="collapsibleNavAppLink--recent" - href="http://localhost/test/" + href="http://localhost/" key="title-0" label="dashboard" onClick={[Function]} @@ -8044,7 +8044,7 @@ exports[`Header handles visibility and lock changes 1`] = ` aria-label="dashboard, type: opensearchDashboards" className="euiListGroupItem__button" data-test-subj="collapsibleNavAppLink--recent" - href="http://localhost/test/" + href="http://localhost/" onClick={[Function]} rel="noreferrer" title="dashboard, type: opensearchDashboards" diff --git a/src/core/public/chrome/ui/header/nav_link.test.tsx b/src/core/public/chrome/ui/header/nav_link.test.tsx index fd68ff0cad2c..1bf3928bf09c 100644 --- a/src/core/public/chrome/ui/header/nav_link.test.tsx +++ b/src/core/public/chrome/ui/header/nav_link.test.tsx @@ -103,6 +103,6 @@ describe('createRecentNavLink', () => { mockedNavigateToUrl ); - expect(recentLink.href).toEqual('http://localhost/test/w/foo/app/foo'); + expect(recentLink.href).toEqual('http://localhost/test/app/foo'); }); }); From 7c28a46948de5071bb776920372bfa1164a46b8a Mon Sep 17 00:00:00 2001 From: Kapian1234 Date: Tue, 24 Dec 2024 15:12:51 +0800 Subject: [PATCH 09/13] Remove workspaceEnabled props in recent_items Signed-off-by: Kapian1234 --- src/core/public/chrome/ui/header/header.tsx | 1 - src/core/public/chrome/ui/header/recent_items.tsx | 2 -- 2 files changed, 3 deletions(-) diff --git a/src/core/public/chrome/ui/header/header.tsx b/src/core/public/chrome/ui/header/header.tsx index 5667d8e807b5..0b99c62e0fd4 100644 --- a/src/core/public/chrome/ui/header/header.tsx +++ b/src/core/public/chrome/ui/header/header.tsx @@ -500,7 +500,6 @@ export function Header({ navigateToUrl={application.navigateToUrl} renderBreadcrumbs={renderBreadcrumbs(true, true)} buttonSize={useApplicationHeader ? 's' : 'xs'} - workspaceEnabled={application.capabilities.workspaces.enabled} loadingCount$={observables.loadingCount$} /> diff --git a/src/core/public/chrome/ui/header/recent_items.tsx b/src/core/public/chrome/ui/header/recent_items.tsx index 5cf341cdad8e..298bf51d2bc6 100644 --- a/src/core/public/chrome/ui/header/recent_items.tsx +++ b/src/core/public/chrome/ui/header/recent_items.tsx @@ -44,7 +44,6 @@ export interface Props { renderBreadcrumbs: React.JSX.Element; buttonSize?: EuiHeaderSectionItemButtonProps['size']; http: HttpStart; - workspaceEnabled: boolean | undefined; loadingCount$: Rx.Observable; } @@ -112,7 +111,6 @@ export const RecentItems = ({ renderBreadcrumbs, buttonSize = 's', http, - workspaceEnabled, loadingCount$, }: Props) => { const [isPopoverOpen, setIsPopoverOpen] = useState(false); From 0c92d9e70b78f8c3ab490e48097d88494500bfa9 Mon Sep 17 00:00:00 2001 From: Kapian1234 Date: Tue, 24 Dec 2024 16:25:19 +0800 Subject: [PATCH 10/13] Fix links at recent accessed items Signed-off-by: Kapian1234 --- .../public/management_section/recent_work.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/saved_objects_management/public/management_section/recent_work.tsx b/src/plugins/saved_objects_management/public/management_section/recent_work.tsx index 917c4a4f7b25..6565021b2404 100644 --- a/src/plugins/saved_objects_management/public/management_section/recent_work.tsx +++ b/src/plugins/saved_objects_management/public/management_section/recent_work.tsx @@ -241,7 +241,7 @@ export const RecentWork = (props: { core: CoreStart; workspaceEnabled?: boolean ...recentAccessItem.meta, workspaceName: findWorkspace?.name, updatedAt: moment(obj?.updated_at).valueOf(), - link: href, + link: workspaceEnabled ? href : link, label: label || obj.meta.title, }; }) @@ -254,7 +254,7 @@ export const RecentWork = (props: { core: CoreStart; workspaceEnabled?: boolean } finally { setIsLoading(false); } - }, [core.http, currentWorkspace, recentAccessed, workspaceList]); + }, [core.http, currentWorkspace, recentAccessed, workspaceList, workspaceEnabled]); useEffect(() => { // reset to allOption From 4c83a8c349d85475b6bbf572770cdb87f080eaa7 Mon Sep 17 00:00:00 2001 From: Kapian1234 Date: Wed, 25 Dec 2024 15:23:12 +0800 Subject: [PATCH 11/13] Fix unit tests Signed-off-by: Kapian1234 --- src/core/public/chrome/ui/header/collapsible_nav.test.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/public/chrome/ui/header/collapsible_nav.test.tsx b/src/core/public/chrome/ui/header/collapsible_nav.test.tsx index 955b7d7ca242..06cca2172558 100644 --- a/src/core/public/chrome/ui/header/collapsible_nav.test.tsx +++ b/src/core/public/chrome/ui/header/collapsible_nav.test.tsx @@ -95,6 +95,7 @@ function mockProps(branding = {}) { customNavLink$: new BehaviorSubject(undefined), branding, logos: getLogos(branding, mockBasePath.serverBasePath), + workspaceEnabled: true, }; } From 101c4b8e49e0d40fb09726803886abfcdddf6190 Mon Sep 17 00:00:00 2001 From: Kapian1234 Date: Wed, 25 Dec 2024 15:51:26 +0800 Subject: [PATCH 12/13] Update snapshots Signed-off-by: Kapian1234 --- .../collapsible_nav.test.tsx.snap | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/core/public/chrome/ui/header/__snapshots__/collapsible_nav.test.tsx.snap b/src/core/public/chrome/ui/header/__snapshots__/collapsible_nav.test.tsx.snap index 607e854572a0..472905b48177 100644 --- a/src/core/public/chrome/ui/header/__snapshots__/collapsible_nav.test.tsx.snap +++ b/src/core/public/chrome/ui/header/__snapshots__/collapsible_nav.test.tsx.snap @@ -418,6 +418,7 @@ exports[`CollapsibleNav renders links grouped by category 1`] = ` "values": Array [], } } + workspaceEnabled={true} > Date: Thu, 9 Jan 2025 14:44:53 +0800 Subject: [PATCH 13/13] Modify unit tests Signed-off-by: Kapian1234 --- .../public/chrome/ui/header/nav_link.test.tsx | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/core/public/chrome/ui/header/nav_link.test.tsx b/src/core/public/chrome/ui/header/nav_link.test.tsx index 1bf3928bf09c..05380472e94f 100644 --- a/src/core/public/chrome/ui/header/nav_link.test.tsx +++ b/src/core/public/chrome/ui/header/nav_link.test.tsx @@ -100,7 +100,25 @@ describe('createRecentNavLink', () => { }, mockNavLinks, mockBasePath, - mockedNavigateToUrl + mockedNavigateToUrl, + true + ); + + expect(recentLink.href).toEqual('http://localhost/test/w/foo/app/foo'); + }); + + it('create a recent link when workspace disabled', () => { + const recentLink = createRecentNavLink( + { + id: 'foo', + label: 'foo', + link: '/app/foo', + workspaceId: 'foo', + }, + mockNavLinks, + mockBasePath, + mockedNavigateToUrl, + false ); expect(recentLink.href).toEqual('http://localhost/test/app/foo');