@@ -5,9 +5,17 @@ import useActiveDatasetManager from "../../hooks/use-active-dataset-manager"
55import isEmpty from "lodash/isEmpty"
66import datasetManagerCognito from "udt-dataset-managers/dist/CognitoDatasetManager"
77import useAuth from "../../utils/auth-handlers/use-auth"
8- import { Grid , TextField } from "@material-ui/core"
98import { useTranslation } from "react-i18next"
10- const orangeText = { color : "orange" }
9+ import { TextField , Grid , IconButton } from "@material-ui/core"
10+ import WarningHeader from "./warning-header"
11+ import initConfigExport from "./init-config-export"
12+ import SettingDialog from "./interface-setting-export.js"
13+ import createAssets from "./create-assets"
14+ import { setIn } from "seamless-immutable"
15+ import {
16+ Settings as SettingsIcon ,
17+ Storage as StorageIcon ,
18+ } from "@material-ui/icons/"
1119
1220const customStyles = {
1321 headCells : {
@@ -62,6 +70,7 @@ export default ({ open, onClose }) => {
6270 )
6371 }
6472 const [ refreshInterface , setRefreshInterface ] = useState ( false )
73+ const [ configExport , setConfigExport ] = useState ( initConfigExport )
6574
6675 const getCurrentDataset = async ( ) => {
6776 if ( currentDataset ) return currentDataset
@@ -73,6 +82,10 @@ export default ({ open, onClose }) => {
7382 const getProjectName = ( ) => {
7483 if ( ! currentDataset ) return
7584 if ( ! currentDataset . name ) return
85+ if ( currentDataset . name === "New undefined Dataset" ) {
86+ setNameProjectToCreate ( "" )
87+ return ""
88+ }
7689 setNameProjectToCreate ( currentDataset . name )
7790 return currentDataset . name
7891 }
@@ -135,14 +148,30 @@ export default ({ open, onClose }) => {
135148 const handleCreateProject = async ( ) => {
136149 if ( ! currentDataset ) return
137150 var dataset = currentDataset
138- dataset = dataset . setIn ( [ "name" ] , nameProjectToCreate )
151+
152+ dataset = await dataset . setIn ( [ "name" ] , nameProjectToCreate )
153+
139154 if ( nameProjectExist ) await dm . removeSamplesFolder ( nameProjectToCreate )
155+ if ( nameProjectExist && configExport . typeAssetExport === "withProxy" )
156+ await dm . removeAssetsFolder ( nameProjectToCreate )
157+ if ( configExport . typeAssetExport === "withProxy" ) {
158+ dataset = await renameAllSamples ( dataset )
159+ await createAssets ( dataset , configExport , dm )
160+ }
140161 await dm . setDataset ( dataset )
141162 await activeDatasetManager . setDataset ( dataset )
142- await getProjects ( )
143163 onClose ( )
144164 }
145165
166+ const renameAllSamples = async ( dataset ) => {
167+ var samples = await Promise . all (
168+ await dataset . samples . map ( async ( sample , index , samples ) => {
169+ return await dm . addNamesToSample ( sample , index , samples )
170+ } )
171+ )
172+ return ( dataset = await setIn ( dataset , [ "samples" ] , samples ) )
173+ }
174+
146175 return (
147176 < SimpleDialog
148177 title = { t ( "export-project" ) }
@@ -158,13 +187,12 @@ export default ({ open, onClose }) => {
158187 ] }
159188 >
160189 {
161- < Grid container spacing = { 0 } >
190+ < Grid container spacing = { 1 } >
162191 < Grid container item xs = { 12 } spacing = { 0 } justify = "center" >
163- { nameProjectExist ? (
164- < p style = { orangeText } > { t ( "warning-project-exist" ) } </ p >
165- ) : (
166- < p > </ p >
167- ) }
192+ < WarningHeader
193+ nameProjectToCreate = { nameProjectToCreate }
194+ nameProjectExist = { nameProjectExist }
195+ />
168196 </ Grid >
169197 < Grid container item xs = { 12 } spacing = { 0 } justify = "center" >
170198 < TextField
@@ -176,21 +204,42 @@ export default ({ open, onClose }) => {
176204 } }
177205 value = { nameProjectToCreate }
178206 />
207+ < IconButton
208+ onClick = { ( ) => {
209+ setConfigExport ( {
210+ ...configExport ,
211+ contentDialogBoxIsSetting : ! configExport . contentDialogBoxIsSetting ,
212+ } )
213+ } }
214+ >
215+ { configExport . contentDialogBoxIsSetting ? (
216+ < StorageIcon id = "StorageIcon" />
217+ ) : (
218+ < SettingsIcon id = "SettingIcon" />
219+ ) }
220+ </ IconButton >
179221 </ Grid >
180222 < Grid container item xs = { 12 } spacing = { 0 } justify = "center" >
181- { ! isEmpty ( projects ) && (
182- < DataTable
183- expandableRows
184- expandableRowsComponent = { < ExpandedRow /> }
185- dense
186- noHeader
187- noTableHead
188- columns = { columns }
189- selectableRowSelected = { ( row ) => row . isSelected }
190- data = { projects }
191- pagination = { projects . length > 10 }
192- paginationPerPage = { 10 }
193- paginationRowsPerPageOptions = { [ 10 , 20 , 25 , 50 , 100 , 200 ] }
223+ { ! configExport . contentDialogBoxIsSetting ? (
224+ ! isEmpty ( projects ) && (
225+ < DataTable
226+ expandableRows
227+ expandableRowsComponent = { < ExpandedRow /> }
228+ dense
229+ noHeader
230+ noTableHead
231+ columns = { columns }
232+ selectableRowSelected = { ( row ) => row . isSelected }
233+ data = { projects }
234+ pagination = { projects . length > 10 }
235+ paginationPerPage = { 10 }
236+ paginationRowsPerPageOptions = { [ 10 , 20 , 25 , 50 , 100 , 200 ] }
237+ />
238+ )
239+ ) : (
240+ < SettingDialog
241+ configExport = { configExport }
242+ setConfigExport = { setConfigExport }
194243 />
195244 ) }
196245 </ Grid >
0 commit comments