From 205c23b656265adf6d6a5d5496b98f96cf7ff5ba Mon Sep 17 00:00:00 2001 From: Ayden Date: Thu, 14 Jul 2022 20:58:21 +0800 Subject: [PATCH] feat: table action add reload button (#630) * feat: table action add reload button * feat: reload => refresh * feat: reload icon --- .../client/src/block-provider/hooks/index.ts | 9 +++++++++ packages/core/client/src/locale/en_US.ts | 1 + packages/core/client/src/locale/zh_CN.ts | 1 + .../buttons/TableActionInitializers.tsx | 12 ++++++++++++ .../src/schema-initializer/items/index.tsx | 16 +++++++++++++++- 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/core/client/src/block-provider/hooks/index.ts b/packages/core/client/src/block-provider/hooks/index.ts index 41d16bc7b..a2d7277d0 100644 --- a/packages/core/client/src/block-provider/hooks/index.ts +++ b/packages/core/client/src/block-provider/hooks/index.ts @@ -415,6 +415,15 @@ export const useBulkDestroyActionProps = () => { }; }; +export const useRefreshActionProps = () => { + const { service } = useBlockRequestContext(); + return { + async onClick() { + service?.refresh?.(); + }, + }; +} + export const useDetailsPaginationProps = () => { const ctx = useDetailsBlockContext(); const count = ctx.service?.data?.meta?.count || 0; diff --git a/packages/core/client/src/locale/en_US.ts b/packages/core/client/src/locale/en_US.ts index b71128507..65075700f 100644 --- a/packages/core/client/src/locale/en_US.ts +++ b/packages/core/client/src/locale/en_US.ts @@ -98,6 +98,7 @@ export default { "Update": "Update", "View": "View", "View record": "View record", + "Refresh": "Refresh", "Data changes": "Data changes", "Field name": "Field name", "Before change": "Before change", diff --git a/packages/core/client/src/locale/zh_CN.ts b/packages/core/client/src/locale/zh_CN.ts index 9bb763d6b..00ae17085 100644 --- a/packages/core/client/src/locale/zh_CN.ts +++ b/packages/core/client/src/locale/zh_CN.ts @@ -99,6 +99,7 @@ export default { "Update": "更新", "View": "查看", "View record": "查看数据", + "Refresh": "刷新", "Data changes": "数据变更", "Field name": "字段标识", diff --git a/packages/core/client/src/schema-initializer/buttons/TableActionInitializers.tsx b/packages/core/client/src/schema-initializer/buttons/TableActionInitializers.tsx index 384e0c92e..2fe60633a 100644 --- a/packages/core/client/src/schema-initializer/buttons/TableActionInitializers.tsx +++ b/packages/core/client/src/schema-initializer/buttons/TableActionInitializers.tsx @@ -42,6 +42,18 @@ export const TableActionInitializers = { }, }, }, + { + type: 'item', + title: "{{t('Refresh')}}", + component: 'RefreshActionInitializer', + schema: { + 'x-align': 'right', + 'x-decorator': 'ACLActionProvider', + 'x-acl-action-props': { + skipScopeCheck: true, + }, + }, + }, ], }, ], diff --git a/packages/core/client/src/schema-initializer/items/index.tsx b/packages/core/client/src/schema-initializer/items/index.tsx index 470f784cf..7906c6c22 100644 --- a/packages/core/client/src/schema-initializer/items/index.tsx +++ b/packages/core/client/src/schema-initializer/items/index.tsx @@ -538,6 +538,20 @@ export const BulkDestroyActionInitializer = (props) => { return ; }; +export const RefreshActionInitializer = (props) => { + const schema = { + title: '{{ t("Refresh") }}', + 'x-action': 'refresh', + 'x-component': 'Action', + 'x-designer': 'Action.Designer', + 'x-component-props': { + icon: 'ReloadOutlined', + useProps: '{{ useRefreshActionProps }}', + }, + }; + return ; +}; + export const SubmitActionInitializer = (props) => { const schema = { title: '{{ t("Submit") }}', @@ -728,7 +742,7 @@ export const RecordAssociationFormBlockInitializer = (props) => { icon={} {...others} onClick={async ({ item }) => { - + const action = ['hasOne', 'belongsTo'].includes(field.type) ? 'get' : null; const actionInitializers = ['hasOne', 'belongsTo'].includes(field.type) ? 'UpdateFormActionInitializers' : 'CreateFormActionInitializers';