import { mutator } from "satcheljs" ; import { addChoice , deleteChoice , showBlankTitleError , changeItemCheckedStatus , updateChoiceText , updateTitle , setContext , setProgressState , setSendingFlag , } from "../actions/CreationActions" ; import { Status , ChecklistItem , checklistItemState , } from "../utils" ; import getStore from "../store/CreationStore" ; import * as actionSDK from "@microsoft/m365-action-sdk" ; import { Utils } from "../utils/Utils" ; mutator ( setProgressState , ( msg ) => { const store = getStore ( ) ; store . progressState = msg . state ; } ) ; /**
 * Creation view mutators to modify store data on which create view relies
 */ mutator ( setContext , ( msg ) => { const store = getStore ( ) ; store . context = msg . context ; if ( ! Utils . isEmptyObject ( store . context . lastSessionData ) ) { const lastSessionData = store . context . lastSessionData ; const actionInstance = lastSessionData . action ; const actionInstanceRows = lastSessionData . dataRows ; const itemsCopy = [ ] ; if ( actionInstanceRows && actionInstanceRows . length > 0 ) { actionInstanceRows . forEach ( ( rowItem , index ) => { let title = rowItem . columnValues [ "checklistItem" ] ; let state ; if ( rowItem . columnValues [ "status" ] == Status . ACTIVE ) { state = Status . ACTIVE ; } if ( rowItem . columnValues [ "status" ] == Status . COMPLETED ) { state = Status . COMPLETED ; } let item = new ChecklistItem ( title , state , "" , checklistItemState . MODIFIED , "" , ( new Date ( ) . getTime ( ) + index ) . toString ( ) , "" , "" ) ; itemsCopy . push ( item ) ; } ) ; getStore ( ) . items = itemsCopy ; } getStore ( ) . title = actionInstance . displayName ; } } ) ; mutator ( addChoice , ( ) => { const store = getStore ( ) ; const itemsCopy = [ ... store . items ] ; let item = new ChecklistItem ( ) ; itemsCopy . push ( item ) ; store . items = itemsCopy ; } ) ; mutator ( deleteChoice , ( msg ) => { let item = msg . item ; const store = getStore ( ) ; store . items = store . items . filter ( ( x ) => x !== item ) ; } ) ; mutator ( showBlankTitleError , ( msg ) => { let blankTitleError = msg . blankTitleError ; const store = getStore ( ) ; store . showBlankTitleError = blankTitleError ; } ) ; mutator ( changeItemCheckedStatus , ( msg ) => { let item = msg . item ; let state = msg . state ; const store = getStore ( ) ; const itemsCopy = [ ... store . items ] ; let index = itemsCopy . indexOf ( item ) ; if ( index > - 1 ) { itemsCopy [ index ] = itemsCopy [ index ] . clone ( ) ; if ( state ) { itemsCopy [ index ] . status = Status . COMPLETED ; } else { itemsCopy [ index ] . status = Status . ACTIVE ; } itemsCopy [ index ] . itemState = checklistItemState . MODIFIED ; } store . items = itemsCopy ; } ) ; mutator ( updateChoiceText , ( msg ) => { let item = msg . item ; let text = msg . text ; const store = getStore ( ) ; const itemsCopy = [ ... store . items ] ; let index = itemsCopy . indexOf ( item ) ; if ( index > - 1 ) { itemsCopy [ index ] = itemsCopy [ index ] . clone ( ) ; itemsCopy [ index ] . title = text ; itemsCopy [ index ] . itemState = checklistItemState . MODIFIED ; } store . items = itemsCopy ; } ) ; mutator ( updateTitle , ( msg ) => { let title = msg . title ; const store = getStore ( ) ; store . showBlankTitleError = false ; store . title = title ; } ) ; mutator ( setSendingFlag , ( msg ) => { let value = msg . value ; const store = getStore ( ) ; store . isSending = value ; } ) ;