Skip to content

Commit

Permalink
revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
carkom committed Dec 13, 2023
1 parent 4cff288 commit 130ad0f
Show file tree
Hide file tree
Showing 12 changed files with 436 additions and 752 deletions.
3 changes: 0 additions & 3 deletions packages/desktop-client/src/components/common/Block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import { type HTMLProps, type Ref } from 'react';

import { css } from 'glamor';

import { type CSSProperties } from '../../style';

type BlockProps = HTMLProps<HTMLDivElement> & {
innerRef?: Ref<HTMLDivElement>;
style?: CSSProperties;
};

export default function Block(props: BlockProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ export default function CategorySelector({
);
})}
</ul>
<View />
</View>
);
}
67 changes: 16 additions & 51 deletions packages/desktop-client/src/components/reports/ChooseGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import StackedBarGraph from './graphs/StackedBarGraph';
import { ReportOptions } from './ReportOptions';
import ReportTable from './ReportTable';
import ReportTableHeader from './ReportTableHeader';
import ReportTableList from './ReportTableList';
import ReportTableTotals from './ReportTableTotals';

type ChooseGraphProps = {
Expand All @@ -38,12 +39,6 @@ function ChooseGraph({
months,
}: ChooseGraphProps) {
const balanceTypeOp = ReportOptions.balanceTypeMap.get(balanceType);
const groupByData =
groupBy === 'Category'
? 'groupedData'
: ['Month', 'Year'].includes(groupBy)
? 'monthData'
: 'data';

const saveScrollWidth = value => {
setScrollWidth(!value ? 0 : value);
Expand All @@ -52,39 +47,10 @@ function ChooseGraph({
const headerScrollRef = useRef<HTMLDivElement>(null);
const listScrollRef = useRef<HTMLDivElement>(null);
const totalScrollRef = useRef<HTMLDivElement>(null);
const indexScrollRef = useRef<HTMLDivElement>(null);
const scrollScrollRef = useRef<HTMLDivElement>(null);

const handleScroll = scroll => {
if (scroll.target.id === 'total') {
headerScrollRef.current.scrollLeft = scroll.target.scrollLeft;
listScrollRef.current.scrollLeft = scroll.target.scrollLeft;
}
if (scroll.target.id === 'header') {
totalScrollRef.current.scrollLeft = scroll.target.scrollLeft;
listScrollRef.current.scrollLeft = scroll.target.scrollLeft;
}
if (scroll.target.id === 'list') {
if (indexScrollRef.current.scrollTop !== scroll.target.scrollTop) {
indexScrollRef.current.scrollTop = scroll.target.scrollTop;
scrollScrollRef.current.scrollTop = scroll.target.scrollTop;
} else {
if (headerScrollRef.current) {
headerScrollRef.current.scrollLeft = scroll.target.scrollLeft;
}
if (totalScrollRef.current) {
totalScrollRef.current.scrollLeft = scroll.target.scrollLeft;
}
}
}
if (scroll.target.id === 'index') {
listScrollRef.current.scrollTop = scroll.target.scrollTop;
scrollScrollRef.current.scrollTop = scroll.target.scrollTop;
}
if (scroll.target.id === 'scroll') {
listScrollRef.current.scrollTop = scroll.target.scrollTop;
indexScrollRef.current.scrollTop = scroll.target.scrollTop;
}
const handleScrollTotals = scroll => {
headerScrollRef.current.scrollLeft = scroll.target.scrollLeft;
listScrollRef.current.scrollLeft = scroll.target.scrollLeft;
};

if (graphType === 'AreaGraph') {
Expand Down Expand Up @@ -130,28 +96,27 @@ function ChooseGraph({
<View>
<ReportTableHeader
headerScrollRef={headerScrollRef}
handleScroll={handleScroll}
interval={mode === 'time' && data.monthData}
interval={mode === 'time' && months}
scrollWidth={scrollWidth}
groupBy={groupBy}
balanceType={balanceType}
/>
<ReportTable
saveScrollWidth={saveScrollWidth}
listScrollRef={listScrollRef}
indexScrollRef={indexScrollRef}
scrollScrollRef={scrollScrollRef}
handleScroll={handleScroll}
balanceTypeOp={balanceTypeOp}
groupBy={groupBy}
data={data[groupByData]}
showEmpty={showEmpty}
mode={mode}
monthsCount={months.length}
/>
>
<ReportTableList
data={data}
empty={showEmpty}
monthsCount={months.length}
balanceTypeOp={balanceTypeOp}
mode={mode}
groupBy={groupBy}
/>
</ReportTable>
<ReportTableTotals
totalScrollRef={totalScrollRef}
handleScroll={handleScroll}
handleScrollTotals={handleScrollTotals}
scrollWidth={scrollWidth}
data={data}
mode={mode}
Expand Down
154 changes: 16 additions & 138 deletions packages/desktop-client/src/components/reports/ReportTable.tsx
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>
);
}
Loading

0 comments on commit 130ad0f

Please sign in to comment.