Show valueless labels correctly
For labels that don't have scores (aka values), use `approved` and `rejected` fields from LabelInfo. Also, fix runtime exception when valueless label is encountered. Bug: Issue 8010 Change-Id: I7ed198778012ae94a8b1b165f22c286ba19a7d89
This commit is contained in:
@@ -134,10 +134,21 @@
|
||||
_computeLabelValues(labelName, _labels) {
|
||||
const result = [];
|
||||
const labels = _labels.base;
|
||||
const t = labels[labelName];
|
||||
if (!t) { return result; }
|
||||
const approvals = t.all || [];
|
||||
const values = Object.keys(t.values);
|
||||
const labelInfo = labels[labelName];
|
||||
if (!labelInfo) { return result; }
|
||||
if (!labelInfo.values) {
|
||||
if (labelInfo.rejected || labelInfo.approved) {
|
||||
const ok = labelInfo.approved || !labelInfo.rejected;
|
||||
return [{
|
||||
value: ok ? '👍️' : '👎️',
|
||||
className: ok ? 'positive' : 'negative',
|
||||
account: ok ? labelInfo.approved : labelInfo.rejected,
|
||||
}];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
const approvals = labelInfo.all || [];
|
||||
const values = Object.keys(labelInfo.values);
|
||||
for (const label of approvals) {
|
||||
if (label.value && label.value != labels[labelName].default_value) {
|
||||
let labelClassName;
|
||||
|
@@ -664,6 +664,32 @@ limitations under the License.
|
||||
});
|
||||
|
||||
suite('label colors', () => {
|
||||
test('valueless label rejected', () => {
|
||||
element.change = {
|
||||
labels: {
|
||||
'Do-Not-Submit': {
|
||||
rejected: {name: 'someone'},
|
||||
},
|
||||
},
|
||||
};
|
||||
flushAsynchronousOperations();
|
||||
const labels = Polymer.dom(element.root).querySelectorAll('gr-label');
|
||||
assert.isTrue(labels[0].classList.contains('negative'));
|
||||
});
|
||||
|
||||
test('valueless label approved', () => {
|
||||
element.change = {
|
||||
labels: {
|
||||
'To-The-Infinity': {
|
||||
approved: {name: 'someone'},
|
||||
},
|
||||
},
|
||||
};
|
||||
flushAsynchronousOperations();
|
||||
const labels = Polymer.dom(element.root).querySelectorAll('gr-label');
|
||||
assert.isTrue(labels[0].classList.contains('positive'));
|
||||
});
|
||||
|
||||
test('-2 to +2', () => {
|
||||
element.change = {
|
||||
labels: {
|
||||
|
@@ -142,7 +142,9 @@
|
||||
},
|
||||
|
||||
_computeLabelValueTitle(labels, label, value) {
|
||||
return labels[label] && labels[label].values[value];
|
||||
return labels[label] &&
|
||||
labels[label].values &&
|
||||
labels[label].values[value];
|
||||
},
|
||||
});
|
||||
})();
|
||||
|
Reference in New Issue
Block a user