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

Type DataFrame in panel with panel's custom options #53938

Open
joshhunt opened this issue Aug 19, 2022 · 0 comments
Open

Type DataFrame in panel with panel's custom options #53938

joshhunt opened this issue Aug 19, 2022 · 0 comments
Labels
area/schema Related to canonical Grafana entity schemas mob-friendly A good issue to be worked on by mob prio/future Used by the dashboards squad to prioritise their backlog team/grafana-dashboards Dashboards squad

Comments

@joshhunt
Copy link
Contributor

Panel plugins define custom options for controlling the panel's behaviour. We specify these schemas with cue, and generate typescript interfaces from them.

At the moment, panel components use the PanelProps<PanelOptions> interface, which types the options property via the generic, but panel options can also be present in the DataFrames (because field overrides can set different options per frame/series/field). We should update the type of the DataFrame to accept a TOptions generic to type this as well.

This is useful because at the moment panels must use type assertions to change the type to their specific panel options https://github.com/grafana/grafana/blob/a87c6853453c51b3c5e1159b94d44f60dc97e81a/public/app/plugins/panel/heatmap/utils.ts/#L260-L261

I'm not 100% certain on the best way to do this, but we could rely on codegen as much as possible to reduce the chance for inconsistency between plugins. I'm also not sure what level of change we need above plugins, when we generate overrides and pass them to plugins.

Possible tasks:

  • Make the default TOptions more specific than just any in FieldConfig. Perhaps unknown, or Record<string, unknown>.
    • This change would need to flow up to any consuming types:
  • Type DataFrame to accept generic type argument to pass through to FieldConfig.
    • This change would need to flow from DataFrame > Field > FieldConfig
    • It should have a default type that matches the above change.
  • Codegen convenience types that implement the above to reduce the chance for developers to pass in the wrong panel options interface.

Going further:

  • Investigate whether it's possible (or helpful) to type the panel options builder to ensure that the builder produces panel options that are compatible with the schema. It should not be possible to use the panel options builder to produce a Wrong set of options, or miss a field.
@joshhunt joshhunt added the area/schema Related to canonical Grafana entity schemas label Aug 19, 2022
@natellium natellium added the team/grafana-dashboards Dashboards squad label Jun 23, 2023
@natellium natellium added the prio/future Used by the dashboards squad to prioritise their backlog label Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/schema Related to canonical Grafana entity schemas mob-friendly A good issue to be worked on by mob prio/future Used by the dashboards squad to prioritise their backlog team/grafana-dashboards Dashboards squad
Projects
Status: 📝 Backlog
Development

No branches or pull requests

2 participants