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

feat/quick-filter-label #1033

Merged
merged 2 commits into from
Mar 18, 2025
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@equinor/amplify-component-lib",
"version": "9.7.2",
"version": "9.7.3",
"description": "Frontend Typescript components for the Amplify team",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
28 changes: 28 additions & 0 deletions src/organisms/Filter/QuickFilter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,31 @@ test('Sets active like expected', async () => {

expect(onQuickFilter).toHaveBeenCalledWith(key, item);
});

test('Label works as expected', () => {
const label = faker.airline.airplane().name;
const items = {
[faker.lorem.word()]: new Array(faker.number.int({ min: 1, max: 5 }))
.fill(0)
.map(() => {
return {
value: faker.string.uuid(),
label: faker.string.uuid(),
};
}),
};
const key = Object.keys(items)[0];
const onQuickFilter = vi.fn();
render(
<QuickFilter
values={{
[key]: [items[key][0]],
}}
items={items}
label={label}
onQuickFilter={onQuickFilter}
/>
);

expect(screen.getByRole('button', { name: label })).toBeInTheDocument();
});
4 changes: 3 additions & 1 deletion src/organisms/Filter/QuickFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ interface QuickFilterProps<T extends string> {
values: FilterProps<T>['values'];
items: Record<T, SelectOptionRequired[]>;
onQuickFilter: (key: T, value: SelectOptionRequired) => void;
label?: string;
}

export function QuickFilter<T extends string>({
values,
items,
onQuickFilter,
label = 'Quick filter',
}: QuickFilterProps<T>) {
const [isOpen, setIsOpen] = useState(false);

Expand All @@ -38,7 +40,7 @@ export function QuickFilter<T extends string>({
)}
>
<Typography as="span" variant="button" group="navigation">
Quick filter
{label}
</Typography>
<Icon data={isOpen ? arrow_drop_up : arrow_drop_down} />
</ButtonWithMenu>
Expand Down
Loading