Skip to content

Commit

Permalink
[v10.1.x] Plugins: Refresh plugin info after installation (#75225)
Browse files Browse the repository at this point in the history
Plugins: Refresh plugin info after installation (#75074)

(cherry picked from commit 6600dd2)

Co-authored-by: Hugo Kiyodi Oshiro <hugo.oshiro@grafana.com>
  • Loading branch information
grafana-delivery-bot[bot] and oshirohugo committed Sep 22, 2023
1 parent 1bb4a72 commit 354c6a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Expand Up @@ -9,7 +9,14 @@ import { useQueryParams } from 'app/core/hooks/useQueryParams';
import { removePluginFromNavTree } from 'app/core/reducers/navBarTree';
import { useDispatch } from 'app/types';

import { useInstallStatus, useUninstallStatus, useInstall, useUninstall, useUnsetInstall } from '../../state/hooks';
import {
useInstallStatus,
useUninstallStatus,
useInstall,
useUninstall,
useUnsetInstall,
useFetchDetailsLazy,
} from '../../state/hooks';
import { trackPluginInstalled, trackPluginUninstalled } from '../../tracking';
import { CatalogPlugin, PluginStatus, PluginTabIds, Version } from '../../types';

Expand All @@ -36,6 +43,7 @@ export function InstallControlsButton({
const install = useInstall();
const uninstall = useUninstall();
const unsetInstall = useUnsetInstall();
const fetchDetails = useFetchDetailsLazy();
const [isConfirmModalVisible, setIsConfirmModalVisible] = useState(false);
const showConfirmModal = () => setIsConfirmModalVisible(true);
const hideConfirmModal = () => setIsConfirmModalVisible(false);
Expand All @@ -57,6 +65,8 @@ export function InstallControlsButton({
const onInstall = async () => {
trackPluginInstalled(trackingProps);
const result = await install(plugin.id, latestCompatibleVersion?.version);
// refresh the store to have the new installed plugin
await fetchDetails(plugin.id);
if (!errorInstalling && !('error' in result)) {
appEvents.emit(AppEvents.alertSuccess, [`Installed ${plugin.name}`]);
if (plugin.type === 'app') {
Expand Down
6 changes: 6 additions & 0 deletions public/app/features/plugins/admin/state/hooks.ts
Expand Up @@ -133,6 +133,12 @@ export const useFetchDetails = (id: string) => {
}, [plugin]); // eslint-disable-line
};

export const useFetchDetailsLazy = () => {
const dispatch = useDispatch();

return (id: string) => dispatch(fetchDetails(id));
};

export const useDisplayMode = () => {
const dispatch = useDispatch();
const displayMode = useSelector(selectDisplayMode);
Expand Down

0 comments on commit 354c6a4

Please sign in to comment.