Улучшена работа makeDateColumn, DatePickerWrapper и DateRangeWrapper

This commit is contained in:
goodmice 2022-05-31 17:18:05 +05:00
parent b21b327aff
commit 99b3978418
3 changed files with 13 additions and 8 deletions

View File

@ -4,13 +4,15 @@ import { formatDate } from '@utils'
import makeColumn, { columnPropsOther } from '.' import makeColumn, { columnPropsOther } from '.'
import { DatePickerWrapper, makeDateSorter } from '..' import { DatePickerWrapper, makeDateSorter } from '..'
import { DatePickerWrapperProps } from '../DatePickerWrapper'
export const makeDateColumn = ( export const makeDateColumn = (
title: ReactNode, title: ReactNode,
key: string, key: string,
utc?: boolean, utc?: boolean,
format?: string, format?: string,
other?: columnPropsOther other?: columnPropsOther,
pickerOther?: DatePickerWrapperProps,
) => makeColumn(title, key, { ) => makeColumn(title, key, {
...other, ...other,
render: (date) => ( render: (date) => (
@ -19,7 +21,7 @@ export const makeDateColumn = (
</div> </div>
), ),
sorter: makeDateSorter(key), sorter: makeDateSorter(key),
input: <DatePickerWrapper />, input: <DatePickerWrapper {...pickerOther} />,
}) })
export default makeDateColumn export default makeDateColumn

View File

@ -16,7 +16,7 @@ export const DatePickerWrapper = memo<DatePickerWrapperProps>(({ value, onChange
showTime showTime
allowClear={false} allowClear={false}
format={defaultFormat} format={defaultFormat}
defaultValue={moment()} defaultValue={undefined}
onChange={(date) => onChange?.(date)} onChange={(date) => onChange?.(date)}
value={value && (isUTC ? moment.utc(value).local() : moment(value))} value={value && (isUTC ? moment.utc(value).local() : moment(value))}
{...other} {...other}

View File

@ -9,14 +9,17 @@ import { defaultFormat } from '@utils'
const { RangePicker } = DatePicker const { RangePicker } = DatePicker
export type DateRangeWrapperProps = RangePickerSharedProps<Moment> & { export type DateRangeWrapperProps = RangePickerSharedProps<Moment> & {
value: RangeValue<Moment>, value?: RangeValue<Moment>,
isUTC?: boolean isUTC?: boolean
} }
const normalizeDates = (value: RangeValue<Moment>, isUTC?: boolean): RangeValue<Moment> => value && [ const normalizeDates = (value?: RangeValue<Moment>, isUTC?: boolean): RangeValue<Moment> => {
value[0] ? (isUTC ? moment.utc(value[0]).local() : moment(value[0])) : null, if (!value) return [null, null]
value[1] ? (isUTC ? moment.utc(value[1]).local() : moment(value[1])) : null, return [
] value[0] ? (isUTC ? moment.utc(value[0]).local() : moment(value[0])) : null,
value[1] ? (isUTC ? moment.utc(value[1]).local() : moment(value[1])) : null,
]
}
export const DateRangeWrapper = memo<DateRangeWrapperProps>(({ value, isUTC, ...other }) => ( export const DateRangeWrapper = memo<DateRangeWrapperProps>(({ value, isUTC, ...other }) => (
<RangePicker <RangePicker