@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
44import { Link , useNavigate } from 'react-router-dom' ;
55
66import { useImmer } from '@react-devui/hooks' ;
7- import { CaretDownOutlined , CaretUpOutlined , DCustomIcon , EllipsisOutlined } from '@react-devui/icons' ;
7+ import { CaretDownOutlined , CaretUpOutlined , DCustomIcon , EllipsisOutlined , LoadingOutlined } from '@react-devui/icons' ;
88import { DButton , DSeparator , DTable , DDropdown , DEmpty , DCard } from '@react-devui/ui' ;
99import { getClassName } from '@react-devui/utils' ;
1010
@@ -46,9 +46,10 @@ export interface AppTableProps<T> {
4646 index : number
4747 ) => {
4848 text : string ;
49- onclick ?: ( ) => void ;
49+ onclick ?: ( ) => void | Promise < void > ;
5050 link ?: string ;
5151 render ?: ( node : React . ReactElement ) => React . ReactNode ;
52+ loading ?: boolean ;
5253 hidden ?: boolean ;
5354 } [ ] ;
5455 width : number | string ;
@@ -153,8 +154,8 @@ export function AppTable<T = any>(props: AppTableProps<T>): JSX.Element | null {
153154 { action . text }
154155 </ Link >
155156 ) : (
156- < DButton dType = "link" onClick = { action . onclick } >
157- { action . text }
157+ < DButton disabled = { action . loading } dType = "link" onClick = { action . onclick } >
158+ { action . loading ? < LoadingOutlined dSpin /> : action . text }
158159 </ DButton >
159160 ) ;
160161 return action . render ? action . render ( node ) : node ;
@@ -175,7 +176,7 @@ export function AppTable<T = any>(props: AppTableProps<T>): JSX.Element | null {
175176 if ( actions [ id ] . link ) {
176177 navigate ( actions [ id ] . link ! ) ;
177178 } else {
178- actions [ id ] . onclick ?.( ) ;
179+ return actions [ id ] . onclick ?.( ) ;
179180 }
180181 } }
181182 >
@@ -238,18 +239,18 @@ export function AppTable<T = any>(props: AppTableProps<T>): JSX.Element | null {
238239 return undefined ;
239240 }
240241
241- const getAction = ( action : typeof actions [ 0 ] ) => {
242- const node = action . link ? (
243- < Link className = "app-link" to = { action . link } >
244- < EllipsisOutlined />
245- </ Link >
246- ) : (
247- < DButton dType = "link" dIcon = { < EllipsisOutlined /> } onClick = { action . onclick } > </ DButton >
248- ) ;
249- return action . render ? action . render ( node ) : node ;
250- } ;
251242 return actions . length === 1 && actions [ 0 ] . link ? (
252- getAction ( actions [ 0 ] )
243+ ( ( ) => {
244+ const action = actions [ 0 ] ;
245+ const node = action . link ? (
246+ < Link className = "app-link" to = { action . link } >
247+ < EllipsisOutlined />
248+ </ Link >
249+ ) : (
250+ < DButton dType = "link" dIcon = { < EllipsisOutlined /> } onClick = { action . onclick } > </ DButton >
251+ ) ;
252+ return action . render ? action . render ( node ) : node ;
253+ } ) ( )
253254 ) : (
254255 < DDropdown
255256 dList = { actions . map ( ( action , indexOfAction ) => ( {
@@ -262,7 +263,7 @@ export function AppTable<T = any>(props: AppTableProps<T>): JSX.Element | null {
262263 if ( actions [ id ] . link ) {
263264 navigate ( actions [ id ] . link ! ) ;
264265 } else {
265- actions [ id ] . onclick ?.( ) ;
266+ return actions [ id ] . onclick ?.( ) ;
266267 }
267268 } }
268269 >
@@ -318,7 +319,9 @@ export function AppTable<T = any>(props: AppTableProps<T>): JSX.Element | null {
318319 { action . text }
319320 </ DCard . Action >
320321 ) : (
321- < DCard . Action onClick = { action . onclick } > { action . text } </ DCard . Action >
322+ < DCard . Action disabled = { action . loading } onClick = { action . onclick } >
323+ { action . loading ? < LoadingOutlined dSpin /> : action . text }
324+ </ DCard . Action >
322325 ) ;
323326 return action . render ? action . render ( node ) : node ;
324327 } ;
@@ -340,7 +343,7 @@ export function AppTable<T = any>(props: AppTableProps<T>): JSX.Element | null {
340343 if ( actions [ id ] . link ) {
341344 navigate ( actions [ id ] . link ! ) ;
342345 } else {
343- actions [ id ] . onclick ?.( ) ;
346+ return actions [ id ] . onclick ?.( ) ;
344347 }
345348 } }
346349 >
0 commit comments