BC-12 feat: table rows and cells clickable.

This commit is contained in:
a.bouhuolia
2021-09-04 20:12:09 +02:00
parent 11df54d4ed
commit 6b5c26924d
5 changed files with 28 additions and 13 deletions

View File

@@ -4,16 +4,14 @@ import { If } from 'components';
import { Skeleton } from 'components'; import { Skeleton } from 'components';
import { useAppIntlContext } from 'components/AppIntlProvider'; import { useAppIntlContext } from 'components/AppIntlProvider';
import TableContext from './TableContext'; import TableContext from './TableContext';
import { saveInvoke } from 'utils';
import { isCellLoading } from './utils'; import { isCellLoading } from './utils';
/** /**
* Table cell. * Table cell.
*/ */
export default function TableCell({ export default function TableCell({ cell, row, index }) {
cell, const { index: rowIndex, depth, getToggleRowExpandedProps, isExpanded } = row;
row: { index: rowIndex, depth, getToggleRowExpandedProps, isExpanded },
index,
}) {
const { const {
props: { props: {
expandToggleColumn, expandToggleColumn,
@@ -21,6 +19,7 @@ export default function TableCell({
expandable, expandable,
cellsLoading, cellsLoading,
cellsLoadingCoords, cellsLoadingCoords,
onCellClick,
}, },
} = useContext(TableContext); } = useContext(TableContext);
@@ -49,13 +48,19 @@ export default function TableCell({
</div> </div>
); );
} }
// Handle cell click action.
const handleCellClick = (event) => {
saveInvoke(onCellClick, cell, event);
};
return ( return (
<div <div
{...cell.getCellProps({ {...cell.getCellProps({
className: classNames(cell.column.className, 'td', { className: classNames(cell.column.className, 'td', {
'is-text-overview': cell.column.textOverview, 'is-text-overview': cell.column.textOverview,
'clickable': cell.column.clickable,
}), }),
onClick: handleCellClick,
})} })}
> >
<div <div

View File

@@ -76,6 +76,10 @@ function AccountsDataTable({
accountType: account.account_type, accountType: account.account_type,
}); });
}; };
// Handle cell click.
const handleCellClick = (cell, event) => {
openDrawer('account-drawer', { accountId: cell.row.original.id });
};
return ( return (
<DataTable <DataTable
@@ -103,6 +107,7 @@ function AccountsDataTable({
// #TableVirtualizedListRows props. // #TableVirtualizedListRows props.
vListrowHeight={42} vListrowHeight={42}
vListOverscanRowCount={0} vListOverscanRowCount={0}
onCellClick={handleCellClick}
payload={{ payload={{
onEdit: handleEditAccount, onEdit: handleEditAccount,
onDelete: handleDeleteAccount, onDelete: handleDeleteAccount,

View File

@@ -56,6 +56,7 @@ export const useAccountsTableColumns = () => {
accessor: 'name', accessor: 'name',
className: 'account_name', className: 'account_name',
width: 200, width: 200,
clickable: true,
}, },
{ {
id: 'code', id: 'code',
@@ -63,6 +64,7 @@ export const useAccountsTableColumns = () => {
accessor: AccountCodeAccessor, accessor: AccountCodeAccessor,
className: 'code', className: 'code',
width: 80, width: 80,
clickable: true,
}, },
{ {
id: 'type', id: 'type',
@@ -70,6 +72,7 @@ export const useAccountsTableColumns = () => {
accessor: 'account_type_label', accessor: 'account_type_label',
className: 'type', className: 'type',
width: 140, width: 140,
clickable: true,
}, },
{ {
id: 'normal', id: 'normal',
@@ -78,12 +81,14 @@ export const useAccountsTableColumns = () => {
accessor: 'account_normal', accessor: 'account_normal',
className: 'normal', className: 'normal',
width: 80, width: 80,
clickable: true,
}, },
{ {
id: 'currency', id: 'currency',
Header: intl.get('currency'), Header: intl.get('currency'),
accessor: 'currency_code', accessor: 'currency_code',
width: 75, width: 75,
clickable: true,
}, },
{ {
id: 'balance', id: 'balance',
@@ -91,6 +96,7 @@ export const useAccountsTableColumns = () => {
accessor: 'amount', accessor: 'amount',
Cell: BalanceCell, Cell: BalanceCell,
width: 150, width: 150,
clickable: true,
}, },
], ],
[], [],

View File

@@ -51,7 +51,6 @@ function GeneralFormPage({
intent: Intent.SUCCESS, intent: Intent.SUCCESS,
}); });
setSubmitting(false); setSubmitting(false);
resetForm();
}; };
// Handle request error. // Handle request error.
const onError = (errors) => { const onError = (errors) => {

View File

@@ -73,6 +73,10 @@
display: flex; display: flex;
flex: 1 0 auto; flex: 1 0 auto;
} }
&:hover .td.clickable{
cursor: pointer;
}
} }
.th, .th,
@@ -108,10 +112,6 @@
z-index: 1; z-index: 1;
touch-action: none; touch-action: none;
&.isResizing {
// background: red;
}
.inner-resizer { .inner-resizer {
height: 100%; height: 100%;
width: 1px; width: 1px;
@@ -125,12 +125,12 @@
} }
.bp3-control.bp3-checkbox .bp3-control-indicator { .bp3-control.bp3-checkbox .bp3-control-indicator {
border: 2px solid #d7d7d7; border: 1px solid #c2c2c2;
&, &,
&:hover { &:hover {
height: 16px; height: 15px;
width: 16px; width: 15px;
} }
} }