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: hide "show ..." checkboxes in menu #2174

Merged
merged 44 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
aed3fdd
Add Toggles
carkom Dec 16, 2023
28975b7
budget table
carkom Dec 16, 2023
1c638f5
testing
carkom Dec 19, 2023
bb043eb
updates
carkom Dec 20, 2023
2f52f48
updates
carkom Dec 20, 2023
4b31ab3
fixes
carkom Dec 20, 2023
481a6c9
updates
carkom Dec 20, 2023
ea7ae68
Merge remote-tracking branch 'upstream/master' into toggle
carkom Jan 4, 2024
29ba32c
fix Menu
carkom Jan 4, 2024
25ef687
lint fixes
carkom Jan 4, 2024
9d3ae9e
fix keybindings
carkom Jan 5, 2024
ae80b8a
revert budget menu changes
carkom Jan 5, 2024
2f0711d
notes
carkom Jan 5, 2024
d2b776f
remove default exports
carkom Jan 5, 2024
f0aa4a0
fixes
carkom Jan 5, 2024
3aab8bc
disabled fix
carkom Jan 5, 2024
419abd7
add style option
carkom Jan 5, 2024
280a79e
lint fix
carkom Jan 5, 2024
9309435
remove css
carkom Jan 6, 2024
d1cff7c
Merge branch 'master' into toggle
carkom Jan 6, 2024
de9cc38
lint fixes
carkom Jan 6, 2024
f04ddd1
color updates
carkom Jan 6, 2024
e266752
Merge branch 'master' into toggle
carkom Jan 6, 2024
46adddf
Merge branch 'master' into toggle
carkom Jan 6, 2024
ddebe3f
Merge branch 'master' into toggle
carkom Jan 11, 2024
5cf9ecc
merge menu with togglemenu
carkom Jan 12, 2024
319e18f
Merge branch 'master' into toggle
carkom Jan 12, 2024
ce4a0e4
host
carkom Jan 12, 2024
3456b7c
menu fixes
carkom Jan 12, 2024
7cf587e
fix regression
carkom Jan 12, 2024
d958c6f
remove host
carkom Jan 13, 2024
65ec3fa
Merge branch 'master' into toggle
carkom Jan 13, 2024
fb5ed9f
adjustments
carkom Jan 13, 2024
673732b
onToggle
carkom Jan 13, 2024
a1f88eb
Merge branch 'master' into toggle
carkom Jan 15, 2024
17eb080
vrt fix
carkom Jan 15, 2024
13241f9
typecheck
carkom Jan 15, 2024
436d76d
Merge branch 'master' into toggle
carkom Jan 16, 2024
cc62af1
Merge branch 'master' into toggle
carkom Jan 16, 2024
bd26630
Merge branch 'master' into toggle
carkom Jan 22, 2024
f60be9b
merge fixes
carkom Jan 22, 2024
25cbe0c
colors
carkom Jan 22, 2024
bd81bba
lint fix
carkom Jan 22, 2024
3c1feca
Merge branch 'master' into toggle
carkom Jan 23, 2024
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
56 changes: 42 additions & 14 deletions packages/desktop-client/src/components/common/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { type CSSProperties, theme } from '../../style';

import { Text } from './Text';
import { Toggle } from './Toggle';
import { View } from './View';

type KeybindingProps = {
Expand All @@ -33,6 +34,8 @@ type MenuItem = {
text: string;
key?: string;
style?: CSSProperties;
toggle?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it work if we introduce a new TogglableMenuItem which extends from MenuItem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works if we are looking to group toggled items and non-toggled items. If you want a menu with (regular item, toggle item, regular item, toggle item) then a separate toggleitem group would not work without an overly complicated code set. I know we have a couple complex menus right now. Not sure there's any that fit this use case currently but I can imagine we may want this ability in the future.

Thoughts?

Copy link
Contributor Author

@carkom carkom Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joel-jeremy I'd love to have your thoughts on grouping toggle items at top or bottom vs my proposal which would allow for them to be used anywhere in the list. Cheers!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it wouldn't hurt to allow the consumer of the component to place the toggle/regular item wherever it sees fit. It could group the toggles together or not, the component provides the flexibility. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @joel-jeremy, I've sent you a couple messages via discord. I don't see a way to implement how you are suggesting. Can you give me some guidance? If you don't have time to write anything right now, would you be okay with approving as is and we can adjust it to your vision in a new PR?

tooltip?: string;
};

type MenuProps<T extends MenuItem = MenuItem> = {
Expand Down Expand Up @@ -164,23 +167,48 @@ export function Menu<T extends MenuItem>({
onMouseEnter={() => setHoveredIndex(idx)}
onMouseLeave={() => setHoveredIndex(null)}
onClick={() =>
!item.disabled && onMenuSelect && onMenuSelect(item.name)
!item.disabled &&
onMenuSelect &&
item.toggle === undefined &&
onMenuSelect(item.name)
}
>
{/* Force it to line up evenly */}
<Text style={{ lineHeight: 0 }}>
{item.icon &&
createElement(item.icon, {
width: item.iconSize || 10,
height: item.iconSize || 10,
style: {
marginRight: 7,
width: item.iconSize || 10,
},
})}
</Text>
<Text>{item.text}</Text>
<View style={{ flex: 1 }} />
{item.toggle === undefined ? (
<>
<Text style={{ lineHeight: 0 }}>
{item.icon &&
createElement(item.icon, {
width: item.iconSize || 10,
height: item.iconSize || 10,
style: {
marginRight: 7,
width: item.iconSize || 10,
},
})}
</Text>
<Text title={item.tooltip}>{item.text}</Text>
<View style={{ flex: 1 }} />
</>
) : (
<>
<label htmlFor={item.name} title={item.tooltip}>
{item.text}
</label>
<View style={{ flex: 1 }} />
<Toggle
id={item.name}
checked={item.toggle}
onColor={theme.pageTextPositive}
style={{ marginLeft: 5, ...item.style }}
onToggle={() =>
!item.disabled &&
item.toggle !== undefined &&
onMenuSelect(item.name)
}
/>
</>
)}
{item.key && <Keybinding keyName={item.key} />}
</View>
);
Expand Down
75 changes: 75 additions & 0 deletions packages/desktop-client/src/components/common/Toggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React from 'react';

import { css } from 'glamor';

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

type ToggleProps = {
id: string;
checked: boolean;
onToggle?: () => void;
onColor?: string;
style?: CSSProperties;
};

export const Toggle = ({
id,
checked,
onToggle,
onColor,
style,
}: ToggleProps) => {
return (
<div style={{ marginTop: -20, ...style }}>
<input
id={id}
checked={checked}
onChange={onToggle}
className={`${css({
height: 0,
width: 0,
visibility: 'hidden',
})}`}
type="checkbox"
/>
<label
style={{
background: checked ? onColor : theme.checkboxToggleBackground,
}}
className={`${css({
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
cursor: 'pointer',
width: '32px',
height: '16px',
borderRadius: '100px',
position: 'relative',
transition: 'background-color .2s',
})}`}
htmlFor={id}
>
<span
className={`${css(
{
content: '',
position: 'absolute',
top: '2px',
left: '2px',
width: '12px',
height: '12px',
borderRadius: '100px',
transition: '0.2s',
background: '#fff',
boxShadow: '0 0 2px 0 rgba(10, 10, 10, 0.29)',
},
checked && {
left: 'calc(100% - 2px)',
transform: 'translateX(-100%)',
},
)}`}
/>
</label>
</div>
);
};
125 changes: 60 additions & 65 deletions packages/desktop-client/src/components/reports/ReportSidebar.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react';
import React, { useState } from 'react';

import * as monthUtils from 'loot-core/src/shared/months';

import { theme } from '../../style';
import { Button } from '../common/Button';
import { Menu } from '../common/Menu';
import { Select } from '../common/Select';
import { Text } from '../common/Text';
import { View } from '../common/View';
import { Checkbox } from '../forms';
import { Tooltip } from '../tooltips';

import { CategorySelector } from './CategorySelector';
import {
Expand Down Expand Up @@ -39,6 +41,7 @@ export function ReportSidebar({
onChangeDates,
onChangeViews,
}) {
const [menuOpen, setMenuOpen] = useState(false);
const onSelectRange = cond => {
setDateRange(cond);
switch (cond) {
Expand Down Expand Up @@ -242,70 +245,62 @@ export function ReportSidebar({
}}
>
<Text style={{ width: 40, textAlign: 'right', marginRight: 5 }} />

<Checkbox
id="show-empty-columns"
checked={customReportItems.showEmpty}
value={customReportItems.showEmpty}
onChange={() => setShowEmpty(!customReportItems.showEmpty)}
/>
<label
htmlFor="show-empty-columns"
title="Show rows that are zero or blank"
style={{ fontSize: 12 }}
>
Show Empty Rows
</label>
</View>
<View
style={{
flexDirection: 'row',
padding: 5,
alignItems: 'center',
}}
>
<Text style={{ width: 40, textAlign: 'right', marginRight: 5 }} />

<Checkbox
id="show-hidden-columns"
checked={customReportItems.showOffBudgetHidden}
value={customReportItems.showOffBudgetHidden}
onChange={() =>
setShowOffBudgetHidden(!customReportItems.showOffBudgetHidden)
}
/>
<label
htmlFor="show-hidden-columns"
title="Show off budget accounts and hidden categories"
style={{ fontSize: 12 }}
>
Off Budget Items
</label>
</View>
<View
style={{
flexDirection: 'row',
padding: 5,
alignItems: 'center',
}}
>
<Text style={{ width: 40, textAlign: 'right', marginRight: 5 }} />

<Checkbox
id="show-uncategorized"
checked={customReportItems.showUncategorized}
value={customReportItems.showUncategorized}
onChange={() =>
setShowUncategorized(!customReportItems.showUncategorized)
}
/>
<label
htmlFor="show-uncategorized"
title="Show uncategorized transactions"
style={{ fontSize: 12 }}
<Button
onClick={() => {
setMenuOpen(true);
}}
style={{
color: 'currentColor',
padding: '5px 10px',
}}
>
Uncategorized
</label>
Options
{menuOpen && (
<Tooltip
position="bottom-left"
style={{ padding: 0 }}
onClose={() => {
setMenuOpen(false);
}}
>
<Menu
onMenuSelect={type => {
if (type === 'show-hidden-categories') {
setShowOffBudgetHidden(
!customReportItems.showOffBudgetHidden,
);
} else if (type === 'show-empty-rows') {
setShowEmpty(!customReportItems.showEmpty);
} else if (type === 'show-uncategorized') {
setShowUncategorized(
!customReportItems.showUncategorized,
);
}
}}
items={[
{
name: 'show-empty-rows',
text: 'Show Empty Rows',
tooltip: 'Show rows that are zero or blank',
toggle: customReportItems.showEmpty,
},
{
name: 'show-hidden-categories',
text: 'Show Off Budget',
tooltip: 'Show off budget accounts and hidden categories',
toggle: customReportItems.showOffBudgetHidden,
},
{
name: 'show-uncategorized',
text: 'Show Uncategorized',
tooltip: 'Show uncategorized transactions',
toggle: customReportItems.showUncategorized,
},
]}
/>
</Tooltip>
)}
</Button>
</View>
<View
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const adjustTextSize = (
let source;
switch (type) {
case 'variable':
source = variableLookup.find(({ value }) => values > value).arr;
source = variableLookup.find(({ value }) => values >= value).arr;
break;
case 'donut':
source = donutLookup;
Expand Down
1 change: 1 addition & 0 deletions packages/desktop-client/src/style/themes/dark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const checkboxText = tableText;
export const checkboxBackgroundSelected = colorPalette.purple300;
export const checkboxBorderSelected = colorPalette.purple300;
export const checkboxShadowSelected = colorPalette.purple500;
export const checkboxToggleBackground = colorPalette.gray700;

export const pillBackground = colorPalette.navy800;
export const pillBackgroundLight = colorPalette.navy900;
Expand Down
1 change: 1 addition & 0 deletions packages/desktop-client/src/style/themes/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const checkboxText = tableBackground;
export const checkboxBackgroundSelected = colorPalette.blue500;
export const checkboxBorderSelected = colorPalette.blue500;
export const checkboxShadowSelected = colorPalette.blue300;
export const checkboxToggleBackground = colorPalette.gray400;

export const pillBackground = colorPalette.navy150;
export const pillBackgroundLight = colorPalette.navy100;
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2174.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [carkom]
---

Hide "show ..." checkboxes within menu for custom reports page. Introduce toggle switches.
Loading