From 5752edd5d5a85382f95f1d321d50b92bfab6f7d8 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Wed, 29 Mar 2023 17:56:05 +0800 Subject: [PATCH] feat(table): hidden pagination when only one page is available (#1614) * feat(table): hidden pagination when only one page is available * feat: remove console * fix(table): add new button for edit button color does not work * fix: don't support edit type and icon in Link * feat: danger property first * fix: reset shadow of danger button * perf: remove unused logic --- .../src/schema-component/antd/action/Action.Designer.tsx | 4 +++- packages/core/client/src/schema-component/antd/index.less | 7 ++++++- .../client/src/schema-component/antd/table-v2/Table.tsx | 4 +++- .../client/src/schema-initializer/SchemaInitializer.tsx | 2 +- .../schema-initializer/components/CreateRecordAction.tsx | 8 +++++--- .../schema-initializer/items/CreateActionInitializer.tsx | 1 + 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx b/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx index 32aa32e925..acb1a0a325 100644 --- a/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx +++ b/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx @@ -52,6 +52,7 @@ export const ActionDesigner = (props) => { const isLinkageAction = Object.keys(useFormBlockContext()).length > 0 && Object.keys(useRecord()).length > 0; const isChildCollectionAction = getChildrenCollections(name).length > 0 && fieldSchema['x-action'] === 'create'; const isSupportEditButton = fieldSchema['x-action'] !== 'expandAll'; + const isLink = fieldSchema['x-component'] === 'Action.Link'; useEffect(() => { const schemaUid = uid(); const schema: ISchema = { @@ -96,7 +97,7 @@ export const ActionDesigner = (props) => { title: t('Button icon'), default: fieldSchema?.['x-component-props']?.icon, 'x-component-props': {}, - 'x-visible': isSupportEditButton, + 'x-visible': isSupportEditButton && !isLink, // description: `原字段标题:${collectionField?.uiSchema?.title}`, }, type: { @@ -113,6 +114,7 @@ export const ActionDesigner = (props) => { { value: 'primary', label: '{{t("Highlight")}}' }, { value: 'danger', label: '{{t("Danger red")}}' }, ], + 'x-visible': !isLink, }, }, } as ISchema diff --git a/packages/core/client/src/schema-component/antd/index.less b/packages/core/client/src/schema-component/antd/index.less index fa2dbbc1a3..afe7e71123 100644 --- a/packages/core/client/src/schema-component/antd/index.less +++ b/packages/core/client/src/schema-component/antd/index.less @@ -1,3 +1,8 @@ +.ant-btn.ant-btn-danger { + text-shadow: none; + box-shadow: none; +} + .ant-formily-item-label { color: #000000d9; font-weight:600; @@ -21,4 +26,4 @@ .m24 { margin: 16px !important; } -} \ No newline at end of file +} diff --git a/packages/core/client/src/schema-component/antd/table-v2/Table.tsx b/packages/core/client/src/schema-component/antd/table-v2/Table.tsx index bdbd6b762d..a8f0c0a60d 100644 --- a/packages/core/client/src/schema-component/antd/table-v2/Table.tsx +++ b/packages/core/client/src/schema-component/antd/table-v2/Table.tsx @@ -125,12 +125,14 @@ const usePaginationProps = (pagination1, pagination2) => { if (!pagination2 && pagination1 === false) { return false; } - return { + + const result = { showTotal: (total) => t('Total {{count}} items', { count: total }), showSizeChanger: true, ...pagination1, ...pagination2, }; + return result.total < result.pageSize ? false : result; }; const useValidator = (validator: (value: any) => string) => { diff --git a/packages/core/client/src/schema-initializer/SchemaInitializer.tsx b/packages/core/client/src/schema-initializer/SchemaInitializer.tsx index 9162873410..cb198b6f18 100644 --- a/packages/core/client/src/schema-initializer/SchemaInitializer.tsx +++ b/packages/core/client/src/schema-initializer/SchemaInitializer.tsx @@ -56,7 +56,7 @@ SchemaInitializer.Button = observer((props: SchemaInitializerButtonProps) => { return ; } if (item.type === 'item' && item.component) { - const Component = typeof item.component === 'string' ? findComponent(item.component) : item.component; + const Component = findComponent(item.component); item.key = `${item.key || item.title}-${indexA}`; return ( Component && ( diff --git a/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx b/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx index d23e034f44..2bf5388d59 100644 --- a/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx +++ b/packages/core/client/src/schema-initializer/components/CreateRecordAction.tsx @@ -84,6 +84,7 @@ export const CreateRecordAction = observer((props) => { const fieldSchema = useFieldSchema(); const enableChildren = fieldSchema['x-enable-children'] || []; const field = useField(); + const componentType = field.componentProps.type || 'primary'; const { getChildrenCollections } = useCollectionManager(); const totalChildCollections = getChildrenCollections(collection.name); const inheritsCollections = enableChildren @@ -97,7 +98,7 @@ export const CreateRecordAction = observer((props) => { } return { ...childCollection, - title: k.title||childCollection.title, + title: k.title || childCollection.title, }; }) .filter((v) => { @@ -128,7 +129,7 @@ export const CreateRecordAction = observer((props) => { {inheritsCollections?.length > 0 ? ( } buttonsRender={([leftButton, rightButton]) => [ leftButton, @@ -145,7 +146,8 @@ export const CreateRecordAction = observer((props) => { ) : (