1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Allow any inline in the document to be queried by ID

Summary:
Ref T12616. When you "Delete" a comment from the preview, we try to delete the comment on screen too.

It may or may not be present on screen: if you just added it it's usually visible. However, you might also have hidden the file it contains or it could be on an older diff in a file which is no longer present in the current diff.

After updates in T12616, we could only find the comment if you'd previously interacted with it for some reason. Update this code to be able to find all inlines present in the document.

Test Plan:
  - Write a draft comment.
  - Reload the page.
  - DO NOT INTERACT WITH THE COMMENT!
  - Delete it from the preview.
  - After patch: Comment is deleted from the document, too.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12616

Differential Revision: https://secure.phabricator.com/D17937
This commit is contained in:
epriestley 2017-05-17 11:39:56 -07:00
parent 75fb1a0327
commit d03a497616

View file

@ -581,11 +581,19 @@ JX.install('DiffChangeset', {
}, },
getInlineByID: function(id) { getInlineByID: function(id) {
// TODO: Currently, this will only find inlines which the user has // First, look for the inline in the objects we've already built.
// already interacted with! Inlines are built lazily as events arrive. var inline = this._findInlineByID(id);
// This can not yet find inlines which are passively present in the if (inline) {
// document. return inline;
}
// If we haven't found a matching inline yet, rebuild all the inlines
// present in the document, then look again.
this._rebuildAllInlines();
return this._findInlineByID(id);
},
_findInlineByID: function(id) {
for (var ii = 0; ii < this._inlines.length; ii++) { for (var ii = 0; ii < this._inlines.length; ii++) {
var inline = this._inlines[ii]; var inline = this._inlines[ii];
if (inline.getID() == id) { if (inline.getID() == id) {
@ -594,8 +602,21 @@ JX.install('DiffChangeset', {
} }
return null; return null;
},
_rebuildAllInlines: function() {
var rows = JX.DOM.scry(this._node, 'tr');
for (var ii = 0; ii < rows.length; ii++) {
var row = rows[ii];
if (this._getRowType(row) != 'comment') {
continue;
} }
// As a side effect, this builds any missing inline objects and adds
// them to this Changeset's list of inlines.
this.getInlineForRow(row);
}
}
}, },