({ log }: { log: AuditLog })
| 131 | // response was authorized by an access grant — gives users a trail to the |
| 132 | // grant's approval issue. |
| 133 | function AuditLogViewCell({ log }: { log: AuditLog }) { |
| 134 | const staticLink = getViewLink(log); |
| 135 | |
| 136 | // Only attempt the grant fallback when no static link is available. |
| 137 | const grantName = useMemo(() => { |
| 138 | if (staticLink) return null; |
| 139 | try { |
| 140 | const response = JSON.parse(log.response || "{}") as Record< |
| 141 | string, |
| 142 | unknown |
| 143 | >; |
| 144 | const value = response["appliedAccessGrant"]; |
| 145 | return typeof value === "string" && value ? value : null; |
| 146 | } catch { |
| 147 | return null; |
| 148 | } |
| 149 | }, [staticLink, log.response]); |
| 150 | |
| 151 | const fetchAccessGrant = useAppStore((s) => s.fetchAccessGrant); |
| 152 | const grantIssue = useAppStore((s) => |
| 153 | grantName ? (s.accessGrantsByName[grantName]?.issue ?? "") : "" |
| 154 | ); |
| 155 | |
| 156 | useEffect(() => { |
| 157 | if (grantName && !grantIssue) { |
| 158 | void fetchAccessGrant(grantName); |
| 159 | } |
| 160 | }, [grantName, grantIssue, fetchAccessGrant]); |
| 161 | |
| 162 | const target = staticLink || grantIssue || null; |
| 163 | if (!target) return null; |
| 164 | const href = target.startsWith("/") ? target : `/${target}`; |
| 165 | return ( |
| 166 | <RouterLink to={href} target="_blank" rel="noreferrer"> |
| 167 | <ExternalLink className="size-4 text-accent" /> |
| 168 | </RouterLink> |
| 169 | ); |
| 170 | } |
| 171 | |
| 172 | function getViewLink(auditLog: AuditLog): string | null { |
| 173 | let parsedRequest: Record<string, unknown>; |
nothing calls this directly
no test coverage detected