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

fix(Catalog): Using labels causes unintended navigation #1078

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions packages/ui/src/components/Catalog/BaseCatalog.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.catalog-list {
overflow: auto;
padding: var(--pf-v5-global--spacer--sm);
}
2 changes: 1 addition & 1 deletion packages/ui/src/components/Catalog/Catalog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
flex-direction: column;

&__filter {
margin-bottom: var(--pf-v5-global--spacer--xl);
margin-bottom: var(--pf-v5-global--spacer--md);
}

&__base {
Expand Down
16 changes: 16 additions & 0 deletions packages/ui/src/components/Catalog/CatalogFilter.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.filter-bar {
padding: 0 2px;
display: flex;
flex-flow: row;
justify-content: space-between;
margin-bottom: var(--pf-v5-global--spacer--sm);

&__search {
flex: 1;
}
}

.category-bar {
display: flex;
flex-flow: row;
}
117 changes: 58 additions & 59 deletions packages/ui/src/components/Catalog/CatalogFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import {
Badge,
Form,
FormGroup,
Grid,
GridItem,
Label,
LabelGroup,
SearchInput,
ToggleGroup,
ToggleGroupItem,
capitalize,
} from '@patternfly/react-core';
import { TimesCircleIcon } from '@patternfly/react-icons';
import { FunctionComponent, useEffect, useRef } from 'react';
import { CatalogLayout } from './Catalog.models';
import './CatalogFilter.scss';
import { CatalogLayoutIcon } from './CatalogLayoutIcon';
import { TimesCircleIcon } from '@patternfly/react-icons';

interface CatalogFilterProps {
className?: string;
Expand Down Expand Up @@ -63,67 +62,66 @@ export const CatalogFilter: FunctionComponent<CatalogFilterProps> = (props) => {
};

return (
<Form className={props.className}>
<Grid hasGutter>
<GridItem md={5} lg={6}>
<FormGroup label="Filter" fieldId="search-term">
<SearchInput
aria-label="Filter by name, description or tag"
placeholder="Filter by name, description or tag"
value={props.searchTerm}
onChange={props.onChange}
onClear={props.onChange}
ref={inputRef}
/>
</FormGroup>
</GridItem>
<div className={props.className}>
<Form className="filter-bar">
<FormGroup className="filter-bar__search" label="Filter" fieldId="search-term">
<SearchInput
aria-label="Filter by name, description or tag"
placeholder="Filter by name, description or tag"
value={props.searchTerm}
onChange={props.onChange}
onClear={props.onChange}
ref={inputRef}
/>
</FormGroup>

<FormGroup label="Type" fieldId="element-type">
<ToggleGroup aria-label="Select element type">
{props.groups.map((tileGroup) => (
<ToggleGroupItem
text={
<>
<span>{capitalize(tileGroup.name)}</span> <Badge isRead>{tileGroup.count}</Badge>
</>
}
key={tileGroup.name}
data-testid={`${tileGroup.name}-catalog-tab`}
buttonId={`toggle-group-button-${tileGroup.name}`}
isSelected={props.activeGroups.includes(tileGroup.name)}
onChange={(_event, selected: boolean) => toggleActiveGroup(selected, tileGroup.name)}
/>
))}
</ToggleGroup>
</FormGroup>

<FormGroup label="Layout" fieldId="layout">
<ToggleGroup aria-label="Change layout">
{props.layouts.map((key) => (
<ToggleGroupItem
icon={<CatalogLayoutIcon key={key} layout={key} />}
key={key}
data-testid={`toggle-layout-button-${key}`}
buttonId={`toggle-layout-button-${key}`}
aria-label={`toggle-layout-button-${key}`}
isSelected={props.activeLayout === key}
onChange={() => {
props.setActiveLayout(key);
}}
/>
))}
</ToggleGroup>
</FormGroup>
</Form>

<GridItem className="pf-v5-u-text-align-right" md={5}>
<FormGroup label="Type" fieldId="element-type">
<ToggleGroup aria-label="Select element type">
{props.groups.map((tileGroup) => (
<ToggleGroupItem
text={
<>
<span>{capitalize(tileGroup.name)}</span> <Badge isRead>{tileGroup.count}</Badge>
</>
}
key={tileGroup.name}
data-testid={`${tileGroup.name}-catalog-tab`}
buttonId={`toggle-group-button-${tileGroup.name}`}
isSelected={props.activeGroups.includes(tileGroup.name)}
onChange={(_event, selected: boolean) => toggleActiveGroup(selected, tileGroup.name)}
/>
))}
</ToggleGroup>
</FormGroup>
</GridItem>
<GridItem md={2} lg={1}>
<FormGroup label="Layout" fieldId="layout">
<ToggleGroup aria-label="Change layout">
{props.layouts.map((key) => (
<ToggleGroupItem
icon={<CatalogLayoutIcon key={key} layout={key} />}
key={key}
data-testid={`toggle-layout-button-${key}`}
buttonId={`toggle-layout-button-${key}`}
aria-label={`toggle-layout-button-${key}`}
isSelected={props.activeLayout === key}
onChange={() => {
props.setActiveLayout(key);
}}
/>
))}
</ToggleGroup>
</FormGroup>
</GridItem>
</Grid>
<LabelGroup
categoryName={'Filter Categories'}
isCompact
className="category-bar"
categoryName="Filter Categories"
numLabels={props.filterTags.length > 0 ? props.tagsOverflowIndex + 1 : props.tagsOverflowIndex}
>
{props.filterTags.length > 0 && (
<Label
isCompact
key="clear"
id="clear"
color="grey"
Expand All @@ -136,6 +134,7 @@ export const CatalogFilter: FunctionComponent<CatalogFilterProps> = (props) => {
)}
{props.tags.map((tag, index) => (
<Label
isCompact
key={tag + index}
id={tag + index}
data-testid={`button-catalog-tag-${tag}`}
Expand All @@ -147,6 +146,6 @@ export const CatalogFilter: FunctionComponent<CatalogFilterProps> = (props) => {
</Label>
))}
</LabelGroup>
</Form>
</div>
);
};
Loading