From a0653674ff63699c21d958c3522eb0314d465e1a Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 10 May 2020 02:14:42 +0200 Subject: [PATCH] feat: Optimize connect component props with redux store. --- .../components/Preferences/PreferencesPage.js | 2 +- client/src/config/sidebarMenu.js | 1 + client/src/connectors/BalanceSheet.connect.js | 27 -------- .../connectors/BalanceSheetTable.connect.js | 27 -------- .../FinancialStatements.connector.js | 36 ----------- client/src/connectors/Journal.connect.js | 1 + .../src/connectors/ProfitLossSheet.connect.js | 27 -------- .../src/connectors/ProfitLossTable.connect.js | 17 ----- .../connectors/TrialBalanceSheet.connect.js | 1 + .../Accounting/MakeJournalEntriesForm.js | 5 +- .../Accounting/MakeJournalEntriesPage.js | 1 - .../Accounting/MakeJournalEntriesTable.js | 11 +++- .../Accounting/ManualJournalActionsBar.js | 25 ++++++-- .../Accounting/ManualJournalsDataTable.js | 5 +- .../Accounting/ManualJournalsList.js | 7 ++- .../Accounting/ManualJournalsViewTabs.js | 30 ++++++--- .../Accounting/withManualJournals.js | 24 ++++--- .../containers/Accounts/AccountsActionsBar.js | 11 +++- .../src/containers/Accounts/AccountsChart.js | 8 ++- .../containers/Accounts/AccountsDataTable.js | 13 ++-- .../containers/Accounts/AccountsViewsTabs.js | 7 ++- .../src/containers/Accounts/withAccounts.js | 26 +++++--- .../Dialogs/AccountFormDialog.container.js | 5 +- .../containers/Dialogs/ItemCategoryDialog.js | 53 ++++++++++------ .../BalanceSheet/BalanceSheet.js | 58 +++++++++-------- .../BalanceSheet/BalanceSheetTable.js | 48 ++++++++++---- .../BalanceSheet/withBalanceSheetActions.js | 10 +++ .../BalanceSheet/withBalanceSheetDetail.js | 24 +++++++ .../GeneralLedger/withGeneralLedger.js | 0 .../GeneralLedger/withGeneralLedgerActions.js | 0 .../FinancialStatements/Journal/Journal.js | 63 +++++++++---------- .../Journal/JournalHeader.js | 4 +- .../Journal/JournalTable.js | 44 +++++++++---- .../Journal/withJournal.js | 21 +++++++ .../Journal/withJournalActions.js | 10 +++ .../ProfitLossSheet/ProfitLossActionsBar.js | 5 -- .../ProfitLossSheet/ProfitLossSheet.js | 54 +++++++++------- .../ProfitLossSheet/ProfitLossSheetTable.js | 34 +++++++--- .../ProfitLossSheet/withProfitLoss.js | 26 ++++++++ .../ProfitLossSheet/withProfitLossActions.js | 10 +++ .../TrialBalanceSheet/TrialBalanceSheet.js | 56 ++++++++--------- .../TrialBalanceSheetHeader.js | 20 ++---- .../TrialBalanceSheetTable.js | 42 ++++++++++--- .../TrialBalanceSheet/withTrialBalance.js | 21 +++++++ .../withTrialBalanceActions.js | 10 +++ .../containers/Items/ItemCategoriesList.js | 22 ++++--- .../containers/Items/ItemCategoriesTable.js | 24 ++++--- .../src/containers/Items/ItemsActionsBar.js | 9 ++- .../Items/ItemsCategoryActionsBar.js | 12 +++- client/src/containers/Items/ItemsDataTable.js | 7 ++- client/src/containers/Items/ItemsList.js | 19 +++--- client/src/containers/Items/ItemsViewsTabs.js | 5 ++ .../containers/Items/withItemCategories.js | 18 +++--- client/src/containers/Items/withItems.js | 32 +++++----- .../Resources/withResourceDetails.js | 23 ++++--- .../containers/Views/ViewForm.container.js | 9 +-- client/src/containers/Views/ViewForm.js | 1 - client/src/containers/Views/ViewFormPage.js | 9 ++- 58 files changed, 660 insertions(+), 460 deletions(-) delete mode 100644 client/src/connectors/BalanceSheet.connect.js delete mode 100644 client/src/connectors/BalanceSheetTable.connect.js delete mode 100644 client/src/connectors/FinancialStatements.connector.js delete mode 100644 client/src/connectors/ProfitLossSheet.connect.js delete mode 100644 client/src/connectors/ProfitLossTable.connect.js create mode 100644 client/src/containers/FinancialStatements/BalanceSheet/withBalanceSheetActions.js create mode 100644 client/src/containers/FinancialStatements/BalanceSheet/withBalanceSheetDetail.js create mode 100644 client/src/containers/FinancialStatements/GeneralLedger/withGeneralLedger.js create mode 100644 client/src/containers/FinancialStatements/GeneralLedger/withGeneralLedgerActions.js create mode 100644 client/src/containers/FinancialStatements/Journal/withJournal.js create mode 100644 client/src/containers/FinancialStatements/Journal/withJournalActions.js create mode 100644 client/src/containers/FinancialStatements/ProfitLossSheet/withProfitLoss.js create mode 100644 client/src/containers/FinancialStatements/ProfitLossSheet/withProfitLossActions.js create mode 100644 client/src/containers/FinancialStatements/TrialBalanceSheet/withTrialBalance.js create mode 100644 client/src/containers/FinancialStatements/TrialBalanceSheet/withTrialBalanceActions.js diff --git a/client/src/components/Preferences/PreferencesPage.js b/client/src/components/Preferences/PreferencesPage.js index e592dc5dd..4689231c6 100644 --- a/client/src/components/Preferences/PreferencesPage.js +++ b/client/src/components/Preferences/PreferencesPage.js @@ -6,5 +6,5 @@ export default function PreferencesPage() {
- ) + ); } \ No newline at end of file diff --git a/client/src/config/sidebarMenu.js b/client/src/config/sidebarMenu.js index a86301ddb..f1eb8028a 100644 --- a/client/src/config/sidebarMenu.js +++ b/client/src/config/sidebarMenu.js @@ -1,3 +1,4 @@ + export default [ { divider: true diff --git a/client/src/connectors/BalanceSheet.connect.js b/client/src/connectors/BalanceSheet.connect.js deleted file mode 100644 index 15b0fa2cb..000000000 --- a/client/src/connectors/BalanceSheet.connect.js +++ /dev/null @@ -1,27 +0,0 @@ -import {connect} from 'react-redux'; -import { - fetchBalanceSheet, -} from 'store/financialStatement/financialStatements.actions'; -import { - getFinancialSheetIndexByQuery, - getFinancialSheet, - getFinancialSheetAccounts, - getFinancialSheetColumns, - getFinancialSheetQuery, -} from 'store/financialStatement/financialStatements.selectors'; - - -export const mapStateToProps = (state, props) => ({ - getBalanceSheetIndex: (query) => getFinancialSheetIndexByQuery(state.financialStatements.balanceSheet.sheets, query), - getBalanceSheet: (index) => getFinancialSheet(state.financialStatements.balanceSheet.sheets, index), - getBalanceSheetAccounts: (index) => getFinancialSheetAccounts(state.financialStatements.balanceSheet.sheets, index), - getBalanceSheetColumns:(index) => getFinancialSheetColumns(state.financialStatements.balanceSheet.sheets, index), - getBalanceSheetQuery: (index) => getFinancialSheetQuery(state.financialStatements.balanceSheet.sheets, index), - balanceSheetLoading: state.financialStatements.balanceSheet.loading, -}); - -export const mapDispatchToProps = (dispatch) => ({ - fetchBalanceSheet: (query = {}) => dispatch(fetchBalanceSheet({ query })), -}); - -export default connect(mapStateToProps, mapDispatchToProps); \ No newline at end of file diff --git a/client/src/connectors/BalanceSheetTable.connect.js b/client/src/connectors/BalanceSheetTable.connect.js deleted file mode 100644 index 58d8d52d1..000000000 --- a/client/src/connectors/BalanceSheetTable.connect.js +++ /dev/null @@ -1,27 +0,0 @@ -import {connect} from 'react-redux'; -import { - fetchBalanceSheet, -} from 'store/financialStatement/financialStatements.actions'; -import { - getFinancialSheetIndexByQuery, - getFinancialSheet, - getFinancialSheetsAccounts, - getFinancialSheetsColumns, -} from 'store/financialStatement/financialStatements.selectors'; - - -export const mapStateToProps = (state, props) => { - const sheetIndex = props.balanceSheetIndex; - - return { - balanceSheetAccounts: props.getBalanceSheetAccounts(sheetIndex), - balanceSheetQuery: props.getBalanceSheetQuery(sheetIndex), - balanceSheetColumns: props.getBalanceSheetColumns(sheetIndex), - }; -}; - -export const mapDispatchToProps = (dispatch) => ({ - -}); - -export default connect(mapStateToProps, mapDispatchToProps); \ No newline at end of file diff --git a/client/src/connectors/FinancialStatements.connector.js b/client/src/connectors/FinancialStatements.connector.js deleted file mode 100644 index 1791e25de..000000000 --- a/client/src/connectors/FinancialStatements.connector.js +++ /dev/null @@ -1,36 +0,0 @@ -import {connect} from 'react-redux'; -import { - fetchGeneralLedger, - fetchBalanceSheet, -} from 'store/financialStatement/financialStatements.actions'; -import { - getBalanceSheetByQuery, - getBalanceSheetColumns, - getBalanceSheetIndexByQuery, - getBalanceSheetByIndex, - getBalanceSheetAssetsAccounts, - getBalanceSheetLiabilitiesAccounts, - getBalanceSheetQuery, -} from 'store/financialStatement/financialStatements.selectors'; - -export const mapStateToProps = (state, props) => ({ - generalLedeger: state.financialStatements.generalLedger, - balanceSheets: state.financialStatements.balanceSheets, - - getBalanceSheetByQuery: (query) => getBalanceSheetByQuery(state.financialStatements.balanceSheets, query), - getBalanceSheetColumns: (sheetIndex) => getBalanceSheetColumns(state.financialStatements.balanceSheets, sheetIndex), - getBalanceSheetIndexByQuery: (query) => getBalanceSheetIndexByQuery(state.financialStatements.balanceSheets, query), - getBalanceSheetByIndex: (sheetIndex) => getBalanceSheetByIndex(state.financialStatements.balanceSheets, sheetIndex), - - getBalanceSheetAssetsAccounts: (sheetIndex) => getBalanceSheetAssetsAccounts(state.financialStatements.balanceSheets, sheetIndex), - getBalanceSheetLiabilitiesAccounts: (sheetIndex) => getBalanceSheetLiabilitiesAccounts(state.financialStatements.balanceSheets, sheetIndex), - - getBalanceSheetQuery: (sheetIndex) => getBalanceSheetQuery(state.financialStatements.balanceSheets, sheetIndex), -}); - -export const mapDispatchToProps = (dispatch) => ({ - fetchGeneralLedger: (query = {}) => dispatch(fetchGeneralLedger({ query })), - fetchBalanceSheet: (query = {}) => dispatch(fetchBalanceSheet({ query })), -}); - -export default connect(mapStateToProps, mapDispatchToProps); \ No newline at end of file diff --git a/client/src/connectors/Journal.connect.js b/client/src/connectors/Journal.connect.js index f01815379..96325e56c 100644 --- a/client/src/connectors/Journal.connect.js +++ b/client/src/connectors/Journal.connect.js @@ -7,6 +7,7 @@ import { getFinancialSheet, } from 'store/financialStatement/financialStatements.selectors'; + export const mapStateToProps = (state, props) => ({ getJournalSheetIndex: (query) => getFinancialSheetIndexByQuery(state.financialStatements.journal.sheets, query), getJournalSheet: (index) => getFinancialSheet(state.financialStatements.journal.sheets, index), diff --git a/client/src/connectors/ProfitLossSheet.connect.js b/client/src/connectors/ProfitLossSheet.connect.js deleted file mode 100644 index e7ad67afd..000000000 --- a/client/src/connectors/ProfitLossSheet.connect.js +++ /dev/null @@ -1,27 +0,0 @@ -import {connect} from 'react-redux'; -import { - fetchProfitLossSheet, -} from 'store/financialStatement/financialStatements.actions'; -import { - getFinancialSheetIndexByQuery, - getFinancialSheet, - getFinancialSheetColumns, - getFinancialSheetQuery, - getFinancialSheetTableRows, -} from 'store/financialStatement/financialStatements.selectors'; - -export const mapStateToProps = (state, props) => ({ - getProfitLossSheetIndex: (query) => getFinancialSheetIndexByQuery(state.financialStatements.profitLoss.sheets, query), - getProfitLossSheet: (index) => getFinancialSheet(state.financialStatements.profitLoss.sheets, index), - getProfitLossColumns: (index) => getFinancialSheetColumns(state.financialStatements.profitLoss.sheets, index), - getProfitLossQuery: (index) => getFinancialSheetQuery(state.financialStatements.profitLoss.sheets, index), - getProfitLossTableRows: (index) => getFinancialSheetTableRows(state.financialStatements.profitLoss.sheets, index), - - profitLossSheetLoading: state.financialStatements.profitLoss.loading, -}); - -export const mapDispatchToProps = (dispatch) => ({ - fetchProfitLossSheet: (query = {}) => dispatch(fetchProfitLossSheet({ query })), -}); - -export default connect(mapStateToProps, mapDispatchToProps); \ No newline at end of file diff --git a/client/src/connectors/ProfitLossTable.connect.js b/client/src/connectors/ProfitLossTable.connect.js deleted file mode 100644 index 02970c30c..000000000 --- a/client/src/connectors/ProfitLossTable.connect.js +++ /dev/null @@ -1,17 +0,0 @@ -import {connect} from 'react-redux'; - -export const mapStateToProps = (state, props) => { - const sheetIndex = props.profitLossSheetIndex; - - return { - profitLossTableRows: props.getProfitLossTableRows(sheetIndex), - profitLossColumns: props.getProfitLossColumns(sheetIndex), - profitLossQuery: props.getProfitLossQuery(sheetIndex), - }; -}; - -export const mapDispatchToProps = (dispatch) => ({ - -}); - -export default connect(mapStateToProps, mapDispatchToProps); \ No newline at end of file diff --git a/client/src/connectors/TrialBalanceSheet.connect.js b/client/src/connectors/TrialBalanceSheet.connect.js index 01a63e9f2..a37049ad6 100644 --- a/client/src/connectors/TrialBalanceSheet.connect.js +++ b/client/src/connectors/TrialBalanceSheet.connect.js @@ -8,6 +8,7 @@ import { getFinancialSheetQuery, } from 'store/financialStatement/financialStatements.selectors'; + export const mapStateToProps = (state, props) => ({ getTrialBalanceSheetIndex: (query) => getFinancialSheetIndexByQuery(state.financialStatements.trialBalance.sheets, query), getTrialBalanceAccounts: (sheetIndex) => getFinancialSheetAccounts(state.financialStatements.trialBalance.sheets, sheetIndex), diff --git a/client/src/containers/Accounting/MakeJournalEntriesForm.js b/client/src/containers/Accounting/MakeJournalEntriesForm.js index 94af85555..f477132a3 100644 --- a/client/src/containers/Accounting/MakeJournalEntriesForm.js +++ b/client/src/containers/Accounting/MakeJournalEntriesForm.js @@ -23,12 +23,15 @@ import {compose} from 'utils'; function MakeJournalEntriesForm({ + // #withMedia requestSubmitMedia, requestDeleteMedia, + // #withJournalsActions requestMakeJournalEntries, requestEditManualJournal, + // #withDashboard changePageTitle, changePageSubtitle, @@ -252,8 +255,6 @@ function MakeJournalEntriesForm({ } export default compose( - // ManualJournalsConnect, - // MakeJournalEntriesConnect, withJournalsActions, withManualJournalDetail, withAccountsActions, diff --git a/client/src/containers/Accounting/MakeJournalEntriesPage.js b/client/src/containers/Accounting/MakeJournalEntriesPage.js index df46bc486..81edda382 100644 --- a/client/src/containers/Accounting/MakeJournalEntriesPage.js +++ b/client/src/containers/Accounting/MakeJournalEntriesPage.js @@ -46,7 +46,6 @@ function MakeJournalEntriesPage({ } export default compose( - // DashboardConnect, withAccountsActions, withManualJournalsActions, )(MakeJournalEntriesPage); \ No newline at end of file diff --git a/client/src/containers/Accounting/MakeJournalEntriesTable.js b/client/src/containers/Accounting/MakeJournalEntriesTable.js index d0d3dcc56..54ec3cd48 100644 --- a/client/src/containers/Accounting/MakeJournalEntriesTable.js +++ b/client/src/containers/Accounting/MakeJournalEntriesTable.js @@ -76,13 +76,16 @@ const NoteCellRenderer = (chainedComponent) => (props) => { /** * Make journal entries table component. */ -function MakeJournalEntriesTable({ - formik: { errors, values, setFieldValue }, +function MakeJournalEntriesTable({ + // #withAccounts accounts, + + // #ownPorps onClickRemoveRow, onClickAddNewRow, defaultRow, initialValues, + formik: { errors, values, setFieldValue }, }) { const [rows, setRow] = useState([]); @@ -226,5 +229,7 @@ function MakeJournalEntriesTable({ } export default compose( - withAccounts, + withAccounts(({ accounts }) => ({ + accounts, + })), )(MakeJournalEntriesTable); \ No newline at end of file diff --git a/client/src/containers/Accounting/ManualJournalActionsBar.js b/client/src/containers/Accounting/ManualJournalActionsBar.js index 1c52c0c2b..43fe4a648 100644 --- a/client/src/containers/Accounting/ManualJournalActionsBar.js +++ b/client/src/containers/Accounting/ManualJournalActionsBar.js @@ -14,10 +14,12 @@ import { } from '@blueprintjs/core'; import classNames from 'classnames'; import { useRouteMatch, useHistory } from 'react-router-dom'; +import { compose } from 'utils'; + +import FilterDropdown from 'components/FilterDropdown'; import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar'; import DialogConnect from 'connectors/Dialog.connector'; -import { compose } from 'utils'; -import FilterDropdown from 'components/FilterDropdown'; +import { If } from 'components'; import withResourceDetail from 'containers/Resources/withResourceDetails'; import withManualJournals from 'containers/Accounting/withManualJournals'; @@ -25,10 +27,14 @@ import withManualJournalsActions from 'containers/Accounting/withManualJournalsA function ManualJournalActionsBar({ + // #withResourceDetail resourceName = 'manual_journal', resourceFields, + // #withManualJournals manualJournalsViews, + + // #withManualJournalsActions addManualJournalsTableQueries, onFilterChanged, @@ -80,7 +86,9 @@ function ManualJournalActionsBar({ rightIcon={'caret-down'} /> + +