Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

feat: add upgrade plugin support #663

Merged
merged 2 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@formkit/inputs": "^1.0.0-beta.11",
"@formkit/themes": "^1.0.0-beta.11",
"@formkit/vue": "^1.0.0-beta.11",
"@halo-dev/api-client": "^0.0.38",
"@halo-dev/api-client": "^0.0.39",
"@halo-dev/components": "workspace:*",
"@halo-dev/console-shared": "workspace:*",
"@halo-dev/richtext-editor": "^0.0.0-alpha.8",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/modules/interface/themes/components/ThemeListModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ const handleFetchThemes = async () => {
page: 0,
size: 0,
uninstalled: activeTab.value !== "installed",
page: 0,
size: 0,
});
themes.value = data.items;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { VModal } from "@halo-dev/components";
import FilePondUpload from "@/components/upload/FilePondUpload.vue";
import { apiClient } from "@/utils/api-client";
import { computed, mergeProps, ref } from "vue";
import { computed, ref } from "vue";
import type { Theme } from "@halo-dev/api-client";

const props = withDefaults(
Expand Down
6 changes: 3 additions & 3 deletions src/modules/system/plugins/PluginList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
VSpace,
} from "@halo-dev/components";
import PluginListItem from "./components/PluginListItem.vue";
import PluginInstallModal from "./components/PluginInstallModal.vue";
import PluginUploadModal from "./components/PluginUploadModal.vue";
import { onMounted, ref } from "vue";
import { apiClient } from "@/utils/api-client";
import type { PluginList } from "@halo-dev/api-client";
Expand Down Expand Up @@ -140,7 +140,7 @@ function handleSortItemChange(sortItem?: SortItem) {
}
</script>
<template>
<PluginInstallModal
<PluginUploadModal
v-if="currentUserHasPermission(['system:plugins:manage'])"
v-model:visible="pluginInstall"
@close="handleFetchPlugins"
Expand Down Expand Up @@ -306,7 +306,7 @@ function handleSortItemChange(sortItem?: SortItem) {
role="list"
>
<li v-for="(plugin, index) in plugins.items" :key="index">
<PluginListItem :plugin="plugin" />
<PluginListItem :plugin="plugin" @reload="handleFetchPlugins" />
</li>
</ul>

Expand Down
26 changes: 25 additions & 1 deletion src/modules/system/plugins/components/PluginListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
VEntityField,
VAvatar,
} from "@halo-dev/components";
import { toRefs } from "vue";
import PluginUploadModal from "./PluginUploadModal.vue";
import { ref, toRefs } from "vue";
import { usePluginLifeCycle } from "../composables/use-plugin";
import type { Plugin } from "@halo-dev/api-client";
import { formatDatetime } from "@/utils/date";
Expand All @@ -26,11 +27,26 @@ const props = withDefaults(
}
);
const emit = defineEmits<{
(event: "reload"): void;
}>();
const { plugin } = toRefs(props);
const upgradeModal = ref(false);
const { isStarted, changeStatus, uninstall } = usePluginLifeCycle(plugin);
const onUpgradeModalClose = () => {
emit("reload");
};
</script>
<template>
<PluginUploadModal
v-model:visible="upgradeModal"
:upgrade-plugin="plugin"
@close="onUpgradeModalClose"
/>
<VEntity>
<template #start>
<VEntityField>
Expand Down Expand Up @@ -108,6 +124,14 @@ const { isStarted, changeStatus, uninstall } = usePluginLifeCycle(plugin);
v-if="currentUserHasPermission(['system:plugins:manage'])"
#dropdownItems
>
<VButton
v-close-popper
block
type="secondary"
@click="upgradeModal = true"
>
升级
</VButton>
<VButton v-close-popper block type="danger" @click="uninstall">
卸载
</VButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import type { Plugin } from "@halo-dev/api-client";
import { computed, ref } from "vue";
import type { AxiosResponse } from "axios";

withDefaults(
const props = withDefaults(
defineProps<{
visible: boolean;
upgradePlugin?: Plugin;
}>(),
{
visible: false,
upgradePlugin: undefined,
}
);

Expand All @@ -22,6 +24,12 @@ const emit = defineEmits<{

const FilePondUploadRef = ref();

const modalTitle = computed(() => {
return props.upgradePlugin
? `升级插件(${props.upgradePlugin.spec.displayName})`
: "安装插件";
});

const handleVisibleChange = (visible: boolean) => {
emit("update:visible", visible);
if (!visible) {
Expand All @@ -31,6 +39,16 @@ const handleVisibleChange = (visible: boolean) => {
};

const uploadHandler = computed(() => {
if (props.upgradePlugin) {
return (file, config) =>
apiClient.plugin.upgradePlugin(
{
name: props.upgradePlugin.metadata.name as string,
file: file,
},
config
);
}
return (file, config) =>
apiClient.plugin.installPlugin(
{
Expand All @@ -41,6 +59,11 @@ const uploadHandler = computed(() => {
});

const onUploaded = async (response: AxiosResponse) => {
if (props.upgradePlugin) {
handleVisibleChange(false);
return;
}

const plugin = response.data as Plugin;
handleVisibleChange(false);
Dialog.success({
Expand Down Expand Up @@ -71,10 +94,11 @@ const onUploaded = async (response: AxiosResponse) => {
<VModal
:visible="visible"
:width="500"
title="安装插件"
:title="modalTitle"
@update:visible="handleVisibleChange"
>
<FilePondUpload
v-if="visible && uploadHandler"
ref="FilePondUploadRef"
:allow-multiple="false"
:handler="uploadHandler"
Expand Down