Skip to content

Commit 72b24d5

Browse files
committed
improve dataset selection
1 parent 940b517 commit 72b24d5

File tree

3 files changed

+69
-30
lines changed

3 files changed

+69
-30
lines changed

frontend/src/components/datasets/DatasetCard.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Typography from "@mui/material/Typography";
66
import {Link} from "react-router-dom";
77
import {parseDate} from "../../utils/common";
88
import {CardActionArea, CardHeader, CardMedia, IconButton, Tooltip,} from "@mui/material";
9-
import {Add, Download} from "@mui/icons-material";
9+
import {Download} from "@mui/icons-material";
1010
import {generateThumbnailUrl} from "../../utils/visualization";
1111
import config from "../../app.config";
1212

@@ -126,16 +126,6 @@ export default function DatasetCard(props: DatasetCardProps) {
126126
<Download/>
127127
</IconButton>
128128
</Tooltip> : null}
129-
<Tooltip title="Add">
130-
<IconButton
131-
href={`${config.hostname}/api/v2/datasets/${id}/download`}
132-
color="primary"
133-
aria-label="add"
134-
sx={{mr: 3}}
135-
>
136-
<Add/>
137-
</IconButton>
138-
</Tooltip>
139129
{/*<Tooltip title="Favorite">*/}
140130
{/* <IconButton color="primary" aria-label="favorite" sx={{mr: 3}} disabled>*/}
141131
{/* <Favorite/>*/}

frontend/src/components/datasets/DatasetTableEntry.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@ import {Button} from "@mui/material";
77
import {parseDate} from "../../utils/common";
88
import {generateThumbnailUrl} from "../../utils/visualization";
99
import {MoreHoriz} from "@material-ui/icons";
10+
import {DatasetOut} from "../../openapi/v2";
1011

11-
export function DatsetTableEntry(props) {
12+
type DatasetTableEntryProps = {
13+
iconStyle: {};
14+
selectDataset: any;
15+
dataset: DatasetOut;
16+
};
17+
18+
19+
export default function DatsetTableEntry(props: DatasetTableEntryProps) {
1220
const {iconStyle, selectDataset, dataset} = props;
1321
const [thumbnailUrl, setThumbnailUrl] = useState("");
1422

@@ -43,7 +51,7 @@ export function DatsetTableEntry(props) {
4351
) : (
4452
<Dataset sx={iconStyle}/>
4553
)}
46-
<Button onClick={() => selectDataset(dataset.id)}>
54+
<Button onClick={() => selectDataset(dataset.id, dataset.name)}>
4755
{dataset.name}
4856
</Button>
4957
</TableCell>

frontend/src/components/projects/SelectDatasetsModal.tsx

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import React, {ChangeEvent, useEffect, useState} from "react";
2-
import {Box, Grid, Pagination} from "@mui/material";
2+
import {Box, Chip, Grid, Pagination, Table} from "@mui/material";
33

44
import {useDispatch, useSelector} from "react-redux";
55
import config from "../../app.config";
66
import {RootState} from "../../types/data";
77
import {fetchDatasets} from "../../actions/dataset";
8-
import DatasetCard from "../datasets/DatasetCard";
8+
import DatasetTableEntry from "../datasets/DatasetTableEntry";
9+
import TableHead from "@mui/material/TableHead";
10+
import TableRow from "@mui/material/TableRow";
11+
import TableCell from "@mui/material/TableCell";
12+
import TableBody from "@mui/material/TableBody";
13+
import {theme} from "../../theme";
14+
15+
type SelectedDataset = {
16+
id: string,
17+
label: string
18+
};
919

1020
export const SelectDatasetsModal = (): JSX.Element => {
1121
// Redux connect equivalent
@@ -19,6 +29,7 @@ export const SelectDatasetsModal = (): JSX.Element => {
1929
(state: RootState) => state.dataset.datasets.metadata
2030
);
2131

32+
const [selectedDatasets, setSelectedDatasets] = useState<SelectedDataset[]>([]);
2233
const [currPageNum, setCurrPageNum] = useState<number>(1);
2334
const [limit] = useState<number>(config.defaultDatasetPerPage);
2435

@@ -27,6 +38,16 @@ export const SelectDatasetsModal = (): JSX.Element => {
2738
listDatasets((currPageNum - 1) * limit, limit);
2839
}, [currPageNum, limit]);
2940

41+
const selectDataset = (selectedDatasetId: string | undefined, selectedDatasetName: string | undefined) => {
42+
// add dataset to selection list
43+
if (selectedDatasetId && selectedDatasetName) {
44+
setSelectedDatasets([
45+
...selectedDatasets,
46+
{id: selectedDatasetId, label: selectedDatasetName}
47+
]);
48+
}
49+
};
50+
3051
// pagination
3152
const handlePageChange = (_: ChangeEvent<unknown>, value: number) => {
3253
const newSkip = (value - 1) * limit;
@@ -38,24 +59,44 @@ export const SelectDatasetsModal = (): JSX.Element => {
3859
<Grid container spacing={4}>
3960
<Grid item xs>
4061
<Grid container spacing={2}>
41-
{datasets !== undefined ? (
42-
datasets.map((dataset) => {
62+
{
63+
selectedDatasets?.map((selected) => {
4364
return (
44-
<Grid item key={dataset.id} xs={12} sm={6} md={4} lg={3}>
45-
<DatasetCard
46-
id={dataset.id}
47-
name={dataset.name}
48-
author={`${dataset.creator.first_name} ${dataset.creator.last_name}`}
49-
created={dataset.created}
50-
description={dataset.description}
51-
thumbnailId={dataset.thumbnail_id}
52-
frozen={dataset.frozen}
53-
frozenVersionNum={dataset.frozen_version_num}
54-
download={false}
55-
/>
56-
</Grid>
65+
<Chip label={selected.label} key={selected.id}/>
5766
);
5867
})
68+
}
69+
</Grid>
70+
<Grid container spacing={2}>
71+
{datasets !== undefined ? (<>
72+
<Table sx={{minWidth: 650}} aria-label="simple table">
73+
<TableHead>
74+
<TableRow>
75+
<TableCell>Name</TableCell>
76+
<TableCell align="right">Created</TableCell>
77+
<TableCell align="right">Size</TableCell>
78+
<TableCell align="right">Type</TableCell>
79+
<TableCell align="right"/>
80+
</TableRow>
81+
</TableHead>
82+
<TableBody>
83+
{
84+
datasets.map((dataset) => {
85+
return (
86+
<DatasetTableEntry
87+
iconStyle={{
88+
verticalAlign: "middle",
89+
color: theme.palette.primary.main,
90+
}}
91+
selectDataset={selectDataset}
92+
dataset={dataset}
93+
/>
94+
);
95+
})
96+
}
97+
</TableBody>
98+
</Table>
99+
</>
59100
) : (
60101
<></>
61102
)}

0 commit comments

Comments
 (0)