@@ -55,7 +55,7 @@ function mergeJsonObjects(targetObj, sourceObj) {
5555
5656function updateMilestone ( milestone , updatedProps ) {
5757 const entityToUpdate = updatedProps
58- const durationChanged = entityToUpdate . duration && entityToUpdate . duration !== milestone . duration
58+
5959 const statusChanged = entityToUpdate . status && entityToUpdate . status !== milestone . status
6060 const completionDateChanged = entityToUpdate . completionDate
6161 && ! _ . isEqual ( milestone . completionDate , entityToUpdate . completionDate )
@@ -64,40 +64,23 @@ function updateMilestone(milestone, updatedProps) {
6464 // Merge JSON fields
6565 entityToUpdate . details = mergeJsonObjects ( milestone . details , entityToUpdate . details )
6666
67- let actualStartDateCanged = false
6867 // if status has changed
6968 if ( statusChanged ) {
7069 // if status has changed to be completed, set the compeltionDate if not provided
7170 if ( entityToUpdate . status === MILESTONE_STATUS . COMPLETED ) {
7271 entityToUpdate . completionDate = entityToUpdate . completionDate ? entityToUpdate . completionDate : today . toISOString ( )
73- entityToUpdate . duration = moment . utc ( entityToUpdate . completionDate )
74- . diff ( entityToUpdate . actualStartDate , 'days' ) + 1
7572 }
7673 // if status has changed to be active, set the startDate to today
7774 if ( entityToUpdate . status === MILESTONE_STATUS . ACTIVE ) {
7875 // NOTE: not updating startDate as activating a milestone should not update the scheduled start date
7976 // entityToUpdate.startDate = today
8077 // should update actual start date
8178 entityToUpdate . actualStartDate = today . toISOString ( )
82- actualStartDateCanged = true
8379 }
8480 }
8581
86- // Updates the end date of the milestone if:
87- // 1. if duration of the milestone is udpated, update its end date
88- // OR
89- // 2. if actual start date is updated, updating the end date of the activated milestone because
90- // early or late start of milestone, we are essentially changing the end schedule of the milestone
91- if ( durationChanged || actualStartDateCanged ) {
92- const updatedStartDate = actualStartDateCanged ? entityToUpdate . actualStartDate : milestone . startDate
93- const updatedDuration = _ . get ( entityToUpdate , 'duration' , milestone . duration )
94- entityToUpdate . endDate = moment . utc ( updatedStartDate ) . add ( updatedDuration - 1 , 'days' ) . toDate ( ) . toISOString ( )
95- }
96-
9782 // if completionDate has changed
9883 if ( ! statusChanged && completionDateChanged ) {
99- entityToUpdate . duration = moment . utc ( entityToUpdate . completionDate )
100- . diff ( entityToUpdate . actualStartDate , 'days' ) + 1
10184 entityToUpdate . status = MILESTONE_STATUS . COMPLETED
10285 }
10386
@@ -141,7 +124,7 @@ function updateComingMilestones(origMilestone, updMilestone, timelineMilestones)
141124 }
142125
143126 // Calculate the endDate, and update it if different
144- const endDate = moment . utc ( updateProps . startDate || milestone . startDate ) . add ( milestone . duration - 1 , 'days' ) . toDate ( ) . toISOString ( )
127+ const endDate = moment . utc ( updateProps . endDate || milestone . endDate ) . toDate ( ) . toISOString ( )
145128 if ( ! _ . isEqual ( milestone . endDate , endDate ) ) {
146129 updateProps . endDate = endDate
147130 updateProps . updatedBy = updMilestone . updatedBy
@@ -176,7 +159,6 @@ function cascadeMilestones(originalMilestone, updatedMilestone, timelineMileston
176159
177160 // we need to recalculate change in fields because we update some fields before making actual update
178161 const needToCascade = ! _ . isEqual ( original . completionDate , updated . completionDate ) // completion date changed
179- || original . duration !== updated . duration // duration changed
180162 || original . actualStartDate !== updated . actualStartDate // actual start date updated
181163
182164 if ( needToCascade ) {
@@ -199,3 +181,8 @@ export const processUpdateMilestone = (milestone, updatedProps, timelineMileston
199181
200182 return { updatedMilestone, updatedTimelineMilestones }
201183}
184+
185+
186+ export const processDeleteMilestone = ( index , timelineMilestones ) => {
187+ return update ( timelineMilestones , { $splice :[ [ index , 1 ] ] } )
188+ }
0 commit comments