-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sqllab] surfacing more table metadata (indices, pk, fks) (#1485)
* Expose more table/column metadata * [sqllab] expose more table metadata * more tests
- Loading branch information
1 parent
76499af
commit 61509bb
Showing
9 changed files
with
195 additions
and
28 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
caravel/assets/javascripts/SqlLab/components/ColumnElement.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,59 @@ | ||
import React from 'react'; | ||
|
||
import { OverlayTrigger, Tooltip } from 'react-bootstrap'; | ||
|
||
const propTypes = { | ||
column: React.PropTypes.object.isRequired, | ||
}; | ||
|
||
const iconMap = { | ||
pk: 'fa-key', | ||
fk: 'fa-link', | ||
index: 'fa-bookmark', | ||
}; | ||
const tooltipTitleMap = { | ||
pk: 'Primary Key', | ||
fk: 'Foreign Key', | ||
index: 'Index', | ||
}; | ||
|
||
class ColumnElement extends React.PureComponent { | ||
render() { | ||
const col = this.props.column; | ||
let name = col.name; | ||
let icons; | ||
if (col.keys && col.keys.length > 0) { | ||
name = <strong>{col.name}</strong>; | ||
icons = col.keys.map((key, i) => ( | ||
<span key={i} className="ColumnElement"> | ||
<OverlayTrigger | ||
placement="right" | ||
overlay={ | ||
<Tooltip id="idx-json" bsSize="lg"> | ||
<strong>{tooltipTitleMap[key.type]}</strong> | ||
<hr /> | ||
<pre className="text-small"> | ||
{JSON.stringify(key, null, ' ')} | ||
</pre> | ||
</Tooltip> | ||
} | ||
> | ||
<i className={`fa text-muted m-l-2 ${iconMap[key.type]}`} /> | ||
</OverlayTrigger> | ||
</span> | ||
)); | ||
} | ||
return ( | ||
<div className="clearfix table-column"> | ||
<div className="pull-left m-l-10 col-name"> | ||
{name}{icons} | ||
</div> | ||
<div className="pull-right text-muted"> | ||
<small> {col.type}</small> | ||
</div> | ||
</div>); | ||
} | ||
} | ||
ColumnElement.propTypes = propTypes; | ||
|
||
export default ColumnElement; |
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
35 changes: 35 additions & 0 deletions
35
caravel/assets/spec/javascripts/sqllab/ColumnElement_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,35 @@ | ||
import React from 'react'; | ||
import ColumnElement from '../../../javascripts/SqlLab/components/ColumnElement'; | ||
import { mockedActions, table } from './fixtures'; | ||
import { mount } from 'enzyme'; | ||
import { describe, it } from 'mocha'; | ||
import { expect } from 'chai'; | ||
|
||
|
||
describe('ColumnElement', () => { | ||
const mockedProps = { | ||
actions: mockedActions, | ||
column: table.columns[0], | ||
}; | ||
it('is valid with props', () => { | ||
expect( | ||
React.isValidElement(<ColumnElement {...mockedProps} />) | ||
).to.equal(true); | ||
}); | ||
it('renders a proper primary key', () => { | ||
const wrapper = mount(<ColumnElement column={table.columns[0]} />); | ||
expect(wrapper.find('i.fa-key')).to.have.length(1); | ||
expect(wrapper.find('.col-name').first().text()).to.equal('id'); | ||
}); | ||
it('renders a multi-key column', () => { | ||
const wrapper = mount(<ColumnElement column={table.columns[1]} />); | ||
expect(wrapper.find('i.fa-link')).to.have.length(1); | ||
expect(wrapper.find('i.fa-bookmark')).to.have.length(1); | ||
expect(wrapper.find('.col-name').first().text()).to.equal('first_name'); | ||
}); | ||
it('renders a column with no keys', () => { | ||
const wrapper = mount(<ColumnElement column={table.columns[2]} />); | ||
expect(wrapper.find('i')).to.have.length(0); | ||
expect(wrapper.find('.col-name').first().text()).to.equal('last_name'); | ||
}); | ||
}); |
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