|
|
@@ -0,0 +1,167 @@
|
|
|
+import React, { PureComponent } from 'react';
|
|
|
+import styles from './pipelines.less';
|
|
|
+import { connect } from 'umi';
|
|
|
+import { Form, Input, Button, Modal, Table, Popconfirm } from 'antd';
|
|
|
+
|
|
|
+@connect(({ pipeline }) => ({
|
|
|
+ pipeline,
|
|
|
+}))
|
|
|
+export default class Pipelines extends PureComponent {
|
|
|
+ formRef = React.createRef();
|
|
|
+ state = {
|
|
|
+ showModal: false,
|
|
|
+ currentPipeline: null,
|
|
|
+ };
|
|
|
+ componentDidMount() {
|
|
|
+ this.props.dispatch({
|
|
|
+ type: 'pipeline/getAll',
|
|
|
+ });
|
|
|
+ }
|
|
|
+ showPipelineModal(currentPipeline) {
|
|
|
+ if (currentPipeline) {
|
|
|
+ this.formRef.current.setFieldsValue({
|
|
|
+ ...currentPipeline,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.formRef.current.resetFields();
|
|
|
+ }
|
|
|
+ this.setState({
|
|
|
+ showModal: true,
|
|
|
+ currentPipeline: currentPipeline ? currentPipeline : null,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ hidePipelineModal() {
|
|
|
+ this.setState({
|
|
|
+ showModal: false,
|
|
|
+ currentPipeline: null,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ onFinish(values) {
|
|
|
+ this.formRef.current.validateFields().then(values => {
|
|
|
+ this.props.dispatch({
|
|
|
+ type: this.state.currentPipeline?.id
|
|
|
+ ? 'pipeline/update'
|
|
|
+ : 'pipeline/create',
|
|
|
+ payload: {
|
|
|
+ ...values,
|
|
|
+ id: this.state.currentPipeline?.id,
|
|
|
+ callback: response => {
|
|
|
+ if (response && response.code == 0) {
|
|
|
+ this.setState({
|
|
|
+ showModal: false,
|
|
|
+ currentPipeline: null,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ deletePipeline(record) {
|
|
|
+ this.props.dispatch({
|
|
|
+ type: 'pipeline/deletePipeline',
|
|
|
+ payload: {
|
|
|
+ id: record.id,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ render() {
|
|
|
+ const columns = [
|
|
|
+ {
|
|
|
+ title: '名称',
|
|
|
+ dataIndex: 'name',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '描述',
|
|
|
+ dataIndex: ['description'],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '创建时间',
|
|
|
+ dataIndex: ['createdAt'],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '更新时间',
|
|
|
+ dataIndex: ['modifiedAt'],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ render: (text, record, index) => {
|
|
|
+ return (
|
|
|
+ <div key={`action-${record.name}`}>
|
|
|
+ <a
|
|
|
+ key={`action-update-${record.name}`}
|
|
|
+ style={{ marginRight: 5 }}
|
|
|
+ onClick={() => this.showPipelineModal(record)}
|
|
|
+ >
|
|
|
+ 更新
|
|
|
+ </a>
|
|
|
+ <Popconfirm
|
|
|
+ title="确认要删除吗?"
|
|
|
+ onConfirm={() => this.deletePipeline(record)}
|
|
|
+ okText="确定"
|
|
|
+ cancelText="取消"
|
|
|
+ >
|
|
|
+ <a
|
|
|
+ key={`action-delete-${record.name}`}
|
|
|
+ style={{ marginRight: 5 }}
|
|
|
+ >
|
|
|
+ 删除
|
|
|
+ </a>
|
|
|
+ </Popconfirm>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ return (
|
|
|
+ <div className={styles.loginContainer}>
|
|
|
+ <Button type="primary" onClick={() => this.showPipelineModal(null)}>
|
|
|
+ 创建Pipeline
|
|
|
+ </Button>
|
|
|
+ <Table
|
|
|
+ dataSource={this.props.pipeline.pipelines || []}
|
|
|
+ columns={columns}
|
|
|
+ ></Table>
|
|
|
+ <Modal
|
|
|
+ visible={this.state.showModal}
|
|
|
+ forceRender
|
|
|
+ onCancel={this.hidePipelineModal.bind(this)}
|
|
|
+ title={'新建/更新Pipeline'}
|
|
|
+ okText="确认"
|
|
|
+ cancelText="取消"
|
|
|
+ onOk={this.onFinish.bind(this)}
|
|
|
+ width="80%"
|
|
|
+ >
|
|
|
+ <Form
|
|
|
+ ref={this.formRef}
|
|
|
+ labelCol={{ span: 4 }}
|
|
|
+ wrapperCol={{ span: 20 }}
|
|
|
+ name="basic"
|
|
|
+ labelAlign="right"
|
|
|
+ onFinish={this.onFinish.bind(this)}
|
|
|
+ >
|
|
|
+ <Form.Item
|
|
|
+ ref={this.formRef}
|
|
|
+ label="名称"
|
|
|
+ name="name"
|
|
|
+ labelAlign="right"
|
|
|
+ rules={[{ required: true, message: '请输入名称' }]}
|
|
|
+ >
|
|
|
+ <Input />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item label="描述" name="description">
|
|
|
+ <Input />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item
|
|
|
+ label="脚本"
|
|
|
+ name="script"
|
|
|
+ rules={[{ required: true, message: '请输入脚本' }]}
|
|
|
+ >
|
|
|
+ <Input.TextArea />
|
|
|
+ </Form.Item>
|
|
|
+ </Form>
|
|
|
+ </Modal>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|