feat: Optimize connect component props with redux store.

This commit is contained in:
Ahmed Bouhuolia
2020-05-10 02:14:42 +02:00
parent e590a21740
commit a0653674ff
58 changed files with 660 additions and 460 deletions

View File

@@ -1,18 +1,25 @@
import React, {useState, useMemo, useCallback} from 'react';
import React, { useMemo, useCallback } from 'react';
import { connect } from 'react-redux';
import FinancialSheet from 'components/FinancialSheet';
import DataTable from 'components/DataTable';
import Money from 'components/Money';
import ProfitLossSheetConnect from 'connectors/ProfitLossSheet.connect';
import ProfitLossSheetTableConnect from 'connectors/ProfitLossTable.connect';
import { compose, defaultExpanderReducer } from 'utils';
import {
getFinancialSheetIndexByQuery,
} from 'store/financialStatement/financialStatements.selectors';
import withProfitLossDetail from './withProfitLoss';
function ProfitLossSheetTable({
loading,
onFetchData,
// #withProfitLoss
profitLossTableRows,
profitLossQuery,
profitLossColumns,
// #ownProps
loading,
onFetchData,
companyName,
}) {
const columns = useMemo(() => [
@@ -132,7 +139,20 @@ function ProfitLossSheetTable({
);
}
const mapStateToProps = (state, props) => ({
profitLossIndex: getFinancialSheetIndexByQuery(
state.financialStatements.profitLoss.sheets,
props.profitLossQuery,
),
});
const withProfitLossTable = connect(mapStateToProps);
export default compose(
ProfitLossSheetConnect,
ProfitLossSheetTableConnect,
withProfitLossTable,
withProfitLossDetail(({ profitLossQuery, profitLossColumns, profitLossTableRows }) => ({
profitLossColumns,
profitLossQuery,
profitLossTableRows,
})),
)(ProfitLossSheetTable);