var _ = require('lodash');
var React = require('react/addons');
var API = require('data/api');
var RegionTitleMenu     = require('component/RegionTitleMenu.jsx');
var IndicatorDropdownMenu = require('component/IndicatorDropdownMenu.jsx');
var CampaignDropdownMenu = require('component/CampaignDropdownMenu.jsx');

const {
	Datascope, LocalDatascope,
	SimpleDataTable, SimpleDataTableColumn,
	ClearQueryLink,
	Paginator,
	SearchBar,
	FilterPanel, FilterDateRange, FilterInputRadio
	} = require('react-datascope');

var parseSchema = require('ufadmin/utils/parseSchema');

var ReviewPage = React.createClass({
	propTypes: {
		title: React.PropTypes.string.isRequired,
		getMetadata: React.PropTypes.func.isRequired,
		getData: React.PropTypes.func.isRequired,
    loading   : React.PropTypes.bool.isRequired,
		fields 		: React.PropTypes.object.isRequired,
		region 		: React.PropTypes.object.isRequired,
	},
	getInitialState: function() {
		return {
			data: null,
			schema: null,
			query: {},
			loading   : false,
		}
	},

	componentWillMount: function() {
		this.props.getMetadata().then(response => this.setState({
			metadata: response,
			schema: parseSchema(response)
		}));
		this.props.getData({master_object_id:this.props.region.id},null,{'cache-control':'no-cache'}).then(response => this.setState({data: response.objects}));
		},

	componentWillUpdate : function (nextProps, nextState) {
		// update this.state.data if there is a metadata change //
			if (nextProps.region != this.props.region) {
				return;
			}
		},

	componentWillReceiveProps: function(nextProps) {
		console.log('NEW PROPSS!!!!')
		this.props.getMetadata().then(response => this.setState({
			metadata: response,
			schema: parseSchema(response)
		}));
		this.props.getData({master_object_id:nextProps.region.id},null,{'cache-control':'no-cache'}).then(response => this.setState({data: response.objects}));
		this.forceUpdate()
		},
	render() {

		var isLoaded = _.isArray(this.state.data) && this.state.metadata && this.state.schema && (!this.state.loading);
		if(!isLoaded) return this.renderLoading();

		var {data, schema, metadata} = this.state;

		var fields = this.props.fields

		console.log('returning render of review page')
		console.log(data.length)
		console.log('tat was the len of the data..')

		return <div>
			<LocalDatascope data={data} schema={schema} fields={fields} pageSize={25}>
				<Datascope>
					{this.props.children}
				</Datascope>
			</LocalDatascope>
		</div>
	},
	renderLoading() {
		return <div className='admin-loading'> Review Page Loading...</div>
	},
});


module.exports = ReviewPage;

@@ -511,78 +511,21 @@
 );%0A%0A
+%0A
 var 
-parseSchema = require('ufadmin/utils/parseSchema');%0A%0Avar ReviewPag
+BaseTabl
 e = 
@@ -564,13 +564,16 @@
 %7B%0A%09%09
-title
+data %09%09%09
 : Re
@@ -590,14 +590,14 @@
 pes.
-string
+object
 .isR
@@ -611,134 +611,41 @@
 ,%0A%09%09
-getMetadata: React.PropTypes.func.isRequired,%0A%09%09getData: React.PropTypes.func.isRequired,%0A    loading   : React.PropTypes.bool
+schema %09%09: React.PropTypes.object
 .isR
@@ -707,17 +707,18 @@
 ,%0A%09%09
-region %09%09
+loading   
 : Re
@@ -723,38 +723,36 @@
 React.PropTypes.
-object
+bool
 .isRequired,%0A%09%7D,
@@ -748,16 +748,17 @@
 quired,%0A
+%0A
 %09%7D,%0A%09get
@@ -834,17 +834,18 @@
 %0A%09%09%09
-query: %7B%7D
+fields: %5B%5D
 ,%0A%09%09
@@ -878,1040 +878,67 @@
 ,%0A%0A%09
-componentWillMount: function() %7B%0A%09%09this.props.getMetadata().then(response =%3E this.setState(%7B%0A%09%09%09metadata: response,%0A%09%09%09schema: parseSchema(response)%0A%09%09%7D));%0A%09%09this.props.getData(%7Bmaster_object_id:this.props.region.id%7D,null,%7B'cache-control':'no-cache'%7D).then(response =%3E this.setState(%7Bdata: response.objects%7D));%0A%09%09%7D,%0A%0A%09componentWillUpdate : function (nextProps, nextState) %7B%0A%09%09// update this.state.data if there is a metadata change //%0A%09%09%09if (nextProps.region != this.props.region) %7B%0A%09%09%09%09return;%0A%09%09%09%7D%0A%09%09%7D,%0A%0A%09componentWillReceiveProps: function(nextProps) %7B%0A%09%09console.log('NEW PROPSS!!!!')%0A%09%09this.props.getMetadata().then(response =%3E this.setState(%7B%0A%09%09%09metadata: response,%0A%09%09%09schema: parseSchema(response)%0A%09%09%7D));%0A%09%09this.props.getData(%7Bmaster_object_id:nextProps.region.id%7D,null,%7B'cache-control':'no-cache'%7D).then(response =%3E this.setState(%7Bdata: response.objects%7D));%0A%09%09this.forceUpdate()%0A%09%09%7D,%0A%09render() %7B%0A%0A%09%09var isLoaded = _.isArray(this.state.data) && this.state.metadata && this.state.schema && (!this.state.loading);%0A%09%09if(!isLoaded
+render() %7B%0A%0A%09%09var loading = this.props.loading%0A%09%09if(loading
 ) re
@@ -989,46 +989,16 @@
 ema,
- metadata%7D = this.state;%0A%0A%09%09var
  fields
+%7D
  = t
@@ -1010,139 +1010,9 @@
 rops
-.fields%0A%0A%09%09console.log('returning render of review page')%0A%09%09console.log(data.length)%0A%09%09console.log('tat was the len of the data..')
+;
 %0A%0A%09%09
@@ -1260,18 +1260,16 @@
 g'%3E 
-Review Pag
+BaseTabl
 e Lo
@@ -1314,16 +1314,15 @@
 s = 
-ReviewPag
+BaseTabl
 e;%0A

clean up base table class