Skip to content
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

Flux/send query to dashboard #4229

Merged
merged 11 commits into from
Aug 22, 2018
Merged

Flux/send query to dashboard #4229

merged 11 commits into from
Aug 22, 2018

Conversation

AlirieGray
Copy link
Contributor

@AlirieGray AlirieGray commented Aug 15, 2018

Closes #4142

What was the problem?
The user experience of the Data Explorer and the Cell Editor Overlay was similar but not consistent, so that users were using the Data Explorer to create queries but then had to switch to the Dashboards page in order to put that query into a cell.

What was the solution?
These changes allow the user to create a query and press a button to create a cell with that query in one or more dashboards.

  • Rebased/mergeable
  • Tests pass
  • CHANGELOG.md updated

@AlirieGray AlirieGray force-pushed the flux/send-query-to-dashboard branch from ef268fe to 8dda5e3 Compare August 15, 2018 23:26
@AlirieGray AlirieGray requested a review from chnn August 16, 2018 17:18
@AlirieGray AlirieGray force-pushed the flux/send-query-to-dashboard branch 3 times, most recently from f040b38 to 94c5578 Compare August 16, 2018 18:28
class SendToDashboardOverlay extends PureComponent<Props, State> {
constructor(props) {
super(props)
const {queryConfig} = this.props
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nitpick) how about const {queryConfig} = props instead? it would be more consistent with the rest of the codebase


this.state = {
selectedIDs: [],
hasQuery: queryConfig.fields.length !== 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since fields is optional on a QueryConfig, it would be good to guard this property access with

  hasQuery: queryConfig.fields && queryConfig.fields.length !== 0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or via getDeep, if that's your style

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also just check if rawText (the query) is an empty string or if queryConfig is null. thoughts?

<OverlayHeading title="Send to Dashboard" />
<OverlayBody>
<div className="form-group">
<label htmlFor="New Cell Name"> New Cell Name </label>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had never seen for on a label before, that's cool. is it for screen readers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is, yeah

private get dropdownItems(): JSX.Element[] {
const {dashboards} = this.props

const simpleArray = dashboards.map(d => ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nitpick) this might read a bit easier if it's done all in one pass

    return dashboards.map(dashboard => {
      const id = dashboard.id.toString()

      return (
        <MultiSelectDropdown.Item key={id} id={id} value={id}>
          {dashboard.name}
        </MultiSelectDropdown.Item>
      )
    })

const {dashboards} = this.props
const {selectedIDs} = this.state

return dashboards.filter(d => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nitpick) I think this can be done in one line with dashboards.filter(d => selectedIDs.includes(d.id.toString()))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! very clean

const {query} = qs.parse(location.search, {ignoreQueryPrefix: true})
await handleGetDashboards()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before making this request, could you check if dashboards are already in the redux store? it would be great to avoid making this request unless we absolutely have to, since it's quite expensive (it loads every cell for every dashboard as well).

<GraphTips />
<div
className="btn btn-sm btn-default"
<button
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a great Button reusable ui component that you could use here

@@ -231,6 +256,12 @@ export class DataExplorer extends PureComponent<Props, State> {
</>
)
}

private toggleSendToDashboard = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nitpick) how about toggleIsSendToDashboardVisible instead? seems more explicit

@@ -265,6 +298,8 @@ const mapDispatchToProps = dispatch => {
dataExplorerActionCreators,
dispatch
),
handleGetDashboards: bindActionCreators(getDashboardsAsync, dispatch),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nitpick) this isn't consistent across the codebase (not even used here) but I've been digging the following naming convention lately:

  • callbacks passed as props are named like onFoo
  • callbacks defined and used within the same class are named like handleFoo

so in this case it would be onHandleGetDashboards and onAddDashboardCell

Copy link
Contributor

@chnn chnn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

I had a bunch of pedantic style-related suggestions while reading through. Please feel free to ignore these types of comments if they seem unreasonable.

I did pull down the branch and check it out. Is there a design for this overlay?

screen shot 2018-08-16 at 1 27 49 pm

Is it going to get styled in this PR or another?

@AlirieGray AlirieGray force-pushed the flux/send-query-to-dashboard branch 6 times, most recently from 4dc8ec8 to 77b013d Compare August 22, 2018 17:35
@AlirieGray AlirieGray force-pushed the flux/send-query-to-dashboard branch from 77b013d to ad9b9c8 Compare August 22, 2018 17:40
@AlirieGray AlirieGray merged commit 02f9108 into master Aug 22, 2018
@AlirieGray AlirieGray deleted the flux/send-query-to-dashboard branch August 22, 2018 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants