Skip to content

Commit

Permalink
hide liquidated assets by default (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasgerstmayr authored Feb 21, 2025
1 parent a5d8530 commit c12adaf
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 67 deletions.
32 changes: 28 additions & 4 deletions frontend/src/pages/Investments.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Alert } from "@mui/material";
import { Alert, FormControlLabel, FormGroup, Switch } from "@mui/material";
import { Link } from "react-router";
import { createEnumParam, StringParam, useQueryParams, withDefault } from "use-query-params";
import {
BooleanParam,
createEnumParam,
StringParam,
useQueryParam,
useQueryParams,
withDefault,
} from "use-query-params";
import { Investment, useInvestments } from "../api/investments";
import { Dashboard, DashboardRow, Panel } from "../components/Dashboard";
import {
Expand Down Expand Up @@ -53,6 +60,7 @@ export function InvestmentsTable({ groupBy }: InvestmentsTableProps) {
sortColumn: SortColumnParam,
sortOrder: SortOrderParam,
});
const [includeLiquidated, setIncludeLiquidated] = useQueryParam("liquidated", BooleanParam);

const handleSortChange = (column: SortableKeys) => {
if (sort.sortColumn === column) {
Expand All @@ -77,7 +85,7 @@ export function InvestmentsTable({ groupBy }: InvestmentsTableProps) {
);
}

const investments = data.investments.toSorted((a, b) => {
let investments = data.investments.toSorted((a, b) => {
const x = a[sort.sortColumn as SortableKeys];
const y = b[sort.sortColumn as SortableKeys];

Expand All @@ -90,8 +98,12 @@ export function InvestmentsTable({ groupBy }: InvestmentsTableProps) {
return x < y ? 1 : -1;
}
});
if (!includeLiquidated) {
investments = investments.filter((i) => i.marketValue > 0);
}
const percentFormatter = fixedPercentFormatter;
return (

const table = (
<table>
<thead>
<tr>
Expand Down Expand Up @@ -204,4 +216,16 @@ export function InvestmentsTable({ groupBy }: InvestmentsTableProps) {
</tbody>
</table>
);

return (
<>
{table}
<FormGroup>
<FormControlLabel
control={<Switch value={includeLiquidated} onChange={(_, value) => setIncludeLiquidated(value)} />}
label="Include liquidated investments"
/>
</FormGroup>
</>
);
}
Binary file modified frontend/tests/e2e/__image_snapshots__/groups.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/tests/e2e/__image_snapshots__/groups_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/tests/e2e/__image_snapshots__/investments.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/tests/e2e/__image_snapshots__/investments_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions frontend/tests/e2e/__snapshots__/pages.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3247,6 +3247,24 @@ exports[`HTML Snapshot Tests Groups (dark) 1`] = `
</tr>
</tbody>
</table>
<div class="MuiFormGroup-root css-1ytbthu">
<label class="MuiFormControlLabel-root MuiFormControlLabel-labelPlacementEnd css-ovwibz">
<span class="MuiSwitch-root MuiSwitch-sizeMedium css-bnbzk8">
<span class="MuiButtonBase-root MuiSwitch-switchBase MuiSwitch-colorPrimary PrivateSwitchBase-root MuiSwitch-switchBase MuiSwitch-colorPrimary css-1qiw127">
<input class="PrivateSwitchBase-input MuiSwitch-input css-j8yymo"
type="checkbox"
>
<span class="MuiSwitch-thumb css-1k5cbmd">
</span>
</span>
<span class="MuiSwitch-track css-11pcc8d">
</span>
</span>
<span class="MuiTypography-root MuiTypography-body1 MuiFormControlLabel-label css-mpcmsk">
Include liquidated investments
</span>
</label>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -3739,6 +3757,24 @@ exports[`HTML Snapshot Tests Groups 1`] = `
</tr>
</tbody>
</table>
<div class="MuiFormGroup-root css-1ytbthu">
<label class="MuiFormControlLabel-root MuiFormControlLabel-labelPlacementEnd css-ovwibz">
<span class="MuiSwitch-root MuiSwitch-sizeMedium css-bnbzk8">
<span class="MuiButtonBase-root MuiSwitch-switchBase MuiSwitch-colorPrimary PrivateSwitchBase-root MuiSwitch-switchBase MuiSwitch-colorPrimary css-1qiw127">
<input class="PrivateSwitchBase-input MuiSwitch-input css-j8yymo"
type="checkbox"
>
<span class="MuiSwitch-thumb css-1k5cbmd">
</span>
</span>
<span class="MuiSwitch-track css-11pcc8d">
</span>
</span>
<span class="MuiTypography-root MuiTypography-body1 MuiFormControlLabel-label css-mpcmsk">
Include liquidated investments
</span>
</label>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -4253,6 +4289,24 @@ exports[`HTML Snapshot Tests Investments (dark) 1`] = `
</tr>
</tbody>
</table>
<div class="MuiFormGroup-root css-1ytbthu">
<label class="MuiFormControlLabel-root MuiFormControlLabel-labelPlacementEnd css-ovwibz">
<span class="MuiSwitch-root MuiSwitch-sizeMedium css-bnbzk8">
<span class="MuiButtonBase-root MuiSwitch-switchBase MuiSwitch-colorPrimary PrivateSwitchBase-root MuiSwitch-switchBase MuiSwitch-colorPrimary css-1qiw127">
<input class="PrivateSwitchBase-input MuiSwitch-input css-j8yymo"
type="checkbox"
>
<span class="MuiSwitch-thumb css-1k5cbmd">
</span>
</span>
<span class="MuiSwitch-track css-11pcc8d">
</span>
</span>
<span class="MuiTypography-root MuiTypography-body1 MuiFormControlLabel-label css-mpcmsk">
Include liquidated investments
</span>
</label>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -4767,6 +4821,24 @@ exports[`HTML Snapshot Tests Investments 1`] = `
</tr>
</tbody>
</table>
<div class="MuiFormGroup-root css-1ytbthu">
<label class="MuiFormControlLabel-root MuiFormControlLabel-labelPlacementEnd css-ovwibz">
<span class="MuiSwitch-root MuiSwitch-sizeMedium css-bnbzk8">
<span class="MuiButtonBase-root MuiSwitch-switchBase MuiSwitch-colorPrimary PrivateSwitchBase-root MuiSwitch-switchBase MuiSwitch-colorPrimary css-1qiw127">
<input class="PrivateSwitchBase-input MuiSwitch-input css-j8yymo"
type="checkbox"
>
<span class="MuiSwitch-thumb css-1k5cbmd">
</span>
</span>
<span class="MuiSwitch-track css-11pcc8d">
</span>
</span>
<span class="MuiTypography-root MuiTypography-body1 MuiFormControlLabel-label css-mpcmsk">
Include liquidated investments
</span>
</label>
</div>
</div>
</div>
</div>
Expand Down
126 changes: 63 additions & 63 deletions src/fava_portfolio_returns/FavaPortfolioReturns.js

Large diffs are not rendered by default.

0 comments on commit c12adaf

Please sign in to comment.