All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.internal.actions.RemoveDependingExternalIssuesAction.kt Maven / Gradle / Ivy

There is a newer version: 0.23.0
Show newest version
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
                    )
                }
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy