From 9e6497b5495ac85874f46d983ebf355394486629 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 3 Jan 2019 01:39:40 -0500 Subject: [PATCH] Update or remove the error after POSTing changes to server --- modules/services/keepRight.js | 46 +++++++++++++++++++--------------- modules/ui/keepRight_editor.js | 6 ++--- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/modules/services/keepRight.js b/modules/services/keepRight.js index d83a66bb7..15e1efb16 100644 --- a/modules/services/keepRight.js +++ b/modules/services/keepRight.js @@ -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? }, diff --git a/modules/ui/keepRight_editor.js b/modules/ui/keepRight_editor.js index 5d73e0ddf..01f120226 100644 --- a/modules/ui/keepRight_editor.js +++ b/modules/ui/keepRight_editor.js @@ -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); });