-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(search): add input search (#277)
Co-authored-by: Carlos Feria <[email protected]>
- Loading branch information
1 parent
49de708
commit 1fed518
Showing
10 changed files
with
723 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
72 changes: 72 additions & 0 deletions
72
client/src/app/pages/search/components/SearchMenu.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { IEntity, SearchMenu } from "./SearchMenu"; | ||
import { Label, MenuItem } from "@patternfly/react-core"; | ||
import React from "react"; | ||
|
||
const meta = { | ||
title: "Components/Search/SearchMenu", | ||
component: SearchMenu, | ||
tags: ["autodocs"], | ||
} satisfies Meta<typeof SearchMenu>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
function customFilterIncludes(list: IEntity[], searchString: string) { | ||
let options: React.JSX.Element[] = list | ||
.filter( | ||
(option) => | ||
option.id.toLowerCase().includes(searchString.toLowerCase()) || | ||
option.title?.toLowerCase().includes(searchString.toLowerCase()) || | ||
option.description?.toLowerCase().includes(searchString.toLowerCase()) | ||
) | ||
.map((option) => ( | ||
<MenuItem | ||
itemId={option.id} | ||
key={option.id} | ||
description={option.description} | ||
to={option.navLink} | ||
> | ||
{option.title} <Label color={option.typeColor}>{option.type}</Label> | ||
</MenuItem> | ||
)); | ||
|
||
if (options.length > 10) { | ||
options = options.slice(0, 10); | ||
} else { | ||
options = [ | ||
...options, | ||
...list | ||
.filter( | ||
(option: IEntity) => | ||
!option.id.startsWith(searchString.toLowerCase()) && | ||
option.id.includes(searchString.toLowerCase()) | ||
) | ||
.map((option: IEntity) => ( | ||
<MenuItem | ||
itemId={option.id} | ||
key={option.id} | ||
description={option.description} | ||
to={option.navLink} | ||
> | ||
{option.title} <Label color={option.typeColor}>{option.type}</Label> | ||
</MenuItem> | ||
)), | ||
].slice(0, 10); | ||
} | ||
|
||
return options; | ||
} | ||
|
||
export const DefaultState: Story = { | ||
args: { | ||
onChangeSearch: jest.fn(), | ||
}, | ||
}; | ||
|
||
export const WithCustomFilter: Story = { | ||
args: { | ||
filterFunction: customFilterIncludes, | ||
onChangeSearch: jest.fn(), | ||
}, | ||
}; |
Oops, something went wrong.