Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
48 changes: 30 additions & 18 deletions src/components/ProjectAuditTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import makeStyles from "@mui/styles/makeStyles";
import { AuditAction } from "@gliff-ai/annotate";

import { AnnotationSession, ImageData } from "@/index";
import { ProjectAuditAction, ImageData } from "@/index";

const useStyles = makeStyles(() => ({
tableText: {
Expand All @@ -20,13 +20,25 @@ const useStyles = makeStyles(() => ({
}));

interface Props {
sessions: AnnotationSession[];
actions: ProjectAuditAction[];
searchField: string;
searchValue: string;
setAudit: (audit: AuditAction[]) => void;
setProductsNavbarImageData: (imageData: ImageData) => void;
}

function camelNameToLabel (name: string) {
// https://www.codeproject.com/Tips/5320583/Converting-Camel-Case-Names-to-Human-Case-Labels
let reFindHumps = /([A-Z]){1}([a-z0-9]){1}/g
let re1stLower = /^[a-z]{1}/
let label = name.replace(reFindHumps, ' $1$2')

if (re1stLower.test(label)) {
label = label.slice(0,1).toUpperCase() + label.substring(1)
}
return label
}

export const ProjectAuditTable = (props: Props): ReactElement => {
const classes = useStyles();

Expand All @@ -38,37 +50,37 @@ export const ProjectAuditTable = (props: Props): ReactElement => {
<TableCell className={classes.tableText}>Date &amp; Time</TableCell>
<TableCell className={classes.tableText}>User</TableCell>
<TableCell className={classes.tableText}>Action</TableCell>
<TableCell className={classes.tableText}>Image</TableCell>
<TableCell className={classes.tableText}>Details</TableCell>
</TableRow>
</TableHead>
<TableBody>
{props.sessions
{props.actions
.filter(
(session: AnnotationSession) =>
(action: ProjectAuditAction) =>
!["User", "Image"].includes(props.searchField) ||
(props.searchField === "User" &&
session.username.includes(props.searchValue)) ||
action.username.includes(props.searchValue)) ||
(props.searchField.toLowerCase() === "Image" &&
session.imagename.toLowerCase().includes(props.searchValue))
action.action.imagename.toLowerCase().includes(props.searchValue))
)
.map((session: AnnotationSession) => (
.map((action: ProjectAuditAction) => (
<TableRow
key={`${session.timestamp}`}
onClick={() => {
props.setAudit(session.audit);
key={`${action.timestamp}`}
onClick={action.action.type === "annotate" ? () => {
props.setAudit(action.action.audit);
props.setProductsNavbarImageData({
imageName: session?.imagename,
imageUid: session?.imageUid,
imageName: action?.action.imagename,
imageUid: action?.action.imageUid,
});
}}
} : null}
style={{ cursor: "pointer" }}
>
<TableCell>
{new Date(session.timestamp).toLocaleString()}
{new Date(action.timestamp).toLocaleString()}
</TableCell>
<TableCell>{session.username}</TableCell>
<TableCell>Annotate</TableCell>
<TableCell>{session.imagename}</TableCell>
<TableCell>{action.username}</TableCell>
<TableCell>{camelNameToLabel(action.action.type)}</TableCell>
<TableCell>{action.action.imagename}</TableCell>
</TableRow>
))}
</TableBody>
Expand Down
11 changes: 9 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ export interface AnnotationSession {
imageUid: string;
}

export interface ProjectAuditAction {
action: {type: string, audit?: AuditAction[]} & Record<string, string>;
username: string;
timestamp: string;
}

interface Props {
showAppBar: boolean;
sessions: AnnotationSession[];
actions: ProjectAuditAction[];
setProductsNavbarImageData: (imageName: ImageData) => void;
}

Expand Down Expand Up @@ -102,6 +108,7 @@ const UserInterface = (props: Props): ReactElement => {
</AppBar>
);


return (
<StylesProvider generateClassName={generateClassName("audit")}>
<StyledEngineProvider injectFirst>
Expand Down Expand Up @@ -163,7 +170,7 @@ const UserInterface = (props: Props): ReactElement => {
/>
) : (
<ProjectAuditTable
sessions={props.sessions}
actions={props.actions}
searchField={searchField}
searchValue={searchValue}
setAudit={setAudit}
Expand Down