Skip to content

Commit

Permalink
Add profiles to options page (#146)
Browse files Browse the repository at this point in the history
* WIP add profiles option

* Fix i18n for profiles, remove log chatter
  • Loading branch information
dotasek authored Oct 16, 2023
1 parent 7c5a8d4 commit 3506ea7
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/commonMain/kotlin/model/CliContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ expect class CliContext() {

fun getIgs(): List<String>
fun setIgs(igs: List<String>): CliContext

fun getProfiles(): List<String>
fun setProfiles(profiles: List<String>): CliContext
//TODO
// fun getQuestionnaires(): List<String>
// fun setQuestionnaires(questionnaires: List<String>): CliContext
Expand Down
3 changes: 2 additions & 1 deletion src/commonMain/kotlin/model/PackageInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ data class PackageInfo(
when (fhirVersion) {
"DSTU2" -> return "1.0"
"STU3" -> return "3.0"
"R4" ->return "4.0"
"R4" -> return "4.0"
"R5" -> return "5.0"
}
val versions = fhirVersion.split('.')
return if (versions.size >= 2) {
Expand Down
4 changes: 4 additions & 0 deletions src/commonMain/resources/static-content/polyglot/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
"options_extensions_checkbox" : "Allow Any Extensions-German",
"options_extensions_not_added" : "Added Extensions (%{addedExtensions})-German",
"options_extensions_added" : "Added Extensions (%{addedExtensions}):-German",
"options_profiles_title" : "Profiles-German",
"options_profiles_description" : "The canonical URLs for the profiles you wish to validate against. These are usually clearly specified on the page where the profile is published.-German",
"options_profiles_not_added" : "Added Profiles (%{addedProfiles})-German",
"options_profiles_added" : "Added Profiles (%{addedProfiles}):-German",
"options_settings_title" : "Sonstige Einstellungen",
"options_settings_snomed_title" : "Wählen Sie die SNOMED Version aus",
"options_settings_snomed_description" : "Sie können angeben, welche Ausgabe von SNOMED CT der Terminologieserver bei der SNOMED CT-Validierung verwenden soll.",
Expand Down
4 changes: 4 additions & 0 deletions src/commonMain/resources/static-content/polyglot/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
"options_extensions_checkbox" : "Allow Any Extensions",
"options_extensions_not_added" : "Added Extensions (%{addedExtensions})",
"options_extensions_added" : "Added Extensions (%{addedExtensions}):",
"options_profiles_title" : "Profiles",
"options_profiles_description" : "The canonical URLs for the profiles you wish to validate against. These are usually clearly specified on the page where the profile is published.",
"options_profiles_not_added" : "Added Profiles (%{addedProfiles})",
"options_profiles_added" : "Added Profiles (%{addedProfiles}):",
"options_settings_title" : "Other Settings",
"options_settings_snomed_title" : "Select SNOMED Version",
"options_settings_snomed_description" : "You can specify which edition of SNOMED CT for the terminology server to use when doing SNOMED CT Validation.",
Expand Down
4 changes: 4 additions & 0 deletions src/commonMain/resources/static-content/polyglot/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
"options_extensions_not_added": "Extensiones Agregadas (%{addedExtensions})",
"options_extensions_added": "Extensiones Agregadas (%{addedExtensions}):",
"options_settings_title": "Otras configuraciones",
"options_profiles_title" : "Profiles-Spanish",
"options_profiles_description" : "The canonical URLs for the profiles you wish to validate against. These are usually clearly specified on the page where the profile is published.-Spanish",
"options_profiles_not_added" : "Added Profiles (%{addedProfiles})-Spanish",
"options_profiles_added" : "Added Profiles (%{addedProfiles}):-Spanish",
"options_settings_snomed_title": "Elegir versión de SNOMED",
"options_settings_snomed_description": "Puede especificar qué edición de SNOMED CT utilizará para el servidor terminológico cuando valida SNOMED CT",
"options_settings_tm_title": "Definir Servidor de Terminología",
Expand Down
21 changes: 21 additions & 0 deletions src/jsMain/kotlin/model/CliContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ actual class CliContext actual constructor() {
private var sv: String = ""

private var igs: List<String> = listOf()
private var profiles: List<String> = listOf()

private var locale: String = ""
init {
Expand Down Expand Up @@ -157,6 +158,26 @@ actual class CliContext actual constructor() {
return this
}

actual fun getProfiles(): List<String> {
return profiles
}

actual fun setProfiles(profiles: List<String>): CliContext {
this.profiles = profiles
return this
}

fun addProfile(profile: String): CliContext {
this.profiles += profile
return this
}

fun removeProfile(profile: String): CliContext {
if (this.profiles.contains(profile)) {
this.profiles = this.profiles.filterNot { it == profile }.toList()
}
return this
}

actual fun setLocale(languageString: String): CliContext {
this.locale = languageString
Expand Down
6 changes: 6 additions & 0 deletions src/jsMain/kotlin/reactredux/containers/OptionsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ private interface OptionsPageStateProps : Props {
var cliContext: CliContext
var selectedIgPackageInfo: Set<PackageInfo>
var addedExtensionInfo: Set<String>
var addedProfiles: Set<String>
var polyglot: Polyglot
}

private interface OptionsPageDispatchProps : Props {
var updateCliContext: (CliContext) -> Unit
var updateSelectedIgPackageInfo: (Set<PackageInfo>) -> Unit
var updateAddedExtensionUrl: (Set<String>) -> Unit
var updateAddedProfiles: (Set<String>) -> Unit
}

val optionsPage: ComponentClass<Props> =
Expand All @@ -33,6 +35,7 @@ val optionsPage: ComponentClass<Props> =
cliContext = state.validationContextSlice.cliContext
selectedIgPackageInfo = state.validationContextSlice.selectedIgPackageInfo
addedExtensionInfo = state.validationContextSlice.addedExtensionInfo
addedProfiles = state.validationContextSlice.addedProfiles
polyglot = state.localizationSlice.polyglotInstance
},
{ dispatch, _ ->
Expand All @@ -45,5 +48,8 @@ val optionsPage: ComponentClass<Props> =
updateAddedExtensionUrl = {
dispatch(ValidationContextSlice.UpdateAddedExtensionUrl(it))
}
updateAddedProfiles = {
dispatch(ValidationContextSlice.UpdateAddedProfile(it))
}
}
)(OptionsPage::class.js.unsafeCast<ComponentClass<OptionsPageProps>>())
13 changes: 10 additions & 3 deletions src/jsMain/kotlin/reactredux/slices/ValidationContextSlice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ object ValidationContextSlice {
data class State(
val selectedIgPackageInfo: Set<PackageInfo> = mutableSetOf<PackageInfo>(),
val addedExtensionInfo: Set<String> = mutableSetOf<String>(),
val addedProfiles: Set<String> = mutableSetOf<String>(),
val cliContext: CliContext = CliContext()
)

data class UpdateSelectedIgPackageInfo(val packageInfo: Set<PackageInfo>) : RAction

data class UpdateCliContext(val cliContext: CliContext) : RAction

data class UpdateAddedExtensionUrl(val extensionUrl: Set<String>) : RAction
data class UpdateAddedExtensionUrl(val extensionUrls: Set<String>) : RAction

data class UpdateAddedProfile(val profiles: Set<String>) : RAction

fun reducer(state: State = State(), action: RAction): State {
return when (action) {
Expand All @@ -28,8 +31,12 @@ object ValidationContextSlice {
cliContext = action.cliContext
)
is UpdateAddedExtensionUrl -> state.copy(
addedExtensionInfo = action.extensionUrl,
cliContext = state.cliContext.setExtensions(action.extensionUrl.toList())
addedExtensionInfo = action.extensionUrls,
cliContext = state.cliContext.setExtensions(action.extensionUrls.toList())
)
is UpdateAddedProfile -> state.copy(
addedProfiles = action.profiles,
cliContext = state.cliContext.setProfiles(action.profiles.toList())
)
else -> state
}
Expand Down
153 changes: 153 additions & 0 deletions src/jsMain/kotlin/ui/components/options/AddProfile.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package ui.components.options

import Polyglot
import css.const.WHITE
import css.const.SWITCH_GRAY
import css.text.TextStyle
import kotlinx.css.*
import react.*
import ui.components.buttons.imageButton
import kotlinx.browser.document
import kotlinx.html.InputType
import kotlinx.html.id
import utils.getJS

import model.CliContext
import org.w3c.dom.HTMLInputElement
import react.dom.attrs
import react.dom.defaultValue
import styled.*
import ui.components.options.menu.TextFieldEntryStyle
import ui.components.options.menu.checkboxWithDetails

external interface AddProfileProps : Props {
var addedProfiles : MutableSet<String>
var onUpdateProfiles : (String, Boolean) -> Unit
var updateCliContext : (CliContext) -> Unit
var cliContext : CliContext
var polyglot: Polyglot
}

class AddProfileState : State {
}

class AddProfile : RComponent<AddProfileProps, AddProfileState>() {
val textInputId = "profile_entry"
init {
state = AddProfileState()
}

override fun RBuilder.render() {
styledDiv {
css {
+AddExtensionStyle.mainDiv
}
styledSpan {
css {
+TextStyle.optionsDetailText
+IgSelectorStyle.title
}
+props.polyglot.t("options_profiles_description")
}


styledSpan {
css {
+TextFieldEntryStyle.textFieldAndGButtonDiv
}
styledInput {
css {
+TextFieldEntryStyle.entryTextArea
}
attrs {
type = InputType.text
defaultValue = "http://"
id = textInputId
}
}
styledSpan {
imageButton {
backgroundColor = WHITE
borderColor = SWITCH_GRAY
image = "images/add_circle_black_24dp.svg"
label = props.polyglot.t("options_ig_add")
onSelected = {
props.onUpdateProfiles(
(document.getElementById(textInputId) as HTMLInputElement).value,
false
)
}
}
}
}
styledDiv {
css {
padding(top = 24.px)
+if (props.addedProfiles.isEmpty()) TextStyle.optionsDetailText else TextStyle.optionName
}
val polyglotKey = if (props.addedProfiles.isEmpty()) {
"options_profiles_not_added"
} else {
"options_profiles_added"
}
+props.polyglot.t(
polyglotKey,
getJS(arrayOf(Pair("addedProfiles", props.addedProfiles.size.toString())))
)
}
styledDiv {
css {
+IgSelectorStyle.selectedIgsDiv
if (!props.addedProfiles.isEmpty()) {
padding(top = 16.px)
}
}
props.addedProfiles.forEach { _url ->
extensionDisplay {
polyglot = props.polyglot
url = _url
onDelete = {
props.onUpdateProfiles(_url, true)
}
}
}
}
}
}
}

fun RBuilder.addProfile(handler: AddProfileProps.() -> Unit) {
return child(AddProfile::class) {
this.attrs(handler)
}
}

object AddProfileStyle : StyleSheet("AddProfileStyle", isStatic = true) {
val mainDiv by css {
display = Display.flex
flexDirection = FlexDirection.column
padding(horizontal = 8.px)
}
val title by css {
paddingBottom = 16.px
}
val selectedIgsDiv by css {
display = Display.flex
flexDirection = FlexDirection.row
flexWrap = FlexWrap.wrap
}
}














24 changes: 24 additions & 0 deletions src/jsMain/kotlin/ui/components/options/OptionsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ external interface OptionsPageProps : Props {
var updateSelectedIgPackageInfo: (Set<PackageInfo>) -> Unit
var addedExtensionInfo: Set<String>
var updateAddedExtensionUrl: (Set<String>) -> Unit
var addedProfiles: Set<String>
var updateAddedProfiles: (Set<String>) -> Unit
var polyglot: Polyglot
}

Expand Down Expand Up @@ -218,6 +220,28 @@ class OptionsPage : RComponent<OptionsPageProps, OptionsPageState>() {
}
}
}
heading {
text = props.polyglot.t("options_profiles_title")
}
styledDiv {
css {
+OptionsPageStyle.optionsSubSection
}
addProfile {
polyglot = props.polyglot
addedProfiles = props.addedProfiles.toMutableSet()
updateCliContext = updateCliContext
cliContext = cliContext
onUpdateProfiles = { profile , delete ->
val newProfiles = if (delete) {
addedProfiles.minus(profile).toMutableSet()
} else {
addedProfiles.plus(profile).toMutableSet()
}
props.updateAddedProfiles(newProfiles)
}
}
}
heading {
text = props.polyglot.t("options_extensions_title")
}
Expand Down

0 comments on commit 3506ea7

Please sign in to comment.