Skip to content

Commit

Permalink
[navigation] Fix: breadcrumb is not correct when clicking inspect / e…
Browse files Browse the repository at this point in the history
…dit in Assets page (opensearch-project#7749)

* settings header

Signed-off-by: tygao <[email protected]>

* update all pages header

Signed-off-by: tygao <[email protected]>

* Changeset file for PR opensearch-project#7744 created/updated

* style: update management style

Signed-off-by: tygao <[email protected]>

* remove extra spacer

Signed-off-by: tygao <[email protected]>

* add tests and snapshots

Signed-off-by: tygao <[email protected]>

* feat: jump to standard application when the toggle is on

Signed-off-by: SuZhou-Joe <[email protected]>

* Changeset file for PR opensearch-project#7749 created/updated

* feat: improve test coverage

Signed-off-by: SuZhou-Joe <[email protected]>

---------

Signed-off-by: tygao <[email protected]>
Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: tygao <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 23, 2024
1 parent 106b64c commit 9dd9b14
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 17 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7749.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Breadcrumb is not correct when clicking inspect / edit in Assets page ([#7749](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7749))
12 changes: 2 additions & 10 deletions src/plugins/data_source_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,9 @@ export class DataSourceManagementPlugin
},
});

/**
* The data sources features in observability has the same name as `DSM_APP_ID`
* Add a suffix to avoid duplication
*
* The id is used in src/plugins/workspace/public/plugin.ts and please change that accordingly if you change the id here.
*/
const DSM_APP_ID_FOR_STANDARD_APPLICATION = `${DSM_APP_ID}_core`;

if (core.chrome.navGroup.getNavGroupEnabled()) {
core.application.register({
id: DSM_APP_ID_FOR_STANDARD_APPLICATION,
id: DSM_APP_ID,
title: PLUGIN_NAME,
order: 100,
description: i18n.translate('data_source_management.description', {
Expand Down Expand Up @@ -184,7 +176,7 @@ export class DataSourceManagementPlugin

core.chrome.navGroup.addNavLinksToGroup(DEFAULT_NAV_GROUPS.dataAdministration, [
{
id: DSM_APP_ID_FOR_STANDARD_APPLICATION,
id: DSM_APP_ID,
category: DEFAULT_APP_CATEGORIES.manageData,
order: 100,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import React from 'react';
import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';
import { httpServiceMock } from '../../../../../../core/public/mocks';
import { Relationships, RelationshipsProps } from './relationships';
import { render } from '@testing-library/react';

jest.mock('../../../lib/fetch_export_by_type_and_search', () => ({
fetchExportByTypeAndSearch: jest.fn(),
Expand Down Expand Up @@ -702,4 +703,51 @@ describe('Relationships from legacy app', () => {
expect(props.getRelationships).toHaveBeenCalled();
expect(component).toMatchSnapshot();
});

it('should replace the url to standard application when new nav group is enabled', async () => {
const props: RelationshipsProps = {
goInspectObject: () => {},
canGoInApp: () => true,
basePath: httpServiceMock.createSetupContract().basePath,
getRelationships: jest.fn().mockImplementation(() => [
{
type: 'index-patterns',
id: '1',
relationship: 'child',
meta: {
editUrl: '/management/kibana/objects/savedVisualizations/1',
icon: 'visualizeApp',
inAppUrl: {
path: '/app/management/opensearch-dashboards/indexPatterns#/edit/1',
uiCapabilitiesPath: 'visualize.show',
},
title: 'My Visualization Title 1',
},
},
]),
savedObject: {
id: '1',
type: 'dashboard',
attributes: {},
references: [],
meta: {
title: 'MyDashboard',
icon: 'dashboardApp',
editUrl: '/management/kibana/objects/savedDashboards/1',
inAppUrl: {
path: '/dashboard/1',
uiCapabilitiesPath: 'dashboard.show',
},
},
},
close: jest.fn(),
useUpdatedUX: true,
};

const { getByTestId, findByText } = render(<Relationships {...props} />);

await findByText('Type of the saved object');

expect(getByTestId('relationshipsTitle')).toHaveAttribute('href', '/app/indexPatterns#/edit/1');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface RelationshipsProps {
close: () => void;
goInspectObject: (obj: SavedObjectWithMetadata) => void;
canGoInApp: (obj: SavedObjectWithMetadata) => boolean;
useUpdatedUX?: boolean;
}

export interface RelationshipsState {
Expand Down Expand Up @@ -205,6 +206,10 @@ export class Relationships extends Component<RelationshipsProps, RelationshipsSt
render: (title: string, object: SavedObjectWithMetadata) => {
const { path = '' } = object.meta.inAppUrl || {};
const canGoInApp = this.props.canGoInApp(object);
let finalPath = path;
if (this.props.useUpdatedUX && finalPath) {
finalPath = finalPath.replace(/^\/app\/management\/opensearch-dashboards/, '/app');
}
if (!canGoInApp) {
return (
<EuiText size="s" data-test-subj="relationshipsTitle">
Expand All @@ -213,7 +218,7 @@ export class Relationships extends Component<RelationshipsProps, RelationshipsSt
);
}
return (
<EuiLink href={basePath.prepend(path)} data-test-subj="relationshipsTitle">
<EuiLink href={basePath.prepend(finalPath)} data-test-subj="relationshipsTitle">
{title || getDefaultTitle(object)}
</EuiLink>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { columnServiceMock } from '../../../services/column_service.mock';
import { SavedObjectsManagementAction } from '../../..';
import { Table, TableProps } from './table';
import { WorkspaceAttribute } from 'opensearch-dashboards/public';
import { render } from '@testing-library/react';

const defaultProps: TableProps = {
basePath: httpServiceMock.createSetupContract().basePath,
Expand Down Expand Up @@ -257,4 +258,36 @@ describe('Table', () => {
duplicateAction.onClick();
expect(onDuplicateSingle).toHaveBeenCalled();
});

it('should replace legacy path to standard application path when useUpdatedUX is true', () => {
const showDuplicate = true;
const customizedProps = {
...defaultProps,
showDuplicate,
useUpdatedUX: true,
items: [
{
id: '1',
type: 'index-pattern',
attributes: {},
references: [],
meta: {
title: `MyIndexPattern*`,
icon: 'indexPatternApp',
editUrl: '#/management/opensearch-dashboards/indexPatterns/patterns/1',
inAppUrl: {
path: '/app/management/opensearch-dashboards/indexPatterns/patterns/1',
uiCapabilitiesPath: 'management.opensearchDashboards.indexPatterns',
},
},
},
],
};
const { getByTestId } = render(<Table {...customizedProps} />);
expect(
getByTestId('savedObjectsTableRowTitle').querySelector(
'[href="/app/indexPatterns/patterns/1"]'
)
).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,19 @@ export class Table extends PureComponent<TableProps, TableState> {
if (!canGoInApp) {
return <EuiText size="s">{title || getDefaultTitle(object)}</EuiText>;
}
let inAppUrl = basePath.prepend(path);
let finalPath = path;
if (this.props.useUpdatedUX && finalPath) {
finalPath = finalPath.replace(/^\/app\/management\/opensearch-dashboards/, '/app');
}
let inAppUrl = basePath.prepend(finalPath);
if (object.workspaces?.length) {
if (currentWorkspaceId) {
inAppUrl = formatUrlWithWorkspaceId(path, currentWorkspaceId, basePath);
inAppUrl = formatUrlWithWorkspaceId(finalPath, currentWorkspaceId, basePath);
} else {
// find first workspace user have permission
const workspaceId = object.workspaces.find((wsId) => visibleWsIds.includes(wsId));
if (workspaceId) {
inAppUrl = formatUrlWithWorkspaceId(path, workspaceId, basePath);
inAppUrl = formatUrlWithWorkspaceId(finalPath, workspaceId, basePath);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
close={this.onHideRelationships}
goInspectObject={this.props.goInspectObject}
canGoInApp={this.props.canGoInApp}
useUpdatedUX={this.props.useUpdatedUX}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@ const SavedObjectsTablePage = ({
perPageConfig={itemsPerPage}
goInspectObject={(savedObject) => {
const { editUrl } = savedObject.meta;
if (editUrl) {
let finalEditUrl = editUrl;
if (useUpdatedUX && finalEditUrl) {
finalEditUrl = finalEditUrl.replace(/^\/management\/opensearch-dashboards/, '');
}
if (finalEditUrl) {
return coreStart.application.navigateToUrl(
coreStart.http.basePath.prepend(`/app${editUrl}`)
coreStart.http.basePath.prepend(`/app${finalEditUrl}`)
);
}
}}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/workspace/public/services/use_case_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class UseCaseService {
if (navGroupInfo) {
setupDeps.chrome.navGroup.addNavLinksToGroup(navGroupInfo, [
{
id: 'dataSources_core',
id: 'dataSources',
category: DEFAULT_APP_CATEGORIES.manageWorkspace,
order: 100,
},
Expand Down

0 comments on commit 9dd9b14

Please sign in to comment.