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

UI: Add plugin uninstall button #4182

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { GridActionsCellItem } from '@mui/x-data-grid';
import React from 'react';
import { useUninstallPluginMutation } from '@/redux/features/api/agentPlugins/agentPluginEndpoints';
import MonkeyLoadingIcon from '@/_components/icons/MonkeyLoadingIcon';
import { PluginId, PluginInfo } from '@/redux/features/api/agentPlugins/types';
import DeleteIcon from '@mui/icons-material/Delete';

const PluginUninstallButton = (props: PluginInfo) => {
const [uninstallPlugin, { isLoading: isUninstalling }] =
useUninstallPluginMutation();

const onUninstallClick = () => {
uninstallPlugin(props);
};

const UninstallButton = () => {
return (
<GridActionsCellItem
key={props.pluginId + 'uninstall'}
icon={<DeleteIcon />}
label="Uninstall"
onClick={() => onUninstallClick()}
/>
);
};

if (isUninstalling) {
return UninstallInProgressButton(props.pluginId);
} else {
return UninstallButton();
}
};

const UninstallInProgressButton = (pluginId: PluginId) => {
return (
<GridActionsCellItem
key={pluginId}
icon={<MonkeyLoadingIcon />}
label="Uninstalling"
/>
);
};

export default PluginUninstallButton;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Grid from '@mui/material/Grid';
import { InstalledPlugin } from '@/redux/features/api/agentPlugins/types';
import InstalledPluginFilters from '@/app/(protected)/plugins/installed/InstalledPluginFilters';
import PluginUpgradeButton from '@/app/(protected)/plugins/installed/PluginUpgradeButton';
import PluginUninstallButton from '@/app/(protected)/plugins/installed/PluginUninstallButton';

export default function InstalledPluginsPage() {
const {
Expand All @@ -31,9 +32,15 @@ export default function InstalledPluginsPage() {
);
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const getUninstallAction = (plugin: InstalledPlugin) => {
return [];
return (
<PluginUninstallButton
pluginType={plugin.pluginType}
pluginName={plugin.name}
pluginVersion={plugin.version}
pluginId={plugin.id}
/>
);
};

const getRowActions = (row: PluginRow) => {
Expand All @@ -42,7 +49,7 @@ export default function InstalledPluginsPage() {
(installedPlugin) => installedPlugin.id === row.id
);
if (!plugin) return [];
return [getUpgradeAction(plugin)];
return [getUpgradeAction(plugin), getUninstallAction(plugin)];
};

const getOverlayMessage = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum BackendEndpoints {
PLUGIN_INDEX = '/agent-plugins/available/index',
PLUGIN_INDEX_FORCE_REFRESH = `${BackendEndpoints.PLUGIN_INDEX}?force_refresh=true`,
PLUGIN_INSTALL = '/install-agent-plugin',
PLUGIN_UNINSTALL = '/uninstall-agent-plugin',
PLUGIN_MANIFESTS = '/agent-plugins/installed/manifests'
}

Expand Down Expand Up @@ -100,6 +101,17 @@ export const agentPluginEndpoints = islandApiSlice.injectEndpoints({
}
}),
invalidatesTags: ['InstalledAgentPlugins']
}),
uninstallPlugin: builder.mutation<any, PluginInfo>({
query: (pluginInfo: PluginInfo) => ({
url: BackendEndpoints.PLUGIN_UNINSTALL,
method: HTTP_METHODS.POST,
body: {
plugin_type: pluginInfo.pluginType,
name: pluginInfo.pluginName
}
}),
invalidatesTags: ['InstalledAgentPlugins']
})
})
});
Expand All @@ -109,5 +121,6 @@ export const {
useGetInstalledPluginsQuery,
useInstallPluginMutation,
useUploadPluginMutation,
useGetLatestPluginVersionQuery
useGetLatestPluginVersionQuery,
useUninstallPluginMutation
} = agentPluginEndpoints;