Fix empty menu (fix #3610)

This commit is contained in:
the1812 2022-08-25 22:43:32 +08:00
parent afff711f96
commit 5f42af8a29
3 changed files with 20 additions and 5 deletions

View File

@ -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',

View File

@ -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: {

View File

@ -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<VueModule>
}
export type ComponentAction = (metadata: ComponentMetadata)
=> ComponentConfigAction | ComponentVueAction
const builtInActions: ComponentAction[] = [
metadata => ({