1
0
Fork 0
mirror of synced 2024-06-27 02:20:35 +12:00

Respect ordering of options when using a data provider options source

This commit is contained in:
Andrew Kingston 2024-03-21 16:24:35 +00:00
parent c6fca37b43
commit d3535a255d

View file

@ -6,36 +6,24 @@ export const getOptions = (
valueColumn,
customOptions
) => {
const isArray = fieldSchema?.type === "array"
// Take options from schema
if (optionsSource == null || optionsSource === "schema") {
return fieldSchema?.constraints?.inclusion ?? []
}
if (optionsSource === "provider" && isArray) {
let optionsSet = {}
dataProvider?.rows?.forEach(row => {
const value = row?.[valueColumn]
if (value != null) {
const label = row[labelColumn] || value
optionsSet[value] = { value, label }
}
})
return Object.values(optionsSet)
}
// Extract options from data provider
if (optionsSource === "provider" && valueColumn) {
let optionsSet = {}
let valueCache = {}
let options = []
dataProvider?.rows?.forEach(row => {
const value = row?.[valueColumn]
if (value != null) {
if (value != null && !valueCache[value]) {
valueCache[value] = true
const label = row[labelColumn] || value
optionsSet[value] = { value, label }
options.push({ value, label })
}
})
return Object.values(optionsSet)
return options
}
// Extract custom options