-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FiltersPanel): add projects filter
- Loading branch information
1 parent
a9e044b
commit 6ad298e
Showing
12 changed files
with
272 additions
and
117 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
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
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,66 @@ | ||
import React, { useCallback, useEffect, useState } from 'react'; | ||
import dynamic from 'next/dynamic'; | ||
|
||
import { Project } from '../../graphql/@generated/genql'; | ||
|
||
import { FiltersMenuItem } from './FiltersMenuItem'; | ||
import { MenuItem } from './MenuItem'; | ||
|
||
const Dropdown = dynamic(() => import('./Dropdown')); | ||
|
||
interface ProjectFilterDropdownProps { | ||
text: React.ComponentProps<typeof Dropdown>['text']; | ||
projects: Project[]; | ||
value?: number[]; | ||
disabled?: React.ComponentProps<typeof Dropdown>['disabled']; | ||
|
||
onChange?: (selected: number[]) => void; | ||
} | ||
|
||
export const ProjectFilterDropdown: React.FC<ProjectFilterDropdownProps> = React.forwardRef< | ||
HTMLDivElement, | ||
ProjectFilterDropdownProps | ||
>(({ text, projects, value, disabled, onChange }, ref) => { | ||
const [selected, setSelected] = useState(new Set(value)); | ||
|
||
useEffect(() => { | ||
setSelected(new Set(value)); | ||
}, [value]); | ||
|
||
const onProjectClick = useCallback( | ||
(p: Project) => { | ||
selected.has(p.id) ? selected.delete(p.id) : selected.add(p.id); | ||
const newSelected = new Set(selected); | ||
setSelected(newSelected); | ||
|
||
onChange?.(Array.from(newSelected)); | ||
}, | ||
[onChange, selected], | ||
); | ||
|
||
return ( | ||
<Dropdown | ||
ref={ref} | ||
text={text} | ||
value={value} | ||
onChange={onProjectClick} | ||
items={projects} | ||
disabled={disabled} | ||
renderTrigger={(props) => ( | ||
<FiltersMenuItem | ||
ref={props.ref} | ||
active={Boolean(Array.from(selected).length)} | ||
disabled={props.disabled} | ||
onClick={props.onClick} | ||
> | ||
{props.text} | ||
</FiltersMenuItem> | ||
)} | ||
renderItem={(props) => ( | ||
<MenuItem ghost key={props.item.id} selected={selected.has(props.item.id)} onClick={props.onClick}> | ||
{props.item.title} | ||
</MenuItem> | ||
)} | ||
/> | ||
); | ||
}); |
Oops, something went wrong.