-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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] improve metric(s) and groupby(s) controls #2921
Merged
Merged
Changes from all commits
Commits
Show all changes
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import InfoTooltipWithTrigger from './InfoTooltipWithTrigger'; | ||
|
||
const propTypes = { | ||
column: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default function ColumnOption({ column }) { | ||
return ( | ||
<span> | ||
<span className="m-r-5 option-label"> | ||
{column.verbose_name || column.column_name} | ||
</span> | ||
{column.description && | ||
<InfoTooltipWithTrigger | ||
className="m-r-5 text-muted" | ||
icon="info" | ||
tooltip={column.description} | ||
label={`descr-${column.column_name}`} | ||
/> | ||
} | ||
{column.expression && column.expression !== column.column_name && | ||
<InfoTooltipWithTrigger | ||
className="m-r-5 text-muted" | ||
icon="question-circle-o" | ||
tooltip={column.expression} | ||
label={`expr-${column.column_name}`} | ||
/> | ||
} | ||
</span>); | ||
} | ||
ColumnOption.propTypes = propTypes; |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import InfoTooltipWithTrigger from './InfoTooltipWithTrigger'; | ||
|
||
const propTypes = { | ||
metric: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default function MetricOption({ metric }) { | ||
return ( | ||
<div> | ||
<span className="m-r-5 option-label"> | ||
{metric.verbose_name || metric.metric_name} | ||
</span> | ||
{metric.description && | ||
<InfoTooltipWithTrigger | ||
className="m-r-5 text-muted" | ||
icon="info" | ||
tooltip={metric.description} | ||
label={`descr-${metric.metric_name}`} | ||
/> | ||
} | ||
<InfoTooltipWithTrigger | ||
className="m-r-5 text-muted" | ||
icon="question-circle-o" | ||
tooltip={metric.expression} | ||
label={`expr-${metric.metric_name}`} | ||
/> | ||
</div>); | ||
} | ||
MetricOption.propTypes = propTypes; |
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
47 changes: 47 additions & 0 deletions
47
superset/assets/spec/javascripts/components/ColumnOption_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,47 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import ColumnOption from '../../../javascripts/components/ColumnOption'; | ||
import InfoTooltipWithTrigger from '../../../javascripts/components/InfoTooltipWithTrigger'; | ||
|
||
describe('ColumnOption', () => { | ||
const defaultProps = { | ||
column: { | ||
column_name: 'foo', | ||
verbose_name: 'Foo', | ||
expression: 'SUM(foo)', | ||
description: 'Foo is the greatest column of all', | ||
}, | ||
}; | ||
|
||
let wrapper; | ||
let props; | ||
const factory = o => <ColumnOption {...o} />; | ||
beforeEach(() => { | ||
wrapper = shallow(factory(defaultProps)); | ||
props = Object.assign({}, defaultProps); | ||
}); | ||
it('is a valid element', () => { | ||
expect(React.isValidElement(<ColumnOption {...defaultProps} />)).to.equal(true); | ||
}); | ||
it('shows a label with verbose_name', () => { | ||
const lbl = wrapper.find('.option-label'); | ||
expect(lbl).to.have.length(1); | ||
expect(lbl.first().text()).to.equal('Foo'); | ||
}); | ||
it('shows 2 InfoTooltipWithTrigger', () => { | ||
expect(wrapper.find(InfoTooltipWithTrigger)).to.have.length(2); | ||
}); | ||
it('shows only 1 InfoTooltipWithTrigger when no descr', () => { | ||
props.column.description = null; | ||
wrapper = shallow(factory(props)); | ||
expect(wrapper.find(InfoTooltipWithTrigger)).to.have.length(1); | ||
}); | ||
it('shows a label with column_name when no verbose_name', () => { | ||
props.column.verbose_name = null; | ||
wrapper = shallow(factory(props)); | ||
expect(wrapper.find('.option-label').first().text()).to.equal('foo'); | ||
}); | ||
}); |
Oops, something went wrong.
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.
should this be
valueRenderer: opt => opt.value
?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.
This is a bit confusing but essentially the
optionRenderer
applies to what's in the dropdown and thevalueRenderer
applies to the selected item(s). It's nice to have this level of control, for instance we could show theexpression
behind the metric only on the selected metric, not in the list if we wanted to.So they both should show the label.