diff options
Diffstat (limited to 'app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js')
-rw-r--r-- | app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js b/app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js index 29e0c867f6b..6628225cd46 100644 --- a/app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js +++ b/app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js @@ -1,11 +1,21 @@ import getStateKey from 'ee_else_ce/vue_merge_request_widget/stores/get_state_key'; import { statusBoxState } from '~/issuable/components/status_box.vue'; import { formatDate, getTimeago } from '~/lib/utils/datetime_utility'; -import { MTWPS_MERGE_STRATEGY, MT_MERGE_STRATEGY, MWPS_MERGE_STRATEGY } from '../constants'; +import { machine } from '~/lib/utils/finite_state_machine'; +import { + MTWPS_MERGE_STRATEGY, + MT_MERGE_STRATEGY, + MWPS_MERGE_STRATEGY, + STATE_MACHINE, + stateToTransitionMap, +} from '../constants'; import { stateKey } from './state_maps'; const { format } = getTimeago(); +const { states } = STATE_MACHINE; +const { IDLE } = states; + export default class MergeRequestStore { constructor(data) { this.sha = data.diff_head_sha; @@ -16,6 +26,9 @@ export default class MergeRequestStore { this.apiUnapprovePath = data.api_unapprove_path; this.hasApprovalsAvailable = data.has_approvals_available; + this.stateMachine = machine(STATE_MACHINE.definition); + this.machineValue = this.stateMachine.value; + this.setPaths(data); this.setData(data); @@ -215,10 +228,7 @@ export default class MergeRequestStore { setState() { if (this.mergeOngoing) { this.state = 'merging'; - return; - } - - if (this.isOpen) { + } else if (this.isOpen) { this.state = getStateKey.call(this); } else { switch (this.mergeRequestState) { @@ -232,6 +242,8 @@ export default class MergeRequestStore { this.state = null; } } + + this.translateStateToMachine(); } setPaths(data) { @@ -277,7 +289,7 @@ export default class MergeRequestStore { // Security reports this.sastComparisonPath = data.sast_comparison_path; - this.secretScanningComparisonPath = data.secret_scanning_comparison_path; + this.secretDetectionComparisonPath = data.secret_detection_comparison_path; } get isNothingToMergeState() { @@ -356,4 +368,32 @@ export default class MergeRequestStore { (this.onlyAllowMergeIfPipelineSucceeds && this.isPipelineFailed) ); } + + // Because the state machine doesn't yet handle every state and transition, + // some use-cases will need to force a state that can't be reached by + // a known transition. This is undesirable long-term (as it subverts + // the intent of a state machine), but is necessary until the machine + // can handle all possible combinations. (unsafeForce) + transitionStateMachine({ transition, state, unsafeForce = false } = {}) { + if (unsafeForce && state) { + this.stateMachine.value = state; + } else { + this.stateMachine.send(transition); + } + + this.machineValue = this.stateMachine.value; + } + translateStateToMachine() { + const transition = stateToTransitionMap[this.state]; + let transitionOptions = { + state: IDLE, + unsafeForce: true, + }; + + if (transition) { + transitionOptions = { transition }; + } + + this.transitionStateMachine(transitionOptions); + } } |