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.
Make Welcome page into a simple React app (apache#4147)
* Make Welcome page into a simple React app This removes a dependency on datatables, we should be able to get rid of it as we re-write the Table and PivotTable viz * tests/lint * Bump node version to latest
- Loading branch information
1 parent
e006fb7
commit c42866e
Showing
12 changed files
with
221 additions
and
93 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
This file was deleted.
Oops, something went wrong.
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,40 @@ | ||
import React from 'react'; | ||
import { Panel, Row, Col, FormControl } from 'react-bootstrap'; | ||
|
||
import DashboardTable from './DashboardTable'; | ||
|
||
export default class App extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
search: '', | ||
}; | ||
this.onSearchChange = this.onSearchChange.bind(this); | ||
} | ||
onSearchChange(event) { | ||
this.setState({ search: event.target.value }); | ||
} | ||
render() { | ||
return ( | ||
<div className="container welcome"> | ||
<Panel> | ||
<Row> | ||
<Col md={8}><h2>Dashboards</h2></Col> | ||
<Col md={4}> | ||
<FormControl | ||
type="text" | ||
bsSize="sm" | ||
style={{ marginTop: '25px' }} | ||
placeholder="Search" | ||
value={this.state.search} | ||
onChange={this.onSearchChange} | ||
/> | ||
</Col> | ||
</Row> | ||
<hr /> | ||
<DashboardTable search={this.state.search} /> | ||
</Panel> | ||
</div> | ||
); | ||
} | ||
} |
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,71 @@ | ||
/* eslint no-unused-vars: 0 */ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import PropTypes from 'prop-types'; | ||
import { Table, Tr, Td, Thead, Th, unsafe } from 'reactable'; | ||
|
||
import '../../stylesheets/reactable-pagination.css'; | ||
|
||
const $ = window.$ = require('jquery'); | ||
|
||
const propTypes = { | ||
search: PropTypes.string, | ||
}; | ||
|
||
export default class DashboardTable extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
dashboards: false, | ||
}; | ||
} | ||
componentDidMount() { | ||
const url = ( | ||
'/dashboardmodelviewasync/api/read' + | ||
'?_oc_DashboardModelViewAsync=changed_on' + | ||
'&_od_DashboardModelViewAsync=desc'); | ||
$.getJSON(url, (data) => { | ||
this.setState({ dashboards: data.result }); | ||
}); | ||
} | ||
render() { | ||
if (this.state.dashboards) { | ||
return ( | ||
<Table | ||
className="table" | ||
sortable={['dashboard', 'creator', 'modified']} | ||
filterBy={this.props.search} | ||
filterable={['dashboard', 'creator']} | ||
itemsPerPage={50} | ||
hideFilterInput | ||
columns={[ | ||
{ key: 'dashboard', label: 'Dashboard' }, | ||
{ key: 'creator', label: 'Creator' }, | ||
{ key: 'modified', label: 'Modified' }, | ||
]} | ||
defaultSort={{ column: 'modified', direction: 'desc' }} | ||
> | ||
{this.state.dashboards.map(o => ( | ||
<Tr key={o.id}> | ||
<Td column="dashboard" value={o.dashboard_title}> | ||
<a href={o.url}>{o.dashboard_title}</a> | ||
</Td> | ||
<Td column="creator" value={o.changed_by_name}> | ||
{unsafe(o.creator)} | ||
</Td> | ||
<Td column="modified" value={o.changed_on} className="text-muted"> | ||
{unsafe(o.modified)} | ||
</Td> | ||
</Tr>))} | ||
</Table> | ||
); | ||
} | ||
return ( | ||
<img | ||
className="loading" | ||
alt="Loading..." | ||
src="/static/assets/images/loading.gif" | ||
/>); | ||
} | ||
} | ||
DashboardTable.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* eslint no-unused-vars: 0 */ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { Panel, Row, Col, FormControl } from 'react-bootstrap'; | ||
|
||
import { appSetup } from '../common'; | ||
import App from './App'; | ||
|
||
appSetup(); | ||
|
||
const container = document.getElementById('app'); | ||
const bootstrap = JSON.parse(container.getAttribute('data-bootstrap')); | ||
|
||
ReactDOM.render( | ||
<App />, | ||
container, | ||
); |
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,22 @@ | ||
import React from 'react'; | ||
import { Panel, Col, Row } from 'react-bootstrap'; | ||
import { shallow } from 'enzyme'; | ||
import { describe, it } from 'mocha'; | ||
import { expect } from 'chai'; | ||
|
||
import App from '../../../javascripts/welcome/App'; | ||
|
||
describe('App', () => { | ||
const mockedProps = {}; | ||
it('is valid', () => { | ||
expect( | ||
React.isValidElement(<App {...mockedProps} />), | ||
).to.equal(true); | ||
}); | ||
it('renders 2 Col', () => { | ||
const wrapper = shallow(<App {...mockedProps} />); | ||
expect(wrapper.find(Panel)).to.have.length(1); | ||
expect(wrapper.find(Row)).to.have.length(1); | ||
expect(wrapper.find(Col)).to.have.length(2); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
superset/assets/spec/javascripts/welcome/DashboardTable_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,31 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { describe, it } from 'mocha'; | ||
import { expect } from 'chai'; | ||
|
||
import DashboardTable from '../../../javascripts/welcome/DashboardTable'; | ||
|
||
const $ = window.$ = require('jquery'); | ||
|
||
|
||
describe('DashboardTable', () => { | ||
const mockedProps = {}; | ||
let stub; | ||
beforeEach(() => { | ||
stub = sinon.stub($, 'getJSON'); | ||
}); | ||
afterEach(() => { | ||
stub.restore(); | ||
}); | ||
|
||
it('is valid', () => { | ||
expect( | ||
React.isValidElement(<DashboardTable {...mockedProps} />), | ||
).to.equal(true); | ||
}); | ||
it('renders', () => { | ||
const wrapper = mount(<DashboardTable {...mockedProps} />); | ||
expect(stub.callCount).to.equal(1); | ||
expect(wrapper.find('img')).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
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 was deleted.
Oops, something went wrong.
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