-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding column type label to dropdowns (#4566)
* Adding column type label to dropdowns * Changing the style of column type label * Adding tests for ColumnTypeLabel * Adding tests for time and fixing if statement order * Changing location of ColumnTypeLabel tests * Updating ColumnTypeLabel structure
- Loading branch information
1 parent
6875868
commit 3f1dfb3
Showing
9 changed files
with
155 additions
and
17 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
33 changes: 33 additions & 0 deletions
33
superset/assets/javascripts/components/ColumnTypeLabel.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 PropTypes from 'prop-types'; | ||
|
||
const propTypes = { | ||
type: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default function ColumnTypeLabel({ type }) { | ||
let stringIcon = ''; | ||
if (type === '' || type === 'expression') { | ||
stringIcon = 'ƒ'; | ||
} else if (type.match(/.*char.*/i) || type.match(/string.*/i) || type.match(/.*text.*/i)) { | ||
stringIcon = 'ABC'; | ||
} else if (type.match(/.*int.*/i) || type === 'LONG' || type === 'DOUBLE') { | ||
stringIcon = '#'; | ||
} else if (type.match(/.*bool.*/i)) { | ||
stringIcon = 'T/F'; | ||
} else if (type.match(/.*time.*/i)) { | ||
stringIcon = 'time'; | ||
} else if (type.match(/unknown/i)) { | ||
stringIcon = '?'; | ||
} | ||
|
||
const typeIcon = stringIcon === 'time' ? | ||
<i className="fa fa-clock-o type-label" /> : | ||
<div className="type-label">{stringIcon}</div>; | ||
|
||
return ( | ||
<span> | ||
{typeIcon} | ||
</span>); | ||
} | ||
ColumnTypeLabel.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
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
52 changes: 52 additions & 0 deletions
52
superset/assets/spec/javascripts/components/ColumnTypeLabel_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,52 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import ColumnTypeLabel from '../../../javascripts/components/ColumnTypeLabel'; | ||
|
||
describe('ColumnOption', () => { | ||
const defaultProps = { | ||
type: 'string', | ||
}; | ||
|
||
const props = { ...defaultProps }; | ||
|
||
function getWrapper(overrides) { | ||
const wrapper = shallow(<ColumnTypeLabel {...props} {...overrides} />); | ||
return wrapper; | ||
} | ||
|
||
it('is a valid element', () => { | ||
expect(React.isValidElement(<ColumnTypeLabel {...defaultProps} />)).to.equal(true); | ||
}); | ||
it('string type shows ABC icon', () => { | ||
const lbl = getWrapper({}).find('.type-label'); | ||
expect(lbl).to.have.length(1); | ||
expect(lbl.first().text()).to.equal('ABC'); | ||
}); | ||
it('int type shows # icon', () => { | ||
const lbl = getWrapper({ type: 'int(164)' }).find('.type-label'); | ||
expect(lbl).to.have.length(1); | ||
expect(lbl.first().text()).to.equal('#'); | ||
}); | ||
it('bool type shows T/F icon', () => { | ||
const lbl = getWrapper({ type: 'BOOL' }).find('.type-label'); | ||
expect(lbl).to.have.length(1); | ||
expect(lbl.first().text()).to.equal('T/F'); | ||
}); | ||
it('expression type shows function icon', () => { | ||
const lbl = getWrapper({ type: 'expression' }).find('.type-label'); | ||
expect(lbl).to.have.length(1); | ||
expect(lbl.first().text()).to.equal('ƒ'); | ||
}); | ||
it('unknown type shows question mark', () => { | ||
const lbl = getWrapper({ type: 'unknown' }).find('.type-label'); | ||
expect(lbl).to.have.length(1); | ||
expect(lbl.first().text()).to.equal('?'); | ||
}); | ||
it('unknown type shows question mark', () => { | ||
const lbl = getWrapper({ type: 'datetime' }).find('.fa-clock-o'); | ||
expect(lbl).to.have.length(1); | ||
}); | ||
}); |
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