-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global Search: Resource type filter (#2039)
* task: added resource type filter * task: updated tooltip text * task: add resource type filter component in search page
- Loading branch information
1 parent
16d6e50
commit bce6af4
Showing
4 changed files
with
140 additions
and
2 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 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 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,71 @@ | ||
import React from "react"; | ||
import { FC, useState } from "react"; | ||
import { Menu, MenuItem } from "@mui/material"; | ||
|
||
import { FilterButton } from "../../../components/Filters"; | ||
|
||
interface ResourceTypeOptions { | ||
content: string; | ||
schema: string; | ||
} | ||
const RESOURCE_TYPE_OPTIONS: ResourceTypeOptions = { | ||
content: "Content Items", | ||
schema: "Models", | ||
}; | ||
|
||
export type ResourceType = "content" | "schema" | ""; | ||
interface ResourceTypeFilter { | ||
onChange: (value: ResourceType | "") => void; | ||
value?: ResourceType; | ||
} | ||
export const ResourceTypeFilter: FC<ResourceTypeFilter> = ({ | ||
onChange, | ||
value, | ||
}) => { | ||
const [anchorRef, setAnchorRef] = useState<HTMLElement | null>(null); | ||
|
||
return ( | ||
<> | ||
<FilterButton | ||
filterId="resourceType" | ||
isFilterActive={Boolean(value)} | ||
buttonText={ | ||
RESOURCE_TYPE_OPTIONS[value as Exclude<ResourceType, "">] || | ||
"Resource Type" | ||
} | ||
onOpenMenu={(e: React.MouseEvent<HTMLButtonElement>) => | ||
setAnchorRef(e.currentTarget) | ||
} | ||
onRemoveFilter={() => onChange("")} | ||
/> | ||
<Menu | ||
data-cy="ResourceTypeFilterMenu" | ||
anchorEl={anchorRef} | ||
open={Boolean(anchorRef)} | ||
onClose={() => setAnchorRef(null)} | ||
PaperProps={{ | ||
sx: { | ||
mt: 1, | ||
}, | ||
}} | ||
> | ||
{Object.entries(RESOURCE_TYPE_OPTIONS).map(([filter, text]) => ( | ||
<MenuItem | ||
key={filter} | ||
value={filter} | ||
selected={value === filter} | ||
sx={{ | ||
height: 40, | ||
}} | ||
onClick={() => { | ||
onChange(filter as ResourceType); | ||
setAnchorRef(null); | ||
}} | ||
> | ||
{text} | ||
</MenuItem> | ||
))} | ||
</Menu> | ||
</> | ||
); | ||
}; |
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