From 4d4191dfc0584aaa2ca5a5924c3cbcf281b5a706 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 12 Apr 2020 17:13:34 +0200 Subject: [PATCH] feat: optimize chart of accounts. --- .../components/Accounts/AccountsDataTable.js | 92 +++++++++++++++---- client/src/components/DataTable.js | 2 + .../src/components/Items/ItemsCategoryList.js | 6 +- .../JournalEntry/ManualJournalActionsBar.js | 22 +++-- .../JournalEntry/ManualJournalsDataTable.js | 1 + .../JournalEntry/ManualJournalsViewTabs.js | 1 + .../Dashboard/Accounts/AccountsChart.js | 17 +++- client/src/static/json/icons.js | 6 +- client/src/style/App.scss | 8 ++ client/src/style/components/data-table.scss | 18 +++- client/src/style/objects/typography.scss | 2 +- client/src/style/pages/accounts-chart.scss | 36 +++++++- .../src/style/pages/financial-statements.scss | 2 +- server/src/http/controllers/Accounts.js | 1 + 14 files changed, 178 insertions(+), 36 deletions(-) diff --git a/client/src/components/Accounts/AccountsDataTable.js b/client/src/components/Accounts/AccountsDataTable.js index 9b7ff3a07..6afe6fdba 100644 --- a/client/src/components/Accounts/AccountsDataTable.js +++ b/client/src/components/Accounts/AccountsDataTable.js @@ -6,6 +6,8 @@ import { MenuItem, MenuDivider, Position, + Classes, + Tooltip, } from '@blueprintjs/core'; import { useParams } from 'react-router-dom'; import Icon from 'components/Icon'; @@ -16,6 +18,7 @@ import DashboardConnect from 'connectors/Dashboard.connector'; import ViewConnect from 'connectors/View.connector'; import LoadingIndicator from 'components/LoadingIndicator'; import DataTable from 'components/DataTable'; +import Money from 'components/Money'; function AccountsDataTable({ accounts, @@ -45,9 +48,10 @@ function AccountsDataTable({ // Clear page subtitle when unmount the page. useEffect(() => () => { changePageSubtitle(''); }, []); - const handleEditAccount = account => () => { + const handleEditAccount = useCallback((account) => () => { openDialog('account-form', { action: 'edit', id: account.id }); - }; + }, [openDialog]); + const actionMenuList = account => ( @@ -64,20 +68,71 @@ function AccountsDataTable({ ); const columns = useMemo(() => [ + { + // Build our expander column + id: 'expander', // Make sure it has an ID + className: 'expander', + Header: ({ + getToggleAllRowsExpandedProps, + isAllRowsExpanded + }) => ( + + {isAllRowsExpanded ? + () : + () + } + + ), + Cell: ({ row }) => + // Use the row.canExpand and row.getToggleRowExpandedProps prop getter + // to build the toggle for expanding a row + row.canExpand ? ( + + {row.isExpanded ? + () : + () + } + + ) : null, + width: 20, + disableResizing: true, + }, { id: 'name', Header: 'Account Name', - accessor: 'name', + accessor: row => { + return (row.description) ? + ( + { row.name } + ) : row.name; + }, + className: 'account_name', }, { id: 'code', Header: 'Code', - accessor: 'code' + accessor: 'code', + className: 'code', }, { id: 'type', Header: 'Type', - accessor: 'type.name' + accessor: 'type.name', + className: 'type', }, { id: 'normal', @@ -96,14 +151,14 @@ function AccountsDataTable({ Header: 'Balance', Cell: ({ cell }) => { const account = cell.row.original; - const {balance} = account; + const {balance = null} = account; - return ('undefined' !== typeof balance) ? - ({ balance.amount }) : - (--); + return (balance) ? + ( + + ) : + (--); }, - - // canResize: false, }, { id: 'actions', @@ -111,18 +166,23 @@ function AccountsDataTable({ Cell: ({ cell }) => ( + position={Position.RIGHT_TOP}>