forked from halo-dev/halo
-
Notifications
You must be signed in to change notification settings - Fork 38
/
UninstallOperationItem.vue
86 lines (78 loc) · 2.46 KB
/
UninstallOperationItem.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<script lang="ts" setup>
import { Dialog, Toast, VDropdown, VDropdownItem } from "@halo-dev/components";
import type { Theme } from "@halo-dev/api-client";
import { useI18n } from "vue-i18n";
import { apiClient } from "@/utils/api-client";
import { useQueryClient } from "@tanstack/vue-query";
const { t } = useI18n();
const queryClient = useQueryClient();
const props = withDefaults(
defineProps<{
theme: Theme;
}>(),
{}
);
const handleUninstall = async (deleteExtensions?: boolean) => {
Dialog.warning({
title: `${
deleteExtensions
? t("core.theme.operations.uninstall_and_delete_config.title")
: t("core.theme.operations.uninstall.title")
}`,
description: t("core.common.dialog.descriptions.cannot_be_recovered"),
confirmText: t("core.common.buttons.confirm"),
cancelText: t("core.common.buttons.cancel"),
onConfirm: async () => {
try {
await apiClient.extension.theme.deletethemeHaloRunV1alpha1Theme({
name: props.theme.metadata.name,
});
// delete theme setting and configMap
if (deleteExtensions) {
const { settingName, configMapName } = props.theme.spec;
if (settingName) {
await apiClient.extension.setting.deletev1alpha1Setting(
{
name: settingName,
},
{
mute: true,
}
);
}
if (configMapName) {
await apiClient.extension.configMap.deletev1alpha1ConfigMap(
{
name: configMapName,
},
{
mute: true,
}
);
}
}
Toast.success(t("core.common.toast.uninstall_success"));
} catch (e) {
console.error("Failed to uninstall theme", e);
} finally {
queryClient.invalidateQueries({ queryKey: ["installed-themes"] });
}
},
});
};
</script>
<template>
<VDropdown placement="right" :triggers="['click']">
<VDropdownItem type="danger">
{{ $t("core.common.buttons.uninstall") }}
</VDropdownItem>
<template #popper>
<VDropdownItem type="danger" @click="handleUninstall()">
{{ $t("core.common.buttons.uninstall") }}
</VDropdownItem>
<VDropdownItem type="danger" @click="handleUninstall(true)">
{{ $t("core.theme.operations.uninstall_and_delete_config.button") }}
</VDropdownItem>
</template>
</VDropdown>
</template>