Dmitriy Malayev
10/16/2023, 3:35 AMval SelectGseSectionsComponent = FC<SelectGseSectionsComponentProps> { props ->
val gseReportState = props.gseReportStateProps
var checksState by useState(
mutableMapOf<GseSection, Boolean>().also {
GseSection.entries.forEach { enumValue ->
it[enumValue] = false
it[GseSection.GENERALS] = true
}
}
)
Box {
className = styles.MAIN_GSE_FORM.cssClass
Box {
Checkbox {
onChange = { _, checked ->
checksState = checksState.mapValues { checked } as MutableMap<GseSection, Boolean>
if (checked) {
gseReportState.sections.addAll(GseSection.entries.toTypedArray())
} else {
gseReportState.sections.removeAll(GseSection.entries.toTypedArray())
}
}
}
+"Select All?"
}
Box {
className = styles.GSE_CHECKBOXES.cssClass
checksState.forEach { (label, check) ->
Box {
Checkbox {
checked = check
onChange = { _, checked ->
checksState = checksState.toMutableMap().apply {
put(label, !check)
}
if (checked) {
gseReportState.sections.add(label)
} else {
gseReportState.sections.remove(label)
}
}
}
+label.description
Tooltip {
IconButton {
InfoOutlined()
}
title = ReactNode(<http://label.info|label.info>)
}
}
}
}
}
}
Artem Kobzar
10/16/2023, 12:15 PMMutableIterable
there is an overload of the removeAll
with the predicate functionDmitriy Malayev
10/16/2023, 1:58 PMArtem Kobzar
10/16/2023, 3:09 PMgseReportState.sections.addAll(GseSection.entries.filter { CONDITION() }.toTypedArray())
Will this work for you?Dmitriy Malayev
10/16/2023, 3:09 PMgseReportState.sections.removeAll(GseSections.entries.filter { !it.equals(GENERALS) }
.toTypedArray())
not workingArtem Kobzar
10/16/2023, 3:51 PMaddAll
removeAll
you could use the overload with a predicate-function param