-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
436 additions
and
752 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,7 +225,6 @@ export default function CategorySelector({ | |
); | ||
})} | ||
</ul> | ||
<View /> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 16 additions & 138 deletions
154
packages/desktop-client/src/components/reports/ReportTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,170 +1,48 @@ | ||
import React, { | ||
useCallback, | ||
useLayoutEffect, | ||
type UIEventHandler, | ||
} from 'react'; | ||
import React, { useLayoutEffect, useRef, type ReactNode } from 'react'; | ||
import { type RefProp } from 'react-spring'; | ||
|
||
import { theme, type CSSProperties } from '../../style'; | ||
import Block from '../common/Block'; | ||
import { type CSSProperties } from '../../style'; | ||
import View from '../common/View'; | ||
|
||
import { type GroupedEntity } from './entities'; | ||
import ReportTableColumnIndex from './ReportTableColumnIndex'; | ||
import ReportTableColumnTotals from './ReportTableColumTotals'; | ||
import ReportTableInner from './ReportTableInner'; | ||
import ReportTableRow from './ReportTableRow'; | ||
|
||
type ReportTableProps = { | ||
saveScrollWidth: (value: number) => void; | ||
listScrollRef: RefProp<HTMLDivElement>; | ||
indexScrollRef: RefProp<HTMLDivElement>; | ||
scrollScrollRef: RefProp<HTMLDivElement>; | ||
handleScroll: UIEventHandler<HTMLDivElement>; | ||
saveScrollWidth?: (value: number) => void; | ||
listScrollRef?: RefProp<HTMLDivElement>; | ||
style?: CSSProperties; | ||
groupBy: string; | ||
balanceTypeOp: string; | ||
showEmpty: boolean; | ||
data: GroupedEntity[]; | ||
mode: string; | ||
monthsCount: number; | ||
children?: ReactNode; | ||
}; | ||
|
||
export default function ReportTable({ | ||
saveScrollWidth, | ||
listScrollRef, | ||
indexScrollRef, | ||
scrollScrollRef, | ||
handleScroll, | ||
style, | ||
groupBy, | ||
balanceTypeOp, | ||
showEmpty, | ||
data, | ||
mode, | ||
monthsCount, | ||
children, | ||
}: ReportTableProps) { | ||
const groupByItem = ['Month', 'Year'].includes(groupBy) ? 'date' : 'name'; | ||
const contentRef = useRef<HTMLDivElement>(null); | ||
|
||
useLayoutEffect(() => { | ||
if (scrollScrollRef.current && saveScrollWidth) { | ||
const [parent, child] = [ | ||
scrollScrollRef.current.offsetWidth, | ||
scrollScrollRef.current.clientWidth, | ||
]; | ||
|
||
saveScrollWidth(parent > 0 && child > 0 && parent - child); | ||
if (contentRef.current && saveScrollWidth) { | ||
saveScrollWidth(contentRef.current ? contentRef.current.offsetWidth : 0); | ||
} | ||
}); | ||
|
||
const renderItemTotal = useCallback( | ||
({ item, groupByItem, monthsCount, style, key }) => { | ||
return ( | ||
<ReportTableColumnTotals | ||
key={key} | ||
item={item} | ||
balanceTypeOp={balanceTypeOp} | ||
monthsCount={monthsCount} | ||
groupByItem={groupByItem} | ||
mode={mode} | ||
style={style} | ||
/> | ||
); | ||
}, | ||
[], | ||
); | ||
|
||
const renderItem = useCallback(({ item, groupByItem, mode, style, key }) => { | ||
return ( | ||
<ReportTableRow | ||
key={key} | ||
item={item} | ||
balanceTypeOp={balanceTypeOp} | ||
groupByItem={groupByItem} | ||
mode={mode} | ||
style={style} | ||
/> | ||
); | ||
}, []); | ||
|
||
return ( | ||
<View | ||
innerRef={listScrollRef} | ||
style={{ | ||
overflowY: 'auto', | ||
scrollbarWidth: 'none', | ||
'::-webkit-scrollbar': { display: 'none' }, | ||
flex: 1, | ||
flexDirection: 'row', | ||
outline: 'none', | ||
'& .animated .animated-row': { transition: '.25s transform' }, | ||
...style, | ||
}} | ||
tabIndex={1} | ||
data-testid="table" | ||
> | ||
<Block | ||
innerRef={indexScrollRef} | ||
onScroll={handleScroll} | ||
id={'index'} | ||
style={{ | ||
width: 150, | ||
flexShrink: 0, | ||
overflowY: 'auto', | ||
scrollbarWidth: 'none', | ||
'::-webkit-scrollbar': { display: 'none' }, | ||
justifyContent: 'center', | ||
}} | ||
> | ||
{data.map(item => { | ||
return ( | ||
<ReportTableColumnIndex | ||
key={item.id} | ||
item={item} | ||
groupByItem={groupByItem} | ||
headerStyle={ | ||
item.categories && { | ||
color: theme.tableRowHeaderText, | ||
backgroundColor: theme.tableRowHeaderBackground, | ||
fontWeight: 600, | ||
} | ||
} | ||
/> | ||
); | ||
})} | ||
</Block> | ||
<Block | ||
style={{ | ||
overflow: 'auto', | ||
flex: 1, | ||
scrollbarWidth: 'none', | ||
'::-webkit-scrollbar': { display: 'none' }, | ||
}} | ||
id={'list'} | ||
innerRef={listScrollRef} | ||
onScroll={handleScroll} | ||
> | ||
<ReportTableInner | ||
data={data} | ||
monthsCount={monthsCount} | ||
mode={mode} | ||
groupBy={groupBy} | ||
renderItem={renderItem} | ||
/> | ||
</Block> | ||
<Block | ||
id={'scroll'} | ||
innerRef={scrollScrollRef} | ||
onScroll={handleScroll} | ||
style={{ | ||
overflowY: 'auto', | ||
flexShrink: 0, | ||
}} | ||
> | ||
<ReportTableInner | ||
data={data} | ||
monthsCount={monthsCount} | ||
mode={mode} | ||
groupBy={groupBy} | ||
renderItem={renderItemTotal} | ||
/> | ||
</Block> | ||
<View> | ||
<div ref={contentRef}>{children}</div> | ||
</View> | ||
</View> | ||
); | ||
} |
Oops, something went wrong.