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

Signed-off-by: Ryan Wang <i@ryanc.cc>
  • Loading branch information
ruibaby committed Sep 25, 2023
1 parent 5fa0056 commit 1968bdb
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions console/src/modules/system/plugins/PluginDetail.vue
Original file line number Diff line number Diff line change
@@ -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 1968bdb

Please sign in to comment.