Skip to content

Commit

Permalink
move to initializer for final package
Browse files Browse the repository at this point in the history
Expects a div id
Expects a function to call for opening templates
  • Loading branch information
happycollision committed Nov 15, 2016
1 parent e992f44 commit de59aa1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
4 changes: 4 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@
function openInCbox(url){
alert('Would have opened in colorbox on server: ' + url);
}
initTemplateBrowser({
divId: 'root',

})
</script>
</html>
19 changes: 19 additions & 0 deletions specs/features/users-can-open-templates.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { mount } from 'enzyme';
import Browser from '../../src/components/Browser';
import create from '../spec-helpers';

describe('Feature: Users can open templates', () => {
it('calls the attached function with expected params', () => {
const templates = [
create('template', {id: 23, type: 'TextOnly'})
];
const openTemplate = jest.fn( () => {} );
const app = mount(<Browser templates={templates} onTemplateOpen={ openTemplate } />);

app.find('Template').simulate('click');

expect(openTemplate.mock.calls[0]).toEqual([23, 'TextOnly']);
});

});
7 changes: 6 additions & 1 deletion src/components/Browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ class Browser extends Component {
render() {
const tags = this.getTags();
const filteredTemplates = this.getFilteredTemplates().map( (template, i) => {
return(<Template key={`template-item-${i}`} template={ template } options={ this.state.templateOptions } />);
return(
<Template key={`template-item-${i}`}
template={ template }
openTemplate={ this.props.onTemplateOpen }
options={ this.state.templateOptions } />
);
});
const page = this.state.page || 1;
const templates = PaginationPane.paginate(filteredTemplates, page)
Expand Down
6 changes: 4 additions & 2 deletions src/components/Template.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import TemplateFeatures from './TemplateFeatures';
import LoadingSpinner from './LoadingSpinner';
import hoverIntent from 'hoverintent';
import { padLeft } from '../helpers/StringHelpers';
import { openTemplateEditorUrl } from '../helpers/ExternalServices';
import './Template.css';

class Template extends Component {
Expand Down Expand Up @@ -45,7 +44,10 @@ class Template extends Component {

handleClickOnTemplate (e) {
e.preventDefault();
openTemplateEditorUrl( this.createLink() );
this.props.openTemplate(
this.props.template.id,
this.props.template.type
)
}

handleHoverOn () {
Expand Down
3 changes: 0 additions & 3 deletions src/helpers/ExternalServices.js

This file was deleted.

20 changes: 16 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ import Browser from './components/Browser';

let templates = require('./stores/live-data-faker').default;

ReactDOM.render(
<Browser templates={ templates } />,
document.getElementById('root')
);
/*
Required options:
divId: (string) id of the div that will house the browser
onTemplateOpen: (function(templateId)) function to call when opening a template it
will recieve the following:
templateId: (int) the id of the template opened
templateTypeString: (string) the type of template. Eg: 'TextOnly'
*/
function initTemplateBrowser (options) {
ReactDOM.render(
<Browser templates={ templates } />,
document.getElementById(options.divId)
);
}

window.initTemplateBrowser = initTemplateBrowser;

0 comments on commit de59aa1

Please sign in to comment.