Skip to content

Commit c988b1a

Browse files
committed
added translations
1 parent a630982 commit c988b1a

File tree

2 files changed

+31
-44
lines changed

2 files changed

+31
-44
lines changed

site/src/components/AuditLogRow/AuditLogRow.tsx

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,25 @@ import { PaletteIndex } from "theme/palettes"
1515
import userAgentParser from "ua-parser-js"
1616
import { combineClasses } from "util/combineClasses"
1717
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"
1921

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()
2325

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
2826
if (auditLog.resource_type === "workspace_build") {
29-
// target = auditLog.additional_fields.workspaceName.trim()
30-
target = "build"
27+
linkTarget = t("auditLog:table.logRow.buildTarget")
3128
}
3229

33-
return target
30+
return linkTarget
3431
}
3532

3633
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-
4734
return auditLog.description
4835
.replace("{user}", `${auditLog.user?.username.trim()}`)
4936
.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-
// )
5737
}
5838

5939
const httpStatusColor = (httpStatus: number): PaletteIndex => {
@@ -79,6 +59,7 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
7959
defaultIsDiffOpen = false,
8060
}) => {
8161
const styles = useStyles()
62+
const { t } = i18next
8263
const [isDiffOpen, setIsDiffOpen] = useState(defaultIsDiffOpen)
8364
const diffs = Object.entries(auditLog.diff)
8465
const shouldDisplayDiff = diffs.length > 0
@@ -145,23 +126,19 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
145126
>
146127
<span>
147128
{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+
)}
151134
{auditLog.resource_type === "workspace_build" &&
152135
auditLog.additional_fields.workspaceName && (
153-
<span>
154-
{" "}
155-
for workspace{" "}
136+
<>
137+
{t("auditLog:table.logRow.buildFriendlyString")}
156138
{auditLog.additional_fields.workspaceName}
157-
</span>
139+
</>
158140
)}
159141
</span>
160-
{/* <span
161-
dangerouslySetInnerHTML={{
162-
__html: readableActionMessage(auditLog),
163-
}}
164-
/> */}
165142
<span className={styles.auditLogTime}>
166143
{new Date(auditLog.time).toLocaleTimeString()}
167144
</span>
@@ -170,15 +147,18 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
170147
<Stack direction="row" alignItems="center">
171148
<Stack direction="row" spacing={1} alignItems="baseline">
172149
<span className={styles.auditLogInfo}>
173-
IP: <strong>{auditLog.ip ?? notAvailableLabel}</strong>
150+
<>{t("auditLog:table.logRow.ip")}</>
151+
<strong>{auditLog.ip ?? notAvailableLabel}</strong>
174152
</span>
175153

176154
<span className={styles.auditLogInfo}>
177-
OS: <strong>{os.name ?? notAvailableLabel}</strong>
155+
<>{t("auditLog:table.logRow.os")}</>
156+
<strong>{os.name ?? notAvailableLabel}</strong>
178157
</span>
179158

180159
<span className={styles.auditLogInfo}>
181-
Browser: <strong>{displayBrowserInfo}</strong>
160+
<>{t("auditLog:table.logRow.browser")}</>
161+
<strong>{displayBrowserInfo}</strong>
182162
</span>
183163
</Stack>
184164

site/src/i18n/en/auditLog.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
},
77
"table": {
88
"emptyPage": "No audit logs available on this page",
9-
"noLogs": "No audit logs available"
9+
"noLogs": "No audit logs available",
10+
"logRow": {
11+
"buildTarget": "build",
12+
"buildFriendlyString": " for workspace ",
13+
"ip": "IP: ",
14+
"os": "OS: ",
15+
"Browser": "Browser: "
16+
}
1017
}
1118
}

0 commit comments

Comments
 (0)