Skip to content

Commit d5fe0ce

Browse files
authored
fix(ui): respect admin.dateFormat for list view filters (#16040)
Previously, for the list view filters we used only field level `date.displayFormat`. Now, if there is no `date.displayFormat` defined we fallback to `admin.dateFormat` instead of always using the default one. --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1213774486292022
1 parent 9c58e7c commit d5fe0ce

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

  • packages/ui/src/elements/WhereBuilder/Condition/Date
  • test/fields/collections/Date

packages/ui/src/elements/WhereBuilder/Condition/Date/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,28 @@ import React from 'react'
44

55
import type { DateFilterProps as Props } from './types.js'
66

7+
import { useConfig } from '../../../../providers/Config/index.js'
78
import { useTranslation } from '../../../../providers/Translation/index.js'
89
import { DatePickerField } from '../../../DatePicker/index.js'
910

1011
const baseClass = 'condition-value-date'
1112

1213
export const DateFilter: React.FC<Props> = ({ disabled, field: { admin }, onChange, value }) => {
1314
const { date } = admin || {}
15+
const {
16+
config: {
17+
admin: { dateFormat: dateFormatFromConfig },
18+
},
19+
} = useConfig()
1420
const { i18n, t } = useTranslation()
1521

22+
const displayFormat = date?.displayFormat || dateFormatFromConfig
23+
1624
return (
1725
<div className={baseClass}>
1826
<DatePickerField
1927
{...date}
28+
displayFormat={displayFormat}
2029
onChange={onChange}
2130
placeholder={getTranslation(admin.placeholder, i18n) || t('general:enterAValue')}
2231
readOnly={disabled}

test/fields/collections/Date/e2e.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { fileURLToPath } from 'url'
99
import type { PayloadTestSDK } from '../../../__helpers/shared/sdk/index.js'
1010
import type { Config } from '../../payload-types.js'
1111

12+
import { addListFilter } from '../../../__helpers/e2e/filters/addListFilter.js'
1213
import {
1314
ensureCompilationIsDone,
1415
initPageConsoleErrorCatch,
@@ -84,6 +85,43 @@ describe('Date', () => {
8485
await expect(notFormattedDateCell).toContainText('August')
8586
})
8687

88+
test('should use admin.dateFormat in collection filter date picker', async () => {
89+
await goToListView(page)
90+
91+
// Add a date filter without a value — this sets up the field and operator
92+
const { condition } = await addListFilter({
93+
page,
94+
fieldLabel: 'Created At',
95+
operatorLabel: 'is greater than',
96+
})
97+
98+
// Click the date picker input to open the calendar
99+
const dateInput = condition.locator(
100+
'.condition-value-date .date-time-picker__input-wrapper input',
101+
)
102+
await dateInput.click()
103+
104+
// Wait for the calendar popup to appear
105+
const calendar = page.locator('.react-datepicker__month')
106+
await expect(calendar).toBeVisible()
107+
108+
// Click on day 15 of the current month
109+
await page
110+
.locator('.react-datepicker__day--015:not(.react-datepicker__day--outside-month)')
111+
.click()
112+
113+
// The default admin.dateFormat is 'MMMM do yyyy, h:mm a' which renders full month names
114+
// e.g. "March 15th 2026, 12:00 PM". The old hardcoded format would render "03/15/2026".
115+
await expect(async () => {
116+
const inputValue = await dateInput.inputValue()
117+
118+
expect(inputValue).not.toMatch(/^\d{2}\/\d{2}\/\d{4}$/)
119+
expect(inputValue).toMatch(
120+
/^(January|February|March|April|May|June|July|August|September|October|November|December)/,
121+
)
122+
}).toPass()
123+
})
124+
87125
test('should display formatted date in useAsTitle', async () => {
88126
await goToListView(page)
89127
// Wait for hydration

0 commit comments

Comments
 (0)