Skip to content

Commit

Permalink
Merge pull request #20 from ritz078/feat/options
Browse files Browse the repository at this point in the history
API to set options added. also fixes #4
  • Loading branch information
arunoda committed Jul 20, 2016
2 parents 888fceb + e712194 commit d9a435b
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 5 deletions.
3 changes: 3 additions & 0 deletions example/client/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export default class ReactProvider extends Provider {
// You must implement this public API.
handleAPI(api) {
this.api = api;
this.api.setOptions({
name : 'REACT-STORYBOOK',
});

// set stories
this.api.setStories([
Expand Down
16 changes: 16 additions & 0 deletions src/modules/api/actions/__tests__/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,20 @@ describe('manager.api.actions.api', () => {
});
});
});

describe('setOptions', () => {
it('should dispatch related redux action', () => {
const reduxStore = {
dispatch: sinon.stub(),
};
const options = {};

actions.setOptions({ reduxStore }, options);
const a = reduxStore.dispatch.args[0][0];
expect(a).to.deep.equal({
type: types.SET_OPTIONS,
options,
});
});
});
});
7 changes: 7 additions & 0 deletions src/modules/api/actions/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ export default {
action,
});
},

setOptions({ reduxStore }, options) {
reduxStore.dispatch({
type: types.SET_OPTIONS,
options,
});
},
};
1 change: 1 addition & 0 deletions src/modules/api/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const types = {
JUMP_TO_STORY: 'API_JUMP_TO_STORY',
CLEAR_ACTIONS: 'API_CLEAR_ACTIONS',
ADD_ACTION: 'API_ADD_ACTION',
SET_OPTIONS: 'API_SET_OPTIONS',
};

import api from './api';
Expand Down
1 change: 1 addition & 0 deletions src/modules/api/configs/init_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function (provider, reduxStore, actions) {
addAction: actions.api.addAction,
setStories: actions.api.setStories,
selectStory: actions.api.selectStory,
setOptions: actions.api.setOptions,
handleShortcut: actions.shortcuts.handleEvent,
};

Expand Down
24 changes: 24 additions & 0 deletions src/modules/api/configs/reducers/__tests__/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,27 @@ describe('manager.preview.config.reducers.preview', () => {
});
});
});

describe('SET OPTIONS', () => {
it('should set options merging with the default ones', () => {
const options = {
name: 'foo',
url: 'bar',
};

const action = {
type: types.SET_OPTIONS,
options: {
name: 'hello world',
},
};

const expected = {
name: 'hello world',
url: 'bar',
};

const newState = reducer({ options }, action);
expect(newState.options).to.eql(expected);
});
});
16 changes: 16 additions & 0 deletions src/modules/api/configs/reducers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export function jumpToStory(storyKinds, selectedKind, selectedStory, direction)

const defaultState = {
actions: [],
options: {
name: 'REACT STORYBOOK',
url: 'https://github.com/kadirahq/react-storybook',
},
};

export default function (state = defaultState, action) {
Expand Down Expand Up @@ -117,6 +121,18 @@ export default function (state = defaultState, action) {
};
}

case types.SET_OPTIONS: {
const newOptions = {
...state.options,
...action.options,
};

return {
...state,
options: newOptions,
};
}

default:
return state;
}
Expand Down
8 changes: 5 additions & 3 deletions src/modules/ui/components/left_panel/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@ const linkStyle = {
textDecoration: 'none',
};

const Header = ({ openShortcutsHelp }) => (
const Header = ({ openShortcutsHelp, name, url }) => (
<div style={wrapperStyle}>
<button style={shortcutIconStyle} onClick={openShortcutsHelp}></button>
<a style={linkStyle} href="https://github.com/kadirahq/react-storybook" target="_blank">
<h3 style={headingStyle}>React Storybook</h3>
<a style={linkStyle} href={url} target="_blank">
<h3 style={headingStyle}>{name}</h3>
</a>
</div>
);

Header.propTypes = {
openShortcutsHelp: React.PropTypes.func,
name: React.PropTypes.string,
url: React.PropTypes.string,
};

export default Header;
8 changes: 7 additions & 1 deletion src/modules/ui/components/left_panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ const storyProps = ['stories', 'selectedKind', 'selectedStory', 'onSelectStory']

const LeftPanel = (props) => (
<div style={mainStyle}>
<Header openShortcutsHelp={props.openShortcutsHelp} />
<Header
name={props.name}
url={props.url}
openShortcutsHelp={props.openShortcutsHelp}
/>
<TextFilter
text={props.storyFilter}
onClear={() => props.onStoryFilter('')}
Expand All @@ -40,6 +44,8 @@ LeftPanel.propTypes = {
onStoryFilter: React.PropTypes.func,

openShortcutsHelp: React.PropTypes.func,
name: React.PropTypes.string,
url: React.PropTypes.string,
};

export default LeftPanel;
10 changes: 10 additions & 0 deletions src/modules/ui/containers/__tests__/left_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ describe('manager.ui.containers.left_panel', () => {
const stories = [{ kind: 'sk', stories: ['dd'] }];
const selectedKind = 'sk';
const selectedStory = 'dd';
const options = {
name: 'foo',
url: 'bar',
};

const selectStory = () => 'selectStory';
const toggleShortcutsHelp = () => 'toggleShortcutsHelp';
Expand All @@ -33,6 +37,7 @@ describe('manager.ui.containers.left_panel', () => {
stories,
selectedKind,
selectedStory,
options,
},
};

Expand All @@ -55,6 +60,10 @@ describe('manager.ui.containers.left_panel', () => {
];
const selectedKind = 'pk';
const selectedStory = 'dd';
const options = {
name: 'foo',
url: 'bar',
};

const selectStory = () => 'selectStory';
const toggleShortcutsHelp = () => 'toggleShortcutsHelp';
Expand All @@ -80,6 +89,7 @@ describe('manager.ui.containers.left_panel', () => {
stories,
selectedKind,
selectedStory,
options,
},
};

Expand Down
4 changes: 3 additions & 1 deletion src/modules/ui/containers/left_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import reduxComposer from '../libs/redux_composer';

export const composer = ({ api, ui }, { actions }) => {
const actionMap = actions();
const { stories, selectedKind, selectedStory } = api;
const { stories, selectedKind, selectedStory, options } = api;
const { storyFilter } = ui;

const data = {
Expand All @@ -18,6 +18,8 @@ export const composer = ({ api, ui }, { actions }) => {
onStoryFilter: actionMap.ui.setStoryFilter,

openShortcutsHelp: actionMap.ui.toggleShortcutsHelp,
name: options.name,
url: options.url,
};

return data;
Expand Down

0 comments on commit d9a435b

Please sign in to comment.