Skip to content

Commit

Permalink
chore: type src/addSlice (#10127)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Ritter authored Jun 22, 2020
1 parent 231c2b3 commit cb1705f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
* under the License.
*/
import React from 'react';
import { shallow } from 'enzyme';
import { shallow, ShallowWrapper } from 'enzyme';
import { Button } from 'react-bootstrap';
import Select from 'src/components/Select';
import AddSliceContainer from 'src/addSlice/AddSliceContainer';
import AddSliceContainer, {
AddSliceContainerProps,
AddSliceContainerState,
} from 'src/addSlice/AddSliceContainer';
import VizTypeControl from 'src/explore/components/controls/VizTypeControl';

const defaultProps = {
Expand All @@ -31,7 +34,11 @@ const defaultProps = {
};

describe('AddSliceContainer', () => {
let wrapper;
let wrapper: ShallowWrapper<
AddSliceContainerProps,
AddSliceContainerState,
AddSliceContainer
>;

beforeEach(() => {
wrapper = shallow(<AddSliceContainer {...defaultProps} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,35 @@
* under the License.
*/
import React from 'react';
import PropTypes from 'prop-types';
import { Button, Panel } from 'react-bootstrap';
import Select from 'src/components/Select';
import { t } from '@superset-ui/translation';

import VizTypeControl from '../explore/components/controls/VizTypeControl';

const propTypes = {
datasources: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.string.isRequired,
value: PropTypes.string.isRequired,
}),
).isRequired,
interface Datasource {
label: string;
value: string;
}

export type AddSliceContainerProps = {
datasources: Datasource[];
};

export type AddSliceContainerState = {
datasourceId?: string;
datasourceType?: string;
datasourceValue?: string;
visType: string;
};

const styleSelectWidth = { width: 600 };

export default class AddSliceContainer extends React.PureComponent {
constructor(props) {
export default class AddSliceContainer extends React.PureComponent<
AddSliceContainerProps,
AddSliceContainerState
> {
constructor(props: AddSliceContainerProps) {
super(props);
this.state = {
visType: 'table',
Expand All @@ -61,15 +70,15 @@ export default class AddSliceContainer extends React.PureComponent {
window.location.href = this.exploreUrl();
}

changeDatasource(e) {
changeDatasource(option: { value: string }) {
this.setState({
datasourceValue: e.value,
datasourceId: e.value.split('__')[0],
datasourceType: e.value.split('__')[1],
datasourceValue: option.value,
datasourceId: option.value.split('__')[0],
datasourceType: option.value.split('__')[1],
});
}

changeVisType(visType) {
changeVisType(visType: string) {
this.setState({ visType });
}

Expand Down Expand Up @@ -97,7 +106,13 @@ export default class AddSliceContainer extends React.PureComponent {
options={this.props.datasources}
placeholder={t('Choose a datasource')}
style={styleSelectWidth}
value={this.state.datasourceValue}
value={
this.state.datasourceValue
? {
value: this.state.datasourceValue,
}
: undefined
}
width={600}
/>
</div>
Expand Down Expand Up @@ -141,5 +156,3 @@ export default class AddSliceContainer extends React.PureComponent {
);
}
}

AddSliceContainer.propTypes = propTypes;
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ setupPlugins();

const addSliceContainer = document.getElementById('js-add-slice-container');
const bootstrapData = JSON.parse(
addSliceContainer.getAttribute('data-bootstrap'),
addSliceContainer?.getAttribute('data-bootstrap') || '{}',
);

const App = () => (
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion superset-frontend/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const config = {
entry: {
theme: path.join(APP_DIR, '/src/theme.ts'),
preamble: PREAMBLE,
addSlice: addPreamble('/src/addSlice/index.jsx'),
addSlice: addPreamble('/src/addSlice/index.tsx'),
explore: addPreamble('/src/explore/index.jsx'),
dashboard: addPreamble('/src/dashboard/index.jsx'),
sqllab: addPreamble('/src/SqlLab/index.jsx'),
Expand Down

0 comments on commit cb1705f

Please sign in to comment.