From 6b84446697b9300c75f073d8e2730610ee190b77 Mon Sep 17 00:00:00 2001 From: chenos Date: Fri, 11 Dec 2020 15:11:45 +0800 Subject: [PATCH] feat: add onTrigger to Actions component --- packages/app/src/components/actions/Destroy.tsx | 14 +++++++++----- packages/app/src/components/actions/index.tsx | 16 ++++++++++++---- .../app/src/components/views/SimpleTable.tsx | 12 ++++++++++++ packages/app/src/components/views/Table.tsx | 12 ++++++++++++ 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/packages/app/src/components/actions/Destroy.tsx b/packages/app/src/components/actions/Destroy.tsx index bbc9195e29..11c961b4c2 100644 --- a/packages/app/src/components/actions/Destroy.tsx +++ b/packages/app/src/components/actions/Destroy.tsx @@ -1,16 +1,20 @@ import React, { useRef } from 'react'; -import { Button } from 'antd'; +import { Button, Popconfirm } from 'antd'; import ViewFactory from '@/components/views'; export function Destroy(props) { console.log(props); - const { title, viewId } = props.schema; + const { onTrigger } = props; + const { title, viewId, isBulk = true } = props.schema; const drawerRef = useRef(); return ( <> - + { + console.log('destroy', onTrigger); + onTrigger && onTrigger(); + }}> + + ) } diff --git a/packages/app/src/components/actions/index.tsx b/packages/app/src/components/actions/index.tsx index f059b8192a..b079651bab 100644 --- a/packages/app/src/components/actions/index.tsx +++ b/packages/app/src/components/actions/index.tsx @@ -25,15 +25,23 @@ export function Action(props) { const { schema = {} } = props; // cnsole.log(schema); const { type } = schema; - const Action = getAction(type); - return Action && ; + const Component = getAction(type); + return Component && ; } export function Actions(props) { - const { style, schema, actions = [] } = props; + const { onTrigger = {}, style, schema, actions = [], ...restProps } = props; + console.log(onTrigger); return actions.length > 0 && ( - {actions.map(action => )} + {actions.map(action => ( + + ))} ); } diff --git a/packages/app/src/components/views/SimpleTable.tsx b/packages/app/src/components/views/SimpleTable.tsx index 710c0d7e13..26eb239a1b 100644 --- a/packages/app/src/components/views/SimpleTable.tsx +++ b/packages/app/src/components/views/SimpleTable.tsx @@ -71,6 +71,18 @@ export function SimpleTable(props: SimpleTableProps) { onFinish={() => { refresh(); }} + onTrigger={{ + async destroy() { + await api.resource(name).destroy({ + associatedKey, + filter: { + [`${rowKey}.in`]: selectedRowKeys, + }, + }); + await refresh(); + console.log('destroy.onTrigger', selectedRowKeys); + } + }} /> { refresh(); }} + onTrigger={{ + async destroy() { + await api.resource(name).destroy({ + associatedKey, + filter: { + [`${rowKey}.in`]: selectedRowKeys, + }, + }); + await refresh(); + console.log('destroy.onTrigger', selectedRowKeys); + } + }} />