Skip to content

Commit 881852f

Browse files
Merge pull request HumanBrainProject#5 from appukuttan-shailesh/master
implement test and model duplicate feature
2 parents 7582dec + 90cf39d commit 881852f

File tree

7 files changed

+182
-48
lines changed

7 files changed

+182
-48
lines changed

apps/model_catalog/src/ModelAddForm.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,28 @@ export default class ModelAddForm extends React.Component {
5555
errorAddModel: null,
5656
isAliasNotUnique: true,
5757
aliasLoading: false,
58-
name: "",
59-
alias: "",
60-
author: [],
61-
owner: [],
62-
private: false,
63-
project_id: "",
64-
description: "",
65-
species: "",
66-
brain_region: "",
67-
cell_type: "",
68-
model_scope: "",
69-
abstraction_level: "",
70-
organization: "",
58+
name: this.props.duplicateData.name || "",
59+
alias: this.props.duplicateData.alias || "",
60+
author: this.props.duplicateData.author || [],
61+
owner: this.props.duplicateData.owner || [],
62+
private: this.props.duplicateData.private || false,
63+
project_id: this.props.duplicateData.project_id || "",
64+
description: this.props.duplicateData.description || "",
65+
species: this.props.duplicateData.species || "",
66+
brain_region: this.props.duplicateData.brain_region || "",
67+
cell_type: this.props.duplicateData.cell_type || "",
68+
model_scope: this.props.duplicateData.model_scope || "",
69+
abstraction_level: this.props.duplicateData.abstraction_level || "",
70+
organization: this.props.duplicateData.organization || "",
7171
instances: [
7272
{
73-
version: "",
74-
description: "",
75-
parameters: "",
76-
morphology: "",
77-
source: "",
78-
code_format: "",
79-
license: "",
73+
version: this.props.duplicateData.instances[0].version || "",
74+
description: this.props.duplicateData.instances[0].description || "",
75+
parameters: this.props.duplicateData.instances[0].parameters || "",
76+
morphology: this.props.duplicateData.instances[0].morphology || "",
77+
source: this.props.duplicateData.instances[0].source || "",
78+
code_format: this.props.duplicateData.instances[0].code_format || "",
79+
license: this.props.duplicateData.instances[0].license || "",
8080
},
8181
],
8282
auth: authContext,

apps/model_catalog/src/ModelDetail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ class ModelDetail extends React.Component {
416416
compareFlag={this.state.compareFlag}
417417
addModelCompare={this.addModelCompare}
418418
removeModelCompare={this.removeModelCompare}
419-
></ModelDetailHeader>
419+
/>
420420
</Grid>
421421
<Grid item xs={12}>
422422
<AppBar position="static">

apps/model_catalog/src/ModelDetailHeader.js

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Grid from "@material-ui/core/Grid";
33
import IconButton from "@material-ui/core/IconButton";
44
import Tooltip from "@material-ui/core/Tooltip";
55
import AddToQueueIcon from "@material-ui/icons/AddToQueue";
6+
import FileCopyIcon from '@material-ui/icons/FileCopy';
67
import EditIcon from "@material-ui/icons/Edit";
78
import LockIcon from "@material-ui/icons/Lock";
89
import PublicIcon from "@material-ui/icons/Public";
@@ -12,6 +13,7 @@ import React from "react";
1213
import ContextMain from "./ContextMain";
1314
import ErrorDialog from "./ErrorDialog";
1415
import ModelEditForm from "./ModelEditForm";
16+
import ModelAddForm from "./ModelAddForm";
1517
import Theme from "./theme";
1618
import {
1719
copyToClipboard,
@@ -115,19 +117,26 @@ class ModelDetailHeader extends React.Component {
115117

116118
this.state = {
117119
openEditForm: false,
120+
openDuplicateForm: false,
118121
errorEditModel: null,
122+
errorDuplicateModel: null,
119123
};
120-
this.handleEditModelFormClose =
121-
this.handleEditModelFormClose.bind(this);
124+
this.handleEditModelFormClose = this.handleEditModelFormClose.bind(this);
125+
this.handleDuplicateModelFormClose = this.handleDuplicateModelFormClose.bind(this);
122126
this.handleEditClick = this.handleEditClick.bind(this);
123-
this.handleErrorEditDialogClose =
124-
this.handleErrorEditDialogClose.bind(this);
127+
this.handleDuplicateClick = this.handleDuplicateClick.bind(this);
128+
this.handleErrorEditDialogClose = this.handleErrorEditDialogClose.bind(this);
129+
this.handleErrorDuplicateDialogClose = this.handleErrorDuplicateDialogClose.bind(this);
125130
}
126131

127132
handleErrorEditDialogClose() {
128133
this.setState({ errorEditModel: null });
129134
}
130135

136+
handleErrorDuplicateDialogClose() {
137+
this.setState({ errorDuplicateModel: null });
138+
}
139+
131140
handleEditModelFormClose(model) {
132141
console.log("close edit");
133142

@@ -143,12 +152,33 @@ class ModelDetailHeader extends React.Component {
143152
}
144153
}
145154

155+
handleDuplicateModelFormClose(model) {
156+
console.log("close duplicate");
157+
158+
this.setState({ openDuplicateForm: false });
159+
if (model) {
160+
this.props.updateCurrentModelData(model);
161+
showNotification(
162+
this.props.enqueueSnackbar,
163+
this.props.closeSnackbar,
164+
"Model duplicated!",
165+
"success"
166+
);
167+
}
168+
}
169+
146170
handleEditClick() {
147171
this.setState({
148172
openEditForm: true,
149173
});
150174
}
151175

176+
handleDuplicateClick() {
177+
this.setState({
178+
openDuplicateForm: true,
179+
});
180+
}
181+
152182
render() {
153183
let errorMessage = "";
154184
if (this.state.errorEditModel) {
@@ -163,6 +193,18 @@ class ModelDetailHeader extends React.Component {
163193
/>
164194
);
165195
}
196+
if (this.state.errorDuplicateModel) {
197+
errorMessage = (
198+
<ErrorDialog
199+
open={Boolean(this.state.errorDuplicateModel)}
200+
handleErrorDialogClose={this.handleErrorDuplicateDialogClose}
201+
error={
202+
this.state.errorDuplicateModel.message ||
203+
this.state.errorDuplicateModel
204+
}
205+
/>
206+
);
207+
}
166208

167209
let editForm = "";
168210
if (this.state.openEditForm) {
@@ -175,6 +217,17 @@ class ModelDetailHeader extends React.Component {
175217
);
176218
}
177219

220+
let duplicateForm = "";
221+
if (this.state.openDuplicateForm) {
222+
duplicateForm = (
223+
<ModelAddForm
224+
open={this.state.openDuplicateForm}
225+
onClose={this.handleDuplicateModelFormClose}
226+
duplicateData={this.props.modelData}
227+
/>
228+
);
229+
}
230+
178231
return (
179232
<React.Fragment>
180233
<Grid item>
@@ -198,6 +251,18 @@ class ModelDetailHeader extends React.Component {
198251
canEdit={this.props.canEdit}
199252
handleEditClick={this.handleEditClick}
200253
/>
254+
<Tooltip placement="top" title="Duplicate Model">
255+
<IconButton
256+
aria-label="duplicate model"
257+
onClick={() => this.handleDuplicateClick()}
258+
style={{
259+
backgroundColor: Theme.buttonPrimary,
260+
marginLeft: 10,
261+
}}
262+
>
263+
<FileCopyIcon />
264+
</IconButton>
265+
</Tooltip>
201266
<CompareIcon
202267
compareFlag={this.props.compareFlag}
203268
addModelCompare={this.props.addModelCompare}
@@ -275,6 +340,7 @@ class ModelDetailHeader extends React.Component {
275340
{/* optional image goes here */}
276341
{/* </Grid> */}
277342
<div>{editForm}</div>
343+
<div>{duplicateForm}</div>
278344
<div>{errorMessage}</div>
279345
</React.Fragment>
280346
);

apps/model_catalog/src/TestAddForm.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,26 @@ export default class TestAddForm extends React.Component {
5353
errorAddTest: null,
5454
isAliasNotUnique: true,
5555
aliasLoading: false,
56-
name: "",
57-
alias: "",
58-
author: [],
59-
description: "",
60-
data_location: [],
61-
data_type: "",
62-
species: "",
63-
brain_region: "",
64-
cell_type: "",
65-
test_type: "",
66-
score_type: "",
67-
recording_modality: "",
68-
implementation_status: "",
56+
name: this.props.duplicateData.name || "",
57+
alias: this.props.duplicateData.alias || "",
58+
author: this.props.duplicateData.author || [],
59+
description: this.props.duplicateData.description || "",
60+
data_location: this.props.duplicateData.data_location || [],
61+
data_type: this.props.duplicateData.data_type || "",
62+
species: this.props.duplicateData.species || "",
63+
brain_region: this.props.duplicateData.brain_region || "",
64+
cell_type: this.props.duplicateData.cell_type || "",
65+
test_type: this.props.duplicateData.test_type || "",
66+
score_type: this.props.duplicateData.score_type || "",
67+
recording_modality: this.props.duplicateData.recording_modality || "",
68+
implementation_status: this.props.duplicateData.implementation_status || "",
6969
instances: [
7070
{
71-
version: "",
72-
repository: "",
73-
path: "",
74-
description: "",
75-
parameters: "",
71+
version: this.props.duplicateData.instances[0].version || "",
72+
repository: this.props.duplicateData.instances[0].repository || "",
73+
path: this.props.duplicateData.instances[0].path || "",
74+
description: this.props.duplicateData.instances[0].description || "",
75+
parameters: this.props.duplicateData.instances[0].parameters || "",
7676
},
7777
],
7878
auth: authContext,
@@ -90,7 +90,6 @@ export default class TestAddForm extends React.Component {
9090
}
9191

9292
handleCancel() {
93-
console.log("Hello");
9493
this.props.onClose();
9594
}
9695

@@ -353,7 +352,7 @@ export default class TestAddForm extends React.Component {
353352
<TextField
354353
name="data_location"
355354
label="Data Location (URL)"
356-
defaultValue=""
355+
defaultValue={this.state.data_location}
357356
onBlur={this.handleFieldChange}
358357
variant="outlined"
359358
fullWidth={true}

apps/model_catalog/src/TestDetail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ class TestDetail extends React.Component {
388388
compareFlag={this.state.compareFlag}
389389
addTestCompare={this.addTestCompare}
390390
removeTestCompare={this.removeTestCompare}
391-
></TestDetailHeader>
391+
/>
392392
</Grid>
393393
<Grid item xs={12}>
394394
<AppBar position="static">

0 commit comments

Comments
 (0)