Dc3e4 new matrix field (#484)

* fix password reset bug

* wip: matrix input

* wip: matrix input

* wip: matrix input

* Fixed matric input component logic

* matrix input cleanup

* fix lint errors

* table border and radius

* cleanup, linting

* fix component methos

* wip matrix input

* matrix condition for contains and not contain

* patch matrix input condition logic

* linting

* refactor and cleanup

* fix syntax error

* Polished the matrix input

* Fix linting

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Favour Olayinka
2024-08-23 14:28:21 +01:00
committed by GitHub
parent fedc382594
commit 1adac8e00f
25 changed files with 919 additions and 85 deletions

View File

@@ -1,3 +1,5 @@
import { default as _isEqual } from "lodash/isEqual"
export function conditionsMet(conditions, formData) {
if (conditions === undefined || conditions === null) {
return false
@@ -59,6 +61,8 @@ function propertyConditionMet(propertyCondition, value) {
return multiSelectConditionMet(propertyCondition, value)
case "files":
return filesConditionMet(propertyCondition, value)
case "matrix":
return matrixConditionMet(propertyCondition, value)
}
return false
}
@@ -67,6 +71,24 @@ function checkEquals(condition, fieldValue) {
return condition.value === fieldValue
}
function checkObjectEquals(condition, fieldValue) {
return _isEqual(condition.value, fieldValue)
}
function checkMatrixContains(condition, fieldValue)
{
if (typeof fieldValue === "undefined" || typeof fieldValue !== "object") {
return false
}
const conditionValue = condition.value
for (const key in conditionValue) {
if(conditionValue[key] == fieldValue[key]){
return true
}
}
return false
}
function checkContains(condition, fieldValue) {
return fieldValue ? fieldValue.includes(condition.value) : false
}
@@ -148,7 +170,7 @@ function checkPastWeek(condition, fieldValue) {
return (
fieldDate <= today &&
fieldDate >=
new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7)
new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7)
)
}
@@ -159,7 +181,7 @@ function checkPastMonth(condition, fieldValue) {
return (
fieldDate <= today &&
fieldDate >=
new Date(today.getFullYear(), today.getMonth() - 1, today.getDate())
new Date(today.getFullYear(), today.getMonth() - 1, today.getDate())
)
}
@@ -170,7 +192,7 @@ function checkPastYear(condition, fieldValue) {
return (
fieldDate <= today &&
fieldDate >=
new Date(today.getFullYear() - 1, today.getMonth(), today.getDate())
new Date(today.getFullYear() - 1, today.getMonth(), today.getDate())
)
}
@@ -181,7 +203,7 @@ function checkNextWeek(condition, fieldValue) {
return (
fieldDate >= today &&
fieldDate <=
new Date(today.getFullYear(), today.getMonth(), today.getDate() + 7)
new Date(today.getFullYear(), today.getMonth(), today.getDate() + 7)
)
}
@@ -192,7 +214,7 @@ function checkNextMonth(condition, fieldValue) {
return (
fieldDate >= today &&
fieldDate <=
new Date(today.getFullYear(), today.getMonth() + 1, today.getDate())
new Date(today.getFullYear(), today.getMonth() + 1, today.getDate())
)
}
@@ -203,7 +225,7 @@ function checkNextYear(condition, fieldValue) {
return (
fieldDate >= today &&
fieldDate <=
new Date(today.getFullYear() + 1, today.getMonth(), today.getDate())
new Date(today.getFullYear() + 1, today.getMonth(), today.getDate())
)
}
@@ -371,3 +393,17 @@ function filesConditionMet(propertyCondition, value) {
}
return false
}
function matrixConditionMet(propertyCondition, value) {
switch (propertyCondition.operator) {
case "equals":
return checkObjectEquals(propertyCondition, value)
case "does_not_equal":
return !checkObjectEquals(propertyCondition, value)
case "contains":
return checkMatrixContains(propertyCondition, value)
case "does_not_contain":
return !checkMatrixContains(propertyCondition, value)
}
return false
}

View File

@@ -107,7 +107,7 @@ class FormPropertyLogicRule {
(type === "string" && typeof value !== "string") ||
(type === "boolean" && typeof value !== "boolean") ||
(type === "number" && typeof value !== "number") ||
(type === "object" && !Array.isArray(value))
(type === "object" && !(Array.isArray(value) || typeof value === 'object'))
) {
return false
}