Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

Commit

Permalink
Merge 7bf7a14 into ea6525c
Browse files Browse the repository at this point in the history
  • Loading branch information
rvennam committed Jan 28, 2017
2 parents ea6525c + 7bf7a14 commit 9fa87ea
Show file tree
Hide file tree
Showing 66 changed files with 1,265 additions and 692 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"no-constant-condition": [2, {"checkLoops": false}],
"react/jsx-filename-extension": [0],
"func-names": [0],
"react/prefer-stateless-function": [1]
"react/prefer-stateless-function": [1],
"no-console": "off",
"no-underscore-dangle": "off"
}
}
19 changes: 19 additions & 0 deletions src/components/GhostButton/GhostButton.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import test from 'ava';
import React from 'react';
import { shallow } from 'enzyme';
import GhostButton from './GhostButton';

const setup = () => {
const spies = {
};
const props = {
};
const component = shallow(<GhostButton label="Ghost Button" />);

return { component, props, spies };
};

test('(Component) Has expected elements.', t => {
const { component } = setup();
t.is(component.find('RaisedButton').length, 1);
});
29 changes: 21 additions & 8 deletions src/components/GlobalNav/GlobalNav.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { connect } from 'react-redux';
import { endDemoSession } from 'modules/demos';
import IconButton from 'material-ui/IconButton';
import { Toolbar, ToolbarGroup, ToolbarTitle, ToolbarSeparator } from 'material-ui/Toolbar';
import { Toolbar, ToolbarGroup, ToolbarTitle } from 'material-ui/Toolbar';
import { Icon } from 'react-fa';
import { Link } from 'react-router';
import RoleSwitcher from 'containers/RoleSwitcherContainer';
Expand All @@ -11,15 +13,18 @@ const styles = {
margin: '0px 0.75rem 0px 1rem',
},
toolbarTitle: {
fontSize: '.8rem',
fontSize: '0.8rem',
fontWeight: '600',
},
toolbar: {
height: '42px',
height: '56px',
},
iconButton: {
top: '-1.5px',
},
};

export const GlobalNav = () => (
export const GlobalNav = (props) => (
<div className={classes.globalNav}>
<Toolbar style={styles.toolbar}>
<ToolbarGroup firstChild>
Expand All @@ -29,9 +34,8 @@ export const GlobalNav = () => (
</ToolbarGroup>

<ToolbarGroup>
<RoleSwitcher />
<ToolbarSeparator style={styles.separator} />
<IconButton >
<RoleSwitcher logout={props.endDemoSession} />
<IconButton style={styles.iconButton}>
<a href="https://github.com/IBM-Bluemix/logistics-wizard" target="_blank">
<Icon
name="github"
Expand All @@ -46,6 +50,15 @@ export const GlobalNav = () => (
);

GlobalNav.propTypes = {
endDemoSession: React.PropTypes.func.isRequired,
};

const mapActionCreators = {
endDemoSession,
};

export default GlobalNav;
const mapStateToProps = () => ({
});

// export default GlobalNav;
export default connect(mapStateToProps, mapActionCreators)(GlobalNav);
3 changes: 2 additions & 1 deletion src/components/GlobalNav/GlobalNav.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@import '~styles/base/colors';

.title {
padding-left: 2rem;
margin-left: 0;
padding-left: 24px;
color: $alternateTextColor;
}

Expand Down
3 changes: 1 addition & 2 deletions src/components/GlobalNav/GlobalNav.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'ava';
import React from 'react';
import { shallow } from 'enzyme';
import GlobalNav from './GlobalNav';
import { GlobalNav } from './GlobalNav';

const setup = () => {
const spies = {
Expand All @@ -15,7 +15,6 @@ const setup = () => {

test('(Component) Has expected elements.', t => {
const { component } = setup();

t.is(component.find('Connect(RoleSwitcher)').length, 1);
t.is(component.find('Link').length, 1);
t.is(component.find('Link').first().props().to, '/');
Expand Down
2 changes: 1 addition & 1 deletion src/components/GlobalNav/RoleSwitcher/RoleItem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
margin: 0;
padding: 0;
padding-left: 5px;
padding-right: 5px;
outline: none;

&:last-child {
Expand All @@ -29,7 +30,6 @@
.iconContainer {
border-left: 5px solid transparent;
align-self: center;

}

.icon {
Expand Down
26 changes: 20 additions & 6 deletions src/components/GlobalNav/RoleSwitcher/RoleSwitcher.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import IconMenu from 'material-ui/IconMenu';
import IconButton from 'material-ui/IconButton';
import AccountUser from 'material-ui/svg-icons/action/account-circle';
import { palette } from 'styles/muiTheme';
import RoleItem from './RoleItem';
import LoadingSpinner from 'components/LoadingSpinner';
import RoleItem from './RoleItem';
import classes from './RoleItem.scss';


const iconStyles = {
width: '1.7rem',
Expand All @@ -20,20 +22,31 @@ const AccountButton = () => (
</IconButton>
);

export const RoleSwitcher = ({ users, login, createUser }) => (
users
export const RoleSwitcher = (props) => (
props.users
? <IconMenu
anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
iconButtonElement={AccountButton()}
>
{users.map((user, key) => (
{props.users.map((user, key) => (
<RoleItem
key={key}
user={user}
roleAction={login}
roleAction={props.login}
/>
))}
<RoleItem roleAction={createUser} />
<button className={classes.item} onClick={props.logout}>
<div className={classes.iconContainer}>
<i className={`${classes.icon} fa-sign-out fa`} />
</div>
<div className={classes.textContainer}>
<div className={classes.label}>
End Session
</div>
</div>
</button>
{/* keep new user creation disabled until it becomes useful */}
{/* <RoleItem roleAction={createUser} /> */}
</IconMenu>
: <div><LoadingSpinner color={palette.primary3Color} /></div>
);
Expand All @@ -47,6 +60,7 @@ RoleSwitcher.propTypes = {
}).isRequired),
login: React.PropTypes.func.isRequired,
createUser: React.PropTypes.func.isRequired,
logout: React.PropTypes.func.isRequired,
};

export default RoleSwitcher;
20 changes: 20 additions & 0 deletions src/components/GlobalNav/RoleSwitcher/RoleSwitcher.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import test from 'ava';
import React from 'react';
import { shallow } from 'enzyme';
import RoleSwitcher from './RoleSwitcher';

const setup = () => {
const spies = {
};
const props = {
};
const component = shallow(<RoleSwitcher />);

return { component, props, spies };
};

test('(Component) Has expected elements.', t => {
const { component } = setup();
t.is(component.find('div').length, 1);
t.is(component.find('LoadingSpinner').length, 1);
});
7 changes: 4 additions & 3 deletions src/components/LoadingSpinner/LoadingSpinner.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import CircularProgress from 'material-ui/CircularProgress';
import { palette } from 'styles/muiTheme';

const LoadingSpinner = (props) => (
<CircularProgress
style={props.style || {marginLeft: '50%'}}
color={props.color}
size={props.size || .5}
style={props.style || {}}
color={props.color || palette.primary3Color}
size={props.size || 32}
/>
);

Expand Down
8 changes: 8 additions & 0 deletions src/components/LoadingSpinner/LoadingSpinner.story.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import { storiesOf } from '@kadira/storybook';
import LoadingSpinner from './LoadingSpinner';

storiesOf('LoadingSpinner', module)
.add('default', () => (
<LoadingSpinner />
));
19 changes: 19 additions & 0 deletions src/components/LoadingSpinner/LoadingSpinner.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import test from 'ava';
import React from 'react';
import { shallow } from 'enzyme';
import LoadingSpinner from './LoadingSpinner';

const setup = () => {
const spies = {
};
const props = {
};
const component = shallow(<LoadingSpinner />);

return { component, props, spies };
};

test('(Component) Has expected elements.', t => {
const { component } = setup();
t.is(component.find('CircularProgress').length, 1);
});
2 changes: 1 addition & 1 deletion src/containers/AppContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const AppContainer = (props) => {
return (
<Provider store={store}>
<MuiThemeProvider muiTheme={muiTheme}>
<div style={{ height: '100vh' }}>
<div style={{ display: 'flex', flexGrow: 1, flexDirection: 'column' }}>
<Router history={history} children={routes} />
</div>
</MuiThemeProvider>
Expand Down
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<link href="https://fonts.googleapis.com/css?family=Libre+Franklin:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
</head>
<body>
<div id="root" style="height: 100%"></div>
<div id="root" style="display: flex; flex-direction: column; height: 100%"></div>
</body>
</html>
6 changes: 4 additions & 2 deletions src/layouts/CoreLayout/CoreLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import 'styles/core.scss';

const styles = {
wrapper: {
height: '100%',
display: 'flex',
flexDirection: 'column',
flexGrow: 1,
},
content: {
flex: 1,
display: 'flex',
flexDirection: 'column',
flexGrow: 1,
},
};

Expand Down
21 changes: 21 additions & 0 deletions src/modules/demos.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getAdminData } from 'routes/Dashboard/modules/Dashboard';
export const CREATE_DEMO = 'demos/CREATE_DEMO';
export const CREATE_DEMO_FAILURE = 'demos/CREATE_DEMO_FAILURE';
export const GET_DEMO_SESSION = 'demos/GET_DEMO_SESSION';
export const END_DEMO_SESSION = 'demos/END_DEMO_SESSION';
export const GET_DEMO_SUCCESS = 'demos/GET_DEMO_SUCCESS';
export const LOGIN = 'demos/LOGIN';
export const LOGIN_SUCCESS = 'demos/LOGIN_SUCCESS';
Expand All @@ -33,6 +34,10 @@ export const getDemoSession = (guid) => ({
guid,
});

export const endDemoSession = () => ({
type: END_DEMO_SESSION,
});

export const getDemoSuccess = (payload) => ({
type: GET_DEMO_SUCCESS,
demo: payload.demo,
Expand Down Expand Up @@ -165,6 +170,21 @@ export function *watchGetDemoSession() {
}
}

export function *watchEndDemoSession() {
while (true) {
yield take(END_DEMO_SESSION);
const demoState = yield select(demoSelector);
try {
yield call(api.endDemo, demoState.guid);
}
catch (error) {
console.log('Error during logout', error);
}
window.localStorage.removeItem('savedGuid');
yield put(push('/'));
}
}

export function *watchLogin() {
while (true) {
const { userid } = yield take(LOGIN);
Expand All @@ -183,6 +203,7 @@ export function *watchLogin() {

export const sagas = [
watchCreateDemo,
watchEndDemoSession,
watchGetDemoSession,
watchLogin,
];
10 changes: 5 additions & 5 deletions src/routes/Dashboard/components/AlertsCard/AlertsCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ import React from 'react';
import { connect } from 'react-redux';
import classes from './AlertsCard.scss';

export const AlertsCard = ({ weather }) => (
<div className={weather.length > 0 ? classes.wrapper : classes.hidden}>
export const AlertsCard = ({ storms }) => (
<div className={storms.length > 0 ? classes.wrapper : classes.hidden}>
<div className={classes.content}>
<div>{weather.length} storm(s) detected!</div>
<div>{storms.length} storm(s) detected!</div>
<i className={`fa fa-times-circle-o ${classes.closeIcon}`} />
</div>
</div>
);

AlertsCard.propTypes = {
weather: React.PropTypes.array,
storms: React.PropTypes.array,
};

// ------------------------------------
// Connect Component to Redux
// ------------------------------------

const mapStateToProps = (state) => ({
weather: state.dashboard.weather,
storms: state.dashboard.storms,
});

export default connect(mapStateToProps, {})(AlertsCard);
2 changes: 1 addition & 1 deletion src/routes/Dashboard/components/AlertsCard/AlertsCard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

.wrapper {
border: 1px solid $map2Primary;
margin-bottom: 1rem;
margin: 1rem;
background-color: $map2Accent;
padding: 6px;
padding-left: 12px;
Expand Down
Loading

0 comments on commit 9fa87ea

Please sign in to comment.