Sorting the field list to make sure we have the important fields at the top (if known).
This commit is contained in:
parent
05fd9e8b81
commit
63c0d9afb8
|
@ -55,6 +55,20 @@ function getRelationshipLimit() {
|
||||||
return envLimit || 500
|
return envLimit || 500
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function prioritisedArraySort(toSort: string[], priorities: string[]) {
|
||||||
|
return toSort.sort((a, b) => {
|
||||||
|
const aPriority = priorities.find(field => field && a.endsWith(field))
|
||||||
|
const bPriority = priorities.find(field => field && b.endsWith(field))
|
||||||
|
if (aPriority && !bPriority) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if (!aPriority && bPriority) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return a.localeCompare(b)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function getTableName(table?: Table): string | undefined {
|
function getTableName(table?: Table): string | undefined {
|
||||||
// SQS uses the table ID rather than the table name
|
// SQS uses the table ID rather than the table name
|
||||||
if (
|
if (
|
||||||
|
@ -924,11 +938,12 @@ class InternalBuilder {
|
||||||
const requiredFields = [
|
const requiredFields = [
|
||||||
...(relatedTable?.primary || []),
|
...(relatedTable?.primary || []),
|
||||||
relatedTable?.primaryDisplay,
|
relatedTable?.primaryDisplay,
|
||||||
]
|
].filter(field => field) as string[]
|
||||||
let relationshipFields = fields
|
// sort the required fields to first in the list, so they don't get sliced out
|
||||||
.filter(field => field.split(".")[0] === toAlias)
|
let relationshipFields = prioritisedArraySort(
|
||||||
// sort the required fields to first in the list
|
fields.filter(field => field.split(".")[0] === toAlias),
|
||||||
.sort(field => (requiredFields.includes(field) ? 1 : -1))
|
requiredFields
|
||||||
|
)
|
||||||
|
|
||||||
relationshipFields = relationshipFields.slice(
|
relationshipFields = relationshipFields.slice(
|
||||||
0,
|
0,
|
||||||
|
|
Loading…
Reference in New Issue