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

Commit

Permalink
Handle import of existing files in FileSelector logic
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixHenninger committed Jan 2, 2019
1 parent 18798c4 commit 04458eb
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion packages/builder/src/components/FileSelector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import PropTypes from 'prop-types'
import { Nav, NavItem, NavLink, ModalBody } from 'reactstrap'
import classnames from 'classnames'

import { addGlobalFile, addLocalFile } from '../../logic/util/files'
import { addGlobalFile, addLocalFile,
getLocalFile } from '../../logic/util/files'

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

this.handleUpload = this.handleUpload.bind(this)
this.handleImport = this.handleImport.bind(this)
this.select = this.select.bind(this)
this.toggle = this.toggle.bind(this)
}
Expand Down Expand Up @@ -70,6 +72,40 @@ export default class FileSelector extends Component {
return result
}

handleImport(sourceComponent, sourceLocalPath) {
const { poolPath } = getLocalFile(
this.context.store,
sourceComponent,
sourceLocalPath
)
// TODO: Consider whether it is ever possible
// that a file lookup might fail, and add error
// handling if so.

const result = {
localPath: sourceLocalPath,
poolPath,
}

if (
this.props.component && this.props.addToComponent &&
this.props.component !== sourceComponent
) {
addLocalFile(this.context.store, {
component: this.props.component,
localPath: result.localPath,
poolPath,
})
}

// Resolve promise
if (this.promiseHandlers.resolve) {
this.promiseHandlers.resolve(result)
}

return result
}

async select() {
this.toggle()
return new Promise(
Expand Down

0 comments on commit 04458eb

Please sign in to comment.