Skip to content

chore: use emotion for styling (pt. 8) #10447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Nov 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
emotion: AuditLogRow
  • Loading branch information
aslilac committed Oct 31, 2023
commit 0cbd32bd5c49eba8eece5ce7fc1e49cb3b063a31
65 changes: 30 additions & 35 deletions site/src/pages/AuditPage/AuditLogRow/AuditLogRow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type CSSObject, type Interpolation, type Theme } from "@emotion/react";
import Collapse from "@mui/material/Collapse";
import { makeStyles } from "@mui/styles";
import TableCell from "@mui/material/TableCell";
import { AuditLog } from "api/typesGenerated";
import type { AuditLog } from "api/typesGenerated";
import { DropdownArrow } from "components/DropdownArrow/DropdownArrow";
import { Pill, type PillType } from "components/Pill/Pill";
import { Stack } from "components/Stack/Stack";
Expand Down Expand Up @@ -40,7 +40,6 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
auditLog,
defaultIsDiffOpen = false,
}) => {
const styles = useStyles();
const [isDiffOpen, setIsDiffOpen] = useState(defaultIsDiffOpen);
const diffs = Object.entries(auditLog.diff);
const shouldDisplayDiff = diffs.length > 0;
Expand All @@ -65,11 +64,11 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
data-testid={`audit-log-row-${auditLog.id}`}
clickable={shouldDisplayDiff}
>
<TableCell className={styles.auditLogCell}>
<TableCell css={styles.auditLogCell}>
<Stack
direction="row"
alignItems="center"
className={styles.auditLogHeader}
css={styles.auditLogHeader}
tabIndex={0}
onClick={toggle}
onKeyDown={(event) => {
Expand All @@ -81,57 +80,53 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
<Stack
direction="row"
alignItems="center"
className={styles.auditLogHeaderInfo}
css={styles.auditLogHeaderInfo}
>
<Stack
direction="row"
alignItems="center"
className={styles.fullWidth}
>
<Stack direction="row" alignItems="center" css={styles.fullWidth}>
<UserAvatar
username={auditLog.user?.username ?? "?"}
avatarURL={auditLog.user?.avatar_url}
/>

<Stack
alignItems="baseline"
className={styles.fullWidth}
css={styles.fullWidth}
justifyContent="space-between"
direction="row"
>
<Stack
className={styles.auditLogSummary}
css={styles.auditLogSummary}
direction="row"
alignItems="baseline"
spacing={1}
>
<AuditLogDescription auditLog={auditLog} />
{auditLog.is_deleted && (
<span className={styles.deletedLabel}>
<span css={styles.deletedLabel}>
<>(deleted)</>
</span>
)}
<span className={styles.auditLogTime}>
<span css={styles.auditLogTime}>
{new Date(auditLog.time).toLocaleTimeString()}
</span>
</Stack>

<Stack direction="row" alignItems="center">
<Stack direction="row" spacing={1} alignItems="baseline">
{auditLog.ip && (
<span className={styles.auditLogInfo}>
<span css={styles.auditLogInfo}>
<>IP: </>
<strong>{auditLog.ip}</strong>
</span>
)}
{os.name && (
<span className={styles.auditLogInfo}>
<span css={styles.auditLogInfo}>
<>OS: </>
<strong>{os.name}</strong>
</span>
)}
{browser.name && (
<span className={styles.auditLogInfo}>
<span css={styles.auditLogInfo}>
<>Browser: </>
<strong>
{browser.name} {browser.version}
Expand All @@ -141,7 +136,7 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
</Stack>

<Pill
className={styles.httpStatusPill}
css={styles.httpStatusPill}
type={httpStatusColor(auditLog.status_code)}
text={auditLog.status_code.toString()}
/>
Expand All @@ -153,7 +148,7 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
{shouldDisplayDiff ? (
<div> {<DropdownArrow close={isDiffOpen} />}</div>
) : (
<div className={styles.columnWithoutDiff}></div>
<div css={styles.columnWithoutDiff}></div>
)}
</Stack>

Expand All @@ -167,37 +162,37 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({
);
};

const useStyles = makeStyles((theme) => ({
const styles = {
auditLogCell: {
padding: "0 !important",
border: 0,
},

auditLogHeader: {
auditLogHeader: (theme) => ({
padding: theme.spacing(2, 4),
},
}),

auditLogHeaderInfo: {
flex: 1,
},

auditLogSummary: {
...theme.typography.body1,
auditLogSummary: (theme) => ({
...(theme.typography.body1 as CSSObject),
fontFamily: "inherit",
},
}),

auditLogTime: {
auditLogTime: (theme) => ({
color: theme.palette.text.secondary,
fontSize: 12,
},
}),

auditLogInfo: {
...theme.typography.body2,
auditLogInfo: (theme) => ({
...(theme.typography.body2 as CSSObject),
fontSize: 12,
fontFamily: "inherit",
color: theme.palette.text.secondary,
display: "block",
},
}),

// offset the absence of the arrow icon on diff-less logs
columnWithoutDiff: {
Expand All @@ -216,8 +211,8 @@ const useStyles = makeStyles((theme) => ({
fontWeight: 600,
},

deletedLabel: {
...theme.typography.caption,
deletedLabel: (theme) => ({
...(theme.typography.caption as CSSObject),
color: theme.palette.text.secondary,
},
}));
}),
} satisfies Record<string, Interpolation<Theme>>;