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

Plugins: Support for link extensions #61663

Merged
merged 50 commits into from Feb 7, 2023
Merged

Plugins: Support for link extensions #61663

merged 50 commits into from Feb 7, 2023

Conversation

mckn
Copy link
Contributor

@mckn mckn commented Jan 18, 2023

What is this feature?
This PR introduces an extensions registry that allows app plugins to extend core/plugins via plugin.json. It exposes a helper function for plugins/core to query the registry for extensions made by plugins allowing cross-plugin linking.

Links will only be registered if the app plugin defining the link:

  • Is installed.
  • Is enabled.
  • Defines the link that we try to generate.

Why do we need this feature?
Please read the epic for more details.

Who is this feature for?
Plugin developers, Grafana developers and end-users.

Example

Here is an example on how to extend Grafana with a link from a plugin. It will place a link in Grafana (grafana/sandbox/testing):

{
  "$schema": "https://raw.githubusercontent.com/grafana/grafana/b56bc15bf5129d6d7590a5e4dce9023a826c26a2/docs/sources/developers/plugins/plugin.schema.json",
  "type": "app",
  "name": "Basic App",
  "id": "myorg-app-basic",
  "info": {
    "keywords": ["basic", "app", "example"],
    "description": "A basic grafana app plugin",
    "author": {
      "name": "Your name"
    },
    "logos": {
      "small": "img/logo.svg",
      "large": "img/logo.svg"
    },
    "screenshots": [],
    "version": "%VERSION%",
    "updated": "%TODAY%"
  },
  "includes": [
    {
      "type": "page",
      "name": "Page One",
      "path": "/a/%PLUGIN_ID%/one",
      "role": "Admin",
      "addToNav": true,
      "defaultNav": true
    },
    {
      "type": "page",
      "name": "Page Two",
      "path": "/a/%PLUGIN_ID%/two",
      "role": "Admin",
      "addToNav": true,
      "defaultNav": false
    },
    {
      "type": "page",
      "name": "Page Three",
      "path": "/a/%PLUGIN_ID%/three",
      "role": "Admin",
      "addToNav": true,
      "defaultNav": false
    },
    {
      "type": "page",
      "name": "Page Four",
      "path": "/a/%PLUGIN_ID%/four",
      "role": "Admin",
      "addToNav": true,
      "defaultNav": false
    },
    {
      "type": "page",
      "icon": "cog",
      "name": "Configuration",
      "path": "/plugins/%PLUGIN_ID%",
      "role": "Admin",
      "addToNav": true
    }
  ],
  "extensions": [
    {
      "target": "grafana/sandbox/testing",
      "title": "Open thing",
      "path": "/one",
      "type": "link"
    }
  ],
  "dependencies": {
    "grafanaDependency": ">=9.1.2",
    "plugins": []
  }
}

const { extensions, error } = getPluginExtensions({ target });


⚠️   Possible breaking changes

(Open the links below in a new tab to go to the correct steps)

grafana-data has possible breaking changes (more info)grafana-runtime has possible breaking changes (more info)

Console output Read our guideline

This is due to removal of the preload plugins types. It got replaced by the AppConfig types and should not have been used by plugin authors.

@mckn mckn marked this pull request as ready for review January 20, 2023 15:13
@mckn mckn requested review from a team as code owners January 20, 2023 15:13
@mckn mckn marked this pull request as draft February 1, 2023 11:16
@mckn mckn removed the levitate breaking change A label indicating a breaking change and assigned by Levitate. label Feb 6, 2023
@mckn mckn marked this pull request as ready for review February 6, 2023 13:20
@sdboyer sdboyer dismissed their stale review February 6, 2023 14:16

Resolved in discussions

@sdboyer
Copy link
Contributor

sdboyer commented Feb 6, 2023

my concerns are resolved, so i'm getting my review out of the way!

@mckn mckn requested a review from torkelo February 6, 2023 14:24
@grafanabot grafanabot added the levitate breaking change A label indicating a breaking change and assigned by Levitate. label Feb 7, 2023
@mckn mckn merged commit 1cfd3f8 into main Feb 7, 2023
@mckn mckn deleted the mckn/ui-extensions-link branch February 7, 2023 16:20
@DanCech
Copy link
Collaborator

DanCech commented Feb 7, 2023

Very cool!

The term "target" did throw me off initially since in html a link target refers to the name of the window the link should open in, whereas we're using it to mean the location that the link should be displayed.

ryantxu pushed a commit that referenced this pull request Mar 2, 2023
* added extensions to plugin.json and exposing it via frontend settings.

* added extensions to the plugin.json schema.

* changing the extensions in frontend settings to a map instead of an array.

* wip

* feat(pluginregistry): begin wiring up registry

* feat(pluginextensions): prevent duplicate links and clean up

* added test case for link extensions.

* added tests and implemented the getPluginLink function.

* wip

* feat(pluginextensions): expose plugin extension registry

* fix(pluginextensions): appease the typescript gods post rename

* renamed file and will throw error if trying to call setExtensionsRegistry if trying to call it twice.

* added reafactorings.

* fixed failing test.

* minor refactorings to make sure we only include extensions if the app is enabled.

* fixed some nits.

* Update public/app/features/plugins/extensions/registry.test.ts

Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>

* Update packages/grafana-runtime/src/services/pluginExtensions/registry.ts

Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>

* Update packages/grafana-runtime/src/services/pluginExtensions/registry.ts

Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>

* Update public/app/features/plugins/extensions/registry.test.ts

Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>

* Moved types for extensions from data to runtime.

* added a small example on how you could consume link extensions.

* renamed after feedback from levi.

* updated the plugindef.cue.

* using the generated plugin def.

* added tests for apps and extensions.

* fixed linting issues.

* wip

* wip

* wip

* wip

* test(extensions): fix up failing tests

* feat(extensions): freeze registry extension arrays, include type in registry items

* added restrictions in the pugindef cue schema.

* wip

* added required fields.

* added key to uniquely identify each item.

* test(pluginextensions): align tests with implementation

* chore(schema): refresh reference.md

---------

Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

10 participants