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

Datasource: Fix - apply default query also to queries in new panels #59625

Merged
merged 3 commits into from Dec 5, 2022

Conversation

sunker
Copy link
Contributor

@sunker sunker commented Dec 1, 2022

What is this feature?

This PR attempts to fix a problem @mmandrus found in this PR, where the default query is only applied when new query rows are added but not when new panels are created.

Will add tests if this turns out to be the right approach.

Why do we need this feature?

This feature is useful because it allows datasources to define a default query without having to call onChange the first time the editor is rendered.

Who is this feature for?

Plugin developers.

Fixes #59689
Related to #49581
cc @idastambuk

@@ -9,6 +9,27 @@ export const getNextRefIdChar = (queries: DataQuery[]): string => {
}
};

export function queryIsEmpty(query: DataQuery): boolean {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check does not feel future proof as it doesn't take new props into consideration. Any ideas of how to make this more robust?

Copy link
Member

Choose a reason for hiding this comment

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

is this not the same as just doing Object.keys(query).length === 0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently this function is checking if the query has prop that is not defined in the DataQuery interface. So basically if it the data source has called onChange for the given query.

};

for (const key in query) {
if (key === 'label') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also seems like the query runner adds this label prop to the query. I have no idea where this is coming from.

@sunker sunker changed the title Datasource: Fix - apply default query also to new panels Datasource: Fix - apply default query also to queries in new panels Dec 1, 2022
@grafanabot
Copy link
Contributor

Hello @sunker!
Backport pull requests need to be either:

  • Pull requests which address bugs,
  • Urgent fixes which need product approval, in order to get merged,
  • Docs changes.

Please, if the current pull request addresses a bug fix, label it with the type/bug label.
If it already has the product approval, please add the product-approved label. For docs changes, please add the type/docs label.
If none of the above applies, please consider removing the backport label and target the next major/minor release.
Thanks!

@sunker sunker merged commit 32309a8 into main Dec 5, 2022
@sunker sunker deleted the default-query-fix branch December 5, 2022 14:44
@grafanabot
Copy link
Contributor

The backport to v9.3.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-59625-to-v9.3.x origin/v9.3.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x 32309a8373fbcf276b24e319010e5ba57818bd9e
# Push it to GitHub
git push --set-upstream origin backport-59625-to-v9.3.x
git switch main
# Remove the local backport branch
git branch -D backport-59625-to-v9.3.x

Then, create a pull request where the base branch is v9.3.x and the compare/head branch is backport-59625-to-v9.3.x.

@grafanabot grafanabot added the backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. label Dec 5, 2022
sunker added a commit that referenced this pull request Dec 5, 2022
…59625)

* apply default query also to new panels

* add comment

* add tests

(cherry picked from commit 32309a8)
sunker added a commit that referenced this pull request Dec 6, 2022
… panels (#59833)

Datasource: Fix - apply default query also to queries in new panels (#59625)

* apply default query also to new panels

* add comment

* add tests

(cherry picked from commit 32309a8)
GuYounes pushed a commit to paul-wurth/BIXpert that referenced this pull request Feb 8, 2023
… panels (grafana#59833)

Datasource: Fix - apply default query also to queries in new panels (grafana#59625)

* apply default query also to new panels

* add comment

* add tests

(cherry picked from commit 32309a8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/frontend backport v9.3.x backport-failed Failed to generate backport PR. Please resolve conflicts and create one manually. enterprise-failed type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Datasource: Default query not applied when creating new panels
3 participants