From cf48d5aec0499b644230f7d3d1c90eac5227cec2 Mon Sep 17 00:00:00 2001 From: Andrey Kuleshov Date: Wed, 6 Sep 2023 23:06:24 +0300 Subject: [PATCH] Diktat fixes --- .../vulnerability/VulnerabilityDateType.kt | 8 +- .../save/frontend/components/HasErrorModal.kt | 3 +- .../components/basic/TimelineComponent.kt | 101 +++++++++--------- .../views/usersettings/SettingsView.kt | 2 +- .../views/vuln/VulnerabilityGeneralInfo.kt | 13 ++- .../views/vuln/VulnerabilityHeader.kt | 9 +- .../views/vuln/VulnerabilityInfoTab.kt | 1 - .../views/vuln/VulnerabilityView.kt | 22 ++-- 8 files changed, 76 insertions(+), 83 deletions(-) diff --git a/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/entities/vulnerability/VulnerabilityDateType.kt b/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/entities/vulnerability/VulnerabilityDateType.kt index 133b5892cb..eaadd21699 100644 --- a/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/entities/vulnerability/VulnerabilityDateType.kt +++ b/save-cloud-common/src/commonMain/kotlin/com/saveourtool/save/entities/vulnerability/VulnerabilityDateType.kt @@ -41,14 +41,14 @@ enum class VulnerabilityDateType(val value: String) { PUBLISHED("Published"), /** - * Date from [com.saveourtool.osv4k.OsvSchema.withdrawn] in COSV schema + * Date when the vuln was submitted to our archive, our platform specific */ - WITHDRAWN("Withdrawn"), + SUBMITTED("Submitted"), /** - * Date when the vuln was submitted to our archive, our platform specific + * Date from [com.saveourtool.osv4k.OsvSchema.withdrawn] in COSV schema */ - SUBMITTED("Submitted") + WITHDRAWN("Withdrawn"), ; override fun toString(): String = value diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/HasErrorModal.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/HasErrorModal.kt index ef4c35a078..d7f9f7c8c5 100644 --- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/HasErrorModal.kt +++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/HasErrorModal.kt @@ -10,7 +10,6 @@ import com.saveourtool.save.frontend.externals.animations.ringLoader import com.saveourtool.save.info.UserInfo import js.core.jso -import kotlinx.browser.window import org.w3c.fetch.Response import react.* import react.dom.html.ReactHTML.button @@ -21,6 +20,8 @@ import react.router.useNavigate import web.cssom.ClassName import web.html.ButtonType +import kotlinx.browser.window + /** * Loader animation */ diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/basic/TimelineComponent.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/basic/TimelineComponent.kt index 5a39ac85bf..5dc656a2ef 100644 --- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/basic/TimelineComponent.kt +++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/basic/TimelineComponent.kt @@ -14,79 +14,72 @@ import kotlinx.datetime.LocalDateTime const val HOVERABLE_CONST = "hoverable" val timelineComponent: FC = FC { props -> - console.log(props.dates) - if (props.dates != undefined) { - val hoverable = props.onNodeClick?.let { HOVERABLE_CONST }.orEmpty() + val hoverable = props.onNodeClick?.let { HOVERABLE_CONST }.orEmpty() - div { - className = ClassName("mb-3") - props.title?.let { title -> - div { - className = ClassName("mt-3 mb-3 text-xs text-center font-weight-bold text-primary text-uppercase") - +title - } + div { + className = ClassName("mb-3") + props.title?.let { title -> + div { + className = ClassName("mt-3 mb-3 text-xs text-center font-weight-bold text-primary text-uppercase") + +title } + } - props.onAddClick?.let { onClickCallback -> - buttonBuilder( - label = "Add date", - style = "secondary", - isOutline = true, - classes = "btn btn-sm btn-primary" - ) { - onClickCallback() - } + props.onAddClick?.let { onClickCallback -> + buttonBuilder( + label = "Add date", + style = "secondary", + isOutline = true, + classes = "btn btn-sm btn-primary" + ) { + onClickCallback() } + } + div { + className = ClassName("p-0 timeline-container") div { - className = ClassName("p-0 timeline-container") + className = ClassName("steps-container") div { - className = ClassName("steps-container") - div { - className = ClassName("line") - } - props.dates - .plus( - VulnerabilityDateType.SUBMITTED.value to - (props.vulnerability.creationDateTime ?: LocalDateTime(0, 1, 1, 0, 0, 0, 0)) - ) - .toList() - .sortedBy { it.second } - .forEach { (label, dateTime) -> - div { - className = + className = ClassName("line") + } + props.dates + .plus( + VulnerabilityDateType.SUBMITTED.value to + (props.vulnerability.creationDateTime ?: LocalDateTime(0, 1, 1, 0, 0, 0, 0)) + ) + .toList() + .sortedBy { it.second } + .forEach { (label, dateTime) -> + div { + className = ClassName(if (!label.isSubmittedType()) "step $hoverable" else "step-non-editable") - if (!label.isSubmittedType()) { - props.onNodeClick?.let { onClickCallback -> - onClick = { onClickCallback(dateTime, label) } - } - } - div { - className = ClassName("text-label") - +label - } - div { - className = ClassName("date-label") - +dateTime.date.toString() + if (!label.isSubmittedType()) { + props.onNodeClick?.let { onClickCallback -> + onClick = { onClickCallback(dateTime, label) } } } div { - className = ClassName("line") + className = ClassName("text-label") + +label + } + div { + className = ClassName("date-label") + +dateTime.date.toString() } } - div { - className = ClassName("line-end") + div { + className = ClassName("line") + } } + div { + className = ClassName("line-end") } } } - } else { - } } -private fun String.isSubmittedType() = this == VulnerabilityDateType.SUBMITTED.value - /** * [Props] of [timelineComponent] */ @@ -117,3 +110,5 @@ external interface TimelineComponentProps : Props { */ var vulnerability: VulnerabilityDto } + +private fun String.isSubmittedType() = this == VulnerabilityDateType.SUBMITTED.value diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/usersettings/SettingsView.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/usersettings/SettingsView.kt index 68081f0973..c783f7c9ee 100644 --- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/usersettings/SettingsView.kt +++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/usersettings/SettingsView.kt @@ -16,7 +16,6 @@ import com.saveourtool.save.info.UserInfo import com.saveourtool.save.validation.FrontendRoutes import js.core.jso -import kotlinx.browser.window import react.* import react.dom.html.ReactHTML.button import react.dom.html.ReactHTML.div @@ -28,6 +27,7 @@ import web.cssom.* import web.html.ButtonType import web.html.InputType +import kotlinx.browser.window import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityGeneralInfo.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityGeneralInfo.kt index b84c0756a3..666d30e4cd 100644 --- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityGeneralInfo.kt +++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityGeneralInfo.kt @@ -9,24 +9,23 @@ import com.saveourtool.save.frontend.externals.fontawesome.* import com.saveourtool.save.frontend.utils.* import com.saveourtool.save.info.UserInfo import com.saveourtool.save.utils.toUnixCalendarFormat -import js.core.jso +import js.core.jso import react.* import react.dom.html.ReactHTML.div import react.dom.html.ReactHTML.h6 import react.dom.html.ReactHTML.hr import react.dom.html.ReactHTML.label +import react.dom.html.ReactHTML.p import react.dom.html.ReactHTML.textarea import react.router.dom.Link import web.cssom.ClassName +import web.cssom.TextDecoration.Companion.underline import web.cssom.rem import kotlinx.datetime.TimeZone import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json -import react.dom.html.ReactHTML.p -import web.cssom.Color -import web.cssom.TextDecoration.Companion.underline /** * [FC] that is used to display some general vulnerability information @@ -60,13 +59,13 @@ val vulnerabilityGeneralInfo: FC = FC { props -> if (props.isEditDisabled) { // only Super Users and owners of unapproved vuln. can edit it if (props.userInfo?.isSuperAdmin() == true || - (props.userInfo?.name == userInfo.name && props.vulnerability.status != VulnerabilityStatus.APPROVED)) { + (props.userInfo?.name == userInfo.name && props.vulnerability.status != VulnerabilityStatus.APPROVED)) { buttonBuilder( labelBuilder = { p { className = ClassName("mb-0") style = jso { - textDecoration = underline; + textDecoration = underline } +"Edit " fontAwesomeIcon(icon = faEdit) @@ -221,7 +220,7 @@ external interface VulnerabilityGeneralInfo : Props { var vulnerability: VulnerabilityDto /** - * + * Vulnerabilities setter */ var setVulnerability: StateSetter diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityHeader.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityHeader.kt index a433541970..2556a6e01b 100644 --- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityHeader.kt +++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityHeader.kt @@ -30,14 +30,11 @@ import react.dom.html.ReactHTML.h6 import react.dom.html.ReactHTML.textarea import react.router.useNavigate import react.useState +import web.cssom.* import kotlinx.browser.window import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json -import react.dom.html.ReactHTML.h4 -import react.dom.html.ReactHTML.img -import web.cssom.* -import web.cssom.HtmlAttributes.Companion.src internal val headerMenu: FC = FC { props -> val rejectVulnerabilityWindowOpenness = useWindowOpenness() @@ -183,7 +180,6 @@ internal val headerMenu: FC = FC { props -> style = jso { height = "7rem".unsafeCast() } - } } @@ -213,7 +209,7 @@ internal val headerMenu: FC = FC { props -> } if (props.permissions.isSuperAdmin || - (props.permissions.isOwner && props.vulnerability.status != VulnerabilityStatus.APPROVED) + (props.permissions.isOwner && props.vulnerability.status != VulnerabilityStatus.APPROVED) ) { buttonBuilder( faTrash, @@ -241,7 +237,6 @@ internal val headerMenu: FC = FC { props -> div { className = ClassName("col-3") } - } } } diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityInfoTab.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityInfoTab.kt index a86db7e937..df34f43928 100644 --- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityInfoTab.kt +++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityInfoTab.kt @@ -18,7 +18,6 @@ import com.saveourtool.save.frontend.externals.fontawesome.* import com.saveourtool.save.frontend.utils.* import com.saveourtool.save.info.UserInfo -import js.core.jso import react.* import react.dom.html.ReactHTML.div import react.dom.html.ReactHTML.h4 diff --git a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityView.kt b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityView.kt index 669f4b3022..50559b1935 100644 --- a/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityView.kt +++ b/save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/VulnerabilityView.kt @@ -22,15 +22,6 @@ import web.cssom.* const val HEADER_HEIGHT = "9rem" -fun borderEditStyle(pointerCursor: Boolean = false): CSSProperties = jso { - borderColor = "#5711d9".unsafeCast() - borderStyle = "dashed".unsafeCast() - borderWidth = "thin".unsafeCast() - if (pointerCursor) { - cursor = "pointer".unsafeCast() - } -} - @Suppress( "MAGIC_NUMBER", "TOO_LONG_FUNCTION", @@ -188,6 +179,19 @@ private fun ChildrenBuilder.languageSpan(language: VulnerabilityLanguage) { } } +/** + * @param pointerCursor + * @return returns the css for editable text form + */ +fun borderEditStyle(pointerCursor: Boolean = false): CSSProperties = jso { + borderColor = "#5711d9".unsafeCast() + borderStyle = "dashed".unsafeCast() + borderWidth = "thin".unsafeCast() + if (pointerCursor) { + cursor = "pointer".unsafeCast() + } +} + /** * @param currentUserInfo * @param vulnerability