Refactor to not define components inside a component
This commit is contained in:
committed by
M. Shull
parent
ab04cbab27
commit
c8c47eb37a
@ -1,29 +1,15 @@
|
|||||||
import React, { useLayoutEffect } from 'react';
|
import React, { useLayoutEffect } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
import _ from 'underscore';
|
|
||||||
|
|
||||||
import generateColumnSelection from './generate_column_selection.jsx';
|
import generateColumnSelection from './generate_column_selection.jsx';
|
||||||
import matchColumns from './match_columns.jsx';
|
import matchColumns from './match_columns.jsx';
|
||||||
|
|
||||||
const MAX_SUBSCRIBERS_SHOWN = 10;
|
const MAX_SUBSCRIBERS_SHOWN = 10;
|
||||||
|
|
||||||
function MatchTable({
|
function ColumnDataMatch({ header, subscribers }) {
|
||||||
subscribersCount,
|
|
||||||
subscribers,
|
|
||||||
header,
|
|
||||||
}) {
|
|
||||||
let selectedColumns = [];
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
generateColumnSelection((selectedOptionId, columnIndex) => {
|
|
||||||
selectedColumns[columnIndex] = selectedOptionId;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function ColumnDataMatch() {
|
|
||||||
const matchedColumnTypes = matchColumns(subscribers, header);
|
const matchedColumnTypes = matchColumns(subscribers, header);
|
||||||
selectedColumns = _.pluck(matchedColumnTypes, 'column_id');
|
// selectedColumns = _.pluck(matchedColumnTypes, 'column_id');
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
<th>{MailPoet.I18n.t('matchData')}</th>
|
<th>{MailPoet.I18n.t('matchData')}</th>
|
||||||
@ -43,18 +29,25 @@ function MatchTable({
|
|||||||
}
|
}
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
ColumnDataMatch.propTypes = {
|
||||||
|
header: PropTypes.arrayOf(PropTypes.string).isRequired,
|
||||||
|
subscribers: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.string)).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
function Header() {
|
function Header({ header }) {
|
||||||
return (
|
return (
|
||||||
<tr className="mailpoet_header">
|
<tr className="mailpoet_header">
|
||||||
<td />
|
<td />
|
||||||
{header.map(headerName => <td key={headerName}>{headerName}</td>)}
|
{header.map(headerName => <td key={headerName}>{headerName}</td>)}
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Header.propTypes = {
|
||||||
|
header: PropTypes.arrayOf(PropTypes.string).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
function Subscriber({ subscriber, index }) {
|
function Subscriber({ subscriber, index }) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<td>{index}</td>
|
<td>{index}</td>
|
||||||
@ -62,14 +55,13 @@ function MatchTable({
|
|||||||
{subscriber.map((field, i) => <td key={field + index + i}>{field}</td>)}
|
{subscriber.map((field, i) => <td key={field + index + i}>{field}</td>)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Subscriber.propTypes = {
|
||||||
Subscriber.propTypes = {
|
|
||||||
subscriber: PropTypes.arrayOf(PropTypes.string).isRequired,
|
subscriber: PropTypes.arrayOf(PropTypes.string).isRequired,
|
||||||
index: PropTypes.node.isRequired,
|
index: PropTypes.node.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
function Subscribers() {
|
function Subscribers({ subscribers, subscribersCount }) {
|
||||||
const filler = '. . .';
|
const filler = '. . .';
|
||||||
const fillerArray = Array(subscribers[0].length).fill(filler);
|
const fillerArray = Array(subscribers[0].length).fill(filler);
|
||||||
return (
|
return (
|
||||||
@ -102,17 +94,34 @@ function MatchTable({
|
|||||||
}
|
}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Subscribers.propTypes = {
|
||||||
|
subscribersCount: PropTypes.number.isRequired,
|
||||||
|
subscribers: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.string)).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
function MatchTable({
|
||||||
|
subscribersCount,
|
||||||
|
subscribers,
|
||||||
|
header,
|
||||||
|
}) {
|
||||||
|
const selectedColumns = [];
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
generateColumnSelection((selectedOptionId, columnIndex) => {
|
||||||
|
selectedColumns[columnIndex] = selectedOptionId;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="subscribers_data">
|
<div className="subscribers_data">
|
||||||
<table className="mailpoet_subscribers widefat fixed">
|
<table className="mailpoet_subscribers widefat fixed">
|
||||||
<thead>
|
<thead>
|
||||||
<ColumnDataMatch />
|
<ColumnDataMatch header={header} subscribers={subscribers} />
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<Header />
|
<Header header={header} />
|
||||||
<Subscribers />
|
<Subscribers subscribers={subscribers} subscribersCount={subscribersCount} />
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user