Skip to content

Commit

Permalink
[#216] Andreas' review implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
notcruz committed Mar 1, 2023
1 parent 23b819f commit 7ec7b04
Show file tree
Hide file tree
Showing 12 changed files with 732 additions and 750 deletions.
10 changes: 4 additions & 6 deletions client/src/components/exercise/lab7/Main.js
@@ -1,4 +1,4 @@
import React, { Component } from "react";
import React from "react";
import { Router } from "@reach/router";
import "../../../assets/stylesheets/main.scss";

Expand All @@ -12,9 +12,8 @@ import AlterationStart from "./pages/AlterationActivity/AlterationStart";
import AlterationQuiz from "./pages/AlterationActivity/AlterationQuiz";
import ExerciseEnd from "./pages/ExerciseEnd";

class Main extends Component {
render() {
return (
const Main = () => {
return (
<div className="bottomSpace">
<Router className="app">
<ExerciseStart default path="/*" />
Expand All @@ -35,8 +34,7 @@ class Main extends Component {
<ExerciseEnd path="/ExerciseEnd" />
</Router>
</div>
);
}
);
}

export default Main;
13 changes: 6 additions & 7 deletions client/src/components/exercise/lab7/components/Code.js
Expand Up @@ -156,18 +156,15 @@ class Code extends Component {
<div className="code_editor">
<div className="code_editor__content">
<div className="code_editor__files">

{/* AutoSysAI.js */}
<div className="code_editor__file code_editor__file--active">
AutoSysAI.js
</div>
{/* psuedocode */}
{/* <div className="code_editor__file code_editor__file--inactive">
Psuedocode
</div> */}
</div>

{/* import React, Component from react */}
<div className="code_editor__code">
{/* import React, Component from react */}
<div className="code_editor__line">
<span className="code_editor__line--purple">import&nbsp;</span>
<span className="code_editor__line--blue">React</span>
Expand Down Expand Up @@ -199,13 +196,15 @@ class Code extends Component {
<div className="code_editor__line">
{/* AI function comment */}
<span className="code_editor__line--darkgreen">
&#47;&#47; Here is where you will update the equation to improve the AI&lsquo;s accuracy
&#47;&#47; Here is where you will update the equation to improve
the AI&lsquo;s accuracy
</span>
</div>
<div className="code_editor__line">
{/* AI function comment */}
<span className="code_editor__line--darkgreen">
&#47;&#47; Feel free to add other math operations to improve its accuracy
&#47;&#47; Feel free to add other math operations to improve its
accuracy
</span>
</div>
<div className="code_editor__line">
Expand Down
202 changes: 92 additions & 110 deletions client/src/components/exercise/lab7/components/Collapsible.js
@@ -1,137 +1,119 @@
import React, { Component } from "react";
import {
FILE_INCORRECT,
FILE_INTRUSION,
FILE_PROTECTED,
THREAT_LEVEL_TEXT,
} from "../../../../constants/lab7";
import React, {useState} from "react";
import {FILE_INCORRECT, FILE_INTRUSION, FILE_PROTECTED, THREAT_LEVEL_TEXT,} from "../../../../constants/lab7";
import PropTypes from "prop-types";

class Collapsible extends Component {
constructor(props) {
super(props);
this.state = {
active: false,
};
}
const Collapsible = ({result: {files, threatLvl}, index}) => {
const [active, setActive] = useState(false);

/**
* Toggle method for dropdown. No dropdown if no intrusions occurred.
*
* @param numOfIntrusions number of intrusions
*/
handleClick = (numOfIntrusions) => {
const { active } = this.state;
if (numOfIntrusions > 0) this.setState({ active: !active });
};
/**
* Toggle method for dropdown. No dropdown if no intrusions occurred.
*
* @param numOfIntrusions number of intrusions
*/
const handleClick = (numOfIntrusions) => {
if (numOfIntrusions > 0) setActive(!active);
};

render = () => {
const { active } = this.state;
const {
result: { files, threatLvl },
index,
} = this.props;
const intrusions = files.filter((file) => file.result === FILE_INTRUSION);
const protectedFiles = files.filter(
(file) => file.result === FILE_PROTECTED
(file) => file.result === FILE_PROTECTED
);
const incorrectFiles = files.filter(
(file) => file.result === FILE_INCORRECT
(file) => file.result === FILE_INCORRECT
);

return (
<div className={"tw-bg-[#EBE8E8] tw-shadow-xl"}>
<button
onClick={() => this.handleClick(intrusions.length)}
className={
"tw-border-none tw-flex tw-w-full tw-items-center tw-justify-around tw-justify-center tw-text-lg tw-py-3 tw-px-6"
}
>
<p className={"tw-font-bold tw-text-xl tw-w-28"}>Round {index + 1}</p>
<p className={"tw-font-semibold tw-text-left tw-w-44"}>
Threat Level: {THREAT_LEVEL_TEXT[threatLvl]}
</p>
<p className={"tw-font-semibold tw-text-left tw-w-28"}>
<div className={"tw-bg-[#EBE8E8] tw-shadow-xl"}>
<button
onClick={() => handleClick(intrusions.length)}
className={
"tw-border-none tw-flex tw-w-full tw-items-center tw-justify-around tw-justify-center tw-text-lg tw-py-3 tw-px-6"
}
>
<p className={"tw-font-bold tw-text-xl tw-w-28"}>Round {index + 1}</p>
<p className={"tw-font-semibold tw-text-left tw-w-44"}>
Threat Level: {THREAT_LEVEL_TEXT[threatLvl]}
</p>
<p className={"tw-font-semibold tw-text-left tw-w-28"}>
<span className={intrusions.length > 0 ? "tw-text-[#e31c3d]" : ""}>
Intrusions: {intrusions.length}
</span>
</p>
<p className={"tw-font-semibold tw-text-left tw-w-36"}>
Protected (TP): {protectedFiles.length}
</p>
<p className={"tw-font-semibold tw-text-left tw-w-36"}>
</p>
<p className={"tw-font-semibold tw-text-left tw-w-36"}>
Protected (TP): {protectedFiles.length}
</p>
<p className={"tw-font-semibold tw-text-left tw-w-36"}>
<span
className={incorrectFiles.length > 0 ? "tw-text-brightRed" : ""}
className={incorrectFiles.length > 0 ? "tw-text-brightRed" : ""}
>
Incorrect (FP): {incorrectFiles.length}
</span>
</p>
<div className={"tw-w-3"}>{active ? "-" : "+"}</div>
</button>
{active && intrusions.length > 0 && (
<div className={"tw-px-16"}>
<div className={"tw-mt-6"}>
<h3 className={"tw-font-bold"}>List of Intrusions</h3>
<ul className={"tw-pb-9 tw-pt-3"}>
{intrusions.map((file, index) => {
const className =
"tw-flex tw-text-left tw-py-3 tw-border-x-0 tw-border-b tw-border-solid ";
return (
<li
key={index}
className={
className +
(index === 0 ? "tw-border-t" : "tw-border-t-0")
}
>
<div className={"tw-flex-shrink-0 tw-w-64"}>
<p>
<span className={"tw-font-bold"}>Filename:</span>{" "}
{file.fileName}
</p>
<p>
</p>
<div className={"tw-w-3"}>{active ? "-" : "+"}</div>
</button>
{active && intrusions.length > 0 && (
<div className={"tw-px-16"}>
<div className={"tw-mt-6"}>
<h3 className={"tw-font-bold"}>List of Intrusions</h3>
<ul className={"tw-pb-9 tw-pt-3"}>
{intrusions.map((file, index) => {
const className =
"tw-flex tw-text-left tw-py-3 tw-border-x-0 tw-border-b tw-border-solid ";
return (
<li
key={index}
className={
className +
(index === 0 ? "tw-border-t" : "tw-border-t-0")
}
>
<div className={"tw-flex-shrink-0 tw-w-64"}>
<p>
<span className={"tw-font-bold"}>Filename:</span>{" "}
{file.fileName}
</p>
<p>
<span className={"tw-font-bold"}>
Sensitivity Level:
</span>{" "}
{file.sensitivityLevel}
</p>
<p>
<span className={"tw-font-bold"}>Content:</span>{" "}
{file.content}
</p>
</div>
<div className={"tw-ml-3"}>
<p className={"tw-font-bold"}>Intrusion Message:</p>
<p>{file.message}</p>
</div>
</li>
);
})}
</ul>
</div>
</div>
)}
</div>
{file.sensitivityLevel}
</p>
<p>
<span className={"tw-font-bold"}>Content:</span>{" "}
{file.content}
</p>
</div>
<div className={"tw-ml-3"}>
<p className={"tw-font-bold"}>Intrusion Message:</p>
<p>{file.message}</p>
</div>
</li>
);
})}
</ul>
</div>
</div>
)}
</div>
);
};
}
};

export default Collapsible;

Collapsible.propTypes = {
result: PropTypes.shape({
threatLvl: PropTypes.number,
files: PropTypes.arrayOf(
PropTypes.shape({
fileName: PropTypes.string,
content: PropTypes.string,
sensitivityLevel: PropTypes.number,
decision: PropTypes.string,
result: PropTypes.string,
report: PropTypes.string,
message: PropTypes.string,
})
),
}),
index: PropTypes.number,
result: PropTypes.shape({
threatLvl: PropTypes.number,
files: PropTypes.arrayOf(
PropTypes.shape({
fileName: PropTypes.string,
content: PropTypes.string,
sensitivityLevel: PropTypes.number,
decision: PropTypes.string,
result: PropTypes.string,
report: PropTypes.string,
message: PropTypes.string,
})
),
}),
index: PropTypes.number,
};

0 comments on commit 7ec7b04

Please sign in to comment.