Skip to content

Commit

Permalink
Merge pull request #5870 from formio/FIO-9189-fixed-conditions-with-s…
Browse files Browse the repository at this point in the history
…elect-resource

FIO-9189: moved some methods to core
  • Loading branch information
brendanbond authored Oct 18, 2024
2 parents 8dbfe8d + aa1e3d9 commit af52e2d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 88 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 2 additions & 13 deletions src/utils/conditionOperators/IsEqualTo.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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);
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/utils/formUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ const {
applyFormChanges,
findComponent,
getEmptyValue,
isComponentDataEmpty
isComponentDataEmpty,
isSelectResourceWithObjectValue,
compareSelectResourceWithObjectTypeValues,
getItemTemplateKeys
} = Utils;

/**
Expand Down Expand Up @@ -85,5 +88,8 @@ export {
applyFormChanges,
findComponent,
getEmptyValue,
isComponentDataEmpty
isComponentDataEmpty,
isSelectResourceWithObjectValue,
compareSelectResourceWithObjectTypeValues,
getItemTemplateKeys
};
34 changes: 0 additions & 34 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>} - 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'));
}
45 changes: 7 additions & 38 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand All @@ -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"
Expand Down Expand Up @@ -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==
Expand All @@ -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"
Expand Down Expand Up @@ -8502,7 +8480,7 @@ [email protected]:
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==
Expand All @@ -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"
Expand Down

0 comments on commit af52e2d

Please sign in to comment.