How can I enable the 'Paste panel' button using custom PanelModel?

Hello,

I would like to allow users to copy and paste panels from one dashboard to another.

I have written some custom logic that swaps out the template variables used in the dashboard & panel for the selected values, so that when a user copies the panel, they won’t need to re-define the variables again.

The only issue I have is that when copying the panel data the Paste panel option in the Add menu appears disabled. I have tried the following:

  1. Copying the data to my clipboard
  2. Calling the CopyPanelEvent class (this does nothing it seems)
  3. Looking through the docs to see how I can call the onCopyPanel function (not exposed).
  4. Looking at the HTTP API docs to see how I can trigger this to be enabled.

Is this possible currently?

I can see that the memoised const copiedPanelPlugin manages whether the button is disabled or not. Is it possible to interact with the redux store from the core grafana app to toggle this myself? Can I do this from within a panel plugin?

I figured this out. In the Grafana application, the Store class is actually just referencing window.localStorage. So I was able to store my PanelModel object there, using

window.localStorage['panel-copy'] = JSON.stringify(myPanelModel);

This in turn triggered the onCopyPanelPlugin() method, allowing me to use the in-built feature.