From 6a1441cc06da81c106e70c790f81fada5e947958 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Wed, 8 Apr 2020 13:44:41 -0400 Subject: [PATCH 1/5] Remove the console log --- src/components/AddressSearchBGroup/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/AddressSearchBGroup/index.js b/src/components/AddressSearchBGroup/index.js index ca18c291..b89040fa 100644 --- a/src/components/AddressSearchBGroup/index.js +++ b/src/components/AddressSearchBGroup/index.js @@ -89,7 +89,6 @@ class AddressSearchBGroup extends Component { } let result = ''; - console.log(this.props.buildings); const bGroupBuildingIDs = this.state.bGroupBuildings.map(building => building.building_id); if (this.props.buildings !== undefined && this.props.buildings.length > 0) { if (this.state.searchClicked) { -- GitLab From f5323bec071b6eb54cc460541f1b0ab67501103a Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Wed, 8 Apr 2020 14:42:18 -0400 Subject: [PATCH 2/5] new building address endpoint --- src/containers/SearchBar/actions.js | 27 ++++++++++++++++++++++++++ src/containers/SearchBar/constants.js | 3 +++ src/containers/SearchBar/reducer.js | 23 ++++++++++++++++++++++ src/containers/SearchBar/sagas.js | 21 ++++++++++++++++++++ src/screens/BuildingsHomePage/index.js | 4 ++++ 5 files changed, 78 insertions(+) diff --git a/src/containers/SearchBar/actions.js b/src/containers/SearchBar/actions.js index 623714c8..454c2f92 100644 --- a/src/containers/SearchBar/actions.js +++ b/src/containers/SearchBar/actions.js @@ -4,6 +4,9 @@ import { SEARCH_BUILDINGS, SEARCH_BUILDINGS_SUCCESS, SEARCH_BUILDINGS_ERROR, + CREATE_BUILDING, + CREATE_BUILDING_SUCCESS, + CREATE_BUILDING_ERROR, } from './constants'; /** @@ -44,3 +47,27 @@ export function buildingsSearchingError(error, args) { error, }; } + +export function buildingCreated(buildings, args) { + if (args) { + const address = `Address created: ${args.address}`; + if (buildings.length > 0) { + ReactGA.event({ category: 'Create', action: 'Success', label: `${address}` }); + } else { + ReactGA.event({ category: 'Create', action: 'Fail', label: `${address} not found` }); + } + } + return { + type: CREATE_BUILDINGS_SUCCESS, + payload: buildings, + }; +} + +// TODO: Add doctring +export function buildingCreatingError(error, args) { + ReactGA.event({ category: 'Create', action: 'Error', label: `Created for ${args.address}, Failed due to ${error}` }); + return { + type: CREATE_BUILDINGS_ERROR, + error, + }; +} \ No newline at end of file diff --git a/src/containers/SearchBar/constants.js b/src/containers/SearchBar/constants.js index b0a679aa..1ee0c361 100644 --- a/src/containers/SearchBar/constants.js +++ b/src/containers/SearchBar/constants.js @@ -3,3 +3,6 @@ export const UPDATE_BUILDING_SEARCH_PARAMS = 'UPDATE_BUILDING_SEARCH_PARAMS'; export const SEARCH_BUILDINGS = 'SEARCH_BUILDINGS'; export const SEARCH_BUILDINGS_SUCCESS = 'SEARCH_BUILDINGS_SUCCESS'; export const SEARCH_BUILDINGS_ERROR = 'SEARCH_BUILDINGS_ERROR'; +export const CREATE_BUILDING = 'CREATE_BUILDING'; +export const CREATE_BUILDING_SUCCESS = 'CREATE_BUILDING_SUCCESS'; +export const CREATE_BUILDING_ERROR = 'CREATE_BUILDING_ERROR'; diff --git a/src/containers/SearchBar/reducer.js b/src/containers/SearchBar/reducer.js index fbef0b65..ff2c9232 100644 --- a/src/containers/SearchBar/reducer.js +++ b/src/containers/SearchBar/reducer.js @@ -2,6 +2,9 @@ import { SEARCH_BUILDINGS, SEARCH_BUILDINGS_SUCCESS, SEARCH_BUILDINGS_ERROR, + CREATE_BUILDING, + CREATE_BUILDING_SUCCESS, + CREATE_BUILDING_ERROR, } from './constants'; const initState = { @@ -32,6 +35,26 @@ export default function (state = initState, action) { loading: false, error: action.error, }; + case CREATE_BUILDING: + return { + ...state, + loading: true, + error: false, + }; + case CREATE_BUILDING_SUCCESS: { + return { + ...state, + buildings: action.payload, + loading: false, + error: false, + }; + } + case CREATE_BUILDING_ERROR: + return { + ...state, + loading: false, + error: action.error, + }; default: return state; } diff --git a/src/containers/SearchBar/sagas.js b/src/containers/SearchBar/sagas.js index 47288ccd..8675ed19 100644 --- a/src/containers/SearchBar/sagas.js +++ b/src/containers/SearchBar/sagas.js @@ -4,11 +4,14 @@ import { getHeaders, buildingsURL } from '../../utils/restServices'; import { SEARCH_BUILDINGS, + CREATE_BUILDING, } from './constants'; import { buildingsSearched, buildingsSearchingError, + buildingCreated, + buildingCreatingError, } from './actions'; /** @@ -31,9 +34,27 @@ function* getBuildingsByFilter(action) { } } +function* createBuilding(action) { + const placeName = action.address; + const res = yield call( + request, + `${buildingsURL}?place_name=${placeName}`, { + method: 'POST', + headers: getHeaders(), + } + ); + + if (!res.err) { + yield put(buildingCreated(res.data, placeName)); + } else { + yield put(buildingCreatingError(res.err, placeName)); + } +} + /** * TODO: docstring */ export default function* buildingsWatcher() { yield takeLatest(SEARCH_BUILDINGS, getBuildingsByFilter); + yield takeLatest(CREATE_BUILDING, createBuilding); } diff --git a/src/screens/BuildingsHomePage/index.js b/src/screens/BuildingsHomePage/index.js index 23e5c100..ad0daea4 100644 --- a/src/screens/BuildingsHomePage/index.js +++ b/src/screens/BuildingsHomePage/index.js @@ -16,6 +16,10 @@ import NotAuthorized from '../../components/NotAuthorized'; /* eslint-disable react/prefer-stateless-function */ class BuildingsHomePage extends Component { + + function componentDidMount() { + console.log(this.props.buildingList.buildings); + } render() { if (!this.props.user.permissions['view::buildingSearch']) { -- GitLab From 621ea3661caeecb0052055230b229b77c3bced60 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Wed, 8 Apr 2020 14:58:38 -0400 Subject: [PATCH 3/5] add console logs for debugging --- src/containers/SearchBar/actions.js | 20 +++++++++++++++++--- src/screens/BuildingsHomePage/index.js | 7 ++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/containers/SearchBar/actions.js b/src/containers/SearchBar/actions.js index 454c2f92..65b78102 100644 --- a/src/containers/SearchBar/actions.js +++ b/src/containers/SearchBar/actions.js @@ -48,6 +48,20 @@ export function buildingsSearchingError(error, args) { }; } +/** + * Load the list of buildings, this action starts the request saga + * + * @param {dict} args The args to send to the backend + * @returns {object} An action object with a type of LOAD_BUILDINGS + * and filterName and value + */ +export function createBuilding(address) { + return { + type: CREATE_BUILDING, + address, + }; +} + export function buildingCreated(buildings, args) { if (args) { const address = `Address created: ${args.address}`; @@ -58,7 +72,7 @@ export function buildingCreated(buildings, args) { } } return { - type: CREATE_BUILDINGS_SUCCESS, + type: CREATE_BUILDING_SUCCESS, payload: buildings, }; } @@ -67,7 +81,7 @@ export function buildingCreated(buildings, args) { export function buildingCreatingError(error, args) { ReactGA.event({ category: 'Create', action: 'Error', label: `Created for ${args.address}, Failed due to ${error}` }); return { - type: CREATE_BUILDINGS_ERROR, + type: CREATE_BUILDING_ERROR, error, }; -} \ No newline at end of file +} diff --git a/src/screens/BuildingsHomePage/index.js b/src/screens/BuildingsHomePage/index.js index ad0daea4..12015db0 100644 --- a/src/screens/BuildingsHomePage/index.js +++ b/src/screens/BuildingsHomePage/index.js @@ -16,12 +16,13 @@ import NotAuthorized from '../../components/NotAuthorized'; /* eslint-disable react/prefer-stateless-function */ class BuildingsHomePage extends Component { - - function componentDidMount() { - console.log(this.props.buildingList.buildings); + + componentDidMount() { + console.log(this.props.buildingList.buildings); // eslint-disable-line } render() { + console.log(this.props.buildingList.buildings); // eslint-disable-line if (!this.props.user.permissions['view::buildingSearch']) { return ; } -- GitLab From 63fa2cf25490f1d037f87ebd4427f6ad5e5ffe98 Mon Sep 17 00:00:00 2001 From: Jinal Soni Date: Wed, 8 Apr 2020 15:22:18 -0400 Subject: [PATCH 4/5] address not in building service logic --- src/screens/BuildingsHomePage/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/screens/BuildingsHomePage/index.js b/src/screens/BuildingsHomePage/index.js index 12015db0..eec2e125 100644 --- a/src/screens/BuildingsHomePage/index.js +++ b/src/screens/BuildingsHomePage/index.js @@ -9,6 +9,7 @@ import { buildingListPropTypes } from '../../containers/SearchBar/propTypes'; import { searchBuildings, buildingsSearched, + createBuilding, } from '../../containers/SearchBar/actions'; import userPropType from '../../containers/User/propTypes'; import NotAuthorized from '../../components/NotAuthorized'; @@ -21,6 +22,17 @@ class BuildingsHomePage extends Component { console.log(this.props.buildingList.buildings); // eslint-disable-line } + componentWillReceiveProps(nextProps) { + console.log(this.props.buildingList.buildings); + console.log(nextProps.buildingList.buildings); + if ( + this.props.buildingList !== nextProps.buildingList + && nextProps.buildingList.buildings.length === 0 + ) { + this.props.createBuilding(nextProps.buildingList.address); + } + } + render() { console.log(this.props.buildingList.buildings); // eslint-disable-line if (!this.props.user.permissions['view::buildingSearch']) { @@ -63,6 +75,7 @@ BuildingsHomePage.propTypes = { buildingList: buildingListPropTypes, searchBuildings: PropTypes.func, buildingsSearched: PropTypes.func, + createBuilding: PropTypes.func, user: userPropType, }; @@ -73,6 +86,7 @@ function mapDispatchToProps(dispatch) { return bindActionCreators({ searchBuildings, buildingsSearched, + createBuilding, }, dispatch); } -- GitLab From bc7c8c0de6a9dd0065c4cfb7b5cdb7de1025a4d2 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Wed, 8 Apr 2020 18:39:45 -0400 Subject: [PATCH 5/5] Add POST action to allow creating new building with fake object --- .../AddressSearchBuildings/index.js | 2 ++ src/components/NavBar/index.js | 2 ++ src/containers/SearchBar/sagas.js | 31 ++++++++++++++----- src/screens/BuildingsHomePage/index.js | 18 +++++++---- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/components/AddressSearchBuildings/index.js b/src/components/AddressSearchBuildings/index.js index f2465456..139149e0 100644 --- a/src/components/AddressSearchBuildings/index.js +++ b/src/components/AddressSearchBuildings/index.js @@ -51,6 +51,7 @@ class AddressSearchBuildings extends Component { addressFound: true, }, () => { this.props.searchBuildings(this.state.address); + this.props.setAddress(this.state.address); }); } @@ -115,6 +116,7 @@ AddressSearchBuildings.propTypes = { buildingList: PropTypes.objectOf, searchBuildings: PropTypes.func, buildingsSearched: PropTypes.func, + setAddress: PropTypes.func, }; export default AddressSearchBuildings; diff --git a/src/components/NavBar/index.js b/src/components/NavBar/index.js index 9d0190b3..9c3c1e8f 100644 --- a/src/components/NavBar/index.js +++ b/src/components/NavBar/index.js @@ -65,6 +65,7 @@ export default class NavBar extends Component { buildingsSearched={this.buildingsSearched} searchBuildings={this.searchBuildings} setNavbar={this.setNavbar} + setAddress={this.props.setAddress} /> : null}