-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Primer component for RepositorySelector
There seemed to be a bug with the Tremor selector where clearing the search filter by closing the popover didn't restore the filtered list of items. This commit switches to using the Primer `SelectPanel` instead. I added a `RepositorySelector` component to manage the state for this. There may have been a simpler fix - I'll probably take a look into the Tremor component to see if I'm missing something. We should decide what Component library we want to use for this - it might more sense to roll with Tremor if we're going to use that for the charting. I can also look into opening a PR upstream if there is in fact a bug in the Select component. Finally, I added some logic to make the Primer theme match the Tremor theme. This is a downside of using two different component libraries.
- Loading branch information
Showing
3 changed files
with
76 additions
and
17 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,58 @@ | ||
import { TriangleDownIcon } from "@primer/octicons-react"; | ||
import { Button, SelectPanel } from "@primer/react"; | ||
import { ItemInput } from "@primer/react/lib/deprecated/ActionList/List"; | ||
import { useState } from "react"; | ||
|
||
export const RepositorySelector = ({ | ||
selectedNames, | ||
setSelectedNames, | ||
repositoryNames, | ||
}: { | ||
selectedNames: string[]; | ||
setSelectedNames: (nextSelection: string[]) => void; | ||
repositoryNames: string[]; | ||
}) => { | ||
const [open, setOpen] = useState(false); | ||
const [filter, setFilter] = useState(""); | ||
|
||
const items: ItemInput[] = repositoryNames.map((repositoryName, index) => { | ||
return { | ||
text: repositoryName, | ||
id: index, | ||
}; | ||
}); | ||
|
||
const filteredItems = items.filter((item) => item.text?.includes(filter)); | ||
|
||
const selected = items.filter((item) => { | ||
return item.text && selectedNames.includes(item.text); | ||
}); | ||
|
||
const updateSelection = (selectedItems: ItemInput[]) => { | ||
const updatedNames: string[] = selectedItems.map((item) => item.text || ""); | ||
setSelectedNames(updatedNames.filter((updatedName) => updatedName !== "")); | ||
}; | ||
return ( | ||
<SelectPanel | ||
renderAnchor={({ "aria-labelledby": ariaLabelledBy, ...anchorProps }) => ( | ||
<Button | ||
trailingAction={TriangleDownIcon} | ||
aria-labelledby={` ${ariaLabelledBy}`} | ||
{...anchorProps} | ||
> | ||
Select repositories | ||
</Button> | ||
)} | ||
title="Select repositories" | ||
placeholderText="Filter repositories" | ||
open={open} | ||
onOpenChange={setOpen} | ||
items={filteredItems} | ||
selected={selected} | ||
onSelectedChange={updateSelection} | ||
onFilterChange={setFilter} | ||
showItemDividers={true} | ||
overlayProps={{ width: "xlarge", height: "xlarge" }} | ||
/> | ||
); | ||
}; |