commonMain.internal.actions.RemoveDependingExternalIssuesAction.kt Maven / Gradle / Ivy
package io.kform.internal.actions
import io.kform.FormManager
import io.kform.LocatedValidationIssue
import io.kform.internal.*
/** Action that removes all provided external issues from the form manager. */
internal class RemoveDependingExternalIssuesAction(
formManager: FormManager,
private val externalIssues: Iterable
) : ValueStateAction(formManager) {
override fun toString() = "RemoveDependingExternalIssuesAction(${externalIssues})"
override val accesses =
listOf(
AccessValueStateTree(ActionAccessType.Read),
AccessValidationState(ActionAccessType.Write),
AccessIsTouched(ActionAccessType.Read),
AccessDescendantsDisplayingIssues(ActionAccessType.Read)
)
override val accessedPaths = externalIssues.mapTo(HashSet()) { it.path }
override suspend fun run() {
for ((path, issues) in externalIssues.groupBy { it.path }) {
for (info in stateInfo(path)) {
val state = info.state as StateImpl? ?: continue
val oldLocalDisplayStatus = state.localDisplayStatus()
val oldDisplayStatus = state.displayStatus()
if (state.removeExternalIssues(issues)) {
// Update validation state with the new external issues
ValidateAction.updateValidationState(
formManager,
info.schema,
path,
state,
oldLocalDisplayStatus,
oldDisplayStatus
)
}
}
}
}
}