From e694438033b6e7fe5b3e2c93fa30e1b84bb394c2 Mon Sep 17 00:00:00 2001 From: Pavel Dohnal Date: Wed, 23 Jan 2019 09:47:58 +0100 Subject: [PATCH] Auto fix broken rules --- .../src/announcements/in_app_announcement.jsx | 12 +-- assets/js/src/common/confirm_alert.jsx | 12 ++- assets/js/src/common/key_value_table.jsx | 5 +- assets/js/src/common/loading.jsx | 2 + assets/js/src/common/print_boolean.jsx | 6 +- assets/js/src/common/thumbnail.jsx | 99 +++++++++---------- assets/js/src/form/fields/date.jsx | 68 ++++++++----- assets/js/src/form/fields/select.jsx | 15 ++- assets/js/src/form/fields/selection.jsx | 20 ++-- assets/js/src/form/fields/text.jsx | 4 +- assets/js/src/forms/list.jsx | 12 ++- assets/js/src/help-tooltip.jsx | 20 ++-- assets/js/src/help/cron_status.jsx | 2 +- assets/js/src/help/help.jsx | 4 +- assets/js/src/help/queue_status.jsx | 2 +- assets/js/src/help/system_info.jsx | 20 ++-- assets/js/src/help/system_status.jsx | 6 +- assets/js/src/help/tabs.jsx | 4 +- assets/js/src/help/tasks_list/tasks_list.jsx | 4 +- .../help/tasks_list/tasks_list_data_row.jsx | 3 +- assets/js/src/listing/bulk_actions.jsx | 4 +- assets/js/src/listing/filters.jsx | 4 +- assets/js/src/listing/groups.jsx | 6 +- assets/js/src/listing/listing_column.jsx | 4 +- assets/js/src/listing/listing_item.jsx | 18 +++- assets/js/src/listing/listing_items.jsx | 13 ++- assets/js/src/listing/pages.jsx | 15 +-- assets/js/src/newsletters/badges/stats.jsx | 5 +- assets/js/src/newsletters/listings/mixins.jsx | 76 +++++++++----- .../src/newsletters/listings/notification.jsx | 12 ++- .../listings/notification_history.jsx | 8 +- .../js/src/newsletters/listings/standard.jsx | 4 +- assets/js/src/newsletters/listings/tabs.jsx | 7 +- .../js/src/newsletters/listings/welcome.jsx | 8 +- assets/js/src/newsletters/newsletters.jsx | 4 +- .../js/src/newsletters/scheduling/common.jsx | 4 +- assets/js/src/newsletters/send.jsx | 40 ++++---- .../send/congratulate/congratulate.jsx | 38 ++++--- .../newsletters/send/congratulate/fail.jsx | 4 +- .../newsletters/send/congratulate/success.jsx | 14 +-- .../js/src/newsletters/send/notification.jsx | 1 - assets/js/src/newsletters/send/standard.jsx | 4 +- .../newsletters/templates/import_template.jsx | 7 +- assets/js/src/newsletters/templates/tabs.jsx | 16 +-- .../newsletters/templates/template_box.jsx | 20 +++- assets/js/src/newsletters/types.jsx | 9 +- .../types/automatic_emails/event.jsx | 6 +- .../types/automatic_emails/events_list.jsx | 3 +- .../types/notification/notification.jsx | 1 - .../types/notification/scheduling.jsx | 4 + assets/js/src/newsletters/types/standard.jsx | 1 - .../newsletters/types/welcome/scheduling.jsx | 4 + assets/js/src/poll.jsx | 6 +- assets/js/src/segments/list.jsx | 12 ++- .../settings/new_subscriber_announcement.jsx | 3 +- assets/js/src/subscribers/form.jsx | 8 +- assets/js/src/subscribers/list.jsx | 30 ++++-- assets/js/src/welcome_wizard/header.jsx | 4 +- .../src/welcome_wizard/steps/sender_step.jsx | 6 +- .../steps/usage_tracking_step.jsx | 4 +- .../src/welcome_wizard/steps_controller.jsx | 82 ++++++++------- assets/js/src/welcome_wizard/wizard.jsx | 2 +- 62 files changed, 516 insertions(+), 325 deletions(-) diff --git a/assets/js/src/announcements/in_app_announcement.jsx b/assets/js/src/announcements/in_app_announcement.jsx index 6c4b723b8c..81910dc5a9 100644 --- a/assets/js/src/announcements/in_app_announcement.jsx +++ b/assets/js/src/announcements/in_app_announcement.jsx @@ -25,8 +25,8 @@ class InAppAnnouncement extends React.Component { } render() { - if (this.props.showToNewUser !== null && - window.mailpoet_is_new_user !== this.props.showToNewUser + if (this.props.showToNewUser !== null + && window.mailpoet_is_new_user !== this.props.showToNewUser ) { return null; } @@ -37,14 +37,14 @@ class InAppAnnouncement extends React.Component { return null; } - if (this.props.showToPremiumUser !== null && - window.mailpoet_premium_active !== this.props.showToPremiumUser + if (this.props.showToPremiumUser !== null + && window.mailpoet_premium_active !== this.props.showToPremiumUser ) { return null; } - if (this.props.showOnlyOnceSlug && - this.state.announcementsSettings.displayed.includes(this.props.showOnlyOnceSlug) + if (this.props.showOnlyOnceSlug + && this.state.announcementsSettings.displayed.includes(this.props.showOnlyOnceSlug) ) { return null; } diff --git a/assets/js/src/common/confirm_alert.jsx b/assets/js/src/common/confirm_alert.jsx index 0a9b8cc1ec..a440701a13 100644 --- a/assets/js/src/common/confirm_alert.jsx +++ b/assets/js/src/common/confirm_alert.jsx @@ -39,17 +39,22 @@ class ConfirmAlert extends React.Component { } render() { - const { title, message, confirmLabel, cancelLabel } = this.props; + const { + title, message, confirmLabel, cancelLabel, + } = this.props; - return (this.state.show && + return (this.state.show + && (
+ ) ); } } diff --git a/assets/js/src/common/key_value_table.jsx b/assets/js/src/common/key_value_table.jsx index 1010b512e3..94ae2af000 100644 --- a/assets/js/src/common/key_value_table.jsx +++ b/assets/js/src/common/key_value_table.jsx @@ -2,11 +2,12 @@ import PropTypes from 'prop-types'; import React from 'react'; const KeyValueTable = props => ( - +
{props.rows.map(row => ( - + + ))} diff --git a/assets/js/src/common/loading.jsx b/assets/js/src/common/loading.jsx index bdde3da874..29daf8dbfb 100644 --- a/assets/js/src/common/loading.jsx +++ b/assets/js/src/common/loading.jsx @@ -5,9 +5,11 @@ class Loading extends React.Component { componentWillMount() { MailPoet.Modal.loading(true); } + componentWillUnmount() { MailPoet.Modal.loading(false); } + render() { return null; } diff --git a/assets/js/src/common/print_boolean.jsx b/assets/js/src/common/print_boolean.jsx index 9c050cc335..eb7cd0c432 100644 --- a/assets/js/src/common/print_boolean.jsx +++ b/assets/js/src/common/print_boolean.jsx @@ -4,9 +4,9 @@ import MailPoet from 'mailpoet'; const PrintBoolean = props => ( - {(props.children === true && props.truthy) || - (props.children === false && props.falsy) || - (props.unknown)} + {(props.children === true && props.truthy) + || (props.children === false && props.falsy) + || (props.unknown)} ); diff --git a/assets/js/src/common/thumbnail.jsx b/assets/js/src/common/thumbnail.jsx index 8ce2e923fd..40a43d92ce 100644 --- a/assets/js/src/common/thumbnail.jsx +++ b/assets/js/src/common/thumbnail.jsx @@ -8,10 +8,9 @@ import html2canvas from 'html2canvas'; * @param {DOMElement} element * @return {Promise} DataURL of the generated image. */ -export const fromDom = element => - html2canvas(element, { - logging: false, - }).then(canvas => canvas.toDataURL('image/jpeg')); +export const fromDom = element => html2canvas(element, { + logging: false, +}).then(canvas => canvas.toDataURL('image/jpeg')); /** * Generates a thumbnail from an URL. @@ -19,37 +18,36 @@ export const fromDom = element => * @param {String} url * @return {Promise} DataURL of the generated image. */ -export const fromUrl = url => - new Promise((resolve, reject) => { - const iframe = document.createElement('iframe'); - const protocol = location.href.startsWith('https://') ? 'https:' : 'http:'; - iframe.src = protocol + url.replace(/^https?:/, ''); - iframe.style.opacity = 0; - iframe.scrolling = 'no'; - iframe.onload = () => { - fromDom(iframe.contentDocument.documentElement) - .then((image) => { - document.body.removeChild(iframe); - resolve(image); - }) - .catch(() => { - document.body.removeChild(iframe); - reject(MailPoet.I18n.t('errorWhileTakingScreenshot')); - }); - }; - const onError = () => { - document.body.removeChild(iframe); - reject(MailPoet.I18n.t('errorWhileTakingScreenshot')); - }; - iframe.onerror = onError; - iframe.onError = onError; - iframe.className = 'mailpoet_template_iframe'; - try { - document.body.appendChild(iframe); - } catch (err) { - onError(); - } - }); +export const fromUrl = url => new Promise((resolve, reject) => { + const iframe = document.createElement('iframe'); + const protocol = location.href.startsWith('https://') ? 'https:' : 'http:'; + iframe.src = protocol + url.replace(/^https?:/, ''); + iframe.style.opacity = 0; + iframe.scrolling = 'no'; + iframe.onload = () => { + fromDom(iframe.contentDocument.documentElement) + .then((image) => { + document.body.removeChild(iframe); + resolve(image); + }) + .catch(() => { + document.body.removeChild(iframe); + reject(MailPoet.I18n.t('errorWhileTakingScreenshot')); + }); + }; + const onError = () => { + document.body.removeChild(iframe); + reject(MailPoet.I18n.t('errorWhileTakingScreenshot')); + }; + iframe.onerror = onError; + iframe.onError = onError; + iframe.className = 'mailpoet_template_iframe'; + try { + document.body.appendChild(iframe); + } catch (err) { + onError(); + } +}); /** * Generates a thumbnail from a newsletter's data. @@ -57,20 +55,17 @@ export const fromUrl = url => * @param {Object} data * @return {Promise} DataURL of the generated image. */ -export const fromNewsletter = data => - new Promise((resolve, reject) => { - const json = data; - if (!_.isUndefined(json.body)) { - json.body = JSON.stringify(json.body); - } - MailPoet.Ajax.post({ - api_version: window.mailpoet_api_version, - endpoint: 'newsletters', - action: 'showPreview', - data: json, - }).done(response => fromUrl(response.meta.preview_url) - .then(resolve) - .catch(reject) - ).fail(response => reject(response.errors)); - }); - +export const fromNewsletter = data => new Promise((resolve, reject) => { + const json = data; + if (!_.isUndefined(json.body)) { + json.body = JSON.stringify(json.body); + } + MailPoet.Ajax.post({ + api_version: window.mailpoet_api_version, + endpoint: 'newsletters', + action: 'showPreview', + data: json, + }).done(response => fromUrl(response.meta.preview_url) + .then(resolve) + .catch(reject)).fail(response => reject(response.errors)); +}); diff --git a/assets/js/src/form/fields/date.jsx b/assets/js/src/form/fields/date.jsx index a2ccd1d6f4..417e93c6e9 100644 --- a/assets/js/src/form/fields/date.jsx +++ b/assets/js/src/form/fields/date.jsx @@ -18,7 +18,9 @@ function FormFieldDateYear(props) { + > + { i } + )); } return ( @@ -56,7 +58,9 @@ function FormFieldDateMonth(props) { + > + { props.monthNames[i - 1] } + )); } return ( @@ -95,7 +99,9 @@ function FormFieldDateDay(props) { + > + { i } + )); } @@ -131,9 +137,11 @@ class FormFieldDate extends React.Component { this.onValueChange = this.onValueChange.bind(this); } + componentDidMount() { this.extractDateParts(); } + componentDidUpdate(prevProps) { if ( (this.props.item !== undefined && prevProps.item !== undefined) @@ -142,6 +150,7 @@ class FormFieldDate extends React.Component { this.extractDateParts(); } } + onValueChange(e) { // extract property from name const matches = e.target.name.match(/(.*?)\[(.*?)\]/); @@ -166,6 +175,7 @@ class FormFieldDate extends React.Component { }); } } + formatValue() { const dateType = this.props.field.params.date_type; @@ -207,6 +217,7 @@ class FormFieldDate extends React.Component { return value; } + extractDateParts() { const value = (this.props.item[this.props.field.name] !== undefined) ? this.props.item[this.props.field.name].trim() @@ -224,6 +235,7 @@ class FormFieldDate extends React.Component { day: dateTime.format('D'), }); } + render() { const monthNames = window.mailpoet_month_names || []; const dateFormats = window.mailpoet_date_formats || {}; @@ -233,32 +245,38 @@ class FormFieldDate extends React.Component { const fields = dateSelects.map((type) => { switch (type) { case 'YYYY': - return (); + return ( + + ); case 'MM': - return (); + return ( + + ); case 'DD': - return (); + return ( + + ); default: return
Invalid date type
; diff --git a/assets/js/src/form/fields/select.jsx b/assets/js/src/form/fields/select.jsx index 3a365543d4..fb3020f904 100644 --- a/assets/js/src/form/fields/select.jsx +++ b/assets/js/src/form/fields/select.jsx @@ -30,14 +30,13 @@ class FormFieldSelect extends React.Component { if (sortBy) { // Extract keys from sorted [key, value] select value pairs, sorted by // provided sorting order. - keys = - _.map( - _.sortBy( - _.pairs(this.props.field.values), - item => sortBy(item[0], item[1]) - ), - item => item[0] - ); + keys = _.map( + _.sortBy( + _.pairs(this.props.field.values), + item => sortBy(item[0], item[1]) + ), + item => item[0] + ); } else { keys = Object.keys(this.props.field.values); } diff --git a/assets/js/src/form/fields/selection.jsx b/assets/js/src/form/fields/selection.jsx index 434e514f9a..cecee9245f 100644 --- a/assets/js/src/form/fields/selection.jsx +++ b/assets/js/src/form/fields/selection.jsx @@ -10,6 +10,7 @@ class Selection extends React.Component { super(props); this.selectRef = React.createRef(); } + componentDidMount() { if (this.isSelect2Component()) { this.setupSelect2(); @@ -25,9 +26,9 @@ class Selection extends React.Component { .trigger('change'); } - if (this.isSelect2Initialized() && - (this.getFieldId(this.props) !== this.getFieldId(prevProps)) && - this.props.field.resetSelect2OnUpdate !== undefined + if (this.isSelect2Initialized() + && (this.getFieldId(this.props) !== this.getFieldId(prevProps)) + && this.props.field.resetSelect2OnUpdate !== undefined ) { this.resetSelect2(); } @@ -47,7 +48,7 @@ class Selection extends React.Component { getSelectedValues = () => { if (this.props.field.selected !== undefined) { return this.props.field.selected(this.props.item); - } else if (this.props.item !== undefined && this.props.field.name !== undefined) { + } if (this.props.item !== undefined && this.props.field.name !== undefined) { if (this.allowMultipleValues()) { if (_.isArray(this.props.item[this.props.field.name])) { return this.props.item[this.props.field.name].map(item => item.id); @@ -112,7 +113,7 @@ class Selection extends React.Component { templateResult: function templateResult(item) { if (item.element && item.element.selected) { return null; - } else if (item.title) { + } if (item.title) { return item.title; } return item.text; @@ -140,11 +141,10 @@ class Selection extends React.Component { }; }, processResults: function processResults(response) { - return { results: (!_.has(response, 'data')) ? - [] : - response.data.map(item => - ({ id: item.id || item.value, text: item.name || item.text }) - ), + return { + results: (!_.has(response, 'data')) + ? [] + : response.data.map(item => ({ id: item.id || item.value, text: item.name || item.text })), }; }, }, diff --git a/assets/js/src/form/fields/text.jsx b/assets/js/src/form/fields/text.jsx index 3df5be92b3..1323c81761 100644 --- a/assets/js/src/form/fields/text.jsx +++ b/assets/js/src/form/fields/text.jsx @@ -11,8 +11,8 @@ class FormFieldText extends React.Component { // eslint-disable-line react/prefe if (this.props.onValueChange instanceof Function) { value = item[this.props.field.name]; // set value to defaultValue if available - value = (value === undefined) ? - (this.props.field.defaultValue || '') : value; + value = (value === undefined) + ? (this.props.field.defaultValue || '') : value; } // defaultValue should only be set only when value is not set if (!value && this.props.field.defaultValue) { diff --git a/assets/js/src/forms/list.jsx b/assets/js/src/forms/list.jsx index ff18dd9e77..40c29dd48c 100644 --- a/assets/js/src/forms/list.jsx +++ b/assets/js/src/forms/list.jsx @@ -164,7 +164,9 @@ class FormList extends React.Component { { form.name } + > + { form.name } + { actions } @@ -185,12 +187,16 @@ class FormList extends React.Component { return (

- {MailPoet.I18n.t('pageTitle')} {MailPoet.I18n.t('new')} + > + {MailPoet.I18n.t('new')} +

- {ReactHtmlParser(props.tooltip)} - ); + tooltip = ( + + {ReactHtmlParser(props.tooltip)} + + ); } return ( diff --git a/assets/js/src/help/cron_status.jsx b/assets/js/src/help/cron_status.jsx index 3192f89c5f..1b73af6d96 100644 --- a/assets/js/src/help/cron_status.jsx +++ b/assets/js/src/help/cron_status.jsx @@ -14,7 +14,7 @@ const CronStatus = (props) => {

{MailPoet.I18n.t('systemStatusCronStatusTitle')}

{

{MailPoet.I18n.t('systemStatusQueueTitle')}

`${key}: ${data[key]}`); - return (
{ row.key }{ row.value }{ row.key }{ row.value }