-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Create Chart onClick Functionality #20809
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,9 @@ import { | |
SaveDatasetModal, | ||
} from 'src/SqlLab/components/SaveDatasetModal'; | ||
import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes'; | ||
import { EXPLORE_CHART_DEFAULT } from 'src/SqlLab/types'; | ||
import { mountExploreUrl } from 'src/explore/exploreUtils'; | ||
import { postFormData } from 'src/explore/exploreUtils/formData'; | ||
import ProgressBar from 'src/components/ProgressBar'; | ||
import Loading from 'src/components/Loading'; | ||
import FilterableTable, { | ||
|
@@ -41,6 +44,7 @@ import ExploreCtasResultsButton from '../ExploreCtasResultsButton'; | |
import ExploreResultsButton from '../ExploreResultsButton'; | ||
import HighlightedSql from '../HighlightedSql'; | ||
import QueryStateLabel from '../QueryStateLabel'; | ||
import { URL_PARAMS } from 'src/constants'; | ||
|
||
enum LIMITING_FACTOR { | ||
QUERY = 'QUERY', | ||
|
@@ -134,6 +138,8 @@ export default class ResultSet extends React.PureComponent< | |
this.reFetchQueryResults = this.reFetchQueryResults.bind(this); | ||
this.toggleExploreResultsButton = | ||
this.toggleExploreResultsButton.bind(this); | ||
this.createExploreResultsOnClick = | ||
this.createExploreResultsOnClick.bind(this); | ||
} | ||
|
||
async componentDidMount() { | ||
|
@@ -213,6 +219,26 @@ export default class ResultSet extends React.PureComponent< | |
} | ||
} | ||
|
||
async createExploreResultsOnClick() { | ||
const { results } = this.props.query; | ||
|
||
if (results.query_id) { | ||
const key = await postFormData(results.query_id, 'table', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the type should be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing I noticed with this await is that if you set your network speed in dev tools to slow 3G to represent a poor connection, the UI looks unresponsive after clicking the button. We could consider setting state before the await to trigger a re-render and show UI that indicates the user's button clicked is being processed. Not critical, and maybe a separate ticket, but these types of things often get missed in our local dev environment where responses are near instant and have no real world latency / bandwidth restrictions |
||
...EXPLORE_CHART_DEFAULT, | ||
datasource: `${results.query_id}__table`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type should be |
||
...{ | ||
all_columns: results.columns.map(column => column.name), | ||
}, | ||
}); | ||
const url = mountExploreUrl(null, { | ||
[URL_PARAMS.formDataKey.name]: key, | ||
}); | ||
window.open(url, '_blank', 'noreferrer'); | ||
} else { | ||
this.setState({ showSaveDatasetModal: true }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can remove this |
||
} | ||
} | ||
|
||
renderControls() { | ||
if (this.props.search || this.props.visualize || this.props.csv) { | ||
let { data } = this.props.query.results; | ||
|
@@ -250,19 +276,11 @@ export default class ResultSet extends React.PureComponent< | |
this.props.database?.allows_virtual_table_explore && ( | ||
<ExploreResultsButton | ||
database={this.props.database} | ||
onClick={() => { | ||
// There is currently redux / state issue where sometimes a query will have serverId | ||
// and other times it will not. We need this attribute consistently for this to work | ||
// const qid = this.props?.query?.results?.query_id; | ||
// if (qid) { | ||
// // This will open explore using the query as datasource | ||
// window.location.href = `/explore/?dataset_type=query&dataset_id=${qid}`; | ||
// } else { | ||
// this.setState({ showSaveDatasetModal: true }); | ||
// } | ||
this.setState({ showSaveDatasetModal: true }); | ||
}} | ||
onClick={() => this.setState({ showSaveDatasetModal: true })} | ||
/> | ||
// In order to use the new workflow for a query powered chart, replace the | ||
// above function with: | ||
// onClick={this.createExploreResultsOnClick} | ||
)} | ||
{this.props.csv && ( | ||
<Button buttonSize="small" href={`/superset/csv/${query.id}`}> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we use arrow function syntax here, you don't have to add the .bind call on line 141,142:
async createExploreResultsOnClick = () => {
Arrow functions automatically bind
this
to where the function is defined which has the same effect as callingthis.createExploreResultsOnClick = this.createExploreResultsOnClick.bind(this);
I have been updating files I work in to convert to arrow functions and remove the bind calls because it removes the second step and extra code.