Commit c938c0d7 authored by chenshouchao's avatar chenshouchao

feat: 表格增加禁用功能

parent 28b78e92
...@@ -18,6 +18,7 @@ export type IQueueLi = { ...@@ -18,6 +18,7 @@ export type IQueueLi = {
memory: number; memory: number;
total: number; total: number;
partition: string; partition: string;
enabled: boolean;
}; };
type IQueueSelectProps = { type IQueueSelectProps = {
...@@ -44,6 +45,7 @@ export type IShowCPULi = { ...@@ -44,6 +45,7 @@ export type IShowCPULi = {
cpuName: string; cpuName: string;
coreNum: number; coreNum: number;
partition: string; partition: string;
enabled: boolean;
memoryList: Array<IMemoryLi>; memoryList: Array<IMemoryLi>;
}; };
...@@ -153,6 +155,7 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -153,6 +155,7 @@ const QueueSelect = (props: IQueueSelectProps) => {
cpuName: item.cpuName, cpuName: item.cpuName,
coreNum: item.coreNum, coreNum: item.coreNum,
partition: item.partition, partition: item.partition,
enabled: item.enabled,
memoryList: [ memoryList: [
{ {
memory: item.memory, memory: item.memory,
...@@ -347,6 +350,7 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -347,6 +350,7 @@ const QueueSelect = (props: IQueueSelectProps) => {
activeId={activePartition} activeId={activePartition}
tableKey="partition" tableKey="partition"
loading={cpuLoading} loading={cpuLoading}
disableFn={(row: any) => !row.enabled}
></MyTable> ></MyTable>
)} )}
{queueType === "GPU" && ( {queueType === "GPU" && (
...@@ -364,6 +368,7 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -364,6 +368,7 @@ const QueueSelect = (props: IQueueSelectProps) => {
activeId={activePartition} activeId={activePartition}
tableKey="partition" tableKey="partition"
loading={gpuLoading} loading={gpuLoading}
disableFn={(row: any) => !row.enabled}
></MyTable> ></MyTable>
)} )}
</div> </div>
......
...@@ -46,6 +46,7 @@ interface IMyTableProps { ...@@ -46,6 +46,7 @@ interface IMyTableProps {
nodataText?: any; // 无数据文案 nodataText?: any; // 无数据文案
handleRow?: any; // 点击一行 handleRow?: any; // 点击一行
activeId?: string; // 选中的一行的id activeId?: string; // 选中的一行的id
disableFn?: any; // 禁用时根据disableFn来判断是否禁用
} }
const MyTable = (props: IMyTableProps) => { const MyTable = (props: IMyTableProps) => {
...@@ -71,6 +72,7 @@ const MyTable = (props: IMyTableProps) => { ...@@ -71,6 +72,7 @@ const MyTable = (props: IMyTableProps) => {
nodataText, nodataText,
handleRow, handleRow,
activeId, activeId,
disableFn,
} = props; } = props;
const theme = useMemo(() => { const theme = useMemo(() => {
...@@ -236,6 +238,17 @@ const MyTable = (props: IMyTableProps) => { ...@@ -236,6 +238,17 @@ const MyTable = (props: IMyTableProps) => {
[selectItems, setSelectItems] [selectItems, setSelectItems]
); );
const handleRowFn = useCallback(
(row: any) => {
if (!disableFn) {
handleRow && handleRow(row);
} else {
!disableFn(row) && handleRow && handleRow(row);
}
},
[disableFn, handleRow]
);
const handleSort = useCallback( const handleSort = useCallback(
(field: string) => { (field: string) => {
if (sortState?.field === field) { if (sortState?.field === field) {
...@@ -370,10 +383,13 @@ const MyTable = (props: IMyTableProps) => { ...@@ -370,10 +383,13 @@ const MyTable = (props: IMyTableProps) => {
{rows.map((row, rowIndex) => ( {rows.map((row, rowIndex) => (
<TableRow <TableRow
key={row[tableKey] || rowIndex} key={row[tableKey] || rowIndex}
onClick={() => handleRow && handleRow(row)} // onClick={() => handleRow && handleRow(row)}
onClick={() => handleRowFn(row)}
sx={{ sx={{
background: background:
activeId === row[tableKey] ? "rgba(237, 244, 255, 1)" : "", activeId === row[tableKey] ? "rgba(237, 244, 255, 1)" : "",
cursor: disableFn && disableFn(row) ? "no-drop" : "",
opacity: disableFn && disableFn(row) ? "0.3" : "",
}} }}
> >
{hasCheckbox && ( {hasCheckbox && (
...@@ -393,12 +409,10 @@ const MyTable = (props: IMyTableProps) => { ...@@ -393,12 +409,10 @@ const MyTable = (props: IMyTableProps) => {
)} )}
{headCells.map((headCell, index) => ( {headCells.map((headCell, index) => (
<TableCell key={index} align="left" width={headCell.width}> <TableCell key={index} align="left" width={headCell.width}>
{/* {row[headCell.id]} */}
{headCell.showOverflowTooltip && ( {headCell.showOverflowTooltip && (
<MyTooltip title={row[headCell.id]}> <MyTooltip title={row[headCell.id]}>
<div <div
style={{ style={{
// width: headCell.width,
width: Number(headCell.width) - 32 || "", width: Number(headCell.width) - 32 || "",
overflow: "hidden", overflow: "hidden",
textOverflow: "ellipsis", textOverflow: "ellipsis",
...@@ -433,8 +447,9 @@ const MyTable = (props: IMyTableProps) => { ...@@ -433,8 +447,9 @@ const MyTable = (props: IMyTableProps) => {
headCells, headCells,
nodataText, nodataText,
loading, loading,
handleRow, handleRowFn,
activeId, activeId,
disableFn,
]); ]);
const randerTableFooter = useMemo(() => { const randerTableFooter = useMemo(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment