From d569d84fe971f0187e8ff8feaec50a7dd1a4dc7c Mon Sep 17 00:00:00 2001 From: yubonluo Date: Wed, 13 Nov 2024 17:02:29 +0800 Subject: [PATCH 1/2] 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, }; } From e190886596f72d685fa1ee6a315fa5deb11b23c2 Mon Sep 17 00:00:00 2001 From: "opensearch-changeset-bot[bot]" <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Date: Wed, 13 Nov 2024 09:12:50 +0000 Subject: [PATCH 2/2] Changeset file for PR #8857 created/updated --- changelogs/fragments/8857.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/8857.yml diff --git a/changelogs/fragments/8857.yml b/changelogs/fragments/8857.yml new file mode 100644 index 000000000000..45d5fa5c5213 --- /dev/null +++ b/changelogs/fragments/8857.yml @@ -0,0 +1,2 @@ +fix: +- [Workspace][Bug] Fix inspect page url error. ([#8857](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8857)) \ No newline at end of file