mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
refactor(TrialBalanceSheet).
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
import { DataTable, FinancialSheet } from 'components';
|
import { DataTable, FinancialSheet } from 'components';
|
||||||
|
|
||||||
import { useTrialBalanceSheetContext } from './TrialBalanceProvider';
|
import { useTrialBalanceSheetContext } from './TrialBalanceProvider';
|
||||||
import { useTrialBalanceTableColumns } from './components';
|
import { useTrialBalanceTableColumns } from './components';
|
||||||
|
|
||||||
|
import { tableRowTypesToClassnames } from 'utils';
|
||||||
import { TableStyle } from 'common';
|
import { TableStyle } from 'common';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,20 +23,6 @@ export default function TrialBalanceSheetTable({ companyName }) {
|
|||||||
// Trial balance sheet table columns.
|
// Trial balance sheet table columns.
|
||||||
const columns = useTrialBalanceTableColumns();
|
const columns = useTrialBalanceTableColumns();
|
||||||
|
|
||||||
const rowClassNames = (row) => {
|
|
||||||
const { original } = row;
|
|
||||||
const rowTypes = Array.isArray(original.rowType)
|
|
||||||
? original.rowType
|
|
||||||
: [original.rowType];
|
|
||||||
|
|
||||||
return {
|
|
||||||
...rowTypes.reduce((acc, rowType) => {
|
|
||||||
acc[`row_type--${rowType}`] = rowType;
|
|
||||||
return acc;
|
|
||||||
}, {}),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FinancialSheet
|
<FinancialSheet
|
||||||
companyName={companyName}
|
companyName={companyName}
|
||||||
@@ -45,16 +33,36 @@ export default function TrialBalanceSheetTable({ companyName }) {
|
|||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
basis={'cash'}
|
basis={'cash'}
|
||||||
>
|
>
|
||||||
<DataTable
|
<TrialBalanceDataTable
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={tableRows}
|
data={tableRows}
|
||||||
expandable={true}
|
expandable={true}
|
||||||
expandToggleColumn={1}
|
expandToggleColumn={1}
|
||||||
expandColumnSpace={1}
|
expandColumnSpace={1}
|
||||||
sticky={true}
|
sticky={true}
|
||||||
rowClassNames={rowClassNames}
|
rowClassNames={tableRowTypesToClassnames}
|
||||||
styleName={TableStyle.Constrant}
|
styleName={TableStyle.Constrant}
|
||||||
/>
|
/>
|
||||||
</FinancialSheet>
|
</FinancialSheet>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TrialBalanceDataTable = styled(DataTable)`
|
||||||
|
.table {
|
||||||
|
.tbody {
|
||||||
|
.tr .td {
|
||||||
|
border-bottom: 0;
|
||||||
|
padding-top: 0.36rem;
|
||||||
|
padding-bottom: 0.36rem;
|
||||||
|
}
|
||||||
|
.balance.td {
|
||||||
|
border-top-color: #000;
|
||||||
|
}
|
||||||
|
.tr.row_type--total .td {
|
||||||
|
border-top: 1px solid #bbb;
|
||||||
|
font-weight: 500;
|
||||||
|
border-bottom: 3px double #000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|||||||
@@ -1,12 +1,61 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { Button } from '@blueprintjs/core';
|
import { Button } from '@blueprintjs/core';
|
||||||
|
|
||||||
import { getColumnWidth } from 'utils';
|
import { getColumnWidth } from 'utils';
|
||||||
import { If, Icon, FormattedMessage as T } from 'components';
|
import { If, Icon, FormattedMessage as T } from 'components';
|
||||||
import { CellTextSpan } from 'components/Datatable/Cells';
|
import { CellTextSpan } from 'components/Datatable/Cells';
|
||||||
import { useTrialBalanceSheetContext } from './TrialBalanceProvider';
|
import { useTrialBalanceSheetContext } from './TrialBalanceProvider';
|
||||||
import FinancialLoadingBar from '../FinancialLoadingBar';
|
import FinancialLoadingBar from '../FinancialLoadingBar';
|
||||||
|
|
||||||
|
import { Align } from 'common';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the credit column.
|
||||||
|
*/
|
||||||
|
const getCreditColumn = (data) => {
|
||||||
|
const width = getColumnWidth(data, `credit`, { minWidth: 140 });
|
||||||
|
|
||||||
|
return {
|
||||||
|
Header: intl.get('credit'),
|
||||||
|
Cell: CellTextSpan,
|
||||||
|
accessor: 'formatted_credit',
|
||||||
|
className: 'credit',
|
||||||
|
width,
|
||||||
|
textOverview: true,
|
||||||
|
align: Align.Right,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the debit column.
|
||||||
|
*/
|
||||||
|
const getDebitColumn = (data) => {
|
||||||
|
return {
|
||||||
|
Header: intl.get('debit'),
|
||||||
|
Cell: CellTextSpan,
|
||||||
|
accessor: 'formatted_debit',
|
||||||
|
width: getColumnWidth(data, `debit`, { minWidth: 140 }),
|
||||||
|
textOverview: true,
|
||||||
|
align: Align.Right,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the balance column.
|
||||||
|
*/
|
||||||
|
const getBalanceColumn = (data) => {
|
||||||
|
return {
|
||||||
|
Header: intl.get('balance'),
|
||||||
|
Cell: CellTextSpan,
|
||||||
|
accessor: 'formatted_balance',
|
||||||
|
className: 'balance',
|
||||||
|
width: getColumnWidth(data, `balance`, { minWidth: 140 }),
|
||||||
|
textOverview: true,
|
||||||
|
align: Align.Right,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve trial balance sheet table columns.
|
* Retrieve trial balance sheet table columns.
|
||||||
*/
|
*/
|
||||||
@@ -25,33 +74,9 @@ export const useTrialBalanceTableColumns = () => {
|
|||||||
width: 350,
|
width: 350,
|
||||||
textOverview: true,
|
textOverview: true,
|
||||||
},
|
},
|
||||||
{
|
getCreditColumn(tableRows),
|
||||||
Header: intl.get('credit'),
|
getDebitColumn(tableRows),
|
||||||
Cell: CellTextSpan,
|
getBalanceColumn(tableRows),
|
||||||
accessor: 'formatted_credit',
|
|
||||||
className: 'credit',
|
|
||||||
width: getColumnWidth(tableRows, `credit`, {
|
|
||||||
minWidth: 80,
|
|
||||||
}),
|
|
||||||
textOverview: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Header: intl.get('debit'),
|
|
||||||
Cell: CellTextSpan,
|
|
||||||
accessor: 'formatted_debit',
|
|
||||||
width: getColumnWidth(tableRows, `debit`, { minWidth: 80 }),
|
|
||||||
textOverview: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Header: intl.get('balance'),
|
|
||||||
Cell: CellTextSpan,
|
|
||||||
accessor: 'formatted_balance',
|
|
||||||
className: 'balance',
|
|
||||||
width: getColumnWidth(tableRows, `balance`, {
|
|
||||||
minWidth: 80,
|
|
||||||
}),
|
|
||||||
textOverview: true,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
[tableRows],
|
[tableRows],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export const trialBalanceSheetReducer = (sheet) => {
|
|||||||
}
|
}
|
||||||
if (sheet.total) {
|
if (sheet.total) {
|
||||||
results.push({
|
results.push({
|
||||||
rowType: 'total',
|
row_types: 'total',
|
||||||
...sheet.total,
|
...sheet.total,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -908,7 +908,7 @@ export const tableRowTypesToClassnames = ({ original }) => {
|
|||||||
const rowTypes = _.castArray(original.row_types);
|
const rowTypes = _.castArray(original.row_types);
|
||||||
const rowId = original.id;
|
const rowId = original.id;
|
||||||
|
|
||||||
const rowTypesClsx = rowTypes.map((t) => `row_type--${t}`);
|
const rowTypesClsx = rowTypes.filter((t) => t).map((t) => `row_type--${t}`);
|
||||||
const rowIdClsx = `row-id--${original.id}`;
|
const rowIdClsx = `row-id--${original.id}`;
|
||||||
|
|
||||||
return clsx(rowTypesClsx, { [`${rowIdClsx}`]: rowId });
|
return clsx(rowTypesClsx, { [`${rowIdClsx}`]: rowId });
|
||||||
|
|||||||
Reference in New Issue
Block a user