From e632ddac9a7e4d968f839589c4eef788f1567f3b Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Tue, 27 Sep 2022 15:46:15 +0800 Subject: [PATCH] feat: add deleting theme setting and configMap support (#621) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind feature /milestone 2.0 #### What this PR does / why we need it: 支持删除主题的时候删除对应的 Setting 和 ConfigMap 资源。 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/2325 #### Screenshots: image #### Special notes for your reviewer: 测试方式: 1. 安装一个带有设置项的主题并做一定的配置。 2. 选择**卸载并删除配置**的选项。 3. 重新安装主题,检查设置项是否已经恢复为默认。 #### Does this PR introduce a user-facing change? ```release-note 支持卸载主题时,删除对应的 Setting 和 ConfigMap 资源。 ``` --- .../themes/components/ThemeListModal.vue | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/modules/interface/themes/components/ThemeListModal.vue b/src/modules/interface/themes/components/ThemeListModal.vue index ca4f1c34..47b830b0 100644 --- a/src/modules/interface/themes/components/ThemeListModal.vue +++ b/src/modules/interface/themes/components/ThemeListModal.vue @@ -57,15 +57,38 @@ const handleFetchThemes = async () => { } }; -const handleUninstall = async (theme: Theme) => { +const handleUninstall = async (theme: Theme, deleteExtensions?: boolean) => { dialog.warning({ - title: "是否确定删除该主题?", + title: `${ + deleteExtensions + ? "是否确认删除该主题以及对应的配置?" + : "是否确认删除该主题?" + }`, description: "删除后将无法恢复。", onConfirm: async () => { try { await apiClient.extension.theme.deletethemeHaloRunV1alpha1Theme({ name: theme.metadata.name, }); + + // delete theme setting and configMap + if (!deleteExtensions) { + return; + } + + const { settingName, configMapName } = theme.spec; + + if (settingName) { + await apiClient.extension.setting.deletev1alpha1Setting({ + name: settingName, + }); + } + + if (configMapName) { + await apiClient.extension.configMap.deletev1alpha1ConfigMap({ + name: configMapName, + }); + } } catch (e) { console.error("Failed to uninstall theme", e); } finally { @@ -224,6 +247,15 @@ defineExpose({ > 卸载 + + 卸载并删除配置 +