From 782538f13f3450d0436ddfc2111798afc333da65 Mon Sep 17 00:00:00 2001 From: Conrad S Date: Mon, 8 May 2017 16:44:50 -0400 Subject: [PATCH 1/3] Add expire hit button --- src/components/TurkHit/index.js | 122 ++++++++++++++++--------- src/components/TurkHit/turkStatus.js | 7 ++ src/containers/Dimensions/actions.js | 42 +++++++++ src/containers/Dimensions/constants.js | 3 + src/containers/Dimensions/index.js | 4 + src/containers/Dimensions/reducer.js | 41 +++++++++ src/containers/Dimensions/sagas.js | 28 +++++- 7 files changed, 202 insertions(+), 45 deletions(-) diff --git a/src/components/TurkHit/index.js b/src/components/TurkHit/index.js index 76f24739..91da0586 100644 --- a/src/components/TurkHit/index.js +++ b/src/components/TurkHit/index.js @@ -32,14 +32,18 @@ class TurkHit extends Component { componentDidUpdate() { // Create the chart when the component updates with turk data + const container = document.getElementById('chart-container'); const hit = this.props.hit; - if (!hit.loading && - (hit.hitData.length > 0) && - hit.hitData[0].dimensions && - !this.state.chart) { + if ( + container != null && + !hit.loading && + (hit.hitData.length > 0) && + hit.hitData[0].dimensions && + !this.state.chart + ) { const curHit = this.props.hit.hitData[0]; - // Calculate the minLat to get a measurement + // Calculate the minLat to get a measureme let minLat = null; let minLong = null; let maxFoot = null; @@ -377,27 +381,47 @@ class TurkHit extends Component { } if (document) { return ( - - Download - +
+ + Download + +
); } return (); } + renderDeleteHitButton = (hit) => { + const { deleteHit } = this.props; + return ( +
+ +
+ ); + } + renderCreateHitButton = () => { const { createHitConfirmation, address, building_id } = this.props; return (
); }) @@ -480,7 +504,6 @@ class TurkHit extends Component { const { hit } = this.props; const status = hit.status; - let mainContent =
; if (hit.loading) { return (
@@ -498,10 +521,41 @@ class TurkHit extends Component { let oldHits = (
); + let mainContent = null; if (hit.hitData.length > 0 && status !== null) { const curHit = hit.hitData[0]; const currStatus = turkStatus[status]; - if (hit.hitData.length > 1) { + oldHits = hit.hitData.slice(1); + // If we are in a createbtn state, do not show the most recent hit in the mainContent + // Instead, show it in the old hits section + if (currStatus.createBtn) { + oldHits = hit.hitData; + } else { + mainContent = ( +
+ {currStatus.createBtn && this.renderCreateHitButton()} +
+ + + + {curHit.response_message ? + () : } + + + +
Status{currStatus.message}
Message{curHit.response_message}
Creation Date{curHit.hit_date}
Creator{curHit.requester_name}
+
+ {currStatus.downloadLink && this.renderDownloadLink(curHit.csv_document_key)} + {this.state.chart && this.renderChartToggleButton()} + {currStatus.fileActions && this.renderHitActions(curHit)} + {currStatus.expireable && this.renderDeleteHitButton(curHit)} + {this.renderChart()} +
+
+
+ ); + } + if (oldHits.length > 0) { oldHits = (

Previously created hits

@@ -509,33 +563,12 @@ class TurkHit extends Component {

These are hits that are no longer active.

- {this.renderOldHits(hit.hitData.slice(1))} + {this.renderOldHits(oldHits)}
); } - mainContent = ( -
- {currStatus.createBtn && this.renderCreateHitButton()} -
- - - - {curHit.response_message ? - () : } - - - -
Status{currStatus.message}
Message{curHit.response_message}
Creation Date{curHit.hit_date}
Creator{curHit.requester_name}
-
- {currStatus.downloadLink && this.renderDownloadLink(curHit.csv_document_key)} - {currStatus.fileActions && this.renderHitActions(curHit)} - {this.state.chart && this.renderChartToggleButton()} - {this.renderChart()} -
-
-
- ); - } else { + } + if (mainContent == null) { mainContent = (

HIT has not been created yet.

@@ -563,6 +596,7 @@ class TurkHit extends Component { TurkHit.propTypes = { createHitConfirmation: PropTypes.func, hitDecision: PropTypes.func, + deleteHit: PropTypes.func, address: PropTypes.string, building_id: PropTypes.number, hit: turkHitPropTypes, diff --git a/src/components/TurkHit/turkStatus.js b/src/components/TurkHit/turkStatus.js index edaecf52..2814cb47 100644 --- a/src/components/TurkHit/turkStatus.js +++ b/src/components/TurkHit/turkStatus.js @@ -5,6 +5,7 @@ export default { createBtn: false, fileActions: false, downloadLink: false, + expireable: true, }, 2: { statusText: 'Unassignable', @@ -12,6 +13,7 @@ export default { createBtn: false, fileActions: false, downloadLink: false, + expireable: true, }, 3: { statusText: 'Reviewable', @@ -19,6 +21,7 @@ export default { createBtn: false, fileActions: true, downloadLink: true, + expireable: true, }, 4: { statusText: 'Accepted', @@ -26,6 +29,7 @@ export default { createBtn: false, fileActions: false, downloadLink: true, + expireable: false, }, 5: { statusText: 'Rejected', @@ -33,6 +37,7 @@ export default { createBtn: true, fileActions: false, downloadLink: true, + expireable: false, }, 6: { statusText: 'Disposed', @@ -40,6 +45,7 @@ export default { createBtn: true, fileActions: false, downloadLink: false, + expireable: false, }, 7: { statusText: 'Expired', @@ -47,5 +53,6 @@ export default { createBtn: true, fileActions: false, downloadLink: false, + expireable: false, }, }; diff --git a/src/containers/Dimensions/actions.js b/src/containers/Dimensions/actions.js index c3ef2062..19451f58 100644 --- a/src/containers/Dimensions/actions.js +++ b/src/containers/Dimensions/actions.js @@ -9,6 +9,9 @@ import { DECIDE_HIT, DECIDE_HIT_SUCCESS, DECIDE_HIT_ERROR, + DELETE_HIT, + DELETE_HIT_SUCCESS, + DELETE_HIT_ERROR, } from './constants'; /** @@ -137,3 +140,42 @@ export function hitDecisionError(error) { error, }; } + +/** + * Delete mturk HIT + * + * @param {object} hit The mturk hit object + * @returns {object} An action object with a type of DELETE_HIT + */ +export function deleteHit(hit) { + return { + type: DELETE_HIT, + hit, + }; +} + +/** + * Disptached when a hit is successfully deleted + * + * @param {object} data + * @returns {object} + */ +export function deleteHitSuccess(data) { + return { + type: DELETE_HIT_SUCCESS, + payload: data, + }; +} + +/** + * Disptached when there is an error deleting a hit + * + * @param {object} data + * @returns {object} + */ +export function deleteHitError(data) { + return { + type: DELETE_HIT_ERROR, + payload: data, + }; +} diff --git a/src/containers/Dimensions/constants.js b/src/containers/Dimensions/constants.js index 7d202767..966fd379 100644 --- a/src/containers/Dimensions/constants.js +++ b/src/containers/Dimensions/constants.js @@ -7,3 +7,6 @@ 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'; +export const DELETE_HIT = 'DELETE_HIT'; +export const DELETE_HIT_SUCCESS = 'DELETE_HIT_SUCCESS'; +export const DELETE_HIT_ERROR = 'DELETE_HIT_ERROR'; diff --git a/src/containers/Dimensions/index.js b/src/containers/Dimensions/index.js index cfb68a6a..d8ae4621 100644 --- a/src/containers/Dimensions/index.js +++ b/src/containers/Dimensions/index.js @@ -8,6 +8,7 @@ import { loadHit, createHit, hitDecision, + deleteHit, } from './actions'; import { @@ -55,6 +56,7 @@ class Dimensions extends Component { Date: Tue, 9 May 2017 16:47:11 -0400 Subject: [PATCH 2/3] Add comments --- src/components/TurkHit/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/TurkHit/index.js b/src/components/TurkHit/index.js index 91da0586..cdf58cad 100644 --- a/src/components/TurkHit/index.js +++ b/src/components/TurkHit/index.js @@ -35,6 +35,7 @@ class TurkHit extends Component { const container = document.getElementById('chart-container'); const hit = this.props.hit; if ( + // If the container does not exist highcharts will throw an exception container != null && !hit.loading && (hit.hitData.length > 0) && @@ -43,7 +44,7 @@ class TurkHit extends Component { ) { const curHit = this.props.hit.hitData[0]; - // Calculate the minLat to get a measureme + // Calculate the minLat to get a measurement let minLat = null; let minLong = null; let maxFoot = null; -- GitLab From 822c0b2cb7431cb28831a8aca5f99a7b0f23e532 Mon Sep 17 00:00:00 2001 From: Conrad Date: Thu, 11 May 2017 14:27:59 -0400 Subject: [PATCH 3/3] Check status of current mech turk hit to determine if chart should be drawn --- src/components/TurkHit/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/TurkHit/index.js b/src/components/TurkHit/index.js index cdf58cad..c2f8e720 100644 --- a/src/components/TurkHit/index.js +++ b/src/components/TurkHit/index.js @@ -32,11 +32,14 @@ class TurkHit extends Component { componentDidUpdate() { // Create the chart when the component updates with turk data - const container = document.getElementById('chart-container'); - const hit = this.props.hit; + const { hit } = this.props; + if (hit == null) { + return; + } + const status = hit.status; + const currStatus = turkStatus[status]; if ( - // If the container does not exist highcharts will throw an exception - container != null && + !currStatus.createBtn && !hit.loading && (hit.hitData.length > 0) && hit.hitData[0].dimensions && -- GitLab