Merge "Convert gr-apply-fix-dialog to class based element"
This commit is contained in:
@@ -16,35 +16,42 @@
|
|||||||
*/
|
*/
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
Polymer({
|
|
||||||
is: 'gr-apply-fix-dialog',
|
|
||||||
|
|
||||||
properties: {
|
/**
|
||||||
|
* @appliesMixin Gerrit.FireMixin
|
||||||
|
* @extends Polymer.Element
|
||||||
|
*/
|
||||||
|
class GrApplyFixDialog extends Polymer.mixinBehaviors( [
|
||||||
|
Gerrit.FireBehavior,
|
||||||
|
], Polymer.GestureEventListeners(
|
||||||
|
Polymer.LegacyElementMixin(
|
||||||
|
Polymer.Element))) {
|
||||||
|
static get is() { return 'gr-apply-fix-dialog'; }
|
||||||
|
|
||||||
|
static get properties() {
|
||||||
|
return {
|
||||||
// Diff rendering preference API response.
|
// Diff rendering preference API response.
|
||||||
prefs: Array,
|
prefs: Array,
|
||||||
// ChangeInfo API response object.
|
// ChangeInfo API response object.
|
||||||
change: Object,
|
change: Object,
|
||||||
changeNum: String,
|
changeNum: String,
|
||||||
_patchNum: Number,
|
_patchNum: Number,
|
||||||
// robot ID associated with a robot comment.
|
// robot ID associated with a robot comment.
|
||||||
_robotId: String,
|
_robotId: String,
|
||||||
// Selected FixSuggestionInfo entity from robot comment API response.
|
// Selected FixSuggestionInfo entity from robot comment API response.
|
||||||
_currentFix: Object,
|
_currentFix: Object,
|
||||||
// Flattened /preview API response DiffInfo map object.
|
// Flattened /preview API response DiffInfo map object.
|
||||||
_currentPreviews: {type: Array, value: () => []},
|
_currentPreviews: {type: Array, value: () => []},
|
||||||
// FixSuggestionInfo entities from robot comment API response.
|
// FixSuggestionInfo entities from robot comment API response.
|
||||||
_fixSuggestions: Array,
|
_fixSuggestions: Array,
|
||||||
_isApplyFixLoading: {
|
_isApplyFixLoading: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: false,
|
value: false,
|
||||||
},
|
},
|
||||||
// Index of currently showing suggested fix.
|
// Index of currently showing suggested fix.
|
||||||
_selectedFixIdx: Number,
|
_selectedFixIdx: Number,
|
||||||
},
|
};
|
||||||
|
}
|
||||||
behaviors: [
|
|
||||||
Gerrit.FireBehavior,
|
|
||||||
],
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given robot comment CustomEvent objevt, fetch diffs associated
|
* Given robot comment CustomEvent objevt, fetch diffs associated
|
||||||
@@ -73,24 +80,26 @@
|
|||||||
// ensures gr-overlay repositions overlay in center
|
// ensures gr-overlay repositions overlay in center
|
||||||
this.$.applyFixOverlay.fire('iron-resize');
|
this.$.applyFixOverlay.fire('iron-resize');
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
attached() {
|
attached() {
|
||||||
|
super.attached();
|
||||||
this.refitOverlay = () => {
|
this.refitOverlay = () => {
|
||||||
// re-center the dialog as content changed
|
// re-center the dialog as content changed
|
||||||
this.$.applyFixOverlay.fire('iron-resize');
|
this.$.applyFixOverlay.fire('iron-resize');
|
||||||
};
|
};
|
||||||
this.addEventListener('diff-context-expanded', this.refitOverlay);
|
this.addEventListener('diff-context-expanded', this.refitOverlay);
|
||||||
},
|
}
|
||||||
|
|
||||||
detached() {
|
detached() {
|
||||||
|
super.detached();
|
||||||
this.removeEventListener('diff-context-expanded', this.refitOverlay);
|
this.removeEventListener('diff-context-expanded', this.refitOverlay);
|
||||||
},
|
}
|
||||||
|
|
||||||
_showSelectedFixSuggestion(fixSuggestion) {
|
_showSelectedFixSuggestion(fixSuggestion) {
|
||||||
this._currentFix = fixSuggestion;
|
this._currentFix = fixSuggestion;
|
||||||
return this._fetchFixPreview(fixSuggestion.fix_id);
|
return this._fetchFixPreview(fixSuggestion.fix_id);
|
||||||
},
|
}
|
||||||
|
|
||||||
_fetchFixPreview(fixId) {
|
_fetchFixPreview(fixId) {
|
||||||
return this.$.restAPI
|
return this.$.restAPI
|
||||||
@@ -107,27 +116,27 @@
|
|||||||
this._close();
|
this._close();
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
hasSingleFix(_fixSuggestions) {
|
hasSingleFix(_fixSuggestions) {
|
||||||
return (_fixSuggestions || {}).length === 1;
|
return (_fixSuggestions || {}).length === 1;
|
||||||
},
|
}
|
||||||
|
|
||||||
overridePartialPrefs(prefs) {
|
overridePartialPrefs(prefs) {
|
||||||
// generate a smaller gr-diff than fullscreen for dialog
|
// generate a smaller gr-diff than fullscreen for dialog
|
||||||
return Object.assign({}, prefs, {line_length: 50});
|
return Object.assign({}, prefs, {line_length: 50});
|
||||||
},
|
}
|
||||||
|
|
||||||
onCancel(e) {
|
onCancel(e) {
|
||||||
if (e) {
|
if (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
this._close();
|
this._close();
|
||||||
},
|
}
|
||||||
|
|
||||||
addOneTo(_selectedFixIdx) {
|
addOneTo(_selectedFixIdx) {
|
||||||
return _selectedFixIdx + 1;
|
return _selectedFixIdx + 1;
|
||||||
},
|
}
|
||||||
|
|
||||||
_onPrevFixClick(e) {
|
_onPrevFixClick(e) {
|
||||||
if (e) e.stopPropagation();
|
if (e) e.stopPropagation();
|
||||||
@@ -136,7 +145,7 @@
|
|||||||
return this._showSelectedFixSuggestion(
|
return this._showSelectedFixSuggestion(
|
||||||
this._fixSuggestions[this._selectedFixIdx]);
|
this._fixSuggestions[this._selectedFixIdx]);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_onNextFixClick(e) {
|
_onNextFixClick(e) {
|
||||||
if (e) e.stopPropagation();
|
if (e) e.stopPropagation();
|
||||||
@@ -146,16 +155,16 @@
|
|||||||
return this._showSelectedFixSuggestion(
|
return this._showSelectedFixSuggestion(
|
||||||
this._fixSuggestions[this._selectedFixIdx]);
|
this._fixSuggestions[this._selectedFixIdx]);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_noPrevFix(_selectedFixIdx) {
|
_noPrevFix(_selectedFixIdx) {
|
||||||
return _selectedFixIdx === 0;
|
return _selectedFixIdx === 0;
|
||||||
},
|
}
|
||||||
|
|
||||||
_noNextFix(_selectedFixIdx, fixSuggestions) {
|
_noNextFix(_selectedFixIdx, fixSuggestions) {
|
||||||
if (fixSuggestions == null) return true;
|
if (fixSuggestions == null) return true;
|
||||||
return _selectedFixIdx === fixSuggestions.length - 1;
|
return _selectedFixIdx === fixSuggestions.length - 1;
|
||||||
},
|
}
|
||||||
|
|
||||||
_close() {
|
_close() {
|
||||||
this._currentFix = {};
|
this._currentFix = {};
|
||||||
@@ -167,11 +176,11 @@
|
|||||||
composed: true,
|
composed: true,
|
||||||
}));
|
}));
|
||||||
this.$.applyFixOverlay.close();
|
this.$.applyFixOverlay.close();
|
||||||
},
|
}
|
||||||
|
|
||||||
_getApplyFixButtonLabel(isLoading) {
|
_getApplyFixButtonLabel(isLoading) {
|
||||||
return isLoading ? 'Saving...' : 'Apply Fix';
|
return isLoading ? 'Saving...' : 'Apply Fix';
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleApplyFix(e) {
|
_handleApplyFix(e) {
|
||||||
if (e) {
|
if (e) {
|
||||||
@@ -192,11 +201,13 @@
|
|||||||
}
|
}
|
||||||
this._isApplyFixLoading = false;
|
this._isApplyFixLoading = false;
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
getFixDescription(currentFix) {
|
getFixDescription(currentFix) {
|
||||||
return currentFix != null && currentFix.description ?
|
return currentFix != null && currentFix.description ?
|
||||||
currentFix.description : '';
|
currentFix.description : '';
|
||||||
},
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
customElements.define(GrApplyFixDialog.is, GrApplyFixDialog);
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user