diff --git a/app/components/AssetTree/AssetNode/AssetNode.js b/app/components/AssetTree/AssetNode/AssetNode.js index 21ff03f1..444179e3 100644 --- a/app/components/AssetTree/AssetNode/AssetNode.js +++ b/app/components/AssetTree/AssetNode/AssetNode.js @@ -71,16 +71,16 @@ const StyledLabel = styled.span` function AssetNode(props) { const { node, - root, - openNodes, - checkedNodes, - selectedAsset, - level, - checkboxes, - onToggle, - onRightClick, - onClick, - ancestorArchived, + root = false, + openNodes = [], + checkedNodes = [], + selectedAsset = null, + level = 0, + checkboxes = false, + onToggle = null, + onRightClick = null, + onClick = null, + ancestorArchived = false, } = props; const isOpen = root || openNodes.includes(node.uri); const isChecked = checkboxes && (root || checkedNodes.includes(node.uri)); @@ -185,18 +185,4 @@ AssetNode.propTypes = { ancestorArchived: PropTypes.bool, }; -AssetNode.defaultProps = { - root: false, - onToggle: null, - onRightClick: null, - onClick: null, - onCheck: null, - level: 0, - selectedAsset: null, - openNodes: [], - checkedNodes: [], - checkboxes: false, - ancestorArchived: false, -}; - export default AssetNode; diff --git a/app/components/AssetTree/AssetTree.js b/app/components/AssetTree/AssetTree.js index e8fc5135..dddfad9a 100644 --- a/app/components/AssetTree/AssetTree.js +++ b/app/components/AssetTree/AssetTree.js @@ -12,25 +12,39 @@ import styles from './AssetTree.css'; class AssetTree extends Component { constructor(props) { super(props); + + const { + selectedAsset = null, + checkboxes = false, + onCheckAsset = null, + rootSelectable = true + } = props; + this.state = { expandedNodes: [], checkedNodes: [] }; } handleClick = (node) => { + const { + assets, + onSelectAsset, + rootSelectable = true + } = this.props; + // Determine if this is selectable. We don't consider a selection if: // 1. The asset collection is null // 2. The selected node is null // 3. Root selection is disabled and this is the root item // // To handle unselectable items, we trigger to clear the active selection. - if (this.props.assets === null || node === null) { - this.props.onSelectAsset(null); + if (assets === null || node === null) { + onSelectAsset(null); return; - } else if (!this.props.rootSelectable && (node.uri === this.props.assets.uri)) { - this.props.onSelectAsset(null); + } else if (!rootSelectable && (node.uri === assets.uri)) { + onSelectAsset(null); return; } - this.props.onSelectAsset(node); + onSelectAsset(node); }; onToggle = (node) => { @@ -64,6 +78,8 @@ class AssetTree extends Component { }; setExpandAll = (expand) => { + const { assets } = this.props; + this.setState(() => { const expandedNodes = []; // If we're collapsing, we just set this to an empty array. Easy! @@ -72,15 +88,17 @@ class AssetTree extends Component { } // If we're expanding, we need to recursively add every folder URI. - expandedNodes.push(this.props.assets.uri); - if (this.props.assets.children) { - this.props.assets.children.forEach((c) => this.setNodeExpanded(c, expandedNodes)); + expandedNodes.push(assets.uri); + if (assets.children) { + assets.children.forEach((c) => this.setNodeExpanded(c, expandedNodes)); } return { expandedNodes }; }); }; handleCheck = (node, value) => { + const { onCheckAsset = null } = this.props; + this.setState((prevState) => { const checkedNodes = [...prevState.checkedNodes]; const index = checkedNodes.indexOf(node.uri); @@ -92,22 +110,30 @@ class AssetTree extends Component { return { checkedNodes }; }); - if (this.props.onCheckAsset) { - this.props.onCheckAsset(node, value); + if (onCheckAsset) { + onCheckAsset(node, value); } }; render() { - const assetTree = !this.props.assets ? null : ( + const { + assets, + selectedAsset = null, + checkboxes = false, + } = this.props; + + const { expandedNodes, checkedNodes } = this.state; + + const assetTree = !assets ? null : ( @@ -126,11 +152,4 @@ AssetTree.propTypes = { rootSelectable: PropTypes.bool }; -AssetTree.defaultProps = { - selectedAsset: null, - checkboxes: false, - onCheckAsset: null, - rootSelectable: true -}; - export default AssetTree; diff --git a/app/components/CloneDirectory/CloneDirectory.js b/app/components/CloneDirectory/CloneDirectory.js index 0013eb44..22e4787d 100644 --- a/app/components/CloneDirectory/CloneDirectory.js +++ b/app/components/CloneDirectory/CloneDirectory.js @@ -62,20 +62,30 @@ class CloneDirectory extends Component { }; render() { + const { + sourceDirectory, + targetBaseDirectory, + projectName, + onSourceDirectoryChanged, + onTargetBaseDirectoryChanged, + onProjectNameChanged, + isValidDirectory = false, + } = this.props; + let validation = null; if (this.state.validationErrorMessage) { validation = {this.state.validationErrorMessage}; } - const targetDirectory = this.props.targetBaseDirectory && this.props.projectName - ? `${this.props.targetBaseDirectory}/${this.props.projectName}` + const targetDirectory = targetBaseDirectory && projectName + ? `${targetBaseDirectory}/${projectName}` : ''; return (
Source project directory to clone: - +
- {targetDirectory && this.props.isValidDirectory && ( + {targetDirectory && isValidDirectory && (

New project will be created at:

{targetDirectory} @@ -127,10 +137,7 @@ CloneDirectory.propTypes = { onSourceDirectoryChanged: PropTypes.func.isRequired, onTargetBaseDirectoryChanged: PropTypes.func.isRequired, onProjectNameChanged: PropTypes.func.isRequired, - isValidDirectory: PropTypes.bool, -}; -CloneDirectory.defaultProps = { - isValidDirectory: false, // Default to false + isValidDirectory: PropTypes.bool, }; export default CloneDirectory; diff --git a/app/components/EditableLabel/EditableLabel.js b/app/components/EditableLabel/EditableLabel.js index 31a9b2b4..018cead3 100644 --- a/app/components/EditableLabel/EditableLabel.js +++ b/app/components/EditableLabel/EditableLabel.js @@ -44,10 +44,12 @@ export default class EditableLabel extends React.Component { }; handleFocus = () => { - if (this.state.isEditing && typeof this.props.onFocusOut === 'function') { - this.props.onFocusOut(this.state.text); - } else if (typeof this.props.onFocus === 'function') { - this.props.onFocus(this.state.text); + const { onFocusOut, onFocus, emptyEdit = false } = this.props; + + if (this.state.isEditing && typeof onFocusOut === 'function') { + onFocusOut(this.state.text); + } else if (typeof onFocus === 'function') { + onFocus(this.state.text); } if (this.isTextValueValid()) { @@ -57,7 +59,7 @@ export default class EditableLabel extends React.Component { })); } else if (this.state.isEditing) { this.setState({ - isEditing: this.props.emptyEdit || false, + isEditing: emptyEdit, }); } else { this.setState((prevState) => ({ @@ -68,8 +70,9 @@ export default class EditableLabel extends React.Component { }; handleSave = () => { - if (typeof this.props.onFocusOut === 'function') { - this.props.onFocusOut(this.state.text); + const { onFocusOut } = this.props; + if (typeof onFocusOut === 'function') { + onFocusOut(this.state.text); } this.setState({ isEditing: false }); }; @@ -89,7 +92,8 @@ export default class EditableLabel extends React.Component { handleKeyDown = (e) => { // We only allow enter-completion when this is a single line editor. - if (e.keyCode === ENTER_KEY_CODE && !this.props.multiline) { + const { multiline = false } = this.props; + if (e.keyCode === ENTER_KEY_CODE && !multiline) { this.handleEnterKey(); } }; @@ -99,31 +103,51 @@ export default class EditableLabel extends React.Component { }; render() { + const { + multiline = false, + containerClassName = null, + inputClassName = null, + inputWidth = null, + inputHeight = null, + inputFontSize = null, + inputFontWeight = null, + inputBorderWidth = null, + inputMaxLength = 524288, + inputPlaceHolder = null, + inputTabIndex = 0, + showSaveCancel = false, + labelContainerClassName = null, + labelClassName = null, + labelFontSize = null, + labelFontWeight = null, + labelPlaceHolder = null, + } = this.props; + if (this.state.isEditing) { - if (this.props.multiline) { + if (multiline) { return ( -
+