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) {
|
_computeLabelValues(labelName, _labels) {
|
||||||
const result = [];
|
const result = [];
|
||||||
const labels = _labels.base;
|
const labels = _labels.base;
|
||||||
const t = labels[labelName];
|
const labelInfo = labels[labelName];
|
||||||
if (!t) { return result; }
|
if (!labelInfo) { return result; }
|
||||||
const approvals = t.all || [];
|
if (!labelInfo.values) {
|
||||||
const values = Object.keys(t.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) {
|
for (const label of approvals) {
|
||||||
if (label.value && label.value != labels[labelName].default_value) {
|
if (label.value && label.value != labels[labelName].default_value) {
|
||||||
let labelClassName;
|
let labelClassName;
|
||||||
|
@@ -664,6 +664,32 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
suite('label colors', () => {
|
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', () => {
|
test('-2 to +2', () => {
|
||||||
element.change = {
|
element.change = {
|
||||||
labels: {
|
labels: {
|
||||||
|
@@ -142,7 +142,9 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_computeLabelValueTitle(labels, label, value) {
|
_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