Skip to content

Commit 075fe77

Browse files
authored
Fixed error on vulnerability page (#2834)
- added error message to ErrorBoundary - added missing namespace for translation
1 parent f0e74c5 commit 075fe77

3 files changed

Lines changed: 32 additions & 29 deletions

File tree

save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/ErrorBoundary.kt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@ import com.saveourtool.save.frontend.components.topbar.topBarComponent
88
import com.saveourtool.save.frontend.components.views.FallbackView
99

1010
import js.core.jso
11-
import react.Component
12-
import react.PropsWithChildren
13-
import react.RStatics
14-
import react.ReactNode
15-
import react.State
16-
import react.create
11+
import react.*
1712
import react.dom.html.ReactHTML.div
18-
import react.react
1913
import web.cssom.ClassName
2014

2115
/**
2216
* State of error boundary component
2317
*/
2418
external interface ErrorBoundaryState : State {
19+
/**
20+
* The error message
21+
*/
22+
var errorMessage: String?
23+
2524
/**
2625
* True is there is an error in the wrapped component tree
2726
*/
@@ -34,21 +33,24 @@ external interface ErrorBoundaryState : State {
3433
class ErrorBoundary : Component<PropsWithChildren, ErrorBoundaryState>() {
3534
init {
3635
state = jso {
36+
errorMessage = null
3737
hasError = false
3838
}
3939
}
4040

4141
override fun render(): ReactNode? = if (state.hasError == true) {
42-
div.create {
43-
className = ClassName("container-fluid")
44-
topBarComponent()
45-
FallbackView::class.react {
46-
bigText = "Error"
47-
smallText = "Something went wrong"
42+
FC {
43+
div {
44+
className = ClassName("container-fluid")
45+
topBarComponent()
46+
FallbackView::class.react {
47+
bigText = "Error"
48+
smallText = "Something went wrong: ${state.errorMessage ?: "Unknown error"}"
49+
}
50+
@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
51+
footer { }
4852
}
49-
@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
50-
footer { }
51-
}
53+
}.create()
5254
} else {
5355
props.children
5456
}
@@ -59,8 +61,9 @@ class ErrorBoundary : Component<PropsWithChildren, ErrorBoundaryState>() {
5961
* From [React docs](https://reactjs.org/docs/error-boundaries.html):
6062
* 'A class component becomes an error boundary if it defines either (or both) of the lifecycle methods static getDerivedStateFromError() or componentDidCatch()'
6163
*/
62-
getDerivedStateFromError = {
64+
getDerivedStateFromError = { ex ->
6365
jso {
66+
errorMessage = ex.message
6467
hasError = true
6568
}
6669
}

save-frontend/src/main/kotlin/com/saveourtool/save/frontend/components/views/vuln/component/UploadCosvButton.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,22 @@ package com.saveourtool.save.frontend.components.views.vuln.component
55
import com.saveourtool.save.frontend.externals.fontawesome.faFile
66
import com.saveourtool.save.frontend.externals.i18next.useTranslation
77
import com.saveourtool.save.frontend.utils.buttonBuilder
8-
import com.saveourtool.save.frontend.utils.withNavigate
98
import com.saveourtool.save.validation.FrontendRoutes
109
import react.FC
1110
import react.Props
11+
import react.router.useNavigate
1212

1313
val uploadCosvButton: FC<UploadCosvButtonProps> = FC { props ->
1414
val (t) = useTranslation("vulnerability-upload")
15+
val navigate = useNavigate()
1516

16-
withNavigate { navigateContext ->
17-
18-
if (props.isImage) {
19-
buttonBuilder(faFile, style = "primary", title = "Add new vulnerability from json", classes = "icon-2-5rem", isOutline = true) {
20-
navigateContext.navigate("/${FrontendRoutes.VULN_UPLOAD}")
21-
}
22-
} else {
23-
buttonBuilder("Upload COSV files".t(), style = "primary", isOutline = true) {
24-
navigateContext.navigate("/${FrontendRoutes.VULN_UPLOAD}")
25-
}
17+
if (props.isImage) {
18+
buttonBuilder(faFile, style = "primary", title = "Add new vulnerability from json", classes = "icon-2-5rem", isOutline = true) {
19+
navigate("/${FrontendRoutes.VULN_UPLOAD}")
20+
}
21+
} else {
22+
buttonBuilder("Upload COSV files".t(), style = "primary", isOutline = true) {
23+
navigate("/${FrontendRoutes.VULN_UPLOAD}")
2624
}
2725
}
2826
}

save-frontend/src/main/kotlin/com/saveourtool/save/frontend/externals/i18next/InitI18n.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ fun initI18n(isDebug: Boolean = false, interpolationEscapeValue: Boolean = false
3232
'table-headers',
3333
'thanks-for-registration',
3434
'vulnerability-collection',
35+
'vulnerability-upload',
3536
'welcome',
3637
'vulnerability',
3738
'comments',
38-
'dates'
39+
'dates',
40+
'index'
3941
],
4042
backend: {
4143
loadPath: '/locales/{{lng}}/{{ns}}.json'

0 commit comments

Comments
 (0)