Skip to content

Commit

Permalink
Add new card with the number of vulnerabilities (#2467) (#2494)
Browse files Browse the repository at this point in the history
### What's done:
* add a new card in welcome view
  • Loading branch information
JustinB1eber authored Aug 26, 2023
1 parent fa9388d commit a2f8998
Showing 1 changed file with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@

package com.saveourtool.save.frontend.components.views.welcome

import com.saveourtool.save.entities.vulnerability.VulnerabilityDto
import com.saveourtool.save.frontend.components.views.welcome.pagers.vuln.renderVulnerabilityGeneralInfo
import com.saveourtool.save.frontend.externals.fontawesome.*
import com.saveourtool.save.frontend.themes.Colors
import com.saveourtool.save.frontend.utils.*
import com.saveourtool.save.info.OauthProviderInfo
import com.saveourtool.save.validation.FrontendRoutes

import js.core.jso
import org.w3c.fetch.Headers
import react.*
import react.dom.html.ReactHTML.div
import react.dom.html.ReactHTML.h1
import react.dom.html.ReactHTML.main
import react.dom.html.ReactHTML.span
import react.dom.html.ReactHTML.strong
import web.cssom.*

import kotlinx.browser.window

val vulnWelcomeView: FC<WelcomeProps> = FC { props ->
Expand All @@ -42,6 +43,16 @@ val vulnWelcomeView: FC<WelcomeProps> = FC { props ->
oauthProviderInfoList?.let { setOauthProviders(it) }
}

val (vulnerabilities, setVulnerabilities) = useState<List<VulnerabilityDto>>(emptyList())
useRequest {
val vuln: List<VulnerabilityDto> = get(
url = "$apiUrl/vulnerabilities/get-all-public",
headers = jsonHeaders,
loadingHandler = ::loadingHandler
).unsafeMap { it.decodeFromJsonString() }
setVulnerabilities(vuln)
}

main {
className = ClassName("main-content mt-0 ps")
div {
Expand Down Expand Up @@ -79,6 +90,7 @@ val vulnWelcomeView: FC<WelcomeProps> = FC { props ->
}
} ?: inputCredentialsView(oauthProviders, Colors.VULN_PRIMARY, "/${FrontendRoutes.VULNERABILITIES}")
}
stats(vulnerabilities)
}

div {
Expand All @@ -89,3 +101,34 @@ val vulnWelcomeView: FC<WelcomeProps> = FC { props ->
}
}
}

/**
* add a card getting all vulnerabilities and return nums
*
* @param vulnerabilities
*/
fun ChildrenBuilder.stats(vulnerabilities: List<VulnerabilityDto>) {
div {
className = ClassName("card mt-3")
div {
className = ClassName("mt-5 mb-5")
style = jso {
height = 15.rem
}
div {
className = ClassName("row justify-content-center")
strong {
className = ClassName("d-inline-block mb-2 card-text")
+"total vulnerabilities"
}
}
div {
className = ClassName("row justify-content-center")
h1 {
className = ClassName("text-dark")
+vulnerabilities.size.toString()
}
}
}
}
}

0 comments on commit a2f8998

Please sign in to comment.