<commit_before>/* eslint-disable react/forbid-prop-types */
/**
 * mSupply Mobile
 * Sustainable Solutions (NZ) Ltd. 2018
 */

import React, { useState } from 'react';
import { View, StyleSheet } from 'react-native';

import { ReportSideBar } from '../widgets/ReportSideBar';
import { ReportChart } from '../widgets/ReportChart';

import { UIDatabase } from '../database/index';

import globalStyles from '../globalStyles';

export const DashboardPage = () => {
  const [reports] = useState(UIDatabase.objects('Report'));
  const [selectedItemIndex, setSelectedItemIndex] = useState(0);

  const onPressItem = id => {
    if (selectedItemIndex === id) return;
    setSelectedItemIndex(id);
  };

  const { pageContentContainer, container, pageTopSectionContainer } = globalStyles;
  const pageContainer = StyleSheet.flatten([pageTopSectionContainer, { paddingHorizontal: 0 }]);

  if (!reports) return null;
  const report = reports ? reports[selectedItemIndex] : null;
  return (
    <View style={pageContentContainer}>
      <View style={container}>
        <View style={pageContainer}>
          <ReportSideBar
            data={reports}
            onPressItem={onPressItem}
            selectedItemIndex={selectedItemIndex}
            dimensions={localStyles.sidebarDimensions}
          />
          <ReportChart report={report} />
        </View>
      </View>
    </View>
  );
};

const localStyles = StyleSheet.create({
  sidebarDimensions: {
    width: '25%',
    height: '100%',
  },
});
<commit_msg>Add adjustments to DashboardPage to use DashboardReducer<commit_after>/* eslint-disable react/require-default-props */
/* eslint-disable react/forbid-prop-types */
/**
 * mSupply Mobile
 * Sustainable Solutions (NZ) Ltd. 2018
 */

import React from 'react';
import { View, StyleSheet } from 'react-native';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';

import { ReportSideBar } from '../widgets/ReportSideBar';
import { ReportChart } from '../widgets/ReportChart';

import globalStyles from '../globalStyles';
import { DashboardActions } from '../actions/index';

const DashboardPageComponent = ({ reports, currentReport, switchReport }) => {
  const { pageContentContainer, container, pageTopSectionContainer } = globalStyles;
  const pageContainer = StyleSheet.flatten([pageTopSectionContainer, { paddingHorizontal: 0 }]);

  return (
    <View style={pageContentContainer}>
      <View style={container}>
        <View style={pageContainer}>
          <ReportSideBar
            reports={reports}
            onPressItem={switchReport}
            currentReport={currentReport}
            dimensions={localStyles.sidebarDimensions}
          />
          <ReportChart report={currentReport} />
        </View>
      </View>
    </View>
  );
};

const localStyles = StyleSheet.create({
  sidebarDimensions: {
    width: '25%',
    height: '100%',
  },
});

const mapStateToProps = state => {
  const { dashboard } = state;
  const { reports, currentReport } = dashboard;
  return { reports, currentReport };
};

const mapDispatchToProps = dispatch => {
  const switchReport = report => dispatch(DashboardActions.switchReport(report));
  return { dispatch, switchReport };
};

DashboardPageComponent.defaultProps = {
  currentReport: null,
};

DashboardPageComponent.propTypes = {
  reports: PropTypes.oneOfType([PropTypes.array, PropTypes.object]).isRequired,
  currentReport: PropTypes.object,
  switchReport: PropTypes.func.isRequired,
};

export const DashboardPage = connect(mapStateToProps, mapDispatchToProps)(DashboardPageComponent);

{'fraction_non_alphanumeric': 0.12855549358616844, 'fraction_numerical': 0.005856107083100948, 'mean_word_length': 3.7572944297082227, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, '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': '5294502', 'n_tokens_mistral': 1012, 'n_tokens_neox': 999, 'n_words': 228}