refactor: remove unused codes, move blocks to /schema-initializer/blocks

This commit is contained in:
sealday 2024-03-21 20:38:26 +08:00
parent 59d2af69c3
commit 68025facb4
17 changed files with 122 additions and 237 deletions

View File

@ -2,7 +2,7 @@ import { SchemaSettingsItem } from '@nocobase/client';
import React, { useContext } from 'react';
import { useTranslation } from '../../locale';
import { Modal } from 'antd';
import { GroupBlockContext } from '../../schema-initializer/GroupBlockInitializer';
import { GroupBlockContext } from '../../schema-initializer/blocks/GroupBlockInitializer';
export const GroupBlockConfigure = (props) => {
const { t } = useTranslation();

View File

@ -3,7 +3,7 @@ import { useDesignable, useFieldNames, useFilterBlock } from '@nocobase/client';
import { App, Button, Flex, Input, Modal, Select } from 'antd';
import React, { useContext, useEffect, useState } from 'react';
import { useTranslation } from '../../locale';
import { GroupBlockContext } from '../../schema-initializer/GroupBlockInitializer';
import { GroupBlockContext } from '../../schema-initializer/blocks/GroupBlockInitializer';
import { transformers } from './transformers';
import { DeleteOutlined, PullRequestOutlined } from '@ant-design/icons';
import { uid } from '@formily/shared';

View File

@ -24,13 +24,12 @@ import {
useSetFilterScopeVisible,
AfterSuccess,
} from './schema-settings';
import { useCreateActionProps } from './hooks/useCreateActionProps';
import { useCreateActionProps } from './schema-initializer/actions/hooks/useCreateActionProps';
import { useCustomizeUpdateActionProps } from './hooks/useCustomizeUpdateActionProps';
import { useFilterBlockActionProps } from './hooks/useFilterBlockActionProps';
import { useFilterFormCustomProps } from './hooks/useFilterFormCustomProps';
import { useGetCustomAssociatedComponents } from './hooks/useGetCustomAssociatedComponents';
import { useGetCustomComponents } from './hooks/useGetCustomComponents';
import { useOutboundActionProps } from './hooks/useOutboundActionProps';
import { AdminLayout, DetailsPage, HomePage, OutboundPage, PageLayout } from './pages';
import { Configuration, HomePageConfiguration, LinkManager } from './settings-manager-components';
import {
@ -71,6 +70,7 @@ import {
GroupBlockInitializer,
GroupBlockProvider,
GroupBlockToolbar,
OutboundActionHelper,
OutboundButton,
OutboundLinkActionInitializer,
PDFViewerBlockInitializer,
@ -81,7 +81,13 @@ import {
pdfViewActionInitializer,
usePDFViewerPrintActionProps,
} from './schema-initializer';
import { SheetBlock, SheetBlockInitializer, SheetBlockProvider, SheetBlockToolbar, sheetBlockSettings } from './schema-initializer/SheetBlockInitializer';
import {
SheetBlock,
SheetBlockInitializer,
SheetBlockProvider,
SheetBlockToolbar,
sheetBlockSettings,
} from './schema-initializer/blocks/SheetBlockInitializer';
export { usePDFViewerRef } from './schema-initializer';
export * from './components/custom-components/custom-components';
@ -182,7 +188,6 @@ export class PluginCoreClient extends Plugin {
useFilterFormCustomProps,
useGetCustomAssociatedComponents,
useGetCustomComponents,
useOutboundActionProps,
usePDFViewerPrintActionProps,
});
@ -216,8 +221,6 @@ export class PluginCoreClient extends Plugin {
// @ts-ignore
Designer: MenuDesigner,
},
OutboundButton,
OutboundLinkActionInitializer,
PDFViewerBlockInitializer,
PDFViewerPrintActionInitializer,
PDFViewerProvider,
@ -232,7 +235,6 @@ export class PluginCoreClient extends Plugin {
SheetBlockProvider,
SheetBlockToolbar,
});
}
async registerRouters() {
@ -263,15 +265,6 @@ export class PluginCoreClient extends Plugin {
title: '筛选区块添加一对一的引用',
Component: 'FilterAssociatedFields',
};
const outboundItem = {
type: 'item',
name: 'enableActions.outbound',
title: '外链',
Component: 'OutboundLinkActionInitializer',
schema: {
'x-align': 'right',
},
};
const calendarBlockItem = {
name: 'calendarV2',
title: '{{t("Calendar")}}',
@ -298,8 +291,6 @@ export class PluginCoreClient extends Plugin {
Component: 'FilterFormItemCustom',
};
this.schemaInitializerManager.add(pdfViewActionInitializer);
this.app.schemaInitializerManager.addItem('TableActionInitializers', outboundItem.name, outboundItem);
this.app.schemaInitializerManager.get('ReadPrettyFormActionInitializers').add(outboundItem.name, outboundItem);
this.app.schemaInitializerManager.get('BlockInitializers').add(calendarBlockItem.name, calendarBlockItem);
this.app.schemaInitializerManager.get('BlockInitializers').add(settingBlockItem.name, settingBlockItem);
this.app.schemaInitializerManager.get('BlockInitializers').add('dataBlocks.groupBlock', {
@ -311,7 +302,6 @@ export class PluginCoreClient extends Plugin {
Component: 'SheetBlockInitializer',
});
this.app.schemaInitializerManager.get('KanbanActionInitializers').add(refreshActionItem.name, refreshActionItem);
this.app.schemaInitializerManager.get('KanbanActionInitializers').add(outboundItem.name, outboundItem);
this.app.schemaInitializerManager.get('FilterFormItemInitializers').add(associationFields.name, associationFields);
this.app.schemaInitializerManager.addItem('FilterFormItemInitializers', 'custom-item-divider', {
type: 'divider',
@ -364,6 +354,7 @@ export class PluginCoreClient extends Plugin {
async load() {
this.locale = new Locale(this.app);
await new OutboundActionHelper(this.app).load();
await this.registerTricks();
await this.registerScopesAndComponents();
await this.registerSettings();

View File

@ -1,4 +1,4 @@
import { Application, useApp, tval as nTval } from '@nocobase/client';
import { Application, useApp, tval as nTval, i18n } from '@nocobase/client';
const NAMESPACE = '@hera/plugin-core';
@ -21,3 +21,7 @@ export const useTranslation = (): any => {
};
export const tval = (key: string) => nTval(key, { ns: NAMESPACE });
export function lang(key: string) {
return i18n.t(key, { ns: NAMESPACE });
}

View File

@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from 'react';
import { PDFViewer } from '../components/PDFViewer';
import { Space } from 'antd';
import { css } from '@nocobase/client';
import { usePDFViewerRef } from '../schema-initializer/PDFVIewerBlockInitializer';
import { usePDFViewerRef } from '../schema-initializer/blocks/PDFVIewerBlockInitializer';
export const InternalPDFViewer = (props) => {
const { usePdfPath: useMaybePdfPath } = props;

View File

@ -1,147 +0,0 @@
import { useCollection_deprecated } from '@nocobase/client';
const useVisibleCollection = () => {
const collection = useCollection_deprecated();
return (collection.template !== 'view' || collection?.writableView) && collection.template !== 'sql';
};
// 表单的操作配置
export const DetailsActionInitializers = {
title: '{{t("Configure actions")}}',
icon: 'SettingOutlined',
style: {
marginLeft: 8,
},
items: [
{
type: 'itemGroup',
title: '{{t("Enable actions")}}',
children: [
{
type: 'item',
title: '{{t("Edit")}}',
component: 'UpdateActionInitializer',
schema: {
'x-component': 'Action',
'x-decorator': 'ACLActionProvider',
'x-component-props': {
type: 'primary',
},
},
},
{
type: 'item',
title: '{{t("Delete")}}',
component: 'DestroyActionInitializer',
schema: {
'x-component': 'Action',
'x-decorator': 'ACLActionProvider',
},
},
{
type: 'item',
title: '{{t("Duplicate")}}',
component: 'DuplicateActionInitializer',
schema: {
'x-component': 'Action',
'x-action': 'duplicate',
'x-decorator': 'ACLActionProvider',
'x-component-props': {
type: 'primary',
},
},
},
],
},
{
type: 'divider',
},
{
type: 'subMenu',
title: '{{t("Customize")}}',
children: [
{
type: 'item',
title: '{{t("Popup")}}',
component: 'CustomizeActionInitializer',
schema: {
type: 'void',
title: '{{ t("Popup") }}',
'x-action': 'customize:popup',
'x-designer': 'Action.Designer',
'x-component': 'Action',
'x-component-props': {
openMode: 'drawer',
},
properties: {
drawer: {
type: 'void',
title: '{{ t("Popup") }}',
'x-component': 'Action.Container',
'x-component-props': {
className: 'nb-action-popup',
},
properties: {
tabs: {
type: 'void',
'x-component': 'Tabs',
'x-component-props': {},
'x-initializer': 'TabPaneInitializers',
properties: {
tab1: {
type: 'void',
title: '{{t("Details")}}',
'x-component': 'Tabs.TabPane',
'x-designer': 'Tabs.Designer',
'x-component-props': {},
properties: {
grid: {
type: 'void',
'x-component': 'Grid',
'x-initializer': 'RecordBlockInitializers',
properties: {},
},
},
},
},
},
},
},
},
},
},
{
type: 'item',
title: '{{t("Update record")}}',
component: 'CustomizeActionInitializer',
schema: {
title: '{{ t("Update record") }}',
'x-component': 'Action',
'x-designer': 'Action.Designer',
'x-action': 'customize:update',
'x-decorator': 'ACLActionProvider',
'x-acl-action': 'update',
'x-action-settings': {
assignedValues: {},
onSuccess: {
manualClose: true,
redirecting: false,
successMessage: '{{t("Updated successfully")}}',
},
},
'x-component-props': {
useProps: '{{ useCustomizeUpdateActionProps }}',
},
},
visible: useVisibleCollection,
},
{
type: 'item',
title: '{{t("Custom request")}}',
component: 'CustomRequestInitializer',
visible: useVisibleCollection,
},
],
},
],
};

View File

@ -1,46 +0,0 @@
import React from 'react';
import { ActionInitializer } from '@nocobase/client';
import { Popover, Space, Button, Input } from 'antd';
import { useFieldSchema } from '@formily/react';
import { useProps } from '@nocobase/client';
import { ShareAltOutlined } from '@ant-design/icons';
export const OutboundLinkActionInitializer = (props) => {
const schema = {
title: '外链',
'x-action': 'outbound',
'x-component': 'OutboundButton',
'x-designer': 'Action.Designer',
'x-component-props': {
icon: 'ShareAltOutlined',
useProps: '{{ useOutboundActionProps }}',
},
};
return <ActionInitializer {...props} schema={schema} />;
};
export const OutboundButton = (props) => {
const { onClick } = useProps(props);
const schema = useFieldSchema();
const url = window.location.href.split('/', 3).join('/');
return (
<Popover
placement="bottomRight"
trigger="click"
autoAdjustOverflow
content={
<Space.Compact style={{ width: '100%' }}>
<Input defaultValue={`${url}/r/${schema['x-uid']}`} />
<Button type="primary" onClick={onClick}>
</Button>
</Space.Compact>
}
>
<Button>
<ShareAltOutlined />
</Button>
</Popover>
);
};

View File

@ -1,9 +1,9 @@
import React from 'react';
import { ActionInitializer } from '@nocobase/client';
import { ActionInitializer, tval } from '@nocobase/client';
export const CreateSubmitActionInitializer = (props) => {
export const CreateSubmitActionInitializer: React.FC = (props) => {
const schema = {
title: '{{ t("Submit") }}',
title: tval('Submit'),
'x-action': 'submit',
'x-component': 'Action',
'x-designer': 'Action.Designer',
@ -20,3 +20,4 @@ export const CreateSubmitActionInitializer = (props) => {
};
return <ActionInitializer {...props} schema={schema} />;
};
CreateSubmitActionInitializer.displayName = 'CreateSubmitActionInitializer';

View File

@ -0,0 +1,78 @@
import React from 'react';
import { ActionInitializer, Application } from '@nocobase/client';
import { Popover, Space, Button, Input } from 'antd';
import { useFieldSchema } from '@formily/react';
import { useProps } from '@nocobase/client';
import { ShareAltOutlined } from '@ant-design/icons';
import { lang, tval, useTranslation } from '../../locale';
import { useOutboundActionProps } from './hooks/useOutboundActionProps';
export class OutboundActionHelper {
constructor(private app: Application) {}
async load() {
this.app.addScopes({
useOutboundActionProps,
});
this.app.addComponents({
OutboundButton,
OutboundLinkActionInitializer,
});
const outboundItem = {
type: 'item',
name: 'enableActions.outbound',
title: lang('outbound'),
Component: 'OutboundLinkActionInitializer',
schema: {
'x-align': 'right',
},
};
this.app.schemaInitializerManager.addItem('table:configureActions', outboundItem.name, outboundItem);
this.app.schemaInitializerManager.addItem('details:configureActions', outboundItem.name, outboundItem);
this.app.schemaInitializerManager.addItem('kanban:configureActions', outboundItem.name, outboundItem);
}
}
export const OutboundLinkActionInitializer: React.FC = (props) => {
const schema = {
title: tval('outbound'),
'x-action': 'outbound',
'x-component': 'OutboundButton',
'x-designer': 'Action.Designer',
'x-component-props': {
icon: 'ShareAltOutlined',
useProps: '{{ useOutboundActionProps }}',
},
};
return <ActionInitializer {...props} schema={schema} />;
};
OutboundLinkActionInitializer.displayName = 'OutboundLinkActionInitializer';
export const OutboundButton: React.FC = (props) => {
const { onClick } = useProps(props);
const schema = useFieldSchema();
// FIXME 处理多应用情况
const url = window.location.href.split('/', 3).join('/');
const { t } = useTranslation();
return (
<Popover
placement="bottomRight"
trigger="click"
autoAdjustOverflow
content={
<Space.Compact style={{ width: '100%' }}>
<Input defaultValue={`${url}/r/${schema['x-uid']}`} />
<Button type="primary" onClick={onClick}>
{t('Copy link')}
</Button>
</Space.Compact>
}
>
<Button>
<ShareAltOutlined />
{t('Outbound')}
</Button>
</Popover>
);
};
OutboundButton.displayName = 'OutboundButton';

View File

@ -19,14 +19,15 @@ import { useTranslation } from 'react-i18next';
import { App, message } from 'antd';
import { useNavigate, useParams } from 'react-router-dom';
import { isURL } from '@nocobase/utils/client';
import React, { useCallback } from 'react';
import { useCallback } from 'react';
import _ from 'lodash';
import { tval } from '../../../locale';
const pageDetailsViewer = 'PageLayout';
const viewerSchema: ISchema = {
type: 'void',
title: '{{ t("View record") }}',
title: tval('View record'),
'x-component': pageDetailsViewer,
'x-component-props': {
className: 'nb-action-popup',
@ -34,7 +35,7 @@ const viewerSchema: ISchema = {
properties: {
page: {
type: 'void',
title: '详情页面',
title: tval('Detail page'),
'x-designer': 'Page.Designer',
'x-component': 'Page',
'x-component-props': { disablePageHeader: true },

View File

@ -1,21 +1,24 @@
import { message } from 'antd';
import { useFieldSchema } from '@formily/react';
import copy from 'copy-to-clipboard';
import { useTranslation } from '../../../locale';
export const useOutboundActionProps = () => {
let schema = useFieldSchema();
const { t } = useTranslation();
while (!('x-decorator-props' in schema)) {
schema = schema.parent;
}
// FIXME: 处理多应用路径
const url = window.location.href.split('/', 3).join('/');
return {
async onClick() {
const c = copy(`${url}/r/${schema['x-uid']}`);
if (c) {
message.success('链接保存成功');
message.success(t('Save link successful'));
} else {
message.success('链接保存失败');
message.success(t('Save link failed'));
}
},
};

View File

@ -13,7 +13,7 @@ import {
} from '@nocobase/client';
import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { createCalendarBlockSchema } from './utils';
import { createCalendarBlockSchema } from '../utils';
export const CalendarBlockInitializer = () => {
const { insert } = useSchemaInitializer();

View File

@ -16,8 +16,8 @@ import {
import React, { createContext, useState } from 'react';
import { uid } from '@nocobase/utils/client';
import { Checkbox, Spin } from 'antd';
import { GroupBlockConfigure } from '../components/GroupBlockConfigure/GroupBlockConfigure';
import { GroupConfigure } from '../components/GroupBlockConfigure/GroupConfigure';
import { GroupBlockConfigure } from '../../components/GroupBlockConfigure/GroupBlockConfigure';
import { GroupConfigure } from '../../components/GroupBlockConfigure/GroupConfigure';
export const GroupBlockContext = createContext<any>({});

View File

@ -12,7 +12,7 @@ import {
useSchemaInitializerItem,
} from '@nocobase/client';
import React, { useContext } from 'react';
import { useTranslation } from '../locale';
import { tval, useTranslation } from '../../locale';
export const SettingBlockInitializer = () => {
const { insert } = useSchemaInitializer();
@ -41,7 +41,7 @@ export const SettingBlockInitializer = () => {
schema={{
properties: {
id: {
title: t('Please select'),
title: tval('Please select'),
enum: result.data.data.map((item) => {
return {
label: item[titleField],
@ -68,7 +68,7 @@ export const SettingBlockInitializer = () => {
collection: collection.name,
action: 'get',
filterByTk: values.id,
actionInitializers: 'UpdateFormActionInitializers',
actionInitializers: 'editForm:configureActions',
});
insert(formSchema);
}}

View File

@ -13,7 +13,7 @@ import {
import React, { createContext, useRef } from 'react';
import { uid } from '@nocobase/utils/client';
import { Button, Spin } from 'antd';
import Sheet, { SheetRef } from '../components/Sheet';
import Sheet, { SheetRef } from '../../components/Sheet';
export const SheetBlockContext = createContext<any>({});

View File

@ -1,8 +1,8 @@
export * from './FilterFormItemCustomInitializer/FilterFormItemCustom';
export * from './CalendarBlockInitializer';
export * from './PDFVIewerBlockInitializer';
export * from './OutboundLinkActionInitializer';
export * from './CreateSubmitActionInitializer';
export * from './blocks/CalendarBlockInitializer';
export * from './blocks/PDFVIewerBlockInitializer';
export * from './actions/OutboundLinkActionInitializer';
export * from './actions/CreateSubmitActionInitializer';
export * from './FilterAssociatedFields';
export * from './SettingBlockInitializer';
export * from './GroupBlockInitializer';
export * from './blocks/SettingBlockInitializer';
export * from './blocks/GroupBlockInitializer';