refactor: optimize context menu and clean @hera/plugin-core (#886)

Co-authored-by: sealday <sealday@gmail.com>
Reviewed-on: daoyoucloud/tachybase#886
This commit is contained in:
sealday 2024-04-29 01:48:06 +08:00
parent cfa2bc9775
commit f3bd122b57
4 changed files with 98 additions and 72 deletions

View File

@ -0,0 +1,59 @@
import { Plugin, useCollection } from '@nocobase/client';
import {
EditDefaultValue,
EditFormulaTitleField,
FilterVariableInput,
SetFilterScope,
useFormulaTitleVisible,
useSetFilterScopeVisible,
} from '../../schema-settings';
import { FilterFormItem, FilterFormItemCustom, FilterItemCustomDesigner } from '../../schema-initializer';
import { tval } from '../../locale';
import { useFilterBlockActionProps } from '../../hooks/useFilterBlockActionProps';
import { useFilterFormCustomProps } from '../../hooks/useFilterFormCustomProps';
export class PluginExtendedFilterForm extends Plugin {
async load() {
this.app.addScopes({
useFilterBlockActionProps,
useFilterFormCustomProps,
});
this.app.addComponents({
FilterFormItem,
FilterFormItemCustom,
FilterItemCustomDesigner,
FilterVariableInput,
});
this.schemaSettingsManager.addItem('FilterFormItemSettings', 'formulatitleField', {
Component: EditFormulaTitleField,
useVisible: useFormulaTitleVisible,
});
this.schemaSettingsManager.addItem('FilterFormItemSettings', 'editDefaultValue', {
Component: EditDefaultValue,
});
this.schemaSettingsManager.addItem('fieldSettings:component:Select', 'editDefaultValue', {
Component: EditDefaultValue,
});
const customItem = {
title: tval('Custom filter field'),
name: 'custom',
type: 'item',
Component: 'FilterFormItemCustom',
};
this.app.schemaInitializerManager.addItem('filterForm:configureFields', 'custom-item-divider', {
type: 'divider',
});
this.app.schemaInitializerManager.addItem('filterForm:configureFields', customItem.name, customItem);
this.schemaSettingsManager.addItem('ActionSettings', 'Customize.setFilterScope', {
Component: SetFilterScope,
useVisible: useSetFilterScopeVisible,
useComponentProps() {
const collection = useCollection();
return {
collectionName: collection.name,
};
},
});
}
}

View File

@ -0,0 +1,33 @@
import { Plugin } from '@nocobase/client';
import {
PDFViewerBlockInitializer,
PDFViewerPrintActionInitializer,
PDFViewerProvider,
pdfViewActionInitializer,
usePDFViewerPrintActionProps,
} from '../../schema-initializer';
import { InternalPDFViewer } from '../../schema-components';
import { tval } from '../../locale';
export class PluginPDF extends Plugin {
async load() {
this.app.addScopes({
usePDFViewerPrintActionProps,
});
this.app.addComponents({
PDFViewerBlockInitializer,
PDFViewerPrintActionInitializer,
PDFViewerProvider,
PDFViwer: InternalPDFViewer,
});
this.schemaInitializerManager.add(pdfViewActionInitializer);
// 预览区块需要提前加进来,没法放在 afterload 中,这块后面需要重构
const previewBlockItem = {
title: tval('preview block'),
name: 'previewBlock',
type: 'itemGroup',
children: [],
};
this.app.schemaInitializerManager.get('popup:common:addBlock').add(previewBlockItem.name, previewBlockItem);
}
}

View File

@ -12,14 +12,8 @@ import {
useFormulaTitleVisible, useFormulaTitleVisible,
usePaginationVisible, usePaginationVisible,
EditTitle, EditTitle,
SetFilterScope,
useSetFilterScopeVisible,
FilterVariableInput,
EditDefaultValue,
} from './schema-settings'; } from './schema-settings';
import { useCreateActionProps } from './schema-initializer/actions/hooks/useCreateActionProps'; import { useCreateActionProps } from './schema-initializer/actions/hooks/useCreateActionProps';
import { useFilterBlockActionProps } from './hooks/useFilterBlockActionProps';
import { useFilterFormCustomProps } from './hooks/useFilterFormCustomProps';
import { useGetCustomAssociatedComponents } from './hooks/useGetCustomAssociatedComponents'; import { useGetCustomAssociatedComponents } from './hooks/useGetCustomAssociatedComponents';
import { useGetCustomComponents } from './hooks/useGetCustomComponents'; import { useGetCustomComponents } from './hooks/useGetCustomComponents';
import { AdminLayout, DetailsPage, HomePage, OutboundPage, PageLayout } from './pages'; import { AdminLayout, DetailsPage, HomePage, OutboundPage, PageLayout } from './pages';
@ -44,20 +38,12 @@ import {
SignatureInput, SignatureInput,
ExcelFile, ExcelFile,
} from './components'; } from './components';
import { AutoComplete, InternalPDFViewer } from './schema-components'; import { AutoComplete } from './schema-components';
import { import {
CreateSubmitActionInitializer, CreateSubmitActionInitializer,
FilterFormItem,
FilterFormItemCustom,
FilterItemCustomDesigner,
GroupBlockPlugin, GroupBlockPlugin,
OutboundActionHelper, OutboundActionHelper,
PDFViewerBlockInitializer,
PDFViewerPrintActionInitializer,
PDFViewerProvider,
SettingBlockInitializer, SettingBlockInitializer,
pdfViewActionInitializer,
usePDFViewerPrintActionProps,
} from './schema-initializer'; } from './schema-initializer';
import { import {
SheetBlock, SheetBlock,
@ -81,6 +67,8 @@ import { PluginHeraVersion } from './features/hera-version';
import { PluginAssistant } from './features/assistant'; import { PluginAssistant } from './features/assistant';
import { TstzrangeFieldInterface } from './interfaces/TstzrangeFieldInterface'; import { TstzrangeFieldInterface } from './interfaces/TstzrangeFieldInterface';
import { PluginContextMenu } from './features/context-menu'; import { PluginContextMenu } from './features/context-menu';
import { PluginPDF } from './features/pdf';
import { PluginExtendedFilterForm } from './features/extended-filter-form';
export { usePDFViewerRef } from './schema-initializer'; export { usePDFViewerRef } from './schema-initializer';
export * from './components/custom-components/custom-components'; export * from './components/custom-components/custom-components';
@ -95,21 +83,13 @@ export class PluginCoreClient extends Plugin {
await this.app.pm.add(PluginHeraVersion); await this.app.pm.add(PluginHeraVersion);
await this.app.pm.add(PluginContextMenu); await this.app.pm.add(PluginContextMenu);
await this.app.pm.add(PluginAssistant); await this.app.pm.add(PluginAssistant);
await this.app.pm.add(PluginPDF);
await this.app.pm.add(PluginExtendedFilterForm);
} }
async registerSettings() { async registerSettings() {
this.schemaSettingsManager.add(sheetBlockSettings); this.schemaSettingsManager.add(sheetBlockSettings);
this.schemaSettingsManager.add(customComponentDispatcherSettings); this.schemaSettingsManager.add(customComponentDispatcherSettings);
this.schemaSettingsManager.addItem('FilterFormItemSettings', 'formulatitleField', {
Component: EditFormulaTitleField,
useVisible: useFormulaTitleVisible,
});
this.schemaSettingsManager.addItem('FilterFormItemSettings', 'editDefaultValue', {
Component: EditDefaultValue,
});
this.schemaSettingsManager.addItem('fieldSettings:component:Select', 'editDefaultValue', {
Component: EditDefaultValue,
});
this.schemaSettingsManager.addItem('fieldSettings:component:DatePicker', 'datePickerType', { this.schemaSettingsManager.addItem('fieldSettings:component:DatePicker', 'datePickerType', {
Component: SchemaSettingsDatePickerType, Component: SchemaSettingsDatePickerType,
@ -138,16 +118,6 @@ export class PluginCoreClient extends Plugin {
Component: IsTablePageSize, Component: IsTablePageSize,
useVisible: usePaginationVisible, useVisible: usePaginationVisible,
}); });
this.schemaSettingsManager.addItem('ActionSettings', 'Customize.setFilterScope', {
Component: SetFilterScope,
useVisible: useSetFilterScopeVisible,
useComponentProps() {
const collection = useCollection();
return {
collectionName: collection.name,
};
},
});
this.app.schemaSettingsManager.addItem('actionSettings:submit', 'pageMode', { this.app.schemaSettingsManager.addItem('actionSettings:submit', 'pageMode', {
Component: PageModeSetting, Component: PageModeSetting,
useVisible() { useVisible() {
@ -155,25 +125,13 @@ export class PluginCoreClient extends Plugin {
return isValid(fieldSchema?.['x-action-settings']?.pageMode); return isValid(fieldSchema?.['x-action-settings']?.pageMode);
}, },
}); });
// 预览区块需要提前加进来,没法放在 afterload 中,这块后面需要重构
const previewBlockItem = {
title: tval('preview block'),
name: 'previewBlock',
type: 'itemGroup',
children: [],
};
this.app.schemaInitializerManager.get('popup:common:addBlock').add(previewBlockItem.name, previewBlockItem);
} }
async registerScopesAndComponents() { async registerScopesAndComponents() {
this.app.addScopes({ this.app.addScopes({
useCreateActionProps, useCreateActionProps,
useFilterBlockActionProps,
useFilterFormCustomProps,
useGetCustomAssociatedComponents, useGetCustomAssociatedComponents,
useGetCustomComponents, useGetCustomComponents,
usePDFViewerPrintActionProps,
useCustomPresets1, useCustomPresets1,
useCustomPresets, useCustomPresets,
}); });
@ -192,14 +150,6 @@ export class PluginCoreClient extends Plugin {
EditTitle, EditTitle,
EditTitleField, EditTitleField,
Expression, Expression,
FilterFormItem,
FilterFormItemCustom,
FilterItemCustomDesigner,
FilterVariableInput,
PDFViewerBlockInitializer,
PDFViewerPrintActionInitializer,
PDFViewerProvider,
PDFViwer: InternalPDFViewer,
PageLayout, PageLayout,
SettingBlock: SettingBlockInitializer, SettingBlock: SettingBlockInitializer,
SheetBlock, SheetBlock,
@ -227,11 +177,6 @@ export class PluginCoreClient extends Plugin {
}); });
} }
async registerTricks() {
// Loading this provider in an unauthenticated state will result in an error; remove it here.
remove(this.app.providers, ([provider]) => provider === RemoteSchemaTemplateManagerProvider);
}
async registerSchemaInitializer() { async registerSchemaInitializer() {
const settingBlockItem = { const settingBlockItem = {
name: 'setting', name: 'setting',
@ -247,23 +192,12 @@ export class PluginCoreClient extends Plugin {
'x-align': 'right', 'x-align': 'right',
}, },
}; };
const customItem = {
title: tval('Custom filter field'),
name: 'custom',
type: 'item',
Component: 'FilterFormItemCustom',
};
this.schemaInitializerManager.add(pdfViewActionInitializer);
this.app.schemaInitializerManager.addItem('page:addBlock', settingBlockItem.name, settingBlockItem); this.app.schemaInitializerManager.addItem('page:addBlock', settingBlockItem.name, settingBlockItem);
this.app.schemaInitializerManager.addItem('page:addBlock', 'dataBlocks.sheetBlock', { this.app.schemaInitializerManager.addItem('page:addBlock', 'dataBlocks.sheetBlock', {
title: tval('Sheet'), title: tval('Sheet'),
Component: 'SheetBlockInitializer', Component: 'SheetBlockInitializer',
}); });
this.app.schemaInitializerManager.addItem('kanban:configureActions', refreshActionItem.name, refreshActionItem); this.app.schemaInitializerManager.addItem('kanban:configureActions', refreshActionItem.name, refreshActionItem);
this.app.schemaInitializerManager.addItem('filterForm:configureFields', 'custom-item-divider', {
type: 'divider',
});
this.app.schemaInitializerManager.addItem('filterForm:configureFields', customItem.name, customItem);
const addCustomComponent = { const addCustomComponent = {
name: 'addCustomComponent', name: 'addCustomComponent',
title: tval('Add custom component'), title: tval('Add custom component'),
@ -310,7 +244,6 @@ export class PluginCoreClient extends Plugin {
this.locale = new Locale(this.app); this.locale = new Locale(this.app);
await new OutboundActionHelper(this.app).load(); await new OutboundActionHelper(this.app).load();
await new PluginSettingsHelper(this.app).load(); await new PluginSettingsHelper(this.app).load();
await this.registerTricks();
await this.registerScopesAndComponents(); await this.registerScopesAndComponents();
await this.registerSettings(); await this.registerSettings();
await this.registerRouters(); await this.registerRouters();

View File

@ -41,6 +41,7 @@ export class PluginCoreServer extends Plugin {
// init web controllers // init web controllers
await Container.get(WebService).load(); await Container.get(WebService).load();
this.app.acl.allow('link-manage', 'init', 'public'); this.app.acl.allow('link-manage', 'init', 'public');
this.app.acl.allow('hera', 'version', 'public');
} catch (err) { } catch (err) {
console.warn(err); console.warn(err);
} }