Skip to content

Commit

Permalink
fix: plugin self tab extension point not working when no setting defi…
Browse files Browse the repository at this point in the history
…nition (#4659)

#### What type of PR is this?

/area console
/kind bug
/milestone 2.10.x

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

修复当插件没有设置表单定义时,详情选项卡扩展点不生效的问题。

<img width="1061" alt="image" src="https://github.com/halo-dev/halo/assets/21301288/01abc565-a55e-40d5-9d2b-41a7eab2d9b5">

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

Fixes #4633

#### Special notes for your reviewer:

可以通过以下插件进行测试:

1. [plugin-migrate-1.2.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/halo/files/12713261/plugin-migrate-1.2.0-SNAPSHOT.jar.zip)
2. https://github.com/halo-dev/plugin-app-store/releases/tag/v1.0.0-alpha.4
3. https://github.com/halo-dev/plugin-s3

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

```release-note
None
```
  • Loading branch information
ruibaby committed Sep 25, 2023
1 parent 5fa0056 commit 927e45b
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions console/src/modules/system/plugins/PluginDetail.vue
@@ -1,6 +1,6 @@
<script lang="ts" setup>
// core libs
import { provide, ref, computed, onMounted } from "vue";
import { provide, ref, computed } from "vue";
import { useRoute } from "vue-router";
import { apiClient } from "@/utils/api-client";
Expand Down Expand Up @@ -50,6 +50,11 @@ const { data: plugin } = useQuery({
});
return data;
},
onSuccess(data) {
if (!data.spec.settingName) {
tabs.value = [...initialTabs.value, ...getTabsFromExtensions()];
}
},
});
provide<Ref<Plugin | undefined>>("plugin", plugin);
Expand All @@ -74,6 +79,7 @@ const { data: setting } = useQuery({
const { forms } = data.spec;
tabs.value = [
...initialTabs.value,
...getTabsFromExtensions(),
...forms.map((item: SettingForm) => {
return {
id: item.group,
Expand All @@ -88,29 +94,29 @@ const { data: setting } = useQuery({
provide<Ref<Setting | undefined>>("setting", setting);
onMounted(() => {
function getTabsFromExtensions(): PluginTab[] {
const { pluginModuleMap } = usePluginModuleStore();
const currentPluginModule = pluginModuleMap[route.params.name as string];
if (!currentPluginModule) {
return;
return [];
}
const { extensionPoints } = currentPluginModule;
if (!extensionPoints?.["plugin:self:tabs:create"]) {
return;
return [];
}
const extraTabs = extensionPoints["plugin:self:tabs:create"]() as PluginTab[];
const pluginTabs = extensionPoints[
"plugin:self:tabs:create"
]() as PluginTab[];
extraTabs.forEach((tab) => {
if (currentUserHasPermission(tab.permissions)) {
initialTabs.value.push(tab);
}
return pluginTabs.filter((tab) => {
return currentUserHasPermission(tab.permissions);
});
});
}
</script>
<template>
<VPageHeader :title="plugin?.spec?.displayName">
Expand Down

0 comments on commit 927e45b

Please sign in to comment.