mirror of https://github.com/halo-dev/halo
fix: failed to change plugin status (#4506)
#### What type of PR is this? /area console /kind bug /milestone 2.9.x #### What this PR does / why we need it: 修复可能因为 version 锁的原因导致无法正常切换插件状态,现在改为在调用切换状态接口前,获取一次最新的插件信息,并提供了 retry 的配置,即失败之后重试 3 次。 #### Special notes for your reviewer: 测试能否正常切换插件状态即可。 #### Does this PR introduce a user-facing change? ```release-note None ```pull/4518/head^2
parent
a819296945
commit
22571367fa
|
@ -1,10 +1,11 @@
|
||||||
import type { ComputedRef, Ref } from "vue";
|
import type { ComputedRef, Ref } from "vue";
|
||||||
import { computed, ref } from "vue";
|
import { computed } 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";
|
||||||
import { Dialog, Toast } from "@halo-dev/components";
|
import { Dialog, Toast } from "@halo-dev/components";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
|
import { useMutation } from "@tanstack/vue-query";
|
||||||
|
|
||||||
interface usePluginLifeCycleReturn {
|
interface usePluginLifeCycleReturn {
|
||||||
isStarted: ComputedRef<boolean | undefined>;
|
isStarted: ComputedRef<boolean | undefined>;
|
||||||
|
@ -37,26 +38,28 @@ export function usePluginLifeCycle(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const changingStatus = ref(false);
|
const { isLoading: changingStatus, mutate: changeStatus } = useMutation({
|
||||||
|
mutationKey: ["change-plugin-status"],
|
||||||
|
mutationFn: async () => {
|
||||||
|
if (!plugin?.value) return;
|
||||||
|
|
||||||
const changeStatus = async () => {
|
const { data: pluginToUpdate } =
|
||||||
if (!plugin?.value) return;
|
await apiClient.extension.plugin.getpluginHaloRunV1alpha1Plugin({
|
||||||
|
name: plugin.value.metadata.name,
|
||||||
|
});
|
||||||
|
|
||||||
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,
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
retry: 3,
|
||||||
|
retryDelay: 1000,
|
||||||
|
onSuccess() {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
} catch (e) {
|
},
|
||||||
console.error(e);
|
});
|
||||||
changingStatus.value = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const uninstall = (deleteExtensions?: boolean) => {
|
const uninstall = (deleteExtensions?: boolean) => {
|
||||||
if (!plugin?.value) return;
|
if (!plugin?.value) return;
|
||||||
|
|
Loading…
Reference in New Issue