-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e8ed55
commit 2494bfb
Showing
8 changed files
with
490 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { useState } from "react"; | ||
import { configDataPropTypes } from "./UserInput"; | ||
import UserInput from "./UserInput"; | ||
import Header from "./Header"; | ||
import { Box } from "@mui/material"; | ||
import { ErrorBoundary } from "react-error-boundary"; | ||
import UserOutput from "./UserOutput"; | ||
|
||
export default function AppTwo() { | ||
const [textData, setTextData] = useState(""); | ||
const [configData, setConfigData] = useState<configDataPropTypes>({ | ||
useAutomation: true, | ||
overallDrawConfig: { | ||
seed: 0, | ||
}, | ||
}); | ||
const [jsonResult, setJsonResult] = useState(null); | ||
const [svgResult, setSvgResult] = useState(null); | ||
const [failureBanner, setFailureBanner] = useState(""); | ||
|
||
const onTextDataSubmit = (event?) => { | ||
event?.preventDefault(); | ||
try { | ||
setJsonResult(JSON.parse(textData)); | ||
setFailureBanner(""); | ||
} catch (error) { | ||
const errorMessage = `Error parsing inputted JSON: ${error.message}`; | ||
console.error(errorMessage); | ||
setFailureBanner(errorMessage); | ||
setJsonResult(null); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Header /> | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
gap: "2rem", | ||
}} | ||
> | ||
<Box sx={{ width: "40%" }}> | ||
<UserInput | ||
textData={textData} | ||
setTextData={setTextData} | ||
configData={configData} | ||
setConfigData={setConfigData} | ||
onTextDataSubmit={onTextDataSubmit} | ||
setFailureBanner={setFailureBanner} | ||
jsonResult={jsonResult} | ||
/> | ||
</Box> | ||
<Box sx={{ width: "60%" }}> | ||
<UserOutput | ||
jsonResult={jsonResult} | ||
configData={configData} | ||
setConfigData={setConfigData} | ||
svgResult={svgResult} | ||
setSvgResult={setSvgResult} | ||
/> | ||
</Box> | ||
</Box> | ||
</> | ||
); | ||
} |
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,28 @@ | ||
import React from "react"; | ||
import { Button } from "@mui/material"; | ||
|
||
type DownloadJSONButtonPropTypes = { | ||
jsonResult: string; | ||
sx: object; | ||
}; | ||
export default function DownloadJSONButton(props: DownloadJSONButtonPropTypes) { | ||
const file = new Blob([JSON.stringify(props.jsonResult, null, 2)], { | ||
type: "application/JSON", | ||
}); | ||
|
||
return ( | ||
<Button | ||
variant="contained" | ||
color="primary" | ||
data-testid="download-json-btn" | ||
disabled={!props.jsonResult} | ||
download="memory_model.json" | ||
target="_blank" | ||
rel="noreferrer" | ||
href={window.URL.createObjectURL(file)} | ||
sx={{ ...props.sx, textTransform: "none" }} | ||
> | ||
Download This JSON | ||
</Button> | ||
); | ||
} |
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,25 @@ | ||
import React from "react"; | ||
import { Button } from "@mui/material"; | ||
|
||
type DownloadSVGButtonPropTypes = { | ||
svgResult: string; | ||
}; | ||
export default function DownloadSVGButton(props: DownloadSVGButtonPropTypes) { | ||
const file = new global.Blob([props.svgResult], { type: "image/svg+xml" }); | ||
|
||
return ( | ||
<Button | ||
variant="contained" | ||
color="primary" | ||
data-testid="download-svg-btn" | ||
disabled={!props.svgResult} | ||
href={URL.createObjectURL(file)} | ||
target="_blank" | ||
rel="noreferrer" | ||
download="output.svg" | ||
sx={{ textTransform: "none" }} | ||
> | ||
Download This SVG | ||
</Button> | ||
); | ||
} |
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,78 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { | ||
Accordion, | ||
AccordionDetails, | ||
AccordionSummary, | ||
Button, | ||
Card, | ||
CardContent, | ||
Grid, | ||
} from "@mui/material"; | ||
import { ExpandMore } from "@mui/icons-material"; | ||
|
||
import { SAMPLES } from "./sample"; | ||
|
||
type MemoryModelsSamplePropTypes = { | ||
setTextData: React.Dispatch<React.SetStateAction<string>>; | ||
setConfigData: React.Dispatch<React.SetStateAction<object>>; | ||
onTextDataSubmit: () => void; | ||
}; | ||
|
||
export default function MemoryModelsSample(props: MemoryModelsSamplePropTypes) { | ||
const [clickedBtnIndex, setClickedBtnIndex] = useState<Number>(null); | ||
|
||
useEffect(() => { | ||
if (clickedBtnIndex !== null) { | ||
props.onTextDataSubmit(); | ||
} | ||
}, [clickedBtnIndex]); | ||
|
||
const handleButtonClick = (index: Number, sample: Object) => { | ||
// Note: the following conversion to a string is inefficient, as the data is later parsed | ||
// back into JSON for rendering. | ||
// TODO: fix this. | ||
props.setTextData(JSON.stringify(sample["data"], null, 4)); | ||
props.setConfigData((prevConfigData) => ({ | ||
...prevConfigData, | ||
...sample["config"], | ||
})); | ||
setClickedBtnIndex(index); | ||
}; | ||
|
||
return ( | ||
<Accordion> | ||
<AccordionSummary | ||
expandIcon={<ExpandMore />} | ||
data-testid="sample-inputs-accordion" | ||
> | ||
Sample Inputs | ||
</AccordionSummary> | ||
<AccordionDetails> | ||
<Card color="neutral"> | ||
<CardContent> | ||
<Grid container spacing={2}> | ||
{SAMPLES.map((sample, index) => ( | ||
<Grid item xs={12} sm={6} md={4} key={index}> | ||
<Button | ||
variant="contained" | ||
onClick={() => | ||
handleButtonClick(index, sample) | ||
} | ||
color={ | ||
index === clickedBtnIndex | ||
? "success" | ||
: "primary" | ||
} | ||
sx={{ textTransform: "capitalize" }} | ||
> | ||
{sample["name"]} | ||
</Button> | ||
</Grid> | ||
))} | ||
</Grid> | ||
</CardContent> | ||
</Card> | ||
</AccordionDetails> | ||
</Accordion> | ||
); | ||
} |
Oops, something went wrong.