Commit fb4b38d9 authored by chenshouchao's avatar chenshouchao

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

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