Skip to content

Commit

Permalink
Hide hidden categories in auto-complete (#2429)
Browse files Browse the repository at this point in the history
* the work

* notes

* add to elements
  • Loading branch information
carkom authored Mar 11, 2024
1 parent 998efb9 commit 5bcfc71
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type CategoryListProps = {
) => ReactNode;
renderCategoryItemGroupHeader?: (props: ItemHeaderProps) => ReactNode;
renderCategoryItem?: (props: CategoryItemProps) => ReactNode;
showHiddenItems?: boolean;
};
function CategoryList({
items,
Expand All @@ -46,6 +47,7 @@ function CategoryList({
renderSplitTransactionButton = defaultRenderSplitTransactionButton,
renderCategoryItemGroupHeader = defaultRenderCategoryItemGroupHeader,
renderCategoryItem = defaultRenderCategoryItem,
showHiddenItems,
}: CategoryListProps) {
let lastGroup: string | undefined | null = null;

Expand All @@ -68,6 +70,10 @@ function CategoryList({
});
}

if ((item.hidden || item.group?.hidden) && !showHiddenItems) {
return <Fragment key={item.id} />;
}

const showGroup = item.cat_group !== lastGroup;
lastGroup = item.cat_group;
return (
Expand All @@ -76,6 +82,13 @@ function CategoryList({
<Fragment key={item.group.name}>
{renderCategoryItemGroupHeader({
title: item.group.name,
style: {
color:
showHiddenItems && item.group?.hidden
? theme.pageTextSubdued
: theme.menuAutoCompleteTextHeader,
},
item: item.group,
})}
</Fragment>
)}
Expand All @@ -85,6 +98,12 @@ function CategoryList({
item,
highlighted: highlightedIndex === idx,
embedded,
style: {
color:
showHiddenItems && item.hidden
? theme.pageTextSubdued
: 'inherit',
},
})}
</Fragment>
</Fragment>
Expand All @@ -104,6 +123,7 @@ type CategoryAutocompleteProps = ComponentProps<typeof Autocomplete> & {
) => ReactNode;
renderCategoryItemGroupHeader?: (props: ItemHeaderProps) => ReactNode;
renderCategoryItem?: (props: CategoryItemProps) => ReactNode;
showHiddenItems?: boolean;
};

export function CategoryAutocomplete({
Expand All @@ -114,6 +134,7 @@ export function CategoryAutocomplete({
renderSplitTransactionButton,
renderCategoryItemGroupHeader,
renderCategoryItem,
showHiddenItems,
...props
}: CategoryAutocompleteProps) {
const categorySuggestions: Array<
Expand Down Expand Up @@ -167,6 +188,7 @@ export function CategoryAutocomplete({
renderSplitTransactionButton={renderSplitTransactionButton}
renderCategoryItemGroupHeader={renderCategoryItemGroupHeader}
renderCategoryItem={renderCategoryItem}
showHiddenItems={showHiddenItems}
/>
)}
{...props}
Expand Down Expand Up @@ -268,13 +290,15 @@ type CategoryItemProps = {
export function CategoryItem({
item,
className,
style,
highlighted,
embedded,
...props
}: CategoryItemProps) {
const { isNarrowWidth } = useResponsive();
return (
<div
style={style}
// See comment above.
role="button"
className={`${className} ${css([
Expand All @@ -294,6 +318,7 @@ export function CategoryItem({
{...props}
>
{item.name}
{item.hidden ? ' (hidden)' : null}
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import React from 'react';

import { type CategoryGroupEntity } from 'loot-core/types/models/category-group';

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

export type ItemHeaderProps = {
title: string;
style?: CSSProperties;
type?: string;
item?: CategoryGroupEntity;
};

export function ItemHeader({ title, style, type, ...props }: ItemHeaderProps) {
export function ItemHeader({
title,
style,
type,
item,
...props
}: ItemHeaderProps) {
return (
<div
style={{
Expand All @@ -21,6 +30,7 @@ export function ItemHeader({ title, style, type, ...props }: ItemHeaderProps) {
{...props}
>
{title}
{item?.hidden ? ' (hidden)' : null}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function CoverTooltip({
}
},
}}
showHiddenItems={false}
/>
)}
</InitialFocus>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export function TransferTooltip({
onUpdate={() => {}}
onSelect={id => setCategory(id)}
inputProps={{ onEnter: submit, placeholder: '(none)' }}
showHiddenItems={true}
/>

<View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export function CloseAccount({
setCategoryError(false);
}
}}
showHiddenItems={true}
/>

{categoryError && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export function ConfirmCategoryDelete({
placeholder: 'Select category...',
}}
onSelect={category => setTransferCategory(category)}
showHiddenItems={true}
/>
</View>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export function EditField({ modalProps, name, onSubmit, onClose }) {
),
})}
{...autocompleteProps}
showHiddenItems={false}
/>
);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@ const Transaction = memo(function Transaction(props) {
onUpdate={onUpdate}
onSelect={onSave}
menuPortalTarget={undefined}
showHiddenItems={false}
/>
)}
</CustomCell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function GenericInput({
multi={multi}
openOnFocus={true}
onSelect={onChange}
showHiddenItems={false}
inputProps={{
inputRef,
...(showPlaceholder ? { placeholder: 'nothing' } : null),
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2429.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [Shazib, carkom]
---

Hide hidden categories on the Category AutoComplete. Allow a prop for showing (with indication).

0 comments on commit 5bcfc71

Please sign in to comment.