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

Move things around, make the navigation calculation run in seperate thread #955

Merged
merged 6 commits into from
Sep 14, 2020
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
26 changes: 26 additions & 0 deletions src/js/App/Header/Header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { Fragment } from 'react';
import Brand from './Brand';
import Tools from './Tools';
import UnAuthtedHeader from './UnAuthtedHeader';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';

const Header = ({ user }) => {
return user ? (
<Fragment>
<Brand />
<Tools />
</Fragment>
) : <UnAuthtedHeader />;
};

Header.propTypes = {
user: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.shape({
[PropTypes.string]: PropTypes.any
})
])
};

export default connect(({ chrome: { user } }) => ({ user }))(Header);
34 changes: 34 additions & 0 deletions src/js/App/Header/HeaderTests/Header.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import toJson from 'enzyme-to-json';
import { shallow, mount } from 'enzyme';
import configureStore from 'redux-mock-store';
import { Provider } from 'react-redux';
import Header from '../Header';
import UnauthedHeader from '../UnAuthtedHeader';

describe('Header', () => {
let initialState;
let mockStore;

beforeEach(() =>{
mockStore = configureStore();
initialState = ({ chrome: {
activeTechnology: 'someTechnology',
activeLocation: 'someLocation'
} });
});
it('should render correctly', () => {
const store = mockStore(initialState);
const wrapper = mount(<Provider store={store}>
<Header currentApp='Red Hat Insights'/>
</Provider>);
expect(toJson(wrapper, { mode: 'deep' })).toMatchSnapshot();
});
});

describe('unauthed', () => {
it('should render correctly', () => {
const wrapper = shallow(<UnauthedHeader/>);
expect(toJson(wrapper)).toMatchSnapshot();
});
});
88 changes: 88 additions & 0 deletions src/js/App/Header/HeaderTests/__snapshots__/Header.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Header should render correctly 1`] = `
<Connect(Header)
currentApp="Red Hat Insights"
>
Array [
<Connect(Brand)>
<div
className="pf-c-page__header-brand"
>
<div
className="pf-c-page__header-brand-toggle"
>
<button
aria-disabled={false}
aria-label="Toggle primary navigation"
className="pf-c-button pf-m-plain"
data-ouia-component-id={0}
data-ouia-component-type="PF4/Button"
data-ouia-safe={true}
disabled={false}
onClick={[Function]}
type="button"
widget-type="InsightsNavToggle"
>
<svg
aria-hidden={true}
aria-labelledby={null}
fill="currentColor"
height="1.5em"
role="img"
style={
Object {
"verticalAlign": "-0.1875em",
}
}
viewBox="0 0 448 512"
width="1.5em"
>
<path
d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"
transform=""
/>
</svg>
</button>
</div>
<a
className="pf-c-page__header-brand-link"
href="./"
>
<img
alt="Red Hat Logo"
src="test-file-stub"
/>
</a>
</div>
</Connect(Brand)>,
<div
className="pf-c-page__header-tools"
>
<button
aria-disabled={false}
aria-label="Toggle primary navigation"
className="pf-c-button pf-m-tertiary"
data-ouia-component-id={1}
data-ouia-component-type="PF4/Button"
data-ouia-safe={true}
disabled={false}
onClick={[Function]}
type="button"
widget-type="InsightsNavToggle"
>
Log in
</button>
</div>,
"",
]
</Connect(Header)>
`;

exports[`unauthed should render correctly 1`] = `
<Fragment>
<Connect(Brand) />
<Login />
<LogoutAlert />
</Fragment>
`;
16 changes: 0 additions & 16 deletions src/js/App/Header/HeaderTests/__snapshots__/index.test.js.snap

This file was deleted.

19 changes: 0 additions & 19 deletions src/js/App/Header/HeaderTests/index.test.js

This file was deleted.

33 changes: 22 additions & 11 deletions src/js/App/Header/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import React, { Fragment } from 'react';
import Brand from './Brand';
import Tools from './Tools';
import React, { lazy, Suspense, Fragment } from 'react';
import { Provider } from 'react-redux';
import { render } from 'react-dom';
import { spinUpStore } from '../../redux-config';

const Header = () => {
return (
<Fragment>
<Brand />
<Tools />
</Fragment>
);};
const Header = lazy(() => import(/* webpackChunkName: "Sidenav" */ './Header'));

export default Header;
export const headerLoader = () => {
const { store } = spinUpStore();
if (document.querySelector('header')) {
render(
<Provider store={store}>
<Suspense fallback={<Fragment />}>
<Header />
</Suspense>
</Provider>,
document.querySelector('header')
);
}

if (window.insights.chrome.isPenTest()) {
document.querySelector('header').classList.add('ins-c-pen-test');
}
};
2 changes: 1 addition & 1 deletion src/js/App/Sidenav/AppSwitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const AppSwitcher = ({ currentApp }) => {
};

return (
<section className='ins-c-app-switcher'>
<section className="ins-c-app-switcher">
<Dropdown
isPlain
className='ins-c-app-switcher__dropdown'
Expand Down
21 changes: 17 additions & 4 deletions src/js/App/Sidenav/AppSwitcher.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import React from 'react';
import toJson from 'enzyme-to-json';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import configureStore from 'redux-mock-store';
import { Provider } from 'react-redux';
import AppSwitcher from './AppSwitcher';

describe('AppSwitcher', () => {

let initialState;
let mockStore;
beforeEach(() =>{
mockStore = configureStore();
initialState = ({ chrome: {
activeTechnology: 'someTechnology',
activeLocation: 'someLocation'
} });
});
it('should render correctly', () =>{
const wrapper = shallow(<AppSwitcher currentApp='Red Hat Insights'/>);
expect(toJson(wrapper)).toMatchSnapshot();
const store = mockStore(initialState);
const wrapper = mount(<Provider store={store}>
<AppSwitcher currentApp='Red Hat Insights'/>
</Provider>);
expect(toJson(wrapper, { mode: 'deep' })).toMatchSnapshot();
});
});
26 changes: 26 additions & 0 deletions src/js/App/Sidenav/Loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { Fragment } from 'react';
import { Skeleton, SkeletonSize } from '@redhat-cloud-services/frontend-components/components/cjs/Skeleton';
import { Nav } from '@patternfly/react-core/dist/js/components/Nav/Nav';
import { NavList } from '@patternfly/react-core/dist/js/components/Nav/NavList';
import NavigationItem from './NavigationItem';

const NavLoader = () => (
<Fragment>
<section className={'ins-c-app-switcher--loading'}>
<Skeleton size={SkeletonSize.lg} className="ins-m-dark"/>
</section>
<Nav aria-label="Insights Global Navigation" data-ouia-safe="false">
<NavList>
{[...new Array(4)].map((_i, key) => (
<NavigationItem
key={key}
title={<a className="ins-c-skeleton__link">
<Skeleton size={SkeletonSize.lg} className="ins-m-dark"/>
</a>}
/>))}
</NavList>
</Nav>
</Fragment>
);

export default NavLoader;
Loading