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

Commit

Permalink
storms vs weather
Browse files Browse the repository at this point in the history
  • Loading branch information
rvennam987 committed Jan 17, 2017
1 parent 3d5d0a3 commit 7dea2b1
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"react/jsx-filename-extension": [0],
"func-names": [0],
"react/prefer-stateless-function": [1],
"no-console": "off"
"no-console": "off",
"no-underscore-dangle": "off"
}
}
8 changes: 4 additions & 4 deletions src/routes/Dashboard/components/AlertsCard/AlertsCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ 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>
Expand All @@ -20,7 +20,7 @@ AlertsCard.propTypes = {
// ------------------------------------

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

export default connect(mapStateToProps, {})(AlertsCard);
4 changes: 2 additions & 2 deletions src/routes/Dashboard/components/Dashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import Dashboard from './Dashboard';
const setup = () => {
const spies = {
simulateWeather: sinon.spy(),
simulateStorm: sinon.spy(),
};
const props = {
demoName: 'Test Demo',
shipments: [],
retailers: [],
distributionCenters: [],
weather: [],
storms: [],
token: '1234',
};
const component = shallow(<Dashboard {...props} />);
Expand Down
16 changes: 8 additions & 8 deletions src/routes/Dashboard/components/Map/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { connect } from 'react-redux';
import GoogleMap from 'google-map-react';
import RaisedButton from 'material-ui/RaisedButton';
import { simulateWeather, selectMarker } from 'routes/Dashboard/modules/Dashboard';
import { simulateStorm, selectMarker } from 'routes/Dashboard/modules/Dashboard';
import MapMarker from './MapMarker/';
// map style from https://snazzymaps.com/style/151/ultra-light-with-labels
// https://googlemaps.github.io/js-samples/styledmaps/wizard/
Expand Down Expand Up @@ -68,7 +68,7 @@ export const Map = (props) => (
data={retailer}
/>
)}
{props.weather.map((storm, i) =>
{props.storms.map((storm, i) =>
<MapMarker
type="storm"
lat={storm.event.lat}
Expand All @@ -81,7 +81,7 @@ export const Map = (props) => (
</GoogleMap>
<RaisedButton
label="Simulate Storm"
onClick={props.simulateWeather}
onClick={props.simulateStorm}
className={classes.simulateButton}
/>
</div>
Expand All @@ -94,8 +94,8 @@ Map.propTypes = {
distributionCenters: React.PropTypes.array,
shipments: React.PropTypes.array,
retailers: React.PropTypes.array,
weather: React.PropTypes.array,
simulateWeather: React.PropTypes.func.isRequired,
storms: React.PropTypes.array,
simulateStorm: React.PropTypes.func.isRequired,
};

Map.defaultProps = {
Expand All @@ -106,23 +106,23 @@ Map.defaultProps = {
distributionCenters: [],
shipments: [],
retailers: [],
weather: [],
storms: [],
};

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

const mapActionCreators = {
simulateWeather,
simulateStorm,
selectMarker,
};

const mapStateToProps = (state) => ({
shipments: state.dashboard.shipments,
retailers: state.dashboard.retailers,
distributionCenters: state.dashboard['distribution-centers'],
weather: state.dashboard.weather,
storms: state.dashboard.storms,
});

export default connect(mapStateToProps, mapActionCreators)(Map);
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const StormCard = ({ storm }) => {
Consider sending additional supplies to affected locations.
</small>
{recommendations.map(recommendation =>
<div className={classes.shipmentDialog}>
<div className={classes.shipmentDialog} key={recommendation._id}>
<div className={classes.shipmentTitle}>
Shipment from {recommendation.fromId} to {recommendation.toId}
</div>
Expand Down
32 changes: 16 additions & 16 deletions src/routes/Dashboard/modules/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export const dashboardSelector = state => state.dashboard;
// Constants
// ------------------------------------
export const GET_ADMIN_DATA = 'Dashboard/GET_ADMIN_DATA';
export const SIMULATE_WEATHER = 'Dashboard/SIMULATE_WEATHER';
export const SIMULATE_STORM = 'Dashboard/SIMULATE_STORM';
export const SELECT_MARKER = 'Dashboard/SELECT_MARKER';
export const ADMIN_DATA_RECEIVED = 'Dashboard/ADMIN_DATA_RECEIVED';
export const WEATHER_DATA_RECEIVED = 'Dashboard/WEATHER_DATA_RECEIVED';
export const STORM_DATA_RECEIVED = 'Dashboard/STORM_DATA_RECEIVED';
export const WEATHER_OBSERVATIONS = 'Dashboard/WEATHER_OBSERVATIONS';
export const WEATHER_OBSERVATIONS_RECEIVED = 'Dashboard/WEATHER_OBSERVATIONS_RECEIVED';

Expand All @@ -36,12 +36,12 @@ export const adminDataReceived = (payload) => ({
payload,
});

export const simulateWeather = () => ({
type: SIMULATE_WEATHER,
export const simulateStorm = () => ({
type: SIMULATE_STORM,
});

export const weatherDataReceived = payload => ({
type: WEATHER_DATA_RECEIVED,
export const stormDataReceived = payload => ({
type: STORM_DATA_RECEIVED,
payload,
});

Expand All @@ -62,7 +62,7 @@ export const actions = {
selectMarker,
getAdminData,
adminDataReceived,
weatherDataReceived,
stormDataReceived,
};

// ------------------------------------
Expand All @@ -77,9 +77,9 @@ const ACTION_HANDLERS = {
...state,
...action.payload,
}),
[WEATHER_DATA_RECEIVED]: (state, action) => ({
[STORM_DATA_RECEIVED]: (state, action) => ({
...state,
weather: [action.payload],
storms: [action.payload],
}),
[WEATHER_OBSERVATIONS_RECEIVED]: (state, action) => {
// payload.locationType
Expand Down Expand Up @@ -138,7 +138,7 @@ const initialState = {
shipments: [],
retailers: [],
'distribution-centers': [],
weather: [],
storms: [],
};

export const dashboardReducer = (state = initialState, action) => {
Expand Down Expand Up @@ -169,17 +169,17 @@ export function *watchGetAdminData() {
}
}

export function *watchSimulateWeather() {
export function *watchSimulateStorm() {
while (true) {
yield take(SIMULATE_WEATHER);
yield take(SIMULATE_STORM);
const demoState = yield select(demoSelector);

try {
const weatherData = yield call(api.simulateWeather, demoState.token);
yield put(weatherDataReceived(weatherData));
const stormData = yield call(api.simulateStorm, demoState.token);
yield put(stormDataReceived(stormData));
}
catch (error) {
console.log('Failed to retrieve weather data');
console.log('Failed to retrieve storm data from simulation');
console.error(error);
}
}
Expand Down Expand Up @@ -211,6 +211,6 @@ export function *watchWeatherObservations() {

export const sagas = [
watchGetAdminData,
watchSimulateWeather,
watchSimulateStorm,
watchWeatherObservations,
];
2 changes: 1 addition & 1 deletion src/routes/Dashboard/modules/Dashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test('(Action) getAdminData',
// shipments: [],
// retailers: [],
// 'distribution-centers': [],
// weather: [],
// storms: [],
// });
// });

Expand Down
4 changes: 2 additions & 2 deletions src/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const getRetailers = guid => callApi(`demos/${guid}/retailers`);
export const getAdminData = token =>
callApi('admin', { headers: { Authorization: `Bearer ${token}` } });

export const simulateWeather = token =>
export const simulateStorm = token =>
callApi('weather/simulate', {
headers: { Authorization: `Bearer ${token}` },
method: 'POST',
Expand All @@ -58,7 +58,7 @@ export const api = {
login,
getRetailers,
getAdminData,
simulateWeather,
simulateStorm,
getWeatherObservations,
};

Expand Down

0 comments on commit 7dea2b1

Please sign in to comment.