import CSVReader from 'readers/csv/csv';
import { isNumber } from 'base/utils';

const CSVTimeInColumnsReader = CSVReader.extend({

  init(readerInfo) {
    this.name = 'csv-time_in_columns';
    this._super(readerInfo);
  },

  load() {
    return this._super()
      .then((data) => {
        const concepts = data.reduce((result, row) => {
          Object.keys(row).forEach(concept => {
            concept = concept === 'indicator' ? row.indicator : concept;

            if (Number(concept) != concept && !result.includes(concept)) {
              result.push(concept);
            }
          });

          return result;
        }, []).concat('time');

        const indicators = concepts.slice(1, -1);
        const [which] = concepts;
        return data.reduce((result, row) => {
          Object.keys(row).forEach((key) => {
            if (![which, 'indicator'].includes(key)) {
              result.push(
                Object.assign({
                    [which]: row[which],
                    time: key,
                  }, indicators.reduce((result, indicator) => {
                    result[indicator] = row.indicator === indicator ? row[key] : null;
                    return result;
                  }, {})
                )
              );
            }
          });

          return result;
        }, []);
      });
  }

});

export default CSVTimeInColumnsReader;

@@ -720,21 +720,28 @@
  const %5B
-which
+entityDomain
 %5D = conc
@@ -856,21 +856,28 @@
   if (!%5B
-which
+entityDomain
 , 'indic
@@ -984,25 +984,39 @@
    %5B
-which%5D: row%5Bwhich
+entityDomain%5D: row%5BentityDomain
 %5D,%0A 

Rename variable