Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit 04458eb

Browse files
Handle import of existing files in FileSelector logic
1 parent 18798c4 commit 04458eb

File tree

1 file changed

+37
-1
lines changed
  • packages/builder/src/components/FileSelector

1 file changed

+37
-1
lines changed

packages/builder/src/components/FileSelector/index.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import PropTypes from 'prop-types'
33
import { Nav, NavItem, NavLink, ModalBody } from 'reactstrap'
44
import classnames from 'classnames'
55

6-
import { addGlobalFile, addLocalFile } from '../../logic/util/files'
6+
import { addGlobalFile, addLocalFile,
7+
getLocalFile } from '../../logic/util/files'
78

89
import Modal from '../Modal'
910
import Icon from '../Icon'
@@ -21,6 +22,7 @@ export default class FileSelector extends Component {
2122
this.promiseHandlers = {}
2223

2324
this.handleUpload = this.handleUpload.bind(this)
25+
this.handleImport = this.handleImport.bind(this)
2426
this.select = this.select.bind(this)
2527
this.toggle = this.toggle.bind(this)
2628
}
@@ -70,6 +72,40 @@ export default class FileSelector extends Component {
7072
return result
7173
}
7274

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+
73109
async select() {
74110
this.toggle()
75111
return new Promise(

0 commit comments

Comments
 (0)