Skip to content

Commit

Permalink
STU-306 | Fix check code (#1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
LatentDream authored Feb 28, 2024
1 parent d862232 commit 69c2093
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ import { Light as SyntaxHighlighter } from "react-syntax-highlighter";
type Props = {
isModalOpen: boolean;
handleModalOpen: Dispatch<SetStateAction<boolean>>;
row: Row<TestSequenceElement>;
test: Test;
};
SyntaxHighlighter.registerLanguage("python", python);

const PythonTestFileModal = ({ isModalOpen, handleModalOpen, row }: Props) => {
const PythonTestFileModal = ({ isModalOpen, handleModalOpen, test }: Props) => {
const [sourceCode, setSourceCode] = useState("");

useEffect(() => {
window.api
.getFileContent((row.original as Test).path.split("::")[0])
.getFileContent(test.path.split("::")[0])
.then((content) => setSourceCode(content));
}, [row.original]);
}, [test]);
return (
<Dialog open={isModalOpen} onOpenChange={handleModalOpen}>
<DialogContent className="my-12 max-h-screen overflow-y-scroll border-muted bg-background p-12 sm:max-w-2xl md:max-w-4xl">
<DialogHeader>
<DialogTitle>{(row.original as Test).testName}</DialogTitle>
<DialogTitle>{test.testName}</DialogTitle>
</DialogHeader>
<h2 className="text-lg font-semibold text-muted-foreground">
Python code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
ConditionalComponent,
Conditional,
StatusTypes,
Test,
} from "@/renderer/types/testSequencer";
import { useTestSequencerState } from "@/renderer/hooks/useTestSequencerState";
import { parseInt, filter, map } from "lodash";
Expand All @@ -56,6 +57,7 @@ import {
HoverCardContent,
HoverCardTrigger,
} from "@/components/ui/hover-card";
import PythonTestFileModal from "../PythonTestFileModal";

function renderErrorMessage(text: string): JSX.Element {
const lines = text.split("\n");
Expand Down Expand Up @@ -93,6 +95,8 @@ export function DataTable() {
const { elems, setElems, running } = useTestSequencerState();
const [addIfStatement] = useState(false);
const indentLevels = getIndentLevels(elems);
const [openPyTestFileModal, setOpenPyTestFileModal] = useState(false);
const [testToDisplay, setTestToDisplay] = useState<Test | null>(null);

const columns: ColumnDef<TestSequenceElement>[] = [
{
Expand Down Expand Up @@ -363,6 +367,13 @@ export function DataTable() {
handleWriteConditionalModalOpen={setShowWriteConditionalModal}
handleWrite={handleWriteConditionalModal}
/>
{openPyTestFileModal && (
<PythonTestFileModal
isModalOpen={openPyTestFileModal}
handleModalOpen={setOpenPyTestFileModal}
test={testToDisplay as Test}
/>
)}
<div className="m-1 flex items-center py-0">
<LockableButton
disabled={Object.keys(rowSelection).length == 0}
Expand Down Expand Up @@ -461,6 +472,16 @@ export function DataTable() {
>
Remove Test
</ContextMenuItem>
{row.original.type === "test" && (
<ContextMenuItem
onClick={() => {
setOpenPyTestFileModal(true);
setTestToDisplay(row.original as Test);
}}
>
Consult Code
</ContextMenuItem>
)}
</ContextMenuContent>
</ContextMenu>
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
import { CellContext } from "@tanstack/react-table";
import { Loader } from "lucide-react";
import React, { useState } from "react";
import PythonTestFileModal from "../PythonTestFileModal";
type Props = {
cellProps: CellContext<TestSequenceElement, unknown>;
indentLevels: number[];
Expand All @@ -33,33 +32,20 @@ const IndentLine = ({
);

const TestNameCell = ({ cellProps: { row }, indentLevels, running }: Props) => {
const [openPyTestFileModal, setOpenPyTestFileModal] = useState(false);

const isTest = row.original.type === "test";

return isTest ? (
<>
<div className="flex h-full cursor-pointer space-x-2">
{/* Indent levels */}
<div
className="flex flex-row space-x-1"
onClick={() => setOpenPyTestFileModal(true)}
>
<div className="flex flex-row space-x-1">
<IndentLine
content={(row.original as Test).testName}
level={indentLevels[row.id]}
/>
{running.includes(row.original.id) && <Loader className="scale-50" />}
</div>
</div>
{/* Conditionally add modal component to unmount it on close */}
{openPyTestFileModal && (
<PythonTestFileModal
isModalOpen={openPyTestFileModal}
handleModalOpen={setOpenPyTestFileModal}
row={row}
/>
)}
</>
) : (
<IndentLine
Expand Down

0 comments on commit 69c2093

Please sign in to comment.