diff --git a/src/pages/devops/components/Pipeline/StepModals/application.jsx b/src/pages/devops/components/Pipeline/StepModals/application.jsx new file mode 100644 index 00000000000..8f5c509afec --- /dev/null +++ b/src/pages/devops/components/Pipeline/StepModals/application.jsx @@ -0,0 +1,70 @@ +/* + * This file is part of KubeSphere Console. + * Copyright (C) 2022 The KubeSphere Console Authors. + * + * KubeSphere Console is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KubeSphere Console is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with KubeSphere Console. If not, see . + */ + +import React, { Component } from 'react' +import { pick } from 'lodash' +import { observer } from 'mobx-react' +import { Select, Form } from '@kube-design/components' + +@observer +export default class CDSelect extends Component { + componentDidMount() { + this.getCDListData() + } + + getCDListData = params => { + return this.props.store.getCDListData(params) + } + + getCDList = () => { + return [ + ...this.props.store.cdList.data.map(item => ({ + label: item.name, + value: item.name, + })), + ] + } + + render() { + const { option } = this.props + const { cdList } = this.props.store + const formProps = { + key: option.name, + label: t(option.display), + rules: [ + { + required: option.required ?? false, + message: t('PARAM_REQUIRED'), + }, + ], + } + return ( + + - - - - ) - } -} diff --git a/src/pages/devops/components/Pipeline/StepModals/cd.jsx b/src/pages/devops/components/Pipeline/StepModals/cd.jsx deleted file mode 100644 index 10ab1f7c1d7..00000000000 --- a/src/pages/devops/components/Pipeline/StepModals/cd.jsx +++ /dev/null @@ -1,240 +0,0 @@ -/* - * This file is part of KubeSphere Console. - * Copyright (C) 2022 The KubeSphere Console Authors. - * - * KubeSphere Console is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * KubeSphere Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with KubeSphere Console. If not, see . - */ - -import React from 'react' -import PropTypes from 'prop-types' - -import { observer } from 'mobx-react' -import { Modal } from 'components/Base' -import { Form, Input, Select, Tag } from '@kube-design/components' - -import { Column, Columns } from '@kube-design/components/lib/components/Layout' -import { pick } from 'lodash' -import styles from './index.scss' - -const formTemplate = ({ - credentialsId, - appName, - devops, - name, - newName, - branch, - tag, -}) => ({ - arguments: { - isLiteral: true, - value: 'base', - }, - children: [ - { - arguments: { - isLiteral: false, - value: `\${[usernamePassword(credentialsId : '${credentialsId}' ,passwordVariable : 'PASS' ,usernameVariable : 'USER')]}`, - }, - children: [ - { - arguments: [ - { - key: 'script', - value: { - isLiteral: true, - value: `ks app update --app-name ${appName} \\\n --app-namespace ${devops} \\\n --name ${name} \\\n --newName ${newName}${ - tag ? `:${tag}` : '' - } \\\n --git-password $PASS --git-username=$USER \\\n --git-target-branch ${branch}`, - }, - }, - ], - name: 'sh', - }, - ], - name: 'withCredentials', - }, - ], - name: 'container', -}) - -@observer -export default class CD extends React.Component { - static propTypes = { - name: PropTypes.string, - } - - static defaultProps = { - visible: false, - onOk() {}, - onCancel() {}, - } - - constructor(props) { - super(props) - this.formRef = React.createRef() - this.state = { formData: {} } - } - - componentDidMount() { - this.getCDListData() - } - - getCredentialsListData = params => { - return this.props.store.getCredentials(params) - } - - getCredentialsList = () => { - return [ - ...this.props.store.credentialsList.data.map(credential => ({ - label: credential.name, - value: credential.name, - type: credential.type, - disabled: credential.type !== 'username_password', - })), - ] - } - - getCDListData = params => { - return this.props.store.getCDListData(params) - } - - getCDList = () => { - return [ - ...this.props.store.cdList.data.map(item => ({ - label: item.name, - value: item.name, - })), - ] - } - - handleOk = () => { - const formData = this.formRef.current.getData() - - this.formRef.current.validate(() => { - const _arguments = formTemplate({ - ...formData, - devops: this.props.store.params.devops, - }) - - this.props.onAddStep(_arguments) - }) - } - - optionRender = ({ label, type, disabled }) => ( - - {label}   - - {type === 'ssh' ? 'SSH' : t(type)} - - - ) - - render() { - const { visible, onCancel } = this.props - const { credentialsList, cdList } = this.props.store - - return ( - -
-
- - - - - - - -
- - - -
- - - - - - - - - - - - -
- - {t('SELECT_CREDENTIAL_DESC')} - - {t('CREATE_CREDENTIAL')} - -

- } - rules={[{ required: true, message: t('PARAM_REQUIRED') }]} - > - -
- - - -
-
- ) - } -} diff --git a/src/pages/devops/components/Pipeline/StepModals/cleanWs.jsx b/src/pages/devops/components/Pipeline/StepModals/cleanWs.jsx deleted file mode 100644 index afb53ac99f3..00000000000 --- a/src/pages/devops/components/Pipeline/StepModals/cleanWs.jsx +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of KubeSphere Console. - * Copyright (C) 2019 The KubeSphere Console Authors. - * - * KubeSphere Console is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * KubeSphere Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with KubeSphere Console. If not, see . - */ - -import React from 'react' -import PropTypes from 'prop-types' - -import { observable } from 'mobx' -import { observer } from 'mobx-react' -import { Checkbox, Form } from '@kube-design/components' -import { Modal } from 'components/Base' - -import styles from './index.scss' - -@observer -export default class Echo extends React.Component { - static propTypes = { - name: PropTypes.string, - } - - static defaultProps = { - visible: false, - onOk() {}, - onCancel() {}, - } - - constructor(props) { - super(props) - this.formRef = React.createRef() - } - - @observable - formData = {} - - handleOk = () => { - const formData = this.formRef.current.getData() - const _arguments = Object.keys(formData).map(key => ({ - key, - value: { - isLiteral: true, - value: Array.isArray(formData[key]) ? formData[key][0] : formData[key], - }, - })) - this.props.onAddStep({ - name: 'cleanWs', - arguments: _arguments, - }) - } - - render() { - const { visible, onCancel } = this.props - - return ( - -
- - - {t('Clean when aborted')} - - - - - {t('Not fail build')} - - -
-
- ) - } -} diff --git a/src/pages/devops/components/Pipeline/StepModals/container.jsx b/src/pages/devops/components/Pipeline/StepModals/container.jsx deleted file mode 100644 index 4bad6c375fb..00000000000 --- a/src/pages/devops/components/Pipeline/StepModals/container.jsx +++ /dev/null @@ -1,95 +0,0 @@ -/* - * This file is part of KubeSphere Console. - * Copyright (C) 2019 The KubeSphere Console Authors. - * - * KubeSphere Console is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * KubeSphere Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with KubeSphere Console. If not, see . - */ - -import React from 'react' -import PropTypes from 'prop-types' -import { get } from 'lodash' - -import { observer } from 'mobx-react' -import { Modal } from 'components/Base' -import { Form, Input } from '@kube-design/components' - -import styles from './index.scss' - -@observer -export default class Container extends React.Component { - static propTypes = { - name: PropTypes.string, - } - - static defaultProps = { - visible: false, - onOk() {}, - onCancel() {}, - } - - constructor(props) { - super(props) - this.formRef = React.createRef() - this.state = { formData: {} } - } - - static getDerivedStateFromProps(props) { - if (props.edittingData.type === 'container') { - const formData = { - name: get(props.edittingData, 'data.value', ''), - } - return { formData } - } - return null - } - - handleOk = () => { - const formData = this.formRef.current.getData() - this.formRef.current.validate(() => { - this.props.onAddStep({ - name: 'container', - arguments: { - isLiteral: true, - value: formData.name, - }, - children: [], - }) - }) - } - - render() { - const { visible, onCancel } = this.props - - return ( - -
- - - -
-
- ) - } -} diff --git a/src/pages/devops/components/Pipeline/StepModals/credential.jsx b/src/pages/devops/components/Pipeline/StepModals/credential.jsx new file mode 100644 index 00000000000..db2736077b6 --- /dev/null +++ b/src/pages/devops/components/Pipeline/StepModals/credential.jsx @@ -0,0 +1,102 @@ +/* + * This file is part of KubeSphere Console. + * Copyright (C) 2022 The KubeSphere Console Authors. + * + * KubeSphere Console is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * KubeSphere Console is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with KubeSphere Console. If not, see . + */ + +import React, { Component } from 'react' +import { pick, get } from 'lodash' +import { Select, Tag, Form } from '@kube-design/components' +import { observer } from 'mobx-react' + +import styles from '../index.scss' + +@observer +export default class SecretSelect extends Component { + async componentDidMount() { + const { formData, onChange, option } = this.props + await this.getCredentialsListData() + if (!get(formData, `${option.name}.name`)) { + onChange(formData[option.name]) + } + } + + getCredentialsListData = params => { + return this.props.store.getCredentials(params) + } + + getCredentialsList = option => { + return [ + ...this.props.store.credentialsList.data.map(credential => ({ + label: credential.name, + value: credential.name, + type: credential.type, + disabled: option.secretType + ? credential.type !== option.secretType + : false, + })), + ] + } + + optionRender = ({ label, type, disabled }) => ( + + {label}   + + {type === 'ssh' ? 'SSH' : t(type)} + + + ) + + renderCredentialDesc() { + return ( +

+ {t('SELECT_CREDENTIAL_DESC')} + + {t('CREATE_CREDENTIAL')} + +

+ ) + } + + render() { + const { option, onChange } = this.props + const { credentialsList } = this.props.store + const formProps = { + key: option.name, + label: t(option.display), + rules: [ + { + required: option.required ?? false, + message: t('PARAM_REQUIRED'), + }, + ], + desc: this.renderCredentialDesc(), + } + return ( + + - - - - ) - } -} diff --git a/src/pages/devops/components/Pipeline/StepModals/echo.jsx b/src/pages/devops/components/Pipeline/StepModals/echo.jsx deleted file mode 100644 index fbe84d3f586..00000000000 --- a/src/pages/devops/components/Pipeline/StepModals/echo.jsx +++ /dev/null @@ -1,96 +0,0 @@ -/* - * This file is part of KubeSphere Console. - * Copyright (C) 2019 The KubeSphere Console Authors. - * - * KubeSphere Console is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * KubeSphere Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with KubeSphere Console. If not, see . - */ - -import React from 'react' -import PropTypes from 'prop-types' -import { Form, TextArea } from '@kube-design/components' -import { Modal } from 'components/Base' -import styles from './index.scss' - -export default class Echo extends React.Component { - static propTypes = { - name: PropTypes.string, - } - - static defaultProps = { - visible: false, - onOk() {}, - onCancel() {}, - } - - constructor(props) { - super(props) - this.formRef = React.createRef() - this.state = { formData: {} } - } - - static getDerivedStateFromProps(nextProps) { - if (nextProps.edittingData.type === 'echo') { - const formData = nextProps.edittingData.data.reduce((prev, arg) => { - prev[arg.key] = arg.value.value - return prev - }, {}) - return { formData } - } - return null - } - - handleOk = () => { - const formData = this.formRef.current.getData() - this.formRef.current.validate(() => { - const _arguments = Object.keys(formData).map(key => ({ - key, - value: { - isLiteral: true, - value: formData[key].trim(), - }, - })) - this.props.onAddStep({ - name: 'echo', - arguments: _arguments.filter(arg => arg.value.value !== ''), - }) - }) - } - - render() { - const { visible, onCancel } = this.props - - return ( - -
- -