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

commonMain.internal.actions.AddExternalIssuesAction.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 adds external issues to the form manager. */
internal class AddExternalIssuesAction(
    formManager: FormManager,
    private val externalIssues: Iterable
) : ValueStateAction(formManager) {
    override fun toString() = "AddExternalIssues(${externalIssues.toList()})"

    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 }) {
            val (state, schema) = stateInfo(path).single()
            state as StateImpl

            val oldLocalDisplayStatus = state.localDisplayStatus()
            val oldDisplayStatus = state.displayStatus()

            // Add external issues to state
            state.addExternalIssues(issues)
            formManager.externalIssuesDependencies.addDependenciesOfExternalIssues(issues)

            ValidateAction.updateValidationState(
                formManager,
                schema,
                path,
                state,
                oldLocalDisplayStatus,
                oldDisplayStatus
            )
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy