forked from ddrilling/asb_cloud_front
Улучшена работа makeDateColumn, DatePickerWrapper и DateRangeWrapper
This commit is contained in:
parent
b21b327aff
commit
99b3978418
@ -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
|
||||||
|
@ -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}
|
||||||
|
@ -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> => {
|
||||||
|
if (!value) return [null, null]
|
||||||
|
return [
|
||||||
value[0] ? (isUTC ? moment.utc(value[0]).local() : moment(value[0])) : null,
|
value[0] ? (isUTC ? moment.utc(value[0]).local() : moment(value[0])) : null,
|
||||||
value[1] ? (isUTC ? moment.utc(value[1]).local() : moment(value[1])) : 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
|
||||||
|
Loading…
Reference in New Issue
Block a user