forked from holubv/s-forms-smart-components
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use property for component mapping instead of ComponentRegistry
- Loading branch information
Showing
4 changed files
with
57 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import CompositeQuestion from "./components/CompositeQuestion"; | ||
import JsonLdUtils from "jsonld-utils"; | ||
import Constants from "./Constants"; | ||
import QuestionWithAdvanced from "./components/QuestionWithAdvanced"; | ||
import {Constants as SConstants, FormUtils} from "s-forms"; | ||
import WizardStepWithAdvanced from "./components/WizardStepWithAdvanced"; | ||
|
||
export default class SmartComponents { | ||
|
||
static getComponentMapping() { | ||
return [ | ||
{ | ||
component: CompositeQuestion, | ||
mapRule: q => JsonLdUtils.getJsonAttValue(q, Constants.COMPOSITE_PATTERN) | ||
}, | ||
{ | ||
component: QuestionWithAdvanced, | ||
mapRule: q => { | ||
return SmartComponents._hasAdvancedQuestion(q) && !FormUtils.isWizardStep(q); | ||
} | ||
}, | ||
{ | ||
component: WizardStepWithAdvanced, | ||
mapRule: q => { | ||
return SmartComponents._hasAdvancedQuestion(q) && FormUtils.isWizardStep(q); | ||
} | ||
} | ||
]; | ||
} | ||
|
||
static _hasAdvancedQuestion(q) { | ||
|
||
if (!FormUtils.isSection(q) && !FormUtils.isAnswerable(q)) { | ||
return false; | ||
} | ||
let subQuestions = q[SConstants.HAS_SUBQUESTION]; | ||
if (subQuestions && subQuestions.length) { | ||
for (let subQuestion of subQuestions) { | ||
if (JsonLdUtils.hasValue(subQuestion, Constants.SHOW_ADVANCED_QUESTION, true)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
|
||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters