mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-09 23:49:27 +08:00
feat: support summary props (#5640)
This commit is contained in:
parent
66e0f02216
commit
1d508b8e96
@ -18,7 +18,7 @@ import { useFormBlockContext } from '../../block-provider/FormBlockProvider';
|
|||||||
import { useDynamicComponentProps } from '../../hoc/withDynamicSchemaProps';
|
import { useDynamicComponentProps } from '../../hoc/withDynamicSchemaProps';
|
||||||
import { ErrorFallback, useCompile, useComponent } from '../../schema-component';
|
import { ErrorFallback, useCompile, useComponent } from '../../schema-component';
|
||||||
import { useIsAllowToSetDefaultValue } from '../../schema-settings/hooks/useIsAllowToSetDefaultValue';
|
import { useIsAllowToSetDefaultValue } from '../../schema-settings/hooks/useIsAllowToSetDefaultValue';
|
||||||
import { CollectionFieldProvider, useCollectionField } from './CollectionFieldProvider';
|
import { CollectionFieldOriginalContext, CollectionFieldProvider, useCollectionField } from './CollectionFieldProvider';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
component: any;
|
component: any;
|
||||||
@ -93,11 +93,14 @@ export const CollectionFieldInternalField: React.FC = (props: Props) => {
|
|||||||
|
|
||||||
export const CollectionField = connect((props) => {
|
export const CollectionField = connect((props) => {
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
|
const field = useField<Field>();
|
||||||
return (
|
return (
|
||||||
<ErrorBoundary FallbackComponent={ErrorFallback.Modal} onError={(err) => console.log(err)}>
|
<ErrorBoundary FallbackComponent={ErrorFallback.Modal} onError={(err) => console.log(err)}>
|
||||||
<CollectionFieldProvider name={fieldSchema.name}>
|
<CollectionFieldOriginalContext.Provider value={{ fieldSchema, field }}>
|
||||||
<CollectionFieldInternalField {...props} />
|
<CollectionFieldProvider name={fieldSchema.name}>
|
||||||
</CollectionFieldProvider>
|
<CollectionFieldInternalField {...props} />
|
||||||
|
</CollectionFieldProvider>
|
||||||
|
</CollectionFieldOriginalContext.Provider>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -18,6 +18,9 @@ import { CollectionDeletedPlaceholder } from '../components/CollectionDeletedPla
|
|||||||
export const CollectionFieldContext = createContext<CollectionFieldOptions>(null);
|
export const CollectionFieldContext = createContext<CollectionFieldOptions>(null);
|
||||||
CollectionFieldContext.displayName = 'CollectionFieldContext';
|
CollectionFieldContext.displayName = 'CollectionFieldContext';
|
||||||
|
|
||||||
|
export const CollectionFieldOriginalContext = createContext<any>(null);
|
||||||
|
CollectionFieldOriginalContext.displayName = 'CollectionFieldOriginalContext';
|
||||||
|
|
||||||
export type CollectionFieldProviderProps = {
|
export type CollectionFieldProviderProps = {
|
||||||
name?: SchemaKey;
|
name?: SchemaKey;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
|
@ -235,6 +235,7 @@ export const tableBlockSettings = new SchemaSettings({
|
|||||||
{
|
{
|
||||||
name: 'divider',
|
name: 'divider',
|
||||||
type: 'divider',
|
type: 'divider',
|
||||||
|
sort: 7000,
|
||||||
useVisible: () => {
|
useVisible: () => {
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const supportTemplate = !fieldSchema?.['x-decorator-props']?.disableTemplate;
|
const supportTemplate = !fieldSchema?.['x-decorator-props']?.disableTemplate;
|
||||||
@ -243,6 +244,7 @@ export const tableBlockSettings = new SchemaSettings({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'ConvertReferenceToDuplicate',
|
name: 'ConvertReferenceToDuplicate',
|
||||||
|
sort: 8000,
|
||||||
Component: SchemaSettingsTemplate,
|
Component: SchemaSettingsTemplate,
|
||||||
useComponentProps() {
|
useComponentProps() {
|
||||||
const { name } = useCollection_deprecated();
|
const { name } = useCollection_deprecated();
|
||||||
@ -265,10 +267,12 @@ export const tableBlockSettings = new SchemaSettings({
|
|||||||
{
|
{
|
||||||
name: 'divider2',
|
name: 'divider2',
|
||||||
type: 'divider',
|
type: 'divider',
|
||||||
|
sort: 9000,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'delete',
|
name: 'delete',
|
||||||
type: 'remove',
|
type: 'remove',
|
||||||
|
sort: 10000,
|
||||||
useComponentProps: () => {
|
useComponentProps: () => {
|
||||||
return {
|
return {
|
||||||
removeParentsIfNoChildren: true,
|
removeParentsIfNoChildren: true,
|
||||||
|
@ -13,7 +13,7 @@ import { SortableContext, SortableContextProps, useSortable } from '@dnd-kit/sor
|
|||||||
import { css, cx } from '@emotion/css';
|
import { css, cx } from '@emotion/css';
|
||||||
import { ArrayField } from '@formily/core';
|
import { ArrayField } from '@formily/core';
|
||||||
import { spliceArrayState } from '@formily/core/esm/shared/internals';
|
import { spliceArrayState } from '@formily/core/esm/shared/internals';
|
||||||
import { RecursionField, Schema, observer, useField, useFieldSchema } from '@formily/react';
|
import { RecursionField, Schema, SchemaOptionsContext, observer, useField, useFieldSchema } from '@formily/react';
|
||||||
import { action } from '@formily/reactive';
|
import { action } from '@formily/reactive';
|
||||||
import { uid } from '@formily/shared';
|
import { uid } from '@formily/shared';
|
||||||
import { isPortalInBody } from '@nocobase/utils/client';
|
import { isPortalInBody } from '@nocobase/utils/client';
|
||||||
@ -26,10 +26,12 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { useInView } from 'react-intersection-observer';
|
import { useInView } from 'react-intersection-observer';
|
||||||
import { DndContext, useDesignable, useTableSize } from '../..';
|
import { DndContext, useDesignable, useTableSize } from '../..';
|
||||||
import {
|
import {
|
||||||
|
CollectionFieldOriginalContext,
|
||||||
RecordIndexProvider,
|
RecordIndexProvider,
|
||||||
RecordProvider,
|
RecordProvider,
|
||||||
useCollection,
|
useCollection,
|
||||||
useCollectionParentRecordData,
|
useCollectionParentRecordData,
|
||||||
|
useDataBlockProps,
|
||||||
useDataBlockRequest,
|
useDataBlockRequest,
|
||||||
useFlag,
|
useFlag,
|
||||||
useSchemaInitializerRender,
|
useSchemaInitializerRender,
|
||||||
@ -321,11 +323,18 @@ const usePaginationProps = (pagination1, pagination2) => {
|
|||||||
[JSON.stringify({ ...pagination1, ...pagination2 })],
|
[JSON.stringify({ ...pagination1, ...pagination2 })],
|
||||||
);
|
);
|
||||||
const { total: totalCount, current, pageSize } = pagination || {};
|
const { total: totalCount, current, pageSize } = pagination || {};
|
||||||
|
const blockProps = useDataBlockProps();
|
||||||
|
const original = useContext(CollectionFieldOriginalContext);
|
||||||
|
const { components } = useContext(SchemaOptionsContext);
|
||||||
|
const C = original?.fieldSchema?.['x-component-props']?.summary?.Component || blockProps?.summary?.Component;
|
||||||
const showTotal = useCallback(
|
const showTotal = useCallback(
|
||||||
(total) => {
|
(total) => {
|
||||||
|
if (components[C]) {
|
||||||
|
return React.createElement(components[C]);
|
||||||
|
}
|
||||||
return t('Total {{count}} items', { count: total });
|
return t('Total {{count}} items', { count: total });
|
||||||
},
|
},
|
||||||
[t, totalCount],
|
[components, C, t],
|
||||||
);
|
);
|
||||||
const result = useMemo(() => {
|
const result = useMemo(() => {
|
||||||
if (totalCount) {
|
if (totalCount) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user