style: worker filter bar
This commit is contained in:
@@ -56,22 +56,24 @@ interface FilterBarProps {
|
|||||||
handleInputChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
handleInputChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
||||||
handleSelectChange?: (value: any) => void;
|
handleSelectChange?: (value: any) => void;
|
||||||
handleSearch: () => void;
|
handleSearch: () => void;
|
||||||
handleDeleteByBatch: () => void;
|
handleDeleteByBatch?: () => void;
|
||||||
handleClickPrimary: (item: any) => void;
|
handleClickPrimary?: (item: any) => void;
|
||||||
rowSelection: any;
|
rowSelection?: any;
|
||||||
actionItems: ActionItem[];
|
actionItems?: ActionItem[];
|
||||||
selectOptions?: Global.BaseOption<string | number>[];
|
selectOptions?: Global.BaseOption<string | number>[];
|
||||||
showSelect?: boolean;
|
showSelect?: boolean;
|
||||||
buttonText: string;
|
buttonText: string;
|
||||||
buttonIcon?: React.ReactNode;
|
buttonIcon?: React.ReactNode;
|
||||||
marginBottom?: number;
|
marginBottom?: number;
|
||||||
marginTop?: number;
|
marginTop?: number;
|
||||||
inputHolder: string;
|
inputHolder?: string;
|
||||||
selectHolder: string;
|
selectHolder?: string;
|
||||||
actionType: 'dropdown' | 'button';
|
actionType?: 'dropdown' | 'button';
|
||||||
|
showPrimaryButton?: boolean;
|
||||||
|
showDeleteButton?: boolean;
|
||||||
width?: {
|
width?: {
|
||||||
input: number;
|
input?: number;
|
||||||
select: number;
|
select?: number;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,15 +90,64 @@ export const FilterBar: React.FC<FilterBarProps> = (props) => {
|
|||||||
showSelect,
|
showSelect,
|
||||||
buttonText,
|
buttonText,
|
||||||
buttonIcon,
|
buttonIcon,
|
||||||
actionType,
|
actionType = 'button',
|
||||||
marginBottom = 10,
|
marginBottom = 10,
|
||||||
marginTop = 10,
|
marginTop = 10,
|
||||||
inputHolder,
|
inputHolder = 'common.filter.name',
|
||||||
selectHolder,
|
selectHolder,
|
||||||
|
showPrimaryButton = true,
|
||||||
|
showDeleteButton = true,
|
||||||
width
|
width
|
||||||
} = props;
|
} = props;
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
|
const renderRight = useMemo(() => {
|
||||||
|
if (!showPrimaryButton && !showDeleteButton) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Space size={20}>
|
||||||
|
{actionType === 'dropdown' ? (
|
||||||
|
<DropDownActions
|
||||||
|
menu={{
|
||||||
|
items: actionItems,
|
||||||
|
onClick: handleClickPrimary
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
icon={<DownOutlined></DownOutlined>}
|
||||||
|
type="primary"
|
||||||
|
iconPosition="end"
|
||||||
|
>
|
||||||
|
{buttonText}
|
||||||
|
</Button>
|
||||||
|
</DropDownActions>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
icon={buttonIcon ?? <PlusOutlined></PlusOutlined>}
|
||||||
|
type="primary"
|
||||||
|
onClick={handleClickPrimary}
|
||||||
|
>
|
||||||
|
{buttonText}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
icon={<DeleteOutlined />}
|
||||||
|
danger
|
||||||
|
onClick={handleDeleteByBatch}
|
||||||
|
disabled={!rowSelection.selectedRowKeys.length}
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
{intl?.formatMessage?.({ id: 'common.button.delete' })}
|
||||||
|
{rowSelection.selectedRowKeys.length > 0 && (
|
||||||
|
<span>({rowSelection.selectedRowKeys?.length})</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</Button>
|
||||||
|
</Space>
|
||||||
|
);
|
||||||
|
}, [actionItems, actionType]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageTools
|
<PageTools
|
||||||
marginBottom={marginBottom}
|
marginBottom={marginBottom}
|
||||||
@@ -132,47 +183,7 @@ export const FilterBar: React.FC<FilterBarProps> = (props) => {
|
|||||||
></Button>
|
></Button>
|
||||||
</Space>
|
</Space>
|
||||||
}
|
}
|
||||||
right={
|
right={renderRight}
|
||||||
<Space size={20}>
|
|
||||||
{actionType === 'dropdown' ? (
|
|
||||||
<DropDownActions
|
|
||||||
menu={{
|
|
||||||
items: actionItems,
|
|
||||||
onClick: handleClickPrimary
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
icon={<DownOutlined></DownOutlined>}
|
|
||||||
type="primary"
|
|
||||||
iconPosition="end"
|
|
||||||
>
|
|
||||||
{buttonText}
|
|
||||||
</Button>
|
|
||||||
</DropDownActions>
|
|
||||||
) : (
|
|
||||||
<Button
|
|
||||||
icon={buttonIcon ?? <PlusOutlined></PlusOutlined>}
|
|
||||||
type="primary"
|
|
||||||
onClick={handleClickPrimary}
|
|
||||||
>
|
|
||||||
{buttonText}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
<Button
|
|
||||||
icon={<DeleteOutlined />}
|
|
||||||
danger
|
|
||||||
onClick={handleDeleteByBatch}
|
|
||||||
disabled={!rowSelection.selectedRowKeys.length}
|
|
||||||
>
|
|
||||||
<span>
|
|
||||||
{intl?.formatMessage?.({ id: 'common.button.delete' })}
|
|
||||||
{rowSelection.selectedRowKeys.length > 0 && (
|
|
||||||
<span>({rowSelection.selectedRowKeys?.length})</span>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
</Button>
|
|
||||||
</Space>
|
|
||||||
}
|
|
||||||
></PageTools>
|
></PageTools>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,8 +13,16 @@ export default function useTableFetch<ListItem>(options: {
|
|||||||
fetchAPI: (params: any) => Promise<Global.PageResponse<ListItem>>;
|
fetchAPI: (params: any) => Promise<Global.PageResponse<ListItem>>;
|
||||||
deleteAPI?: (id: number, params?: any) => Promise<any>;
|
deleteAPI?: (id: number, params?: any) => Promise<any>;
|
||||||
contentForDelete?: string;
|
contentForDelete?: string;
|
||||||
|
defaultData?: any[];
|
||||||
}) {
|
}) {
|
||||||
const { fetchAPI, deleteAPI, contentForDelete, API, watch } = options;
|
const {
|
||||||
|
fetchAPI,
|
||||||
|
deleteAPI,
|
||||||
|
contentForDelete,
|
||||||
|
API,
|
||||||
|
watch,
|
||||||
|
defaultData = []
|
||||||
|
} = options;
|
||||||
const chunkRequedtRef = useRef<any>(null);
|
const chunkRequedtRef = useRef<any>(null);
|
||||||
const modalRef = useRef<any>(null);
|
const modalRef = useRef<any>(null);
|
||||||
const rowSelection = useTableRowSelection();
|
const rowSelection = useTableRowSelection();
|
||||||
@@ -28,7 +36,7 @@ export default function useTableFetch<ListItem>(options: {
|
|||||||
loadend: boolean;
|
loadend: boolean;
|
||||||
total: number;
|
total: number;
|
||||||
}>({
|
}>({
|
||||||
dataList: [],
|
dataList: [...defaultData],
|
||||||
loading: false,
|
loading: false,
|
||||||
loadend: false,
|
loadend: false,
|
||||||
total: 0
|
total: 0
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import AutoTooltip from '@/components/auto-tooltip';
|
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 ProgressBar from '@/components/progress-bar';
|
||||||
import InfoColumn from '@/components/simple-table/info-column';
|
import InfoColumn from '@/components/simple-table/info-column';
|
||||||
import useTableFetch from '@/hooks/use-table-fetch';
|
import useTableFetch from '@/hooks/use-table-fetch';
|
||||||
import { convertFileSize } from '@/utils';
|
import { convertFileSize } from '@/utils';
|
||||||
import { SyncOutlined } from '@ant-design/icons';
|
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Button, ConfigProvider, Empty, Input, Space, Table } from 'antd';
|
import { ConfigProvider, Empty, Table } from 'antd';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import React from 'react';
|
||||||
import { queryGpuDevicesList } from '../apis';
|
import { queryGpuDevicesList } from '../apis';
|
||||||
import { GPUDeviceItem } from '../config/types';
|
import { GPUDeviceItem } from '../config/types';
|
||||||
const { Column } = Table;
|
const { Column } = Table;
|
||||||
@@ -67,30 +67,17 @@ const GPUList: React.FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageTools
|
<FilterBar
|
||||||
marginBottom={10}
|
buttonText={intl.formatMessage({ id: 'resources.button.create' })}
|
||||||
marginTop={10}
|
handleSearch={handleSearch}
|
||||||
left={
|
handleInputChange={handleNameChange}
|
||||||
<Space>
|
showDeleteButton={false}
|
||||||
<Input
|
showPrimaryButton={false}
|
||||||
placeholder={intl.formatMessage({
|
width={{ input: 300 }}
|
||||||
id: 'common.filter.name'
|
></FilterBar>
|
||||||
})}
|
|
||||||
style={{ width: 300 }}
|
|
||||||
allowClear
|
|
||||||
onChange={handleNameChange}
|
|
||||||
></Input>
|
|
||||||
<Button
|
|
||||||
type="text"
|
|
||||||
style={{ color: 'var(--ant-color-text-tertiary)' }}
|
|
||||||
onClick={handleSearch}
|
|
||||||
icon={<SyncOutlined></SyncOutlined>}
|
|
||||||
></Button>
|
|
||||||
</Space>
|
|
||||||
}
|
|
||||||
></PageTools>
|
|
||||||
<ConfigProvider renderEmpty={renderEmpty}>
|
<ConfigProvider renderEmpty={renderEmpty}>
|
||||||
<Table
|
<Table
|
||||||
|
tableLayout={dataSource.loadend ? 'auto' : 'fixed'}
|
||||||
dataSource={dataSource.dataList}
|
dataSource={dataSource.dataList}
|
||||||
loading={dataSource.loading}
|
loading={dataSource.loading}
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import AutoTooltip from '@/components/auto-tooltip';
|
import AutoTooltip from '@/components/auto-tooltip';
|
||||||
import DeleteModal from '@/components/delete-modal';
|
import DeleteModal from '@/components/delete-modal';
|
||||||
import DropdownButtons from '@/components/drop-down-buttons';
|
import DropdownButtons from '@/components/drop-down-buttons';
|
||||||
import PageTools from '@/components/page-tools';
|
import { FilterBar } from '@/components/page-tools';
|
||||||
import ProgressBar from '@/components/progress-bar';
|
import ProgressBar from '@/components/progress-bar';
|
||||||
import InfoColumn from '@/components/simple-table/info-column';
|
import InfoColumn from '@/components/simple-table/info-column';
|
||||||
import StatusTag from '@/components/status-tag';
|
import StatusTag from '@/components/status-tag';
|
||||||
@@ -11,21 +11,10 @@ import { convertFileSize } from '@/utils';
|
|||||||
import {
|
import {
|
||||||
DeleteOutlined,
|
DeleteOutlined,
|
||||||
EditOutlined,
|
EditOutlined,
|
||||||
InfoCircleOutlined,
|
InfoCircleOutlined
|
||||||
PlusOutlined,
|
|
||||||
SyncOutlined
|
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import {
|
import { ConfigProvider, Empty, Table, Tooltip, message } from 'antd';
|
||||||
Button,
|
|
||||||
ConfigProvider,
|
|
||||||
Empty,
|
|
||||||
Input,
|
|
||||||
Space,
|
|
||||||
Table,
|
|
||||||
Tooltip,
|
|
||||||
message
|
|
||||||
} from 'antd';
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import React, { useCallback, useState } from 'react';
|
import React, { useCallback, useState } from 'react';
|
||||||
import { useHotkeys } from 'react-hotkeys-hook';
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
@@ -206,54 +195,18 @@ const Workers: React.FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageTools
|
<FilterBar
|
||||||
marginBottom={10}
|
buttonText={intl.formatMessage({ id: 'resources.button.create' })}
|
||||||
marginTop={10}
|
handleDeleteByBatch={handleDeleteBatch}
|
||||||
left={
|
handleSearch={handleSearch}
|
||||||
<Space>
|
handleClickPrimary={handleAddWorker}
|
||||||
<Input
|
handleInputChange={handleNameChange}
|
||||||
placeholder={intl.formatMessage({
|
rowSelection={rowSelection}
|
||||||
id: 'common.filter.name'
|
width={{ input: 300 }}
|
||||||
})}
|
></FilterBar>
|
||||||
style={{ width: 300 }}
|
|
||||||
allowClear
|
|
||||||
onChange={handleNameChange}
|
|
||||||
></Input>
|
|
||||||
<Button
|
|
||||||
type="text"
|
|
||||||
style={{ color: 'var(--ant-color-text-tertiary)' }}
|
|
||||||
onClick={handleSearch}
|
|
||||||
icon={<SyncOutlined></SyncOutlined>}
|
|
||||||
></Button>
|
|
||||||
</Space>
|
|
||||||
}
|
|
||||||
right={
|
|
||||||
<Space size={20}>
|
|
||||||
<Button
|
|
||||||
icon={<PlusOutlined></PlusOutlined>}
|
|
||||||
type="primary"
|
|
||||||
onClick={handleAddWorker}
|
|
||||||
>
|
|
||||||
{intl.formatMessage({ id: 'resources.button.create' })}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
icon={<DeleteOutlined />}
|
|
||||||
danger
|
|
||||||
onClick={handleDeleteBatch}
|
|
||||||
disabled={!rowSelection.selectedRowKeys.length}
|
|
||||||
>
|
|
||||||
<span>
|
|
||||||
{intl?.formatMessage?.({ id: 'common.button.delete' })}
|
|
||||||
{rowSelection.selectedRowKeys.length > 0 && (
|
|
||||||
<span>({rowSelection.selectedRowKeys?.length})</span>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
</Button>
|
|
||||||
</Space>
|
|
||||||
}
|
|
||||||
></PageTools>
|
|
||||||
<ConfigProvider renderEmpty={renderEmpty}>
|
<ConfigProvider renderEmpty={renderEmpty}>
|
||||||
<Table
|
<Table
|
||||||
|
tableLayout={dataSource.loadend ? 'auto' : 'fixed'}
|
||||||
style={{ width: '100%' }}
|
style={{ width: '100%' }}
|
||||||
dataSource={dataSource.dataList}
|
dataSource={dataSource.dataList}
|
||||||
loading={dataSource.loading}
|
loading={dataSource.loading}
|
||||||
|
|||||||
Reference in New Issue
Block a user