diff --git a/client/src/components/Accounts/AccountsDataTable.js b/client/src/components/Accounts/AccountsDataTable.js index 4cd5097fd..7e51e2ec6 100644 --- a/client/src/components/Accounts/AccountsDataTable.js +++ b/client/src/components/Accounts/AccountsDataTable.js @@ -68,45 +68,6 @@ 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', @@ -197,7 +158,9 @@ function AccountsDataTable({ data={accounts} onFetchData={handleDatatableFetchData} manualSortBy={true} - selectionColumn={selectionColumn} /> + selectionColumn={selectionColumn} + expandable={true} + treeGraph={true} /> ); } diff --git a/client/src/components/DataTable.js b/client/src/components/DataTable.js index 9d45ee411..3e3f31e9e 100644 --- a/client/src/components/DataTable.js +++ b/client/src/components/DataTable.js @@ -12,7 +12,7 @@ import { import {Checkbox} from '@blueprintjs/core'; import classnames from 'classnames'; import { FixedSizeList } from 'react-window' -import Icon from 'components/Icon'; +import { ConditionalWrapper } from 'utils'; const IndeterminateCheckbox = React.forwardRef( ({ indeterminate, ...rest }, ref) => { @@ -38,6 +38,8 @@ export default function DataTable({ fixedSizeHeight = 100, fixedItemSize = 30, payload, + expandable = false, + expandToggleColumn = 2, }) { const { getTableProps, @@ -56,6 +58,8 @@ export default function DataTable({ setPageSize, selectedFlatRows, totalColumnsWidth, + getToggleAllRowsExpandedProps, + isAllRowsExpanded, // Get the state from the instance state: { pageIndex, pageSize, sortBy, selectedRowIds }, @@ -116,6 +120,32 @@ export default function DataTable({ onFetchData && onFetchData({ pageIndex, pageSize, sortBy }) }, [pageIndex, pageSize, sortBy]); + // Renders table cell. + const RenderCell = useCallback(({ row, cell, index }) => ( + (
{children}
)} + > + { + // Use the row.canExpand and row.getToggleRowExpandedProps prop getter + // to build the toggle for expanding a row + (row.canExpand && expandable && index === expandToggleColumn) && ( + + + + ) + } + { cell.render('Cell') } +
+ ), [expandable, expandToggleColumn]); + // Renders table row. const RenderRow = useCallback(({ style = {}, row }) => { prepareRow(row); @@ -123,16 +153,18 @@ export default function DataTable({ return (
- {row.cells.map((cell) => { + {row.cells.map((cell, i) => { + const index = i + 1; return
{ cell.render('Cell') }
+ })}> + { RenderCell({ cell, row, index }) } +
})} ); - }, [prepareRow, rowClassNames]); + }, [prepareRow, rowClassNames, expandable, RenderCell, expandToggleColumn]); // Renders virtualize circle table rows. const RenderVirtualizedRows = useCallback(({ index, style }) => { @@ -144,6 +176,7 @@ export default function DataTable({ return page.map((row, index) => RenderRow({ row })); }, [RenderRow, page]); + // Renders fixed size tbody. const RenderTBody = useCallback(() => { return (virtualizedRows) ? ( ) : RenderPage(); - }, [fixedSizeHeight, rows, fixedItemSize, virtualizedRows, - RenderVirtualizedRows, RenderPage]) + }, [fixedSizeHeight, rows, fixedItemSize, virtualizedRows, RenderVirtualizedRows, RenderPage]); return ( -
+
{headerGroups.map(headerGroup => (
- {headerGroup.headers.map(column => ( + {headerGroup.headers.map((column, index) => (
+ {(expandable && (index + 1) === expandToggleColumn) && ( + + + )} +
{column.render('Header')} diff --git a/client/src/components/MenuItem.js b/client/src/components/MenuItem.js index 97921f8d2..5e9ef659f 100644 --- a/client/src/components/MenuItem.js +++ b/client/src/components/MenuItem.js @@ -122,7 +122,7 @@ export default class MenuItem extends AbstractPureComponent2 { constructor(props) { super(props); this.state = { - isCollapseActive: false, + isCollapseActive: this.props.callapseActive || false, }; } @@ -193,6 +193,13 @@ export default class MenuItem extends AbstractPureComponent2 { }; } + componentWillReceiveProps(nextProps){ + if(nextProps.callapseActive!==this.props.callapseActive){ + //Perform some operation + this.setState({ isCollapseActive: nextProps.callapseActive }); + } + } + maybeRenderLabel(labelElement) { const { label, labelClassName } = this.props; if (label == null && labelElement == null) { diff --git a/client/src/components/Sidebar/SidebarMenu.js b/client/src/components/Sidebar/SidebarMenu.js index 9d78bc8fb..260e2886f 100644 --- a/client/src/components/Sidebar/SidebarMenu.js +++ b/client/src/components/Sidebar/SidebarMenu.js @@ -1,22 +1,29 @@ import React, { useState } from 'react'; import {Menu, MenuDivider, Collapse} from "@blueprintjs/core"; -import {useHistory} from 'react-router-dom'; +import {useHistory, useLocation} from 'react-router-dom'; import sidebarMenuList from 'config/sidebarMenu'; import Icon from 'components/Icon'; import MenuItem from 'components/MenuItem'; +import classNames from 'classnames'; export default function SidebarMenu() { - let history = useHistory(); + const history = useHistory(); + const location = useLocation(); const menuItemsMapper = (list) => { return list.map((item, index) => { const children = Array.isArray(item.children) ? menuItemsMapper(item.children) : null; + const isActive = (item.href && item.href === location.pathname) || + (item.children && item.children.some((c) => c.href === location.pathname)); + const handleItemClick = () => { + if (item.href) { history.push(item.href); } + }; return ( (item.divider) ? - : + : } text={item.text} label={item.label} @@ -24,11 +31,9 @@ export default function SidebarMenu() { children={children} dropdownType={item.dropdownType || 'collapse'} caretIconSize={15} - onClick={() => { - if (item.href) { - history.push(item.href); - } - }} /> + onClick={handleItemClick} + callapseActive={!!isActive} + className={classNames({ 'is-active': isActive })} /> ); }); }; diff --git a/client/src/config/sidebarMenu.js b/client/src/config/sidebarMenu.js index e47ddb21d..a3a4ae156 100644 --- a/client/src/config/sidebarMenu.js +++ b/client/src/config/sidebarMenu.js @@ -129,6 +129,6 @@ export default [ }, { text: 'Auditing System', - href: '/dashboard/accounts' + href: '/dashboard/auditing/list' } ]; diff --git a/client/src/containers/Dashboard/Items/ItemsCategoryList.js b/client/src/containers/Dashboard/Items/ItemsCategoryList.js index 705495c81..b4161629c 100644 --- a/client/src/containers/Dashboard/Items/ItemsCategoryList.js +++ b/client/src/containers/Dashboard/Items/ItemsCategoryList.js @@ -15,7 +15,8 @@ const ItemCategoriesList = ({ changePageTitle, views, requestFetchItemCategories, - requestEditItemCategory + requestEditItemCategory, + requestDeleteItemCategory, }) => { const { id } = useParams(); const [deleteCategory, setDeleteCategory] = useState(false); @@ -40,7 +41,7 @@ const ItemCategoriesList = ({ }; const handelConfirmCategoryDelete = useCallback(() => { - requestEditItemCategory(deleteCategory.id).then(() => { + requestDeleteItemCategory(deleteCategory.id).then(() => { setDeleteCategory(false); AppToaster.show({ message: 'the_category_has_been_delete' diff --git a/client/src/style/components/data-table.scss b/client/src/style/components/data-table.scss index 4d9310a4f..f67b26e1d 100644 --- a/client/src/style/components/data-table.scss +++ b/client/src/style/components/data-table.scss @@ -144,40 +144,36 @@ } } - .tr .th.expander, - .tr .td.expander{ - padding: 0; - - .toggle{ + .tr .th, + .tr .td{ + .expand-toggle{ cursor: pointer; - display: block; - padding: 14px 8px; + display: inline-block; + padding: 0 8px 0 0; padding-left: 0; + margin: auto 0; margin-left: 4px; + + .arrow-right{ + width: 0; + height: 0; + border-top: 5px solid transparent; + border-bottom: 5px solid transparent; + border-left: 8px solid #acacac; + display: block; + } + + .arrow-down{ + width: 0; + height: 0; + border-left: 5px solid transparent; + border-right: 5px solid transparent; + border-top: 8px solid #acacac; + display: block; + } } - .arrow-right{ - width: 0; - height: 0; - border-top: 5px solid transparent; - border-bottom: 5px solid transparent; - border-left: 8px solid #acacac; - display: block; - } - - .arrow-down{ - width: 0; - height: 0; - border-left: 5px solid transparent; - border-right: 5px solid transparent; - border-top: 8px solid #acacac; - display: block; - } - - + .td, - + .th{ - padding-left: 0; - } + } } @@ -202,14 +198,16 @@ &--financial-report{ - .thead{ - .tr .th{ - background: transparent; - border-top: 1px solid #666; - border-bottom: 1px solid #666; - - padding: 10px 0.4rem; - color: #222; + .table { + .thead{ + .tr .th{ + background: transparent; + border-top: 1px solid #666; + border-bottom: 1px solid #666; + + padding: 10px 0.4rem; + color: #222; + } } } } diff --git a/client/src/style/views/Sidebar.scss b/client/src/style/views/Sidebar.scss index f5cee8be0..974829987 100644 --- a/client/src/style/views/Sidebar.scss +++ b/client/src/style/views/Sidebar.scss @@ -52,9 +52,10 @@ $sidebar-popover-submenu-bg: rgb(1, 20, 62); font-size: 15px; font-weight: 400; - &:hover{ + &:hover, + &.bp3-active{ background: #012470; - color: #b2bbd0; + color: #c1c9dd; } &:focus, &:active{ @@ -89,7 +90,8 @@ $sidebar-popover-submenu-bg: rgb(1, 20, 62); font-size: 15px; color: #8a95b6; - &:hover{ + &:hover, + &.bp3-active{ background: transparent; color: #C5CBE3; } diff --git a/client/src/utils.js b/client/src/utils.js index 2aac703cb..a1f2074ea 100644 --- a/client/src/utils.js +++ b/client/src/utils.js @@ -136,10 +136,12 @@ export const defaultExpanderReducer = (tableRows, level) => { return expended; } - export function formattedAmount(cents, currency) { const { symbol, decimal_digits: precision } = Currency[currency]; const amount = cents / Math.pow(10, precision); return accounting.formatMoney(amount, { symbol, precision }); -} \ No newline at end of file +} + +export const ConditionalWrapper = ({ condition, wrapper, children }) => + condition ? wrapper(children) : children; \ No newline at end of file