From 5f42af8a293a4d785577f9473d68557bb9680c46 Mon Sep 17 00:00:00 2001 From: the1812 Date: Thu, 25 Aug 2022 22:43:32 +0800 Subject: [PATCH] Fix empty menu (fix #3610) --- registry/lib/components/utils/dev-client/plugin.ts | 6 +++++- src/components/settings-panel/ComponentDetail.vue | 12 ++++++++++-- .../component-actions/component-actions.ts | 7 +++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/registry/lib/components/utils/dev-client/plugin.ts b/registry/lib/components/utils/dev-client/plugin.ts index 434fbefe7..d5a85d4b4 100644 --- a/registry/lib/components/utils/dev-client/plugin.ts +++ b/registry/lib/components/utils/dev-client/plugin.ts @@ -2,6 +2,7 @@ import { PluginSetupParameters } from '@/plugins/plugin' import { ComponentAction } from '@/components/settings-panel/component-actions/component-actions' import { isIframe } from '@/core/utils' import { LaunchBarAction, LaunchBarActionProvider } from '@/components/launch-bar/launch-bar-action' +import { autoUpdateOptions } from './options' export const setupPlugin = async ({ addData }: PluginSetupParameters) => { if (isIframe()) { @@ -9,7 +10,10 @@ export const setupPlugin = async ({ addData }: PluginSetupParameters) => { } addData('settingsPanel.componentActions', (actions: ComponentAction[]) => { actions.push( - () => { + component => { + if (!autoUpdateOptions.urls.components[component.name]) { + return undefined + } const ActionModule = () => import('./Action.vue') return { name: 'devClient', diff --git a/src/components/settings-panel/ComponentDetail.vue b/src/components/settings-panel/ComponentDetail.vue index 030946c5e..cf315ce80 100644 --- a/src/components/settings-panel/ComponentDetail.vue +++ b/src/components/settings-panel/ComponentDetail.vue @@ -108,7 +108,7 @@ import { ComponentOptions } from '../component' import ComponentDescription from './ComponentDescription.vue' import ComponentOption from './ComponentOption.vue' import { componentSettingsMixin } from './mixins' -import { componentActions } from './component-actions/component-actions' +import { componentActions, ComponentConfigAction } from './component-actions/component-actions' import ComponentAction from './component-actions/ComponentAction.vue' export default Vue.extend({ @@ -127,7 +127,15 @@ export default Vue.extend({ virtual: false, componentActions: componentActions .map(factory => factory((this as any).componentData)) - .filter(it => it !== undefined), + .filter(it => { + if (it === undefined) { + return false + } + if ((it as ComponentConfigAction).visible === false) { + return false + } + return true + }), } }, computed: { diff --git a/src/components/settings-panel/component-actions/component-actions.ts b/src/components/settings-panel/component-actions/component-actions.ts index 532bcfea5..cae35e0fc 100644 --- a/src/components/settings-panel/component-actions/component-actions.ts +++ b/src/components/settings-panel/component-actions/component-actions.ts @@ -5,7 +5,7 @@ import { isUserComponent } from '@/core/settings' import { ComponentMetadata } from '../../types' import { uninstallComponent } from '../../user-component' -export type ComponentAction = (metadata: ComponentMetadata) => { +export interface ComponentConfigAction { name: string displayName: string action: Executable @@ -13,10 +13,13 @@ export type ComponentAction = (metadata: ComponentMetadata) => { visible?: boolean title?: string // condition?: () => boolean -} | { +} +export interface ComponentVueAction { name: string component: Executable } +export type ComponentAction = (metadata: ComponentMetadata) + => ComponentConfigAction | ComponentVueAction const builtInActions: ComponentAction[] = [ metadata => ({