feat: add deleting plugin setting and configMap support

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/636/head
Ryan Wang 2022-10-10 17:04:32 +08:00
parent 95d58fbcdb
commit ca141d7da6
2 changed files with 30 additions and 4 deletions

View File

@ -107,6 +107,9 @@ const { isStarted, changeStatus, uninstall } = usePluginLifeCycle(plugin);
<VButton v-close-popper block type="danger" @click="uninstall">
卸载
</VButton>
<VButton v-close-popper block type="danger" @click="uninstall(true)">
卸载并删除配置
</VButton>
</template>
</VEntity>
</template>

View File

@ -8,7 +8,7 @@ import { useDialog } from "@halo-dev/components";
interface usePluginLifeCycleReturn {
isStarted: ComputedRef<boolean | undefined>;
changeStatus: () => void;
uninstall: () => void;
uninstall: (deleteExtensions?: boolean) => void;
}
export function usePluginLifeCycle(
@ -45,13 +45,17 @@ export function usePluginLifeCycle(
});
};
const uninstall = () => {
const uninstall = (deleteExtensions?: boolean) => {
if (!plugin?.value) return;
const { enabled } = plugin.value.spec;
dialog.warning({
title: `确定要卸载该插件吗?`,
title: `${
deleteExtensions
? "是否确认卸载该插件以及对应的配置?"
: "是否确认卸载该插件?"
}`,
description: `${
enabled ? "当前插件还在启用状态,将在停止运行后卸载。" : ""
}`,
@ -73,8 +77,27 @@ export function usePluginLifeCycle(
await apiClient.extension.plugin.deletepluginHaloRunV1alpha1Plugin({
name: plugin.value.metadata.name,
});
// delete plugin setting and configMap
if (!deleteExtensions) {
return;
}
const { settingName, configMapName } = plugin.value.spec;
if (settingName) {
await apiClient.extension.setting.deletev1alpha1Setting({
name: settingName,
});
}
if (configMapName) {
await apiClient.extension.configMap.deletev1alpha1ConfigMap({
name: configMapName,
});
}
} catch (e) {
console.error(e);
console.error("Failed to uninstall plugin", e);
} finally {
window.location.reload();
}