import React, { Component } from 'react';
import FlybaseDataGrid from 'react-flybase-datagrid';

function getHeaders(){

  var columns = [
   {id:'do_name', name:'Disease Name'},
   {id:'associationType', name:'Association'},
   {id:'evidence', name:'Evidence Code'},
   {id:'dataProvider', name:'Association Source'},
   {id:'ref', name:'References'}
  ];
  return columns;
}

class DiseaseTable extends Component {
  constructor(props) {
    super(props);

    // const diseases = this.props.data.diseases;

    var diseases = [
      {
        associationType": "contributes_to_condition",
        "dataProvider": "ZFIN",
        "do_name": [
          "cardiomyopathy"
        ],
        "evidence": [
        {
          "evidenceCode": "TAS",
          "pubs": [
            {
              "pubMedId": "27642634",
              "publicationModId": "ZFIN:ZDB-PUB-160920-5"
            },
            {
              "pubMedId": "1233",
              "publicationModId": "ZFIN:ZDB-PUB-170406-10"
            }
          ]
        }
      ],
    },
    {
      "associationType": "contributes_to_condition",
      "dataProvider": "flybase",
      "do_name": [
        "cancer"
      ],
      "evidence": [
        {
          "evidenceCode": "TAS",
          "pubs": [
            {
              "pubMedId": "987654",
              "publicationModId": "ZFIN:ZDB-PUB-160920-5"
            },
            {
              "pubMedId": "",
              "publicationModId": "ZFIN:ZDB-PUB-170406-10"
            }
          ]
        }
      ],
    }
  ];

    this.data = diseases.map((disease) => {

      const {
        associationType: associationType,
        dataProvider: dataProvider,
        do_name: do_name,
        evidence: [
          {
            evidenceCode: evidenceCode,
            pubs: [ ...pubs ]
          }
        ],
      } = disease;

      return {
        do_name : do_name,
        associationType: associationType,
        evidence: evidenceCode,
        dataProvider: dataProvider,
        ref: pubs.map((pub) => { return pub['pubMedId']; }).filter((pub) => { return (pub!=''); }).join()
      };
    });
  }

  render() {
    return (

       <FlybaseDataGrid
         columns={getHeaders()}
         data={this.data}
         showDownloadButton={false}
         showFilter={false}
       />

    );
  }
}

export default DiseaseTable;

@@ -459,11 +459,8 @@
 %0A   
- //
  con
@@ -504,1054 +504,8 @@
 s;%0A%0A
-    var diseases = %5B%0A      %7B%0A        associationType%22: %22contributes_to_condition%22,%0A        %22dataProvider%22: %22ZFIN%22,%0A        %22do_name%22: %5B%0A          %22cardiomyopathy%22%0A        %5D,%0A        %22evidence%22: %5B%0A        %7B%0A          %22evidenceCode%22: %22TAS%22,%0A          %22pubs%22: %5B%0A            %7B%0A              %22pubMedId%22: %2227642634%22,%0A              %22publicationModId%22: %22ZFIN:ZDB-PUB-160920-5%22%0A            %7D,%0A            %7B%0A              %22pubMedId%22: %221233%22,%0A              %22publicationModId%22: %22ZFIN:ZDB-PUB-170406-10%22%0A            %7D%0A          %5D%0A        %7D%0A      %5D,%0A    %7D,%0A    %7B%0A      %22associationType%22: %22contributes_to_condition%22,%0A      %22dataProvider%22: %22flybase%22,%0A      %22do_name%22: %5B%0A        %22cancer%22%0A      %5D,%0A      %22evidence%22: %5B%0A        %7B%0A          %22evidenceCode%22: %22TAS%22,%0A          %22pubs%22: %5B%0A            %7B%0A              %22pubMedId%22: %22987654%22,%0A              %22publicationModId%22: %22ZFIN:ZDB-PUB-160920-5%22%0A            %7D,%0A            %7B%0A              %22pubMedId%22: %22%22,%0A              %22publicationModId%22: %22ZFIN:ZDB-PUB-170406-10%22%0A            %7D%0A          %5D%0A        %7D%0A      %5D,%0A    %7D%0A  %5D;%0A%0A
     
@@ -952,32 +952,32 @@
 : dataProvider,%0A
-
         ref: pub
@@ -1066,16 +1066,45 @@
 .join()%0A
+        // ref: evidenceCode%0A
       %7D;

remove hard coded disease reference