forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding rowcount label to explore view header (apache#4059)
- Loading branch information
1 parent
643091c
commit c4a7ae2
Showing
6 changed files
with
122 additions
and
7 deletions.
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
42 changes: 42 additions & 0 deletions
42
superset/assets/javascripts/explore/components/RowCountLabel.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,42 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Label } from 'react-bootstrap'; | ||
|
||
import { t } from '../../locales'; | ||
import { defaultNumberFormatter } from '../../modules/utils'; | ||
import TooltipWrapper from '../../components/TooltipWrapper'; | ||
|
||
|
||
const propTypes = { | ||
rowcount: PropTypes.number, | ||
limit: PropTypes.number, | ||
}; | ||
|
||
const defaultProps = { | ||
}; | ||
|
||
export default function RowCountLabel({ rowcount, limit }) { | ||
const limitReached = rowcount === limit; | ||
const bsStyle = (limitReached || rowcount === 0) ? 'warning' : 'default'; | ||
const formattedRowCount = defaultNumberFormatter(rowcount); | ||
const tooltip = ( | ||
<span> | ||
{limitReached && | ||
<div>{t('Limit reached')}</div>} | ||
{rowcount} | ||
</span> | ||
); | ||
return ( | ||
<TooltipWrapper label="tt-rowcount" tooltip={tooltip}> | ||
<Label | ||
bsStyle={bsStyle} | ||
style={{ fontSize: '10px', marginRight: '5px', cursor: 'pointer' }} | ||
> | ||
{formattedRowCount} rows | ||
</Label> | ||
</TooltipWrapper> | ||
); | ||
} | ||
|
||
RowCountLabel.propTypes = propTypes; | ||
RowCountLabel.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
33 changes: 33 additions & 0 deletions
33
superset/assets/spec/javascripts/explore/components/RowCountLabel_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,33 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
import { shallow } from 'enzyme'; | ||
import { Label } from 'react-bootstrap'; | ||
|
||
import TooltipWrapper from './../../../../javascripts/components/TooltipWrapper'; | ||
|
||
import RowCountLabel from '../../../../javascripts/explore/components/RowCountLabel'; | ||
|
||
describe('RowCountLabel', () => { | ||
const defaultProps = { | ||
rowcount: 51, | ||
limit: 100, | ||
}; | ||
|
||
it('is valid', () => { | ||
expect(React.isValidElement(<RowCountLabel {...defaultProps} />)).to.equal(true); | ||
}); | ||
it('renders a Label and a TooltipWrapper', () => { | ||
const wrapper = shallow(<RowCountLabel {...defaultProps} />); | ||
expect(wrapper.find(Label)).to.have.lengthOf(1); | ||
expect(wrapper.find(TooltipWrapper)).to.have.lengthOf(1); | ||
}); | ||
it('renders a warning when limit is reached', () => { | ||
const props = { | ||
rowcount: 100, | ||
limit: 100, | ||
}; | ||
const wrapper = shallow(<RowCountLabel {...props} />); | ||
expect(wrapper.find(Label).first().props().bsStyle).to.equal('warning'); | ||
}); | ||
}); |
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