-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Providing standard navigation for pipeline pages.
- Loading branch information
1 parent
23bd230
commit ce36e76
Showing
10 changed files
with
181 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import Navigation from './Navigation'; | ||
import withLinks from '../../../helpers/withLinks'; | ||
import { PipelineIcon, EditIcon } from '../../icons'; | ||
|
||
const PipelineNavigation = ({ | ||
pipelineId, | ||
canViewDetail = false, | ||
canEdit = false, | ||
links: { PIPELINE_URI_FACTORY, PIPELINE_EDIT_URI_FACTORY }, | ||
}) => ( | ||
<Navigation | ||
pipelineId={pipelineId} | ||
links={[ | ||
canViewDetail && { | ||
caption: <FormattedMessage id="app.navigation.pipeline" defaultMessage="Pipeline" />, | ||
link: PIPELINE_URI_FACTORY(pipelineId), | ||
icon: <PipelineIcon gapRight />, | ||
}, | ||
canEdit && { | ||
caption: <FormattedMessage id="app.navigation.edit" defaultMessage="Edit" />, | ||
link: PIPELINE_EDIT_URI_FACTORY(pipelineId), | ||
icon: <EditIcon gapRight />, | ||
}, | ||
]} | ||
/> | ||
); | ||
|
||
PipelineNavigation.propTypes = { | ||
pipelineId: PropTypes.string.isRequired, | ||
canViewDetail: PropTypes.bool, | ||
canEdit: PropTypes.bool, | ||
isLoggedInUser: PropTypes.bool, | ||
links: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default withLinks(PipelineNavigation); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/containers/PipelineNameContainer/PipelineNameContainer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import ImmutablePropTypes from 'react-immutable-proptypes'; | ||
import { connect } from 'react-redux'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { fetchPipelineIfNeeded } from '../../redux/modules/pipelines'; | ||
import { getPipeline } from '../../redux/selectors/pipelines'; | ||
import ResourceRenderer from '../../components/helpers/ResourceRenderer'; | ||
import { LoadingIcon } from '../../components/icons'; | ||
import withLinks from '../../helpers/withLinks'; | ||
|
||
class PipelineNameContainer extends Component { | ||
componentDidMount = () => this.props.loadPipelineIfNeeded(); | ||
|
||
componentDidUpdate(prevProps) { | ||
if (this.props.pipelineId !== prevProps.pipelineId) { | ||
this.props.loadPipelineIfNeeded(); | ||
} | ||
} | ||
|
||
render() { | ||
const { | ||
pipelineId, | ||
pipeline, | ||
noLink = false, | ||
links: { PIPELINE_URI_FACTORY }, | ||
} = this.props; | ||
return ( | ||
<ResourceRenderer | ||
resource={pipeline} | ||
loading={ | ||
<> | ||
<LoadingIcon gapRight /> | ||
<FormattedMessage id="generic.loading" defaultMessage="Loading..." /> | ||
</> | ||
}> | ||
{pipeline => | ||
noLink ? <>{pipeline.name}</> : <Link to={PIPELINE_URI_FACTORY(pipelineId)}>{pipeline.name}</Link> | ||
} | ||
</ResourceRenderer> | ||
); | ||
} | ||
} | ||
|
||
PipelineNameContainer.propTypes = { | ||
pipelineId: PropTypes.string.isRequired, | ||
pipeline: ImmutablePropTypes.map, | ||
noLink: PropTypes.bool, | ||
loadPipelineIfNeeded: PropTypes.func.isRequired, | ||
links: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default withLinks( | ||
connect( | ||
(state, { pipelineId }) => ({ | ||
pipeline: getPipeline(pipelineId)(state), | ||
}), | ||
(dispatch, { pipelineId }) => ({ | ||
loadPipelineIfNeeded: () => dispatch(fetchPipelineIfNeeded(pipelineId)), | ||
}) | ||
)(PipelineNameContainer) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import PipelineNameContainer from './PipelineNameContainer'; | ||
export default PipelineNameContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.