Update or remove the error after POSTing changes to server

This commit is contained in:
Bryan Housel
2019-01-03 01:39:40 -05:00
parent 69ce5ee964
commit 9e6497b549
2 changed files with 28 additions and 24 deletions
+26 -20
View File
@@ -324,34 +324,40 @@ export default {
},
postKeepRightUpdate: function(update, callback) {
if (_krCache.inflight[update.id]) {
return callback({ message: 'Error update already inflight', status: -2 }, update);
postKeepRightUpdate: function(d, callback) {
if (_krCache.inflight[d.id]) {
return callback({ message: 'Error update already inflight', status: -2 }, d);
}
var path = apibase + 'comment.php?';
if (update.state) {
path += '&st=' + update.state;
var that = this;
var params = { schema: d.schema, id: d.error_id };
if (d.state) {
params.st = d.state;
}
if (update.newComment !== undefined) {
path += '&' + utilQsString({ co: update.newComment });
if (d.newComment !== undefined) {
params.co = d.newComment;
}
path += '&schema=' + update.schema + '&id=' + update.error_id;
// NOTE: This throws a CORS err, but it seems successful.
// We don't care too much about the response, so this is fine.
var url = apibase + 'comment.php?' + utilQsString(params);
_krCache.inflight[d.id] = d3_request(url)
.post(function(err) {
delete _krCache.inflight[d.id];
if (d.state === 'ignore' || d.state === 'ignore_t') {
that.removeError(d);
} else {
d = that.replaceError(d.update({
comment: d.newComment,
newComment: undefined,
state: undefined
}));
}
_krCache.inflight[update.id] = d3_request(path)
.mimeType('application/json')
.response(function(xhr) {
return JSON.parse(xhr.responseText);
})
.post(function(err, data) {
delete _krCache.inflight[update.id];
if (err) { return callback(err); }
console.log('data ', data);
return callback(err, d);
});
// NOTE: This throws a CORS error, but it seems successful?
},
+2 -4
View File
@@ -174,7 +174,6 @@ export function uiKeepRightEditor(context) {
buttonSection.select('.close-button') // select and propagate data
.text(function(d) {
// NOTE: no state is available because keepRight export only exports open errors
var andComment = (d.newComment !== undefined ? '_comment' : '');
return t('QA.keepRight.close' + andComment);
})
@@ -182,8 +181,7 @@ export function uiKeepRightEditor(context) {
this.blur(); // avoid keeping focus on the button - #4641
var keepRight = services.keepRight;
if (keepRight) {
d.state = d.state === 'ignore_t' ? '' : 'ignore_t';
d.state = 'ignore_t'; // ignore temporarily (error fixed)
keepRight.postKeepRightUpdate(d, function(err, error) {
dispatch.call('change', error);
});
@@ -199,7 +197,7 @@ export function uiKeepRightEditor(context) {
this.blur(); // avoid keeping focus on the button - #4641
var keepRight = services.keepRight;
if (keepRight) {
d.state = d.state === 'ignore' ? '' : 'ignore';
d.state = 'ignore'; // ignore permanently (false positive)
keepRight.postKeepRightUpdate(d, function(err, error) {
dispatch.call('change', error);
});