Files
payloadcms/test/eslint.config.js
Jacob Fletcher d7a3faa4e9 fix(ui): properly sync search params to user preferences (#13200)
Some search params within the list view do not properly sync to user
preferences, and visa versa.

For example, when selecting a query preset, the `?preset=123` param is
injected into the URL and saved to preferences, but when reloading the
page without the param, that preset is not reactivated as expected.

### Problem 

The reason this wasn't working before is that omitting this param would
also reset prefs. It was designed this way in order to support
client-side resets, e.g. clicking the query presets "x" button.

This pattern would never work, however, because this means that every
time the user navigates to the list view directly, their preference is
cleared, as no param would exist in the query.

Note: this is not an issue with _all_ params, as not all are handled in
the same way.

### Solution

The fix is to use empty values instead, e.g. `?preset=`. When the server
receives this, it knows to clear the pref. If it doesn't exist at all,
it knows to load from prefs. And if it has a value, it saves to prefs.
On the client, we sanitize those empty values back out so they don't
appear in the URL in the end.

This PR also refactors much of the list query context and its respective
provider to be significantly more predictable and easier to work with,
namely:

- The `ListQuery` type now fully aligns with what Payload APIs expect,
e.g. `page` is a number, not a string
- The provider now receives a single `query` prop which matches the
underlying context 1:1
- Propagating the query from the server to the URL is significantly more
predictable
- Any new props that may be supported in the future will automatically
work
- No more reconciling `columns` and `listPreferences.columns`, its just
`query.columns`

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1210827129744922
2025-07-18 09:29:26 -04:00

95 lines
2.9 KiB
JavaScript

import { defaultESLintIgnores, rootEslintConfig, rootParserOptions } from '../eslint.config.js'
import payloadPlugin from '@payloadcms/eslint-plugin'
import playwright from 'eslint-plugin-playwright'
/** @typedef {import('eslint').Linter.Config} Config */
/** @type {Config[]} */
export const testEslintConfig = [
...rootEslintConfig,
{
ignores: [...defaultESLintIgnores, '**/payload-types.ts', 'jest.setup.js'],
},
{
rules: {
'payload/no-relative-monorepo-imports': 'error',
},
},
{
files: ['**/*.ts'],
rules: {
'payload/no-jsx-import-statements': 'warn',
'payload/no-relative-monorepo-imports': 'error',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-use-before-define': 'off',
// turn the @typescript-eslint/unbound-method rule off *only* for test files. See https://typescript-eslint.io/rules/unbound-method/#when-not-to-use-it
'@typescript-eslint/unbound-method': 'off',
'no-console': 'off',
'perfectionist/sort-objects': 'off',
},
},
{
files: ['**/*.config.ts', '**/config.ts'],
rules: {
'no-restricted-exports': 'off',
},
},
{
files: ['**/*.int.spec.ts', '**/int.spec.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'jest/prefer-strict-equal': 'off',
},
},
{
...playwright.configs['flat/recommended'],
files: ['**/*.e2e.spec.ts', '**/e2e.spec.ts', 'helpers.ts'],
},
{
files: ['**/*.e2e.spec.ts', '**/e2e.spec.ts', 'helpers.ts'],
rules: {
'payload/no-relative-monorepo-imports': 'error',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'jest/consistent-test-it': 'off',
'jest/expect-expect': 'off',
'jest/no-test-callback': 'off',
'jest/prefer-strict-equal': 'off',
'jest/require-top-level-describe': 'off',
'jest-dom/prefer-to-have-attribute': 'off',
'playwright/prefer-web-first-assertions': 'error',
'payload/no-flaky-assertions': 'warn',
'payload/no-wait-function': 'warn',
// Enable the no-non-retryable-assertions rule ONLY for hunting for flakes
// 'payload/no-non-retryable-assertions': 'error',
'playwright/expect-expect': [
'error',
{
assertFunctionNames: [
'assertToastErrors',
'saveDocAndAssert',
'runFilterOptionsTest',
'assertNetworkRequests',
'assertRequestBody',
'expectNoResultsAndCreateFolderButton',
'createFolder',
'createFolderFromDoc',
'assertURLParams',
],
},
],
},
},
{
files: ['*.e2e.ts'],
rules: {
'payload/no-relative-monorepo-imports': 'error',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'jest/expect-expect': 'off',
},
},
]
export default testEslintConfig