Skip to content
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

Large diffs are not rendered by default.

26 changes: 22 additions & 4 deletions src/plugins/home/public/application/components/home.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { Home } from './home';

import { FeatureCatalogueCategory } from '../../services';
import { telemetryPluginMock } from '../../../../telemetry/public/mocks';
import { Welcome } from './welcome';

let mockHasIntegrationsPermission = true;
jest.mock('../kibana_services', () => ({
getServices: () => ({
getBasePath: () => 'path',
Expand All @@ -22,6 +24,13 @@ jest.mock('../kibana_services', () => ({
chrome: {
setBreadcrumbs: () => {},
},
application: {
capabilities: {
navLinks: {
integrations: mockHasIntegrationsPermission,
},
},
},
}),
}));

Expand All @@ -35,6 +44,7 @@ describe('home', () => {
let defaultProps: HomeProps;

beforeEach(() => {
mockHasIntegrationsPermission = true;
defaultProps = {
directories: [],
solutions: [],
Expand Down Expand Up @@ -182,7 +192,7 @@ describe('home', () => {

expect(defaultProps.localStorage.getItem).toHaveBeenCalledTimes(1);

expect(component).toMatchSnapshot();
expect(component.find(Welcome).exists()).toBe(true);
});

test('stores skip welcome setting if skipped', async () => {
Expand All @@ -196,7 +206,7 @@ describe('home', () => {

expect(defaultProps.localStorage.setItem).toHaveBeenCalledWith('home:welcome:show', 'false');

expect(component).toMatchSnapshot();
expect(component.find(Welcome).exists()).toBe(false);
});

test('should show the normal home page if loading fails', async () => {
Expand All @@ -205,15 +215,23 @@ describe('home', () => {
const hasUserIndexPattern = jest.fn(() => Promise.reject('Doh!'));
const component = await renderHome({ hasUserIndexPattern });

expect(component).toMatchSnapshot();
expect(component.find(Welcome).exists()).toBe(false);
});

test('should show the normal home page if welcome screen is disabled locally', async () => {
defaultProps.localStorage.getItem = jest.fn(() => 'false');

const component = await renderHome();

expect(component).toMatchSnapshot();
expect(component.find(Welcome).exists()).toBe(false);
});

test("should show the normal home page if user doesn't have access to integrations", async () => {
mockHasIntegrationsPermission = false;

const component = await renderHome();

expect(component.find(Welcome).exists()).toBe(false);
});
});

Expand Down
8 changes: 4 additions & 4 deletions src/plugins/home/public/application/components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export class Home extends Component<HomeProps, State> {
constructor(props: HomeProps) {
super(props);

const isWelcomeEnabled = !(
getServices().homeConfig.disableWelcomeScreen ||
props.localStorage.getItem(KEY_ENABLE_WELCOME) === 'false'
);
const isWelcomeEnabled =
!getServices().homeConfig.disableWelcomeScreen &&
getServices().application.capabilities.navLinks.integrations &&
props.localStorage.getItem(KEY_ENABLE_WELCOME) !== 'false';

const body = document.querySelector('body')!;
body.classList.add('isHomPage');
Expand Down
12 changes: 11 additions & 1 deletion src/plugins/home/public/application/components/home_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ const RedirectToDefaultApp = () => {
return null;
};

const REDIRECT_TO_INTEGRATIONS_TAB_IDS = ['all', 'logging', 'metrics', 'security'];

export function HomeApp({ directories, solutions }) {
const {
application,
savedObjectsClient,
getBasePath,
addBasePath,
Expand All @@ -39,10 +42,17 @@ export function HomeApp({ directories, solutions }) {
const isCloudEnabled = environment.cloud;

const renderTutorialDirectory = (props) => {
// Redirect to integrations app unless a specific tab that is still supported was specified.
const tabId = props.match.params.tab;
if (!tabId || REDIRECT_TO_INTEGRATIONS_TAB_IDS.includes(tabId)) {
application.navigateToApp('integrations', { replace: true });
return null;
}

return (
<TutorialDirectory
addBasePath={addBasePath}
openTab={props.match.params.tab}
openTab={tabId}
isCloudEnabled={isCloudEnabled}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ const INSTRUCTIONS_TYPE = {
ON_PREM_ELASTIC_CLOUD: 'onPremElasticCloud',
};

const homeTitle = i18n.translate('home.breadcrumbs.homeTitle', { defaultMessage: 'Home' });
const addDataTitle = i18n.translate('home.breadcrumbs.addDataTitle', {
defaultMessage: 'Add data',
const integrationsTitle = i18n.translate('home.breadcrumbs.integrationsAppTitle', {
defaultMessage: 'Integrations',
});

class TutorialUi extends React.Component {
Expand Down Expand Up @@ -80,12 +79,8 @@ class TutorialUi extends React.Component {

getServices().chrome.setBreadcrumbs([
{
text: homeTitle,
href: '#/',
},
{
text: addDataTitle,
href: '#/tutorial_directory',
text: integrationsTitle,
href: this.props.addBasePath('/app/integrations/browse'),
},
{
text: tutorial ? tutorial.name : this.props.tutorialId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ import { getServices } from '../kibana_services';
import { KibanaPageTemplate } from '../../../../kibana_react/public';
import { getTutorials } from '../load_tutorials';

const ALL_TAB_ID = 'all';
const SAMPLE_DATA_TAB_ID = 'sampleData';

const homeTitle = i18n.translate('home.breadcrumbs.homeTitle', { defaultMessage: 'Home' });
const addDataTitle = i18n.translate('home.breadcrumbs.addDataTitle', {
defaultMessage: 'Add data',
const integrationsTitle = i18n.translate('home.breadcrumbs.integrationsAppTitle', {
defaultMessage: 'Integrations',
});

class TutorialDirectoryUi extends React.Component {
Expand All @@ -48,7 +46,7 @@ class TutorialDirectoryUi extends React.Component {
})),
];

let openTab = ALL_TAB_ID;
let openTab = SAMPLE_DATA_TAB_ID;
if (
props.openTab &&
this.tabs.some((tab) => {
Expand All @@ -72,10 +70,9 @@ class TutorialDirectoryUi extends React.Component {

getServices().chrome.setBreadcrumbs([
{
text: homeTitle,
href: '#/',
text: integrationsTitle,
href: this.props.addBasePath(`/app/integrations/browse`),
},
{ text: addDataTitle },
]);

const tutorialConfigs = await getTutorials();
Expand Down Expand Up @@ -155,6 +152,15 @@ class TutorialDirectoryUi extends React.Component {
renderTabContent = () => {
const tab = this.tabs.find(({ id }) => id === this.state.selectedTabId);
if (tab?.content) {
getServices().chrome.setBreadcrumbs([
{
text: integrationsTitle,
href: this.props.addBasePath(`/app/integrations/browse`),
},
{
text: tab.name,
},
]);
return tab.content;
}

Expand All @@ -163,7 +169,7 @@ class TutorialDirectoryUi extends React.Component {
{this.state.tutorialCards
.filter((tutorial) => {
return (
this.state.selectedTabId === ALL_TAB_ID ||
this.state.selectedTabId === SAMPLE_DATA_TAB_ID ||
this.state.selectedTabId === tutorial.category
);
})
Expand Down
Loading