fix: plugin settings manager Component optional & delete isBookmark (#3027)

This commit is contained in:
jack zhang 2023-11-13 12:21:40 +08:00 committed by GitHub
parent 83245a406b
commit 34d1406ede
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 10 deletions

View File

@ -1,5 +1,6 @@
import { set } from 'lodash'; import { set } from 'lodash';
import { createElement } from 'react'; import { createElement } from 'react';
import { Outlet } from 'react-router-dom';
import { Icon } from '../icon'; import { Icon } from '../icon';
import type { Application } from './Application'; import type { Application } from './Application';
@ -11,14 +12,16 @@ export const SNIPPET_PREFIX = 'pm.';
export interface PluginSettingsManagerSettingOptionsType { export interface PluginSettingsManagerSettingOptionsType {
title: string; title: string;
Component: RouteType['Component']; /**
* @default Outlet
*/
Component?: RouteType['Component'];
icon?: string; icon?: string;
/** /**
* sort, the smaller the number, the higher the priority * sort, the smaller the number, the higher the priority
* @default 0 * @default 0
*/ */
sort?: number; sort?: number;
isBookmark?: boolean;
aclSnippet?: string; aclSnippet?: string;
[index: string]: any; [index: string]: any;
} }
@ -32,7 +35,6 @@ export interface PluginSettingsPageType {
sort?: number; sort?: number;
name?: string; name?: string;
pluginName?: string; pluginName?: string;
isBookmark?: boolean;
children?: PluginSettingsPageType[]; children?: PluginSettingsPageType[];
[index: string]: any; [index: string]: any;
} }
@ -65,7 +67,7 @@ export class PluginSettingsManager {
add(name: string, options: PluginSettingsManagerSettingOptionsType) { add(name: string, options: PluginSettingsManagerSettingOptionsType) {
const nameArr = name.split('.'); const nameArr = name.split('.');
const pluginName = nameArr[0]; const pluginName = nameArr[0];
this.settings[name] = { ...options, name, pluginName }; this.settings[name] = { Component: Outlet, ...options, name, pluginName };
// add children // add children
if (nameArr.length > 1) { if (nameArr.length > 1) {
@ -75,7 +77,7 @@ export class PluginSettingsManager {
// add route // add route
this.app.router.add(this.getRouteName(name), { this.app.router.add(this.getRouteName(name), {
path: this.getRoutePath(name), path: this.getRoutePath(name),
Component: options.Component, Component: this.settings[name].Component,
}); });
} }

View File

@ -27,28 +27,23 @@ export class PMPlugin extends Plugin {
icon: 'LockOutlined', icon: 'LockOutlined',
Component: ACLPane, Component: ACLPane,
aclSnippet: 'pm.acl.roles', aclSnippet: 'pm.acl.roles',
isBookmark: true,
}); });
this.app.pluginSettingsManager.add('ui-schema-storage', { this.app.pluginSettingsManager.add('ui-schema-storage', {
title: '{{t("Block templates")}}', title: '{{t("Block templates")}}',
icon: 'LayoutOutlined', icon: 'LayoutOutlined',
Component: BlockTemplatesPane, Component: BlockTemplatesPane,
isBookmark: true,
aclSnippet: 'pm.ui-schema-storage.block-templates', aclSnippet: 'pm.ui-schema-storage.block-templates',
}); });
this.app.pluginSettingsManager.add('system-settings', { this.app.pluginSettingsManager.add('system-settings', {
icon: 'SettingOutlined', icon: 'SettingOutlined',
title: '{{t("System settings")}}', title: '{{t("System settings")}}',
Component: SystemSettingsPane, Component: SystemSettingsPane,
isBookmark: true,
aclSnippet: 'pm.system-settings.system-settings', aclSnippet: 'pm.system-settings.system-settings',
}); });
this.app.pluginSettingsManager.add('collection-manager', { this.app.pluginSettingsManager.add('collection-manager', {
icon: 'DatabaseOutlined', icon: 'DatabaseOutlined',
title: '{{t("Collection manager")}}', title: '{{t("Collection manager")}}',
Component: () => <Outlet />,
isBookmark: true,
}); });
this.app.pluginSettingsManager.add('collection-manager.collections', { this.app.pluginSettingsManager.add('collection-manager.collections', {