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

[Backport 2.x] Navigate to Import Sample Data Page without Refresh when New Home is Enabled #458

Merged
merged 1 commit into from
Oct 21, 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Create index component Renders create index component 1`] = `
<CreateIndex>
<CreateIndex
application={
Object {
"navigateToApp": [MockFunction],
}
}
chrome={
Object {
"navGroup": Object {
"getNavGroupEnabled": [MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"type": "return",
"value": false,
},
],
},
},
}
}
>
<Header>
<EuiPanel
borderRadius="none"
Expand Down Expand Up @@ -105,12 +128,14 @@ exports[`Create index component Renders create index component 1`] = `
>
Learn how to index your data
</EuiLink>
, or
, or

<EuiLink
href="/app/home#/tutorial_directory"
>
add sample data
add sample data
</EuiLink>

to OpenSearch Dashboards.
</p>
}
Expand Down Expand Up @@ -209,7 +234,8 @@ exports[`Create index component Renders create index component 1`] = `
</EuiScreenReaderOnly>
</a>
</EuiLink>
, or
, or

<EuiLink
href="/app/home#/tutorial_directory"
>
Expand All @@ -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
</a>
</EuiLink>

to OpenSearch Dashboards.
</p>
</div>
Expand Down
31 changes: 29 additions & 2 deletions public/components/query_compare/__test__/create_index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,46 @@
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(<CreateIndex />);
const wrapper = mount(
<CreateIndex chrome={coreMockStart.chrome} application={coreMockStart.application} />
);

wrapper.update();

await waitFor(() => {
expect(wrapper).toMatchSnapshot();
});
});

it('should call application.navigateToApp', async () => {
coreMockStart.chrome.navGroup.getNavGroupEnabled.mockReturnValue(true);
const { getByText } = render(
<CreateIndex chrome={coreMockStart.chrome} application={coreMockStart.application} />
);

fireEvent.click(getByText('add sample data'));
expect(coreMockStart.application.navigateToApp).toHaveBeenLastCalledWith('import_sample_data');
});
});
24 changes: 21 additions & 3 deletions public/components/query_compare/create_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<Header />
Expand All @@ -24,8 +31,19 @@ export const CreateIndex = () => {
>
Learn how to index your data
</EuiLink>
, or <EuiLink href="/app/home#/tutorial_directory">add sample data </EuiLink>to
OpenSearch Dashboards.
, or{' '}
<EuiLink
{...(navGroupEnabled
? {
onClick: () => {
application.navigateToApp('import_sample_data');
},
}
: { href: '/app/home#/tutorial_directory' })}
>
add sample data
</EuiLink>{' '}
to OpenSearch Dashboards.
</p>
}
/>
Expand Down
3 changes: 1 addition & 2 deletions public/components/query_compare/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -155,7 +154,7 @@ export const Home = ({
<>
<div className="osdOverviewWrapper">
{shouldShowCreateIndex ? (
<CreateIndex />
<CreateIndex application={application} chrome={chrome} />
) : (
<SearchResult
application={application}
Expand Down
Loading