From 7b4d1046c3f1fe9f42a88cf8d848bca55d4f04ef Mon Sep 17 00:00:00 2001 From: "ICX\\Tatsiana.Hashtold" Date: Thu, 17 Oct 2024 15:52:08 +0300 Subject: [PATCH 1/2] FIO-9189: moved some formio/js methods to core --- src/utils/conditionOperators/IsEqualTo.js | 15 ++-------- src/utils/formUtils.js | 10 +++++-- src/utils/utils.js | 34 ----------------------- 3 files changed, 10 insertions(+), 49 deletions(-) diff --git a/src/utils/conditionOperators/IsEqualTo.js b/src/utils/conditionOperators/IsEqualTo.js index a577fc7413..4ee93895a7 100644 --- a/src/utils/conditionOperators/IsEqualTo.js +++ b/src/utils/conditionOperators/IsEqualTo.js @@ -1,6 +1,6 @@ import ConditionOperator from './ConditionOperator'; import _ from 'lodash'; -import { getItemTemplateKeys, isSelectResourceWithObjectValue } from '../utils'; +import { compareSelectResourceWithObjectTypeValues, isSelectResourceWithObjectValue } from '../utils'; export default class IsEqualTo extends ConditionOperator { static get operatorKey() { @@ -28,18 +28,7 @@ export default class IsEqualTo extends ConditionOperator { && isSelectResourceWithObjectValue(conditionTriggerComponent.component) && conditionTriggerComponent.component?.template ) { - if (!value || !_.isPlainObject(value)) { - return false; - } - - const { template, valueProperty } = conditionTriggerComponent.component; - - if (valueProperty === 'data') { - value = { data: value }; - comparedValue = { data: comparedValue }; - } - - return _.every(getItemTemplateKeys(template) || [], k => _.isEqual(_.get(value, k), _.get(comparedValue, k))); + return compareSelectResourceWithObjectTypeValues(value, comparedValue, conditionTriggerComponent.component); } } diff --git a/src/utils/formUtils.js b/src/utils/formUtils.js index 9bd0f6e7ba..4f7ac0eef7 100644 --- a/src/utils/formUtils.js +++ b/src/utils/formUtils.js @@ -35,7 +35,10 @@ const { applyFormChanges, findComponent, getEmptyValue, - isComponentDataEmpty + isComponentDataEmpty, + isSelectResourceWithObjectValue, + compareSelectResourceWithObjectTypeValues, + getItemTemplateKeys } = Utils; /** @@ -85,5 +88,8 @@ export { applyFormChanges, findComponent, getEmptyValue, - isComponentDataEmpty + isComponentDataEmpty, + isSelectResourceWithObjectValue, + compareSelectResourceWithObjectTypeValues, + getItemTemplateKeys }; diff --git a/src/utils/utils.js b/src/utils/utils.js index fadad0a87a..c9d36bd2f4 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -1783,37 +1783,3 @@ export const interpolateErrors = (component, errors, interpolateFn) => { return { ...error, message: unescapeHTML(interpolateFn(toInterpolate, context)), context: { ...context } }; }); }; - -/** - * Returns the template keys inside the template code. - * @param {string} template - The template to get the keys from. - * @returns {Array} - The keys inside the template. - */ -export function getItemTemplateKeys(template) { - const templateKeys = []; - if (!template) { - return templateKeys; - } - const keys = template.match(/({{\s*(.*?)\s*}})/g); - - if (keys) { - keys.forEach((key) => { - const propKey = key.match(/{{\s*item\.(.*?)\s*}}/); - if (propKey && propKey.length > 1) { - templateKeys.push(propKey[1]); - } - }); - } - - return templateKeys; -} - -/** - * Returns if the component is a select resource with an object for its value. - * @param {import('@formio/core').Component} comp - The component to check. - * @returns {boolean} - TRUE if the component is a select resource with an object for its value; FALSE otherwise. - */ -export function isSelectResourceWithObjectValue(comp = {}) { - const { reference, dataSrc, valueProperty } = comp; - return reference || (dataSrc === 'resource' && (!valueProperty || valueProperty === 'data')); -} From aa1e3d95f313f1dd9a47bf3d8ae7b016e4409e85 Mon Sep 17 00:00:00 2001 From: "ICX\\Tatsiana.Hashtold" Date: Thu, 17 Oct 2024 15:53:53 +0300 Subject: [PATCH 2/2] updated modules --- package.json | 2 +- yarn.lock | 45 +++++++-------------------------------------- 2 files changed, 8 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index 047df13421..ba9e8b9a45 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "dependencies": { "@formio/bootstrap": "3.0.0-dev.98.17ba6ea", "@formio/choices.js": "^10.2.1", - "@formio/core": "2.3.0-dev.160.cabaa43", + "@formio/core": "v2.1.0-dev.174.9a3c6ec", "@formio/text-mask-addons": "^3.8.0-formio.2", "@formio/vanilla-text-mask": "^5.1.1-formio.1", "abortcontroller-polyfill": "^1.7.5", diff --git a/yarn.lock b/yarn.lock index d9aa4aea58..01ba546034 100644 --- a/yarn.lock +++ b/yarn.lock @@ -381,12 +381,11 @@ fuse.js "^6.6.2" redux "^4.2.0" -"@formio/core@2.3.0-dev.160.cabaa43": - version "2.3.0-dev.160.cabaa43" - resolved "https://registry.yarnpkg.com/@formio/core/-/core-2.3.0-dev.160.cabaa43.tgz#d61abaeecdfe7adb472afa33f68fe40f3f833751" - integrity sha512-GOpg2Fihsxph6aShM76q5SzrUSo5Xg3fm0aV6Up1hS+fZmJZb5xl+Ig5ABh3CnVncxkNPBsPj8I96sLYMdvj/A== +"@formio/core@v2.1.0-dev.174.9a3c6ec": + version "2.1.0-dev.174.9a3c6ec" + resolved "https://registry.yarnpkg.com/@formio/core/-/core-2.1.0-dev.174.9a3c6ec.tgz#f223b5ce4f374a9f4e922dada0af7c029320e035" + integrity sha512-QQK04dP0xBFa3vuhiOi+TUP8Zwqlg38qxzHgDmBwSlRO5XqQIObPJpSSnv2VA8H7fBWWiV2g7AErHBxugJW7Rw== dependencies: - "@types/json-logic-js" "^2.0.7" browser-cookies "^1.2.0" core-js "^3.38.0" dayjs "^1.11.12" @@ -653,11 +652,6 @@ resolved "https://registry.npmjs.org/@types/expect/-/expect-1.20.4.tgz#8288e51737bf7e3ab5d7c77bfa695883745264e5" integrity sha512-Q5Vn3yjTDyCMV50TB6VRIbQNxSE4OmZR86VSbGaNpfUolm0iePBB4KdEEHmxoY5sT2+2DIvXW0rvMDP2nHZ4Mg== -"@types/json-logic-js@^2.0.7": - version "2.0.7" - resolved "https://registry.npmjs.org/@types/json-logic-js/-/json-logic-js-2.0.7.tgz#09a70a932d0be937618a9fc791291b069e637fb0" - integrity sha512-fucvZmbjqa1+gpw/nIwcP+ZIYHTvmwxuQQFKw/yU7+ZSD63z/xgY5pWN7sYUDRzg2Wf9STapL+7c66FNzhU6+Q== - "@types/json-schema@*", "@types/json-schema@^7.0.8": version "7.0.15" resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841" @@ -7325,7 +7319,7 @@ string-replace-loader@^3.1.0: loader-utils "^2.0.0" schema-utils "^3.0.0" -"string-width-cjs@npm:string-width@^4.2.0": +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0: version "4.2.3" resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -7343,15 +7337,6 @@ string-width@^1.0.1, string-width@^1.0.2: is-fullwidth-code-point "^1.0.0" strip-ansi "^3.0.0" -string-width@^4.1.0, string-width@^4.2.0: - version "4.2.3" - resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - string-width@^5.0.1, string-width@^5.1.2: version "5.1.2" resolved "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794" @@ -7412,7 +7397,7 @@ stringifier@^1.3.0: traverse "^0.6.6" type-name "^2.0.1" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -7433,13 +7418,6 @@ strip-ansi@^4.0.0: dependencies: ansi-regex "^3.0.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -8502,7 +8480,7 @@ workerpool@6.2.1: resolved "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343" integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -8528,15 +8506,6 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"