-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(playground): replace antd daterange picker
- Loading branch information
1 parent
e68bd97
commit c1a0581
Showing
6 changed files
with
3,160 additions
and
133 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
46 changes: 46 additions & 0 deletions
46
packages/cubejs-playground/src/QueryBuilder/TimeRangeSelector.tsx
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,46 @@ | ||
import { DateRangeSeparatedPicker, parseAbsoluteDate } from '@cube-dev/ui-kit'; | ||
import { useCallback, useMemo } from 'react'; | ||
|
||
interface TimeDateRangeSelectorProps { | ||
type?: 'time' | 'date'; | ||
value: [string | undefined, string | undefined]; | ||
onChange: (value: [string, string]) => void; | ||
} | ||
|
||
export function TimeDateRangeSelector(props: TimeDateRangeSelectorProps) { | ||
const { value, onChange } = props; | ||
|
||
const onChangeHandler = useCallback( | ||
(val) => { | ||
onChange([ | ||
val.start.toString().split(/[+\]]/)[0].replace('T00:00:00', ''), | ||
val.end.toString().split(/[+\]]/)[0].replace('T00:00:00', ''), | ||
]); | ||
}, | ||
[onChange] | ||
); | ||
|
||
const dateValue = useMemo(() => { | ||
const startDate = parseAbsoluteDate(value[0]); | ||
const endDate = parseAbsoluteDate(value[1]); | ||
|
||
return startDate && endDate | ||
? { | ||
start: startDate, | ||
end: endDate, | ||
} | ||
: null; | ||
}, [value[0], value[1]]); | ||
|
||
return useMemo( | ||
() => ( | ||
<DateRangeSeparatedPicker | ||
aria-label="Date range picker" | ||
size="small" | ||
defaultValue={dateValue} | ||
onChange={onChangeHandler} | ||
/> | ||
), | ||
[onChangeHandler] | ||
); | ||
} |
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.