Skip to content
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/main' into add-audit-coverage/ki…
…ra-pilot
  • Loading branch information
Kira-Pilot committed Oct 27, 2022
commit f669898bb8229ba73046cfe5596b635900d153f7
52 changes: 17 additions & 35 deletions site/src/components/AuditLogRow/AuditLogRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,6 @@ import userAgentParser from "ua-parser-js"
import { combineClasses } from "util/combineClasses"
import { AuditLogDiff } from "./AuditLogDiff"

const readableActionMessage = (auditLog: AuditLog) => {
return auditLog.description
.replace("{user}", `<strong>${auditLog.user?.username.trim()}</strong>`)
.replace("{target}", `<strong>${auditLog.resource_target.trim()}</strong>`)
}

const httpStatusColor = (httpStatus: number): PaletteIndex => {
if (httpStatus >= 300 && httpStatus < 500) {
return "warning"
}

if (httpStatus >= 500) {
return "error"
}

return "success"
}

// the BE returns additional_field as a string, since it's stored as JSON but
// technically, it's a map, so we adjust the type here.
type ExtendedAuditLog = Omit<AuditLog, "additional_fields"> & {
Expand All @@ -57,8 +39,20 @@ const readableActionMessage = (auditLog: ExtendedAuditLog) => {
}

return auditLog.description
.replace("{user}", `<strong>${auditLog.user?.username}</strong>`)
.replace("{target}", `<strong>${auditLog.resource_target}</strong>`)
.replace("{user}", `<strong>${auditLog.user?.username.trim()}</strong>`)
.replace("{target}", `<strong>${auditLog.resource_target.trim()}</strong>`)
}

const httpStatusColor = (httpStatus: number): PaletteIndex => {
if (httpStatus >= 300 && httpStatus < 500) {
return "warning"
}

if (httpStatus >= 500) {
return "error"
}

return "success"
}

export interface AuditLogRowProps {
Expand Down Expand Up @@ -123,20 +117,6 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
username={auditLog.user?.username ?? ""}
avatarURL={auditLog.user?.avatar_url}
/>
<div>
<span
className={styles.auditLogResume}
dangerouslySetInnerHTML={{
__html: readableActionMessage(
auditLog as unknown as ExtendedAuditLog,
),
}}
/>
<span className={styles.auditLogTime}>
{createDayString(auditLog.time)}
</span>
</div>
</Stack>

<Stack
alignItems="baseline"
Expand All @@ -152,7 +132,9 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
>
<span
dangerouslySetInnerHTML={{
__html: readableActionMessage(auditLog),
__html: readableActionMessage(
auditLog as unknown as ExtendedAuditLog,
),
}}
/>
<span className={styles.auditLogTime}>
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.