chore: adjust deployment modal form
This commit is contained in:
@@ -11,7 +11,6 @@ import {
|
||||
ClusterListItem as ListItem
|
||||
} from '../config/types';
|
||||
import CloudProvider from './cloud-provider-form';
|
||||
import K8SProvider from './k8s-provider-form';
|
||||
|
||||
type AddModalProps = {
|
||||
title: string;
|
||||
@@ -34,7 +33,7 @@ const AddCluster: React.FC<AddModalProps> = ({
|
||||
const [form] = Form.useForm();
|
||||
const intl = useIntl();
|
||||
|
||||
const handleSumit = () => {
|
||||
const handleSubmit = () => {
|
||||
form.submit();
|
||||
};
|
||||
|
||||
@@ -62,7 +61,7 @@ const AddCluster: React.FC<AddModalProps> = ({
|
||||
width={600}
|
||||
styles={{}}
|
||||
footer={
|
||||
<ModalFooter onOk={handleSumit} onCancel={onCancel}></ModalFooter>
|
||||
<ModalFooter onOk={handleSubmit} onCancel={onCancel}></ModalFooter>
|
||||
}
|
||||
>
|
||||
<Form form={form} onFinish={onOk} preserve={false}>
|
||||
@@ -85,8 +84,9 @@ const AddCluster: React.FC<AddModalProps> = ({
|
||||
required
|
||||
></SealInput.Input>
|
||||
</Form.Item>
|
||||
{provider === 'digitalocean' && <CloudProvider></CloudProvider>}
|
||||
{provider === 'kubernetes' && <K8SProvider></K8SProvider>}
|
||||
{provider === 'digitalocean' && (
|
||||
<CloudProvider provider={provider}></CloudProvider>
|
||||
)}
|
||||
<Form.Item<FormData> name="description" rules={[{ required: false }]}>
|
||||
<SealInput.TextArea
|
||||
label={intl.formatMessage({ id: 'common.table.description' })}
|
||||
|
||||
@@ -4,7 +4,7 @@ import SealInput from '@/components/seal-form/seal-input';
|
||||
import { PageAction, PasswordReg } from '@/config';
|
||||
import { PageActionType } from '@/config/types';
|
||||
import { useIntl } from '@umijs/max';
|
||||
import { Form } from 'antd';
|
||||
import { Button, Form } from 'antd';
|
||||
import React from 'react';
|
||||
import { FormData, ListItem } from '../config/types';
|
||||
|
||||
@@ -47,7 +47,11 @@ const AddModal: React.FC<AddModalProps> = ({
|
||||
width={600}
|
||||
styles={{}}
|
||||
footer={
|
||||
<ModalFooter onOk={handleSumit} onCancel={onCancel}></ModalFooter>
|
||||
<ModalFooter
|
||||
onOk={handleSumit}
|
||||
onCancel={onCancel}
|
||||
description={<Button>Validation Test</Button>}
|
||||
></ModalFooter>
|
||||
}
|
||||
>
|
||||
<Form form={form} onFinish={onOk} preserve={false}>
|
||||
@@ -70,29 +74,6 @@ const AddModal: React.FC<AddModalProps> = ({
|
||||
required
|
||||
></SealInput.Input>
|
||||
</Form.Item>
|
||||
{/* <Form.Item<FormData>
|
||||
name="provider"
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: intl.formatMessage(
|
||||
{ id: 'common.form.rule.input' },
|
||||
{
|
||||
name: 'Provider'
|
||||
}
|
||||
)
|
||||
}
|
||||
]}
|
||||
>
|
||||
<SealSelect
|
||||
label="Provider"
|
||||
required
|
||||
options={['Digital Ocean', 'Kubernetes', 'Custom'].map((item) => ({
|
||||
label: item,
|
||||
value: item
|
||||
}))}
|
||||
></SealSelect>
|
||||
</Form.Item> */}
|
||||
{provider === 'digital_ocean' && (
|
||||
<>
|
||||
<Form.Item<FormData>
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
import DropdownButtons from '@/components/drop-down-buttons';
|
||||
import GaugeChart from '@/components/echarts/gauge';
|
||||
import IconFont from '@/components/icon-font';
|
||||
import StatusTag from '@/components/status-tag';
|
||||
import Card from '@/components/templates/card';
|
||||
import {
|
||||
DeleteOutlined,
|
||||
EditOutlined,
|
||||
KubernetesOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { Card as ACard, Button, Col, Row, Tag } from 'antd';
|
||||
import React, { useMemo } from 'react';
|
||||
import styled from 'styled-components';
|
||||
import {
|
||||
ClusterStatus,
|
||||
ClusterStatusLabelMap,
|
||||
ProviderLabelMap,
|
||||
ProviderValueMap
|
||||
} from '../config';
|
||||
import { ClusterListItem as ListItem } from '../config/types';
|
||||
import WorkerPools from './worker-pools';
|
||||
|
||||
const CollapseTitle = styled.div`
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: var(--font-size-middle);
|
||||
font-weight: 500;
|
||||
color: var(--ant-color-text);
|
||||
height: 32px;
|
||||
cursor: pointer;
|
||||
`;
|
||||
|
||||
const Content = styled.div`
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
.chart-wrapper {
|
||||
flex: 1;
|
||||
}
|
||||
`;
|
||||
|
||||
const CardWrapper = styled(ACard)`
|
||||
text-align: center;
|
||||
box-shadow: none;
|
||||
.ant-card {
|
||||
box-shadow: none;
|
||||
}
|
||||
.ant-card-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-weight: 500;
|
||||
font-size: var(--font-size-middle);
|
||||
}
|
||||
.value {
|
||||
font-weight: 500;
|
||||
color: var(--ant-color-text);
|
||||
}
|
||||
`;
|
||||
|
||||
const actionItems = [
|
||||
{
|
||||
key: 'edit',
|
||||
label: 'common.button.edit',
|
||||
icon: <EditOutlined />
|
||||
},
|
||||
{
|
||||
key: 'add_worker',
|
||||
label: 'Add Worker',
|
||||
provider: ProviderValueMap.Custom,
|
||||
locale: false,
|
||||
icon: <IconFont type="icon-docker" />
|
||||
},
|
||||
{
|
||||
key: 'register_cluster',
|
||||
label: 'Register Cluster',
|
||||
provider: ProviderValueMap.Kubernetes,
|
||||
locale: false,
|
||||
icon: <KubernetesOutlined />
|
||||
},
|
||||
{
|
||||
key: 'addPool',
|
||||
label: 'Add Node Pool',
|
||||
provider: ProviderValueMap.DigitalOcean,
|
||||
locale: false,
|
||||
icon: <IconFont type="icon-catalog1" />
|
||||
},
|
||||
{
|
||||
key: 'delete',
|
||||
label: 'common.button.delete',
|
||||
icon: <DeleteOutlined />,
|
||||
props: {
|
||||
danger: true
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
const Inner = styled.div`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
cursor: default;
|
||||
|
||||
.title {
|
||||
margin-bottom: 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding-bottom: 8px;
|
||||
|
||||
.text {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: var(--font-size-middle);
|
||||
font-weight: 500;
|
||||
color: var(--ant-color-text);
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
flex: 1;
|
||||
}
|
||||
`;
|
||||
|
||||
interface CardProps {
|
||||
data: ListItem;
|
||||
onSelect?: (key: string, row: ListItem) => void;
|
||||
}
|
||||
|
||||
const CardItem: React.FC<CardProps> = (props) => {
|
||||
const { data, onSelect } = props;
|
||||
const [show, setShow] = React.useState(false);
|
||||
|
||||
const handleOnSelect = (key: string) => {
|
||||
console.log('Selected action:', key);
|
||||
onSelect?.(key, data);
|
||||
};
|
||||
|
||||
const actions = useMemo(() => {
|
||||
return actionItems.filter((item) => {
|
||||
if (item.provider) {
|
||||
return item.provider === data.provider;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}, [data.provider]);
|
||||
|
||||
return (
|
||||
<Card height={'auto'} clickable={false} ghost>
|
||||
<Inner>
|
||||
<div className="title">
|
||||
<span className="flex-center gap-8">
|
||||
<span className="text">{data.name}</span>
|
||||
<Tag style={{ borderRadius: 4 }}>
|
||||
{ProviderLabelMap[data.provider]}
|
||||
</Tag>
|
||||
<StatusTag
|
||||
statusValue={{
|
||||
status: ClusterStatus[data.status],
|
||||
text: ClusterStatusLabelMap[data.status]
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
<span>
|
||||
<DropdownButtons
|
||||
items={actions}
|
||||
onSelect={handleOnSelect}
|
||||
></DropdownButtons>
|
||||
</span>
|
||||
</div>
|
||||
<Content>
|
||||
<div className="flex gap-16">
|
||||
<CardWrapper bordered={false}>
|
||||
<div className="label">Workers</div>
|
||||
<div className="value">1</div>
|
||||
</CardWrapper>
|
||||
<CardWrapper bordered={false}>
|
||||
<div className="label">GPUs</div>
|
||||
<div className="value">12</div>
|
||||
</CardWrapper>
|
||||
<CardWrapper bordered={false}>
|
||||
<div className="label">Deployments</div>
|
||||
<div className="value">2</div>
|
||||
</CardWrapper>
|
||||
</div>
|
||||
<div className="chart-wrapper">
|
||||
<Row gutter={16} style={{ width: '100%' }}>
|
||||
<Col span={6}>
|
||||
<GaugeChart title="GPU Utilization" value={85} height={160} />
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<GaugeChart title="CPU Utilization" value={50} height={160} />
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<GaugeChart title="RAM Utilization" value={70} height={160} />
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<GaugeChart title="VRAM Utilization" value={60} height={160} />
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</Content>
|
||||
{data.provider === ProviderValueMap.DigitalOcean && (
|
||||
<>
|
||||
<CollapseTitle>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
icon={<IconFont type="icon-down" rotate={show ? 0 : -90} />}
|
||||
onClick={() => setShow(!show)}
|
||||
>
|
||||
Worker Pools
|
||||
</Button>
|
||||
</CollapseTitle>
|
||||
<WorkerPools
|
||||
provider={data.provider}
|
||||
dataSource={data.worker_pools}
|
||||
height={show ? 'auto' : 0}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Inner>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default CardItem;
|
||||
@@ -0,0 +1,104 @@
|
||||
import ModalFooter from '@/components/modal-footer';
|
||||
import ScrollerModal from '@/components/scroller-modal/index';
|
||||
import SealInput from '@/components/seal-form/seal-input';
|
||||
import { PageActionType } from '@/config/types';
|
||||
import { CloseOutlined } from '@ant-design/icons';
|
||||
import { useIntl } from '@umijs/max';
|
||||
import { Button, Form } from 'antd';
|
||||
import React from 'react';
|
||||
import {
|
||||
ClusterFormData as FormData,
|
||||
ClusterListItem as ListItem
|
||||
} from '../config/types';
|
||||
import CloudProvider from './cloud-provider-form';
|
||||
import K8SProvider from './k8s-provider-form';
|
||||
|
||||
type AddModalProps = {
|
||||
title: string;
|
||||
action: PageActionType;
|
||||
open: boolean;
|
||||
provider: string; // 'kubernetes' | 'custom' | 'digitalocean';
|
||||
onOk: (values: FormData) => void;
|
||||
data?: ListItem;
|
||||
onCancel: () => void;
|
||||
};
|
||||
const AddCluster: React.FC<AddModalProps> = ({
|
||||
title,
|
||||
action,
|
||||
open,
|
||||
provider,
|
||||
onOk,
|
||||
data,
|
||||
onCancel
|
||||
}) => {
|
||||
const [form] = Form.useForm();
|
||||
const intl = useIntl();
|
||||
|
||||
const handleSubmit = () => {
|
||||
form.submit();
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
form.resetFields();
|
||||
onCancel();
|
||||
};
|
||||
|
||||
return (
|
||||
<ScrollerModal
|
||||
title={
|
||||
<div className="flex-between flex-center">
|
||||
<span>{title}</span>
|
||||
<Button type="text" size="small" onClick={handleCancel}>
|
||||
<CloseOutlined></CloseOutlined>
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
open={open}
|
||||
onClose={onCancel}
|
||||
destroyOnClose={true}
|
||||
closeIcon={false}
|
||||
maskClosable={false}
|
||||
keyboard={false}
|
||||
width={600}
|
||||
styles={{}}
|
||||
footer={
|
||||
<ModalFooter onOk={handleSubmit} onCancel={onCancel}></ModalFooter>
|
||||
}
|
||||
>
|
||||
<Form form={form} onFinish={onOk} preserve={false}>
|
||||
<Form.Item<FormData>
|
||||
name="display_name"
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: intl.formatMessage(
|
||||
{ id: 'common.form.rule.input' },
|
||||
{
|
||||
name: intl.formatMessage({ id: 'common.table.name' })
|
||||
}
|
||||
)
|
||||
}
|
||||
]}
|
||||
>
|
||||
<SealInput.Input
|
||||
label={intl.formatMessage({ id: 'common.table.name' })}
|
||||
required
|
||||
></SealInput.Input>
|
||||
</Form.Item>
|
||||
{provider === 'digitalocean' && (
|
||||
<CloudProvider provider={provider}></CloudProvider>
|
||||
)}
|
||||
{provider === 'kubernetes' && (
|
||||
<K8SProvider provider={provider}></K8SProvider>
|
||||
)}
|
||||
<Form.Item<FormData> name="description" rules={[{ required: false }]}>
|
||||
<SealInput.TextArea
|
||||
label={intl.formatMessage({ id: 'common.table.description' })}
|
||||
></SealInput.TextArea>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</ScrollerModal>
|
||||
);
|
||||
};
|
||||
|
||||
export default AddCluster;
|
||||
@@ -0,0 +1,117 @@
|
||||
import DropdownButtons from '@/components/drop-down-buttons';
|
||||
import { DeleteOutlined, EditOutlined } from '@ant-design/icons';
|
||||
import { Table } from 'antd';
|
||||
|
||||
const actionItems = [
|
||||
{
|
||||
key: 'edit',
|
||||
label: 'common.button.edit',
|
||||
icon: <EditOutlined />
|
||||
},
|
||||
|
||||
{
|
||||
key: 'delete',
|
||||
label: 'common.button.delete',
|
||||
icon: <DeleteOutlined />,
|
||||
props: {
|
||||
danger: true
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
interface WorkerPoolsProps {
|
||||
dataSource: any[];
|
||||
loading?: boolean;
|
||||
provider: string;
|
||||
height?: string | number;
|
||||
onAction?: (action: string, record: any) => void;
|
||||
}
|
||||
|
||||
const WorkerPools: React.FC<WorkerPoolsProps> = ({
|
||||
dataSource,
|
||||
loading = false,
|
||||
provider,
|
||||
height = 'auto',
|
||||
onAction
|
||||
}) => {
|
||||
// dataindex: type, replicas, Batchsize, GPU, Memory, CPU, Storage, CreateTime, Operations
|
||||
const columns = [
|
||||
{
|
||||
title: 'Type',
|
||||
dataIndex: 'type',
|
||||
key: 'type'
|
||||
},
|
||||
{
|
||||
title: 'Replicas',
|
||||
dataIndex: 'replicas',
|
||||
key: 'replicas'
|
||||
},
|
||||
{
|
||||
title: 'Batch Size',
|
||||
dataIndex: 'batchSize',
|
||||
key: 'batchSize'
|
||||
},
|
||||
{
|
||||
title: 'GPU',
|
||||
dataIndex: 'gpu',
|
||||
key: 'gpu'
|
||||
},
|
||||
{
|
||||
title: 'Memory',
|
||||
dataIndex: 'memory',
|
||||
key: 'memory'
|
||||
},
|
||||
{
|
||||
title: 'CPU',
|
||||
dataIndex: 'cpu',
|
||||
key: 'cpu'
|
||||
},
|
||||
{
|
||||
title: 'Storage',
|
||||
dataIndex: 'storage',
|
||||
key: 'storage'
|
||||
},
|
||||
{
|
||||
title: 'Create Time',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime'
|
||||
},
|
||||
{
|
||||
title: 'Operations',
|
||||
key: 'operations',
|
||||
render: (_, record) => (
|
||||
<DropdownButtons
|
||||
items={actionItems}
|
||||
onSelect={(key) => onAction?.(key, record)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
];
|
||||
|
||||
// mock dataSource
|
||||
const mockData = Array.from({ length: 3 }, (_, index) => ({
|
||||
key: index,
|
||||
type: `Type ${index + 1}`,
|
||||
replicas: Math.floor(Math.random() * 10) + 1,
|
||||
batchSize: Math.floor(Math.random() * 100) + 1,
|
||||
gpu: `NVIDIA 4090`,
|
||||
memory: `${Math.floor(Math.random() * 16) + 1} GB`,
|
||||
cpu: `${Math.floor(Math.random() * 8) + 1} Cores`,
|
||||
storage: `${Math.floor(Math.random() * 500) + 50} GB`,
|
||||
createTime: new Date().toLocaleDateString()
|
||||
}));
|
||||
|
||||
return (
|
||||
<div style={{ height: height, overflow: 'hidden' }}>
|
||||
<Table
|
||||
dataSource={dataSource || mockData}
|
||||
columns={columns}
|
||||
loading={loading}
|
||||
pagination={false}
|
||||
rowKey="id"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default WorkerPools;
|
||||
Reference in New Issue
Block a user