import React from "react";
import PropTypes from "prop-types";
import ArticleRow from "./article-body-row";

const ArticleBody = props => {
  const { section, content: bodyContent, contextUrl } = props;
  const contentArray = bodyContent.map((data, index) => {
    const item = {
      data,
      index
    };
    if (data.name === "ad") {
      item.data.attributes = {
        ...item.data.attributes,
        ...{ section, contextUrl }
      };
    }
    return item;
  });
  const BodyView = contentArray.map(content => (
    <ArticleRow key={`cont-${content.index}`} content={content} />
  ));

  return BodyView;
};

ArticleBody.propTypes = {
  content: PropTypes.arrayOf(
    PropTypes.shape({
      attributes: PropTypes.object,
      children: PropTypes.arrayOf(PropTypes.object),
      name: PropTypes.string
    })
  ).isRequired,
  section: PropTypes.string,
  contextUrl: PropTypes.string.isRequired
};

export default ArticleBody;

import React from "react";
import PropTypes from "prop-types";
import ArticleRow from "./article-body-row";

const ArticleBody = props => {
  const { section, content: bodyContent, contextUrl } = props;
  const contentArray = bodyContent.map((rowData, index) => {
    const item = {
      data: Object.assign({}, rowData),
      index
    };
    if (rowData.name === "ad") {
      item.data.attributes = {
        ...item.data.attributes,
        ...{ section, contextUrl }
      };
    }
    return item;
  });
  const BodyView = contentArray.map(content => (
    <ArticleRow key={`cont-${content.index}`} content={content} />
  ));

  return BodyView;
};

ArticleBody.propTypes = {
  content: PropTypes.arrayOf(
    PropTypes.shape({
      attributes: PropTypes.object,
      children: PropTypes.arrayOf(PropTypes.object),
      name: PropTypes.string
    })
  ).isRequired,
  section: PropTypes.string,
  contextUrl: PropTypes.string.isRequired
};

export default ArticleBody;

use mutable object as apollo uses immutables (#766)