Add support for multiple dependsOn constraints in the manifest and fix issue with nullish dependsOn contraints
This commit is contained in:
parent
93d717d2e9
commit
bdc2bcd97d
|
@ -70,14 +70,22 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const shouldDisplay = (instance, setting) => {
|
const shouldDisplay = (instance, setting) => {
|
||||||
// Parse dependant settings
|
let dependsOn = setting.dependsOn
|
||||||
if (setting.dependsOn) {
|
if (dependsOn && !Array.isArray(dependsOn)) {
|
||||||
let dependantSetting = setting.dependsOn
|
dependsOn = [dependsOn]
|
||||||
|
}
|
||||||
|
if (!dependsOn?.length) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure all conditions are met
|
||||||
|
return dependsOn.every(condition => {
|
||||||
|
let dependantSetting = condition
|
||||||
let dependantValues = null
|
let dependantValues = null
|
||||||
let invert = !!setting.dependsOn.invert
|
let invert = !!condition.invert
|
||||||
if (typeof setting.dependsOn === "object") {
|
if (typeof condition === "object") {
|
||||||
dependantSetting = setting.dependsOn.setting
|
dependantSetting = condition.setting
|
||||||
dependantValues = setting.dependsOn.value
|
dependantValues = condition.value
|
||||||
}
|
}
|
||||||
if (!dependantSetting) {
|
if (!dependantSetting) {
|
||||||
return false
|
return false
|
||||||
|
@ -93,14 +101,12 @@
|
||||||
const currentVal = helpers.deepGet(instance, dependantSetting)
|
const currentVal = helpers.deepGet(instance, dependantSetting)
|
||||||
const anyMatches = dependantValues.some(dependantVal => {
|
const anyMatches = dependantValues.some(dependantVal => {
|
||||||
if (dependantVal == null) {
|
if (dependantVal == null) {
|
||||||
return currentVal == null || currentVal === false || currentVal === ""
|
return currentVal != null && currentVal !== false && currentVal !== ""
|
||||||
}
|
}
|
||||||
return dependantVal === currentVal
|
return dependantVal === currentVal
|
||||||
})
|
})
|
||||||
return anyMatches !== invert
|
return anyMatches !== invert
|
||||||
}
|
})
|
||||||
|
|
||||||
return typeof setting.visible == "boolean" ? setting.visible : true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const canRenderControl = (instance, setting, isScreen) => {
|
const canRenderControl = (instance, setting, isScreen) => {
|
||||||
|
|
|
@ -5567,18 +5567,35 @@
|
||||||
"type": "columns/grid",
|
"type": "columns/grid",
|
||||||
"label": "Columns",
|
"label": "Columns",
|
||||||
"key": "columns",
|
"key": "columns",
|
||||||
"dependsOn": "table"
|
"dependsOn": [
|
||||||
|
"datasource",
|
||||||
|
{
|
||||||
|
"setting": "datasource.type",
|
||||||
|
"value": "custom",
|
||||||
|
"invert": true
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "filter",
|
"type": "filter",
|
||||||
"label": "Filtering",
|
"label": "Filtering",
|
||||||
"key": "initialFilter"
|
"key": "initialFilter",
|
||||||
|
"dependsOn": {
|
||||||
|
"setting": "datasource.type",
|
||||||
|
"value": "custom",
|
||||||
|
"invert": true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "field/sortable",
|
"type": "field/sortable",
|
||||||
"label": "Sort column",
|
"label": "Sort column",
|
||||||
"key": "initialSortColumn",
|
"key": "initialSortColumn",
|
||||||
"placeholder": "Default"
|
"placeholder": "Default",
|
||||||
|
"dependsOn": {
|
||||||
|
"setting": "datasource.type",
|
||||||
|
"value": "custom",
|
||||||
|
"invert": true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "select",
|
"type": "select",
|
||||||
|
|
Loading…
Reference in New Issue