|
| 1 | +import React, { Component } from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import ImmutablePropTypes from 'react-immutable-proptypes'; |
| 4 | +import { FormattedMessage } from 'react-intl'; |
| 5 | +import { Row, Col } from 'react-bootstrap'; |
| 6 | +import { connect } from 'react-redux'; |
| 7 | + |
| 8 | +import Page from '../../components/layout/Page'; |
| 9 | +import { PipelineNavigation } from '../../components/layout/Navigation'; |
| 10 | +import Callout from '../../components/widgets/Callout'; |
| 11 | +import { PipelineStructureIcon } from '../../components/icons'; |
| 12 | +import PipelineFilesTableContainer from '../../containers/PipelineFilesTableContainer'; |
| 13 | +import PipelineEditContainer from '../../containers/PipelineEditContainer'; |
| 14 | + |
| 15 | +import { fetchPipelineIfNeeded } from '../../redux/modules/pipelines'; |
| 16 | +import { fetchBoxTypes } from '../../redux/modules/boxes'; |
| 17 | +import { fetchRuntimeEnvironments } from '../../redux/modules/runtimeEnvironments'; |
| 18 | +import { getPipeline } from '../../redux/selectors/pipelines'; |
| 19 | + |
| 20 | +import { hasPermissions } from '../../helpers/common'; |
| 21 | + |
| 22 | +class EditPipeline extends Component { |
| 23 | + componentDidMount = () => this.props.loadAsync(); |
| 24 | + |
| 25 | + componentDidUpdate(prevProps) { |
| 26 | + if (this.props.match.params.pipelineId !== prevProps.match.params.pipelineId) { |
| 27 | + this.props.loadAsync(); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + static loadAsync = ({ pipelineId }, dispatch) => |
| 32 | + Promise.all([ |
| 33 | + dispatch(fetchPipelineIfNeeded(pipelineId)), |
| 34 | + dispatch(fetchRuntimeEnvironments()), |
| 35 | + dispatch(fetchBoxTypes()), |
| 36 | + ]); |
| 37 | + |
| 38 | + render() { |
| 39 | + const { pipeline } = this.props; |
| 40 | + |
| 41 | + return ( |
| 42 | + <Page |
| 43 | + resource={pipeline} |
| 44 | + icon={<PipelineStructureIcon />} |
| 45 | + title={<FormattedMessage id="app.editPipelineStructure.title" defaultMessage="Modify Pipeline Structure" />}> |
| 46 | + {pipeline => ( |
| 47 | + <> |
| 48 | + <PipelineNavigation |
| 49 | + pipelineId={pipeline.id} |
| 50 | + canViewDetail={hasPermissions(pipeline, 'viewDetail')} |
| 51 | + canEdit={hasPermissions(pipeline, 'update')} |
| 52 | + /> |
| 53 | + |
| 54 | + <Row> |
| 55 | + <Col lg={12}> |
| 56 | + <Callout variant="warning"> |
| 57 | + <h4> |
| 58 | + <FormattedMessage id="app.editPipeline.disclaimer" defaultMessage="Disclaimer" /> |
| 59 | + </h4> |
| 60 | + <p> |
| 61 | + <FormattedMessage |
| 62 | + id="app.editPipeline.disclaimerWarning" |
| 63 | + defaultMessage="Modifying the pipeline might break all exercises using the pipeline!" |
| 64 | + /> |
| 65 | + </p> |
| 66 | + </Callout> |
| 67 | + </Col> |
| 68 | + </Row> |
| 69 | + |
| 70 | + <Row> |
| 71 | + <Col lg={12}> |
| 72 | + <PipelineEditContainer pipeline={pipeline} /> |
| 73 | + </Col> |
| 74 | + </Row> |
| 75 | + |
| 76 | + <Row> |
| 77 | + <Col xl={6}> |
| 78 | + <PipelineFilesTableContainer pipeline={pipeline} /> |
| 79 | + </Col> |
| 80 | + </Row> |
| 81 | + </> |
| 82 | + )} |
| 83 | + </Page> |
| 84 | + ); |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +EditPipeline.propTypes = { |
| 89 | + pipeline: ImmutablePropTypes.map, |
| 90 | + loadAsync: PropTypes.func.isRequired, |
| 91 | + match: PropTypes.shape({ |
| 92 | + params: PropTypes.shape({ |
| 93 | + pipelineId: PropTypes.string.isRequired, |
| 94 | + }).isRequired, |
| 95 | + }).isRequired, |
| 96 | +}; |
| 97 | + |
| 98 | +export default connect( |
| 99 | + ( |
| 100 | + state, |
| 101 | + { |
| 102 | + match: { |
| 103 | + params: { pipelineId }, |
| 104 | + }, |
| 105 | + } |
| 106 | + ) => { |
| 107 | + return { |
| 108 | + pipeline: getPipeline(pipelineId)(state), |
| 109 | + }; |
| 110 | + }, |
| 111 | + ( |
| 112 | + dispatch, |
| 113 | + { |
| 114 | + match: { |
| 115 | + params: { pipelineId }, |
| 116 | + }, |
| 117 | + } |
| 118 | + ) => ({ |
| 119 | + loadAsync: () => EditPipeline.loadAsync({ pipelineId }, dispatch), |
| 120 | + }) |
| 121 | +)(EditPipeline); |
0 commit comments