Files
payload/test/helpers/e2e/sortColumn.ts
Jacob Fletcher bccf6ab16f feat: group by (#13138)
Supports grouping documents by specific fields within the list view.

For example, imagine having a "posts" collection with a "categories"
field. To report on each specific category, you'd traditionally filter
for each category, one at a time. This can be quite inefficient,
especially with large datasets.

Now, you can interact with all categories simultaneously, grouped by
distinct values.

Here is a simple demonstration:


https://github.com/user-attachments/assets/0dcd19d2-e983-47e6-9ea2-cfdd2424d8b5

Enable on any collection by setting the `admin.groupBy` property:

```ts
import type { CollectionConfig } from 'payload'

const MyCollection: CollectionConfig = {
  // ...
  admin: {
    groupBy: true
  }
}
```

This is currently marked as beta to gather feedback while we reach full
stability, and to leave room for API changes and other modifications.
Use at your own risk.

Note: when using `groupBy`, bulk editing is done group-by-group. In the
future we may support cross-group bulk editing.

Dependent on #13102 (merged).

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1210774523852467

---------

Co-authored-by: Paul Popus <paul@payloadcms.com>
2025-07-24 14:00:52 -04:00

37 lines
1.3 KiB
TypeScript

import type { Locator, Page } from '@playwright/test'
import { expect } from '@playwright/test'
/**
* Sort by columns within the list view.
* Will search for that field's heading in the selector, and click the appropriate sort button.
*/
export const sortColumn = async (
page: Page,
options: {
fieldLabel: string
fieldPath: string
/**
* Scope the sorting to a specific scope. If not provided, will search the whole page for the column heading.
*/
scope?: Locator
targetState: 'asc' | 'desc'
},
) => {
const pathAsClassName = options.fieldPath.replace(/\./g, '__')
const field = (options.scope || page).locator(`#heading-${pathAsClassName}`)
const upChevron = field.locator('button.sort-column__asc')
const downChevron = field.locator('button.sort-column__desc')
if (options.targetState === 'asc') {
await upChevron.click()
await expect(field.locator('button.sort-column__asc.sort-column--active')).toBeVisible()
await page.waitForURL(() => page.url().includes(`sort=${options.fieldPath}`))
} else if (options.targetState === 'desc') {
await downChevron.click()
await expect(field.locator('button.sort-column__desc.sort-column--active')).toBeVisible()
await page.waitForURL(() => page.url().includes(`sort=-${options.fieldPath}`))
}
}