Skip to content

Commit a3a067b

Browse files
committed
add bulk delete phases functionality
1 parent 0682daf commit a3a067b

File tree

8 files changed

+79
-8
lines changed

8 files changed

+79
-8
lines changed

src/api/projects.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,8 @@ export function deleteProjectPhase(projectId, phaseId) {
223223
return axios.delete(`${PROJECTS_API_URL}/v5/projects/${projectId}/phases/${phaseId}`)
224224
.then(() => ({ projectId, phaseId }))
225225
}
226+
227+
export function deleteBulkProjectPhase(projectId, phaseIds) {
228+
return axios.delete(`${PROJECTS_API_URL}/v5/projects/${projectId}/phases`, { data: { phaseIds } })
229+
.then(() => ({ phaseIds }))
230+
}

src/config/constants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ export const DELETE_PROJECT_PHASE_PENDING = 'DELETE_PROJECT_PHASE_PENDING'
300300
export const DELETE_PROJECT_PHASE_FAILURE = 'DELETE_PROJECT_PHASE_FAILURE'
301301
export const DELETE_PROJECT_PHASE_SUCCESS = 'DELETE_PROJECT_PHASE_SUCCESS'
302302

303+
export const DELETE_BULK_PROJECT_PHASE = 'DELETE_BULK_PROJECT_PHASE'
304+
export const DELETE_BULK_PROJECT_PHASE_PENDING = 'DELETE_BULK_PROJECT_PHASE_PENDING'
305+
export const DELETE_BULK_PROJECT_PHASE_FAILURE = 'DELETE_BULK_PROJECT_PHASE_FAILURE'
306+
export const DELETE_BULK_PROJECT_PHASE_SUCCESS = 'DELETE_BULK_PROJECT_PHASE_SUCCESS'
307+
303308
export const UPDATE_PRODUCT = 'UPDATE_PRODUCT'
304309
export const UPDATE_PRODUCT_PENDING = 'UPDATE_PRODUCT_PENDING'
305310
export const UPDATE_PRODUCT_SUCCESS = 'UPDATE_PRODUCT_SUCCESS'

src/projects/actions/project.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getProjectById,
77
updateProject as updateProjectAPI,
88
deleteProject as deleteProjectAPI,
99
deleteProjectPhase as deleteProjectPhaseAPI,
10+
deleteBulkProjectPhase as deleteBulkProjectPhaseAPI,
1011
getProjectPhases,
1112
updateProduct as updateProductAPI,
1213
updatePhase as updatePhaseAPI,
@@ -79,7 +80,8 @@ import {
7980
CUSTOMER_APPROVE_MILESTONE_APPROVE_SUCCESS,
8081
CUSTOMER_APPROVE_MILESTONE_REJECT_FAILURE,
8182
CUSTOMER_APPROVE_MILESTONE_APPROVE_FAILURE,
82-
CUSTOMER_APPROVE_MILESTONE_REJECT_SUCCESS
83+
CUSTOMER_APPROVE_MILESTONE_REJECT_SUCCESS,
84+
DELETE_BULK_PROJECT_PHASE
8385
} from '../../config/constants'
8486
import {
8587
updateProductMilestone,
@@ -441,6 +443,15 @@ export function deleteProjectPhase(projectId, phaseId) {
441443
}
442444
}
443445

446+
export function deleteBulkProjectPhase(projectId, phaseIds) {
447+
return (dispatch) => {
448+
return dispatch({
449+
type: DELETE_BULK_PROJECT_PHASE,
450+
payload: deleteBulkProjectPhaseAPI(projectId, phaseIds)
451+
})
452+
}
453+
}
454+
444455
export function updateProject(projectId, updatedProps, updateExisting = false) {
445456
return (dispatch) => {
446457
return dispatch({

src/projects/detail/components/SimplePlan/CreateSimplePlan/CreateSimplePlan.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class CreateSimplePlan extends React.Component {
3939
onChangeMilestones,
4040
onSaveMilestone,
4141
onRemoveMilestone,
42+
onRemoveAllMilestones,
4243
onGetChallenges,
4344
onApproveMilestones,
4445
isProjectLive,
@@ -78,6 +79,7 @@ class CreateSimplePlan extends React.Component {
7879
onChangeMilestones={onChangeMilestones}
7980
onSaveMilestone={onSaveMilestone}
8081
onRemoveMilestone={onRemoveMilestone}
82+
onRemoveAllMilestones={onRemoveAllMilestones}
8183
onApproveMilestones={onApproveMilestones}
8284
projectMembers={project.members}
8385
project={project}
@@ -97,6 +99,7 @@ CreateSimplePlan.propTypes = {
9799
onChangeMilestones: PT.func,
98100
onSaveMilestone: PT.func,
99101
onRemoveMilestone: PT.func,
102+
onRemoveAllMilestones: PT.func,
100103
onGetChallenges: PT.func,
101104
onApproveMilestones: PT.func,
102105
isCustomer: PT.bool,

src/projects/detail/components/SimplePlan/ManageMilestones/ManageMilestones.jsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@ class ManageMilestones extends React.Component {
8484
}
8585

8686
onDeleteAll() {
87-
const { milestones, onRemoveMilestone } = this.props
88-
const seletedMilestones = _.filter(milestones, m => m.selected)
89-
_.forEach(seletedMilestones, m => {
90-
onRemoveMilestone(m.id)
91-
})
87+
const { milestones, onRemoveAllMilestones } = this.props
88+
const selectedPhases = _.filter(milestones, m => m.selected)
89+
90+
if (selectedPhases.length) {
91+
const { projectId } = selectedPhases[0]
92+
const phaseIds = selectedPhases.map(m => m.id)
93+
onRemoveAllMilestones(projectId, phaseIds)
94+
}
9295
}
9396

9497
onUnselectAll() {
@@ -388,6 +391,7 @@ ManageMilestones.propTypes = {
388391
onChangeMilestones: PT.func,
389392
onSaveMilestone: PT.func,
390393
onRemoveMilestone: PT.func,
394+
onRemoveAllMilestones: PT.func,
391395
onGetChallenges: PT.func,
392396
onApproveMilestones: PT.func,
393397
projectMembers: PT.arrayOf(PT.shape()),

src/projects/detail/containers/DashboardContainer.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
fireProductDirty,
2727
fireProductDirtyUndo,
2828
deleteProjectPhase,
29+
deleteBulkProjectPhase,
2930
expandProjectPhase,
3031
collapseProjectPhase,
3132
collapseAllProjectPhases,
@@ -94,6 +95,7 @@ class DashboardContainer extends React.Component {
9495
this.onChangeMilestones = this.onChangeMilestones.bind(this)
9596
this.onSaveMilestone = this.onSaveMilestone.bind(this)
9697
this.onRemoveMilestone = this.onRemoveMilestone.bind(this)
98+
this.onRemoveAllMilestones = this.onRemoveAllMilestones.bind(this)
9799
this.onGetChallenges = this.onGetChallenges.bind(this)
98100
this.onApproveMilestones = this.onApproveMilestones.bind(this)
99101
}
@@ -323,6 +325,21 @@ class DashboardContainer extends React.Component {
323325
})
324326
}
325327

328+
onRemoveAllMilestones(projectId, phaseIds) {
329+
this.props.deleteBulkProjectPhase(
330+
projectId,
331+
phaseIds
332+
).then(() => {
333+
if (!this.state.createGameplanPhases) {
334+
return
335+
}
336+
337+
// remove phases
338+
const newGameplanPhases = this.state.createGameplanPhases.filter(phase => !phaseIds.includes(phase.id))
339+
this.setState({createGameplanPhases: newGameplanPhases})
340+
})
341+
}
342+
326343

327344
render() {
328345
const {
@@ -525,6 +542,7 @@ class DashboardContainer extends React.Component {
525542
onSaveMilestone={this.onSaveMilestone}
526543
onGetChallenges={this.onGetChallenges}
527544
onRemoveMilestone={this.onRemoveMilestone}
545+
onRemoveAllMilestones={this.onRemoveAllMilestones}
528546
onApproveMilestones={this.onApproveMilestones}
529547
/>
530548
)
@@ -577,6 +595,7 @@ const mapDispatchToProps = {
577595
updateProductAttachment,
578596
removeProductAttachment,
579597
deleteProjectPhase,
598+
deleteBulkProjectPhase,
580599
expandProjectPhase,
581600
collapseProjectPhase,
582601
collapseAllProjectPhases,

src/projects/reducers/project.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
ACCEPT_OR_REFUSE_INVITE_SUCCESS, ACCEPT_OR_REFUSE_INVITE_FAILURE, ACCEPT_OR_REFUSE_INVITE_PENDING,
2727
UPLOAD_PROJECT_ATTACHMENT_FILES, DISCARD_PROJECT_ATTACHMENT, CHANGE_ATTACHMENT_PERMISSION,
2828
CREATE_SCOPE_CHANGE_REQUEST_SUCCESS, APPROVE_SCOPE_CHANGE_SUCCESS, REJECT_SCOPE_CHANGE_SUCCESS, CANCEL_SCOPE_CHANGE_SUCCESS, ACTIVATE_SCOPE_CHANGE_SUCCESS,
29-
LOAD_PROJECT_MEMBERS_SUCCESS, LOAD_PROJECT_MEMBER_INVITES_SUCCESS, LOAD_PROJECT_MEMBER_SUCCESS, CREATE_PROJECT_PHASE_PENDING, CREATE_PROJECT_PHASE_SUCCESS, CUSTOMER_APPROVE_MILESTONE_PENDING, CUSTOMER_APPROVE_MILESTONE_FINISHED,
29+
LOAD_PROJECT_MEMBERS_SUCCESS, LOAD_PROJECT_MEMBER_INVITES_SUCCESS, LOAD_PROJECT_MEMBER_SUCCESS, CREATE_PROJECT_PHASE_PENDING, CREATE_PROJECT_PHASE_SUCCESS, CUSTOMER_APPROVE_MILESTONE_PENDING, CUSTOMER_APPROVE_MILESTONE_FINISHED, DELETE_BULK_PROJECT_PHASE_PENDING, DELETE_BULK_PROJECT_PHASE_SUCCESS,
3030
} from '../../config/constants'
3131
import _ from 'lodash'
3232
import update from 'react-addons-update'
@@ -519,6 +519,7 @@ export const projectState = function (state=initialState, action) {
519519
case UPDATE_PROJECT_PENDING:
520520
case UPDATE_PHASE_PENDING:
521521
case DELETE_PROJECT_PHASE_PENDING:
522+
case DELETE_BULK_PROJECT_PHASE_PENDING:
522523
return Object.assign({}, state, {
523524
isLoading: false,
524525
processing: true,
@@ -562,6 +563,18 @@ export const projectState = function (state=initialState, action) {
562563
})
563564
}
564565

566+
case DELETE_BULK_PROJECT_PHASE_SUCCESS: {
567+
const { phaseIds } = action.payload
568+
569+
const newPhases = state.phases.filter(phase => !phaseIds.includes(phase.id))
570+
571+
return Object.assign({}, state, {
572+
phases: newPhases,
573+
phasesNonDirty: newPhases,
574+
processing: false,
575+
})
576+
}
577+
565578
case UPDATE_PRODUCT_SUCCESS:
566579
return {
567580
...state,

src/reducers/alerts.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ import {
7777
CUSTOMER_APPROVE_MILESTONE_APPROVE_SUCCESS,
7878
CUSTOMER_APPROVE_MILESTONE_REJECT_SUCCESS,
7979
CUSTOMER_APPROVE_MILESTONE_APPROVE_FAILURE,
80-
CUSTOMER_APPROVE_MILESTONE_REJECT_FAILURE
80+
CUSTOMER_APPROVE_MILESTONE_REJECT_FAILURE,
81+
DELETE_BULK_PROJECT_PHASE_SUCCESS
8182
} from '../config/constants'
8283
/* eslint-enable no-unused-vars */
8384

@@ -112,6 +113,16 @@ export default function(state = {}, action) {
112113
return state
113114
}
114115

116+
case DELETE_BULK_PROJECT_PHASE_SUCCESS: {
117+
if (state.project.version === 'v4') {
118+
Alert.success('Project milestones deleted.')
119+
} else {
120+
Alert.success('Project phases deleted.')
121+
}
122+
123+
return state
124+
}
125+
115126
case DELETE_PROJECT_SUCCESS:
116127
Alert.success('Project deleted.')
117128
return state

0 commit comments

Comments
 (0)