Command shape: id & propType validation

This commit is contained in:
Cássio Zen 2016-07-08 07:20:07 -03:00
parent c7033a614e
commit bee2169aa0

View File

@ -6,7 +6,7 @@ import { connect } from 'react-redux';
import { Icon } from '../components/UI'; import { Icon } from '../components/UI';
import styles from './FindBar.css'; import styles from './FindBar.css';
const SEARCH = 'SEARCH'; export const SEARCH = 'SEARCH';
const PLACEHOLDER = 'Type to search or execute commands'; const PLACEHOLDER = 'Type to search or execute commands';
class FindBar extends Component { class FindBar extends Component {
@ -103,7 +103,7 @@ class FindBar extends Component {
placeholder: '' placeholder: ''
}); });
enteredParamValue && this.props.dispatch(runCommand('search', { searchTerm: enteredParamValue })); enteredParamValue && this.props.dispatch(runCommand(SEARCH, { searchTerm: enteredParamValue }));
} else if (command.param && !enteredParamValue) { } else if (command.param && !enteredParamValue) {
// Partial Match // Partial Match
// Command was partially matched: It requires a param, but param wasn't entered // Command was partially matched: It requires a param, but param wasn't entered
@ -117,8 +117,13 @@ class FindBar extends Component {
// Match // Match
// Command was matched and either it doesn't require a param or it's required param was entered // Command was matched and either it doesn't require a param or it's required param was entered
// Dispatch action // Dispatch action
this.setState({
value: '',
placeholder: PLACEHOLDER,
activeScope: null
});
const payload = paramName ? { [paramName]: enteredParamValue } : null; const payload = paramName ? { [paramName]: enteredParamValue } : null;
this.props.dispatch(runCommand(command.token, payload)); this.props.dispatch(runCommand(command.id, payload));
} }
} }
@ -339,7 +344,10 @@ class FindBar extends Component {
} }
} }
FindBar.propTypes = { FindBar.propTypes = {
commands: PropTypes.array.isRequired, commands: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string.isRequired,
pattern: PropTypes.string.isRequired
})).isRequired,
dispatch: PropTypes.func.isRequired, dispatch: PropTypes.func.isRequired,
}; };