Skip to content

Commit 23e9d21

Browse files
committed
feat: add download metadata button to python and matlab local tabs
1 parent ebc1195 commit 23e9d21

File tree

2 files changed

+54
-21
lines changed

2 files changed

+54
-21
lines changed

src/components/DatasetDetailPage/LoadDatasetTabs.tsx

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import CloudDownloadIcon from "@mui/icons-material/CloudDownload";
12
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
23
import {
34
Tabs,
@@ -7,6 +8,7 @@ import {
78
IconButton,
89
Tooltip,
910
Link,
11+
Button,
1012
} from "@mui/material";
1113
import { Colors } from "design/theme";
1214
import React from "react";
@@ -34,6 +36,7 @@ interface LoadDatasetTabsProps {
3436
serverUrl: string;
3537
datasetDocument?: any;
3638
onekey: string;
39+
handleDownloadDataset: () => void;
3740
}
3841

3942
const flashcardStyles = {
@@ -76,6 +79,7 @@ const LoadDatasetTabs: React.FC<LoadDatasetTabsProps> = ({
7679
serverUrl,
7780
datasetDocument,
7881
onekey,
82+
handleDownloadDataset,
7983
}) => {
8084
const [tabIndex, setTabIndex] = useState(0);
8185
const handleTabChange = (event: React.SyntheticEvent, newValue: number) => {
@@ -201,8 +205,8 @@ const LoadDatasetTabs: React.FC<LoadDatasetTabsProps> = ({
201205
>
202206
<Tab label="Python (REST API)" />
203207
<Tab label="MATLAB (REST API)" />
204-
<Tab label="MATLAB/Octave (Local)" />
205208
<Tab label="Python (Local)" />
209+
<Tab label="MATLAB/Octave (Local)" />
206210
<Tab label="C++" />
207211
<Tab label="Node.js" />
208212
</Tabs>
@@ -240,10 +244,6 @@ jd.jdlink(links, {'regex': 'anat/sub-0[12]_.*\.nii'})`}
240244
Load by URL with REST-API in MATLAB
241245
</Typography>
242246
<Typography>Install:</Typography>
243-
{/* <CopyableCodeBlock
244-
code={`Download and addpath to JSONLab`}
245-
language="text"
246-
/> */}
247247
<Typography>
248248
Download and addpath to{" "}
249249
<Link
@@ -271,40 +271,73 @@ niidata = jdlink(links, 'regex', 'anat/sub-0[12]_.*\.nii');`}
271271
</Box>
272272
</TabPanel>
273273

274-
{/* FLASHCARD 3: MATLAB/Octave */}
274+
{/* FLASHCARD 3: Python Local */}
275275
<TabPanel value={tabIndex} index={2}>
276276
<Box style={flashcardStyles.flashcard}>
277277
<Typography variant="h6" style={flashcardStyles.flashcardTitle}>
278-
Use in MATLAB/Octave
278+
Use in Python
279279
</Typography>
280+
281+
<Typography sx={{ marginBottom: 1 }}>Download dataset</Typography>
282+
<Button
283+
variant="contained"
284+
startIcon={<CloudDownloadIcon />}
285+
onClick={handleDownloadDataset}
286+
sx={{
287+
backgroundColor: Colors.purple,
288+
color: Colors.lightGray,
289+
mb: 2,
290+
"&:hover": {
291+
backgroundColor: Colors.secondaryPurple,
292+
},
293+
}}
294+
>
295+
Download Metadata
296+
</Button>
280297
<Typography>Load:</Typography>
281298
<CopyableCodeBlock
282-
// code={`data = loadjd('${docname}.json');`}
283-
code={`data = loadjd('${pagename}.json');`}
284-
language="matlab"
299+
code={`import jdata as jd
300+
data = jd.load('${pagename}.json')`}
301+
language="python"
285302
/>
286303
<Typography>Read value:</Typography>
287-
<CopyableCodeBlock
288-
code={`data.(encodevarname('${onekey}'))`}
289-
language="matlab"
290-
/>
304+
<CopyableCodeBlock code={`data["${onekey}"]`} language="python" />
291305
</Box>
292306
</TabPanel>
293307

294-
{/* FLASHCARD 4: Python Local */}
308+
{/* FLASHCARD 4: MATLAB/Octave */}
295309
<TabPanel value={tabIndex} index={3}>
296310
<Box style={flashcardStyles.flashcard}>
297311
<Typography variant="h6" style={flashcardStyles.flashcardTitle}>
298-
Use in Python
312+
Use in MATLAB/Octave
299313
</Typography>
314+
<Typography sx={{ marginBottom: 1 }}>Download dataset</Typography>
315+
<Button
316+
variant="contained"
317+
startIcon={<CloudDownloadIcon />}
318+
onClick={handleDownloadDataset}
319+
sx={{
320+
backgroundColor: Colors.purple,
321+
color: Colors.lightGray,
322+
mb: 2,
323+
"&:hover": {
324+
backgroundColor: Colors.secondaryPurple,
325+
},
326+
}}
327+
>
328+
Download Metadata
329+
</Button>
300330
<Typography>Load:</Typography>
301331
<CopyableCodeBlock
302-
code={`import jdata as jd
303-
data = jd.load('${pagename}.json')`}
304-
language="python"
332+
// code={`data = loadjd('${docname}.json');`}
333+
code={`data = loadjd('${pagename}.json');`}
334+
language="matlab"
305335
/>
306336
<Typography>Read value:</Typography>
307-
<CopyableCodeBlock code={`data["${onekey}"]`} language="python" />
337+
<CopyableCodeBlock
338+
code={`data.(encodevarname('${onekey}'))`}
339+
language="matlab"
340+
/>
308341
</Box>
309342
</TabPanel>
310343

src/pages/DatasetDetailPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,8 +1339,8 @@ const DatasetDetailPage: React.FC = () => {
13391339
dbname={dbName || ""}
13401340
serverUrl={"https://neurojson.io:7777/"}
13411341
datasetDocument={datasetDocument}
1342-
// onekey={"dataset_description.json"}
13431342
onekey={onekey}
1343+
handleDownloadDataset={handleDownloadDataset}
13441344
/>
13451345

13461346
{/* Global spinner while loading (before modal mounts) */}

0 commit comments

Comments
 (0)