refactor: remove the confirmation box of the enable/disable plugin (#4472)

#### What type of PR is this?

/area console
/kind improvement
/milestone 2.9.x

#### What this PR does / why we need it:

移除启动/停止插件的确认弹框。

#### Which issue(s) this PR fixes:

Fixes #4471 

#### Special notes for your reviewer:

测试启动和停止插件是否正常工作即可。

#### Does this PR introduce a user-facing change?

```release-note
移除 Console 端启动/停止插件的确认弹框。
```
pull/4461/head^2
Ryan Wang 2023-08-25 04:26:13 -05:00 committed by GitHub
parent 70eb039468
commit 7a057679da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 39 deletions

View File

@ -736,9 +736,6 @@ core:
uninstall_when_enabled: uninstall_when_enabled:
confirm_text: Stop running and uninstall confirm_text: Stop running and uninstall
description: The current plugin is still in the enabled state and will be uninstalled after it stops running. This operation cannot be undone. description: The current plugin is still in the enabled state and will be uninstalled after it stops running. This operation cannot be undone.
change_status:
active_title: Are you sure you want to active this plugin?
inactive_title: Are you sure you want to inactive this plugin?
remote_download: remote_download:
title: Remote download address detected, do you want to download? title: Remote download address detected, do you want to download?
description: "Please carefully verify whether this address can be trusted: {url}" description: "Please carefully verify whether this address can be trusted: {url}"

View File

@ -736,9 +736,6 @@ core:
uninstall_when_enabled: uninstall_when_enabled:
confirm_text: 停止运行并卸载 confirm_text: 停止运行并卸载
description: 当前插件还在启用状态,将在停止运行后卸载,该操作不可恢复。 description: 当前插件还在启用状态,将在停止运行后卸载,该操作不可恢复。
change_status:
active_title: 确定要启用该插件吗?
inactive_title: 确定要停用该插件吗?
remote_download: remote_download:
title: 检测到了远程下载地址,是否需要下载? title: 检测到了远程下载地址,是否需要下载?
description: 请仔细鉴别此地址是否可信:{url} description: 请仔细鉴别此地址是否可信:{url}

View File

@ -736,9 +736,6 @@ core:
uninstall_when_enabled: uninstall_when_enabled:
confirm_text: 停止運行並卸載 confirm_text: 停止運行並卸載
description: 當前插件還在啟用狀態,將在停止運行後卸載,該操作不可恢復。 description: 當前插件還在啟用狀態,將在停止運行後卸載,該操作不可恢復。
change_status:
active_title: 確定要啟用該插件嗎?
inactive_title: 確定要停用該插件嗎?
remote_download: remote_download:
title: 偵測到遠端下載地址,是否需要下載? title: 偵測到遠端下載地址,是否需要下載?
description: 請仔細鑑別此地址是否可信:{url} description: 請仔細鑑別此地址是否可信:{url}

View File

@ -40,7 +40,7 @@ const emit = defineEmits<{
const { plugin } = toRefs(props); const { plugin } = toRefs(props);
const { getFailedMessage, changeStatus, uninstall } = const { getFailedMessage, changeStatus, changingStatus, uninstall } =
usePluginLifeCycle(plugin); usePluginLifeCycle(plugin);
const handleResetSettingConfig = async () => { const handleResetSettingConfig = async () => {
@ -205,6 +205,7 @@ const { dropdownItems } = useEntityDropdownItemExtensionPoint<Plugin>(
<div class="flex items-center"> <div class="flex items-center">
<VSwitch <VSwitch
:model-value="plugin?.spec.enabled" :model-value="plugin?.spec.enabled"
:disabled="changingStatus"
@click="changeStatus" @click="changeStatus"
/> />
</div> </div>

View File

@ -1,5 +1,5 @@
import type { ComputedRef, Ref } from "vue"; import type { ComputedRef, Ref } from "vue";
import { computed } from "vue"; import { computed, ref } from "vue";
import type { Plugin } from "@halo-dev/api-client"; import type { Plugin } from "@halo-dev/api-client";
import cloneDeep from "lodash.clonedeep"; import cloneDeep from "lodash.clonedeep";
import { apiClient } from "@/utils/api-client"; import { apiClient } from "@/utils/api-client";
@ -10,6 +10,7 @@ interface usePluginLifeCycleReturn {
isStarted: ComputedRef<boolean | undefined>; isStarted: ComputedRef<boolean | undefined>;
getFailedMessage: () => string | undefined; getFailedMessage: () => string | undefined;
changeStatus: () => void; changeStatus: () => void;
changingStatus: Ref<boolean>;
uninstall: (deleteExtensions?: boolean) => void; uninstall: (deleteExtensions?: boolean) => void;
} }
@ -36,37 +37,25 @@ export function usePluginLifeCycle(
} }
}; };
const changeStatus = () => { const changingStatus = ref(false);
const changeStatus = async () => {
if (!plugin?.value) return; if (!plugin?.value) return;
const pluginToUpdate = cloneDeep(plugin.value);
Dialog.info({
title: pluginToUpdate.spec.enabled
? t("core.plugin.operations.change_status.inactive_title")
: t("core.plugin.operations.change_status.active_title"),
confirmText: t("core.common.buttons.confirm"),
cancelText: t("core.common.buttons.cancel"),
onConfirm: async () => {
try { try {
changingStatus.value = true;
const pluginToUpdate = cloneDeep(plugin.value);
pluginToUpdate.spec.enabled = !pluginToUpdate.spec.enabled; pluginToUpdate.spec.enabled = !pluginToUpdate.spec.enabled;
await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({ await apiClient.extension.plugin.updatepluginHaloRunV1alpha1Plugin({
name: pluginToUpdate.metadata.name, name: pluginToUpdate.metadata.name,
plugin: pluginToUpdate, plugin: pluginToUpdate,
}); });
Toast.success( window.location.reload();
pluginToUpdate.spec.enabled
? t("core.common.toast.active_success")
: t("core.common.toast.inactive_success")
);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} finally { changingStatus.value = false;
window.location.reload();
} }
},
});
}; };
const uninstall = (deleteExtensions?: boolean) => { const uninstall = (deleteExtensions?: boolean) => {
@ -150,6 +139,7 @@ export function usePluginLifeCycle(
isStarted, isStarted,
getFailedMessage, getFailedMessage,
changeStatus, changeStatus,
changingStatus,
uninstall, uninstall,
}; };
} }