-
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(EstimateFilterDropdown): user can filter goals via estimates
- Loading branch information
1 parent
64eeb53
commit a9e044b
Showing
12 changed files
with
500 additions
and
303 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React, { useCallback, useEffect, useState } from 'react'; | ||
import dynamic from 'next/dynamic'; | ||
|
||
import { Estimate } from '../../graphql/@generated/genql'; | ||
|
||
import { FiltersMenuItem } from './FiltersMenuItem'; | ||
import { MenuItem } from './MenuItem'; | ||
|
||
const Dropdown = dynamic(() => import('./Dropdown')); | ||
|
||
interface EstimateFilterDropdownProps { | ||
text: React.ComponentProps<typeof Dropdown>['text']; | ||
value?: string[]; | ||
estimates: Estimate[]; | ||
disabled?: React.ComponentProps<typeof Dropdown>['disabled']; | ||
|
||
onChange?: (selected: string[]) => void; | ||
} | ||
|
||
const estimateToString = (estimate: Estimate) => `${estimate.q}/${estimate.y}`; | ||
|
||
export const EstimateFilterDropdown: React.FC<EstimateFilterDropdownProps> = React.forwardRef< | ||
HTMLDivElement, | ||
EstimateFilterDropdownProps | ||
>(({ text, estimates, value, disabled, onChange }, ref) => { | ||
const [selected, setSelected] = useState(new Set(value)); | ||
|
||
useEffect(() => { | ||
setSelected(new Set(value)); | ||
}, [value]); | ||
|
||
const onEstimateClick = useCallback( | ||
(e: Estimate) => { | ||
selected.has(estimateToString(e)) | ||
? selected.delete(estimateToString(e)) | ||
: selected.add(estimateToString(e)); | ||
const newSelected = new Set(selected); | ||
setSelected(newSelected); | ||
|
||
onChange?.(Array.from(newSelected)); | ||
}, | ||
[onChange, selected], | ||
); | ||
|
||
return ( | ||
<Dropdown | ||
ref={ref} | ||
text={text} | ||
value={value} | ||
onChange={onEstimateClick} | ||
items={estimates} | ||
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={estimateToString(props.item)} | ||
selected={selected.has(estimateToString(props.item))} | ||
onClick={props.onClick} | ||
> | ||
{estimateToString(props.item)} | ||
</MenuItem> | ||
)} | ||
/> | ||
); | ||
}); |
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
Oops, something went wrong.