Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Reports compact additions #2245

Merged
merged 8 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/desktop-client/src/components/common/MenuButton.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// @ts-strict-ignore
import React from 'react';

import { SvgDotsHorizontalTriple } from '../../icons/v1';
import { type CSSProperties } from '../../style';

import { Button } from './Button';

export function MenuButton({ onClick }) {
export function MenuButton({
onClick,
style,
}: {
onClick: () => void;
style?: CSSProperties;
}) {
return (
<Button type="bare" onClick={onClick} aria-label="Menu">
<Button type="bare" onClick={onClick} aria-label="Menu" style={style}>
<SvgDotsHorizontalTriple
width={15}
height={15}
Expand Down
37 changes: 25 additions & 12 deletions packages/desktop-client/src/components/reports/ChooseGraph.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-strict-ignore
import React, { useRef } from 'react';

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

import { type DataEntity, type Month } from './entities';
Expand All @@ -21,11 +22,12 @@ type ChooseGraphProps = {
graphType: string;
balanceType: string;
groupBy: string;
showEmpty: boolean;
scrollWidth: number;
setScrollWidth: (value: number) => void;
months: Month[];
viewLabels: boolean;
scrollWidth?: number;
setScrollWidth?: (value: number) => void;
months?: Month[];
viewLabels?: boolean;
compact?: boolean;
style?: CSSProperties;
};

export function ChooseGraph({
Expand All @@ -34,12 +36,14 @@ export function ChooseGraph({
graphType,
balanceType,
groupBy,
showEmpty,
scrollWidth,
setScrollWidth,
months,
viewLabels,
compact,
style,
}: ChooseGraphProps) {
const graphStyle = compact ? { ...style } : { flexGrow: 1 };
const balanceTypeOp = ReportOptions.balanceTypeMap.get(balanceType);
const groupByData =
groupBy === 'Category'
Expand Down Expand Up @@ -74,7 +78,8 @@ export function ChooseGraph({
if (graphType === 'AreaGraph') {
return (
<AreaGraph
style={{ flexGrow: 1 }}
style={graphStyle}
compact={compact}
data={data}
balanceTypeOp={balanceTypeOp}
viewLabels={viewLabels}
Expand All @@ -84,7 +89,8 @@ export function ChooseGraph({
if (graphType === 'BarGraph') {
return (
<BarGraph
style={{ flexGrow: 1 }}
style={graphStyle}
compact={compact}
data={data}
groupBy={groupBy}
balanceTypeOp={balanceTypeOp}
Expand All @@ -93,12 +99,15 @@ export function ChooseGraph({
);
}
if (graphType === 'BarLineGraph') {
return <BarLineGraph style={{ flexGrow: 1 }} graphData={data} />;
return (
<BarLineGraph style={graphStyle} compact={compact} graphData={data} />
);
}
if (graphType === 'DonutGraph') {
return (
<DonutGraph
style={{ flexGrow: 1 }}
style={graphStyle}
compact={compact}
data={data}
groupBy={groupBy}
balanceTypeOp={balanceTypeOp}
Expand All @@ -107,12 +116,13 @@ export function ChooseGraph({
);
}
if (graphType === 'LineGraph') {
return <LineGraph style={{ flexGrow: 1 }} graphData={data} />;
return <LineGraph style={graphStyle} compact={compact} graphData={data} />;
}
if (graphType === 'StackedBarGraph') {
return (
<StackedBarGraph
style={{ flexGrow: 1 }}
style={graphStyle}
compact={compact}
data={data}
viewLabels={viewLabels}
/>
Expand All @@ -128,6 +138,7 @@ export function ChooseGraph({
scrollWidth={scrollWidth}
groupBy={groupBy}
balanceType={balanceType}
compact={compact}
/>
<ReportTable
saveScrollWidth={saveScrollWidth}
Expand All @@ -138,6 +149,7 @@ export function ChooseGraph({
data={data[groupByData]}
mode={mode}
monthsCount={months.length}
compact={compact}
/>
<ReportTableTotals
totalScrollRef={totalScrollRef}
Expand All @@ -147,6 +159,7 @@ export function ChooseGraph({
mode={mode}
balanceTypeOp={balanceTypeOp}
monthsCount={months.length}
compact={compact}
/>
</View>
);
Expand Down
40 changes: 19 additions & 21 deletions packages/desktop-client/src/components/reports/graphs/BarGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,29 +190,27 @@ export function BarGraph({
formatter={numberFormatterTooltip}
isAnimationActive={false}
/>
{!compact && <CartesianGrid strokeDasharray="3 3" />}
{!compact && (
<XAxis
dataKey={yAxis}
angle={-35}
textAnchor="end"
height={Math.sqrt(longestLabelLength) * 25}
tick={{ fill: theme.pageText }}
tickLine={{ stroke: theme.pageText }}
/>
)}
{!compact && (
<YAxis
tickFormatter={value => getCustomTick(value, privacyMode)}
tick={{ fill: theme.pageText }}
tickLine={{ stroke: theme.pageText }}
/>
)}
{!compact && (
<ReferenceLine y={0} stroke={theme.pageTextLight} />
<>
<CartesianGrid strokeDasharray="3 3" />
<XAxis
dataKey={yAxis}
angle={-35}
textAnchor="end"
height={Math.sqrt(longestLabelLength) * 25}
tick={{ fill: theme.pageText }}
tickLine={{ stroke: theme.pageText }}
/>
<YAxis
tickFormatter={value => getCustomTick(value, privacyMode)}
tick={{ fill: theme.pageText }}
tickLine={{ stroke: theme.pageText }}
/>
<ReferenceLine y={0} stroke={theme.pageTextLight} />
</>
)}
<Bar dataKey={val => getVal(val)} stackId="a">
{viewLabels && (
{viewLabels && !compact && (
<LabelList
dataKey={val => getVal(val)}
content={customLabel}
Expand All @@ -228,7 +226,7 @@ export function BarGraph({
</Bar>
{yAxis === 'date' && balanceTypeOp === 'totalTotals' && (
<Bar dataKey="totalDebts" stackId="a">
{viewLabels && (
{viewLabels && !compact && (
<LabelList dataKey="totalDebts" content={customLabel} />
)}
{data[splitData].map((entry, index) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ export function BarLineGraph({ style, graphData, compact }: BarLineGraphProps) {
formatter={numberFormatterTooltip}
isAnimationActive={false}
/>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="x" />
<YAxis dataKey="y" tickFormatter={tickFormatter} />
{!compact && (
<>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="x" />
<YAxis dataKey="y" tickFormatter={tickFormatter} />
</>
)}
<Bar type="monotone" dataKey="y" fill="#8884d8" />
<Line type="monotone" dataKey="y" stroke="#8884d8" />
</ComposedChart>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ export function DonutGraph({
innerRadius={Math.min(width, height) * 0.2}
fill="#8884d8"
labelLine={false}
label={e => (viewLabels ? customLabel(e) : <div />)}
label={e =>
viewLabels && !compact ? customLabel(e) : <div />
}
onMouseEnter={onPieEnter}
>
{data.legend.map((entry, index) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ export function LineGraph({ style, graphData, compact }: LineGraphProps) {
formatter={numberFormatterTooltip}
isAnimationActive={false}
/>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="x" />
<YAxis dataKey="y" tickFormatter={tickFormatter} />
{!compact && (
<>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="x" />
<YAxis dataKey="y" tickFormatter={tickFormatter} />
</>
)}
<Line type="monotone" dataKey="y" stroke="#8884d8" />
</LineChart>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,20 @@ export function StackedBarGraph({
isAnimationActive={false}
cursor={{ fill: 'transparent' }}
/>
<CartesianGrid strokeDasharray="3 3" />
<XAxis
dataKey="date"
tick={{ fill: theme.pageText }}
tickLine={{ stroke: theme.pageText }}
/>
{!compact && (
<YAxis
tickFormatter={value => getCustomTick(value, privacyMode)}
tick={{ fill: theme.pageText }}
tickLine={{ stroke: theme.pageText }}
/>
<>
<CartesianGrid strokeDasharray="3 3" />
<XAxis
dataKey="date"
tick={{ fill: theme.pageText }}
tickLine={{ stroke: theme.pageText }}
/>
<YAxis
tickFormatter={value => getCustomTick(value, privacyMode)}
tick={{ fill: theme.pageText }}
tickLine={{ stroke: theme.pageText }}
/>
</>
)}
{data.legend
.slice(0)
Expand All @@ -182,7 +184,7 @@ export function StackedBarGraph({
stackId="a"
fill={entry.color}
>
{viewLabels && (
{viewLabels && !compact && (
<LabelList dataKey={entry.name} content={customLabel} />
)}
</Bar>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type ReportTableProps = {
data: GroupedEntity[];
mode: string;
monthsCount: number;
compact: boolean;
};

export function ReportTable({
Expand All @@ -37,6 +38,7 @@ export function ReportTable({
data,
mode,
monthsCount,
compact,
}: ReportTableProps) {
const contentRef = useRef<HTMLDivElement>(null);

Expand Down Expand Up @@ -94,6 +96,7 @@ export function ReportTable({
mode={mode}
groupBy={groupBy}
renderItem={renderItem}
compact={compact}
/>
</Block>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type ReportTableHeaderProps = {
balanceType: string;
headerScrollRef: RefProp<HTMLDivElement>;
handleScroll: UIEventHandler<HTMLDivElement>;
compact: boolean;
};

export function ReportTableHeader({
Expand All @@ -23,6 +24,7 @@ export function ReportTableHeader({
balanceType,
headerScrollRef,
handleScroll,
compact,
}: ReportTableHeaderProps) {
return (
<Row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ReportTableListProps = {
monthsCount?: number;
groupBy: string;
renderItem;
compact: boolean;
};

export function ReportTableList({
Expand All @@ -20,6 +21,7 @@ export function ReportTableList({
mode,
groupBy,
renderItem,
compact,
}: ReportTableListProps) {
const groupByItem = ['Month', 'Year'].includes(groupBy) ? 'date' : 'name';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ReportTableTotalsProps = {
monthsCount: number;
totalScrollRef: RefProp<HTMLDivElement>;
handleScroll: UIEventHandler<HTMLDivElement>;
compact: boolean;
};

export function ReportTableTotals({
Expand All @@ -31,6 +32,7 @@ export function ReportTableTotals({
monthsCount,
totalScrollRef,
handleScroll,
compact,
}: ReportTableTotalsProps) {
const [scrollWidthTotals, setScrollWidthTotals] = useState(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ export function CustomReport() {
setScrollWidth={setScrollWidth}
months={months}
viewLabels={viewLabels}
compact={false}
/>
) : (
<LoadingIndicator message="Loading report..." />
Expand Down
5 changes: 4 additions & 1 deletion packages/desktop-client/src/hooks/useFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export function useFilters<T>(initialFilters: T[] = []) {

const onApply = useCallback(
newFilter => {
if (newFilter.conditions) {
if (newFilter === null) {
setFilters([]);
setSaved(null);
} else if (newFilter.conditions) {
setFilters([...newFilter.conditions]);
setConditionsOp(newFilter.conditionsOp);
setSaved(newFilter.id);
Expand Down
3 changes: 3 additions & 0 deletions packages/desktop-client/src/style/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export const styles = {
verySmallText: {
fontSize: 13,
},
tinyText: {
fontSize: 10,
},
page: {
flex: 1,
'@media (max-height: 550px)': {
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2245.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [carkom]
---

Adding compact identifier to all of the graphs and cleaning them up. Plus other staging bits for saving custom reports.