Skip to content

Commit

Permalink
Hide hidden groups and categories in spending report category selector
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Löthberg <[email protected]>
  • Loading branch information
kyrias committed Sep 13, 2023
1 parent b6100cf commit f560015
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 106 deletions.
219 changes: 113 additions & 106 deletions packages/desktop-client/src/components/reports/CategorySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,117 +53,124 @@ export default function CategorySelector({
}}
>
{categoryGroups &&
categoryGroups.map(categoryGroup => {
const allCategoriesInGroupSelected = categoryGroup.categories.every(
category =>
selectedCategories.some(
selectedCategory => selectedCategory.id === category.id,
),
);
const noCategorySelected = categoryGroup.categories.every(
category =>
!selectedCategories.some(
selectedCategory => selectedCategory.id === category.id,
),
);
return (
<Fragment key={categoryGroup.id}>
<li
style={{
display:
noCategorySelected && uncheckedHidden ? 'none' : 'flex',
marginBottom: 8,
flexDirection: 'row',
}}
>
<Checkbox
id={`form_${categoryGroup.id}`}
checked={allCategoriesInGroupSelected}
onChange={e => {
const selectedCategoriesExcludingGroupCategories =
selectedCategories.filter(
selectedCategory =>
!categoryGroup.categories.some(
groupCategory =>
groupCategory.id === selectedCategory.id,
),
);
if (allCategoriesInGroupSelected) {
setSelectedCategories(
selectedCategoriesExcludingGroupCategories,
);
} else {
setSelectedCategories(
selectedCategoriesExcludingGroupCategories.concat(
categoryGroup.categories,
),
);
}
}}
/>
<label
htmlFor={`form_${categoryGroup.id}`}
style={{ userSelect: 'none', fontWeight: 'bold' }}
>
{categoryGroup.name}
</label>
</li>
<li>
<ul
categoryGroups
.filter(categoryGroup => !categoryGroup.hidden)

Check failure on line 57 in packages/desktop-client/src/components/reports/CategorySelector.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Property 'hidden' does not exist on type 'CategoryGroup'.
.map(categoryGroup => {
const visibleCategories = categoryGroup.categories.filter(
category => !category.hidden,

Check failure on line 60 in packages/desktop-client/src/components/reports/CategorySelector.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Property 'hidden' does not exist on type 'Category'.
);

const allCategoriesInGroupSelected = visibleCategories.every(
category =>
selectedCategories.some(
selectedCategory => selectedCategory.id === category.id,
),
);
const noCategorySelected = visibleCategories.every(
category =>
!selectedCategories.some(
selectedCategory => selectedCategory.id === category.id,
),
);
return (
<Fragment key={categoryGroup.id}>
<li
style={{
listStyle: 'none',
marginLeft: 0,
marginBottom: 10,
paddingLeft: 10,
display:
noCategorySelected && uncheckedHidden ? 'none' : 'flex',
marginBottom: 8,
flexDirection: 'row',
}}
>
{categoryGroup.categories.map((category, index) => {
const isChecked = selectedCategories.some(
selectedCategory => selectedCategory.id === category.id,
);
return (
<li
key={category.id}
style={{
display:
!isChecked && uncheckedHidden ? 'none' : 'flex',
flexDirection: 'row',
marginBottom: 4,
}}
>
<Checkbox
id={`form_${category.id}`}
checked={isChecked}
onChange={e => {
if (isChecked) {
setSelectedCategories(
selectedCategories.filter(
selectedCategory =>
selectedCategory.id !== category.id,
),
);
} else {
setSelectedCategories([
...selectedCategories,
category,
]);
}
<Checkbox
id={`form_${categoryGroup.id}`}
checked={allCategoriesInGroupSelected}
onChange={e => {
const selectedCategoriesExcludingGroupCategories =
selectedCategories.filter(
selectedCategory =>
!visibleCategories.some(
groupCategory =>
groupCategory.id === selectedCategory.id,
),
);
if (allCategoriesInGroupSelected) {
setSelectedCategories(
selectedCategoriesExcludingGroupCategories,
);
} else {
setSelectedCategories(
selectedCategoriesExcludingGroupCategories.concat(
visibleCategories,
),
);
}
}}
/>
<label
htmlFor={`form_${categoryGroup.id}`}
style={{ userSelect: 'none', fontWeight: 'bold' }}
>
{categoryGroup.name}
</label>
</li>
<li>
<ul
style={{
listStyle: 'none',
marginLeft: 0,
marginBottom: 10,
paddingLeft: 10,
}}
>
{visibleCategories.map((category, index) => {
const isChecked = selectedCategories.some(
selectedCategory =>
selectedCategory.id === category.id,
);
return (
<li
key={category.id}
style={{
display:
!isChecked && uncheckedHidden ? 'none' : 'flex',
flexDirection: 'row',
marginBottom: 4,
}}
/>
<label
htmlFor={`form_${category.id}`}
style={{ userSelect: 'none' }}
>
{category.name}
</label>
</li>
);
})}
</ul>
</li>
</Fragment>
);
})}
<Checkbox
id={`form_${category.id}`}
checked={isChecked}
onChange={e => {
if (isChecked) {
setSelectedCategories(
selectedCategories.filter(
selectedCategory =>
selectedCategory.id !== category.id,
),
);
} else {
setSelectedCategories([
...selectedCategories,
category,
]);
}
}}
/>
<label
htmlFor={`form_${category.id}`}
style={{ userSelect: 'none' }}
>
{category.name}
</label>
</li>
);
})}
</ul>
</li>
</Fragment>
);
})}
</ul>
</>
);
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/1696.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancement
authors: [kyrias]
---

Hide hidden groups and categories from spending report category selector.

0 comments on commit f560015

Please sign in to comment.