fix(ui): reflect default sort in join tables (#12084)
<!-- Thank you for the PR! Please go through the checklist below and make sure you've completed all the steps. Please review the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository if you haven't already. The following items will ensure that your PR is handled as smoothly as possible: - PR Title must follow conventional commits format. For example, `feat: my new feature`, `fix(plugin-seo): my fix`. - Minimal description explained as if explained to someone not immediately familiar with the code. - Provide before/after screenshots or code diffs if applicable. - Link any related issues/discussions from GitHub or Discord. - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Fixes # --> ### What? This PR ensures defaultSort is reflected in join tables. ### Why? Currently, default sort is not reflected in the join table state. The data _is_ sorted correctly, but the table state sort is undefined. This is mainly an issue for join fields with `orderable: true` because you can't re-order the table until `order` is the selected sort column. ### How? Added `defaultSort` prop to the `<ListQueryProvider />` in the `<RelationshipTable />` and ensured the default state gets set in `<ListQueryProvider />` when `modifySearchParams` is false. **Before:** <img width="1390" alt="Screenshot 2025-04-11 at 2 33 19 AM" src="https://github.com/user-attachments/assets/4a008d98-d308-4397-a35a-69795e5a6070" /> **After:** <img width="1362" alt="Screenshot 2025-04-11 at 3 04 07 AM" src="https://github.com/user-attachments/assets/4748e354-36e4-451f-83e8-6f84fe58d5b5" /> Fixes #12083 --------- Co-authored-by: Germán Jabloñski <43938777+GermanJablo@users.noreply.github.com>
This commit is contained in:
@@ -335,6 +335,7 @@ export const RelationshipTable: React.FC<RelationshipTableComponentProps> = (pro
|
||||
defaultLimit={
|
||||
field.defaultLimit ?? collectionConfig?.admin?.pagination?.defaultLimit
|
||||
}
|
||||
defaultSort={field.defaultSort ?? collectionConfig?.defaultSort}
|
||||
modifySearchParams={false}
|
||||
onQueryChange={setQuery}
|
||||
orderableFieldName={
|
||||
|
||||
@@ -48,7 +48,10 @@ export const ListQueryProvider: React.FC<ListQueryProps> = ({
|
||||
if (modifySearchParams) {
|
||||
return searchParams
|
||||
} else {
|
||||
return {}
|
||||
return {
|
||||
limit: String(defaultLimit),
|
||||
sort: defaultSort,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user