From d569d84fe971f0187e8ff8feaec50a7dd1a4dc7c Mon Sep 17 00:00:00 2001 From: yubonluo Date: Wed, 13 Nov 2024 17:02:29 +0800 Subject: [PATCH] Fix inspect page url error Signed-off-by: yubonluo --- src/plugins/saved_objects_management/common/types.ts | 1 + .../saved_objects_management/public/utils.test.ts | 12 ++++++------ src/plugins/saved_objects_management/public/utils.ts | 3 ++- .../server/lib/find_relationships.test.ts | 6 ++++++ .../server/lib/find_relationships.ts | 1 + 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/plugins/saved_objects_management/common/types.ts b/src/plugins/saved_objects_management/common/types.ts index e66fae37724e..cd560886f2e1 100644 --- a/src/plugins/saved_objects_management/common/types.ts +++ b/src/plugins/saved_objects_management/common/types.ts @@ -58,4 +58,5 @@ export interface SavedObjectRelation { type: string; relationship: 'child' | 'parent'; meta: SavedObjectMetadata; + workspaces?: SavedObject['workspaces']; } diff --git a/src/plugins/saved_objects_management/public/utils.test.ts b/src/plugins/saved_objects_management/public/utils.test.ts index bcaed2bb9417..fb9a8e328f04 100644 --- a/src/plugins/saved_objects_management/public/utils.test.ts +++ b/src/plugins/saved_objects_management/public/utils.test.ts @@ -52,7 +52,7 @@ describe('Utils', () => { attributes: {}, references: [], meta: { - editUrl: '/management/opensearch-dashboards/objects/savedDashboards/ID1', + editUrl: '/management/opensearch-dashboards/objects/dashboard/ID1', }, }; const savedObjectWithWorkspaces = { @@ -89,7 +89,7 @@ describe('Utils', () => { get: jest.fn().mockReturnValue(false), }; const result = formatInspectUrl(savedObject, mockCoreStart); - expect(result).toBe('/management/opensearch-dashboards/objects/savedDashboards/ID1'); + expect(result).toBe('/app/management/opensearch-dashboards/objects/dashboard/ID1'); }); it('formats URL correctly when useUpdatedUX is false, saved object does not belong to certain workspaces and not in current workspace', () => { @@ -98,7 +98,7 @@ describe('Utils', () => { get: jest.fn().mockReturnValue(false), }; const result = formatInspectUrl(savedObject, mockCoreStart); - expect(result).toBe('/management/opensearch-dashboards/objects/savedDashboards/ID1'); + expect(result).toBe('/app/management/opensearch-dashboards/objects/dashboard/ID1'); }); it('formats URL correctly when useUpdatedUX is true and in current workspace', () => { @@ -106,21 +106,21 @@ describe('Utils', () => { mockCoreStart.workspaces.currentWorkspace$.next(currentWorkspace); const result = formatInspectUrl(savedObjectWithWorkspaces, mockCoreStart); - expect(result).toBe('http://localhost/w/workspace1/app/objects/savedDashboards/ID1'); + expect(result).toBe('http://localhost/w/workspace1/app/objects/dashboard/ID1'); }); it('formats URL correctly when useUpdatedUX is true and saved object belongs to certain workspaces', () => { mockCoreStart.workspaces.workspaceList$.next([{ id: 'workspace1', name: 'workspace1' }]); const result = formatInspectUrl(savedObjectWithWorkspaces, mockCoreStart); - expect(result).toBe('http://localhost/w/workspace1/app/objects/savedDashboards/ID1'); + expect(result).toBe('http://localhost/w/workspace1/app/objects/dashboard/ID1'); }); it('formats URL correctly when useUpdatedUX is true and the object does not belong to any workspace', () => { mockCoreStart.workspaces.workspaceList$.next([{ id: 'workspace2', name: 'workspace2' }]); const result = formatInspectUrl(savedObjectWithWorkspaces, mockCoreStart); - expect(result).toBe('/app/objects/savedDashboards/ID1'); + expect(result).toBe('/app/objects/dashboard/ID1'); }); }); }); diff --git a/src/plugins/saved_objects_management/public/utils.ts b/src/plugins/saved_objects_management/public/utils.ts index 9dada18e8711..61f3670fed5c 100644 --- a/src/plugins/saved_objects_management/public/utils.ts +++ b/src/plugins/saved_objects_management/public/utils.ts @@ -25,9 +25,10 @@ export function formatInspectUrl( const useUpdatedUX = !!coreStart.uiSettings.get('home:useNewHomePage'); let finalEditUrl = editUrl; if (useUpdatedUX && finalEditUrl) { - finalEditUrl = finalEditUrl.replace(/^\/management\/opensearch-dashboards/, '/app'); + finalEditUrl = finalEditUrl.replace(/^\/management\/opensearch-dashboards/, ''); } if (finalEditUrl) { + finalEditUrl = `/app${finalEditUrl}`; const basePath = coreStart.http.basePath; let inAppUrl = basePath.prepend(finalEditUrl); const workspaceEnabled = coreStart.application.capabilities.workspaces.enabled; diff --git a/src/plugins/saved_objects_management/server/lib/find_relationships.test.ts b/src/plugins/saved_objects_management/server/lib/find_relationships.test.ts index c9ee0a1e766d..b34e65dbc6f6 100644 --- a/src/plugins/saved_objects_management/server/lib/find_relationships.test.ts +++ b/src/plugins/saved_objects_management/server/lib/find_relationships.test.ts @@ -72,12 +72,14 @@ describe('findRelationships', () => { id: 'ref-1', attributes: {}, references: [], + workspaces: ['workspace1'], }, { type: 'another-type', id: 'ref-2', attributes: {}, references: [], + workspaces: ['workspace1'], }, ], }); @@ -90,6 +92,7 @@ describe('findRelationships', () => { attributes: {}, score: 1, references: [], + workspaces: ['workspace1'], }, ], total: 1, @@ -130,18 +133,21 @@ describe('findRelationships', () => { relationship: 'child', type: 'some-type', meta: expect.any(Object), + workspaces: ['workspace1'], }, { id: 'ref-2', relationship: 'child', type: 'another-type', meta: expect.any(Object), + workspaces: ['workspace1'], }, { id: 'parent-id', relationship: 'parent', type: 'parent-type', meta: expect.any(Object), + workspaces: ['workspace1'], }, ]); }); diff --git a/src/plugins/saved_objects_management/server/lib/find_relationships.ts b/src/plugins/saved_objects_management/server/lib/find_relationships.ts index 4a4ed8155c8c..a2582ed7074f 100644 --- a/src/plugins/saved_objects_management/server/lib/find_relationships.ts +++ b/src/plugins/saved_objects_management/server/lib/find_relationships.ts @@ -95,5 +95,6 @@ function extractCommonProperties(savedObject: SavedObjectWithMetadata) { id: savedObject.id, type: savedObject.type, meta: savedObject.meta, + workspaces: savedObject.workspaces, }; }