<commit_before>import flatten from 'flat';
import jsonexport from 'jsonexport';
import React, { Component } from 'react';

class CSVExport extends Component {
	constructor(){
		super();

		this.exportFile = this.exportFile.bind(this);
	}

	convertFileType(data){

		const options = {
			headers: this.props.columns.map((column) => (column.value)),
			rename: this.props.columns.map((column) => (column.label)),
		};
		
		jsonexport(data, options, (err,csv) => {
			if(err) {
				return console.log(err);
			}
			this.exportToBroswer(csv);
		});

	}

	exportFile() {
		this.convertFileType(this.reformatColumns(this.props.filterItems(this.props.items,this.props.query)));
	}

	exportToBroswer(csv) {
		console.log(csv);
	}

	reformatColumns(items) {
		let reformattedList = {};

		// reformattedList = {
		// 	...reformattedList,
		// 	newItem = {
		// 		[flatItem['budgetHours.column']: existingItem[sameCol].value + flatItem['budgetHours.value'],
		// 		total: existingItem[total] + flatItem['budgetHours.value'],
		// 		description: existingItem.description + flatItem['descriptions.budget'],
		// 		'descriptions.assumptions': existingItem['description.assumptions'] + flatItem['descriptions.assumptions'],
		// 		'descriptions.exclusions': existingItem['description.exclusions'] + flatItem['descriptions.exclusions'],
		// 	}
		// }

		// reformattedList[item.feature] = existingItem

		reformattedList = items.map((item) => {
			
			const flatItem = flatten(item, { maxDepth: 2 });

			const reformattedItem = {
				[flatItem['budgetHours.column']]: flatItem['budgetHours.value'],
				total: flatItem['budgetHours.value'],
				feature: flatItem.feature,
				description: flatItem['descriptions.budget'],
				'descriptions.assumptions': flatItem['descriptions.assumptions'],
				'descriptions.exclusions': flatItem['descriptions.exclusions'],
			};

			return reformattedItem;
		});

		console.log(reformattedList);

		return reformattedList;
	}

	render() {
		return (
			<button 
				onClick={this.exportFile}
				className="btn btn-primary">
				Export
			</button>
		);
	}
}

CSVExport.defaultProps = {
	columns: [{
		value:'feature',
		label:'Page/Feature',
	},{
		value:'t&m',
		label:'T&M',
	},{
		value:'Discovery',
		label:'Disc',
	},{
		value:'Design',
		label:'Design',
	},{
		value:'Dev',
		label:'Dev',
	},{
		value:'Testing',
		label:'Testing',
	},{
		value:'Remediation',
		label:'Remediation',
	},{
		value:'Deploy',
		label:'Deploy',
	},{
		value:'PM',
		label:'PM',
	},{
		value:'total',
		label:'Total',
	},{
		value:'description',
		label:'Description',
	},{
		value:'descriptions.assumptions',
		label:'Assumptions',
	},{<commit_msg>Concat itemList on feature<commit_after>import flatten from 'flat';
import jsonexport from 'jsonexport';
import React, { Component } from 'react';

class CSVExport extends Component {
	constructor(){
		super();

		this.exportFile = this.exportFile.bind(this);
	}

	convertFileType(data){

		const options = {
			headers: this.props.columns.map((column) => (column.value)),
			rename: this.props.columns.map((column) => (column.label)),
		};
		
		jsonexport(data, options, (err,csv) => {
			if(err) {
				return console.log(err);
			}
			this.exportToBroswer(csv);
		});

	}

	exportFile() {
		this.convertFileType(this.reformatColumns(this.props.filterItems(this.props.items,this.props.query)));
	}

	exportToBroswer(csv) {
		console.log(csv);
	}

	reformatColumns(items) {

		// list = {
		// 	klevu: {
		// 		dev:,
		// 		total:,
		// 		exclusions:,
		// 	}
		// }

		// list = [{
		// 	feature: klevu,
		// 	dev:,
		// 	total:,
		// }, {
		// 	feature: exia,
		// 	dev:,
		// 	total:,
		// }
		// ]

		const flatList = items.map((item) => flatten(item, { maxDepth: 2 }));
		
		// convert columns
		const reformattedList = flatList.map((item) => ({
				[item['budgetHours.column']]: item['budgetHours.value'],
				total: item['budgetHours.value'],
				feature: item.feature,
				'descriptions.budget': item['descriptions.budget'],
				'descriptions.assumptions': item['descriptions.assumptions'],
				'descriptions.clientResponsibilities': item['descriptions.clientResponsibilities'],
				'descriptions.exclusions': item['descriptions.exclusions'],								
		}));

		let concatObj = {};

		// combine on feature
		reformattedList.map((item) => {
			if(typeof concatObj[item.feature] === 'undefined') {
				concatObj[item.feature] = item;
			} else {
				for (const property in item) {
					if(Array.isArray(item[property])) {
						concatObj[item.feature][property] = [...concatObj[item.feature][property], ...item[property]];
					} else if(typeof item[property] === 'number') {
						concatObj[item.feature][property] = concatObj[item.feature][property] + item[property] || item[property];
						console.log(property);
					} 
				}
			}
		});

		// convert concatObj from properties to array elements
		let concatList = [];
		for (const element in concatObj) {
			concatList = [...concatList, concatObj[element]];
		}

		console.log(reformattedList);
		console.log(concatObj);
		console.log(concatList);


		return concatList;
	}



	render() {
		return (
			<button 
				onClick={this.exportFile}
				className="btn btn-primary">
				Export
			</button>
		);
	}
}

CSVExport.defaultProps = {
	columns: [{
		value:'feature',
		label:'Page/Feature',
	},{
		value:'t&m',
		label:'T&M',
	},{
		value:'Discovery',
		label:'Disc',
	},{
		value:'Design',
		label:'Design',
	},{
		value:'Dev',
		label:'Dev',
	},{
		value:'Testing',
		label:'Testing',
	},{
		value:'Remediation',
		label:'Remediation',
	},{
		value:'Deploy',
		label:'Deploy',
	},{
		value:'PM',
		label:'PM',
	},{
		value:'total',
		label:'Total',
	},{
		value:'descriptions.budget',
		label:'Description',
	},{
		value:'descriptions.assumptions',
		label:'Assumptions',
	},{
{'fraction_non_alphanumeric': 0.18227280565614762, 'fraction_numerical': 0.0003448870494912916, 'mean_word_length': 3.7269763651181744, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '2346677', 'n_tokens_mistral': 2324, 'n_tokens_neox': 1989, 'n_words': 294}