Skip to content

Commit

Permalink
Implemented dynamic md files on the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Thistleman committed Aug 8, 2023
1 parent 23ca082 commit 681d12e
Show file tree
Hide file tree
Showing 12 changed files with 1,540 additions and 960 deletions.
1,495 changes: 1,472 additions & 23 deletions frontend/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"react-dom": "^18.2.0",
"react-drag-drop-files": "^2.3.8",
"react-frame-component": "^5.2.3",
"react-markdown": "^8.0.7",
"react-modal": "^3.16.1",
"react-router-dom": "^6.4.2",
"react-scripts": "^5.0.1",
Expand Down
54 changes: 48 additions & 6 deletions frontend/src/components/Analysis/Analysis.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box, Grid, Button, Tab, Tabs, Typography, CircularProgress } from "@mui/material";
import { Container } from "@mui/system";
import { useState } from "react";
import { useState, useEffect } from "react";
import TabPanel from "../GlobalComponents/TabPanel/TabPanel";
import Data from "./Data/Data";
import { CommentProvider } from "./Discussion/CommentContext";
Expand All @@ -17,6 +17,7 @@ import BlurryPage from "../GlobalComponents/BlurryPage/blurryPage";
import { AnalysisService } from "../../services/analysis_service";
import { faker } from "@faker-js/faker";
import { useNavigate } from "react-router-dom";
import ReactMarkdown from "react-markdown";

export default function Analysis() {
const navigate = useNavigate();
Expand All @@ -29,6 +30,48 @@ export default function Analysis() {

const [isLoading, error, card, analysis_id] = AnalysisService.useGetCardDetails();

// Set the md descriptions

const [datasetDescription, setDatasetDescription] = useState("");
const [longDescription, setLongDescription] = useState("");
const [shortDescription, setShortDescription] = useState("");
const [rulesetDescription, setRulesetDescription] = useState("");

useEffect(() => {
import(`../../public/assets/${analysis_id}/dataset.md`)
.then(res => {
fetch(res.default)
.then(res => res.text())
.then(res => setDatasetDescription(res))
.catch(err => console.log(err));
})
.catch(err => console.log(err));
import(`../../public/assets/${analysis_id}/longdesc.md`)
.then(res => {
fetch(res.default)
.then(res => res.text())
.then(res => setLongDescription(res))
.catch(err => console.log(err));
})
.catch(err => console.log(err));
import(`../../public/assets/${analysis_id}/shortdesc.md`)
.then(res => {
fetch(res.default)
.then(res => res.text())
.then(res => setShortDescription(res))
.catch(err => console.log(err));
})
.catch(err => console.log(err));
import(`../../public/assets/${analysis_id}/ruleset.md`)
.then(res => {
fetch(res.default)
.then(res => res.text())
.then(res => setRulesetDescription(res))
.catch(err => console.log(err));
})
.catch(err => console.log(err));
});

const closeModal = () => {
setIsOpen(false);
}
Expand Down Expand Up @@ -70,7 +113,7 @@ export default function Analysis() {
</Box>
<Box sx={{ flexGrow: 1, marginTop: 2, marginLeft: 2 }}>
<Typography color={"white"} variant="body2" gutterBottom>
{card.short_description}
<ReactMarkdown source={shortDescription} />
</Typography>
</Box>
</Box>
Expand Down Expand Up @@ -117,7 +160,7 @@ export default function Analysis() {
<TabPanel value={value} index={0}>
<Overview
title={"Overview of " + card.analysis_name}
description={card.description}
description={longDescription}
/>
</TabPanel>

Expand All @@ -127,8 +170,7 @@ export default function Analysis() {
<BlurryPage />
:
<Data
data_description={card.dataset_description}
downloadable_link={card.evaluation_script}
data_description={datasetDescription}
/>
}
</TabPanel>
Expand All @@ -142,7 +184,7 @@ export default function Analysis() {
<TabPanel value={value} index={3}>
<Rules
title={card.analysis_name}
description={card.ruleset}
description={rulesetDescription}
/>
</TabPanel>

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Analysis/Data/Data.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Box, Button, Grid, Typography } from "@mui/material";
import { DashboardService } from "../../../services/dashboard_service";
import PropTypes from 'prop-types';
import ReactMarkdown from "react-markdown";

export default function Data(props) {

Expand All @@ -21,7 +22,7 @@ export default function Data(props) {
Dataset Description
</Typography>
<Typography variant="body2">
{props.data_description}
<ReactMarkdown source={props.data_description} />
</Typography>
</Box>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Grid, Typography } from '@mui/material';
import { Box, Container } from '@mui/system';
import PropTypes from 'prop-types';
import { DashboardService } from '../../../services/dashboard_service';
import { ReactMarkdown } from 'react-markdown/lib/react-markdown';

export default function Overview(props) {

Expand All @@ -12,7 +13,7 @@ export default function Overview(props) {
{props.title}
</Typography>
<Typography variant='body2'>
{props.description}
<ReactMarkdown source={props.description} />
</Typography>
</Box>
<Grid container spacing={2} sx={{marginTop: 6}}>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Analysis/Rules/Rules.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Typography } from '@mui/material';
import { Box, Container } from '@mui/system';
import PropTypes from 'prop-types';
import ReactMarkdown from 'react-markdown';

export default function Rules(props) {

Expand All @@ -11,7 +12,7 @@ export default function Rules(props) {
{"Rules for " + props.title}
</Typography>
<Typography variant='body2' sx={{marginTop: 2}}>
{props.description}
<ReactMarkdown source={props.description} />
</Typography>
</Box>
</Container >
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@
# Create a logger
logger = logging.getLogger(__name__)

is_s3_emulation = True
def is_local():
"""
Checks if the application is running locally or in an Amazon ECS environment.
Returns:
bool: True if the application is running locally, False otherwise.
"""
return 'AWS_EXECUTION_ENV' not in os.environ and 'ECS_CONTAINER_METADATA_URI' not in os.environ and 'ECS_CONTAINER_METADATA_URI_V4' not in os.environ

is_s3_emulation = is_local()

def pull_from_s3(s3_file_path):
if s3_file_path.startswith('/'):
Expand Down
2 changes: 1 addition & 1 deletion workers/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# sleep 5
# done

python submission_worker_local.py
python submission_worker.py
Loading

0 comments on commit 681d12e

Please sign in to comment.