Skip to content

Commit

Permalink
Fix inspect page url error
Browse files Browse the repository at this point in the history
Signed-off-by: yubonluo <[email protected]>
  • Loading branch information
yubonluo committed Nov 13, 2024
1 parent 76cf823 commit d569d84
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/plugins/saved_objects_management/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ export interface SavedObjectRelation {
type: string;
relationship: 'child' | 'parent';
meta: SavedObjectMetadata;
workspaces?: SavedObject['workspaces'];
}
12 changes: 6 additions & 6 deletions src/plugins/saved_objects_management/public/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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', () => {
Expand All @@ -98,29 +98,29 @@ 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', () => {
const currentWorkspace = { id: 'workspace1', name: 'workspace1' };
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');
});
});
});
3 changes: 2 additions & 1 deletion src/plugins/saved_objects_management/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ describe('findRelationships', () => {
id: 'ref-1',
attributes: {},
references: [],
workspaces: ['workspace1'],
},
{
type: 'another-type',
id: 'ref-2',
attributes: {},
references: [],
workspaces: ['workspace1'],
},
],
});
Expand All @@ -90,6 +92,7 @@ describe('findRelationships', () => {
attributes: {},
score: 1,
references: [],
workspaces: ['workspace1'],
},
],
total: 1,
Expand Down Expand Up @@ -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'],
},
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@ function extractCommonProperties(savedObject: SavedObjectWithMetadata) {
id: savedObject.id,
type: savedObject.type,
meta: savedObject.meta,
workspaces: savedObject.workspaces,
};
}

0 comments on commit d569d84

Please sign in to comment.