import React, { PureComponent } from 'react'; import { PageHeader, Button, Descriptions, Modal, Card, Icon, Row, Col, Form, Popconfirm, Input, Space, Divider } from 'antd'; import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; import styles from './ConfigModal.less' export default class ConfigModal extends PureComponent { formRef = React.createRef(); state = { } setFormValues(config) { if (config) { this.formRef.current.setFieldsValue({ ...(config.config || {}), envsArr: Object.keys(config.config.envs || {}).map(key => ({ key, value: config.config.envs[key] })), mountsArr: Object.keys(config.config.mounts || {}).map(key => ({ key, value: config.config.mounts[key] })), ingressAnnotaionsArr: Object.keys(config.config.ingressAnnotaions || {}).map(key => ({ key, value: config.config.ingressAnnotaions[key] })), hostPathArr: Object.keys(config.config.hostPath || {}).map(key => ({ key, value: config.config.hostPath[key] })), }); } } componentDidMount() { this.setFormValues(this.props.config); } componentWillReceiveProps(props) { if (props.config != this.props.config) this.setFormValues(props.config); } onOk() { this.formRef.current.validateFields().then(values => { this.props.onOk({ ...this.props.config, config: { ...values, envs: (values.envsArr || []).reduce((obj, item) => { obj[item.key] = item.value; return obj; }, {}), mounts: (values.mountsArr || []).reduce((obj, item) => { obj[item.key] = item.value; return obj; }, {}), hostPath: (values.hostPathArr || []).reduce((obj, item) => { obj[item.key] = item.value; return obj; }, {}), ingressAnnotaions: (values.ingressAnnotaionsArr || []).reduce((obj, item) => { obj[item.key] = item.value; return obj; }, {}), } }) }); } render() { return ( this.props.onCancel()} title={"更新配置"} okText="确认" cancelText="取消" onOk={this.onOk.bind(this)} className={styles.modal} width="80%" >
环境变量配置
{(fields, {add, remove}) => ( <> {fields.map(field => (
remove(field.name)} />
))} )}
挂载文件配置
{(fields, {add, remove}) => ( <> {fields.map(field => (
remove(field.name)} />
))} )}
节点文件挂载
{(fields, {add, remove}) => ( <> {fields.map(field => (
remove(field.name)} />
))} )}
ingress控制器annotations
{(fields, {add, remove}) => ( <> {fields.map(field => (
remove(field.name)} />
))} )}
) } }