Улучшена работа 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 { DatePickerWrapper, makeDateSorter } from '..'
import { DatePickerWrapperProps } from '../DatePickerWrapper'
export const makeDateColumn = (
title: ReactNode,
key: string,
utc?: boolean,
format?: string,
other?: columnPropsOther
other?: columnPropsOther,
pickerOther?: DatePickerWrapperProps,
) => makeColumn(title, key, {
...other,
render: (date) => (
@ -19,7 +21,7 @@ export const makeDateColumn = (
</div>
),
sorter: makeDateSorter(key),
input: <DatePickerWrapper />,
input: <DatePickerWrapper {...pickerOther} />,
})
export default makeDateColumn

View File

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

View File

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