-
Notifications
You must be signed in to change notification settings - Fork 14k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[explore] viz type selector as modal #2787
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
superset/assets/javascripts/explore/components/controls/VizTypeControl.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Label, Row, Col, FormControl, Modal } from 'react-bootstrap'; | ||
import visTypes from '../../stores/visTypes'; | ||
import ControlHeader from '../ControlHeader'; | ||
|
||
const propTypes = { | ||
description: PropTypes.string, | ||
label: PropTypes.string, | ||
name: PropTypes.string.isRequired, | ||
onChange: PropTypes.func, | ||
value: PropTypes.string.isRequired, | ||
}; | ||
|
||
const defaultProps = { | ||
onChange: () => {}, | ||
}; | ||
|
||
export default class VizTypeControl extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
showModal: false, | ||
filter: '', | ||
}; | ||
this.toggleModal = this.toggleModal.bind(this); | ||
this.changeSearch = this.changeSearch.bind(this); | ||
} | ||
onChange(vizType) { | ||
this.props.onChange(vizType); | ||
this.setState({ showModal: false }); | ||
} | ||
toggleModal() { | ||
this.setState({ showModal: !this.state.showModal }); | ||
} | ||
changeSearch(event) { | ||
this.setState({ filter: event.target.value }); | ||
} | ||
renderVizType(vizType) { | ||
const vt = vizType; | ||
return ( | ||
<div | ||
className={`viztype-selector-container ${vt === this.props.value ? 'selected' : ''}`} | ||
onClick={this.onChange.bind(this, vt)} | ||
> | ||
<img | ||
alt={`viz-type-${vt}`} | ||
width="100%" | ||
className={`viztype-selector ${this.props.value === vt ? 'selected' : ''}`} | ||
src={`/static/assets/images/viz_thumbnails/${vt}.png`} | ||
/> | ||
<div className="viztype-label"> | ||
<strong>{visTypes[vt].label}</strong> | ||
</div> | ||
</div>); | ||
} | ||
render() { | ||
const filter = this.state.filter; | ||
const filteredVizTypes = Object.keys(visTypes) | ||
.filter(vt => filter.length === 0 || visTypes[vt].label.toLowerCase().includes(filter)); | ||
|
||
const imgPerRow = 4; | ||
const rows = []; | ||
for (let i = 0; i <= filteredVizTypes.length; i += imgPerRow) { | ||
rows.push( | ||
<Row> | ||
{filteredVizTypes.slice(i, i + imgPerRow).map(vt => ( | ||
<Col md={3} key={`grid-col-${vt}`}> | ||
{this.renderVizType(vt)} | ||
</Col> | ||
))} | ||
</Row>); | ||
} | ||
return ( | ||
<div> | ||
<ControlHeader | ||
{...this.props} | ||
rightNode={ | ||
<a onClick={this.toggleModal}>edit</a> | ||
} | ||
/> | ||
<Label onClick={this.toggleModal} style={{ cursor: 'pointer' }}> | ||
{visTypes[this.props.value].label} | ||
</Label> | ||
<Modal show={this.state.showModal} onHide={this.toggleModal} bsSize="lg"> | ||
<Modal.Header closeButton> | ||
<Modal.Title>Select a visualization type</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<div> | ||
<FormControl | ||
id="formControlsText" | ||
type="text" | ||
bsSize="sm" | ||
value={this.state.filter} | ||
placeholder="Search / Filter" | ||
onChange={this.changeSearch} | ||
/> | ||
</div> | ||
{rows} | ||
</Modal.Body> | ||
</Modal> | ||
</div>); | ||
} | ||
} | ||
|
||
VizTypeControl.propTypes = propTypes; | ||
VizTypeControl.defaultProps = defaultProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
}, | ||
"scripts": { | ||
"test": "mocha --require ignore-styles --compilers js:babel-core/register --require spec/helpers/browser.js --recursive spec/**/*_spec.*", | ||
"cover": "babel-node ./node_modules/.bin/istanbul cover _mocha -- --require spec/helpers/browser.js --recursive spec/**/*_spec.*", | ||
"cover": "babel-node node_modules/.bin/babel-istanbul cover _mocha -- --require spec/helpers/browser.js --recursive spec/**/*_spec.*", | ||
"dev": "NODE_ENV=dev webpack --watch --colors --progress --debug --output-pathinfo --devtool inline-source-map", | ||
"prod": "NODE_ENV=production node --max_old_space_size=4096 ./node_modules/webpack/bin/webpack.js -p --colors --progress", | ||
"build": "NODE_ENV=production webpack --colors --progress", | ||
|
@@ -59,6 +59,7 @@ | |
"immutability-helper": "^2.0.0", | ||
"immutable": "^3.8.1", | ||
"jquery": "^3.2.1", | ||
"jsdom": "9.12.0", | ||
"lodash.throttle": "^4.1.1", | ||
"mapbox-gl": "^0.26.0", | ||
"moment": "^2.14.1", | ||
|
@@ -98,9 +99,10 @@ | |
"devDependencies": { | ||
"babel-cli": "^6.14.0", | ||
"babel-core": "^6.10.4", | ||
"babel-istanbul": "^0.12.2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this change for? |
||
"babel-loader": "^6.2.4", | ||
"babel-plugin-css-modules-transform": "^1.1.0", | ||
"babel-polyfill": "^6.14.0", | ||
"babel-polyfill": "^6.23.0", | ||
"babel-preset-airbnb": "^2.1.1", | ||
"babel-preset-es2015": "^6.14.0", | ||
"babel-preset-react": "^6.11.1", | ||
|
@@ -119,7 +121,7 @@ | |
"ignore-styles": "^5.0.1", | ||
"imports-loader": "^0.7.1", | ||
"istanbul": "^1.0.0-alpha", | ||
"jsdom": "^9.12.0", | ||
"jsdom": "9.12.0", | ||
"json-loader": "^0.5.4", | ||
"less": "^2.6.1", | ||
"less-loader": "^4.0.3", | ||
|
37 changes: 37 additions & 0 deletions
37
superset/assets/spec/javascripts/explorev2/components/VizTypeControl_spec.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import sinon from 'sinon'; | ||
import { expect } from 'chai'; | ||
import { describe, it, beforeEach } from 'mocha'; | ||
import { shallow } from 'enzyme'; | ||
import { Modal } from 'react-bootstrap'; | ||
import VizTypeControl from '../../../../javascripts/explore/components/controls/VizTypeControl'; | ||
|
||
const defaultProps = { | ||
name: 'viz_type', | ||
label: 'Visualization Type', | ||
value: 'table', | ||
onChange: sinon.spy(), | ||
}; | ||
|
||
describe('VizTypeControl', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = shallow(<VizTypeControl {...defaultProps} />); | ||
}); | ||
|
||
it('renders a Modal', () => { | ||
expect(wrapper.find(Modal)).to.have.lengthOf(1); | ||
}); | ||
|
||
it('calls onChange when toggled', () => { | ||
const select = wrapper.find('.viztype-selector-container').first(); | ||
select.simulate('click'); | ||
expect(defaultProps.onChange.called).to.equal(true); | ||
}); | ||
it('filters images based on text input', () => { | ||
expect(wrapper.find('img').length).to.be.above(20); | ||
wrapper.setState({ filter: 'time' }); | ||
expect(wrapper.find('img').length).to.be.below(10); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -422,3 +422,8 @@ hr { | |
} | ||
} | ||
.space-loop(6); | ||
|
||
a { | ||
cursor: pointer; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if description and label are not required, we should add defaults for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they aren't defined we don't print them, that's the case for
FilterControl
where we don't want both a section header and a control header