<commit_before>import * as React from "react";
import { Link } from "react-router";
import * as _ from "lodash";
import { GardenPlant } from "../garden_plant";
import { PlantLayerProps, CropSpreadDict } from "../interfaces";

let cropSpreadDict: CropSpreadDict = {};

export function PlantLayer(p: PlantLayerProps) {
  let { crops, plants, dispatch, visible, currentPlant, dragging, editing } = p;

  crops
    .filter(c => !!c.body.spread)
    .map(c => cropSpreadDict[c.body.slug] = c.body.spread);

  if (visible) {
    return <g>
      {plants
        .filter(x => !!x.body.id)
        .map(p => {
          p.body.spread = cropSpreadDict[p.body.openfarm_slug] || p.body.radius;
          return p;
        })
        .map(p => {
          return {
            selected: !!(currentPlant && (p.uuid === currentPlant.uuid)),
            plantId: (p.body.id || "IMPOSSIBLE_ERR_NO_PLANT_ID").toString(),
            uuid: p.uuid,
            plant: p
          }
        })
        .map(props => {
          let action = { type: "SELECT_PLANT", payload: props.uuid };
          return <Link className="plant-link-wrapper"
            to={"/app/designer/plants/" + props.plantId}<commit_msg>Defensively clone plant before mutating<commit_after>import * as React from "react";
import { Link } from "react-router";
import * as _ from "lodash";
import { GardenPlant } from "../garden_plant";
import { PlantLayerProps, CropSpreadDict } from "../interfaces";
import { defensiveClone } from "../../../util";

let cropSpreadDict: CropSpreadDict = {};

export function PlantLayer(p: PlantLayerProps) {
  let { crops, plants, dispatch, visible, currentPlant, dragging, editing } = p;

  crops
    .filter(c => !!c.body.spread)
    .map(c => cropSpreadDict[c.body.slug] = c.body.spread);

  if (visible) {
    return <g>
      {plants
        .filter(x => !!x.body.id)
        .map(p => defensiveClone(p))
        .map(p => {
          p.body.spread = cropSpreadDict[p.body.openfarm_slug] || p.body.radius;
          return p;
        })
        .map(p => {
          return {
            selected: !!(currentPlant && (p.uuid === currentPlant.uuid)),
            plantId: (p.body.id || "IMPOSSIBLE_ERR_NO_PLANT_ID").toString(),
            uuid: p.uuid,
            plant: p
          }
        })
        .map(props => {
          let action = { type: "SELECT_PLANT", payload: props.uuid };
          return <Link className="plant-link-wrapper"
            to={"/app/designer/plants/" + props.plantId}
{'fraction_non_alphanumeric': 0.1553592934564432, 'fraction_numerical': 0.0, 'mean_word_length': 2.3404825737265416, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2002421', 'n_tokens_mistral': 813, 'n_tokens_neox': 797, 'n_words': 173}