Skip to content

Commit 8c519c5

Browse files
committed
Refactor - eliminate prop drilling by using context where available
1 parent 66c78f8 commit 8c519c5

23 files changed

+1060
-1140
lines changed

src/jsMain/kotlin/App.kt

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -52,48 +52,18 @@ class App : RComponent<Props, State>() {
5252
majorText = polyglot.t("appscreen_validator_major")
5353
minorText = polyglot.t("appscreen_validator_minor")
5454
}
55-
tabLayout {
56-
this.polyglot = polyglot
57-
}
55+
tabLayout {}
5856
}
5957
AppScreen.SETTINGS -> {
6058
sectionTitle {
6159
majorText = polyglot.t("appscreen_options_major")
6260
minorText = polyglot.t("appscreen_options_minor")
6361
}
64-
child(OptionsPage::class) {
65-
attrs.validationContext = validationContext?.validationContext
66-
?: ValidationContext().setBaseEngine("DEFAULT")
67-
attrs.igPackageInfoSet = validationContext?.igPackageInfoSet ?: emptySet()
68-
attrs.extensionSet = validationContext?.extensionSet ?: emptySet()
69-
attrs.profileSet = validationContext?.profileSet ?: emptySet()
70-
attrs.bundleValidationRuleSet = validationContext?.bundleValidationRuleSet ?: emptySet()
71-
attrs.polyglot = polyglot
72-
attrs.updateValidationContext = { context, resetBaseEngine ->
73-
validationContext?.updateValidationContext?.invoke(context, resetBaseEngine)
74-
}
75-
attrs.updateIgPackageInfoSet = { set, resetBaseEngine ->
76-
validationContext?.updateIgPackageInfoSet?.invoke(set, resetBaseEngine)
77-
}
78-
attrs.updateExtensionSet = { set, resetBaseEngine ->
79-
validationContext?.updateExtensionSet?.invoke(set, resetBaseEngine)
80-
}
81-
attrs.setSessionId = { id ->
82-
validationContext?.setSessionId?.invoke(id)
83-
}
84-
attrs.updateProfileSet = { set, resetBaseEngine ->
85-
validationContext?.updateProfileSet?.invoke(set, resetBaseEngine)
86-
}
87-
attrs.updateBundleValidationRuleSet = { set, resetBaseEngine ->
88-
validationContext?.updateBundleValidationRuleSet?.invoke(set, resetBaseEngine)
89-
}
90-
}
62+
child(OptionsPage::class) {}
9163
}
9264
}
9365
}
94-
footer {
95-
this.polyglot = polyglot
96-
}
66+
footer {}
9767
}
9868
}
9969
}

src/jsMain/kotlin/ui/components/footer/Footer.kt

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import styled.*
1515
import utils.Language
1616

1717
external interface FooterProps : Props {
18-
var language: Language //TODO
19-
var polyglot: Polyglot //TODO
18+
2019
}
2120

2221
class FooterState : State {
@@ -39,67 +38,70 @@ class Footer : RComponent<FooterProps, FooterState>() {
3938
}
4039

4140
override fun RBuilder.render() {
42-
styledFooter {
43-
css {
44-
+FooterStyle.footerContainer
45-
}
46-
styledDiv {
41+
context.LocalizationContext.Consumer { localizationContext ->
42+
val polyglot = localizationContext?.polyglot ?: Polyglot()
43+
styledFooter {
4744
css {
48-
+FooterStyle.footerColumn
45+
+FooterStyle.footerContainer
4946
}
50-
styledSpan {
47+
styledDiv {
5148
css {
52-
+FooterStyle.footerTitleLarge
49+
+FooterStyle.footerColumn
50+
}
51+
styledSpan {
52+
css {
53+
+FooterStyle.footerTitleLarge
54+
}
55+
+"validator-wrapper"
56+
}
57+
styledSpan {
58+
css {
59+
+FooterStyle.footerTitleSmall
60+
}
61+
+state.validatorWrapperVersion
62+
}
63+
styledSpan {
64+
css {
65+
+FooterStyle.footerTitleSmall
66+
}
67+
+(polyglot.t("footer_running_version") + state.validatorVersion)
5368
}
54-
+"validator-wrapper"
5569
}
56-
styledSpan {
70+
styledDiv {
5771
css {
58-
+FooterStyle.footerTitleSmall
72+
+FooterStyle.footerColumn
73+
}
74+
footerLineItem {
75+
href = "https://github.com/hapifhir/org.hl7.fhir.validator-wrapper"
76+
icon = "images/github_white.png"
77+
label = polyglot.t("footer_github")
78+
}
79+
footerLineItem {
80+
href = "https://github.com/hapifhir/org.hl7.fhir.validator-wrapper/issues/new/choose"
81+
icon = "images/bug_report_white.png"
82+
label = polyglot.t("footer_create_issue")
83+
}
84+
footerLineItem {
85+
href =
86+
"https://github.com/hapifhir/org.hl7.fhir.validator-wrapper/releases/latest/download/validator-wrapper.jar"
87+
icon = "images/download_white.png"
88+
label = polyglot.t("footer_download_app")
5989
}
60-
+ state.validatorWrapperVersion
6190
}
62-
styledSpan {
91+
styledDiv {
6392
css {
64-
+FooterStyle.footerTitleSmall
93+
+FooterStyle.footerColumn
94+
}
95+
footerLineItem {
96+
href = "https://confluence.hl7.org/display/FHIR/Using+the+FHIR+Validator"
97+
icon = "images/documentation_white.png"
98+
label = polyglot.t("footer_doc")
99+
}
100+
footerLineItem {
101+
href = "../swagger-ui/index.html"
102+
icon = "images/documentation_white.png"
103+
label = polyglot.t("footer_openapi")
65104
}
66-
+ (props.polyglot.t("footer_running_version") + state.validatorVersion)
67-
}
68-
}
69-
styledDiv {
70-
css {
71-
+FooterStyle.footerColumn
72-
}
73-
footerLineItem {
74-
href = "https://github.com/hapifhir/org.hl7.fhir.validator-wrapper"
75-
icon = "images/github_white.png"
76-
label = props.polyglot.t("footer_github")
77-
}
78-
footerLineItem {
79-
href = "https://github.com/hapifhir/org.hl7.fhir.validator-wrapper/issues/new/choose"
80-
icon = "images/bug_report_white.png"
81-
label = props.polyglot.t("footer_create_issue")
82-
}
83-
footerLineItem {
84-
href =
85-
"https://github.com/hapifhir/org.hl7.fhir.validator-wrapper/releases/latest/download/validator-wrapper.jar"
86-
icon = "images/download_white.png"
87-
label = props.polyglot.t("footer_download_app")
88-
}
89-
}
90-
styledDiv {
91-
css {
92-
+FooterStyle.footerColumn
93-
}
94-
footerLineItem {
95-
href = "https://confluence.hl7.org/display/FHIR/Using+the+FHIR+Validator"
96-
icon = "images/documentation_white.png"
97-
label = props.polyglot.t("footer_doc")
98-
}
99-
footerLineItem {
100-
href = "../swagger-ui/index.html"
101-
icon = "images/documentation_white.png"
102-
label = props.polyglot.t("footer_openapi")
103105
}
104106
}
105107
}

src/jsMain/kotlin/ui/components/header/Header.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ import utils.Language
2626
import web.dom.document
2727
import web.window.window
2828

29-
external interface HeaderProps : Props {
30-
// Empty - all data now from contexts
31-
}
29+
external interface HeaderProps : Props {}
3230

3331
class HeaderState : State {
3432
var currentScroll: Double = 0.0

src/jsMain/kotlin/ui/components/header/LanguageOption/LanguageSelect.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import react.ReactNode
1313
import utils.Language
1414

1515

16-
external interface LanguageSelectProps : Props {
17-
// Empty - all data now from contexts
18-
}
16+
external interface LanguageSelectProps : Props {}
1917

2018
class LanguageSelect(props : LanguageSelectProps) : RComponent<LanguageSelectProps, State>() {
2119
init {

0 commit comments

Comments
 (0)