mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 14:56:00 +00:00
fix: block error can delete (#4329)
* fix: block error can delete * fix: test bug
This commit is contained in:
parent
8280077f96
commit
6f4c884799
@ -14,6 +14,7 @@ import { SchemaInitializerItems } from '../components';
|
|||||||
import { SchemaInitializerButton } from '../components/SchemaInitializerButton';
|
import { SchemaInitializerButton } from '../components/SchemaInitializerButton';
|
||||||
import { withInitializer } from '../withInitializer';
|
import { withInitializer } from '../withInitializer';
|
||||||
import { SchemaInitializerOptions } from '../types';
|
import { SchemaInitializerOptions } from '../types';
|
||||||
|
import { SchemaInitializer } from '../SchemaInitializer';
|
||||||
|
|
||||||
const InitializerComponent: FC<SchemaInitializerOptions<any, any>> = React.memo((options) => {
|
const InitializerComponent: FC<SchemaInitializerOptions<any, any>> = React.memo((options) => {
|
||||||
const Component: any = options.Component || SchemaInitializerButton;
|
const Component: any = options.Component || SchemaInitializerButton;
|
||||||
@ -33,12 +34,12 @@ const InitializerComponent: FC<SchemaInitializerOptions<any, any>> = React.memo(
|
|||||||
InitializerComponent.displayName = 'InitializerComponent';
|
InitializerComponent.displayName = 'InitializerComponent';
|
||||||
|
|
||||||
export function useSchemaInitializerRender<P1 = ButtonProps, P2 = {}>(
|
export function useSchemaInitializerRender<P1 = ButtonProps, P2 = {}>(
|
||||||
name: string,
|
name: string | SchemaInitializer<P1, P2>,
|
||||||
options?: Omit<SchemaInitializerOptions<P1, P2>, 'name'>,
|
options?: Omit<SchemaInitializerOptions<P1, P2>, 'name'>,
|
||||||
) {
|
) {
|
||||||
const app = useApp();
|
const app = useApp();
|
||||||
const initializer = useMemo(
|
const initializer = useMemo(
|
||||||
() => app.schemaInitializerManager.get<P1, P2>(name),
|
() => (typeof name === 'object' ? name : app.schemaInitializerManager.get<P1, P2>(name)),
|
||||||
[app.schemaInitializerManager, name],
|
[app.schemaInitializerManager, name],
|
||||||
);
|
);
|
||||||
const res = useMemo(() => {
|
const res = useMemo(() => {
|
||||||
|
@ -16,6 +16,7 @@ import { SchemaSettingsProps } from '../../../schema-settings';
|
|||||||
import { Schema } from '@formily/json-schema';
|
import { Schema } from '@formily/json-schema';
|
||||||
import { GeneralField } from '@formily/core';
|
import { GeneralField } from '@formily/core';
|
||||||
import { Designable } from '../../../schema-component';
|
import { Designable } from '../../../schema-component';
|
||||||
|
import { SchemaSettings } from '../SchemaSettings';
|
||||||
|
|
||||||
type UseSchemaSettingsRenderOptions<T = {}> = Omit<SchemaSettingOptions<T>, 'name' | 'items'> &
|
type UseSchemaSettingsRenderOptions<T = {}> = Omit<SchemaSettingOptions<T>, 'name' | 'items'> &
|
||||||
Omit<SchemaSettingsProps, 'title' | 'children'> & {
|
Omit<SchemaSettingsProps, 'title' | 'children'> & {
|
||||||
@ -24,9 +25,15 @@ type UseSchemaSettingsRenderOptions<T = {}> = Omit<SchemaSettingOptions<T>, 'nam
|
|||||||
dn?: Designable;
|
dn?: Designable;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useSchemaSettingsRender<T = {}>(name: string, options?: UseSchemaSettingsRenderOptions<T>) {
|
export function useSchemaSettingsRender<T = {}>(
|
||||||
|
name: string | SchemaSettings<T>,
|
||||||
|
options?: UseSchemaSettingsRenderOptions<T>,
|
||||||
|
) {
|
||||||
const app = useApp();
|
const app = useApp();
|
||||||
const schemaSetting = useMemo(() => app.schemaSettingsManager.get<T>(name), [app.schemaSettingsManager, name]);
|
const schemaSetting = useMemo(
|
||||||
|
() => (typeof name === 'object' ? name : app.schemaSettingsManager.get<T>(name)),
|
||||||
|
[app.schemaSettingsManager, name],
|
||||||
|
);
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return {
|
return {
|
||||||
exists: false,
|
exists: false,
|
||||||
|
@ -12,10 +12,29 @@ import { FC } from 'react';
|
|||||||
import { ErrorBoundary, FallbackProps } from 'react-error-boundary';
|
import { ErrorBoundary, FallbackProps } from 'react-error-boundary';
|
||||||
import { BlockItemCard } from './BlockItemCard';
|
import { BlockItemCard } from './BlockItemCard';
|
||||||
import { ErrorFallback } from '../error-fallback';
|
import { ErrorFallback } from '../error-fallback';
|
||||||
|
import { SchemaSettings } from '../../../application/schema-settings/SchemaSettings';
|
||||||
|
import { SchemaToolbar } from '../../../schema-settings/GeneralSchemaDesigner';
|
||||||
|
|
||||||
|
const blockDeleteSettings = new SchemaSettings({
|
||||||
|
name: 'blockDeleteSettings',
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
name: 'remove',
|
||||||
|
type: 'remove',
|
||||||
|
componentProps: {
|
||||||
|
removeParentsIfNoChildren: true,
|
||||||
|
breakRemoveOn(s) {
|
||||||
|
return s['x-component'] === 'Grid'; // 其顶级是 Grid,这一层级不能删
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
const FallbackComponent: FC<FallbackProps> = (props) => {
|
const FallbackComponent: FC<FallbackProps> = (props) => {
|
||||||
return (
|
return (
|
||||||
<BlockItemCard>
|
<BlockItemCard>
|
||||||
|
<SchemaToolbar settings={blockDeleteSettings} draggable={false} />
|
||||||
<ErrorFallback {...props} />
|
<ErrorFallback {...props} />
|
||||||
</BlockItemCard>
|
</BlockItemCard>
|
||||||
);
|
);
|
||||||
|
@ -14,7 +14,13 @@ import { Space } from 'antd';
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import React, { FC, useEffect, useMemo, useRef } from 'react';
|
import React, { FC, useEffect, useMemo, useRef } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { SchemaToolbarProvider, useSchemaInitializerRender, useSchemaSettingsRender } from '../application';
|
import {
|
||||||
|
SchemaInitializer,
|
||||||
|
SchemaSettings,
|
||||||
|
SchemaToolbarProvider,
|
||||||
|
useSchemaInitializerRender,
|
||||||
|
useSchemaSettingsRender,
|
||||||
|
} from '../application';
|
||||||
import { useDataSourceManager } from '../data-source/data-source/DataSourceManagerProvider';
|
import { useDataSourceManager } from '../data-source/data-source/DataSourceManagerProvider';
|
||||||
import { useDataSource } from '../data-source/data-source/DataSourceProvider';
|
import { useDataSource } from '../data-source/data-source/DataSourceProvider';
|
||||||
import { DragHandler, useCompile, useDesignable, useGridContext, useGridRowContext } from '../schema-component';
|
import { DragHandler, useCompile, useDesignable, useGridContext, useGridRowContext } from '../schema-component';
|
||||||
@ -181,8 +187,8 @@ export const GeneralSchemaDesigner: FC<GeneralSchemaDesignerProps> = (props: any
|
|||||||
export interface SchemaToolbarProps {
|
export interface SchemaToolbarProps {
|
||||||
title?: string | string[];
|
title?: string | string[];
|
||||||
draggable?: boolean;
|
draggable?: boolean;
|
||||||
initializer?: string | false;
|
initializer?: string | SchemaInitializer<any> | false;
|
||||||
settings?: string | false;
|
settings?: string | SchemaSettings<any> | false;
|
||||||
/**
|
/**
|
||||||
* @default true
|
* @default true
|
||||||
*/
|
*/
|
||||||
@ -215,11 +221,11 @@ const InternalSchemaToolbar: FC<SchemaToolbarProps> = (props) => {
|
|||||||
if (Array.isArray(title)) return title.map((item) => compile(item));
|
if (Array.isArray(title)) return title.map((item) => compile(item));
|
||||||
}, [compile, title]);
|
}, [compile, title]);
|
||||||
const { render: schemaSettingsRender, exists: schemaSettingsExists } = useSchemaSettingsRender(
|
const { render: schemaSettingsRender, exists: schemaSettingsExists } = useSchemaSettingsRender(
|
||||||
fieldSchema['x-settings'] || settings,
|
settings || fieldSchema['x-settings'],
|
||||||
fieldSchema['x-settings-props'],
|
fieldSchema['x-settings-props'],
|
||||||
);
|
);
|
||||||
const { render: schemaInitializerRender, exists: schemaInitializerExists } = useSchemaInitializerRender(
|
const { render: schemaInitializerRender, exists: schemaInitializerExists } = useSchemaInitializerRender(
|
||||||
fieldSchema['x-initializer'] || initializer,
|
initializer || fieldSchema['x-initializer'],
|
||||||
fieldSchema['x-initializer-props'],
|
fieldSchema['x-initializer-props'],
|
||||||
);
|
);
|
||||||
const rowCtx = useGridRowContext();
|
const rowCtx = useGridRowContext();
|
||||||
|
Loading…
Reference in New Issue
Block a user