Files
bigcapital/packages/webapp/src/containers/Accounts/AccountsDataTable.tsx
Ahmed Bouhuolia b6970fefc2 refactor: convert containers default exports to named exports
## Summary
Converted 905 default exports in src/containers to named exports for improved tree-shaking, better IDE refactoring support, and consistency with modern TypeScript practices.

## Changes
- Converted `export default function X` to `export function X` (916 files)
- Converted `export default compose(...)(X)` to `export const X = compose(...)(XInner)` with HOC wrapping
- Updated 373 import sites from default to named imports
- Fixed 136 React.lazy() imports to use .then() pattern for compatibility with named exports
- Updated re-export patterns in index files
- Fixed edge cases (alert arrays, connector HOCs, type definitions)

## Implementation
- Created codemod script: codemod-containers-exports.js (905 files converted)
- Created import updater: codemod-update-default-imports.js (373 imports fixed)
- Created lazy import fixer: codemod-fix-lazy-imports.js (136 lazy imports fixed)
- Manual fixes for 30 edge-case files (arrays, HOC factories, type definitions)

## Testing
- TypeScript type check: 0 codemod-related errors
- All lazy imports updated with .then() pattern
- All import sites updated to use named imports
- Zero remaining default exports in containers directory

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 20:08:39 +02:00

156 lines
4.6 KiB
TypeScript

// @ts-nocheck
import React from 'react';
import {
TableFastCell,
DataTable,
TableSkeletonRows,
TableSkeletonHeader,
TableVirtualizedListRows,
} from '@/components';
import { useAccountsTableColumns, rowClassNames } from './utils';
import { ActionsMenu } from './components';
import { AccountDialogAction } from '@/containers/Dialogs/AccountDialog/utils';
import { useAccountsChartContext } from './AccountsChartProvider';
import { useMemorizedColumnsWidths } from '@/hooks';
import { TABLES } from '@/constants/tables';
import { DialogsName } from '@/constants/dialogs';
import { withSettings } from '@/containers/Settings/withSettings';
import { withAlertActions } from '@/containers/Alert/withAlertActions';
import { withDialogActions } from '@/containers/Dialog/withDialogActions';
import { withDrawerActions } from '@/containers/Drawer/withDrawerActions';
import { withAccountsTableActions } from './withAccountsTableActions';
import { compose } from '@/utils';
import { DRAWERS } from '@/constants/drawers';
/**
* Accounts data-table.
*/
function AccountsDataTableInner({
// #withAlertsDialog
openAlert,
// #withDialog
openDialog,
// #withDrawerActions
openDrawer,
// #withSettings
accountsTableSize,
// #withAccountsTableActions
setAccountsSelectedRows,
}) {
const { isAccountsLoading, isAccountsFetching, accounts } =
useAccountsChartContext();
// Retrieve accounts table columns.
const columns = useAccountsTableColumns();
// Handle delete action account.
const handleDeleteAccount = (account) => {
openAlert('account-delete', { accountId: account.id });
};
// Handle activate action account.
const handleActivateAccount = (account) => {
openAlert('account-activate', { accountId: account.id });
};
// Handle inactivate action account.
const handleInactivateAccount = (account) => {
openAlert('account-inactivate', { accountId: account.id });
};
// Handle edit account action.
const handleEditAccount = (account) => {
openDialog(DialogsName.AccountForm, {
action: AccountDialogAction.Edit,
accountId: account.id,
});
};
// Handle view detail account.
const handleViewDetailAccount = ({ id }) => {
openDrawer(DRAWERS.ACCOUNT_DETAILS, { accountId: id });
};
// Handle new child button click.
const handleNewChildAccount = (account) => {
openDialog(DialogsName.AccountForm, {
action: AccountDialogAction.NewChild,
parentAccountId: account.id,
accountType: account.account_type,
});
};
// Handle cell click.
const handleCellClick = (cell, event) => {
openDrawer(DRAWERS.ACCOUNT_DETAILS, { accountId: cell.row.original.id });
};
// Local storage memorizing columns widths.
const [initialColumnsWidths, , handleColumnResizing] =
useMemorizedColumnsWidths(TABLES.ACCOUNTS);
// Handle selected rows change.
const handleSelectedRowsChange = (selectedFlatRows) => {
const selectedIds = selectedFlatRows?.map((row) => row.original.id) || [];
setAccountsSelectedRows(selectedIds);
};
return (
<DataTable
noInitialFetch={true}
columns={columns}
data={accounts ?? []}
selectionColumn={true}
expandable={true}
sticky={true}
loading={isAccountsLoading}
headerLoading={isAccountsLoading}
progressBarLoading={isAccountsFetching}
rowClassNames={rowClassNames}
autoResetExpanded={false}
autoResetSortBy={false}
autoResetSelectedRows={false}
expandColumnSpace={1}
expandToggleColumn={2}
selectionColumnWidth={45}
TableCellRenderer={TableFastCell}
TableRowsRenderer={TableVirtualizedListRows}
TableLoadingRenderer={TableSkeletonRows}
TableHeaderSkeletonRenderer={TableSkeletonHeader}
ContextMenu={ActionsMenu}
// #TableVirtualizedListRows props.
vListrowHeight={accountsTableSize == 'small' ? 40 : 42}
vListOverscanRowCount={0}
onCellClick={handleCellClick}
onSelectedRowsChange={handleSelectedRowsChange}
initialColumnsWidths={initialColumnsWidths}
onColumnResizing={handleColumnResizing}
size={accountsTableSize}
payload={{
onEdit: handleEditAccount,
onDelete: handleDeleteAccount,
onActivate: handleActivateAccount,
onInactivate: handleInactivateAccount,
onNewChild: handleNewChildAccount,
onViewDetails: handleViewDetailAccount,
}}
/>
);
}
export const AccountsDataTable = compose(
withAlertActions,
withDrawerActions,
withDialogActions,
withAccountsTableActions,
withSettings(({ accountsSettings }) => ({
accountsTableSize: accountsSettings.tableSize,
})),
)(AccountsDataTableInner);