From cc42c21f2408b6b37a5e10078f600cacf85eb018 Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Sat, 12 Feb 2022 16:07:26 +0200 Subject: [PATCH] refactor(JournalSheet) --- .../FinancialStatements/Journal/Journal.js | 2 - .../Journal/JournalTable.js | 54 ++++++++++++------- .../FinancialStatements/reducers.js | 6 +-- .../pages/FinancialStatements/Journal.scss | 46 ---------------- 4 files changed, 38 insertions(+), 70 deletions(-) diff --git a/src/containers/FinancialStatements/Journal/Journal.js b/src/containers/FinancialStatements/Journal/Journal.js index e1e043c31..27edff2c8 100644 --- a/src/containers/FinancialStatements/Journal/Journal.js +++ b/src/containers/FinancialStatements/Journal/Journal.js @@ -25,7 +25,6 @@ function Journal({ const [filter, setFilter] = useState({ ...getDefaultJournalQuery(), }); - // Handle financial statement filter change. const handleFilterSubmit = useCallback( (filter) => { @@ -38,7 +37,6 @@ function Journal({ }, [setFilter], ); - // Hide the journal sheet filter drawer once the page unmount. useEffect( () => () => { diff --git a/src/containers/FinancialStatements/Journal/JournalTable.js b/src/containers/FinancialStatements/Journal/JournalTable.js index faa3bffaf..aa2a2f0b6 100644 --- a/src/containers/FinancialStatements/Journal/JournalTable.js +++ b/src/containers/FinancialStatements/Journal/JournalTable.js @@ -1,5 +1,6 @@ -import React, { useCallback, useMemo } from 'react'; +import React, { useMemo } from 'react'; import intl from 'react-intl-universal'; +import styled from 'styled-components'; import { DataTable, FinancialSheet } from 'components'; import TableVirtualizedListRows from 'components/Datatable/TableVirtualizedRows'; @@ -8,8 +9,7 @@ import TableFastCell from 'components/Datatable/TableFastCell'; import { useJournalTableColumns } from './components'; import { useJournalSheetContext } from './JournalProvider'; -import { defaultExpanderReducer } from 'utils'; - +import { defaultExpanderReducer, tableRowTypesToClassnames } from 'utils'; import { TableStyle } from 'common'; /** @@ -29,20 +29,6 @@ export function JournalTable({ companyName }) { // Default expanded rows of general journal table. 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 ( - ); } + +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; + } + } + } +`; diff --git a/src/containers/FinancialStatements/reducers.js b/src/containers/FinancialStatements/reducers.js index 7196cb8dc..3305a1c41 100644 --- a/src/containers/FinancialStatements/reducers.js +++ b/src/containers/FinancialStatements/reducers.js @@ -39,7 +39,7 @@ export const journalTableRowsReducer = (journal) => { reference_type_formatted: transaction.reference_type_formatted, } : {}), - rowType: TYPES.ENTRY, + row_types: TYPES.ENTRY, ...entry, })); }; @@ -51,7 +51,7 @@ export const journalTableRowsReducer = (journal) => { return [ ...entries, { - rowType: TYPES.TOTAL_ENTRIES, + row_types: TYPES.TOTAL_ENTRIES, currency_code: transaction.currency_code, credit: transaction.credit, debit: transaction.debit, @@ -59,7 +59,7 @@ export const journalTableRowsReducer = (journal) => { formatted_debit: transaction.formatted_debit, }, { - rowType: TYPES.EMPTY_ROW, + row_types: TYPES.EMPTY_ROW, }, ]; }) diff --git a/src/style/pages/FinancialStatements/Journal.scss b/src/style/pages/FinancialStatements/Journal.scss index 40fecf503..26cca5b7d 100644 --- a/src/style/pages/FinancialStatements/Journal.scss +++ b/src/style/pages/FinancialStatements/Journal.scss @@ -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-header-drawer{