From d9d8caad5d64e0a4c24d34e9d954977d326417df Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Wed, 1 Feb 2017 12:24:41 -0500 Subject: [PATCH 01/11] Move Mechanical Turk redux actions and reducers to Dimensions container --- src/containers/BuildingOverview/constants.js | 9 -- src/containers/BuildingOverview/index.js | 27 +--- src/containers/BuildingOverview/reducer.js | 132 ------------------ src/containers/BuildingOverview/sagas.js | 67 +-------- src/containers/Dimensions/actions.js | 137 +++++++++++++++++++ src/containers/Dimensions/constants.js | 9 ++ src/containers/Dimensions/index.js | 66 +++++++++ src/containers/Dimensions/reducer.js | 135 ++++++++++++++++++ src/containers/Dimensions/sagas.js | 88 ++++++++++++ src/containers/Dimensions/styles.css | 0 src/reducers.js | 2 + src/routes.js | 3 +- src/sagas.js | 2 + 13 files changed, 443 insertions(+), 234 deletions(-) create mode 100644 src/containers/Dimensions/actions.js create mode 100644 src/containers/Dimensions/constants.js create mode 100644 src/containers/Dimensions/index.js create mode 100644 src/containers/Dimensions/reducer.js create mode 100644 src/containers/Dimensions/sagas.js create mode 100644 src/containers/Dimensions/styles.css diff --git a/src/containers/BuildingOverview/constants.js b/src/containers/BuildingOverview/constants.js index 4ed5fd68..25650cab 100644 --- a/src/containers/BuildingOverview/constants.js +++ b/src/containers/BuildingOverview/constants.js @@ -1,12 +1,3 @@ export const LOAD_BUILDING_DETAIL = 'LOAD_BUILDING_DETAIL'; export const LOAD_BUILDING_DETAIL_SUCCEES = 'LOAD_BUILDING_DETAIL_SUCCEES'; export const LOAD_BUILDING_DETAIL_ERROR = 'LOAD_BUILDING_DETAIL_ERROR'; -export const LOAD_HIT = 'LOAD_HIT'; -export const LOAD_HIT_SUCCESS = 'LOAD_HIT_SUCCESS'; -export const LOAD_HIT_ERROR = 'LOAD_HIT_ERROR'; -export const CREATE_HIT = 'CREATE_HIT'; -export const CREATE_HIT_SUCCESS = 'CREATE_HIT_SUCCESS'; -export const CREATE_HIT_ERROR = 'CREATE_HIT_ERROR'; -export const DECIDE_HIT = 'DECIDE_HIT'; -export const DECIDE_HIT_SUCCESS = 'DECIDE_HIT_SUCCESS'; -export const DECIDE_HIT_ERROR = 'DECIDE_HIT_ERROR'; diff --git a/src/containers/BuildingOverview/index.js b/src/containers/BuildingOverview/index.js index 24e62a01..f5561817 100644 --- a/src/containers/BuildingOverview/index.js +++ b/src/containers/BuildingOverview/index.js @@ -3,27 +3,19 @@ import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import buildingDetailPropTypes from './buildingDetailPropType'; -import { - loadBuildingDetail, - loadHit, - createHit, - hitDecision, -} from './actions'; +import { loadBuildingDetail } from './actions'; import './styles.scss'; import BuildingOverviewTop from '../../components/BuildingOverviewTop'; -import TurkHit from '../../components/TurkHit'; class BuildingOverview extends Component { componentDidMount() { this.props.loadBuildingDetail(this.props.params.buildingID); - this.props.loadHit(this.props.params.buildingID); } render() { let mainContent =
; - let hit =
; if (this.props.buildingDetail.overview.error) { mainContent = ( @@ -37,22 +29,11 @@ class BuildingOverview extends Component { building={this.props.buildingDetail.overview} /> ); - - hit = ( - - ); } return (
{mainContent} - {hit}
); } @@ -62,17 +43,11 @@ BuildingOverview.propTypes = { buildingDetail: buildingDetailPropTypes, params: PropTypes.objectOf(PropTypes.string), loadBuildingDetail: PropTypes.func, - loadHit: PropTypes.func, - createHit: PropTypes.func, - hitDecision: PropTypes.func, }; function mapDispatchToProps(dispatch) { return bindActionCreators({ loadBuildingDetail, - loadHit, - createHit, - hitDecision, }, dispatch); } diff --git a/src/containers/BuildingOverview/reducer.js b/src/containers/BuildingOverview/reducer.js index fca40940..198aa937 100644 --- a/src/containers/BuildingOverview/reducer.js +++ b/src/containers/BuildingOverview/reducer.js @@ -2,15 +2,6 @@ import { LOAD_BUILDING_DETAIL, LOAD_BUILDING_DETAIL_SUCCEES, LOAD_BUILDING_DETAIL_ERROR, - LOAD_HIT, - LOAD_HIT_SUCCESS, - LOAD_HIT_ERROR, - CREATE_HIT, - CREATE_HIT_SUCCESS, - CREATE_HIT_ERROR, - DECIDE_HIT, - DECIDE_HIT_SUCCESS, - DECIDE_HIT_ERROR, } from './constants'; const initState = { @@ -18,20 +9,6 @@ const initState = { loading: false, error: false, }, - hit: { - id: '', - status: '', - loading: false, - error: false, - create: { - loading: false, - error: false, - }, - approval: { - loading: false, - error: false, - }, - }, }; export default function (state = initState, action) { @@ -66,115 +43,6 @@ export default function (state = initState, action) { }, }; - case LOAD_HIT: - return { - ...state, - hit: { - ...state.hit, - status: '', - loading: true, - error: false, - }, - }; - - case LOAD_HIT_SUCCESS: - return { - ...state, - hit: { - ...state.hit, - status: action.payload.data.status, - url: action.payload.data.hit_url, - loading: false, - error: false, - }, - }; - - case LOAD_HIT_ERROR: - return { - ...state, - hit: { - ...state.hit, - loading: false, - error: action.error, - }, - }; - - case CREATE_HIT: - return { - ...state, - hit: { - ...state.hit, - create: { - loading: true, - error: false, - }, - }, - }; - - case CREATE_HIT_SUCCESS: - return { - ...state, - hit: { - id: action.payload.data.hit_id, - status: action.payload.data.status, - loading: false, - error: false, - create: { - loading: false, - error: false, - }, - }, - }; - - case CREATE_HIT_ERROR: - return { - ...state, - hit: { - ...state.hit, - create: { - loading: false, - error: action.error, - }, - }, - }; - - case DECIDE_HIT: - return { - ...state, - hit: { - ...state.hit, - approval: { - loading: true, - error: false, - }, - }, - }; - - case DECIDE_HIT_SUCCESS: - return { - ...state, - hit: { - ...state.hit, - status: action.payload.data.hit_status, - approval: { - loading: false, - error: false, - }, - }, - }; - - case DECIDE_HIT_ERROR: - return { - ...state, - hit: { - ...state.hit, - approval: { - loading: false, - error: action.error, - }, - }, - }; - default: return state; } diff --git a/src/containers/BuildingOverview/sagas.js b/src/containers/BuildingOverview/sagas.js index 2a410499..284e2d74 100644 --- a/src/containers/BuildingOverview/sagas.js +++ b/src/containers/BuildingOverview/sagas.js @@ -1,23 +1,14 @@ import { call, put, takeEvery } from 'redux-saga/effects'; import request from '../../utils/request'; -import { getHeaders, turkURL, buildingsURL } from '../../utils/rest_services'; +import { getHeaders, buildingsURL } from '../../utils/rest_services'; import { LOAD_BUILDING_DETAIL, - LOAD_HIT, - CREATE_HIT, - DECIDE_HIT, } from './constants'; import { buildingDetailLoaded, buildingDetailLoadingError, - hitLoaded, - hitLoadingError, - createHitSuccess, - createHitError, - hitDecisionSuccess, - hitDecisionError, } from './actions'; /** @@ -42,68 +33,12 @@ function* getBuildingDetail(action) { } } -function* loadHit(action) { - const buildingId = action.payload; - const data = yield call(request, `${turkURL}${buildingId}`, { - method: 'GET', - headers: getHeaders(), - }); - - if (!data.err) { - yield put(hitLoaded(data)); - } else { - yield put(hitLoadingError(data.err)); - } -} - -/** - * Mechanical Turk HIT creation request/response handler - * - * @param {object} action Form data of mechanical turk job - */ -function* createHit(action) { - const turkHitFormData = action.payload; - const data = yield call(request, turkURL, { - method: 'POST', - headers: getHeaders(), - body: JSON.stringify(turkHitFormData), - }); - - if (!data.err) { - yield put(createHitSuccess(data)); - } else { - yield put(createHitError(data.err)); - } -} - -/** - * Approve or reject HIT request/response handler - * - * @param {number} action 1 or 0 representing approve or reject - */ -function* approveHit(action) { - const data = yield call(request, `${turkURL}${action.buildingId}`, { - method: 'PUT', - headers: getHeaders(), - body: JSON.stringify({ accept: action.decision }), - }); - - if (!data.err) { - yield put(hitDecisionSuccess(data)); - } else { - yield put(hitDecisionError(data.err)); - } -} - /** * Watches for LOAD_BUILDING_DETAIL & CREATE_HIT actions and calls * the appropriate handler function. */ function* buildingDetailWatcher() { yield takeEvery(LOAD_BUILDING_DETAIL, getBuildingDetail); - yield takeEvery(LOAD_HIT, loadHit); - yield takeEvery(CREATE_HIT, createHit); - yield takeEvery(DECIDE_HIT, approveHit); } export default buildingDetailWatcher; diff --git a/src/containers/Dimensions/actions.js b/src/containers/Dimensions/actions.js new file mode 100644 index 00000000..0600cfea --- /dev/null +++ b/src/containers/Dimensions/actions.js @@ -0,0 +1,137 @@ +import 'whatwg-fetch'; +import { + LOAD_HIT, + LOAD_HIT_SUCCESS, + LOAD_HIT_ERROR, + CREATE_HIT, + CREATE_HIT_SUCCESS, + CREATE_HIT_ERROR, + DECIDE_HIT, + DECIDE_HIT_SUCCESS, + DECIDE_HIT_ERROR, +} from './constants'; + +/** + * Load status of HIT + * TODO The HIT status should be loaded from the building detail route + * + * @param {string} buildingId The current buildingID + * @returns {object} An action object with a type of + * LOAD_HIT passing the building_id + */ +export function loadHit(buildingId) { + return { + type: LOAD_HIT, + payload: buildingId, + }; +} + +/** + * Dispatched when the hit status was successfully loaded + * + * @param {string} hitStatus The HIT status + * @returns {object} An action object with a type of + * LOAD_HIT_SUCCESS passing the hit status + */ +export function hitLoaded(hitStatus) { + return { + type: LOAD_HIT_SUCCESS, + payload: hitStatus, + }; +} + +/** + * Dispatched when loading the hit status fails + * + * @param {object} error The error + * @returns {object} An action object with a type of + * LOAD_HIT passing the hit status + */ +export function hitLoadingError(error) { + return { + type: LOAD_HIT_ERROR, + error, + }; +} + +/** + * Create mturk HIT, this action starts the request saga + * + * @param {object} formData The mturk form data + * @returns {object} An action object with a type of CREATE_HIT + */ +export function createHit(formData) { + return { + type: CREATE_HIT, + payload: formData, + }; +} + +/** + * Dispatched when the mturk HIT was successfully created + * + * @param {object} hitData The created hit data + * @returns {object} An action object with a type of CREATE_HIT_SUCCESS + */ +export function createHitSuccess(hitData) { + return { + type: CREATE_HIT_SUCCESS, + payload: hitData, + }; +} + +/** + * Dispatched when creating the mturk HIT fails + * + * @param {object} error The error + * @return {object} An action object with a type of CREATE_HIT_ERROR + * passing the error + */ +export function createHitError(error) { + return { + type: CREATE_HIT_ERROR, + error, + }; +} + +/** + * Dispatched when user selects approve or reject HIT + * + * @param {int} buildingId Id of building + * @param {int} decision 1 or 0 representing approve or reject + * @returns {object} An action object with a type of DECIDE_HIT + * passing the decision of the user + */ +export function hitDecision(buildingId, decision) { + return { + type: DECIDE_HIT, + buildingId, + decision, + }; +} + +/** + * Dispatched when the hit was successfully approved or disapproved + * + * @returns {object} + */ +export function hitDecisionSuccess(data) { + return { + type: DECIDE_HIT_SUCCESS, + payload: data, + }; +} + +/** + * Dispatched when there is a error approving or rejecting a HIT + * + * @param error The error + * @returns {object} An action object with a type of DECIDE_HIT_ERROR + * passing the error + */ +export function hitDecisionError(error) { + return { + type: DECIDE_HIT_ERROR, + error, + }; +} diff --git a/src/containers/Dimensions/constants.js b/src/containers/Dimensions/constants.js new file mode 100644 index 00000000..7d202767 --- /dev/null +++ b/src/containers/Dimensions/constants.js @@ -0,0 +1,9 @@ +export const LOAD_HIT = 'LOAD_HIT'; +export const LOAD_HIT_SUCCESS = 'LOAD_HIT_SUCCESS'; +export const LOAD_HIT_ERROR = 'LOAD_HIT_ERROR'; +export const CREATE_HIT = 'CREATE_HIT'; +export const CREATE_HIT_SUCCESS = 'CREATE_HIT_SUCCESS'; +export const CREATE_HIT_ERROR = 'CREATE_HIT_ERROR'; +export const DECIDE_HIT = 'DECIDE_HIT'; +export const DECIDE_HIT_SUCCESS = 'DECIDE_HIT_SUCCESS'; +export const DECIDE_HIT_ERROR = 'DECIDE_HIT_ERROR'; diff --git a/src/containers/Dimensions/index.js b/src/containers/Dimensions/index.js new file mode 100644 index 00000000..256c4694 --- /dev/null +++ b/src/containers/Dimensions/index.js @@ -0,0 +1,66 @@ +import React, { Component, PropTypes } from 'react'; +import { connect } from 'react-redux'; +import { bindActionCreators } from 'redux'; + +import { + loadHit, + createHit, + hitDecision, +} from './actions'; + +import buildingDetailPropTypes from '../BuildingOverview/buildingDetailPropType'; + +import './styles.css'; +import TurkHit from '../../components/TurkHit'; + + +class Dimensions extends Component { + componentDidMount() { + this.props.loadHit(this.props.buildingId); + } + + render() { + return ( +
+ Dimensions! + +
+ ); + } +} + +Dimensions.propTypes = { + buildingId: PropTypes.string, + buildingDetail: buildingDetailPropTypes, + dimensions: PropTypes.shape({ + hit: PropTypes.shape({ + id: PropTypes.string, + status: PropTypes.string, + loading: PropTypes.boolean, + error: PropTypes.boolean, + }), + }), + loadHit: PropTypes.func, + createHit: PropTypes.func, + hitDecision: PropTypes.func, +}; + +function mapDispatchToProps(dispatch) { + return bindActionCreators({ + loadHit, + createHit, + hitDecision, + }, dispatch); +} + +function mapStateToProps({ dimensions, buildingDetail }) { + return { dimensions, buildingDetail }; +} + +export default connect(mapStateToProps, mapDispatchToProps)(Dimensions); diff --git a/src/containers/Dimensions/reducer.js b/src/containers/Dimensions/reducer.js new file mode 100644 index 00000000..2526447f --- /dev/null +++ b/src/containers/Dimensions/reducer.js @@ -0,0 +1,135 @@ +import { + LOAD_HIT, + LOAD_HIT_SUCCESS, + LOAD_HIT_ERROR, + CREATE_HIT, + CREATE_HIT_SUCCESS, + CREATE_HIT_ERROR, + DECIDE_HIT, + DECIDE_HIT_SUCCESS, + DECIDE_HIT_ERROR, +} from './constants'; + +const initState = { + hit: { + id: '', + status: '', + loading: false, + error: false, + create: { + loading: false, + error: false, + }, + approval: { + loading: false, + error: false, + }, + }, +}; + +export default function (state = initState, action) { + switch (action.type) { + case LOAD_HIT: + return { + hit: { + ...state.hit, + status: '', + loading: true, + error: false, + }, + }; + + case LOAD_HIT_SUCCESS: + return { + hit: { + ...state.hit, + status: action.payload.data.status, + url: action.payload.data.hit_url, + loading: false, + error: false, + }, + }; + + case LOAD_HIT_ERROR: + return { + hit: { + ...state.hit, + loading: false, + error: action.error, + }, + }; + + case CREATE_HIT: + return { + hit: { + ...state.hit, + create: { + loading: true, + error: false, + }, + }, + }; + + case CREATE_HIT_SUCCESS: + return { + hit: { + id: action.payload.data.hit_id, + status: action.payload.data.status, + loading: false, + error: false, + create: { + loading: false, + error: false, + }, + }, + }; + + case CREATE_HIT_ERROR: + return { + hit: { + ...state.hit, + create: { + loading: false, + error: action.error, + }, + }, + }; + + case DECIDE_HIT: + return { + hit: { + ...state.hit, + approval: { + loading: true, + error: false, + }, + }, + }; + + case DECIDE_HIT_SUCCESS: + return { + hit: { + ...state.hit, + status: action.payload.data.hit_status, + approval: { + loading: false, + error: false, + }, + }, + }; + + case DECIDE_HIT_ERROR: + return { + hit: { + ...state.hit, + approval: { + loading: false, + error: action.error, + }, + }, + }; + + default: + return state; + } +} diff --git a/src/containers/Dimensions/sagas.js b/src/containers/Dimensions/sagas.js new file mode 100644 index 00000000..ee04cd3c --- /dev/null +++ b/src/containers/Dimensions/sagas.js @@ -0,0 +1,88 @@ +import { call, put, takeEvery } from 'redux-saga/effects'; +import request from '../../utils/request'; +import { getHeaders, turkURL } from '../../utils/rest_services'; + +import { + LOAD_HIT, + CREATE_HIT, + DECIDE_HIT, +} from './constants'; + +import { + hitLoaded, + hitLoadingError, + createHitSuccess, + createHitError, + hitDecisionSuccess, + hitDecisionError, +} from './actions'; + +/** + * Load Mechanical Turk HIT request/response handler + * + * @param {object} action Payload attribute with buildingId + */ +function* loadHit(action) { + const buildingId = action.payload; + const data = yield call(request, `${turkURL}${buildingId}`, { + method: 'GET', + headers: getHeaders(), + }); + + if (!data.err) { + yield put(hitLoaded(data)); + } else { + yield put(hitLoadingError(data.err)); + } +} + +/** + * Mechanical Turk HIT creation request/response handler + * + * @param {object} action Form data of mechanical turk job + */ +function* createHit(action) { + const turkHitFormData = action.payload; + const data = yield call(request, turkURL, { + method: 'POST', + headers: getHeaders(), + body: JSON.stringify(turkHitFormData), + }); + + if (!data.err) { + yield put(createHitSuccess(data)); + } else { + yield put(createHitError(data.err)); + } +} + +/** + * Approve or reject HIT request/response handler + * + * @param {number} action 1 or 0 representing approve or reject + */ +function* approveHit(action) { + const data = yield call(request, `${turkURL}${action.buildingId}`, { + method: 'PUT', + headers: getHeaders(), + body: JSON.stringify({ accept: action.decision }), + }); + + if (!data.err) { + yield put(hitDecisionSuccess(data)); + } else { + yield put(hitDecisionError(data.err)); + } +} + +/** + * Watches for LOAD_BUILDING_DETAIL & CREATE_HIT actions and calls + * the appropriate handler function. + */ +function* dimensionsWatcher() { + yield takeEvery(LOAD_HIT, loadHit); + yield takeEvery(CREATE_HIT, createHit); + yield takeEvery(DECIDE_HIT, approveHit); +} + +export default dimensionsWatcher; diff --git a/src/containers/Dimensions/styles.css b/src/containers/Dimensions/styles.css new file mode 100644 index 00000000..e69de29b diff --git a/src/reducers.js b/src/reducers.js index 24879627..6870601e 100644 --- a/src/reducers.js +++ b/src/reducers.js @@ -4,10 +4,12 @@ import { routerReducer } from 'react-router-redux'; import SearchBarReducer from './containers/SearchBar/reducer'; import BuildingOverviewReducer from './containers/BuildingOverview/reducer'; import GoogleLoginReducer from './containers/GoogleLogin/reducer'; +import DimensionsReducer from './containers/Dimensions/reducer'; export default combineReducers({ routing: routerReducer, buildingList: SearchBarReducer, buildingDetail: BuildingOverviewReducer, googleLogin: GoogleLoginReducer, + dimensions: DimensionsReducer, }); diff --git a/src/routes.js b/src/routes.js index c64dc2a6..4410848d 100644 --- a/src/routes.js +++ b/src/routes.js @@ -8,6 +8,7 @@ import NotFound from './screens/NotFound'; import HomePage from './screens/HomePage'; import BuildingDetail from './screens/BuildingDetail'; import BuildingOverview from './containers/BuildingOverview'; +import Dimensions from './containers/Dimensions'; import Utilities from './components/Utilities'; import Dummy from './components/dummyComponent'; @@ -21,7 +22,7 @@ export default ( - + diff --git a/src/sagas.js b/src/sagas.js index 09714c28..1f35dcd1 100644 --- a/src/sagas.js +++ b/src/sagas.js @@ -1,7 +1,9 @@ import buildingOverviewSaga from './containers/BuildingOverview/sagas'; +import dimensionsSaga from './containers/Dimensions/sagas'; export default function* rootSaga() { yield [ buildingOverviewSaga(), + dimensionsSaga(), ]; } -- GitLab From 5d9c58309212cf3816af639bf08de49846253cfe Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Wed, 1 Feb 2017 16:23:40 -0500 Subject: [PATCH 02/11] Add turkStatus json and fix download link --- src/components/TurkHit/index.js | 163 +++++++++++++++---------- src/components/TurkHit/turkStatus.js | 50 ++++++++ src/containers/Dimensions/index.js | 23 ++-- src/containers/Dimensions/propTypes.js | 17 +++ src/containers/Dimensions/reducer.js | 3 +- 5 files changed, 181 insertions(+), 75 deletions(-) create mode 100644 src/components/TurkHit/turkStatus.js create mode 100644 src/containers/Dimensions/propTypes.js diff --git a/src/components/TurkHit/index.js b/src/components/TurkHit/index.js index 1c3e9383..07514a6a 100644 --- a/src/components/TurkHit/index.js +++ b/src/components/TurkHit/index.js @@ -1,73 +1,111 @@ -import React, { PropTypes } from 'react'; +import React, { PropTypes, Component } from 'react'; import defaultForm from './defaultForm'; import './styles.scss'; +import turkHitPropTypes from '../../containers/Dimensions/propTypes'; +import turkStatus from './turkStatus'; -export default function TurkHit({ createHit, hitDecision, address, building_id, hit }) { - let hitStatus =
; - const createBtn = ( - - ); +class TurkHit extends Component { + static definitionMechanicalTurk = 'Amazon Mechanical Turk is a marketplace for workers to complete HIT\'s.'; + static definitionHIT = 'HIT\'s are Human Intelligence Task. Hit\'s have 6 days to be completed from date of creation.'; - // Loading HIT - if (hit.loading) { - return

Loading...

; - } else if (hit.error.message && hit.error.response.status !== 404) { - return

{hit.error.message}

; + constructor(props) { + super(props); + + this.state = { + error: false, + }; } - if (!hit.error.message && hit.status !== '') { - let fileActions =
; + render() { + const { createHit, hitDecision, address, building_id, hit } = this.props; + const { status } = this.props.hit; - if (hit.status === 'Reviewable') { - fileActions = ( -
- Download File - - -
- ); - } else if (hit.status === 'Rejected' - || hit.status === 'Expired' - || hit.status === 'Disposed') { - fileActions = createBtn; - } + const buildings = this.props.hit.boxBuildingList; + /* eslint-disable jsx-a11y/href-no-hash */ + const downloadLink = ( + 0 ? buildings.slice(-1)[0].url_download : '#'} + > + Download + + ); + + const createBtn = ( + + ); - hitStatus = ( + const fileActions = (
- HIT Status: {hit.status} - {fileActions} + +
); - } else { - hitStatus = createBtn; - } - // Creating HIT -- error message - if (hit.create.error.message) { - return

{hit.create.error.message}

; - } + // Loading HIT + if (hit.loading) { + return

Loading...

; + } else if (hit.error.message && hit.error.response.status !== 404) { + this.setState({ error: hit.error.message }); + } + + // Creating HIT -- error message + if (hit.create.error.message) { + this.setState({ error: hit.create.error.message }); + } + + let mainContent =
; + if (!hit.error.message || hit.error.response.status === 404) { + if (status !== '') { + const currStatus = turkStatus[status]; + mainContent = ( +
+ {turkStatus[status].message} + {currStatus.createBtn && createBtn} + {currStatus.fileActions && fileActions} + {currStatus.downloadLink && downloadLink} +
+ ); + } else { + mainContent = ( +
+

HIT has not been submitted yet.

+ {createBtn} +
+ ); + } + } + + return ( +
+ {this.state.error} +

Mechanical Turk

+
Definitions
+

+ {TurkHit.definitionMechanicalTurk} +
+ {TurkHit.definitionHIT} +

- return ( -
- {hitStatus} -
- ); + {mainContent} +
+ ); + } } TurkHit.propTypes = { @@ -75,14 +113,7 @@ TurkHit.propTypes = { hitDecision: PropTypes.func, address: PropTypes.string, building_id: PropTypes.number, - hit: PropTypes.shape({ - id: PropTypes.string, - status: PropTypes.string, - loading: PropTypes.boolean, - error: PropTypes.boolean, - create: PropTypes.shape({ - loading: PropTypes.boolean, - error: PropTypes.boolean, - }), - }), + hit: turkHitPropTypes, }; + +export default TurkHit; diff --git a/src/components/TurkHit/turkStatus.js b/src/components/TurkHit/turkStatus.js new file mode 100644 index 00000000..b8dcadee --- /dev/null +++ b/src/components/TurkHit/turkStatus.js @@ -0,0 +1,50 @@ +export default { + NotCreated: { + message: 'Create HIT to get started', + createBtn: true, + fileActions: false, + downloadLink: false, + }, + Assignable: { + message: 'HIT is in mechanical turk and is waiting for worker.', + createBtn: false, + fileActions: false, + downloadLink: false, + }, + Unassignable: { + message: 'Worker is finding the measurements of the building.', + createBtn: false, + fileActions: false, + downloadLink: false, + }, + Reviewable: { + message: 'Download the file and see if the measurements are correct.', + createBtn: false, + fileActions: true, + downloadLink: true, + }, + Accepted: { + message: 'HIT is completed and has been accepted.', + createBtn: false, + fileActions: false, + downlaodLink: true, + }, + Rejected: { + message: 'The HIT has been rejected.', + createBtn: true, + fileActions: false, + downloadLink: true, + }, + Disposed: { + message: 'The HIT has been deleted from mechanical turk. Check if HIT was compeleted', + createBtn: false, + fileActions: false, + downloadLink: false, + }, + Expired: { + message: 'The HIT has been expired and must be recreated.', + createBtn: true, + fileActions: false, + downloadLink: false, + }, +}; diff --git a/src/containers/Dimensions/index.js b/src/containers/Dimensions/index.js index 256c4694..70077e56 100644 --- a/src/containers/Dimensions/index.js +++ b/src/containers/Dimensions/index.js @@ -8,7 +8,12 @@ import { hitDecision, } from './actions'; +import { + loadBuildingDetail, +} from '../BuildingOverview/actions'; + import buildingDetailPropTypes from '../BuildingOverview/buildingDetailPropType'; +import turkHitPropTypes from './propTypes'; import './styles.css'; import TurkHit from '../../components/TurkHit'; @@ -16,13 +21,18 @@ import TurkHit from '../../components/TurkHit'; class Dimensions extends Component { componentDidMount() { + /* eslint-disable camelcase */ + const { address, building_id } = this.props.buildingDetail.overview; + this.props.loadHit(this.props.buildingId); + if (!address || this.props.buildingId !== building_id) { + this.props.loadBuildingDetail(this.props.buildingId); + } } render() { return ( -
- Dimensions! +
Date: Wed, 1 Feb 2017 16:26:09 -0500 Subject: [PATCH 03/11] Fix turk download typo --- src/components/TurkHit/turkStatus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/TurkHit/turkStatus.js b/src/components/TurkHit/turkStatus.js index b8dcadee..5b81e5d9 100644 --- a/src/components/TurkHit/turkStatus.js +++ b/src/components/TurkHit/turkStatus.js @@ -27,7 +27,7 @@ export default { message: 'HIT is completed and has been accepted.', createBtn: false, fileActions: false, - downlaodLink: true, + downloadLink: true, }, Rejected: { message: 'The HIT has been rejected.', -- GitLab From 691db932703332ff0944b70c45dde71662da8b91 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Wed, 1 Feb 2017 16:43:55 -0500 Subject: [PATCH 04/11] Change turk download file style --- src/components/TurkHit/index.js | 11 +++++++---- src/components/TurkHit/turkStatus.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/TurkHit/index.js b/src/components/TurkHit/index.js index 07514a6a..754b38f2 100644 --- a/src/components/TurkHit/index.js +++ b/src/components/TurkHit/index.js @@ -22,9 +22,10 @@ class TurkHit extends Component { const { status } = this.props.hit; const buildings = this.props.hit.boxBuildingList; - /* eslint-disable jsx-a11y/href-no-hash */ + /* eslint-disable jsx-a11y/href-no-hash*/ const downloadLink = ( 0 ? buildings.slice(-1)[0].url_download : '#'} > Download @@ -41,7 +42,7 @@ class TurkHit extends Component { ); const fileActions = ( -
+
); - // Loading HIT - if (hit.loading) { - return

Loading...

; - } else if (hit.error.message && hit.error.response.status !== 404) { - this.setState({ error: hit.error.message }); - } - - // Creating HIT -- error message - if (hit.create.error.message) { - this.setState({ error: hit.create.error.message }); - } - let mainContent =
; if (!hit.error.message || hit.error.response.status === 404) { if (status !== '') { @@ -94,9 +87,16 @@ class TurkHit extends Component { } } + const errorBox = (hit.error && hit.error.response.status !== 404) || hit.create.error; + return (
- {this.state.error} +
+ {hit.error.message || hit.create.error.message} +

Mechanical Turk

Definitions

diff --git a/src/components/TurkHit/turkStatus.js b/src/components/TurkHit/turkStatus.js index 735b8962..cc2f5463 100644 --- a/src/components/TurkHit/turkStatus.js +++ b/src/components/TurkHit/turkStatus.js @@ -1,10 +1,4 @@ export default { - NotCreated: { - message: 'Create HIT to get started', - createBtn: true, - fileActions: false, - downloadLink: false, - }, Assignable: { message: 'HIT is in mechanical turk and is waiting for worker.', createBtn: false, -- GitLab From 6c18194b0069cfe71365f4b44e5ba24b02ec04b5 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Wed, 1 Feb 2017 17:30:40 -0500 Subject: [PATCH 06/11] Create render methods for turk buttons --- src/components/TurkHit/index.js | 41 +++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/components/TurkHit/index.js b/src/components/TurkHit/index.js index de49f2d2..31c6abfc 100644 --- a/src/components/TurkHit/index.js +++ b/src/components/TurkHit/index.js @@ -18,17 +18,10 @@ class TurkHit extends Component { }; } - render() { - const { createHit, hitDecision, address, building_id, hit } = this.props; - const { status } = this.props.hit; - - if (hit.loading) { - return

Loading...

; - } - + renderDownloadLink = () => { const buildings = this.props.hit.boxBuildingList; /* eslint-disable jsx-a11y/href-no-hash*/ - const downloadLink = ( + return (
0 ? buildings.slice(-1)[0].url_download : '#'} @@ -36,8 +29,11 @@ class TurkHit extends Component { Download ); + } - const createBtn = ( + renderCreateHitButton = () => { + const { createHit, address, building_id } = this.props; + return ( ); + } - const fileActions = ( + renderHitActions = () => { + const { hitDecision, building_id } = this.props; + return (
); + } + render() { + const { hit } = this.props; + const { status } = this.props.hit; + const errorBox = (hit.error && hit.error.response.status !== 404) || hit.create.error; let mainContent =
; + + if (hit.loading) { + return

Loading...

; + } + if (!hit.error.message || hit.error.response.status === 404) { if (status !== '') { const currStatus = turkStatus[status]; mainContent = (
{turkStatus[status].message} - {currStatus.createBtn && createBtn} + {currStatus.createBtn && this.renderCreateHitButton()}
- {currStatus.downloadLink && downloadLink} - {currStatus.fileActions && fileActions} + {currStatus.downloadLink && this.renderDownloadLink()} + {currStatus.fileActions && this.renderHitActions()}
); @@ -81,14 +90,12 @@ class TurkHit extends Component { mainContent = (

HIT has not been submitted yet.

- {createBtn} + {this.renderCreateHitButton()}
); } } - const errorBox = (hit.error && hit.error.response.status !== 404) || hit.create.error; - return (
Date: Wed, 1 Feb 2017 17:53:30 -0500 Subject: [PATCH 07/11] Fix turk hit error messages --- src/components/TurkHit/index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/TurkHit/index.js b/src/components/TurkHit/index.js index 31c6abfc..ff595533 100644 --- a/src/components/TurkHit/index.js +++ b/src/components/TurkHit/index.js @@ -66,11 +66,18 @@ class TurkHit extends Component { render() { const { hit } = this.props; const { status } = this.props.hit; - const errorBox = (hit.error && hit.error.response.status !== 404) || hit.create.error; let mainContent =
; if (hit.loading) { return

Loading...

; + } else if (hit.error && hit.error.response.status !== 404) { + return ( +
+ Retrieving HIT error. Response message: {hit.error.message} +
+ ); } if (!hit.error.message || hit.error.response.status === 404) { @@ -100,9 +107,9 @@ class TurkHit extends Component {
- {hit.error.message || hit.create.error.message} + Failed to create HIT. Response message: {hit.create.error.message}

Mechanical Turk

Definitions
-- GitLab From 3721c303daa27f50e8c1d3e400774c0511ce84a9 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Wed, 1 Feb 2017 17:56:38 -0500 Subject: [PATCH 08/11] Fix turk assignable message --- src/components/TurkHit/turkStatus.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/TurkHit/turkStatus.js b/src/components/TurkHit/turkStatus.js index cc2f5463..68fde9a4 100644 --- a/src/components/TurkHit/turkStatus.js +++ b/src/components/TurkHit/turkStatus.js @@ -1,6 +1,6 @@ export default { Assignable: { - message: 'HIT is in mechanical turk and is waiting for worker.', + message: 'HIT has been submitted to mechanical turk and is waiting for worker.', createBtn: false, fileActions: false, downloadLink: false, -- GitLab From eb135bfc86952c162e4d992c19cb1ed891eaa592 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Wed, 1 Feb 2017 18:09:50 -0500 Subject: [PATCH 09/11] Fix turk disposed message --- src/components/TurkHit/turkStatus.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/TurkHit/turkStatus.js b/src/components/TurkHit/turkStatus.js index 68fde9a4..5b9478b4 100644 --- a/src/components/TurkHit/turkStatus.js +++ b/src/components/TurkHit/turkStatus.js @@ -30,8 +30,8 @@ export default { downloadLink: true, }, Disposed: { - message: 'The HIT has been deleted from mechanical turk. Check if HIT was compeleted', - createBtn: false, + message: 'The HIT has been deleted from mechanical turk. Create a new HIT.', + createBtn: true, fileActions: false, downloadLink: false, }, -- GitLab From c4e7d1683352ea333dcc5c67014388a0fe1940a1 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Wed, 1 Feb 2017 18:20:47 -0500 Subject: [PATCH 10/11] Update instructions for HIT --- src/components/TurkHit/index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/components/TurkHit/index.js b/src/components/TurkHit/index.js index ff595533..0ca722db 100644 --- a/src/components/TurkHit/index.js +++ b/src/components/TurkHit/index.js @@ -6,9 +6,6 @@ import turkStatus from './turkStatus'; class TurkHit extends Component { - static definitionMechanicalTurk = 'Amazon Mechanical Turk is a marketplace for workers to complete HIT\'s.'; - static definitionHIT = 'HIT\'s are Human Intelligence Task. Hit\'s have 6 days to be completed from date of creation.'; - constructor(props) { super(props); @@ -114,9 +111,11 @@ class TurkHit extends Component {

Mechanical Turk

Definitions

- {TurkHit.definitionMechanicalTurk} + Amazon Mechanical Turk is a marketplace for workers to complete Human + Intelligence Tasks or HITs.
- {TurkHit.definitionHIT} + We will be creating HITs for workers to measure the dimensions of a building. + HITs have 6 days to be completed from date of creation.

{mainContent} -- GitLab From 7b3e58e0114b2d0edff5a395e10470ca83fa8a7c Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Wed, 1 Feb 2017 18:31:47 -0500 Subject: [PATCH 11/11] Remove redundant if statement --- src/components/TurkHit/index.js | 39 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/components/TurkHit/index.js b/src/components/TurkHit/index.js index 0ca722db..517143a2 100644 --- a/src/components/TurkHit/index.js +++ b/src/components/TurkHit/index.js @@ -77,27 +77,25 @@ class TurkHit extends Component { ); } - if (!hit.error.message || hit.error.response.status === 404) { - if (status !== '') { - const currStatus = turkStatus[status]; - mainContent = ( -
- {turkStatus[status].message} - {currStatus.createBtn && this.renderCreateHitButton()} -
- {currStatus.downloadLink && this.renderDownloadLink()} - {currStatus.fileActions && this.renderHitActions()} -
+ if (status !== '') { + const currStatus = turkStatus[status]; + mainContent = ( +
+ {turkStatus[status].message} + {currStatus.createBtn && this.renderCreateHitButton()} +
+ {currStatus.downloadLink && this.renderDownloadLink()} + {currStatus.fileActions && this.renderHitActions()}
- ); - } else { - mainContent = ( -
-

HIT has not been submitted yet.

- {this.renderCreateHitButton()} -
- ); - } +
+ ); + } else { + mainContent = ( +
+

HIT has not been created yet.

+ {this.renderCreateHitButton()} +
+ ); } return ( @@ -108,6 +106,7 @@ class TurkHit extends Component { > Failed to create HIT. Response message: {hit.create.error.message}
+

Mechanical Turk

Definitions

-- GitLab