From 899293f4242b8a08ea0450a38b552e15eb87d1ee Mon Sep 17 00:00:00 2001
From: Lin Wang
Date: Mon, 21 Oct 2024 11:16:02 +0800
Subject: [PATCH] Navigate to import_sample_data app when navGroupEnabled
Signed-off-by: Lin Wang
---
.../__snapshots__/create_index.test.tsx.snap | 37 ++++++++++++++++---
.../__test__/create_index.test.tsx | 31 +++++++++++++++-
.../components/query_compare/create_index.tsx | 24 ++++++++++--
public/components/query_compare/home.tsx | 3 +-
4 files changed, 83 insertions(+), 12 deletions(-)
diff --git a/public/components/query_compare/__test__/__snapshots__/create_index.test.tsx.snap b/public/components/query_compare/__test__/__snapshots__/create_index.test.tsx.snap
index aa3312c6..31fe605f 100644
--- a/public/components/query_compare/__test__/__snapshots__/create_index.test.tsx.snap
+++ b/public/components/query_compare/__test__/__snapshots__/create_index.test.tsx.snap
@@ -1,7 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Create index component Renders create index component 1`] = `
-
+
Learn how to index your data
- , or
+ , or
+
- add sample data
+ add sample data
+
to OpenSearch Dashboards.
}
@@ -209,7 +234,8 @@ exports[`Create index component Renders create index component 1`] = `
- , or
+ , or
+
@@ -218,9 +244,10 @@ exports[`Create index component Renders create index component 1`] = `
href="/app/home#/tutorial_directory"
rel="noreferrer"
>
- add sample data
+ add sample data
+
to OpenSearch Dashboards.
diff --git a/public/components/query_compare/__test__/create_index.test.tsx b/public/components/query_compare/__test__/create_index.test.tsx
index 02d5d5d2..e1ed0db3 100644
--- a/public/components/query_compare/__test__/create_index.test.tsx
+++ b/public/components/query_compare/__test__/create_index.test.tsx
@@ -6,14 +6,31 @@
import { configure, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
-import { waitFor } from '@testing-library/react';
+import { fireEvent, render, waitFor } from '@testing-library/react';
import { CreateIndex } from '../create_index';
+const coreMockStart = {
+ chrome: {
+ navGroup: {
+ getNavGroupEnabled: jest.fn(() => false),
+ },
+ },
+ application: {
+ navigateToApp: jest.fn(),
+ },
+};
+
describe('Create index component', () => {
configure({ adapter: new Adapter() });
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
it('Renders create index component', async () => {
- const wrapper = mount();
+ const wrapper = mount(
+
+ );
wrapper.update();
@@ -21,4 +38,14 @@ describe('Create index component', () => {
expect(wrapper).toMatchSnapshot();
});
});
+
+ it('should call application.navigateToApp', async () => {
+ coreMockStart.chrome.navGroup.getNavGroupEnabled.mockReturnValue(true);
+ const { getByText } = render(
+
+ );
+
+ fireEvent.click(getByText('add sample data'));
+ expect(coreMockStart.application.navigateToApp).toHaveBeenLastCalledWith('import_sample_data');
+ });
});
diff --git a/public/components/query_compare/create_index.tsx b/public/components/query_compare/create_index.tsx
index afc54700..610fcc46 100644
--- a/public/components/query_compare/create_index.tsx
+++ b/public/components/query_compare/create_index.tsx
@@ -7,8 +7,15 @@ import React from 'react';
import { EuiPageBody, EuiEmptyPrompt, EuiLink } from '@elastic/eui';
import { Header } from '../common/header';
+import { CoreStart } from '../../../../../src/core/public';
-export const CreateIndex = () => {
+interface CreateIndexProps {
+ chrome: CoreStart['chrome'];
+ application: CoreStart['application'];
+}
+
+export const CreateIndex = ({ chrome, application }: CreateIndexProps) => {
+ const navGroupEnabled = chrome.navGroup.getNavGroupEnabled();
return (
<>
@@ -24,8 +31,19 @@ export const CreateIndex = () => {
>
Learn how to index your data
- , or add sample data to
- OpenSearch Dashboards.
+ , or{' '}
+ {
+ application.navigateToApp('import_sample_data');
+ },
+ }
+ : { href: '/app/home#/tutorial_directory' })}
+ >
+ add sample data
+ {' '}
+ to OpenSearch Dashboards.
}
/>
diff --git a/public/components/query_compare/home.tsx b/public/components/query_compare/home.tsx
index 9d04aaa2..7c1e4825 100644
--- a/public/components/query_compare/home.tsx
+++ b/public/components/query_compare/home.tsx
@@ -32,7 +32,6 @@ import {
} from '../../../../../src/plugins/data_source_management/public/components/data_source_menu/types';
import * as pluginManifest from '../../../opensearch_dashboards.json';
import './home.scss';
-import { uiSettingsService } from '../common/utils';
interface QueryExplorerProps {
parentBreadCrumbs: ChromeBreadcrumb[];
@@ -155,7 +154,7 @@ export const Home = ({
<>
{shouldShowCreateIndex ? (
-
+
) : (