Skip to content

Commit

Permalink
Save modal component for explore v2 (apache#1612)
Browse files Browse the repository at this point in the history
* Added specs for SaveModal

* Move datasource_id and datasource_name to form_data

* Add comments

* Deleted redundant fetchDashboard

* Replcae has_key for python3

* More react and less jquery

* Added alert for save slice

* Small changes based on comments

* Use react bootstrap
  • Loading branch information
vera-liu authored Nov 18, 2016
1 parent dc25bc6 commit 38e94b9
Show file tree
Hide file tree
Showing 12 changed files with 392 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import classnames from 'classnames';
const propTypes = {
canAdd: PropTypes.string.isRequired,
onQuery: PropTypes.func.isRequired,
onSave: PropTypes.func,
};

export default function QueryAndSaveBtns({ canAdd, onQuery }) {
const defaultProps = {
onSave: () => {},
};

export default function QueryAndSaveBtns({ canAdd, onQuery, onSave }) {
const saveClasses = classnames('btn btn-default btn-sm', {
'disabled disabledButton': canAdd !== 'True',
});
Expand All @@ -21,6 +26,7 @@ export default function QueryAndSaveBtns({ canAdd, onQuery }) {
className={saveClasses}
data-target="#save_modal"
data-toggle="modal"
onClick={onSave}
>
<i className="fa fa-plus-circle"></i> Save as
</button>
Expand All @@ -29,3 +35,4 @@ export default function QueryAndSaveBtns({ canAdd, onQuery }) {
}

QueryAndSaveBtns.propTypes = propTypes;
QueryAndSaveBtns.defaultProps = defaultProps;
50 changes: 50 additions & 0 deletions superset/assets/javascripts/explorev2/actions/exploreActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,53 @@ export const REMOVE_CHART_ALERT = 'REMOVE_CHART_ALERT';
export function removeChartAlert() {
return { type: REMOVE_CHART_ALERT };
}

export const FETCH_DASHBOARDS_SUCCEEDED = 'FETCH_DASHBOARDS_SUCCEEDED';
export function fetchDashboardsSucceeded(choices) {
return { type: FETCH_DASHBOARDS_SUCCEEDED, choices };
}

export const FETCH_DASHBOARDS_FAILED = 'FETCH_DASHBOARDS_FAILED';
export function fetchDashboardsFailed(userId) {
return { type: FETCH_FAILED, userId };
}

export function fetchDashboards(userId) {
return function (dispatch) {
const url = '/dashboardmodelviewasync/api/read?_flt_0_owners=' + userId;
$.get(url, function (data, status) {
if (status === 'success') {
const choices = [];
for (let i = 0; i < data.pks.length; i++) {
choices.push({ value: data.pks[i], label: data.result[i].dashboard_title });
}
dispatch(fetchDashboardsSucceeded(choices));
} else {
dispatch(fetchDashboardsFailed(userId));
}
});
};
}

export const SAVE_SLICE_FAILED = 'SAVE_SLICE_FAILED';
export function saveSliceFailed() {
return { type: SAVE_SLICE_FAILED };
}

export const REMOVE_SAVE_MODAL_ALERT = 'REMOVE_SAVE_MODAL_ALERT';
export function removeSaveModalAlert() {
return { type: REMOVE_SAVE_MODAL_ALERT };
}

export function saveSlice(url) {
return function (dispatch) {
$.get(url, (data, status) => {
if (status === 'success') {
// Go to new slice url or dashboard url
window.location = data;
} else {
dispatch(saveSliceFailed());
}
});
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,4 @@ function mapStateToProps(state) {
};
}

function mapDispatchToProps() {
return {};
}

export default connect(mapStateToProps, mapDispatchToProps)(ChartContainer);
export default connect(mapStateToProps, () => ({}))(ChartContainer);
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ function mapStateToProps(state) {
alert: state.controlPanelAlert,
isDatasourceMetaLoading: state.isDatasourceMetaLoading,
fields: state.fields,
datasource_type: state.datasource_type,
form_data: state.viz.form_data,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as actions from '../actions/exploreActions';
import { connect } from 'react-redux';
import ChartContainer from './ChartContainer';
import ControlPanelsContainer from './ControlPanelsContainer';
import SaveModal from './SaveModal';
import QueryAndSaveBtns from '../../explore/components/QueryAndSaveBtns';
const $ = require('jquery');

Expand All @@ -20,6 +21,7 @@ class ExploreViewContainer extends React.Component {
super(props);
this.state = {
height: this.getHeight(),
showModal: false,
};
}

Expand Down Expand Up @@ -63,6 +65,10 @@ class ExploreViewContainer extends React.Component {
this.props.datasource_type, this.props.form_data.datasource, data);
}

toggleModal() {
this.setState({ showModal: !this.state.showModal });
}

render() {
return (
<div
Expand All @@ -72,16 +78,26 @@ class ExploreViewContainer extends React.Component {
overflow: 'hidden',
}}
>
{this.state.showModal &&
<SaveModal
onHide={this.toggleModal.bind(this)}
actions={this.props.actions}
form_data={this.props.form_data}
datasource_type={this.props.datasource_type}
/>
}
<div className="row">
<div className="col-sm-4">
<QueryAndSaveBtns
canAdd="True"
onQuery={this.onQuery.bind(this)}
onSave={this.toggleModal.bind(this)}
/>
<br /><br />
<ControlPanelsContainer
actions={this.props.actions}
form_data={this.props.form_data}
datasource_type={this.props.datasource_type}
/>
</div>
<div className="col-sm-8">
Expand Down Expand Up @@ -112,6 +128,5 @@ function mapDispatchToProps(dispatch) {
};
}

export { ControlPanelsContainer };

export { ExploreViewContainer };
export default connect(mapStateToProps, mapDispatchToProps)(ExploreViewContainer);
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ const propTypes = {
places: PropTypes.number,
validators: PropTypes.any,
onChange: React.PropTypes.func,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.array]).isRequired,
value: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
PropTypes.bool,
PropTypes.array]).isRequired,
};

const defaultProps = {
Expand Down
Loading

0 comments on commit 38e94b9

Please sign in to comment.