From bbfb211408bbc7ed00d10bfe40866553eebd07dd Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Mon, 27 Sep 2021 07:50:56 -0400 Subject: [PATCH] Plugins Catalog: update the available panels on install/uninstall (#39293) (#39405) * feat(Plugins/Admin): add a function to update panels * fix(Plugins/Admin): update the available panels on plugin install / uninstall (cherry picked from commit c8e94a2443141590cfe8651b28d6d9618bcebb76) Co-authored-by: Levente Balogh --- public/app/features/plugins/admin/helpers.ts | 12 +++++++++++- public/app/features/plugins/admin/state/actions.ts | 11 +++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/public/app/features/plugins/admin/helpers.ts b/public/app/features/plugins/admin/helpers.ts index 667c89d6223..e6c9b460916 100644 --- a/public/app/features/plugins/admin/helpers.ts +++ b/public/app/features/plugins/admin/helpers.ts @@ -1,8 +1,10 @@ import { config } from '@grafana/runtime'; import { gt } from 'semver'; import { PluginSignatureStatus, dateTimeParse, PluginError } from '@grafana/data'; -import { CatalogPlugin, LocalPlugin, RemotePlugin } from './types'; import { contextSrv } from 'app/core/services/context_srv'; +import { getBackendSrv } from 'app/core/services/backend_srv'; +import { Settings } from 'app/core/config'; +import { CatalogPlugin, LocalPlugin, RemotePlugin } from './types'; export function isGrafanaAdmin(): boolean { return config.bootData.user.isGrafanaAdmin; @@ -221,3 +223,11 @@ function groupErrorsByPluginId(errors: PluginError[] = []): Record); } + +// Updates the core Grafana config to have the correct list available panels +export const updatePanels = () => + getBackendSrv() + .get('/api/frontend/settings') + .then((settings: Settings) => { + config.panels = settings.panels; + }); diff --git a/public/app/features/plugins/admin/state/actions.ts b/public/app/features/plugins/admin/state/actions.ts index 67db4275c71..33eba69813e 100644 --- a/public/app/features/plugins/admin/state/actions.ts +++ b/public/app/features/plugins/admin/state/actions.ts @@ -5,6 +5,7 @@ import { StoreState, ThunkResult } from 'app/types'; import { importPanelPlugin } from 'app/features/plugins/plugin_loader'; import { getCatalogPlugins, getPluginDetails, installPlugin, uninstallPlugin } from '../api'; import { STATE_PREFIX } from '../constants'; +import { updatePanels } from '../helpers'; import { CatalogPlugin } from '../types'; export const fetchAll = createAsyncThunk(`${STATE_PREFIX}/fetchAll`, async (_, thunkApi) => { @@ -28,16 +29,16 @@ export const fetchDetails = createAsyncThunk(`${STATE_PREFIX}/fetchDetails`, asy } }); +// We are also using the install API endpoint to update the plugin export const install = createAsyncThunk( `${STATE_PREFIX}/install`, async ({ id, version, isUpdating = false }: { id: string; version: string; isUpdating?: boolean }, thunkApi) => { const changes = isUpdating ? { isInstalled: true, hasUpdate: false } : { isInstalled: true }; try { await installPlugin(id, version); - return { - id, - changes, - } as Update; + await updatePanels(); + + return { id, changes } as Update; } catch (e) { return thunkApi.rejectWithValue('Unknown error.'); } @@ -47,6 +48,8 @@ export const install = createAsyncThunk( export const uninstall = createAsyncThunk(`${STATE_PREFIX}/uninstall`, async (id: string, thunkApi) => { try { await uninstallPlugin(id); + await updatePanels(); + return { id, changes: { isInstalled: false },