Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workspace][Bug] Fix inspect page url error #8857

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8857.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- [Workspace][Bug] Fix inspect page url error. ([#8857](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8857))
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}`;
Comment on lines -28 to +31
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, need to add the \app prefix to the url, otherwise user will not be able to access it. According to previous practice, when new home is closed, the URL will miss the \app prefix

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,
};
}
Loading