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

Explore: List query templates #86897

Merged
merged 62 commits into from
May 14, 2024
Merged

Explore: List query templates #86897

merged 62 commits into from
May 14, 2024

Conversation

ifrost
Copy link
Contributor

@ifrost ifrost commented Apr 24, 2024

Fixes #86122

For testing please use Query Library App plugin, or create some templates by posting requests directly to the API:

Screen.Recording.2024-04-26.at.14.11.11.mov

Changes:

  • Shows the list of query templates
  • Displayed columns:
    • the name of the data source, title, and the query
    • data source type
    • date added
  • Basic error handling

Out of scope:

Follow-ups:

# Conflicts:
#	docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md
#	packages/grafana-data/src/types/featureToggles.gen.ts
#	pkg/services/featuremgmt/registry.go
#	pkg/services/featuremgmt/toggles_gen.csv
#	pkg/services/featuremgmt/toggles_gen.go
#	pkg/services/featuremgmt/toggles_gen.json
This is required to have better UI and an indication of selected state in split view
This is to make it consistent with the toolbar button
This is to avoid confusing UX with 2 button triggering the drawer but with slightly different behavior
To avoid confusion for current users and test it internally a bit more it's behind a feature toggle. Bigger drawer may obstruct the view and add more friction in the UX.
The test was failing because queryLibraryAvailable was set to true for tests. This change makes it more explicit what use case is being tested
# Conflicts:
#	pkg/services/featuremgmt/toggles_gen.json
This is just moved from the app. To be cleaned up and refactored later.
# Conflicts:
#	packages/grafana-data/src/types/featureToggles.gen.ts
#	pkg/services/featuremgmt/registry.go
#	pkg/services/featuremgmt/toggles_gen.csv
#	pkg/services/featuremgmt/toggles_gen.go
#	pkg/services/featuremgmt/toggles_gen.json
# Conflicts:
#	public/app/features/explore/QueriesDrawer/QueriesDrawerDropdown.tsx
#	public/app/features/explore/RichHistory/RichHistory.tsx
It will be moved to the kebab
Just to simplify the PR, it's not needed for Explore yet.
@ifrost ifrost requested review from a team as code owners April 29, 2024 12:37
@ifrost ifrost requested review from ashharrison90, tskarhed and leventebalogh and removed request for a team April 29, 2024 12:37
Copy link
Contributor

@gelicia gelicia left a comment

Choose a reason for hiding this comment

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

Scaffolding looks great, confirmed by adding a query to the library app and seeing it in Explore! Exciting stuff!

@ifrost
Copy link
Contributor Author

ifrost commented Apr 30, 2024

@grafana/grafana-frontend-platform I'm not 100% how to correctly add a dependency to grafana/runtime. What I'm trying to achieve is to expose the ApiProvider and React hooks from RTK Query to plugins. I want to use it in core (Explore) and in an Application Plugin (Query Library). It requires reactjs/toolkit (for RTK Query) to work, which depends on on a peer dependency of react-redux, which depends on react-is. If I don't add @reactjs/redux or react-redux to dependencies/peerDependencies in grafana-runtime I get this error when bulding grafana-runtime:

[!] Error: 'isValidElementType' is not exported by ../../node_modules/react-is/index.js, imported by ../../node_modules/react-redux/es/components/connect.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
../../node_modules/react-redux/es/components/connect.js (8:9)
 6: import hoistStatics from 'hoist-non-react-statics';
 7: import * as React from 'react';
 8: import { isValidElementType, isContextConsumer } from 'react-is';
             ^
 9: import defaultSelectorFactory from '../connect/selectorFactory';
10: import { mapDispatchToPropsFactory } from '../connect/mapDispatchToProps';
Error: 'isValidElementType' is not exported by ../../node_modules/react-is/index.js, imported by ../../node_modules/react-redux/es/components/connect.js
    at error (/Users/ifrost/projects/grafana/node_modules/rollup/dist/shared/rollup.js:198:30)
    at Module.error (/Users/ifrost/projects/grafana/node_modules/rollup/dist/shared/rollup.js:12560:16)
    at Module.traceVariable (/Users/ifrost/projects/grafana/node_modules/rollup/dist/shared/rollup.js:12919:29)
    at ModuleScope.findVariable (/Users/ifrost/projects/grafana/node_modules/rollup/dist/shared/rollup.js:11571:39)
    at FunctionScope.findVariable (/Users/ifrost/projects/grafana/node_modules/rollup/dist/shared/rollup.js:6503:38)
    at ChildScope.findVariable (/Users/ifrost/projects/grafana/node_modules/rollup/dist/shared/rollup.js:6503:38)
    at ReturnValueScope.findVariable (/Users/ifrost/projects/grafana/node_modules/rollup/dist/shared/rollup.js:6503:38)
    at ChildScope.findVariable (/Users/ifrost/projects/grafana/node_modules/rollup/dist/shared/rollup.js:6503:38)
    at Identifier.bind (/Users/ifrost/projects/grafana/node_modules/rollup/dist/shared/rollup.js:7570:40)
    at CallExpression.bind (/Users/ifrost/projects/grafana/node_modules/rollup/dist/shared/rollup.js:5400:23)

The error is coming from rollup which should be able to resolve the dependency from the parent but it fails 🤔

Not sure why though, maybe because react-is resolves dependency conditionally?

if (process.env.NODE_ENV === 'production') {
  module.exports = require('./cjs/react-is.production.min.js');
} else {
  module.exports = require('./cjs/react-is.development.js');
}

Adding dependency/peerDependency cause the module to be marked as external (via externals rollup plugin) and it's bundled correctly, but I'm not sure if that's the right way of doing this 🤔

@gelicia
Copy link
Contributor

gelicia commented May 7, 2024

Had a chat with @ashharrison90 and @joshhunt about this - unfortunately this PR is in the middle of two unknown and emerging practices that the frontend platform team is working on - both app platform and a common interface for generating endpoints. They would ideally like some of the code that is handwritten in here to be generated, to provide guardrails and shape to minimize the possibility of API instability between releases.

If this ends up taking long enough where it becomes a blocker, we can look into marking the query library API as internal and making extremely clear it is unstable and moving forward with it. I communicated to them that I don't consider myself blocked at the moment and it could wait, and I would just work off this branch.

Cc: @ifrost

@ifrost ifrost requested a review from tolzhabayev as a code owner May 10, 2024 12:11
@ifrost ifrost requested a review from gelicia May 13, 2024 08:15
@ifrost
Copy link
Contributor Author

ifrost commented May 13, 2024

After having a chat with @grafana/grafana-frontend-platform we have decided to move this functionality back to core and used it from there until there's a consenus reached on how such APIs should be exposed.

Related issues/prs/docs:

@ifrost ifrost merged commit fd218ed into main May 14, 2024
14 checks passed
@ifrost ifrost deleted the ifrost/list-query-templates branch May 14, 2024 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/explore area/frontend no-changelog Skip including change in changelog/release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explore: Load Query Library items
2 participants