Skip to content

Commit

Permalink
fix overview card, fix offbudget checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
carkom committed Oct 24, 2023
1 parent a432aae commit 7d99b30
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 78 deletions.
87 changes: 58 additions & 29 deletions packages/desktop-client/src/components/reports/Custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as d from 'date-fns';

import { send } from 'loot-core/src/platform/client/fetch';
import * as monthUtils from 'loot-core/src/shared/months';
import { integerToCurrency } from 'loot-core/src/shared/util';
import { amountToCurrency } from 'loot-core/src/shared/util';

import useCategories from '../../hooks/useCategories';
import useFilters from '../../hooks/useFilters';
Expand All @@ -16,6 +16,8 @@ import ChartPie from '../../icons/v1/ChartPie';
import InboxFull from '../../icons/v1/InboxFull';
import ListBullet from '../../icons/v1/ListBullet';
import { theme, styles } from '../../style';
import AlignedText from '../common/AlignedText';
import Block from '../common/Block';
import Button from '../common/Button';
import Select from '../common/Select';
import Text from '../common/Text';
Expand All @@ -24,7 +26,6 @@ import { FilterButton, AppliedFilters } from '../filters/FiltersMenu';
import { Checkbox } from '../forms';
import PrivacyFilter from '../PrivacyFilter';

import Change from './Change';
import AreaGraph from './graphs/AreaGraph';
import BarGraph from './graphs/BarGraph';
import BarLineGraph from './graphs/BarLineGraph';
Expand Down Expand Up @@ -108,7 +109,7 @@ export default function Custom() {

const [allMonths, setAllMonths] = useState(null);
const [start, setStart] = useState(
monthUtils.subMonths(monthUtils.currentMonth(), 5),
monthUtils.subMonths(monthUtils.currentMonth(), 1),
);
const [end, setEnd] = useState(monthUtils.currentMonth());

Expand All @@ -135,8 +136,19 @@ export default function Custom() {
accounts,
filters,
conditionsOp,
hidden,
);
}, [start, end, split, categories, payees, accounts, filters, conditionsOp]);
}, [
start,
end,
split,
categories,
payees,
accounts,
filters,
conditionsOp,
hidden,
]);
const data = useReport('default', getGraphData);

useEffect(() => {
Expand Down Expand Up @@ -762,31 +774,6 @@ export default function Custom() {
flexGrow: 1,
}}
>
{graphType !== 'TableGraph' && (
<View
style={{
textAlign: 'right',
paddingTop: 10,
paddingRight: 20,
flexShrink: 0,
}}
>
<View
style={{
...styles.largeText,
fontWeight: 400,
marginBottom: 5,
}}
>
<PrivacyFilter blurIntensity={5}>
{integerToCurrency(0)}
</PrivacyFilter>
</View>
<PrivacyFilter>
<Change amount={0} />
</PrivacyFilter>
</View>
)}
<View
style={{
flexDirection: 'row',
Expand All @@ -801,6 +788,48 @@ export default function Custom() {
paddingTop: 0,
}}
>
{graphType !== 'TableGraph' && (
<View
style={{
alignItems: 'flex-end',
paddingTop: 10,
}}
>
<View
style={{
...styles.mediumText,
fontWeight: 500,
marginBottom: 5,
}}
>
<AlignedText
left={
<Block>
{
typeOptions.find(opt => opt.value === type)
.description
}
:
</Block>
}
right={
<Text>
<PrivacyFilter blurIntensity={5}>
{amountToCurrency(
Math.abs(
data[
typeOptions.find(opt => opt.value === type)
.format
],
),
)}
</PrivacyFilter>
</Text>
}
/>
</View>
</View>
)}
<GraphType />
</View>
{(viewSplit || viewSummary) && (
Expand Down
40 changes: 13 additions & 27 deletions packages/desktop-client/src/components/reports/Overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ function CashFlowCard() {

const params = useMemo(() => simpleCashFlow(start, end), [start, end]);
const data = useReport('cash_flow_simple', params);

const [isCardHovered, setIsCardHovered] = useState(false);
const onCardHover = useCallback(() => setIsCardHovered(true));
const onCardHoverEnd = useCallback(() => setIsCardHovered(false));
Expand Down Expand Up @@ -359,11 +360,12 @@ function CustomReportsCard() {
<BarGraph
start={start}
end={end}
graphData={data}
data={data}
compact={true}
split={1}
empty={true}
typeOp={'totalDebts'}
style={{ height: 'auto', flex: 1 }}
/>
) : (
<LoadingIndicator />
Expand Down Expand Up @@ -396,32 +398,16 @@ export default function Overview() {
<NetWorthCard accounts={accounts} />
<CashFlowCard />
</View>

{categorySpendingReportFeatureFlag && (
<View
style={{
flex: '0 0 auto',
flexDirection: 'row',
}}
>
<CategorySpendingCard />
<div style={{ flex: 1 }} />
<div style={{ flex: 1 }} />
</View>
)}

{customReportsFeatureFlag && (
<View
style={{
flex: '0 0 auto',
flexDirection: 'row',
}}
>
<CustomReportsCard />
<div style={{ flex: 1 }} />
<div style={{ flex: 1 }} />
</View>
)}
<View
style={{
flex: '0 0 auto',
flexDirection: 'row',
}}
>
{categorySpendingReportFeatureFlag && <CategorySpendingCard />}
{customReportsFeatureFlag && <CustomReportsCard />}
<div style={{ flex: 1 }} />
</View>
</View>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function BarGraph({
}
margin={{ top: 0, right: 0, left: 0, bottom: 0 }}
>
<Legend content={<CustomLegend />} />
{compact ? null : <Legend content={<CustomLegend />} />}
<Tooltip
content={<CustomTooltip />}
formatter={numberFormatterTooltip}
Expand All @@ -199,7 +199,11 @@ function BarGraph({
.map((entry, index) => (
<Cell
key={`cell-${index}`}
fill={colorScale[index % colorScale.length]}
fill={
yAxis === 'date'
? theme.reportsBlue
: colorScale[index % colorScale.length]
}
name={entry.name}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function createSpreadsheet(
accounts,
conditions = [],
conditionsOp,
hidden,
) {
let splitItem;
let splitList;
Expand Down Expand Up @@ -73,41 +74,57 @@ export default function createSpreadsheet(
let [starting, balances] = await Promise.all([
runQuery(
q('transactions')
.filter(
!hidden && {
$and: [
{
'account.offbudget': false,
'category.hidden': false,
},
],
$or: [
{
'payee.transfer_acct.offbudget': true,
'payee.transfer_acct': null,
},
],
},
)
.filter({
[conditionsOpKey]: filters,
[splitLabel]: splt.id,
'account.offbudget': false,
'category.hidden': false,
date: { $lt: start + '-01' },
$or: [
{
'payee.transfer_acct.offbudget': true,
'payee.transfer_acct': null,
},
$and: [
{ [conditionsOpKey]: filters },
{ date: { $lt: start + '-01' } },
],
})
.calculate({ $sum: '$amount' }),
).then(({ data }) => data),

runQuery(
q('transactions')
.filter({
[conditionsOpKey]: [...filters],
})
.filter(
!hidden && {
$and: [
{
'account.offbudget': false,
'category.hidden': false,
},
],
$or: [
{
'payee.transfer_acct.offbudget': true,
'payee.transfer_acct': null,
},
],
},
)
.filter({
[splitLabel]: splt.id,
'account.offbudget': false,
'category.hidden': false,
$and: [
{ [conditionsOpKey]: filters },
{ date: { $gte: start + '-01' } },
{ date: { $lte: end + '-31' } },
],
$or: [
{
'payee.transfer_acct.offbudget': true,
'payee.transfer_acct': null,
},
],
})
.groupBy({ $month: '$date' })
.select([
Expand Down

0 comments on commit 7d99b30

Please sign in to comment.