Skip to content

Commit 8a91f3e

Browse files
committed
chore(platform): optimize table
1 parent 4d0f87a commit 8a91f3e

3 files changed

Lines changed: 36 additions & 20 deletions

File tree

packages/platform/src/app/components/table/Table.tsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
44
import { Link, useNavigate } from 'react-router-dom';
55

66
import { 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';
88
import { DButton, DSeparator, DTable, DDropdown, DEmpty, DCard } from '@react-devui/ui';
99
import { 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
>

packages/platform/src/app/routes/list/standard-table/StandardTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ export default AppRoute(() => {
342342
aScroll={{ x: 1200 }}
343343
aLabelWidth={72}
344344
/>
345-
<div className="mt-3 d-flex align-items-center justify-content-between flex-wrap" style={{ gap: '10px 12px' }}>
345+
<div className="app-table-footer">
346346
<div>
347347
<DButton className="me-2" disabled={allDeviceSelected === false} dType="secondary">
348348
Download

packages/platform/src/styles/_app.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,16 @@ body {
5454
font-size: 1.1em;
5555
font-weight: 500;
5656
}
57+
58+
.app-table-footer {
59+
display: flex;
60+
flex-wrap: wrap;
61+
row-gap: 10px;
62+
align-items: center;
63+
justify-content: space-between;
64+
margin-top: 20px;
65+
66+
& > div:first-child {
67+
margin-right: 20px;
68+
}
69+
}

0 commit comments

Comments
 (0)