@oneblink/apps-react 0.6.1 → 0.6.2-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@oneblink/apps-react",
3
3
  "description": "Helper functions for OneBlink apps in ReactJS.",
4
- "version": "0.6.1",
4
+ "version": "0.6.2-beta.3",
5
5
  "author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/oneblink/apps-react/issues"
8
8
  },
9
9
  "dependencies": {
10
10
  "@blinkmobile/geolocation": "^2.0.3",
11
- "@emotion/react": "^11.8.2",
11
+ "@emotion/react": "^11.9.0",
12
12
  "@emotion/styled": "^11.8.1",
13
- "@mui/material": "^5.5.3",
14
- "@oneblink/sdk-core": "^0.3.6",
13
+ "@mui/material": "^5.6.1",
14
+ "@oneblink/sdk-core": "^0.4.0-beta.2",
15
15
  "@react-google-maps/api": "2.7.0",
16
16
  "blueimp-load-image": "^5.16.0",
17
17
  "bulma": "^0.9.3",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "devDependencies": {
44
44
  "@babel/preset-env": "^7.16.11",
45
- "@oneblink/apps": "^0.12.10-beta.1",
45
+ "@oneblink/apps": "0.12.0",
46
46
  "@oneblink/release-cli": "^1.0.0",
47
47
  "@oneblink/types": "github:oneblink/types",
48
48
  "@types/blueimp-load-image": "^5.14.4",
@@ -61,10 +61,10 @@
61
61
  "@types/sanitize-html": "^2.6.2",
62
62
  "@types/uuid": "^8.3.4",
63
63
  "@types/xml2js": "^0.4.9",
64
- "@typescript-eslint/eslint-plugin": "^5.18.0",
65
- "@typescript-eslint/parser": "^5.18.0",
64
+ "@typescript-eslint/eslint-plugin": "^5.19.0",
65
+ "@typescript-eslint/parser": "^5.19.0",
66
66
  "copyfiles": "^2.4.1",
67
- "eslint": "^8.12.0",
67
+ "eslint": "^8.13.0",
68
68
  "eslint-config-prettier": "^8.5.0",
69
69
  "eslint-plugin-prettier": "^4.0.0",
70
70
  "eslint-plugin-react": "^7.29.4",
@@ -75,9 +75,9 @@
75
75
  "react": "^17.0.2",
76
76
  "react-dom": "^17.0.2",
77
77
  "react-router-dom": "^5.3.0",
78
- "sass": "^1.49.11",
78
+ "sass": "^1.50.0",
79
79
  "ts-jest": "^27.1.4",
80
- "tsc-watch": "^5.0.2",
80
+ "tsc-watch": "^5.0.3",
81
81
  "typescript": "^4.6.3"
82
82
  },
83
83
  "engines": {
@@ -92,7 +92,7 @@
92
92
  "main": "./dist/index.js",
93
93
  "module": "./dist/index.js",
94
94
  "peerDependencies": {
95
- "@oneblink/apps": "^0.12.10-beta.1",
95
+ "@oneblink/apps": "^0.12.0 || ^0.12.11-beta.1",
96
96
  "react": "^17.0.0",
97
97
  "react-dom": "^17.0.0",
98
98
  "react-router-dom": "^5.2.0"
@@ -1,11 +0,0 @@
1
- import { FormTypes } from '@oneblink/types';
2
- import { FormSubmissionModel } from '../types/form';
3
- export declare type FormElementsCtrl = {
4
- model: FormSubmissionModel;
5
- flattenedElements: import('@oneblink/types').FormTypes.FormElement[];
6
- parentFormElementsCtrl?: FormElementsCtrl;
7
- };
8
- export default function conditionallyShowElement(formElementsCtrl: FormElementsCtrl, elementToEvaluate: FormTypes.FormElement, elementsEvaluated: Array<{
9
- id: string;
10
- label: string;
11
- }>): boolean;
@@ -1,92 +0,0 @@
1
- import { conditionalLogicService } from '@oneblink/sdk-core';
2
- const getParentFormElements = (formElementsCtrl, childElement) => {
3
- const parentElement = formElementsCtrl.flattenedElements.find((element) => {
4
- return ((element.type === 'page' || element.type === 'section') &&
5
- element.elements.some(({ id }) => id === childElement.id));
6
- });
7
- if (parentElement &&
8
- (parentElement.type === 'page' || parentElement.type === 'section')) {
9
- return [
10
- parentElement,
11
- ...getParentFormElements(formElementsCtrl, parentElement),
12
- ];
13
- }
14
- return [];
15
- };
16
- const conditionallyShowByPredicate = (formElementsCtrl, predicate, elementsEvaluated) => {
17
- const predicateElement = formElementsCtrl.flattenedElements.find((element) => {
18
- return element.id === predicate.elementId;
19
- });
20
- // If we cant find the element used for the predicate,
21
- // we can check to see if the element being evaluated
22
- // is in a repeatable set and the predicate element is
23
- // in a parent list of elements.
24
- if (!predicateElement) {
25
- if (formElementsCtrl.parentFormElementsCtrl) {
26
- return conditionallyShowByPredicate(formElementsCtrl.parentFormElementsCtrl, predicate, elementsEvaluated);
27
- }
28
- else {
29
- return false;
30
- }
31
- }
32
- // Here we will also need to check if the predicate element
33
- // is on a page/section element and the page/section element
34
- // is also hidden. If it is hidden we will treat this
35
- // predicate element as hidden as well.
36
- const parentFormElements = getParentFormElements(formElementsCtrl, predicateElement);
37
- for (const parentFormElement of parentFormElements) {
38
- if (!conditionallyShowElement(formElementsCtrl, parentFormElement, [
39
- ...elementsEvaluated,
40
- ])) {
41
- return false;
42
- }
43
- }
44
- // Check to see if the model has one of the valid values to show the element
45
- return (conditionallyShowElement(formElementsCtrl, predicateElement, elementsEvaluated) &&
46
- conditionalLogicService.evaluateConditionalPredicate({
47
- predicate,
48
- submission: formElementsCtrl.model,
49
- predicateElement,
50
- }));
51
- };
52
- export default function conditionallyShowElement(formElementsCtrl, elementToEvaluate, elementsEvaluated) {
53
- // If the element does not have the `conditionallyShow` flag set,
54
- // we can always show the element.
55
- if (!elementToEvaluate ||
56
- !elementToEvaluate.conditionallyShow ||
57
- !Array.isArray(elementToEvaluate.conditionallyShowPredicates) ||
58
- !elementToEvaluate.conditionallyShowPredicates.length) {
59
- return true;
60
- }
61
- const conditionallyShowPredicates = elementToEvaluate.conditionallyShowPredicates;
62
- // Check to see if this element has already been used to evaluate
63
- // if the element should be shown based on parent element conditional logic
64
- const elementAlreadyEvaluated = elementsEvaluated.find(({ id }) => id === elementToEvaluate.id);
65
- if (elementAlreadyEvaluated) {
66
- throw new Error(`Your conditional logic has caused an infinite loop. Check the "${elementAlreadyEvaluated.label}" form element to ensure element A does not rely on element B if element B also relies on element A.`);
67
- }
68
- else {
69
- elementsEvaluated.push({
70
- id: elementToEvaluate.id,
71
- label: elementToEvaluate.type === 'form' ||
72
- elementToEvaluate.type === 'infoPage'
73
- ? elementToEvaluate.name
74
- : elementToEvaluate.label,
75
- });
76
- }
77
- const predicateFunction = (predicate) => {
78
- // Spread the array of elements evaluated so that each predicate can
79
- // evaluate the tree without causing false positives for infinite
80
- // loop conditional logic
81
- return conditionallyShowByPredicate(formElementsCtrl, predicate, [
82
- ...elementsEvaluated,
83
- ]);
84
- };
85
- if (elementToEvaluate.requiresAllConditionallyShowPredicates) {
86
- return conditionallyShowPredicates.every(predicateFunction);
87
- }
88
- else {
89
- return conditionallyShowPredicates.some(predicateFunction);
90
- }
91
- }
92
- //# sourceMappingURL=conditionally-show-element.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"conditionally-show-element.js","sourceRoot":"","sources":["../../src/services/conditionally-show-element.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAS5D,MAAM,qBAAqB,GAAG,CAC5B,gBAAkC,EAClC,YAAmC,EACsB,EAAE;IAC3D,MAAM,aAAa,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QACxE,OAAO,CACL,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC;YACvD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,YAAY,CAAC,EAAE,CAAC,CAC1D,CAAA;IACH,CAAC,CAAC,CAAA;IACF,IACE,aAAa;QACb,CAAC,aAAa,CAAC,IAAI,KAAK,MAAM,IAAI,aAAa,CAAC,IAAI,KAAK,SAAS,CAAC,EACnE;QACA,OAAO;YACL,aAAa;YACb,GAAG,qBAAqB,CAAC,gBAAgB,EAAE,aAAa,CAAC;SAC1D,CAAA;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import { conditionalLogicService } from '@oneblink/sdk-core'\nimport { FormSubmissionModel } from '../types/form'\n\nexport type FormElementsCtrl = {\n model: FormSubmissionModel\n flattenedElements: import('@oneblink/types').FormTypes.FormElement[]\n parentFormElementsCtrl?: FormElementsCtrl\n}\n\nconst getParentFormElements = (\n formElementsCtrl: FormElementsCtrl,\n childElement: FormTypes.FormElement,\n): Array<FormTypes.SectionElement | FormTypes.PageElement> => {\n const parentElement = formElementsCtrl.flattenedElements.find((element) => {\n return (\n (element.type === 'page' || element.type === 'section') &&\n element.elements.some(({ id }) => id === childElement.id)\n )\n })\n if (\n parentElement &&\n (parentElement.type === 'page' || parentElement.type === 'section')\n ) {\n return [\n parentElement,\n ...getParentFormElements(formElementsCtrl, parentElement),\n ]\n }\n return []\n}\n\nconst conditionallyShowByPredicate = (\n formElementsCtrl: FormElementsCtrl,\n predicate: ConditionTypes.ConditionalPredicate,\n elementsEvaluated: Array<{ id: string; label: string }>,\n): FormTypes.FormElement | boolean => {\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element: FormTypes.FormElement) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return conditionallyShowByPredicate(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return false\n }\n }\n\n // Here we will also need to check if the predicate element\n // is on a page/section element and the page/section element\n // is also hidden. If it is hidden we will treat this\n // predicate element as hidden as well.\n const parentFormElements = getParentFormElements(\n formElementsCtrl,\n predicateElement,\n )\n for (const parentFormElement of parentFormElements) {\n if (\n !conditionallyShowElement(formElementsCtrl, parentFormElement, [\n ...elementsEvaluated,\n ])\n ) {\n return false\n }\n }\n\n // Check to see if the model has one of the valid values to show the element\n return (\n conditionallyShowElement(\n formElementsCtrl,\n predicateElement,\n elementsEvaluated,\n ) &&\n conditionalLogicService.evaluateConditionalPredicate({\n predicate,\n submission: formElementsCtrl.model,\n predicateElement,\n })\n )\n}\n\nexport default function conditionallyShowElement(\n formElementsCtrl: FormElementsCtrl,\n elementToEvaluate: FormTypes.FormElement,\n elementsEvaluated: Array<{ id: string; label: string }>,\n): boolean {\n // If the element does not have the `conditionallyShow` flag set,\n // we can always show the element.\n if (\n !elementToEvaluate ||\n !elementToEvaluate.conditionallyShow ||\n !Array.isArray(elementToEvaluate.conditionallyShowPredicates) ||\n !elementToEvaluate.conditionallyShowPredicates.length\n ) {\n return true\n }\n const conditionallyShowPredicates =\n elementToEvaluate.conditionallyShowPredicates\n\n // Check to see if this element has already been used to evaluate\n // if the element should be shown based on parent element conditional logic\n const elementAlreadyEvaluated = elementsEvaluated.find(\n ({ id }) => id === elementToEvaluate.id,\n )\n if (elementAlreadyEvaluated) {\n throw new Error(\n `Your conditional logic has caused an infinite loop. Check the \"${elementAlreadyEvaluated.label}\" form element to ensure element A does not rely on element B if element B also relies on element A.`,\n )\n } else {\n elementsEvaluated.push({\n id: elementToEvaluate.id,\n label:\n elementToEvaluate.type === 'form' ||\n elementToEvaluate.type === 'infoPage'\n ? elementToEvaluate.name\n : elementToEvaluate.label,\n })\n }\n\n const predicateFunction = (\n predicate: ConditionTypes.ConditionalPredicate,\n ) => {\n // Spread the array of elements evaluated so that each predicate can\n // evaluate the tree without causing false positives for infinite\n // loop conditional logic\n return conditionallyShowByPredicate(formElementsCtrl, predicate, [\n ...elementsEvaluated,\n ])\n }\n\n if (elementToEvaluate.requiresAllConditionallyShowPredicates) {\n return conditionallyShowPredicates.every(predicateFunction)\n } else {\n return conditionallyShowPredicates.some(predicateFunction)\n }\n}\n"]}
@@ -1,3 +0,0 @@
1
- import { FormTypes } from '@oneblink/types';
2
- import { FormElementsCtrl } from '../services/conditionally-show-element';
3
- export default function conditionallyShowOption(formElementsCtrl: FormElementsCtrl, elementToEvaluate: FormTypes.FormElementWithOptions, optionToEvaluate: FormTypes.ChoiceElementOption, optionsEvaluated: string[]): boolean;
@@ -1,135 +0,0 @@
1
- import { conditionalLogicService } from '@oneblink/sdk-core';
2
- import conditionallyShowElement from '../services/conditionally-show-element';
3
- const handleAttributePredicate = (predicate, model, predicateElement) => {
4
- const values = model[predicateElement.name];
5
- if (!values)
6
- return true;
7
- if (Array.isArray(values) &&
8
- (!values.length ||
9
- !values.filter((value) => typeof value !== 'undefined').length)) {
10
- return true;
11
- }
12
- return conditionalLogicService.evaluateConditionalOptionsPredicate({
13
- predicate: {
14
- type: 'OPTIONS',
15
- elementId: predicate.elementId,
16
- optionIds: predicate.optionIds,
17
- },
18
- submission: model,
19
- predicateElement,
20
- });
21
- };
22
- const conditionallyShowOptionByPredicate = (formElementsCtrl, predicate, elementsEvaluated) => {
23
- // Validate the predicate data, if it is invalid,
24
- // we will always show the field
25
- if (!predicate ||
26
- !predicate.elementId ||
27
- !predicate.optionIds ||
28
- !predicate.optionIds.length) {
29
- return true;
30
- }
31
- const predicateElement = formElementsCtrl.flattenedElements.find((element) => {
32
- return element.id === predicate.elementId;
33
- });
34
- // If we cant find the element used for the predicate,
35
- // we can check to see if the element being evaluated
36
- // is in a repeatable set and the predicate element is
37
- // in a parent list of elements.
38
- if (!predicateElement) {
39
- if (formElementsCtrl.parentFormElementsCtrl) {
40
- return conditionallyShowOptionByPredicate(formElementsCtrl.parentFormElementsCtrl, predicate, elementsEvaluated);
41
- }
42
- else {
43
- return false;
44
- }
45
- }
46
- if (predicateElement.type !== 'compliance' &&
47
- predicateElement.type !== 'select' &&
48
- predicateElement.type !== 'autocomplete' &&
49
- predicateElement.type !== 'checkboxes' &&
50
- predicateElement.type !== 'radio') {
51
- return false;
52
- }
53
- // If the predicate element does not have any options to evaluate,
54
- // we will show the element.
55
- // Unless the predicate element has dynamic options and
56
- // options have not been fetched yet.
57
- if (!Array.isArray(predicateElement.options)) {
58
- return predicateElement.optionsType !== 'DYNAMIC';
59
- }
60
- const everyOptionIsShowing = predicate.optionIds.every((id) => {
61
- var _a;
62
- const predicateOption = (_a = predicateElement.options) === null || _a === void 0 ? void 0 : _a.find((o) => o.id === id);
63
- if (!predicateOption)
64
- return false;
65
- return conditionallyShowOption({ model: formElementsCtrl.model, flattenedElements: [] }, predicateElement, predicateOption, elementsEvaluated);
66
- });
67
- if (!everyOptionIsShowing) {
68
- return false;
69
- }
70
- // Check to see if the model has one of the valid values to show the element
71
- return handleAttributePredicate(predicate, formElementsCtrl.model, predicateElement);
72
- };
73
- const isAttributeFilterValid = (formElementsCtrl, predicate, elementsEvaluated) => {
74
- const predicateElement = formElementsCtrl.flattenedElements.find((element) => {
75
- return element.id === predicate.elementId;
76
- });
77
- // If we cant find the element used for the predicate,
78
- // we can check to see if the element being evaluated
79
- // is in a repeatable set and the predicate element is
80
- // in a parent list of elements.
81
- if (!predicateElement) {
82
- if (formElementsCtrl.parentFormElementsCtrl) {
83
- return isAttributeFilterValid(formElementsCtrl.parentFormElementsCtrl, predicate, elementsEvaluated);
84
- }
85
- else {
86
- return false;
87
- }
88
- }
89
- // now we have the model and predicate element, verify that the predicate element
90
- // is not hidden
91
- if (
92
- // Will never be a page, just making typescript happy :)
93
- predicateElement.type === 'page' ||
94
- predicateElement.type === 'section' ||
95
- !conditionallyShowElement(formElementsCtrl, predicateElement, [])) {
96
- return false;
97
- }
98
- // verify that at least one option is selected
99
- const values = formElementsCtrl.model[predicateElement.name];
100
- if (!values)
101
- return false;
102
- // if the model value is an array, verify that it has a selection
103
- if (Array.isArray(values) &&
104
- (!values.length ||
105
- !values.filter((value) => typeof value !== 'undefined').length)) {
106
- return false;
107
- }
108
- return true;
109
- };
110
- export default function conditionallyShowOption(formElementsCtrl, elementToEvaluate, optionToEvaluate, optionsEvaluated) {
111
- // If the element does not have the `conditionallyShow` flag set,
112
- // we can always show the element.
113
- if (!elementToEvaluate.conditionallyShowOptions ||
114
- !optionToEvaluate ||
115
- !optionToEvaluate.attributes ||
116
- !Array.isArray(optionToEvaluate.attributes) ||
117
- !optionToEvaluate.attributes.length) {
118
- return true;
119
- }
120
- // Check to see if this element has already been used to evaluate
121
- // if the element should be shown based on parent element conditional logic
122
- if (optionsEvaluated.some((optionId) => optionId === optionToEvaluate.id)) {
123
- throw new Error('Your conditional logic has caused an infinite loop. Check the following Fields to ensure element A does not rely on element B if element B also relies on element A.');
124
- }
125
- else {
126
- optionsEvaluated.push(optionToEvaluate.id);
127
- }
128
- const validPredicates = (optionToEvaluate.attributes || []).filter((predicate) => {
129
- return isAttributeFilterValid(formElementsCtrl, predicate, optionsEvaluated);
130
- });
131
- if (!validPredicates.length)
132
- return true;
133
- return validPredicates.some((predicate) => conditionallyShowOptionByPredicate(formElementsCtrl, predicate, optionsEvaluated));
134
- }
135
- //# sourceMappingURL=conditionally-show-option.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"conditionally-show-option.js","sourceRoot":"","sources":["../../src/services/conditionally-show-option.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAE5D,OAAO,wBAEN,MAAM,wCAAwC,CAAA;AAG/C,MAAM,wBAAwB,GAAG,CAC/B,SAAiD,EACjD,KAA0B,EAC1B,gBAAkD,EAClD,EAAE;IACF,MAAM,MAAM,GAAG,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAA;IAC3C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,IACE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QACrB,CAAC,CAAC,MAAM,CAAC,MAAM;YACb,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,WAAW,CAAC,CAAC,MAAM,CAAC,EACjE;QACA,OAAO,IAAI,CAAA;KACZ;IAED,OAAO,uBAAuB,CAAC,mCAAmC,CAAC;QACjE,SAAS,EAAE;YACT,IAAI,EAAE,SAAS;YACf,SAAS,EAAE,SAAS,CAAC,SAAS;YAC9B,SAAS,EAAE,SA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AAgB,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,MAAM,CAChE,CAAC,SAAS,EAAE,EAAE;QACZ,OAAO,sBAAsB,CAC3B,gBAAgB,EAChB,SAAS,EACT,gBAAgB,CACjB,CAAA;IACH,CAAC,CACF,CAAA;IAED,IAAI,CAAC,eAAe,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IACxC,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CACxC,kCAAkC,CAChC,gBAAgB,EAChB,SAAS,EACT,gBAAgB,CACjB,CACF,CAAA;AACH,CAAC","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport { conditionalLogicService } from '@oneblink/sdk-core'\n\nimport conditionallyShowElement, {\n FormElementsCtrl,\n} from '../services/conditionally-show-element'\nimport { FormSubmissionModel } from '../types/form'\n\nconst handleAttributePredicate = (\n predicate: FormTypes.ChoiceElementOptionAttribute,\n model: FormSubmissionModel,\n predicateElement: FormTypes.FormElementWithOptions,\n) => {\n const values = model[predicateElement.name]\n if (!values) return true\n\n if (\n Array.isArray(values) &&\n (!values.length ||\n !values.filter((value) => typeof value !== 'undefined').length)\n ) {\n return true\n }\n\n return conditionalLogicService.evaluateConditionalOptionsPredicate({\n predicate: {\n type: 'OPTIONS',\n elementId: predicate.elementId,\n optionIds: predicate.optionIds,\n },\n submission: model,\n predicateElement,\n })\n}\n\nconst conditionallyShowOptionByPredicate = (\n formElementsCtrl: FormElementsCtrl,\n predicate: FormTypes.ChoiceElementOptionAttribute,\n elementsEvaluated: string[],\n): boolean => {\n // Validate the predicate data, if it is invalid,\n // we will always show the field\n if (\n !predicate ||\n !predicate.elementId ||\n !predicate.optionIds ||\n !predicate.optionIds.length\n ) {\n return true\n }\n\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return conditionallyShowOptionByPredicate(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return false\n }\n }\n\n if (\n predicateElement.type !== 'compliance' &&\n predicateElement.type !== 'select' &&\n predicateElement.type !== 'autocomplete' &&\n predicateElement.type !== 'checkboxes' &&\n predicateElement.type !== 'radio'\n ) {\n return false\n }\n\n // If the predicate element does not have any options to evaluate,\n // we will show the element.\n // Unless the predicate element has dynamic options and\n // options have not been fetched yet.\n if (!Array.isArray(predicateElement.options)) {\n return predicateElement.optionsType !== 'DYNAMIC'\n }\n\n const everyOptionIsShowing = predicate.optionIds.every((id) => {\n const predicateOption = predicateElement.options?.find((o) => o.id === id)\n if (!predicateOption) return false\n\n return conditionallyShowOption(\n { model: formElementsCtrl.model, flattenedElements: [] },\n predicateElement,\n predicateOption,\n elementsEvaluated,\n )\n })\n\n if (!everyOptionIsShowing) {\n return false\n }\n\n // Check to see if the model has one of the valid values to show the element\n return handleAttributePredicate(\n predicate,\n formElementsCtrl.model,\n predicateElement,\n )\n}\n\nconst isAttributeFilterValid = (\n formElementsCtrl: FormElementsCtrl,\n predicate: FormTypes.ChoiceElementOptionAttribute,\n elementsEvaluated: string[],\n): boolean => {\n const predicateElement = formElementsCtrl.flattenedElements.find(\n (element) => {\n return element.id === predicate.elementId\n },\n )\n\n // If we cant find the element used for the predicate,\n // we can check to see if the element being evaluated\n // is in a repeatable set and the predicate element is\n // in a parent list of elements.\n if (!predicateElement) {\n if (formElementsCtrl.parentFormElementsCtrl) {\n return isAttributeFilterValid(\n formElementsCtrl.parentFormElementsCtrl,\n predicate,\n elementsEvaluated,\n )\n } else {\n return false\n }\n }\n\n // now we have the model and predicate element, verify that the predicate element\n // is not hidden\n if (\n // Will never be a page, just making typescript happy :)\n predicateElement.type === 'page' ||\n predicateElement.type === 'section' ||\n !conditionallyShowElement(formElementsCtrl, predicateElement, [])\n ) {\n return false\n }\n\n // verify that at least one option is selected\n const values = formElementsCtrl.model[predicateElement.name]\n if (!values) return false\n // if the model value is an array, verify that it has a selection\n if (\n Array.isArray(values) &&\n (!values.length ||\n !values.filter((value) => typeof value !== 'undefined').length)\n ) {\n return false\n }\n\n return true\n}\n\nexport default function conditionallyShowOption(\n formElementsCtrl: FormElementsCtrl,\n elementToEvaluate: FormTypes.FormElementWithOptions,\n optionToEvaluate: FormTypes.ChoiceElementOption,\n optionsEvaluated: string[],\n): boolean {\n // If the element does not have the `conditionallyShow` flag set,\n // we can always show the element.\n\n if (\n !elementToEvaluate.conditionallyShowOptions ||\n !optionToEvaluate ||\n !optionToEvaluate.attributes ||\n !Array.isArray(optionToEvaluate.attributes) ||\n !optionToEvaluate.attributes.length\n ) {\n return true\n }\n\n // Check to see if this element has already been used to evaluate\n // if the element should be shown based on parent element conditional logic\n if (optionsEvaluated.some((optionId) => optionId === optionToEvaluate.id)) {\n throw new Error(\n 'Your conditional logic has caused an infinite loop. Check the following Fields to ensure element A does not rely on element B if element B also relies on element A.',\n )\n } else {\n optionsEvaluated.push(optionToEvaluate.id)\n }\n\n const validPredicates = (optionToEvaluate.attributes || []).filter(\n (predicate) => {\n return isAttributeFilterValid(\n formElementsCtrl,\n predicate,\n optionsEvaluated,\n )\n },\n )\n\n if (!validPredicates.length) return true\n return validPredicates.some((predicate) =>\n conditionallyShowOptionByPredicate(\n formElementsCtrl,\n predicate,\n optionsEvaluated,\n ),\n )\n}\n"]}