1- import {
2- useDeleteReleasePipelineMutation ,
3- usePublishReleasePipelineMutation ,
4- } from 'common/services/useReleasePipelines'
1+ import { useDeleteReleasePipelineMutation } from 'common/services/useReleasePipelines'
52import { PagedResponse , ReleasePipeline } from 'common/types/responses'
63import { useHistory } from 'react-router-dom'
74import Button from 'components/base/forms/Button'
@@ -10,8 +7,9 @@ import DropdownMenu from 'components/base/DropdownMenu'
107import PanelSearch from 'components/PanelSearch'
118import Tag from 'components/tags/Tag'
129import { useEffect } from 'react'
10+ import ChangeReleasePipelineStatusModal from './ChangeReleasePipelineStatusModal'
1311
14- const NoReleasePipelines = ( { projectId } : { projectId : string } ) => {
12+ const NoReleasePipelines = ( { projectId } : { projectId : number } ) => {
1513 const history = useHistory ( )
1614
1715 return (
@@ -50,7 +48,7 @@ const NoReleasePipelines = ({ projectId }: { projectId: string }) => {
5048type ReleasePipelinesListProps = {
5149 data : PagedResponse < ReleasePipeline > | undefined
5250 isLoading : boolean
53- projectId : string
51+ projectId : number
5452 page : number
5553 pageSize : number
5654 onPageChange : ( page : number ) => void
@@ -74,30 +72,8 @@ const ReleasePipelinesList = ({
7472 isSuccess : isDeletingSuccess ,
7573 } ,
7674 ] = useDeleteReleasePipelineMutation ( )
77- const [
78- publishReleasePipeline ,
79- {
80- error : publishReleasePipelineError ,
81- isError : isPublishingError ,
82- isLoading : isPublishing ,
83- isSuccess : isPublishingSuccess ,
84- } ,
85- ] = usePublishReleasePipelineMutation ( )
86- const pipelinesList = data ?. results
87-
88- useEffect ( ( ) => {
89- if ( isPublishingSuccess ) {
90- return toast ( 'Release pipeline published successfully' )
91- }
9275
93- if ( isPublishingError ) {
94- return toast (
95- publishReleasePipelineError ?. data ?. detail ??
96- 'Something went wrong while publishing the release pipeline' ,
97- 'danger' ,
98- )
99- }
100- } , [ isPublishingSuccess , isPublishingError , publishReleasePipelineError ] )
76+ const pipelinesList = data ?. results
10177
10278 useEffect ( ( ) => {
10379 if ( isDeletingSuccess ) {
@@ -113,6 +89,21 @@ const ReleasePipelinesList = ({
11389 }
11490 } , [ isDeletingSuccess , isDeletingError , deleteReleasePipelineError ] )
11591
92+ const openChangeReleasePipelineStatusModal = (
93+ projectId : number ,
94+ pipelineId : number ,
95+ isPublished : boolean ,
96+ ) => {
97+ openModal2 (
98+ isPublished ? 'Unpublish Release Pipeline' : 'Publish Release Pipeline' ,
99+ < ChangeReleasePipelineStatusModal
100+ isPublished = { isPublished }
101+ pipelineId = { pipelineId }
102+ projectId = { projectId }
103+ /> ,
104+ )
105+ }
106+
116107 if ( isLoading ) {
117108 return (
118109 < div className = 'text-center' >
@@ -150,6 +141,14 @@ const ReleasePipelinesList = ({
150141 stages_count,
151142 } : ReleasePipeline ) => {
152143 const isPublished = ! ! published_at
144+ const canUnpublish = isPublished && ! features ?. length
145+
146+ const getTooltip = ( action : string ) => {
147+ if ( isPublished ) {
148+ return `Cannot ${ action } a published release pipeline`
149+ }
150+ return undefined
151+ }
153152
154153 return (
155154 < Row key = { id } className = 'list-item' >
@@ -182,43 +181,44 @@ const ReleasePipelinesList = ({
182181 < DropdownMenu
183182 items = { [
184183 {
185- disabled : isPublishing || ! ! published_at ,
184+ disabled : isPublished ,
186185 icon : 'edit' as IconName ,
187- label : 'Edit Release Pipeline ' ,
186+ label : 'Edit' ,
188187 onClick : ( ) => {
189188 history . push (
190189 `/project/${ projectId } /release-pipelines/${ id } /edit` ,
191190 )
192191 } ,
193- tooltip : published_at
194- ? 'Cannot edit a published release pipeline'
195- : undefined ,
192+ tooltip : getTooltip ( 'edit' ) ,
193+ } ,
194+ {
195+ disabled : isPublished && ! canUnpublish ,
196+ icon : isPublished
197+ ? 'minus-circle'
198+ : ( 'checkmark-circle' as IconName ) ,
199+ label : isPublished ? 'Unpublish' : 'Publish' ,
200+ onClick : ( ) =>
201+ openChangeReleasePipelineStatusModal (
202+ projectId ,
203+ id ,
204+ isPublished ,
205+ ) ,
206+ tooltip :
207+ isPublished && ! canUnpublish
208+ ? 'Cannot unpublish a release pipeline with in-flight features'
209+ : undefined ,
196210 } ,
197- ...( ! isPublished
198- ? [
199- {
200- disabled : isPublishing ,
201- icon : 'checkmark-circle' as IconName ,
202- label : 'Publish Release Pipeline' ,
203- onClick : ( ) => {
204- publishReleasePipeline ( {
205- pipelineId : id ,
206- projectId : Number ( projectId ) ,
207- } )
208- } ,
209- } ,
210- ]
211- : [ ] ) ,
212211 {
213- disabled : isDeleting ,
212+ disabled : isDeleting || isPublished ,
214213 icon : 'trash-2' ,
215- label : 'Remove Release Pipeline ' ,
214+ label : 'Remove' ,
216215 onClick : ( ) => {
217216 deleteReleasePipeline ( {
218217 pipelineId : id ,
219218 projectId : Number ( projectId ) ,
220219 } )
221220 } ,
221+ tooltip : getTooltip ( 'remove' ) ,
222222 } ,
223223 ] }
224224 />
0 commit comments