Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0125d4f

Browse files
committed
using Trans component
1 parent 7f71c2a commit 0125d4f

File tree

3 files changed

+61
-46
lines changed

3 files changed

+61
-46
lines changed

site/src/components/AuditLogRow/AuditLogDescription.tsx

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,19 @@ import { AuditLog } from "api/typesGenerated"
33
import { Link as RouterLink } from "react-router-dom"
44
import Link from "@material-ui/core/Link"
55
import { makeStyles } from "@material-ui/core/styles"
6-
import i18next from "i18next"
7-
8-
const BuildAuditDescription: FC<{ auditLog: AuditLog }> = ({
9-
auditLog,
10-
}): JSX.Element => {
11-
const { t } = i18next
12-
13-
// audit logs with a resource_type of workspace build use workspace name as a target
14-
const target = auditLog.additional_fields?.workspace_name?.trim()
15-
// workspaces can be started/stopped by a user, or kicked off automatically by Coder
16-
const user =
17-
auditLog.additional_fields?.build_reason &&
18-
auditLog.additional_fields?.build_reason !== "initiator"
19-
? t("auditLog:table.logRow.buildReason")
20-
: auditLog.user?.username.trim()
21-
22-
const actionVerb =
23-
auditLog.action === "start"
24-
? t("auditLog:table.logRow.started")
25-
: t("auditLog:table.logRow.stopped")
26-
27-
return (
28-
<span>
29-
<>
30-
{user}{" "}
31-
{auditLog.resource_link ? (
32-
<Link component={RouterLink} to={auditLog.resource_link}>
33-
<strong>{actionVerb}</strong>
34-
</Link>
35-
) : (
36-
{ actionVerb }
37-
)}{" "}
38-
{t("auditLog:table.logRow.workspace")}
39-
<strong>{target}</strong>
40-
</>
41-
</span>
42-
)
43-
}
6+
import { useTranslation } from "react-i18next"
7+
import { BuildAuditDescription } from "./BuildAuditDescription"
448

459
export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
4610
auditLog,
4711
}): JSX.Element => {
4812
const classes = useStyles()
49-
const { t } = i18next
13+
const { t } = useTranslation("auditLog")
5014

5115
const target = auditLog.resource_target.trim()
5216
const user = auditLog.user
5317
? auditLog.user.username.trim()
54-
: t("auditLog:table.logRow.unknownUser")
18+
: t("table.logRow.unknownUser")
5519

5620
if (auditLog.resource_type === "workspace_build") {
5721
return <BuildAuditDescription auditLog={auditLog} />
@@ -72,6 +36,21 @@ export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
7236
.replace("{user}", `${user}`)
7337
.replace("{target}", "")
7438

39+
// return (
40+
// <span>
41+
// <Trans
42+
// t={t}
43+
// i18nKey="table.logRow.auditDescription"
44+
// values={{ truncatedDescription, target }}
45+
// >
46+
// {"{{truncatedDescription}}"}
47+
// <Link component={RouterLink} to={auditLog.resource_link}>
48+
// <strong>{"{{target}}"}</strong>
49+
// </Link>
50+
// </Trans>
51+
// </span>
52+
// )
53+
7554
return (
7655
<span>
7756
{truncatedDescription}
@@ -84,7 +63,7 @@ export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
8463
)}
8564
{auditLog.is_deleted && (
8665
<span className={classes.deletedLabel}>
87-
<>{t("auditLog:table.logRow.deletedLabel")}</>
66+
<>{t("table.logRow.deletedLabel")}</>
8867
</span>
8968
)}
9069
{/* logs for workspaces created on behalf of other users indicate ownership in the description */}
@@ -94,7 +73,7 @@ export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
9473
auditLog.user?.username && (
9574
<span>
9675
<>
97-
{t("auditLog:table.logRow.onBehalfOf", {
76+
{t("table.logRow.onBehalfOf", {
9877
owner: auditLog.additional_fields.workspace_owner,
9978
})}
10079
</>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Trans, useTranslation } from "react-i18next"
2+
import { AuditLog } from "api/typesGenerated"
3+
import { FC } from "react"
4+
import { Link as RouterLink } from "react-router-dom"
5+
import Link from "@material-ui/core/Link"
6+
7+
export const BuildAuditDescription: FC<{ auditLog: AuditLog }> = ({
8+
auditLog,
9+
}): JSX.Element => {
10+
const { t } = useTranslation("auditLog")
11+
12+
// audit logs with a resource_type of workspace build use workspace name as a target
13+
const workspaceName = auditLog.additional_fields?.workspace_name?.trim()
14+
// workspaces can be started/stopped by a user, or kicked off automatically by Coder
15+
const user =
16+
auditLog.additional_fields?.build_reason &&
17+
auditLog.additional_fields?.build_reason !== "initiator"
18+
? "Coder automatically"
19+
: auditLog.user?.username.trim()
20+
21+
const action = auditLog.action === "start" ? "started" : "stopped"
22+
23+
return (
24+
<span>
25+
<Trans
26+
t={t}
27+
i18nKey="table.logRow.workspaceBuild"
28+
values={{ user, action, workspaceName }}
29+
>
30+
{"{{user}}"}
31+
<Link component={RouterLink} to={auditLog.resource_link}>
32+
{"{{action}}"}
33+
</Link>
34+
workspace{"{{workspaceName}}"}
35+
</Trans>
36+
</span>
37+
)
38+
}

site/src/i18n/en/auditLog.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
"os": "OS: ",
1414
"browser": "Browser: ",
1515
"onBehalfOf": " on behalf of {{owner}}",
16-
"buildReason": "Coder automatically",
1716
"unknownUser": "an unknown user",
18-
"started": "started",
19-
"stopped": "stopped",
20-
"workspace": " workspace "
17+
"workspaceBuild": "{{user}} <1>{{action}}</1> workspace <strong>{{workspaceName}}</strong>",
18+
"auditDescription": "{{truncatedDescription}} <1>{{target}}</1>"
2119
}
2220
},
2321
"paywall": {

0 commit comments

Comments
 (0)