dispatching actions for complete commands
This commit is contained in:
parent
0e60e2720c
commit
7cf6b500d2
@ -1,6 +1,7 @@
|
|||||||
import React, { Component, PropTypes } from 'react';
|
import React, { Component, PropTypes } from 'react';
|
||||||
import fuzzy from 'fuzzy';
|
import fuzzy from 'fuzzy';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { runCommand } from '../actions/findbar';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import styles from './FindBar.css';
|
import styles from './FindBar.css';
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ class FindBar extends Component {
|
|||||||
|
|
||||||
const matcher = /\(:([a-zA-Z_$][a-zA-Z0-9_$]*)(?:(?: as )(.*))?\)/g;
|
const matcher = /\(:([a-zA-Z_$][a-zA-Z0-9_$]*)(?:(?: as )(.*))?\)/g;
|
||||||
const match = matcher.exec(command.pattern);
|
const match = matcher.exec(command.pattern);
|
||||||
const token = command.pattern.slice(0, match.index);
|
const token = command.pattern.slice(0, match.index) || command.token;
|
||||||
regexp += this._escapeRegExp(command.pattern.slice(0, match.index));
|
regexp += this._escapeRegExp(command.pattern.slice(0, match.index));
|
||||||
|
|
||||||
if (match[1]) {
|
if (match[1]) {
|
||||||
@ -88,15 +89,9 @@ class FindBar extends Component {
|
|||||||
activeScope: command.token,
|
activeScope: command.token,
|
||||||
placeholder: command.param.display
|
placeholder: command.param.display
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.props.dispatch(runCommand(command.token, command.param.name, param));
|
||||||
}
|
}
|
||||||
console.log({
|
|
||||||
command,
|
|
||||||
param
|
|
||||||
})
|
|
||||||
return {
|
|
||||||
command,
|
|
||||||
param
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChange(event) {
|
handleChange(event) {
|
||||||
@ -271,7 +266,8 @@ class FindBar extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
FindBar.propTypes = {
|
FindBar.propTypes = {
|
||||||
commands: PropTypes.array.isRequired
|
commands: PropTypes.array.isRequired,
|
||||||
|
dispatch: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { storiesOf } from '@kadira/storybook';
|
import { storiesOf, action } from '@kadira/storybook';
|
||||||
|
|
||||||
import FindBar from '../FindBar';
|
import FindBar from '../FindBar';
|
||||||
|
|
||||||
@ -57,13 +57,13 @@ const commands = [
|
|||||||
{ pattern: 'Visit West Virginia at(:date)' },
|
{ pattern: 'Visit West Virginia at(:date)' },
|
||||||
{ pattern: 'Visit Wisconsin at(:date)' },
|
{ pattern: 'Visit Wisconsin at(:date)' },
|
||||||
{ pattern: 'Visit Wyoming at(:date)' },
|
{ pattern: 'Visit Wyoming at(:date)' },
|
||||||
{ pattern: '(:searchTerm as Find...)' }
|
{ pattern: '(:searchTerm as Find...)', token:'Search' }
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
storiesOf('FindBar', module)
|
storiesOf('FindBar', module)
|
||||||
.add('Default View', () => (
|
.add('Default View', () => (
|
||||||
<FindBar
|
<FindBar
|
||||||
commands={commands}
|
commands={commands}
|
||||||
|
dispatch={action('DISPATCH')}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user