@@ -15,45 +15,25 @@ import { PaletteIndex } from "theme/palettes"
15
15
import userAgentParser from "ua-parser-js"
16
16
import { combineClasses } from "util/combineClasses"
17
17
import { AuditLogDiff } from "./AuditLogDiff"
18
- import { Link } from "react-router-dom"
18
+ import { Link as RouterLink } from "react-router-dom"
19
+ import i18next from "i18next"
20
+ import Link from "@material-ui/core/Link"
19
21
20
- // const determineInitiator = (auditLog: AuditLog): string => {
21
- // return auditLog.
22
- // }
22
+ const determineResourceLink = ( auditLog : AuditLog ) : string => {
23
+ const { t } = i18next
24
+ let linkTarget = auditLog . resource_target . trim ( )
23
25
24
- const determineResourceTarget = ( auditLog : AuditLog ) : string => {
25
- let target = auditLog . resource_target . trim ( )
26
-
27
- // audit logs with a resource_type of workspace build use workspace name as a target
28
26
if ( auditLog . resource_type === "workspace_build" ) {
29
- // target = auditLog.additional_fields.workspaceName.trim()
30
- target = "build"
27
+ linkTarget = t ( "auditLog:table.logRow.buildTarget" )
31
28
}
32
29
33
- return target
30
+ return linkTarget
34
31
}
35
32
36
33
export const readableActionMessage = ( auditLog : AuditLog ) : string => {
37
- // let target = auditLog.resource_target.trim()
38
-
39
- // audit logs with a resource_type of workspace build use workspace name as a target
40
- // if (
41
- // auditLog.resource_type === "workspace_build" &&
42
- // auditLog.additional_fields.workspaceName
43
- // ) {
44
- // target = auditLog.additional_fields.workspaceName.trim()
45
- // }
46
-
47
34
return auditLog . description
48
35
. replace ( "{user}" , `${ auditLog . user ?. username . trim ( ) } ` )
49
36
. replace ( "{target}" , "" )
50
-
51
- // return auditLog.description
52
- // .replace("{user}", `<strong>${auditLog.user?.username.trim()}</strong>`)
53
- // .replace(
54
- // "{target}",
55
- // `<Link to=/@${auditLog.user?.username.trim()}/${target}>${target}</Link>`,
56
- // )
57
37
}
58
38
59
39
const httpStatusColor = ( httpStatus : number ) : PaletteIndex => {
@@ -79,6 +59,7 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
79
59
defaultIsDiffOpen = false ,
80
60
} ) => {
81
61
const styles = useStyles ( )
62
+ const { t } = i18next
82
63
const [ isDiffOpen , setIsDiffOpen ] = useState ( defaultIsDiffOpen )
83
64
const diffs = Object . entries ( auditLog . diff )
84
65
const shouldDisplayDiff = diffs . length > 0
@@ -145,23 +126,19 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
145
126
>
146
127
< span >
147
128
{ readableActionMessage ( auditLog ) } { " " }
148
- < Link to = { auditLog . resource_link } >
149
- { determineResourceTarget ( auditLog ) }
150
- </ Link >
129
+ { auditLog . resource_link && (
130
+ < Link component = { RouterLink } to = { auditLog . resource_link } >
131
+ { determineResourceLink ( auditLog ) }
132
+ </ Link >
133
+ ) }
151
134
{ auditLog . resource_type === "workspace_build" &&
152
135
auditLog . additional_fields . workspaceName && (
153
- < span >
154
- { " " }
155
- for workspace{ " " }
136
+ < >
137
+ { t ( "auditLog:table.logRow.buildFriendlyString" ) }
156
138
{ auditLog . additional_fields . workspaceName }
157
- </ span >
139
+ </ >
158
140
) }
159
141
</ span >
160
- { /* <span
161
- dangerouslySetInnerHTML={{
162
- __html: readableActionMessage(auditLog),
163
- }}
164
- /> */ }
165
142
< span className = { styles . auditLogTime } >
166
143
{ new Date ( auditLog . time ) . toLocaleTimeString ( ) }
167
144
</ span >
@@ -170,15 +147,18 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
170
147
< Stack direction = "row" alignItems = "center" >
171
148
< Stack direction = "row" spacing = { 1 } alignItems = "baseline" >
172
149
< span className = { styles . auditLogInfo } >
173
- IP: < strong > { auditLog . ip ?? notAvailableLabel } </ strong >
150
+ < > { t ( "auditLog:table.logRow.ip" ) } </ >
151
+ < strong > { auditLog . ip ?? notAvailableLabel } </ strong >
174
152
</ span >
175
153
176
154
< span className = { styles . auditLogInfo } >
177
- OS: < strong > { os . name ?? notAvailableLabel } </ strong >
155
+ < > { t ( "auditLog:table.logRow.os" ) } </ >
156
+ < strong > { os . name ?? notAvailableLabel } </ strong >
178
157
</ span >
179
158
180
159
< span className = { styles . auditLogInfo } >
181
- Browser: < strong > { displayBrowserInfo } </ strong >
160
+ < > { t ( "auditLog:table.logRow.browser" ) } </ >
161
+ < strong > { displayBrowserInfo } </ strong >
182
162
</ span >
183
163
</ Stack >
184
164
0 commit comments