Skip to content

Commit 7479538

Browse files
committed
Check emtpy diffs
1 parent 785f67b commit 7479538

File tree

1 file changed

+60
-50
lines changed

1 file changed

+60
-50
lines changed

site/src/pages/AuditPage/AuditPageView.tsx

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -49,58 +49,73 @@ const AuditDiff = () => {
4949
const AuditLogRow: React.FC<{ auditLog: AuditLog }> = ({ auditLog }) => {
5050
const styles = useStyles()
5151
const [isDiffOpen, setIsDiffOpen] = useState(false)
52+
const diffs = Object.entries(auditLog.diff)
53+
const shouldDisplayDiff = diffs.length > 1
54+
55+
const toggle = () => {
56+
if (shouldDisplayDiff) {
57+
setIsDiffOpen((v) => !v)
58+
}
59+
}
5260

5361
return (
54-
<>
55-
<Stack
56-
direction="row"
57-
alignItems="center"
58-
className={styles.auditLogRow}
59-
tabIndex={0}
60-
onClick={() => setIsDiffOpen((v) => !v)}
61-
onKeyDown={(event) => {
62-
if (event.key === "Enter") {
63-
setIsDiffOpen((v) => !v)
64-
}
65-
}}
66-
>
62+
<TableRow key={auditLog.id} hover={shouldDisplayDiff}>
63+
<TableCell className={styles.auditLogCell}>
6764
<Stack
65+
style={{ cursor: shouldDisplayDiff ? "pointer" : undefined }}
6866
direction="row"
6967
alignItems="center"
70-
justifyContent="space-between"
71-
className={styles.auditLogRowInfo}
68+
className={styles.auditLogRow}
69+
tabIndex={0}
70+
onClick={toggle}
71+
onKeyDown={(event) => {
72+
if (event.key === "Enter") {
73+
toggle()
74+
}
75+
}}
7276
>
73-
<Stack direction="row" alignItems="center">
74-
<UserAvatar username={auditLog.user?.username ?? ""} />
75-
<div>
76-
<span className={styles.auditLogResume}>
77-
<strong>{auditLog.user?.username}</strong> {auditLog.action}{" "}
78-
<strong>{auditLog.resource.name}</strong>
79-
</span>
80-
<span className={styles.auditLogTime}>{createDayString(auditLog.time)}</span>
81-
</div>
82-
</Stack>
83-
84-
<Stack direction="column" alignItems="flex-end" spacing={1}>
85-
<Pill type="success" text={auditLog.status_code.toString()} />
86-
<Stack direction="row" alignItems="center" className={styles.auditLogExtraInfo}>
77+
<Stack
78+
direction="row"
79+
alignItems="center"
80+
justifyContent="space-between"
81+
className={styles.auditLogRowInfo}
82+
>
83+
<Stack direction="row" alignItems="center">
84+
<UserAvatar username={auditLog.user?.username ?? ""} />
8785
<div>
88-
<strong>IP</strong> {auditLog.ip}
89-
</div>
90-
<div>
91-
<strong>Agent</strong> {auditLog.user_agent}
86+
<span className={styles.auditLogResume}>
87+
<strong>{auditLog.user?.username}</strong> {auditLog.action}{" "}
88+
<strong>{auditLog.resource.name}</strong>
89+
</span>
90+
<span className={styles.auditLogTime}>{createDayString(auditLog.time)}</span>
9291
</div>
9392
</Stack>
93+
94+
<Stack direction="column" alignItems="flex-end" spacing={1}>
95+
<Pill type="success" text={auditLog.status_code.toString()} />
96+
<Stack direction="row" alignItems="center" className={styles.auditLogExtraInfo}>
97+
<div>
98+
<strong>IP</strong> {auditLog.ip}
99+
</div>
100+
<div>
101+
<strong>Agent</strong> {auditLog.user_agent}
102+
</div>
103+
</Stack>
104+
</Stack>
94105
</Stack>
95-
</Stack>
96106

97-
{isDiffOpen ? <CloseDropdown /> : <OpenDropdown />}
98-
</Stack>
107+
<div className={shouldDisplayDiff ? undefined : styles.disabledDropdownIcon}>
108+
{isDiffOpen ? <CloseDropdown /> : <OpenDropdown />}
109+
</div>
110+
</Stack>
99111

100-
<Collapse in={isDiffOpen}>
101-
<AuditDiff />
102-
</Collapse>
103-
</>
112+
{shouldDisplayDiff && (
113+
<Collapse in={isDiffOpen}>
114+
<AuditDiff />
115+
</Collapse>
116+
)}
117+
</TableCell>
118+
</TableRow>
104119
)
105120
}
106121

@@ -111,8 +126,6 @@ export const Language = {
111126
}
112127

113128
export const AuditPageView: FC<{ auditLogs?: AuditLog[] }> = ({ auditLogs }) => {
114-
const styles = useStyles()
115-
116129
return (
117130
<Margins>
118131
<PageHeader
@@ -138,13 +151,7 @@ export const AuditPageView: FC<{ auditLogs?: AuditLog[] }> = ({ auditLogs }) =>
138151
</TableHead>
139152
<TableBody>
140153
{auditLogs ? (
141-
auditLogs.map((auditLog) => (
142-
<TableRow key={auditLog.id} hover>
143-
<TableCell className={styles.auditLogCell}>
144-
<AuditLogRow auditLog={auditLog} />
145-
</TableCell>
146-
</TableRow>
147-
))
154+
auditLogs.map((auditLog) => <AuditLogRow auditLog={auditLog} key={auditLog.id} />)
148155
) : (
149156
<TableLoader />
150157
)}
@@ -162,7 +169,6 @@ const useStyles = makeStyles((theme) => ({
162169

163170
auditLogRow: {
164171
padding: theme.spacing(2, 4),
165-
cursor: "pointer",
166172
},
167173

168174
auditLogRowInfo: {
@@ -188,6 +194,10 @@ const useStyles = makeStyles((theme) => ({
188194
color: theme.palette.text.secondary,
189195
},
190196

197+
disabledDropdownIcon: {
198+
opacity: 0.5,
199+
},
200+
191201
diff: {
192202
display: "flex",
193203
alignItems: "flex-start",

0 commit comments

Comments
 (0)