Last active
May 8, 2020 11:52
-
-
Save chukinas/360718e57b8550e05dc5554b953de3af to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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
// https://xstate.js.org/viz/?gist=360718e57b8550e05dc5554b953de3af | |
const local = { | |
on: { | |
CANCEL: '#deleted', | |
SAVE: { | |
target: '#active', | |
cond: 'isPartiallyValidated', | |
}, | |
SUBMIT: { | |
target: '#awaitingDisposition', | |
cond: 'isFullyValidated', | |
}, | |
} | |
} | |
const draft = { | |
id: 'draft', | |
on: { | |
DELETE: '#deleted', | |
SAVE: { | |
target: '#draft', | |
cond: 'isPartiallyValidated', | |
}, | |
SUBMIT: { | |
target: '#awaitingDisposition', | |
cond: 'isFullyValidated', | |
}, | |
} | |
} | |
const inactive = { | |
id: 'inactive', | |
on: { | |
REACTIVATE: '#awaitingDisposition', | |
} | |
} | |
const teamStatus = { | |
id: 'teamStatus', | |
initial: 'tentative', | |
entry: [ | |
'notifySponsor', | |
], | |
states: { | |
tentative: { | |
on: { | |
SPONSOR_APPROVE_TEAM: 'approved', | |
}, | |
}, | |
approved: { | |
entry: 'notifyTeamMembers', | |
}, | |
}, | |
on: { | |
TEAM_CHANGE: '.tentative', | |
} | |
} | |
const dispositionStatus = { | |
id: 'dispositionStatus', | |
initial: 'incomplete', | |
states: { | |
incomplete: {}, | |
complete: { | |
on: { | |
SUBMIT: { | |
target: '#awaitingApproval', | |
in: '#performanceAnalysis.active.awaitingDisposition.teamStatus.approved', | |
}, | |
}, | |
}, | |
}, | |
on: { | |
COMPLETE: '.complete', | |
}, | |
} | |
const awaitingDisposition = { | |
id: 'awaitingDisposition', | |
initial: 'notReady', | |
on: { | |
DEACTIVATE: '#inactive', | |
}, | |
type: 'parallel', | |
states: { | |
teamStatus, | |
dispositionStatus, | |
}, | |
} | |
const awaitingApproval = { | |
id: 'awaitingApproval', | |
entry: 'notifySponsor', | |
initial: 'idle', | |
on: { | |
SPONSOR_APPROVE_DISPO: '#completed', | |
}, | |
states: { | |
idle: { | |
on: { | |
SPONSOR_REJECT_DISPO: '#awaitingApproval.awaitingRejectComment', | |
}, | |
}, | |
awaitingRejectComment: { | |
on: { | |
SUBMIT_REJECT_COMMENT: '#teamStatus.approved', | |
} | |
}, | |
} | |
} | |
const completed = { | |
id: 'completed', | |
entry: [ | |
'notifyRequester', | |
'notifyTeamMembers', | |
'ifNeeded_generateTrReq', | |
'ifNeeded_generateARs', | |
], | |
on: { | |
REOPEN: '#awaitingDisposition', | |
LINK_AR: '#completed', | |
LINK_TR: '#completed', | |
GENERATE_TR: '#completed', | |
} | |
} | |
const active = { | |
id: 'active', | |
initial: 'draft', | |
states: { | |
draft, | |
awaitingDisposition, | |
awaitingApproval, | |
completed | |
} | |
} | |
const perfAnalysisMachine = Machine({ | |
id: 'performanceAnalysis', | |
initial: 'local', | |
states: { | |
deleted: { | |
id: 'deleted', | |
type: 'final', | |
}, | |
local, | |
active, | |
inactive, | |
}, | |
},{ | |
guards: { | |
hasSponsor: ()=>true, | |
isPartiallyValidated: ()=>true, | |
isFullyValidated: ()=>true, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment