From c8c47eb37a78cf1236ada56377d35b0ff279be63 Mon Sep 17 00:00:00 2001 From: Amine Ben hammou Date: Fri, 12 Jul 2019 03:09:42 +0100 Subject: [PATCH] Refactor to not define components inside a component --- .../step_data_manipulation/match_table.jsx | 185 +++++++++--------- 1 file changed, 97 insertions(+), 88 deletions(-) diff --git a/assets/js/src/subscribers/importExport/import/step_data_manipulation/match_table.jsx b/assets/js/src/subscribers/importExport/import/step_data_manipulation/match_table.jsx index dc982c6af3..41cf92ec20 100644 --- a/assets/js/src/subscribers/importExport/import/step_data_manipulation/match_table.jsx +++ b/assets/js/src/subscribers/importExport/import/step_data_manipulation/match_table.jsx @@ -1,19 +1,111 @@ import React, { useLayoutEffect } from 'react'; import PropTypes from 'prop-types'; import MailPoet from 'mailpoet'; -import _ from 'underscore'; import generateColumnSelection from './generate_column_selection.jsx'; import matchColumns from './match_columns.jsx'; const MAX_SUBSCRIBERS_SHOWN = 10; +function ColumnDataMatch({ header, subscribers }) { + const matchedColumnTypes = matchColumns(subscribers, header); + // selectedColumns = _.pluck(matchedColumnTypes, 'column_id'); + return ( + + {MailPoet.I18n.t('matchData')} + { + matchedColumnTypes.map((columnType, i) => ( + // eslint-disable-next-line react/no-array-index-key + + - - )) - } - - ); - } - - function Header() { - return ( - - - {header.map(headerName => {headerName})} - - ); - } - - function Subscriber({ subscriber, index }) { - return ( - <> - {index} - {/* eslint-disable-next-line react/no-array-index-key */} - {subscriber.map((field, i) => {field})} - - ); - } - - Subscriber.propTypes = { - subscriber: PropTypes.arrayOf(PropTypes.string).isRequired, - index: PropTypes.node.isRequired, - }; - - function Subscribers() { - const filler = '. . .'; - const fillerArray = Array(subscribers[0].length).fill(filler); - return ( - <> - { - subscribers - .slice(0, MAX_SUBSCRIBERS_SHOWN) - .map((subscriber, i) => ( - - - - )) - } - { - subscribersCount > MAX_SUBSCRIBERS_SHOWN + 1 - ? - : null - } - { - subscribersCount > MAX_SUBSCRIBERS_SHOWN - ? ( - - - - ) - : null - } - - ); - } - return (
- + -
- +
+