Skip to content

Commit

Permalink
index pattern always show under library (#115)
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am authored and SuZhou-Joe committed Aug 31, 2023
1 parent a3279eb commit f83b7a4
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,7 @@ export class IndexPatternsService {
);

if (!savedObject.version) {
throw new SavedObjectNotFound(
savedObjectType,
id,
'management/opensearch-dashboards/indexPatterns'
);
throw new SavedObjectNotFound(savedObjectType, id, 'indexPatterns');
}

const spec = this.savedObjectToSpec(savedObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export const onRedirectNoIndexPattern = (
overlays: CoreStart['overlays']
) => () => {
const canManageIndexPatterns = capabilities.management.opensearchDashboards.indexPatterns;
const redirectTarget = canManageIndexPatterns
? '/management/opensearch-dashboards/indexPatterns'
: '/home';
const redirectTarget = canManageIndexPatterns ? '/indexPatterns' : '/home';
let timeoutId: NodeJS.Timeout | undefined;

if (timeoutId) {
Expand Down
8 changes: 2 additions & 6 deletions src/plugins/data/server/saved_objects/index_patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,11 @@ export const indexPatternSavedObjectType: SavedObjectsType = {
return obj.attributes.title;
},
getEditUrl(obj) {
return `/management/opensearch-dashboards/indexPatterns/patterns/${encodeURIComponent(
obj.id
)}`;
return `/indexPatterns/patterns/${encodeURIComponent(obj.id)}`;
},
getInAppUrl(obj) {
return {
path: `/app/management/opensearch-dashboards/indexPatterns/patterns/${encodeURIComponent(
obj.id
)}`,
path: `/app/indexPatterns/patterns/${encodeURIComponent(obj.id)}`,
uiCapabilitiesPath: 'management.opensearchDashboards.indexPatterns',
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ const readOnlyBadge = {
export async function mountManagementSection(
getStartServices: StartServicesAccessor<IndexPatternManagementStartDependencies>,
params: ManagementAppMountParams,
getMlCardState: () => MlCardState,
withPage: boolean = false
getMlCardState: () => MlCardState
) {
const [
{ chrome, application, savedObjects, uiSettings, notifications, overlays, http, docLinks },
Expand Down Expand Up @@ -110,14 +109,12 @@ export async function mountManagementSection(
</Switch>
</Router>
);
let content = router;
if (withPage) {
content = (
<EuiPage restrictWidth="1200px">
<EuiPageBody component="main">{router}</EuiPageBody>
</EuiPage>
);
}

const content = (
<EuiPage restrictWidth="1200px">
<EuiPageBody component="main">{router}</EuiPageBody>
</EuiPage>
);

ReactDOM.render(
<OpenSearchDashboardsContextProvider services={deps}>
Expand Down
89 changes: 32 additions & 57 deletions src/plugins/index_pattern_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ export interface IndexPatternManagementStartDependencies {
dataSource?: DataSourcePluginStart;
}

export interface IndexPatternManagementSetup extends IndexPatternManagementServiceSetup {
registerLibrarySubApp: () => void;
}
export type IndexPatternManagementSetup = IndexPatternManagementServiceSetup;

export type IndexPatternManagementStart = IndexPatternManagementServiceStart;

Expand Down Expand Up @@ -95,7 +93,7 @@ export class IndexPatternManagementPlugin
throw new Error('`opensearchDashboards` management section not found.');
}

const newAppPath = `management/opensearch-dashboards/${IPM_APP_ID}`;
const newAppPath = IPM_APP_ID;
const legacyPatternsPath = 'management/opensearch-dashboards/index_patterns';

urlForwarding.forwardApp(
Expand All @@ -108,68 +106,45 @@ export class IndexPatternManagementPlugin
return pathInApp && `/patterns${pathInApp}`;
});

opensearchDashboardsSection.registerApp({
// register it under Library
core.application.register({
id: IPM_APP_ID,
title: sectionsHeader,
order: 0,
mount: async (params) => {
order: 8100,
category: DEFAULT_APP_CATEGORIES.opensearchDashboards,
mount: async (params: AppMountParameters) => {
const { mountManagementSection } = await import('./management_app');

return mountManagementSection(core.getStartServices, params, () =>
const [coreStart] = await core.getStartServices();

const setBreadcrumbsScope = (
crumbs: ChromeBreadcrumb[] = [],
appHistory?: ScopedHistory
) => {
const wrapBreadcrumb = (item: ChromeBreadcrumb, scopedHistory: ScopedHistory) => ({
...item,
...(item.href ? reactRouterNavigate(scopedHistory, item.href) : {}),
});

coreStart.chrome.setBreadcrumbs([
...crumbs.map((item) => wrapBreadcrumb(item, appHistory || params.history)),
]);
};

const managementParams: ManagementAppMountParams = {
element: params.element,
history: params.history,
setBreadcrumbs: setBreadcrumbsScope,
basePath: params.appBasePath,
};

return mountManagementSection(core.getStartServices, managementParams, () =>
this.indexPatternManagementService.environmentService.getEnvironment().ml()
);
},
});

const registerLibrarySubApp = () => {
// disable it under Dashboards Management
opensearchDashboardsSection.getApp(IPM_APP_ID)?.disable();
// register it under Library
core.application.register({
id: IPM_APP_ID,
title: sectionsHeader,
order: 8100,
category: DEFAULT_APP_CATEGORIES.opensearchDashboards,
mount: async (params: AppMountParameters) => {
const { mountManagementSection } = await import('./management_app');

const [coreStart] = await core.getStartServices();

const setBreadcrumbsScope = (
crumbs: ChromeBreadcrumb[] = [],
appHistory?: ScopedHistory
) => {
const wrapBreadcrumb = (item: ChromeBreadcrumb, scopedHistory: ScopedHistory) => ({
...item,
...(item.href ? reactRouterNavigate(scopedHistory, item.href) : {}),
});

coreStart.chrome.setBreadcrumbs([
...crumbs.map((item) => wrapBreadcrumb(item, appHistory || params.history)),
]);
};

const managementParams: ManagementAppMountParams = {
element: params.element,
history: params.history,
setBreadcrumbs: setBreadcrumbsScope,
basePath: params.appBasePath,
};

return mountManagementSection(
core.getStartServices,
managementParams,
() => this.indexPatternManagementService.environmentService.getEnvironment().ml(),
true
);
},
});
};

return {
...this.indexPatternManagementService.setup({ httpClient: core.http }),
registerLibrarySubApp,
};
return this.indexPatternManagementService.setup({ httpClient: core.http });
}

public start(core: CoreStart, plugins: IndexPatternManagementStartDependencies) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ export const GettingStarted: FC<Props> = ({ addBasePath, isDarkTheme, apps }) =>
<EuiSpacer size="xl" />

<RedirectAppLinks application={application}>
<EuiButton
fill
iconType="indexOpen"
href={addBasePath('/app/management/opensearch-dashboards/indexPatterns')}
>
<EuiButton fill iconType="indexOpen" href={addBasePath('/app/indexPatterns')}>
<FormattedMessage
defaultMessage="Add your data"
id="opensearchDashboardsOverview.gettingStarted.addDataButtonLabel"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ describe('Relationships', () => {
meta: {
title: 'MyIndexPattern*',
icon: 'indexPatternApp',
editUrl: '#/management/opensearch-dashboards/indexPatterns/patterns/1',
editUrl: '#/indexPatterns/patterns/1',
inAppUrl: {
path: '/management/opensearch-dashboards/indexPatterns/patterns/1',
path: '/indexPatterns/patterns/1',
uiCapabilitiesPath: 'management.opensearchDashboards.indexPatterns',
},
},
Expand Down Expand Up @@ -120,10 +120,10 @@ describe('Relationships', () => {
id: '1',
relationship: 'child',
meta: {
editUrl: '/management/opensearch-dashboards/indexPatterns/patterns/1',
editUrl: '/indexPatterns/patterns/1',
icon: 'indexPatternApp',
inAppUrl: {
path: '/app/management/opensearch-dashboards/indexPatterns/patterns/1',
path: '/app/indexPatterns/patterns/1',
uiCapabilitiesPath: 'management.opensearchDashboards.indexPatterns',
},
title: 'My Index Pattern',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ const defaultProps: TableProps = {
meta: {
title: `MyIndexPattern*`,
icon: 'indexPatternApp',
editUrl: '#/management/opensearch-dashboards/indexPatterns/patterns/1',
editUrl: '#/indexPatterns/patterns/1',
inAppUrl: {
path: '/management/opensearch-dashboards/indexPatterns/patterns/1',
path: '/indexPatterns/patterns/1',
uiCapabilitiesPath: 'management.opensearchDashboards.indexPatterns',
},
},
Expand Down Expand Up @@ -91,9 +91,9 @@ const defaultProps: TableProps = {
meta: {
title: `MyIndexPattern*`,
icon: 'indexPatternApp',
editUrl: '#/management/opensearch-dashboards/indexPatterns/patterns/1',
editUrl: '#/indexPatterns/patterns/1',
inAppUrl: {
path: '/management/opensearch-dashboards/indexPatterns/patterns/1',
path: '/indexPatterns/patterns/1',
uiCapabilitiesPath: 'management.opensearchDashboards.indexPatterns',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ describe('SavedObjectsTable', () => {
meta: {
title: `MyIndexPattern*`,
icon: 'indexPatternApp',
editUrl: '#/management/opensearch-dashboards/indexPatterns/patterns/1',
editUrl: '#/indexPatterns/patterns/1',
inAppUrl: {
path: '/management/opensearch-dashboards/indexPatterns/patterns/1',
path: '/indexPatterns/patterns/1',
uiCapabilitiesPath: 'management.opensearchDashboards.indexPatterns',
},
},
Expand Down
8 changes: 1 addition & 7 deletions src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ import { SavedObjectsManagementPluginSetup } from '../../saved_objects_managemen
import { getWorkspaceColumn } from './components/utils/workspace_column';
import { getWorkspaceIdFromUrl } from '../../../core/public/utils';
import { WorkspaceClient } from './workspace_client';
import { IndexPatternManagementSetup } from '../../index_pattern_management/public';
import { renderWorkspaceMenu } from './render_workspace_menu';
import { Services } from './types';
import { featureMatchesConfig } from './utils';

interface WorkspacePluginSetupDeps {
savedObjectsManagement?: SavedObjectsManagementPluginSetup;
indexPatternManagement?: IndexPatternManagementSetup;
}

export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps> {
Expand All @@ -46,10 +44,7 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps>
private getWorkspaceIdFromURL(): string | null {
return getWorkspaceIdFromUrl(window.location.href);
}
public async setup(
core: CoreSetup,
{ savedObjectsManagement, indexPatternManagement }: WorkspacePluginSetupDeps
) {
public async setup(core: CoreSetup, { savedObjectsManagement }: WorkspacePluginSetupDeps) {
const workspaceClient = new WorkspaceClient(core.http, core.workspaces);
workspaceClient.init();
const featureFlagResp = await workspaceClient.getSettings();
Expand Down Expand Up @@ -110,7 +105,6 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps>

// register apps for library object management
savedObjectsManagement?.registerLibrarySubApp();
indexPatternManagement?.registerLibrarySubApp();

type WorkspaceAppType = (params: AppMountParameters, services: Services) => () => void;
const mountWorkspaceApp = async (params: AppMountParameters, renderApp: WorkspaceAppType) => {
Expand Down
6 changes: 2 additions & 4 deletions test/api_integration/apis/saved_objects_management/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,9 @@ export default function ({ getService }: FtrProviderContext) {
expect(resp.body.saved_objects[0].meta).to.eql({
icon: 'indexPatternApp',
title: 'saved_objects*',
editUrl:
'/management/opensearch-dashboards/indexPatterns/patterns/8963ca30-3224-11e8-a572-ffca06da1357',
editUrl: '/indexPatterns/patterns/8963ca30-3224-11e8-a572-ffca06da1357',
inAppUrl: {
path:
'/app/management/opensearch-dashboards/indexPatterns/patterns/8963ca30-3224-11e8-a572-ffca06da1357',
path: '/app/indexPatterns/patterns/8963ca30-3224-11e8-a572-ffca06da1357',
uiCapabilitiesPath: 'management.opensearchDashboards.indexPatterns',
},
namespaceType: 'single',
Expand Down
Loading

0 comments on commit f83b7a4

Please sign in to comment.