-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
241 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,131 @@ | ||
import * as React from 'react'; | ||
|
||
import { DateTimeFloatingPicker } from '@devoinc/genesys-ui-datetime'; | ||
import { SelectControl } from '@devoinc/genesys-ui'; | ||
|
||
import { | ||
AdvancedFilter, | ||
BasicFilter, | ||
DATE_OPTIONS, | ||
FilterContainer, | ||
} from '../common'; | ||
import type { TFilter } from '../../declarations'; | ||
HFlex, | ||
IconButton, | ||
Menu, | ||
Popover, | ||
} from '@devoinc/genesys-ui'; | ||
import { GIExitClose, GIFilter } from '@devoinc/genesys-icons'; | ||
|
||
import { DATE_OPTIONS, FilterContainer } from '../common'; | ||
import type { TFilter, TFilterContext } from '../../declarations'; | ||
import type { TDateFilterValue } from './declarations'; | ||
|
||
export const DateFilter: React.FC<TFilter> = ({ colDef, onChange }) => { | ||
const context = colDef?.context as TFilterContext; | ||
const filterValue = context?.filterValue as TDateFilterValue; | ||
const value = filterValue?.value ?? null; | ||
const secondValue = filterValue?.secondValue ?? null; | ||
const operator = filterValue?.operator ?? 'equals'; | ||
return ( | ||
<FilterContainer> | ||
<HFlex.Item flex="1 1 auto"> | ||
<DateTimeFloatingPicker | ||
label="" | ||
size="sm" | ||
value={value} | ||
onApply={(newValue) => { | ||
onChange( | ||
{ | ||
value: newValue, | ||
secondValue, | ||
operator, | ||
}, | ||
'date', | ||
); | ||
}} | ||
/> | ||
</HFlex.Item> | ||
{operator === 'between' && ( | ||
<HFlex.Item flex="1 1 auto"> | ||
<DateTimeFloatingPicker | ||
label="" | ||
size="sm" | ||
aria-label="filter" | ||
placeholder="To..." | ||
value={secondValue} | ||
onApply={(newSecondValue) => { | ||
onChange( | ||
{ | ||
value, | ||
secondValue: newSecondValue, | ||
operator, | ||
}, | ||
'date', | ||
); | ||
}} | ||
/> | ||
</HFlex.Item> | ||
)} | ||
|
||
{(context?.showReset ?? true) && | ||
(value !== null || operator !== 'equals') && ( | ||
<HFlex.Item flex="0 0 auto"> | ||
<IconButton | ||
icon={<GIExitClose />} | ||
onClick={() => { | ||
onChange( | ||
{ | ||
value: null, | ||
operator: 'equals', | ||
} as TDateFilterValue, | ||
'number', | ||
); | ||
}} | ||
size="sm" | ||
colorScheme="quiet" | ||
/> | ||
</HFlex.Item> | ||
)} | ||
|
||
export const DateFilter: React.FC<TFilter> = ({ colDef }) => ( | ||
<FilterContainer> | ||
<BasicFilter> | ||
<DateTimeFloatingPicker | ||
size="sm" | ||
onApply={() => undefined} | ||
onCancel={() => undefined} | ||
/> | ||
</BasicFilter> | ||
<AdvancedFilter id={`date-adv-filter-${colDef.id}`}> | ||
<SelectControl | ||
menuAppendToBody | ||
// onChange={(opt: TSelectOption) => setValue(opt.value)} | ||
options={DATE_OPTIONS} | ||
// value={value} | ||
/> | ||
<DateTimeFloatingPicker | ||
onApply={() => undefined} | ||
onCancel={() => undefined} | ||
/> | ||
</AdvancedFilter> | ||
</FilterContainer> | ||
); | ||
{(context?.showAdvancedFilter ?? true) && ( | ||
<HFlex.Item flex="0 0 auto"> | ||
<Popover id={`text-adv-filter-${colDef.id}`} placement="bottom-start"> | ||
{({ toggle, ref, isOpened }) => ( | ||
<IconButton | ||
aria-controls={`text-adv-filter-${colDef.id}`} | ||
aria-expanded={isOpened} | ||
aria-haspopup="true" | ||
icon={<GIFilter />} | ||
onClick={toggle} | ||
ref={ref} | ||
state={isOpened ? 'expanded' : undefined} | ||
size="sm" | ||
colorScheme="quiet" | ||
/> | ||
)} | ||
{({ setOpened }) => ( | ||
<Popover.Panel maxHeight="34rem" width="28rem"> | ||
<Menu> | ||
{DATE_OPTIONS.map((option) => ( | ||
<Menu.Item | ||
selectionScheme="single" | ||
onChange={() => { | ||
onChange( | ||
{ | ||
value, | ||
secondValue, | ||
operator: option.value, | ||
} as TDateFilterValue, | ||
'date', | ||
); | ||
setOpened(false); | ||
}} | ||
key={option.value} | ||
state={operator === option.value ? 'selected' : 'enabled'} | ||
name="options" | ||
value={option.value} | ||
label={option.label} | ||
/> | ||
))} | ||
</Menu> | ||
</Popover.Panel> | ||
)} | ||
</Popover> | ||
</HFlex.Item> | ||
)} | ||
</FilterContainer> | ||
); | ||
}; |
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,12 @@ | ||
export type TDateFilterValue = { | ||
value: number | Date; | ||
secondValue?: number | Date; | ||
operator: | ||
| 'equals' | ||
| 'notEquals' | ||
| 'greater' | ||
| 'greaterOrEqual' | ||
| 'less' | ||
| 'lessOrEqual' | ||
| 'between'; | ||
}; |
File renamed without changes.
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './BooleanFilter'; | ||
export * from './DateFilter'; | ||
export * from './TextFilter'; | ||
export * from './NumberFilter'; | ||
export * from './OptionsFilter'; |
Oops, something went wrong.