diff --git a/src/components/TurkHit/index.js b/src/components/TurkHit/index.js index 76f24739d6ecbb70f96e7e5e82d1faae23e2998f..c2f8e720eba8bf24e1860fb7ff5e66f307863a00 100644 --- a/src/components/TurkHit/index.js +++ b/src/components/TurkHit/index.js @@ -32,11 +32,19 @@ class TurkHit extends Component { componentDidUpdate() { // Create the chart when the component updates with turk data - const hit = this.props.hit; - if (!hit.loading && - (hit.hitData.length > 0) && - hit.hitData[0].dimensions && - !this.state.chart) { + const { hit } = this.props; + if (hit == null) { + return; + } + const status = hit.status; + const currStatus = turkStatus[status]; + if ( + !currStatus.createBtn && + !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 @@ -377,27 +385,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 +508,6 @@ class TurkHit extends Component { const { hit } = this.props; const status = hit.status; - let mainContent =
; if (hit.loading) { return (
@@ -498,10 +525,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 +567,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 +600,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 edaecf520fca5ef9e39774283be24c6a14caa2f8..2814cb47c054da1f5635b62a2aa9ac6987d0dcee 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 c3ef206215f7eb7ead2d0179116bbfc389987402..19451f58e1e068a47abdd31ac479a563d2dc3f04 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 7d202767b2d5df08df3049adc550d2d234cfa050..966fd379c5c575e6a0691a942c3e0eec23c460bf 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 cfb68a6a91ddea5f9bb720e15bfa04b1ade8ff7b..d8ae462117c438abf8843ae17ed59f22562b3677 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 {