Commit 64a6f220 authored by Daniel Hosseinian's avatar Daniel Hosseinian Committed by Commit Bot

Print Preview: Use a computed property to set CrOS destination status

Slightly clean up the CrOS destination status code by using a computed
property to set |statusText_|. This allows the removal of the observer
on |destination| and manual calls of updateStatusText_(). Additionally,
remove the stale shouldShowStatus_() function.

Change-Id: I50011717b9643f137fdd67f12c580adcae289776
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2357070
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799481}
parent f299b2f7
......@@ -41,11 +41,7 @@ Polymer({
dark: Boolean,
/** @type {!Destination} */
destination: {
type: Object,
observer: 'onDestinationChange_',
},
destination: Object,
disabled: Boolean,
......@@ -69,8 +65,12 @@ Polymer({
value: PDF_DESTINATION_KEY,
},
/** @private */
statusText_: String,
/** @private {string} */
statusText_: {
type: String,
computed:
'computeStatusText_(destination, destination.printerStatusReason)',
},
/** @private {string} */
backgroundImages_: {
......@@ -294,10 +294,9 @@ Polymer({
// If |printerStatus| is for the currently selected printer, use notifyPath
// to trigger the destination printer status icon to recalculate its badge
// color. Next update the destination error status text.
// color and the destination error status text.
if (this.destination && this.destination.key === destinationKey) {
this.notifyPath(`destination.printerStatusReason`);
this.updateStatusText_();
}
},
......@@ -339,47 +338,38 @@ Polymer({
PrinterStatusReason.UNKNOWN_REASON;
},
/** @private */
onDestinationChange_: function() {
this.updateStatusText_();
},
/**
* Check the current destination for an error status then set |statusText_|
* appropriately. If no error status exists, unset |statusText_|.
* @return {string} An error status for the current destination. If no error
* status exists, an empty string.
* @private
*/
updateStatusText_: function() {
computeStatusText_: function() {
// |destination| can be either undefined, or null here.
if (!this.destination) {
this.statusText_ = '';
return;
return '';
}
// Cloudprint destinations contain their own status text.
if (CloudOrigins.some(origin => origin === this.destination.origin)) {
this.statusText_ = this.destination.shouldShowInvalidCertificateError ?
return this.destination.shouldShowInvalidCertificateError ?
this.i18n('noLongerSupportedFragment') :
this.destination.connectionStatusText;
return;
}
// Only when the flag is enabled do we need to fetch a local printer status
// error string.
if (!this.printerStatusFlagEnabled_) {
this.statusText_ = '';
return;
return '';
}
const printerStatusReason = this.destination.printerStatusReason;
if (!printerStatusReason ||
printerStatusReason === PrinterStatusReason.NO_ERROR ||
printerStatusReason === PrinterStatusReason.UNKNOWN_REASON) {
this.statusText_ = '';
return;
return '';
}
this.statusText_ = this.getErrorString_(printerStatusReason);
return this.getErrorString_(printerStatusReason);
},
/**
......@@ -392,14 +382,6 @@ Polymer({
return errorStringKey ? this.i18n(errorStringKey) : '';
},
/**
* @return {!boolean}
* @private
*/
shouldShowStatus_: function() {
return !!this.statusText_;
},
/**
* True when the currently selected destination is a CrOS local printer.
* @return {boolean}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment