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({ ...@@ -41,11 +41,7 @@ Polymer({
dark: Boolean, dark: Boolean,
/** @type {!Destination} */ /** @type {!Destination} */
destination: { destination: Object,
type: Object,
observer: 'onDestinationChange_',
},
disabled: Boolean, disabled: Boolean,
...@@ -69,8 +65,12 @@ Polymer({ ...@@ -69,8 +65,12 @@ Polymer({
value: PDF_DESTINATION_KEY, value: PDF_DESTINATION_KEY,
}, },
/** @private */ /** @private {string} */
statusText_: String, statusText_: {
type: String,
computed:
'computeStatusText_(destination, destination.printerStatusReason)',
},
/** @private {string} */ /** @private {string} */
backgroundImages_: { backgroundImages_: {
...@@ -294,10 +294,9 @@ Polymer({ ...@@ -294,10 +294,9 @@ Polymer({
// If |printerStatus| is for the currently selected printer, use notifyPath // If |printerStatus| is for the currently selected printer, use notifyPath
// to trigger the destination printer status icon to recalculate its badge // 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) { if (this.destination && this.destination.key === destinationKey) {
this.notifyPath(`destination.printerStatusReason`); this.notifyPath(`destination.printerStatusReason`);
this.updateStatusText_();
} }
}, },
...@@ -339,47 +338,38 @@ Polymer({ ...@@ -339,47 +338,38 @@ Polymer({
PrinterStatusReason.UNKNOWN_REASON; PrinterStatusReason.UNKNOWN_REASON;
}, },
/** @private */
onDestinationChange_: function() {
this.updateStatusText_();
},
/** /**
* Check the current destination for an error status then set |statusText_| * @return {string} An error status for the current destination. If no error
* appropriately. If no error status exists, unset |statusText_|. * status exists, an empty string.
* @private * @private
*/ */
updateStatusText_: function() { computeStatusText_: function() {
// |destination| can be either undefined, or null here. // |destination| can be either undefined, or null here.
if (!this.destination) { if (!this.destination) {
this.statusText_ = ''; return '';
return;
} }
// Cloudprint destinations contain their own status text. // Cloudprint destinations contain their own status text.
if (CloudOrigins.some(origin => origin === this.destination.origin)) { if (CloudOrigins.some(origin => origin === this.destination.origin)) {
this.statusText_ = this.destination.shouldShowInvalidCertificateError ? return this.destination.shouldShowInvalidCertificateError ?
this.i18n('noLongerSupportedFragment') : this.i18n('noLongerSupportedFragment') :
this.destination.connectionStatusText; this.destination.connectionStatusText;
return;
} }
// Only when the flag is enabled do we need to fetch a local printer status // Only when the flag is enabled do we need to fetch a local printer status
// error string. // error string.
if (!this.printerStatusFlagEnabled_) { if (!this.printerStatusFlagEnabled_) {
this.statusText_ = ''; return '';
return;
} }
const printerStatusReason = this.destination.printerStatusReason; const printerStatusReason = this.destination.printerStatusReason;
if (!printerStatusReason || if (!printerStatusReason ||
printerStatusReason === PrinterStatusReason.NO_ERROR || printerStatusReason === PrinterStatusReason.NO_ERROR ||
printerStatusReason === PrinterStatusReason.UNKNOWN_REASON) { printerStatusReason === PrinterStatusReason.UNKNOWN_REASON) {
this.statusText_ = ''; return '';
return;
} }
this.statusText_ = this.getErrorString_(printerStatusReason); return this.getErrorString_(printerStatusReason);
}, },
/** /**
...@@ -392,14 +382,6 @@ Polymer({ ...@@ -392,14 +382,6 @@ Polymer({
return errorStringKey ? this.i18n(errorStringKey) : ''; return errorStringKey ? this.i18n(errorStringKey) : '';
}, },
/**
* @return {!boolean}
* @private
*/
shouldShowStatus_: function() {
return !!this.statusText_;
},
/** /**
* True when the currently selected destination is a CrOS local printer. * True when the currently selected destination is a CrOS local printer.
* @return {boolean} * @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