Refactor checkbox condition logic with new operators

- Replace legacy 'equals' and 'does_not_equal' checkbox operators with 'is_checked' and 'is_not_checked'
- Update FormLogicConditionChecker in PHP and JavaScript to handle new operators
- Modify open_filters.json to reflect new checkbox comparator structure
- Add migration logic in ColumnCondition.vue to support legacy operator conversion
- Improve checkbox condition handling with explicit true/false checks
This commit is contained in:
Julien Nahum
2025-02-10 21:48:21 +01:00
parent b457368398
commit f5b9b86c16
6 changed files with 499 additions and 56 deletions

View File

@@ -107,7 +107,7 @@ export default {
).map((key) => {
return {
value: key,
name: this.optionFilterNames(key, this.property.type),
name: this.optionFilterNames(key),
}
})
},
@@ -116,19 +116,22 @@ export default {
if (!operator) {
return false
}
const operatorFormat = operator.format
if (!operatorFormat) return true
// If operator has no format and no expected_type, it means it doesn't need input
if (!operator.format && !operator.expected_type) {
return false
}
if (
operator.expected_type === "boolean" &&
operatorFormat.type === "enum" &&
operatorFormat.values.length === 1
operator.format?.type === "enum" &&
operator.format.values.length === 1
) {
return false
} else if (
operator.expected_type === "object" &&
operatorFormat.type === "empty" &&
operatorFormat.values === "{}"
operator.format?.type === "empty" &&
operator.format.values === "{}"
) {
return false
}
@@ -205,13 +208,7 @@ export default {
this.content.operator
]
},
optionFilterNames(key, propertyType) {
if (propertyType === "checkbox") {
return {
equals: "Is checked",
does_not_equal: "Is not checked",
}[key]
}
optionFilterNames(key) {
return key
.split("_")
.map(function (item) {
@@ -223,9 +220,20 @@ export default {
this.$emit("update:modelValue", this.castContent(this.content))
},
refreshContent() {
const modelValue = { ...this.modelValue }
// Migrate legacy checkbox operators
if (this.property.type === 'checkbox') {
if (modelValue?.operator === 'equals') {
modelValue.operator = 'is_checked'
} else if (modelValue?.operator === 'does_not_equal') {
modelValue.operator = 'is_not_checked'
}
}
this.content = {
operator: this.operators[0].value,
...this.modelValue,
...modelValue,
property_meta: {
id: this.property.id,
type: this.property.type,

View File

@@ -505,24 +505,8 @@
},
"checkbox": {
"comparators": {
"equals": {
"expected_type": "boolean",
"format": {
"type": "enum",
"values": [
true
]
}
},
"does_not_equal": {
"expected_type": "boolean",
"format": {
"type": "enum",
"values": [
true
]
}
}
"is_checked": {},
"is_not_checked": {}
}
},
"select": {

View File

@@ -332,10 +332,15 @@ function numberConditionMet(propertyCondition, value) {
function checkboxConditionMet(propertyCondition, value) {
switch (propertyCondition.operator) {
case "is_checked":
return value === true
case "is_not_checked":
return value === false
// Legacy operators
case "equals":
return checkEquals(propertyCondition, value)
return value === true
case "does_not_equal":
return !checkEquals(propertyCondition, value)
return value === false
}
return false
}