@oneblink/sdk-core
Advanced tools
Comparing version 0.4.4 to 0.4.5
import { FormTypes } from '@oneblink/types'; | ||
import { FormElementsCtrl } from '../types'; | ||
export default function conditionallyShowOption(formElementsCtrl: FormElementsCtrl, elementToEvaluate: FormTypes.FormElementWithOptions, optionToEvaluate: FormTypes.ChoiceElementOption, optionsEvaluated: string[]): boolean; | ||
export declare type ShouldShowOption = 'SHOW' | 'HIDE' | 'LOADING_DYNAMIC_DEPENDENCY' | 'LOADING_STATIC_DEPENDENCY'; | ||
export default function conditionallyShowOption(formElementsCtrl: FormElementsCtrl, elementToEvaluate: FormTypes.FormElementWithOptions, optionToEvaluate: FormTypes.ChoiceElementOption, optionsEvaluated: string[]): ShouldShowOption; |
@@ -35,3 +35,3 @@ "use strict"; | ||
!predicate.optionIds.length) { | ||
return true; | ||
return 'SHOW'; | ||
} | ||
@@ -50,3 +50,3 @@ const predicateElement = formElementsCtrl.flattenedElements.find((element) => { | ||
else { | ||
return false; | ||
return 'HIDE'; | ||
} | ||
@@ -56,3 +56,3 @@ } | ||
if (!optionsPredicateElement) { | ||
return false; | ||
return 'HIDE'; | ||
} | ||
@@ -63,4 +63,10 @@ // If the predicate element does not have any options to evaluate, | ||
// options have not been fetched yet. | ||
if (!Array.isArray(optionsPredicateElement.options)) { | ||
return optionsPredicateElement.optionsType !== 'DYNAMIC'; | ||
const isLoadingPredicateElementsOptions = !Array.isArray(optionsPredicateElement.options); | ||
if (isLoadingPredicateElementsOptions) { | ||
if (optionsPredicateElement.optionsType === 'DYNAMIC') { | ||
return 'LOADING_DYNAMIC_DEPENDENCY'; | ||
} | ||
else { | ||
return 'LOADING_STATIC_DEPENDENCY'; | ||
} | ||
} | ||
@@ -71,10 +77,11 @@ const everyOptionIsShowing = predicate.optionIds.every((id) => { | ||
if (!predicateOption) | ||
return false; | ||
return 'HIDE'; | ||
return conditionallyShowOption({ model: formElementsCtrl.model, flattenedElements: [] }, optionsPredicateElement, predicateOption, elementsEvaluated); | ||
}); | ||
if (!everyOptionIsShowing) { | ||
return false; | ||
return 'HIDE'; | ||
} | ||
// Check to see if the model has one of the valid values to show the element | ||
return handleAttributePredicate(predicate, formElementsCtrl.model, optionsPredicateElement); | ||
const shouldShow = handleAttributePredicate(predicate, formElementsCtrl.model, optionsPredicateElement); | ||
return shouldShow ? 'SHOW' : 'HIDE'; | ||
}; | ||
@@ -126,3 +133,3 @@ const isAttributeFilterValid = (formElementsCtrl, predicate, elementsEvaluated) => { | ||
!optionToEvaluate.attributes.length) { | ||
return true; | ||
return 'SHOW'; | ||
} | ||
@@ -141,6 +148,32 @@ // Check to see if this element has already been used to evaluate | ||
if (!validPredicates.length) | ||
return true; | ||
return validPredicates.some((predicate) => conditionallyShowOptionByPredicate(formElementsCtrl, predicate, optionsEvaluated)); | ||
return 'SHOW'; | ||
let isLoadingDynamicDEPENDENCY = false; | ||
let isLoadingStaticDEPENDENCY = false; | ||
for (const predicate of validPredicates) { | ||
const predicateResult = conditionallyShowOptionByPredicate(formElementsCtrl, predicate, optionsEvaluated); | ||
switch (predicateResult) { | ||
case 'SHOW': { | ||
return 'SHOW'; | ||
} | ||
case 'LOADING_DYNAMIC_DEPENDENCY': { | ||
isLoadingDynamicDEPENDENCY = true; | ||
break; | ||
} | ||
case 'LOADING_STATIC_DEPENDENCY': { | ||
isLoadingStaticDEPENDENCY = true; | ||
break; | ||
} | ||
} | ||
} | ||
if (isLoadingDynamicDEPENDENCY) { | ||
return 'LOADING_DYNAMIC_DEPENDENCY'; | ||
} | ||
else if (isLoadingStaticDEPENDENCY) { | ||
return 'LOADING_STATIC_DEPENDENCY'; | ||
} | ||
else { | ||
return 'HIDE'; | ||
} | ||
} | ||
exports.default = conditionallyShowOption; | ||
//# sourceMappingURL=conditionallyShowOption.js.map |
@@ -7,2 +7,3 @@ import { FormTypes, SubmissionTypes } from '@oneblink/types'; | ||
options?: import('@oneblink/types').FormTypes.ChoiceElementOption[]; | ||
dependencyIsLoading?: boolean; | ||
} | { | ||
@@ -9,0 +10,0 @@ type: 'formElements'; |
@@ -26,3 +26,3 @@ "use strict"; | ||
errorCallback && errorCallback(error); | ||
return false; | ||
return 'HIDE'; | ||
} | ||
@@ -121,4 +121,22 @@ }; | ||
Array.isArray(optionsElement.options)) { | ||
formElementConditionallyShown.options = | ||
optionsElement.options.filter((option) => handleConditionallyShowOption(formElementsCtrl, optionsElement, option, errorCallback)); | ||
const newOptions = []; | ||
for (const option of optionsElement.options) { | ||
const optionPredicatesResult = handleConditionallyShowOption(formElementsCtrl, optionsElement, option, errorCallback); | ||
switch (optionPredicatesResult) { | ||
case 'SHOW': { | ||
newOptions.push(option); | ||
break; | ||
} | ||
case 'LOADING_STATIC_DEPENDENCY': { | ||
newOptions.push(option); | ||
formElementConditionallyShown.dependencyIsLoading = true; | ||
break; | ||
} | ||
case 'LOADING_DYNAMIC_DEPENDENCY': { | ||
formElementConditionallyShown.dependencyIsLoading = true; | ||
break; | ||
} | ||
} | ||
} | ||
formElementConditionallyShown.options = newOptions; | ||
} | ||
@@ -125,0 +143,0 @@ } |
{ | ||
"name": "@oneblink/sdk-core", | ||
"description": "OneBlink SDK for JavaScript (works in Browsers and NodeJS)", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)", | ||
@@ -6,0 +6,0 @@ "bugs": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
232973
2616