refactor(JournalSheet)

This commit is contained in:
a.bouhuolia
2022-02-12 16:07:26 +02:00
parent 2f0322b4fc
commit cc42c21f24
4 changed files with 38 additions and 70 deletions

View File

@@ -25,7 +25,6 @@ function Journal({
const [filter, setFilter] = useState({ const [filter, setFilter] = useState({
...getDefaultJournalQuery(), ...getDefaultJournalQuery(),
}); });
// Handle financial statement filter change. // Handle financial statement filter change.
const handleFilterSubmit = useCallback( const handleFilterSubmit = useCallback(
(filter) => { (filter) => {
@@ -38,7 +37,6 @@ function Journal({
}, },
[setFilter], [setFilter],
); );
// Hide the journal sheet filter drawer once the page unmount. // Hide the journal sheet filter drawer once the page unmount.
useEffect( useEffect(
() => () => { () => () => {

View File

@@ -1,5 +1,6 @@
import React, { useCallback, useMemo } from 'react'; import React, { useMemo } 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 TableVirtualizedListRows from 'components/Datatable/TableVirtualizedRows'; import TableVirtualizedListRows from 'components/Datatable/TableVirtualizedRows';
@@ -8,8 +9,7 @@ import TableFastCell from 'components/Datatable/TableFastCell';
import { useJournalTableColumns } from './components'; import { useJournalTableColumns } from './components';
import { useJournalSheetContext } from './JournalProvider'; import { useJournalSheetContext } from './JournalProvider';
import { defaultExpanderReducer } from 'utils'; import { defaultExpanderReducer, tableRowTypesToClassnames } from 'utils';
import { TableStyle } from 'common'; import { TableStyle } from 'common';
/** /**
@@ -29,20 +29,6 @@ export function JournalTable({ companyName }) {
// Default expanded rows of general journal table. // Default expanded rows of general journal table.
const expandedRows = useMemo(() => defaultExpanderReducer([], 1), []); const expandedRows = useMemo(() => defaultExpanderReducer([], 1), []);
const rowClassNames = useCallback((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}
@@ -53,10 +39,10 @@ export function JournalTable({ companyName }) {
loading={isLoading} loading={isLoading}
fullWidth={true} fullWidth={true}
> >
<DataTable <JournalDataTable
columns={columns} columns={columns}
data={tableRows} data={tableRows}
rowClassNames={rowClassNames} rowClassNames={tableRowTypesToClassnames}
noResults={intl.get( noResults={intl.get(
'this_report_does_not_contain_any_data_between_date_period', 'this_report_does_not_contain_any_data_between_date_period',
)} )}
@@ -73,3 +59,33 @@ export function JournalTable({ companyName }) {
</FinancialSheet> </FinancialSheet>
); );
} }
const JournalDataTable = styled(DataTable)`
.table {
.tbody {
.tr:not(.no-results) .td {
padding: 0.3rem 0.4rem;
color: #000;
border-bottom-color: transparent;
min-height: 28px;
border-left: 1px solid #ececec;
&:first-of-type {
border-left: 0;
}
}
.tr:not(.no-results):last-child {
.td {
border-bottom: 1px solid #dbdbdb;
}
}
.tr.row_type--TOTAL_ENTRIES {
font-weight: 600;
}
.tr:not(.no-results) {
height: 28px;
}
}
}
`;

View File

@@ -39,7 +39,7 @@ export const journalTableRowsReducer = (journal) => {
reference_type_formatted: transaction.reference_type_formatted, reference_type_formatted: transaction.reference_type_formatted,
} }
: {}), : {}),
rowType: TYPES.ENTRY, row_types: TYPES.ENTRY,
...entry, ...entry,
})); }));
}; };
@@ -51,7 +51,7 @@ export const journalTableRowsReducer = (journal) => {
return [ return [
...entries, ...entries,
{ {
rowType: TYPES.TOTAL_ENTRIES, row_types: TYPES.TOTAL_ENTRIES,
currency_code: transaction.currency_code, currency_code: transaction.currency_code,
credit: transaction.credit, credit: transaction.credit,
debit: transaction.debit, debit: transaction.debit,
@@ -59,7 +59,7 @@ export const journalTableRowsReducer = (journal) => {
formatted_debit: transaction.formatted_debit, formatted_debit: transaction.formatted_debit,
}, },
{ {
rowType: TYPES.EMPTY_ROW, row_types: TYPES.EMPTY_ROW,
}, },
]; ];
}) })

View File

@@ -1,50 +1,4 @@
.financial-sheet{
&--journal{
.financial-sheet__table{
.tr .td.credit,
.tr .th.credit,
.tr .td.debit,
.tr .th.debit{
text-align: right;
}
.tbody{
.tr:not(.no-results) .td{
padding: 0.3rem 0.4rem;
color: #000;
border-bottom-color: transparent;
min-height: 28px;
border-left: 1px solid #ececec;
&:first-of-type{
border-left: 0;
}
&.account_name,
&.reference_type_formatted{
white-space: nowrap;
overflow: hidden;
text-overflow:ellipsis;
}
}
.tr:not(.no-results):last-child{
.td{
border-bottom: 1px solid #dbdbdb;
}
}
.tr.row_type--TOTAL_ENTRIES{
font-weight: 600;
}
.tr:not(.no-results) {
height: 28px;
}
}
}
}
}
.financial-statement--journal{ .financial-statement--journal{
.financial-header-drawer{ .financial-header-drawer{