[Bug]: @adminjs/relations default sorting not working in oneToManyHandler
Pekket opened this issue · comments
Contact Details
No response
What happened?
Im trying to sort my oneToMany table on configured sort options.
export const requestLogsResource = (prisma: PrismaClient) => ({
resource: {
model: getModelByName('request_logs'),
client: prisma,
},
features: [targetRelationSettingsFeature()],
options: {
id: 'requestLogs',
navigation: false,
sort: {
direction: 'desc',
sortBy: 'timestamp',
},
listProperties: ['timestamp', 'question'],
...
![image](https://private-user-images.githubusercontent.com/14330518/328152082-1255b1b5-203d-495f-842b-17c7c95110fa.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTgwMzUyMjIsIm5iZiI6MTcxODAzNDkyMiwicGF0aCI6Ii8xNDMzMDUxOC8zMjgxNTIwODItMTI1NWIxYjUtMjAzZC00OTVmLTg0MmItMTdjN2M5NTExMGZhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjEwVDE1NTUyMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQwYjFlMGU5Yjk4NjAwMWU1OGVhMGZiYThiMzdjMWI0M2E3NWI2NjIwZDExMTc2M2NiOWZiMWZmOGE4NzY2NmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.RPOkbnJE5NLPEd5KKFdRC2kywNq38u0TLlCbhxWlF-Q)
Sorting is only working when clicking on the header table of timestamp. This because query parameters are added to the url.
When investigating this problem i found that oneToManyHandler
(@adminjs/relations/lib/actions/one-to-many/one-to-many.handler.js) is defaulting its query parameter direction
to asc.
export const oneToManyHandler = async (a, b, c = {}, d) => {
const {
relation: e,
targetResource: f,
} = b, {
sortBy: g,
direction: h = 'asc',
filters: i = {},
perPage: j = d._admin.options.settings?.defaultPerPage || 10,
page: k = 1,
} = c;
This causes the sortSetter
(adminjs/src/backend/services/sort-setter/sort-setter) to always default back to asc in code.
const computedDirection = direction || options.direction || DEFAULT_DIRECTION
🚀🚀🚀
Proposed solution: remove default of direction
in oneToManyHandler
function.
Bug prevalence
Visting overview page with relations
AdminJS dependencies version
"@adminjs/express": "^6.1.0",
"@adminjs/prisma": "^5.0.1",
"@adminjs/relations": "^1.1.2",
"@prisma/client": "^5.6.0",
"adminjs": "^7.8.1",
What browsers do you see the problem on?
No response
Relevant log output
No response
Relevant code that's giving you issues
No response