Commit fb4b38d9 authored by chenshouchao's avatar chenshouchao

feat: 硬件队列选择器的key由id改为partition

parent 9edf10e3
...@@ -18,6 +18,7 @@ export type IQueueLi = { ...@@ -18,6 +18,7 @@ export type IQueueLi = {
memory: number; memory: number;
total: number; total: number;
id: string; id: string;
partition: string;
}; };
type IQueueSelectProps = { type IQueueSelectProps = {
...@@ -34,6 +35,7 @@ type IMemoryLi = { ...@@ -34,6 +35,7 @@ type IMemoryLi = {
memory: number; memory: number;
total: number; total: number;
id: string; id: string;
partition: string;
}; };
export type IShowCPULi = { export type IShowCPULi = {
...@@ -42,6 +44,7 @@ export type IShowCPULi = { ...@@ -42,6 +44,7 @@ export type IShowCPULi = {
cpuName: string; cpuName: string;
coreNum: number; coreNum: number;
id: string; id: string;
partition: string;
memoryList: Array<IMemoryLi>; memoryList: Array<IMemoryLi>;
}; };
...@@ -67,20 +70,20 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -67,20 +70,20 @@ const QueueSelect = (props: IQueueSelectProps) => {
disabled, disabled,
} = props; } = props;
const Message = useMessage(); const Message = useMessage();
const [activeId, setActiveId] = useState(""); const [activePartition, setActivePartition] = useState("");
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [queueType, setQueueType] = useState("CPU"); const [queueType, setQueueType] = useState("CPU");
const [showCpuList, setShowCpuList] = useState<Array<IShowCPULi>>([]); const [showCpuList, setShowCpuList] = useState<Array<IShowCPULi>>([]);
const handleOpen = () => { const handleOpen = () => {
// setActiveId("");
setOpen(true); setOpen(true);
}; };
// 队列id和前端展示的队列信息的映射关系 // 队列id、partition和前端展示的队列信息的映射关系
const idInfoMap = useMemo(() => { const idInfoMap = useMemo(() => {
return [ return [
...originalCpuList.map((item) => ({ ...originalCpuList.map((item) => ({
id: item.id, id: item.id,
partition: item.partition,
title: `${item.name}/${item.coreNum}${item.coreNum * item.memory}G/${ title: `${item.name}/${item.coreNum}${item.coreNum * item.memory}G/${
item.coreNum item.coreNum
}总核心数`, }总核心数`,
...@@ -88,6 +91,7 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -88,6 +91,7 @@ const QueueSelect = (props: IQueueSelectProps) => {
})), })),
...originalGpuList.map((item) => ({ ...originalGpuList.map((item) => ({
id: item.id, id: item.id,
partition: item.partition,
title: `${item.name}/${item.gpuNum}${item.coreNum}${item.memory}G/${item.gpuNum}总卡数`, title: `${item.name}/${item.gpuNum}${item.coreNum}${item.memory}G/${item.gpuNum}总卡数`,
total: item.total, total: item.total,
})), })),
...@@ -107,11 +111,13 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -107,11 +111,13 @@ const QueueSelect = (props: IQueueSelectProps) => {
cpuName: item.cpuName, cpuName: item.cpuName,
coreNum: item.coreNum, coreNum: item.coreNum,
id: item.id, id: item.id,
partition: item.partition,
memoryList: [ memoryList: [
{ {
memory: item.memory, memory: item.memory,
total: item.total, total: item.total,
id: item.id, id: item.id,
partition: item.partition,
}, },
], ],
}); });
...@@ -120,6 +126,7 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -120,6 +126,7 @@ const QueueSelect = (props: IQueueSelectProps) => {
memory: item.memory, memory: item.memory,
total: item.total, total: item.total,
id: item.id, id: item.id,
partition: item.partition,
}); });
} }
}); });
...@@ -191,17 +198,17 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -191,17 +198,17 @@ const QueueSelect = (props: IQueueSelectProps) => {
return item.memory + "GB"; return item.memory + "GB";
}; };
const setMemory = (id: string) => { const setMemory = (partition: string) => {
const copyShowCpuList: Array<IShowCPULi> = cloneDeep(showCpuList); const copyShowCpuList: Array<IShowCPULi> = cloneDeep(showCpuList);
const selectIndex = copyShowCpuList.findIndex((item) => { const selectIndex = copyShowCpuList.findIndex((item) => {
return item.id === activeId; return item.partition === activePartition;
}); });
if (selectIndex !== -1) { if (selectIndex !== -1) {
copyShowCpuList[selectIndex].id = id; copyShowCpuList[selectIndex].partition = partition;
} }
// 防止被 handleRow 中的 setActiveId覆盖 // 防止被 handleRow 中的 setActiveId覆盖
setTimeout(() => { setTimeout(() => {
setActiveId(id); setActivePartition(partition);
}, 10); }, 10);
setShowCpuList(copyShowCpuList); setShowCpuList(copyShowCpuList);
}; };
...@@ -209,18 +216,19 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -209,18 +216,19 @@ const QueueSelect = (props: IQueueSelectProps) => {
const renderMemory = (item: IShowCPULi) => { const renderMemory = (item: IShowCPULi) => {
return ( return (
<MyMenu <MyMenu
value={item.id} value={item.partition}
options={item.memoryList.map((memoryLi) => ({ options={item.memoryList.map((memoryLi) => ({
label: `${memoryLi.memory}GB/核`, label: `${memoryLi.memory}GB/核`,
value: memoryLi.id, value: memoryLi.partition,
}))} }))}
hasTriangle={true} hasTriangle={true}
setValue={setMemory} setValue={setMemory}
> >
<span className={style.cpuMemory}> <span className={style.cpuMemory}>
{ {
item.memoryList.filter((memoryLi) => memoryLi.id === item.id)[0] item.memoryList.filter(
.memory (memoryLi) => memoryLi.partition === item.partition
)[0].memory
} }
GB/核 GB/核
</span> </span>
...@@ -229,12 +237,12 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -229,12 +237,12 @@ const QueueSelect = (props: IQueueSelectProps) => {
}; };
const handleRow = (e: any) => { const handleRow = (e: any) => {
setActiveId(e.id); setActivePartition(e.partition);
}; };
const handleConfirm = () => { const handleConfirm = () => {
if (activeId) { if (activePartition) {
onChange && onChange(activeId); onChange && onChange(activePartition);
setOpen(false); setOpen(false);
} else { } else {
Message.error("请先选择一个硬件队列。"); Message.error("请先选择一个硬件队列。");
...@@ -244,7 +252,7 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -244,7 +252,7 @@ const QueueSelect = (props: IQueueSelectProps) => {
const getTotal = () => { const getTotal = () => {
let total = 0; let total = 0;
idInfoMap.forEach((item) => { idInfoMap.forEach((item) => {
if (item.id === activeId) { if (item.partition === activePartition) {
total = item.total; total = item.total;
} }
}); });
...@@ -254,7 +262,7 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -254,7 +262,7 @@ const QueueSelect = (props: IQueueSelectProps) => {
const getTitle = () => { const getTitle = () => {
let title = ""; let title = "";
idInfoMap.forEach((item) => { idInfoMap.forEach((item) => {
if (item.id === value) { if (item.partition === value) {
title = item.title; title = item.title;
} }
}); });
...@@ -281,7 +289,7 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -281,7 +289,7 @@ const QueueSelect = (props: IQueueSelectProps) => {
<div className={style.totalBox}> <div className={style.totalBox}>
费用(每小时): 费用(每小时):
<span className={style.total}> <span className={style.total}>
{activeId ? getTotal() : "-"} {activePartition ? getTotal() : "-"}
</span> </span>
</div> </div>
} }
...@@ -306,7 +314,8 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -306,7 +314,8 @@ const QueueSelect = (props: IQueueSelectProps) => {
headCells={cpuHeadCells} headCells={cpuHeadCells}
fixedHead={true} fixedHead={true}
handleRow={(e: any) => handleRow(e)} handleRow={(e: any) => handleRow(e)}
activeId={activeId} activeId={activePartition}
tableKey="partition"
></MyTable> ></MyTable>
)} )}
{queueType === "GPU" && ( {queueType === "GPU" && (
...@@ -321,7 +330,8 @@ const QueueSelect = (props: IQueueSelectProps) => { ...@@ -321,7 +330,8 @@ const QueueSelect = (props: IQueueSelectProps) => {
headCells={gpuHeadCells} headCells={gpuHeadCells}
fixedHead={true} fixedHead={true}
handleRow={(e: any) => handleRow(e)} handleRow={(e: any) => handleRow(e)}
activeId={activeId} activeId={activePartition}
tableKey="partition"
></MyTable> ></MyTable>
)} )}
</div> </div>
......
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