@@ -3,7 +3,8 @@ import PropTypes from 'prop-types'
3
3
import { Nav , NavItem , NavLink , ModalBody } from 'reactstrap'
4
4
import classnames from 'classnames'
5
5
6
- import { addGlobalFile , addLocalFile } from '../../logic/util/files'
6
+ import { addGlobalFile , addLocalFile ,
7
+ getLocalFile } from '../../logic/util/files'
7
8
8
9
import Modal from '../Modal'
9
10
import Icon from '../Icon'
@@ -21,6 +22,7 @@ export default class FileSelector extends Component {
21
22
this . promiseHandlers = { }
22
23
23
24
this . handleUpload = this . handleUpload . bind ( this )
25
+ this . handleImport = this . handleImport . bind ( this )
24
26
this . select = this . select . bind ( this )
25
27
this . toggle = this . toggle . bind ( this )
26
28
}
@@ -70,6 +72,40 @@ export default class FileSelector extends Component {
70
72
return result
71
73
}
72
74
75
+ handleImport ( sourceComponent , sourceLocalPath ) {
76
+ const { poolPath } = getLocalFile (
77
+ this . context . store ,
78
+ sourceComponent ,
79
+ sourceLocalPath
80
+ )
81
+ // TODO: Consider whether it is ever possible
82
+ // that a file lookup might fail, and add error
83
+ // handling if so.
84
+
85
+ const result = {
86
+ localPath : sourceLocalPath ,
87
+ poolPath,
88
+ }
89
+
90
+ if (
91
+ this . props . component && this . props . addToComponent &&
92
+ this . props . component !== sourceComponent
93
+ ) {
94
+ addLocalFile ( this . context . store , {
95
+ component : this . props . component ,
96
+ localPath : result . localPath ,
97
+ poolPath,
98
+ } )
99
+ }
100
+
101
+ // Resolve promise
102
+ if ( this . promiseHandlers . resolve ) {
103
+ this . promiseHandlers . resolve ( result )
104
+ }
105
+
106
+ return result
107
+ }
108
+
73
109
async select ( ) {
74
110
this . toggle ( )
75
111
return new Promise (
0 commit comments