@@ -6,6 +6,7 @@ import { styled } from "@material-ui/core/styles"
66import AssignmentReturnedIcon from "@material-ui/icons/AssignmentReturned"
77import CreateNewFolderIcon from "@material-ui/icons/CreateNewFolder"
88import TextFieldsIcon from "@material-ui/icons/TextFields"
9+ import DescriptionIcon from "@material-ui/icons/Description"
910import PetsIcon from "@material-ui/icons/Pets"
1011import * as colors from "@material-ui/core/colors"
1112import PasteUrlsDialog from "../PasteUrlsDialog"
@@ -16,10 +17,19 @@ import classnames from "classnames"
1617import { setIn } from "seamless-immutable"
1718import useEventCallback from "use-event-callback"
1819import ImportFromGoogleDriveDialog from "../ImportFromGoogleDriveDialog"
20+ import ImportUDTFileDialog from "../ImportUDTFileDialog"
1921import ImportToyDataset from "../ImportToyDatasetDialog"
2022import ImportFromYoutubeUrls from "../ImportFromYoutubeUrls"
2123import { FaGoogleDrive , FaYoutube } from "react-icons/fa"
2224
25+ const extendWithNull = ( ar , len ) => {
26+ ar = [ ...ar ]
27+ while ( ar . length < len ) {
28+ ar . push ( null )
29+ }
30+ return ar
31+ }
32+
2333const ButtonBase = styled ( MuiButton ) ( {
2434 width : 240 ,
2535 height : 140 ,
@@ -132,13 +142,26 @@ export default ({ oha, onChangeOHA, isDesktop }) => {
132142 }
133143 }
134144 const closeDialog = ( ) => changeDialog ( null )
135- const onAddSamples = useEventCallback ( ( samples ) => {
136- onChangeOHA (
137- setIn ( oha , [ "taskData" ] , ( oha . taskData || [ ] ) . concat ( samples ) ) ,
138- true
139- )
140- closeDialog ( )
141- } )
145+ const onAddSamples = useEventCallback (
146+ ( appendedTaskData , appendedTaskOutput ) => {
147+ let newOHA = setIn (
148+ oha ,
149+ [ "taskData" ] ,
150+ ( oha . taskData || [ ] ) . concat ( appendedTaskData )
151+ )
152+ if ( appendedTaskOutput ) {
153+ newOHA = setIn (
154+ newOHA ,
155+ [ "taskOutput" ] ,
156+ extendWithNull ( oha . taskOutput || [ ] , oha . taskData . length ) . concat (
157+ appendedTaskOutput
158+ )
159+ )
160+ }
161+ onChangeOHA ( newOHA , true )
162+ closeDialog ( )
163+ }
164+ )
142165 return (
143166 < SelectDialogContext . Provider value = { { onChangeDialog } } >
144167 < div >
@@ -182,6 +205,13 @@ export default ({ oha, onChangeOHA, isDesktop }) => {
182205 >
183206 Import from Youtube URLs
184207 </ Button >
208+ < Button
209+ isDesktop = { isDesktop }
210+ dialog = "import-csv-json"
211+ Icon = { DescriptionIcon }
212+ >
213+ Import from CSV / JSON
214+ </ Button >
185215 < ImportTextSnippetsDialog
186216 open = { selectedDialog === "import-text-snippets" }
187217 onClose = { closeDialog }
@@ -207,6 +237,11 @@ export default ({ oha, onChangeOHA, isDesktop }) => {
207237 onClose = { closeDialog }
208238 onAddSamples = { onAddSamples }
209239 />
240+ < ImportUDTFileDialog
241+ open = { selectedDialog === "import-csv-json" }
242+ onClose = { closeDialog }
243+ onAddSamples = { onAddSamples }
244+ />
210245 </ div >
211246 </ SelectDialogContext . Provider >
212247 )
0 commit comments