feat: add memorized column.

This commit is contained in:
elforjani3
2021-09-15 16:28:02 +02:00
parent 871eb32963
commit b366ee7dfc
14 changed files with 148 additions and 38 deletions

View File

@@ -0,0 +1,15 @@
export const TABLES = {
ITEMS: 'items',
INVENTORY_ADJUSTMENTS: 'inventory_adjustment',
ESTIMATES: 'estimates',
INVOICES: 'invoices',
RECEIPTS: 'receipts',
PAYMENT_RECEIVES: 'payment_receives',
BILLS: 'bills',
PAYMENT_MADES: 'payment_mades',
CUSTOMER: 'customers',
VENDORS: 'vendors',
ACCOUNTS: 'accounts',
MANUAL_JOURNALS: 'manual_journal',
EXPENSES: 'expenses',
};

View File

@@ -2,6 +2,7 @@ import React from 'react';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { DataTable, DashboardContentTable } from 'components'; import { DataTable, DashboardContentTable } from 'components';
import { TABLES } from 'common/tables';
import ManualJournalsEmptyStatus from './ManualJournalsEmptyStatus'; import ManualJournalsEmptyStatus from './ManualJournalsEmptyStatus';
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
@@ -15,6 +16,7 @@ import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { useManualJournalsContext } from './ManualJournalsListProvider'; import { useManualJournalsContext } from './ManualJournalsListProvider';
import { useManualJournalsColumns } from './utils'; import { useManualJournalsColumns } from './utils';
import { ActionsMenu } from './components'; import { ActionsMenu } from './components';
import { useMemorizedColumnsWidths } from 'hooks';
import { compose } from 'utils'; import { compose } from 'utils';
@@ -78,6 +80,10 @@ function ManualJournalsDataTable({
openDrawer('journal-drawer', { manualJournalId: cell.row.original.id }); openDrawer('journal-drawer', { manualJournalId: cell.row.original.id });
}; };
// Local storage memorizing columns widths.
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.MANUAL_JOURNALS);
// Handle fetch data once the page index, size or sort by of the table change. // Handle fetch data once the page index, size or sort by of the table change.
const handleFetchData = React.useCallback( const handleFetchData = React.useCallback(
({ pageSize, pageIndex, sortBy }) => { ({ pageSize, pageIndex, sortBy }) => {
@@ -101,7 +107,6 @@ function ManualJournalsDataTable({
noInitialFetch={true} noInitialFetch={true}
columns={columns} columns={columns}
data={manualJournals} data={manualJournals}
initialState={manualJournalsTableState}
manualSortBy={true} manualSortBy={true}
selectionColumn={true} selectionColumn={true}
expandable={true} expandable={true}
@@ -118,6 +123,8 @@ function ManualJournalsDataTable({
ContextMenu={ActionsMenu} ContextMenu={ActionsMenu}
onFetchData={handleFetchData} onFetchData={handleFetchData}
onCellClick={handleCellClick} onCellClick={handleCellClick}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
payload={{ payload={{
onDelete: handleDeleteJournal, onDelete: handleDeleteJournal,
onPublish: handlePublishJournal, onPublish: handlePublishJournal,

View File

@@ -5,6 +5,7 @@ import { compose } from 'utils';
import { useAccountsTableColumns, rowClassNames } from './utils'; import { useAccountsTableColumns, rowClassNames } from './utils';
import { ActionsMenu } from './components'; import { ActionsMenu } from './components';
import { TABLES } from 'common/tables';
import TableVirtualizedListRows from 'components/Datatable/TableVirtualizedRows'; import TableVirtualizedListRows from 'components/Datatable/TableVirtualizedRows';
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
@@ -81,7 +82,7 @@ function AccountsDataTable({
}; };
// Local storage memorizing columns widths. // Local storage memorizing columns widths.
const [initialColumnsWidths, , handleColumnResizing] = const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths('accounts'); useMemorizedColumnsWidths(TABLES.ACCOUNTS);
return ( return (
<DataTable <DataTable

View File

@@ -5,6 +5,7 @@ import CustomersEmptyStatus from './CustomersEmptyStatus';
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
import TableSkeletonHeader from 'components/Datatable/TableHeaderSkeleton'; import TableSkeletonHeader from 'components/Datatable/TableHeaderSkeleton';
import { TABLES } from 'common/tables';
import { DataTable, DashboardContentTable } from 'components'; import { DataTable, DashboardContentTable } from 'components';
import withCustomers from './withCustomers'; import withCustomers from './withCustomers';
@@ -15,6 +16,7 @@ import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { useCustomersListContext } from './CustomersListProvider'; import { useCustomersListContext } from './CustomersListProvider';
import { ActionsMenu, useCustomersTableColumns } from './components'; import { ActionsMenu, useCustomersTableColumns } from './components';
import { useMemorizedColumnsWidths } from 'hooks';
import { compose } from 'utils'; import { compose } from 'utils';
@@ -51,6 +53,10 @@ function CustomersTable({
isCustomersFetching, isCustomersFetching,
} = useCustomersListContext(); } = useCustomersListContext();
// Local storage memorizing columns widths.
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.CUSTOMERS);
// Handle fetch data once the page index, size or sort by of the table change. // Handle fetch data once the page index, size or sort by of the table change.
const handleFetchData = React.useCallback( const handleFetchData = React.useCallback(
({ pageSize, pageIndex, sortBy }) => { ({ pageSize, pageIndex, sortBy }) => {
@@ -110,7 +116,6 @@ function CustomersTable({
noInitialFetch={true} noInitialFetch={true}
columns={columns} columns={columns}
data={customers} data={customers}
initialState={customersTableState}
loading={isCustomersLoading} loading={isCustomersLoading}
headerLoading={isCustomersLoading} headerLoading={isCustomersLoading}
progressBarLoading={isCustomersFetching} progressBarLoading={isCustomersFetching}
@@ -128,6 +133,8 @@ function CustomersTable({
TableLoadingRenderer={TableSkeletonRows} TableLoadingRenderer={TableSkeletonRows}
TableHeaderSkeletonRenderer={TableSkeletonHeader} TableHeaderSkeletonRenderer={TableSkeletonHeader}
onCellClick={handleCellClick} onCellClick={handleCellClick}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
payload={{ payload={{
onDelete: handleCustomerDelete, onDelete: handleCustomerDelete,
onEdit: handleCustomerEdit, onEdit: handleCustomerEdit,

View File

@@ -3,6 +3,8 @@ import { useHistory } from 'react-router-dom';
import { compose } from 'utils'; import { compose } from 'utils';
import { useExpensesListContext } from './ExpensesListProvider'; import { useExpensesListContext } from './ExpensesListProvider';
import { useMemorizedColumnsWidths } from 'hooks';
import { TABLES } from 'common/tables';
import { DashboardContentTable } from 'components'; import { DashboardContentTable } from 'components';
import DataTable from 'components/DataTable'; import DataTable from 'components/DataTable';
@@ -45,6 +47,10 @@ function ExpensesDataTable({
// Expenses table columns. // Expenses table columns.
const columns = useExpensesTableColumns(); const columns = useExpensesTableColumns();
// Local storage memorizing columns widths.
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.EXPENSES);
// Handle fetch data of manual jouranls datatable. // Handle fetch data of manual jouranls datatable.
const handleFetchData = useCallback( const handleFetchData = useCallback(
({ pageIndex, pageSize, sortBy }) => { ({ pageIndex, pageSize, sortBy }) => {
@@ -111,6 +117,8 @@ function ExpensesDataTable({
TableHeaderSkeletonRenderer={TableSkeletonHeader} TableHeaderSkeletonRenderer={TableSkeletonHeader}
ContextMenu={ActionsMenu} ContextMenu={ActionsMenu}
onCellClick={handleCellClick} onCellClick={handleCellClick}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
payload={{ payload={{
onPublish: handlePublishExpense, onPublish: handlePublishExpense,
onDelete: handleDeleteExpense, onDelete: handleDeleteExpense,

View File

@@ -1,6 +1,10 @@
import React, { useCallback } from 'react'; import React, { useCallback } from 'react';
import { DataTable } from 'components'; import { DataTable } from 'components';
import { TABLES } from 'common/tables';
import { useInventoryAdjustmentsColumns, ActionsMenu } from './components'; import { useInventoryAdjustmentsColumns, ActionsMenu } from './components';
import { useMemorizedColumnsWidths } from 'hooks';
import intl from 'react-intl-universal'; import intl from 'react-intl-universal';
import withAlertsActions from 'containers/Alert/withAlertActions'; import withAlertsActions from 'containers/Alert/withAlertActions';
@@ -55,6 +59,9 @@ function InventoryAdjustmentDataTable({
// Inventory adjustments columns. // Inventory adjustments columns.
const columns = useInventoryAdjustmentsColumns(); const columns = useInventoryAdjustmentsColumns();
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.INVENTORY_ADJUSTMENTS);
// Handle the table fetch data once states changing. // Handle the table fetch data once states changing.
const handleDataTableFetchData = useCallback( const handleDataTableFetchData = useCallback(
({ pageSize, pageIndex, sortBy }) => { ({ pageSize, pageIndex, sortBy }) => {
@@ -79,7 +86,6 @@ function InventoryAdjustmentDataTable({
loading={isAdjustmentsLoading} loading={isAdjustmentsLoading}
headerLoading={isAdjustmentsLoading} headerLoading={isAdjustmentsLoading}
progressBarLoading={isAdjustmentsFetching} progressBarLoading={isAdjustmentsFetching}
initialState={inventoryAdjustmentTableState}
noInitialFetch={true} noInitialFetch={true}
onFetchData={handleDataTableFetchData} onFetchData={handleDataTableFetchData}
manualSortBy={true} manualSortBy={true}
@@ -89,6 +95,8 @@ function InventoryAdjustmentDataTable({
autoResetSortBy={false} autoResetSortBy={false}
autoResetPage={false} autoResetPage={false}
onCellClick={handleCellClick} onCellClick={handleCellClick}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
payload={{ payload={{
onDelete: handleDeleteAdjustment, onDelete: handleDeleteAdjustment,
onPublish: handlePublishInventoryAdjustment, onPublish: handlePublishInventoryAdjustment,

View File

@@ -8,6 +8,8 @@ import ItemsEmptyStatus from './ItemsEmptyStatus';
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
import TableSkeletonHeader from 'components/Datatable/TableHeaderSkeleton'; import TableSkeletonHeader from 'components/Datatable/TableHeaderSkeleton';
import { TABLES } from 'common/tables';
import withItems from 'containers/Items/withItems'; import withItems from 'containers/Items/withItems';
import withItemsActions from 'containers/Items/withItemsActions'; import withItemsActions from 'containers/Items/withItemsActions';
import withAlertsActions from 'containers/Alert/withAlertActions'; import withAlertsActions from 'containers/Alert/withAlertActions';
@@ -16,6 +18,7 @@ import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { useItemsListContext } from './ItemsListProvider'; import { useItemsListContext } from './ItemsListProvider';
import { useItemsTableColumns, ItemsActionMenuList } from './components'; import { useItemsTableColumns, ItemsActionMenuList } from './components';
import { useMemorizedColumnsWidths } from 'hooks';
import { compose } from 'utils'; import { compose } from 'utils';
/** /**
@@ -55,6 +58,10 @@ function ItemsDataTable({
inactive: !row.original.active, inactive: !row.original.active,
}); });
// Local storage memorizing columns widths.
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.ITEMS);
// Handle fetch data once the page index, size or sort by of the table change. // Handle fetch data once the page index, size or sort by of the table change.
const handleFetchData = React.useCallback( const handleFetchData = React.useCallback(
({ pageSize, pageIndex, sortBy }) => { ({ pageSize, pageIndex, sortBy }) => {
@@ -117,7 +124,6 @@ function ItemsDataTable({
<DataTable <DataTable
columns={columns} columns={columns}
data={items} data={items}
initialState={itemsTableState}
loading={isItemsLoading} loading={isItemsLoading}
headerLoading={isItemsLoading} headerLoading={isItemsLoading}
progressBarLoading={isItemsFetching} progressBarLoading={isItemsFetching}
@@ -138,6 +144,8 @@ function ItemsDataTable({
ContextMenu={ItemsActionMenuList} ContextMenu={ItemsActionMenuList}
onFetchData={handleFetchData} onFetchData={handleFetchData}
onCellClick={handleCellClick} onCellClick={handleCellClick}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
payload={{ payload={{
onDeleteItem: handleDeleteItem, onDeleteItem: handleDeleteItem,
onEditItem: handleEditItem, onEditItem: handleEditItem,

View File

@@ -4,6 +4,8 @@ import { useHistory } from 'react-router-dom';
import { compose } from 'utils'; import { compose } from 'utils';
import DataTable from 'components/DataTable'; import DataTable from 'components/DataTable';
import { TABLES } from 'common/tables';
import { DashboardContentTable } from 'components'; import { DashboardContentTable } from 'components';
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
import TableSkeletonHeader from 'components/Datatable/TableHeaderSkeleton'; import TableSkeletonHeader from 'components/Datatable/TableHeaderSkeleton';
@@ -17,6 +19,7 @@ import withDialogActions from 'containers/Dialog/withDialogActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions'; import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { useBillsTableColumns, ActionsMenu } from './components'; import { useBillsTableColumns, ActionsMenu } from './components';
import { useBillsListContext } from './BillsListProvider'; import { useBillsListContext } from './BillsListProvider';
import { useMemorizedColumnsWidths } from 'hooks';
/** /**
* Bills transactions datatable. * Bills transactions datatable.
@@ -92,39 +95,44 @@ function BillsDataTable({
openDrawer('bill-drawer', { billId: cell.row.original.id }); openDrawer('bill-drawer', { billId: cell.row.original.id });
}; };
// Local storage memorizing columns widths.
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.BILLS);
if (isEmptyStatus) { if (isEmptyStatus) {
return <BillsEmptyStatus />; return <BillsEmptyStatus />;
} }
return ( return (
<DashboardContentTable> <DashboardContentTable>
<DataTable <DataTable
columns={columns} columns={columns}
data={bills} data={bills}
initialState={billsTableState} loading={isBillsLoading}
loading={isBillsLoading} headerLoading={isBillsLoading}
headerLoading={isBillsLoading} progressBarLoading={isBillsFetching}
progressBarLoading={isBillsFetching} onFetchData={handleFetchData}
onFetchData={handleFetchData} manualSortBy={true}
manualSortBy={true} selectionColumn={true}
selectionColumn={true} noInitialFetch={true}
noInitialFetch={true} sticky={true}
sticky={true} pagination={true}
pagination={true} pagesCount={pagination.pagesCount}
pagesCount={pagination.pagesCount} TableLoadingRenderer={TableSkeletonRows}
TableLoadingRenderer={TableSkeletonRows} TableHeaderSkeletonRenderer={TableSkeletonHeader}
TableHeaderSkeletonRenderer={TableSkeletonHeader} ContextMenu={ActionsMenu}
ContextMenu={ActionsMenu} onCellClick={handleCellClick}
onCellClick={handleCellClick} initialColumnsWidths={initialColumnsWidths}
payload={{ onColumnResizing={handleColumnResizing}
onDelete: handleDeleteBill, payload={{
onEdit: handleEditBill, onDelete: handleDeleteBill,
onOpen: handleOpenBill, onEdit: handleEditBill,
onQuick: handleQuickPaymentMade, onOpen: handleOpenBill,
onAllocateLandedCost: handleAllocateLandedCost, onQuick: handleQuickPaymentMade,
onViewDetails: handleViewDetailBill, onAllocateLandedCost: handleAllocateLandedCost,
}} onViewDetails: handleViewDetailBill,
/> }}
/>
</DashboardContentTable> </DashboardContentTable>
); );
} }

View File

@@ -3,6 +3,7 @@ import { useHistory } from 'react-router-dom';
import { compose } from 'utils'; import { compose } from 'utils';
import { TABLES } from 'common/tables';
import { DataTable, DashboardContentTable } from 'components'; import { DataTable, DashboardContentTable } from 'components';
import PaymentMadesEmptyStatus from './PaymentMadesEmptyStatus'; import PaymentMadesEmptyStatus from './PaymentMadesEmptyStatus';
@@ -17,6 +18,7 @@ import withAlertsActions from 'containers/Alert/withAlertActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions'; import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { usePaymentMadesTableColumns, ActionsMenu } from './components'; import { usePaymentMadesTableColumns, ActionsMenu } from './components';
import { usePaymentMadesListContext } from './PaymentMadesListProvider'; import { usePaymentMadesListContext } from './PaymentMadesListProvider';
import { useMemorizedColumnsWidths } from 'hooks';
/** /**
* Payment made datatable transactions. * Payment made datatable transactions.
@@ -71,6 +73,10 @@ function PaymentMadesTable({
}); });
}; };
// Local storage memorizing columns widths.
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.PAYMENT_MADES);
// Handle datatable fetch data once the table state change. // Handle datatable fetch data once the table state change.
const handleDataTableFetchData = useCallback( const handleDataTableFetchData = useCallback(
({ pageIndex, pageSize, sortBy }) => { ({ pageIndex, pageSize, sortBy }) => {
@@ -89,7 +95,6 @@ function PaymentMadesTable({
<DataTable <DataTable
columns={columns} columns={columns}
data={paymentMades} data={paymentMades}
initialState={paymentMadesTableState}
onFetchData={handleDataTableFetchData} onFetchData={handleDataTableFetchData}
loading={isPaymentsLoading} loading={isPaymentsLoading}
headerLoading={isPaymentsLoading} headerLoading={isPaymentsLoading}
@@ -106,6 +111,8 @@ function PaymentMadesTable({
TableHeaderSkeletonRenderer={TableSkeletonHeader} TableHeaderSkeletonRenderer={TableSkeletonHeader}
ContextMenu={ActionsMenu} ContextMenu={ActionsMenu}
onCellClick={handleCellClick} onCellClick={handleCellClick}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
payload={{ payload={{
onEdit: handleEditPaymentMade, onEdit: handleEditPaymentMade,
onDelete: handleDeletePaymentMade, onDelete: handleDeletePaymentMade,

View File

@@ -15,6 +15,8 @@ import withDialogActions from 'containers/Dialog/withDialogActions';
import { useEstimatesListContext } from './EstimatesListProvider'; import { useEstimatesListContext } from './EstimatesListProvider';
import { ActionsMenu, useEstiamtesTableColumns } from './components'; import { ActionsMenu, useEstiamtesTableColumns } from './components';
import { TABLES } from 'common/tables';
import { useMemorizedColumnsWidths } from 'hooks';
/** /**
* Estimates datatable. * Estimates datatable.
@@ -89,6 +91,11 @@ function EstimatesDataTable({
const handleCellClick = (cell, event) => { const handleCellClick = (cell, event) => {
openDrawer('estimate-detail-drawer', { estimateId: cell.row.original.id }); openDrawer('estimate-detail-drawer', { estimateId: cell.row.original.id });
}; };
// Local storage memorizing columns widths.
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.ESTIMATES);
// Handles fetch data. // Handles fetch data.
const handleFetchData = useCallback( const handleFetchData = useCallback(
({ pageIndex, pageSize, sortBy }) => { ({ pageIndex, pageSize, sortBy }) => {
@@ -126,6 +133,8 @@ function EstimatesDataTable({
TableHeaderSkeletonRenderer={TableSkeletonHeader} TableHeaderSkeletonRenderer={TableSkeletonHeader}
ContextMenu={ActionsMenu} ContextMenu={ActionsMenu}
onCellClick={handleCellClick} onCellClick={handleCellClick}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
payload={{ payload={{
onApprove: handleApproveEstimate, onApprove: handleApproveEstimate,
onEdit: handleEditEstimate, onEdit: handleEditEstimate,

View File

@@ -3,8 +3,10 @@ import { useHistory } from 'react-router-dom';
import InvoicesEmptyStatus from './InvoicesEmptyStatus'; import InvoicesEmptyStatus from './InvoicesEmptyStatus';
import { compose } from 'utils';
import { DataTable, DashboardContentTable } from 'components'; import { DataTable, DashboardContentTable } from 'components';
import { TABLES } from 'common/tables';
import { useMemorizedColumnsWidths } from 'hooks';
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
import TableSkeletonHeader from 'components/Datatable/TableHeaderSkeleton'; import TableSkeletonHeader from 'components/Datatable/TableHeaderSkeleton';
@@ -18,6 +20,8 @@ import withDialogActions from 'containers/Dialog/withDialogActions';
import { useInvoicesTableColumns, ActionsMenu } from './components'; import { useInvoicesTableColumns, ActionsMenu } from './components';
import { useInvoicesListContext } from './InvoicesListProvider'; import { useInvoicesListContext } from './InvoicesListProvider';
import { compose } from 'utils';
/** /**
* Invoices datatable. * Invoices datatable.
*/ */
@@ -85,6 +89,11 @@ function InvoicesDataTable({
const handleCellClick = (cell, event) => { const handleCellClick = (cell, event) => {
openDrawer('invoice-detail-drawer', { invoiceId: cell.row.original.id }); openDrawer('invoice-detail-drawer', { invoiceId: cell.row.original.id });
}; };
// Local storage memorizing columns widths.
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.INVOICES);
// Handles fetch data once the table state change. // Handles fetch data once the table state change.
const handleDataTableFetchData = useCallback( const handleDataTableFetchData = useCallback(
({ pageSize, pageIndex, sortBy }) => { ({ pageSize, pageIndex, sortBy }) => {
@@ -107,7 +116,6 @@ function InvoicesDataTable({
<DataTable <DataTable
columns={columns} columns={columns}
data={invoices} data={invoices}
initialState={invoicesTableState}
loading={isInvoicesLoading} loading={isInvoicesLoading}
headerLoading={isInvoicesLoading} headerLoading={isInvoicesLoading}
progressBarLoading={isInvoicesFetching} progressBarLoading={isInvoicesFetching}
@@ -125,6 +133,8 @@ function InvoicesDataTable({
TableHeaderSkeletonRenderer={TableSkeletonHeader} TableHeaderSkeletonRenderer={TableSkeletonHeader}
ContextMenu={ActionsMenu} ContextMenu={ActionsMenu}
onCellClick={handleCellClick} onCellClick={handleCellClick}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
payload={{ payload={{
onDelete: handleDeleteInvoice, onDelete: handleDeleteInvoice,
onDeliver: handleDeliverInvoice, onDeliver: handleDeliverInvoice,

View File

@@ -2,6 +2,7 @@ import React, { useCallback } from 'react';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { compose } from 'utils'; import { compose } from 'utils';
import { TABLES } from 'common/tables';
import { DataTable, DashboardContentTable } from 'components'; import { DataTable, DashboardContentTable } from 'components';
import PaymentReceivesEmptyStatus from './PaymentReceivesEmptyStatus'; import PaymentReceivesEmptyStatus from './PaymentReceivesEmptyStatus';
@@ -14,6 +15,7 @@ import withAlertsActions from 'containers/Alert/withAlertActions';
import withDrawerActions from 'containers/Drawer/withDrawerActions'; import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { usePaymentReceivesColumns, ActionsMenu } from './components'; import { usePaymentReceivesColumns, ActionsMenu } from './components';
import { usePaymentReceivesListContext } from './PaymentReceiptsListProvider'; import { usePaymentReceivesListContext } from './PaymentReceiptsListProvider';
import { useMemorizedColumnsWidths } from 'hooks';
/** /**
* Payment receives datatable. * Payment receives datatable.
@@ -73,6 +75,10 @@ function PaymentReceivesDataTable({
}); });
}; };
// Local storage memorizing columns widths.
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.PAYMENT_RECEIVES);
// Handle datatable fetch once the table's state changing. // Handle datatable fetch once the table's state changing.
const handleDataTableFetchData = useCallback( const handleDataTableFetchData = useCallback(
({ pageIndex, pageSize, sortBy }) => { ({ pageIndex, pageSize, sortBy }) => {
@@ -95,7 +101,6 @@ function PaymentReceivesDataTable({
<DataTable <DataTable
columns={columns} columns={columns}
data={paymentReceives} data={paymentReceives}
initialState={paymentReceivesTableState}
loading={isPaymentReceivesLoading} loading={isPaymentReceivesLoading}
headerLoading={isPaymentReceivesLoading} headerLoading={isPaymentReceivesLoading}
progressBarLoading={isPaymentReceivesFetching} progressBarLoading={isPaymentReceivesFetching}
@@ -112,6 +117,8 @@ function PaymentReceivesDataTable({
TableHeaderSkeletonRenderer={TableSkeletonHeader} TableHeaderSkeletonRenderer={TableSkeletonHeader}
ContextMenu={ActionsMenu} ContextMenu={ActionsMenu}
onCellClick={handleCellClick} onCellClick={handleCellClick}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
payload={{ payload={{
onDelete: handleDeletePaymentReceive, onDelete: handleDeletePaymentReceive,
onEdit: handleEditPaymentReceive, onEdit: handleEditPaymentReceive,

View File

@@ -3,6 +3,7 @@ import { useHistory } from 'react-router-dom';
import { compose } from 'utils'; import { compose } from 'utils';
import { DataTable, DashboardContentTable } from 'components'; import { DataTable, DashboardContentTable } from 'components';
import { TABLES } from 'common/tables';
import ReceiptsEmptyStatus from './ReceiptsEmptyStatus'; import ReceiptsEmptyStatus from './ReceiptsEmptyStatus';
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
@@ -16,6 +17,7 @@ import withReceiptsActions from './withReceiptsActions';
import { useReceiptsListContext } from './ReceiptsListProvider'; import { useReceiptsListContext } from './ReceiptsListProvider';
import { useReceiptsTableColumns, ActionsMenu } from './components'; import { useReceiptsTableColumns, ActionsMenu } from './components';
import { useMemorizedColumnsWidths } from 'hooks';
/** /**
* Sale receipts datatable. * Sale receipts datatable.
@@ -75,6 +77,10 @@ function ReceiptsDataTable({
openDialog('receipt-pdf-preview', { receiptId: id }); openDialog('receipt-pdf-preview', { receiptId: id });
}; };
// Local storage memorizing columns widths.
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.RECEIPTS);
// Handles the datable fetch data once the state changing. // Handles the datable fetch data once the state changing.
const handleDataTableFetchData = useCallback( const handleDataTableFetchData = useCallback(
({ sortBy, pageIndex, pageSize }) => { ({ sortBy, pageIndex, pageSize }) => {
@@ -100,7 +106,6 @@ function ReceiptsDataTable({
<DataTable <DataTable
columns={columns} columns={columns}
data={receipts} data={receipts}
initialState={receiptTableState}
loading={isReceiptsLoading} loading={isReceiptsLoading}
headerLoading={isReceiptsLoading} headerLoading={isReceiptsLoading}
progressBarLoading={isReceiptsFetching} progressBarLoading={isReceiptsFetching}
@@ -118,6 +123,8 @@ function ReceiptsDataTable({
TableHeaderSkeletonRenderer={TableSkeletonHeader} TableHeaderSkeletonRenderer={TableSkeletonHeader}
ContextMenu={ActionsMenu} ContextMenu={ActionsMenu}
onCellClick={handleCellClick} onCellClick={handleCellClick}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
payload={{ payload={{
onEdit: handleEditReceipt, onEdit: handleEditReceipt,
onDelete: handleDeleteReceipt, onDelete: handleDeleteReceipt,

View File

@@ -1,6 +1,8 @@
import React from 'react'; import React from 'react';
import { useHistory } from 'react-router'; import { useHistory } from 'react-router';
import { TABLES } from 'common/tables';
import { DataTable, DashboardContentTable } from 'components'; import { DataTable, DashboardContentTable } from 'components';
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
import TableSkeletonHeader from 'components/Datatable/TableHeaderSkeleton'; import TableSkeletonHeader from 'components/Datatable/TableHeaderSkeleton';
@@ -16,6 +18,7 @@ import withDrawerActions from 'containers/Drawer/withDrawerActions';
import { compose } from 'utils'; import { compose } from 'utils';
import { ActionsMenu, useVendorsTableColumns } from './components'; import { ActionsMenu, useVendorsTableColumns } from './components';
import { useMemorizedColumnsWidths } from 'hooks';
/** /**
* Vendors table. * Vendors table.
@@ -91,6 +94,10 @@ function VendorsTable({
openDrawer('vendor-details-drawer', { vendorId: cell.row.original.id }); openDrawer('vendor-details-drawer', { vendorId: cell.row.original.id });
}; };
// Local storage memorizing columns widths.
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.VENDORS);
// Handle fetch data once the page index, size or sort by of the table change. // Handle fetch data once the page index, size or sort by of the table change.
const handleFetchData = React.useCallback( const handleFetchData = React.useCallback(
({ pageSize, pageIndex, sortBy }) => { ({ pageSize, pageIndex, sortBy }) => {
@@ -114,7 +121,6 @@ function VendorsTable({
noInitialFetch={true} noInitialFetch={true}
columns={columns} columns={columns}
data={vendors} data={vendors}
initialState={vendorsTableState}
loading={isVendorsLoading} loading={isVendorsLoading}
headerLoading={isVendorsLoading} headerLoading={isVendorsLoading}
progressBarLoading={isVendorsFetching} progressBarLoading={isVendorsFetching}
@@ -131,6 +137,8 @@ function VendorsTable({
TableHeaderSkeletonRenderer={TableSkeletonHeader} TableHeaderSkeletonRenderer={TableSkeletonHeader}
ContextMenu={ActionsMenu} ContextMenu={ActionsMenu}
onCellClick={handleCellClick} onCellClick={handleCellClick}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
payload={{ payload={{
onEdit: handleEditVendor, onEdit: handleEditVendor,
onDelete: handleDeleteVendor, onDelete: handleDeleteVendor,