@@ -3,6 +3,7 @@ import Grid from "@material-ui/core/Grid";
33import IconButton from "@material-ui/core/IconButton" ;
44import Tooltip from "@material-ui/core/Tooltip" ;
55import AddToQueueIcon from "@material-ui/icons/AddToQueue" ;
6+ import FileCopyIcon from '@material-ui/icons/FileCopy' ;
67import EditIcon from "@material-ui/icons/Edit" ;
78import LockIcon from "@material-ui/icons/Lock" ;
89import PublicIcon from "@material-ui/icons/Public" ;
@@ -12,6 +13,7 @@ import React from "react";
1213import ContextMain from "./ContextMain" ;
1314import ErrorDialog from "./ErrorDialog" ;
1415import ModelEditForm from "./ModelEditForm" ;
16+ import ModelAddForm from "./ModelAddForm" ;
1517import Theme from "./theme" ;
1618import {
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 ) ;
0 commit comments