Skip to content

Commit

Permalink
Merge pull request #126 from tidepool-org/jebeck/update-uploader
Browse files Browse the repository at this point in the history
handle outdated uploader version error
  • Loading branch information
jh-bate committed Jun 9, 2015
2 parents 55edce3 + 9cb679d commit 2505d56
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 10 deletions.
9 changes: 9 additions & 0 deletions lib/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var ViewDataLink = require('./ViewDataLink.jsx');
var UploadSettings = require('./UploadSettings.jsx');
var TimezoneSelection = require('./TimezoneSelection.jsx');
var DeviceSelection = require('./DeviceSelection.jsx');
var UpdatePlease = require('./UpdatePlease.jsx');

var config = require('../config');

Expand Down Expand Up @@ -131,6 +132,14 @@ var App = React.createClass({
);
}

if (page === 'error') {
return (
// TODO: add the link to help page on tidepool.org or knowledge base
// re: how to update the uploader
<UpdatePlease link={''} />
);
}

return null;
},

Expand Down
42 changes: 42 additions & 0 deletions lib/components/UpdatePlease.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* == BSD2 LICENSE ==
* Copyright (c) 2014, Tidepool Project
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the associated License, which is identical to the BSD 2-Clause
* License as published by the Open Source Initiative at opensource.org.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the License for more details.
*
* You should have received a copy of the License along with this program; if
* not, you can obtain one from Tidepool Project at tidepool.org.
* == BSD2 LICENSE ==
*/

var React = require('react');

var UpdatePlease = React.createClass({
propTypes: {
link: React.PropTypes.string.isRequired
},
render: function() {
var text = {
OUT_OF_DATE: 'Your uploader is out-of-date.',
TO_UPDATE: 'To update it, please follow ',
LINK_TEXT: 'these instructions',
TRY_AGAIN: 'Then try your upload again!'
};

return (
<div className="UpdatePlease">
<p>{text.OUT_OF_DATE}</p>
<p className='most-important'>{text.TO_UPDATE}<a href={this.props.link}>{text.LINK_TEXT}</a>.</p>
<p>{text.TRY_AGAIN}</p>
</div>
);
}
});

module.exports = UpdatePlease;
24 changes: 18 additions & 6 deletions lib/state/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ appActions.errorStages = {
STAGE_PICK_FILE : { code: 'E_SELECTING_FILE' , friendlyMessage: 'Error during file selection' },
STAGE_READ_FILE : { code: 'E_READING_FILE' , friendlyMessage: 'Error trying to read file' },
STAGE_UPLOAD : { code: 'E_UPLOADING' , friendlyMessage: 'Error uploading data' },
STAGE_METADATA_UPLOAD : { code: 'E_METADATA_UPLOAD' , friendlyMessage: 'Error uploading upload metadata'},
STAGE_DEVICE_UPLOAD : { code: 'E_DEVICE_UPLOAD' , friendlyMessage: 'Error uploading device data' },
STAGE_DEVICE_DETECT : { code: 'E_DEVICE_DETECT' , friendlyMessage: 'Error trying to detect a device' },
STAGE_CARELINK_UPLOAD : { code: 'E_CARELINK_UPLOAD' , friendlyMessage: 'Error uploading CareLink data' },
Expand All @@ -74,12 +75,17 @@ function extractMessage(err) {
return err.error || 'Unknown error message';
}
// if err.message is an object, that's because it's an error from jellyfish
else if (typeof err.message === 'object' && err.message.message) {
return err.message.message;
}
// sometimes the jellyfish errors don't have a `message`, only a `reason`?? *shrug*
else if (typeof err.message === 'object' && err.message.reason) {
return err.message.reason;
else if (typeof err.message === 'object') {
if (err.message.code === 'outdatedVersion') {
var stage = appActions.errorStages['STAGE_METADATA_UPLOAD'];
err.code = stage.code;
err.friendlyMessage = stage.friendlyMessage;
return err.message.text;
}
// sometimes the jellyfish errors don't have a `message`, only a `reason`?? *shrug*
else if (err.message.reason) {
return err.message.reason;
}
}
else {
return err.message;
Expand Down Expand Up @@ -725,6 +731,12 @@ appActions._handleUploadError = function(uploadIndex, error) {
}
return upload;
});

if (error.code === appActions.errorStages['STAGE_METADATA_UPLOAD'].code) {
this.app.setState({
page: 'error'
});
}
};

appActions._addToUploadHistory = function(upload, instance) {
Expand Down
2 changes: 1 addition & 1 deletion styles/components/App.less
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

@App-mainPageBorder: 1px;

.App--main .App-page, .App--settings .App-page {
.App--main .App-page, .App--settings .App-page, .App--error .App-page {
width: 550px;
background-color: rgba(255, 255, 255, 0.75);
border: @App-mainPageBorder solid @gray-border;
Expand Down
4 changes: 1 addition & 3 deletions styles/components/DeviceSelection.less
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
.DeviceSelection {
min-height: 300px;
justify-content: center;
.center-container;
}

.DeviceSelection-headline {
width: 250px;
margin: 20px auto 20px auto;
Expand Down
21 changes: 21 additions & 0 deletions styles/components/UpdatePlease.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.UpdatePlease {
.center-container;

a {
.blue-link;
}

p {
font-size: 1.2em;
text-align: center;
// our box-flex mixin wreaked havoc here and was making spans display flex
// (effectively block)
// TODO: fix that at the source
span {
display: inline;
}
&.most-important {
font-weight: bold;
}
}
}
18 changes: 18 additions & 0 deletions styles/core/mixins.less
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,21 @@
padding-right: 15px;
overflow-y: scroll;
}

// used so far for DeviceSelection and UpdatePlease
.center-container {
min-height: 300px;
justify-content: center;
}

// a common link style
.blue-link {
color: lighten(@purple-dark, 20%);

&:hover,
&:focus,
&:active {
color: @blue;
text-decoration: none;
}
}
1 change: 1 addition & 0 deletions styles/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
@import "components/ProgressBar.less";
@import "components/Scan.less";
@import "components/TimezoneSelection.less";
@import "components/UpdatePlease.less";
@import "components/Upload.less";
@import "components/UploadList.less";
@import "components/UploadSettings.less";
Expand Down
24 changes: 24 additions & 0 deletions test/ui/testAppActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,30 @@ describe('appActions', function() {
});
});

it('redirects to the `error` page if jellyfish errors because uploader is out-of-date', function(done) {
now = '2014-01-31T22:00:00-05:00';
device.detect = function(driverId, options, cb) { return cb(null, {}); };
device.upload = function(driverId, options, cb) {
now = '2014-01-31T22:00:30-05:00';
options.progress('fetchData', 50);
var err = new Error('Oops, we got an error');
err.code = 'E_METADATA_UPLOAD';
return cb(err);
};
app.state.targetId = '11';
app.state.uploads = [{
source: {
type: 'device',
driverId: 'DexcomG4'
}
}];

appActions.upload(0, {}, function(err) {
expect(app.state.page).to.equal('error');
done();
});
});

});

});

0 comments on commit 2505d56

Please sign in to comment.