-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show Python code for test in a modal (#1097)
* feat: add pytestfile modal to show python code of tests * refactor: fetch source code after opening modal each time * refactor: do not include source code in test element --------- Co-authored-by: Gui <guillaume.thibault.98@gmail.com>
- Loading branch information
1 parent
0604f1a
commit 933ea79
Showing
9 changed files
with
157 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/renderer/routes/test_sequencer_panel/components/PythonTestFileModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { flojoySyntaxTheme } from "@/renderer/assets/FlojoyTheme"; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogHeader, | ||
DialogTitle, | ||
} from "@/renderer/components/ui/dialog"; | ||
import { ScrollArea, ScrollBar } from "@/renderer/components/ui/scroll-area"; | ||
import { Test, TestSequenceElement } from "@/renderer/types/testSequencer"; | ||
import { Row } from "@tanstack/react-table"; | ||
import { Dispatch, SetStateAction, useEffect, useState } from "react"; | ||
import python from "react-syntax-highlighter/dist/cjs/languages/hljs/python"; | ||
import { Light as SyntaxHighlighter } from "react-syntax-highlighter"; | ||
|
||
type Props = { | ||
isModalOpen: boolean; | ||
handleModalOpen: Dispatch<SetStateAction<boolean>>; | ||
row: Row<TestSequenceElement>; | ||
}; | ||
SyntaxHighlighter.registerLanguage("python", python); | ||
|
||
const PythonTestFileModal = ({ isModalOpen, handleModalOpen, row }: Props) => { | ||
const [sourceCode, setSourceCode] = useState(""); | ||
|
||
useEffect(() => { | ||
window.api | ||
.getFileContent((row.original as Test).path.split("::")[0]) | ||
.then((content) => setSourceCode(content)); | ||
}, [row.original]); | ||
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> | ||
</DialogHeader> | ||
<h2 className="text-lg font-semibold text-muted-foreground"> | ||
Python code | ||
</h2> | ||
<ScrollArea className="h-full w-full rounded-lg"> | ||
<ScrollBar orientation="vertical" /> | ||
<ScrollBar orientation="horizontal" /> | ||
<SyntaxHighlighter language="python" style={flojoySyntaxTheme}> | ||
{sourceCode} | ||
</SyntaxHighlighter> | ||
</ScrollArea> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default PythonTestFileModal; |
2 changes: 1 addition & 1 deletion
2
src/renderer/routes/test_sequencer_panel/components/TestSequencerInfo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/renderer/routes/test_sequencer_panel/components/data-table/test-name-cell.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { | ||
Conditional, | ||
Test, | ||
TestSequenceElement, | ||
} from "@/renderer/types/testSequencer"; | ||
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[]; | ||
running: string[]; | ||
}; | ||
|
||
const IndentLine = ({ | ||
content: name, | ||
level = 0, | ||
}: { | ||
content: React.ReactNode; | ||
level: number; | ||
}) => ( | ||
<div className="flex h-full flex-row"> | ||
{level == 0 ? ( | ||
name | ||
) : ( | ||
<div className="flex flex-row"> | ||
<div className={"mr-5 flex h-full border-l-2 border-blue-800"}></div> | ||
<IndentLine content={name} level={level - 1} /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
|
||
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)} | ||
> | ||
<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 | ||
content={ | ||
<div className="flex flex-col"> | ||
<b>{(row.original as Conditional).conditionalType.toUpperCase()}</b> | ||
<i> | ||
{(row.original as Conditional).condition.substring(0, 45)} | ||
{(row.original as Conditional).condition.length >= 45 && <>...</>} | ||
</i> | ||
</div> | ||
} | ||
level={indentLevels[row.id]} | ||
/> | ||
); | ||
}; | ||
|
||
export default TestNameCell; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters