Files
Joseph Perez f9df1f3051 Docs: Plugins doc reorganization, part 1 (#69864)
* Initial commit

* Prettier fixes

* Doc-validator fixes part 1

* Doc-validator fixes part 2

* More doc-validator fixes

* More doc-validator fixes

* Test

* link test

* Linnk test

* Link test

* More fixes

* More fixes

* Doc-validator fixes

* Doc-validator fixes

* fix broken link

* Fix

* Testing

* Doc fixes

* Link fixes

* Fix links

* Update docs/sources/developers/plugins/create-a-grafana-plugin/_index.md

Co-authored-by: David Harris <david.harris@grafana.com>

* Testing

* Testing

* Testing

* Testing

* Doc-validator fixes

* Doc-validator fixes

* Doc-validator fixes

* Fix broken links for plugins reorganization project

* Prettier fixes

* Prettier fixes

* Incorporate reviewer feedback

* Link fixes

* Link fixes

* Link fixes

* Link fix

* Deleted space

* Codeowners fix

* Change grafana.com links to absolute URLs for Hugo

---------

Co-authored-by: David Harris <david.harris@grafana.com>
2023-07-05 13:25:11 -05:00

2.5 KiB
Raw Blame History

title menuTitle description keywords weight
Migrate a plugin from AngularJS to React Angular to React Guide for migrating plugins from AngularJS to React.
grafana
plugins
migration
plugin
documentation
1000

Migrate a plugin from AngularJS to React

If you want to migrate a plugin to Grafana's React-based plugin platform, then we recommend that you release it under a new major version. Consider keeping a release branch for the previous version to be able to roll out patch releases for versions prior to Grafana 7.

While there's no standard migration path from an Angular plugin to the new React platform, weve learned that one of the easiest ways to migrate is to:

  1. Create a new branch called migrate-to-react.
  2. Start from scratch with one of the templates provided by the create-plugin tool.
  3. Move the existing code into the new plugin incrementally, one component at a time.

Migrate a panel plugin

Starting with Grafana 7.0, plugins export a PanelPlugin from module.ts where MyPanelis a React component containing the props from PanelProps.

src/module.ts

import { PanelPlugin } from '@grafana/data';

export const plugin = new PanelPlugin<MyOptions>(MyPanel);

src/MyPanel.tsx

import { PanelProps } from '@grafana/data';

interface Props extends PanelProps<SimpleOptions> {}

export function MyPanel({ options, data, width, height }: Props) {
  // ...
}

Migrate a data source plugin

While all plugins are different, we'd like to share a migration process that has worked for some of our users.

  1. Define your configuration model and ConfigEditor. For many plugins, the configuration editor is the simplest component, so it's a good candidate to start with.
  2. Implement the testDatasource() method on the class that extends DataSourceApi. Use the settings in your configuration model to make sure that you can successfully configure and access the external API.
  3. Implement the query() method. At this point, you can hard-code your query, because we havent yet implemented the query editor. The query() method supports both the new data frame response and the old TimeSeries response, so dont worry about converting to the new format just yet.
  4. Implement the QueryEditor. How much work this requires depends on how complex your query model is.

By now, you should be able to release your new version.

To fully migrate to the new plugin platform, convert the time series response to a data frame response.