forked from tsai/budibase
7 changed files with 127 additions and 75 deletions
@ -1,52 +1,50 @@ |
|||||
export const getOptions = ( |
export const getOptions = ( |
||||
optionsSource, |
optionsSource, |
||||
fieldSchema, |
fieldSchema, |
||||
dataProvider, |
dataProvider, |
||||
labelColumn, |
labelColumn, |
||||
valueColumn, |
valueColumn, |
||||
customOptions |
customOptions |
||||
) => { |
) => { |
||||
const isArray = fieldSchema?.type === "array" |
const isArray = fieldSchema?.type === "array" |
||||
// Take options from schema
|
// Take options from schema
|
||||
if (optionsSource == null || optionsSource === "schema") { |
if (optionsSource == null || optionsSource === "schema") { |
||||
if (isArray) { |
if (isArray) { |
||||
return fieldSchema?.constraints?.inclusion[0] ?? [] |
return fieldSchema?.constraints?.inclusion[0] ?? [] |
||||
} |
|
||||
return fieldSchema?.constraints?.inclusion ?? [] |
|
||||
} |
} |
||||
|
return fieldSchema?.constraints?.inclusion ?? [] |
||||
|
} |
||||
|
|
||||
if (optionsSource === "provider" && isArray) { |
if (optionsSource === "provider" && isArray) { |
||||
let optionsSet = {} |
let optionsSet = {} |
||||
|
|
||||
dataProvider?.rows?.forEach(row => { |
|
||||
const value = row?.[valueColumn] |
|
||||
if (value) { |
|
||||
const label = row[labelColumn] || value |
|
||||
optionsSet[value] = { value, label } |
|
||||
} |
|
||||
}) |
|
||||
return Object.values(optionsSet) |
|
||||
} |
|
||||
|
|
||||
|
|
||||
|
|
||||
// Extract options from data provider
|
dataProvider?.rows?.forEach(row => { |
||||
if (optionsSource === "provider" && valueColumn) { |
const value = row?.[valueColumn] |
||||
let optionsSet = {} |
if (value) { |
||||
dataProvider?.rows?.forEach(row => { |
const label = row[labelColumn] || value |
||||
const value = row?.[valueColumn] |
optionsSet[value] = { value, label } |
||||
if (value) { |
} |
||||
const label = row[labelColumn] || value |
}) |
||||
optionsSet[value] = { value, label } |
return Object.values(optionsSet) |
||||
} |
} |
||||
}) |
|
||||
return Object.values(optionsSet) |
|
||||
} |
|
||||
|
|
||||
// Extract custom options
|
// Extract options from data provider
|
||||
if (optionsSource === "custom" && customOptions) { |
if (optionsSource === "provider" && valueColumn) { |
||||
return customOptions |
let optionsSet = {} |
||||
} |
dataProvider?.rows?.forEach(row => { |
||||
|
const value = row?.[valueColumn] |
||||
|
if (value) { |
||||
|
const label = row[labelColumn] || value |
||||
|
optionsSet[value] = { value, label } |
||||
|
} |
||||
|
}) |
||||
|
return Object.values(optionsSet) |
||||
|
} |
||||
|
|
||||
return [] |
// Extract custom options
|
||||
|
if (optionsSource === "custom" && customOptions) { |
||||
|
return customOptions |
||||
} |
} |
||||
|
|
||||
|
return [] |
||||
|
} |
||||
|
|||||
Loading…
Reference in new issue