feat(dashboard,ui): DateFilter should open correctly (#9775)
This commit is contained in:
1 parent
92bbd7953b
commit
59e6747800
3 files changed
+59
-15
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/dashboard": patch
|
||||||
|
"@medusajs/ui": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(dashboard,ui): DateFilter should remain open
|
||||||
+6
-2
@@ -9,8 +9,8 @@ import { useTranslation } from "react-i18next"
|
|||||||
import { useDate } from "../../../../hooks/use-date"
|
import { useDate } from "../../../../hooks/use-date"
|
||||||
import { useSelectedParams } from "../hooks"
|
import { useSelectedParams } from "../hooks"
|
||||||
import { useDataTableFilterContext } from "./context"
|
import { useDataTableFilterContext } from "./context"
|
||||||
import { IFilter } from "./types"
|
|
||||||
import FilterChip from "./filter-chip"
|
import FilterChip from "./filter-chip"
|
||||||
|
import { IFilter } from "./types"
|
||||||
|
|
||||||
type DateFilterProps = IFilter
|
type DateFilterProps = IFilter
|
||||||
|
|
||||||
@@ -97,7 +97,9 @@ export const DateFilter = ({
|
|||||||
|
|
||||||
const displayValue = getDisplayValueFromPresets() || getCustomDisplayValue()
|
const displayValue = getDisplayValueFromPresets() || getCustomDisplayValue()
|
||||||
|
|
||||||
const [previousValue, setPreviousValue] = useState<string | undefined>(displayValue)
|
const [previousValue, setPreviousValue] = useState<string | undefined>(
|
||||||
|
displayValue
|
||||||
|
)
|
||||||
|
|
||||||
const handleRemove = () => {
|
const handleRemove = () => {
|
||||||
selectedParams.delete()
|
selectedParams.delete()
|
||||||
@@ -210,6 +212,7 @@ export const DateFilter = ({
|
|||||||
</div>
|
</div>
|
||||||
<div className="px-2 py-1">
|
<div className="px-2 py-1">
|
||||||
<DatePicker
|
<DatePicker
|
||||||
|
modal
|
||||||
maxValue={customEndValue}
|
maxValue={customEndValue}
|
||||||
value={customStartValue}
|
value={customStartValue}
|
||||||
onChange={(d) => handleCustomDateChange(d, "start")}
|
onChange={(d) => handleCustomDateChange(d, "start")}
|
||||||
@@ -224,6 +227,7 @@ export const DateFilter = ({
|
|||||||
</div>
|
</div>
|
||||||
<div className="px-2 py-1">
|
<div className="px-2 py-1">
|
||||||
<DatePicker
|
<DatePicker
|
||||||
|
modal
|
||||||
minValue={customStartValue}
|
minValue={customStartValue}
|
||||||
value={customEndValue || undefined}
|
value={customEndValue || undefined}
|
||||||
onChange={(d) => {
|
onChange={(d) => {
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { CalendarDate, CalendarDateTime, getLocalTimeZone } from "@internationalized/date"
|
import {
|
||||||
|
CalendarDate,
|
||||||
|
CalendarDateTime,
|
||||||
|
getLocalTimeZone,
|
||||||
|
} from "@internationalized/date"
|
||||||
import { CalendarMini, Clock, XMarkMini } from "@medusajs/icons"
|
import { CalendarMini, Clock, XMarkMini } from "@medusajs/icons"
|
||||||
import { cva } from "cva"
|
import { cva } from "cva"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
@@ -38,10 +42,14 @@ type DatePickerValueProps = {
|
|||||||
granularity?: Granularity
|
granularity?: Granularity
|
||||||
size?: "base" | "small"
|
size?: "base" | "small"
|
||||||
className?: string
|
className?: string
|
||||||
|
modal?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DatePickerProps
|
interface DatePickerProps
|
||||||
extends Omit<BaseDatePickerProps<CalendarDateTime | CalendarDate>, keyof DatePickerValueProps>,
|
extends Omit<
|
||||||
|
BaseDatePickerProps<CalendarDateTime | CalendarDate>,
|
||||||
|
keyof DatePickerValueProps
|
||||||
|
>,
|
||||||
DatePickerValueProps {}
|
DatePickerValueProps {}
|
||||||
|
|
||||||
const datePickerStyles = (
|
const datePickerStyles = (
|
||||||
@@ -74,14 +82,25 @@ const datePickerStyles = (
|
|||||||
|
|
||||||
const HAS_TIME = new Set<Granularity>(["hour", "minute", "second"])
|
const HAS_TIME = new Set<Granularity>(["hour", "minute", "second"])
|
||||||
|
|
||||||
const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(({
|
const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(
|
||||||
|
(
|
||||||
|
{
|
||||||
size = "base",
|
size = "base",
|
||||||
shouldCloseOnSelect = true,
|
shouldCloseOnSelect = true,
|
||||||
className,
|
className,
|
||||||
|
modal = false,
|
||||||
...props
|
...props
|
||||||
}, ref) => {
|
},
|
||||||
const [value, setValue] = React.useState<CalendarDateTime | CalendarDate | null | undefined>(
|
ref
|
||||||
getDefaultCalendarDateFromDate(props.value, props.defaultValue, props.granularity)
|
) => {
|
||||||
|
const [value, setValue] = React.useState<
|
||||||
|
CalendarDateTime | CalendarDate | null | undefined
|
||||||
|
>(
|
||||||
|
getDefaultCalendarDateFromDate(
|
||||||
|
props.value,
|
||||||
|
props.defaultValue,
|
||||||
|
props.granularity
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
const innerRef = React.useRef<HTMLDivElement>(null)
|
const innerRef = React.useRef<HTMLDivElement>(null)
|
||||||
@@ -100,8 +119,16 @@ const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(({
|
|||||||
useDatePicker(_props, state, innerRef)
|
useDatePicker(_props, state, innerRef)
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
setValue(props.value ? updateCalendarDateFromDate(value, props.value, props.granularity) : null)
|
setValue(
|
||||||
state.setValue(props.value ? updateCalendarDateFromDate(value, props.value, props.granularity) : null)
|
props.value
|
||||||
|
? updateCalendarDateFromDate(value, props.value, props.granularity)
|
||||||
|
: null
|
||||||
|
)
|
||||||
|
state.setValue(
|
||||||
|
props.value
|
||||||
|
? updateCalendarDateFromDate(value, props.value, props.granularity)
|
||||||
|
: null
|
||||||
|
)
|
||||||
}, [props.value])
|
}, [props.value])
|
||||||
|
|
||||||
function clear(e: React.MouseEvent<HTMLButtonElement>) {
|
function clear(e: React.MouseEvent<HTMLButtonElement>) {
|
||||||
@@ -123,7 +150,7 @@ const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(({
|
|||||||
const Icon = hasTime ? Clock : CalendarMini
|
const Icon = hasTime ? Clock : CalendarMini
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover open={state.isOpen} onOpenChange={state.setOpen}>
|
<Popover modal={modal} open={state.isOpen} onOpenChange={state.setOpen}>
|
||||||
<Popover.Anchor asChild>
|
<Popover.Anchor asChild>
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
@@ -168,7 +195,8 @@ const DatePicker = React.forwardRef<HTMLDivElement, DatePickerProps>(({
|
|||||||
</Popover.Content>
|
</Popover.Content>
|
||||||
</Popover>
|
</Popover>
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
|
)
|
||||||
DatePicker.displayName = "DatePicker"
|
DatePicker.displayName = "DatePicker"
|
||||||
|
|
||||||
function convertProps(
|
function convertProps(
|
||||||
@@ -200,10 +228,16 @@ function convertProps(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
onChange: onChange as BaseDatePickerProps<CalendarDateTime | CalendarDate>["onChange"],
|
onChange: onChange as BaseDatePickerProps<
|
||||||
|
CalendarDateTime | CalendarDate
|
||||||
|
>["onChange"],
|
||||||
isDateUnavailable,
|
isDateUnavailable,
|
||||||
minValue: minValue ? createCalendarDateFromDate(minValue, props.granularity) : minValue,
|
minValue: minValue
|
||||||
maxValue: maxValue ? createCalendarDateFromDate(maxValue, props.granularity) : maxValue,
|
? createCalendarDateFromDate(minValue, props.granularity)
|
||||||
|
: minValue,
|
||||||
|
maxValue: maxValue
|
||||||
|
? createCalendarDateFromDate(maxValue, props.granularity)
|
||||||
|
: maxValue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user