diff --git a/src/components/page-tools/index.tsx b/src/components/page-tools/index.tsx index 279063f1..a0161cfe 100644 --- a/src/components/page-tools/index.tsx +++ b/src/components/page-tools/index.tsx @@ -56,22 +56,24 @@ interface FilterBarProps { handleInputChange: (e: React.ChangeEvent) => void; handleSelectChange?: (value: any) => void; handleSearch: () => void; - handleDeleteByBatch: () => void; - handleClickPrimary: (item: any) => void; - rowSelection: any; - actionItems: ActionItem[]; + handleDeleteByBatch?: () => void; + handleClickPrimary?: (item: any) => void; + rowSelection?: any; + actionItems?: ActionItem[]; selectOptions?: Global.BaseOption[]; showSelect?: boolean; buttonText: string; buttonIcon?: React.ReactNode; marginBottom?: number; marginTop?: number; - inputHolder: string; - selectHolder: string; - actionType: 'dropdown' | 'button'; + inputHolder?: string; + selectHolder?: string; + actionType?: 'dropdown' | 'button'; + showPrimaryButton?: boolean; + showDeleteButton?: boolean; width?: { - input: number; - select: number; + input?: number; + select?: number; }; } @@ -88,15 +90,64 @@ export const FilterBar: React.FC = (props) => { showSelect, buttonText, buttonIcon, - actionType, + actionType = 'button', marginBottom = 10, marginTop = 10, - inputHolder, + inputHolder = 'common.filter.name', selectHolder, + showPrimaryButton = true, + showDeleteButton = true, width } = props; const intl = useIntl(); + const renderRight = useMemo(() => { + if (!showPrimaryButton && !showDeleteButton) { + return null; + } + return ( + + {actionType === 'dropdown' ? ( + + + + ) : ( + + )} + + + ); + }, [actionItems, actionType]); + return ( = (props) => { > } - right={ - - {actionType === 'dropdown' ? ( - - - - ) : ( - - )} - - - } + right={renderRight} > ); }; diff --git a/src/hooks/use-table-fetch.ts b/src/hooks/use-table-fetch.ts index f683fa0c..f58adda3 100644 --- a/src/hooks/use-table-fetch.ts +++ b/src/hooks/use-table-fetch.ts @@ -13,8 +13,16 @@ export default function useTableFetch(options: { fetchAPI: (params: any) => Promise>; deleteAPI?: (id: number, params?: any) => Promise; contentForDelete?: string; + defaultData?: any[]; }) { - const { fetchAPI, deleteAPI, contentForDelete, API, watch } = options; + const { + fetchAPI, + deleteAPI, + contentForDelete, + API, + watch, + defaultData = [] + } = options; const chunkRequedtRef = useRef(null); const modalRef = useRef(null); const rowSelection = useTableRowSelection(); @@ -28,7 +36,7 @@ export default function useTableFetch(options: { loadend: boolean; total: number; }>({ - dataList: [], + dataList: [...defaultData], loading: false, loadend: false, total: 0 diff --git a/src/pages/resources/components/gpus.tsx b/src/pages/resources/components/gpus.tsx index f4fc0469..d237b8bf 100644 --- a/src/pages/resources/components/gpus.tsx +++ b/src/pages/resources/components/gpus.tsx @@ -1,13 +1,13 @@ import AutoTooltip from '@/components/auto-tooltip'; -import PageTools from '@/components/page-tools'; +import { FilterBar } from '@/components/page-tools'; import ProgressBar from '@/components/progress-bar'; import InfoColumn from '@/components/simple-table/info-column'; import useTableFetch from '@/hooks/use-table-fetch'; import { convertFileSize } from '@/utils'; -import { SyncOutlined } from '@ant-design/icons'; import { useIntl } from '@umijs/max'; -import { Button, ConfigProvider, Empty, Input, Space, Table } from 'antd'; +import { ConfigProvider, Empty, Table } from 'antd'; import _ from 'lodash'; +import React from 'react'; import { queryGpuDevicesList } from '../apis'; import { GPUDeviceItem } from '../config/types'; const { Column } = Table; @@ -67,30 +67,17 @@ const GPUList: React.FC = () => { return ( <> - - - - - } - > + { return ( <> - - - - - } - right={ - - - - - } - > +