Moved findBar to components and decopuled it from redux as much as possible.
Removed stories from containers. These aren't possible to write since containers depend on redux.
This commit is contained in:
parent
ede273a732
commit
46667926b2
@ -2,7 +2,6 @@ import { configure } from '@kadira/storybook';
|
|||||||
import '../src/index.css';
|
import '../src/index.css';
|
||||||
|
|
||||||
function loadStories() {
|
function loadStories() {
|
||||||
require('../src/containers/stories/');
|
|
||||||
require('../src/components/stories/');
|
require('../src/components/stories/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import history from '../routing/history';
|
import history from '../routing/history';
|
||||||
import { SEARCH } from '../containers/FindBar';
|
import { SEARCH } from '../components/UI/FindBar/FindBar';
|
||||||
|
|
||||||
export const RUN_COMMAND = 'RUN_COMMAND';
|
export const RUN_COMMAND = 'RUN_COMMAND';
|
||||||
export const SHOW_COLLECTION = 'SHOW_COLLECTION';
|
export const SHOW_COLLECTION = 'SHOW_COLLECTION';
|
||||||
|
@ -3,7 +3,7 @@ import pluralize from 'pluralize';
|
|||||||
import { IndexLink } from 'react-router';
|
import { IndexLink } from 'react-router';
|
||||||
import { Menu, MenuItem, Button } from 'react-toolbox';
|
import { Menu, MenuItem, Button } from 'react-toolbox';
|
||||||
import AppBar from 'react-toolbox/lib/app_bar';
|
import AppBar from 'react-toolbox/lib/app_bar';
|
||||||
import FindBar from '../../../containers/FindBar';
|
import FindBar from '../FindBar/FindBar';
|
||||||
import styles from './AppHeader.css';
|
import styles from './AppHeader.css';
|
||||||
|
|
||||||
export default class AppHeader extends React.Component {
|
export default class AppHeader extends React.Component {
|
||||||
@ -38,7 +38,7 @@ export default class AppHeader extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { collections, commands, defaultCommands } = this.props;
|
const { collections, commands, defaultCommands, runCommand } = this.props;
|
||||||
const { createMenuActive } = this.state;
|
const { createMenuActive } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -52,6 +52,7 @@ export default class AppHeader extends React.Component {
|
|||||||
<FindBar
|
<FindBar
|
||||||
commands={commands}
|
commands={commands}
|
||||||
defaultCommands={defaultCommands}
|
defaultCommands={defaultCommands}
|
||||||
|
runCommand={runCommand}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
className={styles.createBtn}
|
className={styles.createBtn}
|
||||||
|
@ -1,9 +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 { Icon } from '../index';
|
||||||
import { connect } from 'react-redux';
|
|
||||||
import { Icon } from '../components/UI';
|
|
||||||
import styles from './FindBar.css';
|
import styles from './FindBar.css';
|
||||||
|
|
||||||
export const SEARCH = 'SEARCH';
|
export const SEARCH = 'SEARCH';
|
||||||
@ -102,13 +100,15 @@ class FindBar extends Component {
|
|||||||
const paramName = command && command.param ? command.param.name : null;
|
const paramName = command && command.param ? command.param.name : null;
|
||||||
const enteredParamValue = command && command.param && match[1] ? match[1].trim() : null;
|
const enteredParamValue = command && command.param && match[1] ? match[1].trim() : null;
|
||||||
|
|
||||||
|
console.log(this.props.runCommand);
|
||||||
|
|
||||||
if (command.search) {
|
if (command.search) {
|
||||||
this.setState({
|
this.setState({
|
||||||
activeScope: SEARCH,
|
activeScope: SEARCH,
|
||||||
placeholder: ''
|
placeholder: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
enteredParamValue && this.props.dispatch(runCommand(SEARCH, { searchTerm: enteredParamValue }));
|
enteredParamValue && this.props.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
|
||||||
@ -133,7 +133,7 @@ class FindBar extends Component {
|
|||||||
if (paramName) {
|
if (paramName) {
|
||||||
payload[paramName] = enteredParamValue;
|
payload[paramName] = enteredParamValue;
|
||||||
}
|
}
|
||||||
this.props.dispatch(runCommand(command.type, payload));
|
this.props.runCommand(command.type, payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,8 +373,7 @@ FindBar.propTypes = {
|
|||||||
pattern: PropTypes.string.isRequired
|
pattern: PropTypes.string.isRequired
|
||||||
})).isRequired,
|
})).isRequired,
|
||||||
defaultCommands: PropTypes.arrayOf(PropTypes.string),
|
defaultCommands: PropTypes.arrayOf(PropTypes.string),
|
||||||
dispatch: PropTypes.func.isRequired,
|
runCommand: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export { FindBar };
|
export default FindBar;
|
||||||
export default connect()(FindBar);
|
|
@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { storiesOf, action } from '@kadira/storybook';
|
import { storiesOf, action } from '@kadira/storybook';
|
||||||
|
|
||||||
import { FindBar } from '../FindBar';
|
import FindBar from '../UI/FindBar/FindBar';
|
||||||
|
|
||||||
const CREATE_COLLECTION = 'CREATE_COLLECTION';
|
const CREATE_COLLECTION = 'CREATE_COLLECTION';
|
||||||
const CREATE_POST = 'CREATE_POST';
|
const CREATE_POST = 'CREATE_POST';
|
||||||
@ -30,15 +30,13 @@ const style = {
|
|||||||
margin: 20
|
margin: 20
|
||||||
};
|
};
|
||||||
|
|
||||||
const dispatch = action('DISPATCH');
|
|
||||||
|
|
||||||
storiesOf('FindBar', module)
|
storiesOf('FindBar', module)
|
||||||
.add('Default View', () => (
|
.add('Default View', () => (
|
||||||
<div style={style}>
|
<div style={style}>
|
||||||
<FindBar
|
<FindBar
|
||||||
commands={commands}
|
commands={commands}
|
||||||
defaultCommands={[CREATE_POST, CREATE_COLLECTION, OPEN_SETTINGS, HELP, MORE_COMMANDS]}
|
defaultCommands={[CREATE_POST, CREATE_COLLECTION, OPEN_SETTINGS, HELP, MORE_COMMANDS]}
|
||||||
dispatch={f => f(dispatch)}
|
runCommand={action}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
));
|
));
|
@ -1,3 +1,4 @@
|
|||||||
import './Card';
|
import './Card';
|
||||||
import './Icon';
|
import './Icon';
|
||||||
import './Toast';
|
import './Toast';
|
||||||
|
import './FindBar';
|
||||||
|
@ -9,9 +9,10 @@ import {
|
|||||||
SHOW_COLLECTION,
|
SHOW_COLLECTION,
|
||||||
CREATE_COLLECTION,
|
CREATE_COLLECTION,
|
||||||
HELP,
|
HELP,
|
||||||
|
runCommand,
|
||||||
createNewEntryInCollection
|
createNewEntryInCollection
|
||||||
} from '../actions/findbar';
|
} from '../actions/findbar';
|
||||||
import { AppHeader, Loader } from '../components/UI';
|
import { AppHeader, Loader } from '../components/UI/index';
|
||||||
import styles from './App.css';
|
import styles from './App.css';
|
||||||
|
|
||||||
class App extends React.Component {
|
class App extends React.Component {
|
||||||
@ -89,12 +90,6 @@ class App extends React.Component {
|
|||||||
return { commands, defaultCommands };
|
return { commands, defaultCommands };
|
||||||
}
|
}
|
||||||
|
|
||||||
onCreateEntryClick = collectionName => {
|
|
||||||
this.props.dispatch(
|
|
||||||
createNewEntryInCollection(collectionName)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { user, config, children, collections } = this.props;
|
const { user, config, children, collections } = this.props;
|
||||||
|
|
||||||
@ -123,7 +118,8 @@ class App extends React.Component {
|
|||||||
collections={collections}
|
collections={collections}
|
||||||
commands={commands}
|
commands={commands}
|
||||||
defaultCommands={defaultCommands}
|
defaultCommands={defaultCommands}
|
||||||
onCreateEntryClick={this.onCreateEntryClick}
|
runCommand={this.props.runCommand}
|
||||||
|
onCreateEntryClick={this.props.createNewEntryInCollection}
|
||||||
/>
|
/>
|
||||||
<div className={`${styles.alignable} ${styles.main}`}>
|
<div className={`${styles.alignable} ${styles.main}`}>
|
||||||
{children}
|
{children}
|
||||||
@ -141,4 +137,16 @@ function mapStateToProps(state) {
|
|||||||
return { auth, config, collections, user };
|
return { auth, config, collections, user };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps)(App);
|
function mapDispatchToProps(dispatch) {
|
||||||
|
return {
|
||||||
|
dispatch,
|
||||||
|
runCommand: (type, payload) => {
|
||||||
|
dispatch(runCommand(type, payload));
|
||||||
|
},
|
||||||
|
createNewEntryInCollection: (collectionName) => {
|
||||||
|
dispatch(createNewEntryInCollection(collectionName));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(App);
|
||||||
|
@ -1 +0,0 @@
|
|||||||
import './FindBar';
|
|
Loading…
x
Reference in New Issue
Block a user