diff --git a/console/src/modules/system/plugins/composables/use-plugin.ts b/console/src/modules/system/plugins/composables/use-plugin.ts
index 7605592a6..78fb379f2 100644
--- a/console/src/modules/system/plugins/composables/use-plugin.ts
+++ b/console/src/modules/system/plugins/composables/use-plugin.ts
@@ -143,3 +143,101 @@ export function usePluginLifeCycle(
uninstall,
};
}
+
+export function usePluginBatchOperations(names: Ref) {
+ const { t } = useI18n();
+
+ function handleUninstallInBatch(deleteExtensions: boolean) {
+ Dialog.warning({
+ title: `${
+ deleteExtensions
+ ? t(
+ "core.plugin.operations.uninstall_and_delete_config_in_batch.title"
+ )
+ : t("core.plugin.operations.uninstall_in_batch.title")
+ }`,
+ description: t("core.common.dialog.descriptions.cannot_be_recovered"),
+ confirmType: "danger",
+ confirmText: t("core.common.buttons.uninstall"),
+ cancelText: t("core.common.buttons.cancel"),
+ onConfirm: async () => {
+ try {
+ for (let i = 0; i < names.value.length; i++) {
+ await apiClient.extension.plugin.deletepluginHaloRunV1alpha1Plugin({
+ name: names.value[i],
+ });
+
+ if (deleteExtensions) {
+ const { data: plugin } =
+ await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin(
+ {
+ name: names.value[i],
+ }
+ );
+
+ const { settingName, configMapName } = plugin.spec;
+
+ if (settingName) {
+ await apiClient.extension.setting.deletev1alpha1Setting(
+ {
+ name: settingName,
+ },
+ {
+ mute: true,
+ }
+ );
+ }
+
+ if (configMapName) {
+ await apiClient.extension.configMap.deletev1alpha1ConfigMap(
+ {
+ name: configMapName,
+ },
+ {
+ mute: true,
+ }
+ );
+ }
+ }
+ }
+
+ window.location.reload();
+ } catch (e) {
+ console.error("Failed to uninstall plugin in batch", e);
+ }
+ },
+ });
+ }
+
+ function handleChangeStatusInBatch(enabled: boolean) {
+ Dialog.info({
+ title: enabled
+ ? t("core.plugin.operations.change_status_in_batch.activate_title")
+ : t("core.plugin.operations.change_status_in_batch.inactivate_title"),
+ confirmText: t("core.common.buttons.confirm"),
+ cancelText: t("core.common.buttons.cancel"),
+ onConfirm: async () => {
+ try {
+ for (let i = 0; i < names.value.length; i++) {
+ const { data: pluginToUpdate } =
+ await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin({
+ name: names.value[i],
+ });
+
+ pluginToUpdate.spec.enabled = enabled;
+ await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({
+ name: pluginToUpdate.metadata.name,
+ plugin: pluginToUpdate,
+ });
+ }
+
+ window.location.reload();
+ } catch (e) {
+ console.error("Failed to change plugin status in batch", e);
+ }
+ },
+ });
+ }
+
+ return { handleUninstallInBatch, handleChangeStatusInBatch };
+}