Skip to content

A local-first personal finance app

fix: hidden category selection and include hidden when they are shown on budget (#5526)

Michael Süssemilch712d31522989
diff --git a/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx
index 05edc26de9..bf700b807b 100644
--- a/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx
+++ b/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx
@@ -80,14 +80,6 @@ function CategoryList({
const { t } = useTranslation();
let lastGroup: string | undefined | null = null;
- const filteredItems = useMemo(
- () =>
- showHiddenItems
- ? items
- : items.filter(item => !item.hidden && !item.group?.hidden),
- [showHiddenItems, items],
- );
-
return (
<View>
<View
@@ -98,7 +90,7 @@ function CategoryList({
...(!embedded && { maxHeight: 175 }),
}}
>
- {filteredItems.map((item, idx) => {
+ {items.map((item, idx) => {
if (item.id === 'split') {
return renderSplitTransactionButton({
key: 'split',
@@ -133,7 +125,9 @@ function CategoryList({
embedded,
style: {
...(showHiddenItems &&
- item.hidden && { color: theme.pageTextSubdued }),
+ (item.hidden || item.group?.hidden) && {
+ color: theme.pageTextSubdued,
+ }),
},
showBalances,
})}
@@ -193,24 +187,37 @@ export function CategoryAutocomplete({
...props
}: CategoryAutocompleteProps) {
const { grouped: defaultCategoryGroups = [] } = useCategories();
- const categorySuggestions: CategoryAutocompleteItem[] = useMemo(
- () =>
- (categoryGroups || defaultCategoryGroups).reduce(
- (list, group) =>
- list.concat(
- (group.categories || [])
- .filter(category => category.group === group.id)
- .map(category => ({
- ...category,
- group,
- })),
- ),
- showSplitOption
- ? [{ id: 'split', name: '' } as CategoryAutocompleteItem]
- : [],
- ),
- [defaultCategoryGroups, categoryGroups, showSplitOption],
- );
+ const categorySuggestions: CategoryAutocompleteItem[] = useMemo(() => {
+ const allSuggestions = (categoryGroups || defaultCategoryGroups).reduce(
+ (list, group) =>
+ list.concat(
+ (group.categories || [])
+ .filter(category => category.group === group.id)
+ .map(category => ({
+ ...category,
+ group,
+ })),
+ ),
+ showSplitOption
+ ? [{ id: 'split', name: '' } as CategoryAutocompleteItem]
+ : [],
+ );
+
+ if (!showHiddenCategories) {
+ return allSuggestions.filter(
+ suggestion =>
+ suggestion.id === 'split' ||
+ (!suggestion.hidden && !suggestion.group?.hidden),
+ );
+ }
+
+ return allSuggestions;
+ }, [
+ defaultCategoryGroups,
+ categoryGroups,
+ showSplitOption,
+ showHiddenCategories,
+ ]);
const filterSuggestions = useCallback(
(
@@ -429,7 +436,7 @@ function CategoryItem({
<View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
<TextOneLine>
{item.name}
- {item.hidden ? ' ' + t('(hidden)') : null}
+ {item.hidden || item.group?.hidden ? ' ' + t('(hidden)') : ''}
</TextOneLine>
<TextOneLine
style={{
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx
index 61f7ca7da0..97c53068a8 100644
--- a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx
+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx
@@ -70,6 +70,7 @@ import { useAccounts } from '@desktop-client/hooks/useAccounts';
import { useCategories } from '@desktop-client/hooks/useCategories';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
import { useInitialMount } from '@desktop-client/hooks/useInitialMount';
+import { useLocalPref } from '@desktop-client/hooks/useLocalPref';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
import { usePayees } from '@desktop-client/hooks/usePayees';
import {
@@ -486,6 +487,7 @@ const TransactionEditInner = memo(function TransactionEditInner({
const { t } = useTranslation();
const navigate = useNavigate();
const dispatch = useDispatch();
+ const [showHiddenCategories] = useLocalPref('budget.showHiddenCategories');
const transactions = useMemo(
() =>
unserializedTransactions.map(t => serializeTransaction(t, dateFormat)) ||
@@ -647,6 +649,7 @@ const TransactionEditInner = memo(function TransactionEditInner({
name: 'category-autocomplete',
options: {
categoryGroups,
+ showHiddenCategories,
month: monthUtils.monthFromDate(
unserializedTransaction.date,
),
@@ -728,6 +731,7 @@ const TransactionEditInner = memo(function TransactionEditInner({
transaction.id,
transactions,
unserializedTransactions,
+ showHiddenCategories,
],
);
diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.tsx b/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
index deae805146..78f2d5f1ea 100644
--- a/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
@@ -109,6 +109,7 @@ import {
import { useCachedSchedules } from '@desktop-client/hooks/useCachedSchedules';
import { useContextMenu } from '@desktop-client/hooks/useContextMenu';
import { useDisplayPayee } from '@desktop-client/hooks/useDisplayPayee';
+import { useLocalPref } from '@desktop-client/hooks/useLocalPref';
import { useMergedRefs } from '@desktop-client/hooks/useMergedRefs';
import { usePrevious } from '@desktop-client/hooks/usePrevious';
import { useProperFocus } from '@desktop-client/hooks/useProperFocus';
@@ -866,6 +867,7 @@ type TransactionProps = {
listContainerRef?: RefObject<HTMLDivElement>;
showSelection?: boolean;
allowSplitTransaction?: boolean;
+ showHiddenCategories?: boolean;
};
const Transaction = memo(function Transaction({
@@ -912,6 +914,7 @@ const Transaction = memo(function Transaction({
listContainerRef,
showSelection,
allowSplitTransaction,
+ showHiddenCategories,
}: TransactionProps) {
const { t } = useTranslation();
@@ -1567,7 +1570,7 @@ const Transaction = memo(function Transaction({
inputProps={{ onBlur, onKeyDown, style: inputStyle }}
onUpdate={onUpdate}
onSelect={onSave}
- showHiddenCategories={false}
+ showHiddenCategories={showHiddenCategories}
/>
</SheetNameProvider>
)}
@@ -1771,6 +1774,7 @@ type NewTransactionProps = {
transferAccountsByTransaction: {
[id: TransactionEntity['id']]: AccountEntity | null;
};
+ showHiddenCategories?: boolean;
};
function NewTransaction({
transactions,
@@ -1800,6 +1804,7 @@ function NewTransaction({
onNavigateToSchedule,
onNotesTagClick,
balance,
+ showHiddenCategories,
}: NewTransactionProps) {
const error = transactions[0].error;
const isDeposit = transactions[0].amount > 0;
@@ -1862,6 +1867,7 @@ function NewTransaction({
balance={balance ?? 0}
showSelection={true}
allowSplitTransaction={true}
+ showHiddenCategories={showHiddenCategories}
/>
))}
<View
@@ -1980,6 +1986,7 @@ type TransactionTableInnerProps = {
onManagePayees: (id?: PayeeEntity['id']) => void;
onSort: (field: string, ascDesc: 'asc' | 'desc') => void;
+ showHiddenCategories?: boolean;
};
function TransactionTableInner({
@@ -1989,6 +1996,7 @@ function TransactionTableInner({
dateFormat = 'MM/dd/yyyy',
newNavigator,
renderEmpty,
+ showHiddenCategories,
...props
}: TransactionTableInnerProps) {
const containerRef = createRef<HTMLDivElement>();
@@ -2153,6 +2161,7 @@ function TransactionTableInner({
listContainerRef={listContainerRef}
showSelection={showSelection}
allowSplitTransaction={allowSplitTransaction}
+ showHiddenCategories={showHiddenCategories}
/>
);
};
@@ -2215,6 +2224,7 @@ function TransactionTableInner({
onNavigateToSchedule={onNavigateToSchedule}
onNotesTagClick={onNotesTagClick}
onDistributeRemainder={props.onDistributeRemainder}
+ showHiddenCategories={showHiddenCategories}
/>
</View>
)}
@@ -2325,6 +2335,7 @@ export const TransactionTable = forwardRef(
const { t } = useTranslation();
const dispatch = useDispatch();
+ const [showHiddenCategories] = useLocalPref('budget.showHiddenCategories');
const [newTransactions, setNewTransactions] = useState<
TransactionEntity[] | null
>(null);
@@ -2945,6 +2956,7 @@ export const TransactionTable = forwardRef(
newNavigator={newNavigator}
showSelection={props.showSelection}
allowSplitTransaction={props.allowSplitTransaction}
+ showHiddenCategories={showHiddenCategories}
/>
);
},
diff --git a/packages/desktop-client/src/components/util/GenericInput.jsx b/packages/desktop-client/src/components/util/GenericInput.jsx
index 09dc2be023..4f906155df 100644
--- a/packages/desktop-client/src/components/util/GenericInput.jsx
+++ b/packages/desktop-client/src/components/util/GenericInput.jsx
@@ -133,7 +133,7 @@ export function GenericInput({
value={value}
openOnFocus={true}
onSelect={onChange}
- showHiddenCategories={false}
+ showHiddenCategories={true}
inputProps={{
ref,
...(showPlaceholder ? { placeholder: t('nothing') } : null),
diff --git a/upcoming-release-notes/5526.md b/upcoming-release-notes/5526.md
new file mode 100644
index 0000000000..741530d946
--- /dev/null
+++ b/upcoming-release-notes/5526.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [misu-dev]
+---
+
+Fixes a bug where sometimes hidden categories get selected in the transaction table