Skip to content

Commit 8383426

Browse files
authored
fix(ui): prevents column reset on sort (#9517)
Fixes #9492. Sorting columns would unintentionally clear column preferences.
1 parent af096a3 commit 8383426

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

packages/ui/src/providers/ListQuery/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const ListQueryProvider: React.FC<ListQueryProps> = ({
9898
}
9999

100100
if (updatePreferences && preferenceKey) {
101-
await setPreference(preferenceKey, updatedPreferences)
101+
await setPreference(preferenceKey, updatedPreferences, true)
102102
}
103103

104104
const newQuery: ListQuery = {
@@ -151,7 +151,6 @@ export const ListQueryProvider: React.FC<ListQueryProps> = ({
151151
const handleSearchChange = useCallback(
152152
async (arg: string) => {
153153
const search = arg === '' ? undefined : arg
154-
155154
await refineListData({ search })
156155
},
157156
[refineListData],

test/admin/e2e/2/e2e.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const description = 'Description'
2626

2727
let payload: PayloadTestSDK<Config>
2828

29+
import { toggleColumn } from 'helpers/e2e/toggleColumn.js'
2930
import path from 'path'
3031
import { wait } from 'payload/shared'
3132
import { fileURLToPath } from 'url'
@@ -728,6 +729,26 @@ describe('admin2', () => {
728729
await expect(page.locator('.row-1 .cell-number')).toHaveText('2')
729730
await expect(page.locator('.row-2 .cell-number')).toHaveText('1')
730731
})
732+
733+
test('should sort with existing filters', async () => {
734+
await page.goto(postsUrl.list)
735+
const column = await toggleColumn(page, { columnLabel: 'ID' })
736+
await expect(column).not.toHaveClass('column-selector__column--active')
737+
await page.locator('#heading-id').waitFor({ state: 'detached' })
738+
await page.locator('#heading-title button.sort-column__asc').click()
739+
await page.waitForURL(/sort=title/)
740+
741+
const columnAfterSort = page.locator(
742+
`.list-controls__columns .column-selector .column-selector__column`,
743+
{
744+
hasText: exactText('ID'),
745+
},
746+
)
747+
748+
await expect(columnAfterSort).not.toHaveClass('column-selector__column--active')
749+
await expect(page.locator('#heading-id')).toBeHidden()
750+
await expect(page.locator('.cell-id')).toHaveCount(0)
751+
})
731752
})
732753

733754
describe('i18n', () => {

test/helpers/e2e/toggleColumn.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import type { Page } from '@playwright/test'
2+
3+
import { expect } from '@playwright/test'
4+
5+
import { exactText } from '../../helpers.js'
6+
7+
export const toggleColumn = async (
8+
page: Page,
9+
{
10+
togglerSelector = '.list-controls__toggle-columns',
11+
columnContainerSelector = '.list-controls__columns',
12+
columnLabel,
13+
}: {
14+
columnContainerSelector?: string
15+
columnLabel: string
16+
togglerSelector?: string
17+
},
18+
): Promise<any> => {
19+
const columnContainer = page.locator(columnContainerSelector).first()
20+
const isAlreadyOpen = await columnContainer.isVisible()
21+
22+
if (!isAlreadyOpen) {
23+
await page.locator(togglerSelector).first().click()
24+
}
25+
26+
await expect(page.locator(`${columnContainerSelector}.rah-static--height-auto`)).toBeVisible()
27+
28+
const column = columnContainer.locator(`.column-selector .column-selector__column`, {
29+
hasText: exactText(columnLabel),
30+
})
31+
32+
const isActiveBeforeClick = await column.evaluate((el) =>
33+
el.classList.contains('column-selector__column--active'),
34+
)
35+
36+
await expect(column).toBeVisible()
37+
38+
await column.click()
39+
40+
if (isActiveBeforeClick) {
41+
// no class
42+
await expect(column).not.toHaveClass('column-selector__column--active')
43+
} else {
44+
// has class
45+
await expect(column).toHaveClass('column-selector__column--active')
46+
}
47+
48+
return column
49+
}

0 commit comments

Comments
 (0)