diff --git a/.changeset/thin-paws-fly.md b/.changeset/thin-paws-fly.md new file mode 100644 index 0000000000..65dd9a0903 --- /dev/null +++ b/.changeset/thin-paws-fly.md @@ -0,0 +1,5 @@ +--- +"@medusajs/dashboard": patch +--- + +fix(dashboard): include end of the range date in filter results diff --git a/packages/admin/dashboard/src/components/table/data-table/data-table-filter/date-filter.tsx b/packages/admin/dashboard/src/components/table/data-table/data-table-filter/date-filter.tsx index 68ff671537..489269429e 100644 --- a/packages/admin/dashboard/src/components/table/data-table/data-table-filter/date-filter.tsx +++ b/packages/admin/dashboard/src/components/table/data-table/data-table-filter/date-filter.tsx @@ -69,12 +69,19 @@ export const DateFilter = ({ const handleCustomDateChange = (value: Date | null, pos: "start" | "end") => { const key = pos === "start" ? "$gte" : "$lte" - const dateValue = value ? value.toISOString() : undefined + + let dateValue = value + + // offset to the end of the day so the results include the selected end date + if (key === "$lte" && value) { + dateValue = new Date(value.getTime()) + dateValue.setHours(23, 59, 59, 999) + } selectedParams.add( JSON.stringify({ ...(currentDateComparison || {}), - [key]: dateValue, + [key]: dateValue?.toISOString(), }) ) } @@ -306,5 +313,16 @@ const getDateFromComparison = ( comparison: DateComparisonOperator | null, key: "$gte" | "$lte" ) => { - return comparison?.[key] ? new Date(comparison[key] as string) : undefined + if (!comparison?.[key]) { + return undefined + } + + const compareDate = new Date(comparison[key] as string) + + if (key === "$lte") { + // offset back to the display date + compareDate.setHours(0, 0, 0, 0) + } + + return compareDate }