2018-09-25 16:28:26 +00:00
|
|
|
import { next } from '@ember/runloop';
|
|
|
|
import { typeOf } from '@ember/utils';
|
|
|
|
import Service, { inject as service } from '@ember/service';
|
2018-08-28 05:03:55 +00:00
|
|
|
import { Machine } from 'xstate';
|
2021-12-17 03:44:29 +00:00
|
|
|
import { capitalize } from '@ember/string';
|
2018-08-28 05:03:55 +00:00
|
|
|
|
|
|
|
import getStorage from 'vault/lib/token-storage';
|
2018-10-12 18:49:06 +00:00
|
|
|
import { STORAGE_KEYS, DEFAULTS, MACHINES } from 'vault/helpers/wizard-constants';
|
2018-10-18 19:19:50 +00:00
|
|
|
const {
|
|
|
|
TUTORIAL_STATE,
|
|
|
|
COMPONENT_STATE,
|
|
|
|
FEATURE_STATE,
|
|
|
|
FEATURE_LIST,
|
|
|
|
FEATURE_STATE_HISTORY,
|
|
|
|
COMPLETED_FEATURES,
|
|
|
|
RESUME_URL,
|
|
|
|
RESUME_ROUTE,
|
|
|
|
} = STORAGE_KEYS;
|
2018-10-12 18:49:06 +00:00
|
|
|
const TutorialMachine = Machine(MACHINES.tutorial);
|
2018-08-28 05:03:55 +00:00
|
|
|
let FeatureMachine = null;
|
|
|
|
|
|
|
|
export default Service.extend(DEFAULTS, {
|
2018-09-25 16:28:26 +00:00
|
|
|
router: service(),
|
2018-08-28 05:03:55 +00:00
|
|
|
showWhenUnauthenticated: false,
|
2018-10-18 19:19:50 +00:00
|
|
|
featureMachineHistory: null,
|
2018-08-28 05:03:55 +00:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.initializeMachines();
|
|
|
|
},
|
|
|
|
|
|
|
|
initializeMachines() {
|
2018-10-18 19:19:50 +00:00
|
|
|
if (!this.storageHasKey(TUTORIAL_STATE)) {
|
2018-08-28 05:03:55 +00:00
|
|
|
let state = TutorialMachine.initialState;
|
|
|
|
this.saveState('currentState', state.value);
|
2018-10-18 19:19:50 +00:00
|
|
|
this.saveExtState(TUTORIAL_STATE, state.value);
|
2018-08-28 05:03:55 +00:00
|
|
|
}
|
2018-10-18 19:19:50 +00:00
|
|
|
this.saveState('currentState', this.getExtState(TUTORIAL_STATE));
|
|
|
|
if (this.storageHasKey(COMPONENT_STATE)) {
|
|
|
|
this.set('componentState', this.getExtState(COMPONENT_STATE));
|
2018-08-28 05:03:55 +00:00
|
|
|
}
|
2018-10-18 19:19:50 +00:00
|
|
|
let stateNodes = TutorialMachine.getStateNodes(this.currentState);
|
2021-12-17 03:44:29 +00:00
|
|
|
this.executeActions(
|
|
|
|
stateNodes.reduce((acc, node) => acc.concat(node.onEntry), []),
|
|
|
|
null,
|
|
|
|
'tutorial'
|
|
|
|
);
|
2018-10-18 19:19:50 +00:00
|
|
|
|
|
|
|
if (this.storageHasKey(FEATURE_LIST)) {
|
|
|
|
this.set('featureList', this.getExtState(FEATURE_LIST));
|
|
|
|
if (this.storageHasKey(FEATURE_STATE_HISTORY)) {
|
|
|
|
this.set('featureMachineHistory', this.getExtState(FEATURE_STATE_HISTORY));
|
2018-08-28 05:03:55 +00:00
|
|
|
}
|
2018-10-18 19:19:50 +00:00
|
|
|
this.saveState(
|
|
|
|
'featureState',
|
|
|
|
this.getExtState(FEATURE_STATE) || (FeatureMachine ? FeatureMachine.initialState : null)
|
|
|
|
);
|
|
|
|
this.saveExtState(FEATURE_STATE, this.featureState);
|
2018-08-28 05:03:55 +00:00
|
|
|
this.buildFeatureMachine();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-10-18 19:19:50 +00:00
|
|
|
clearFeatureData() {
|
|
|
|
let storage = this.storage();
|
|
|
|
// empty storage
|
2021-12-17 03:44:29 +00:00
|
|
|
[FEATURE_LIST, FEATURE_STATE, FEATURE_STATE_HISTORY, COMPLETED_FEATURES].forEach((key) =>
|
2018-10-18 19:19:50 +00:00
|
|
|
storage.removeItem(key)
|
|
|
|
);
|
|
|
|
|
|
|
|
this.set('currentMachine', null);
|
|
|
|
this.set('featureMachineHistory', null);
|
|
|
|
this.set('featureState', null);
|
|
|
|
this.set('featureList', null);
|
|
|
|
},
|
|
|
|
|
2018-08-28 05:03:55 +00:00
|
|
|
restartGuide() {
|
2018-10-18 19:19:50 +00:00
|
|
|
this.clearFeatureData();
|
2018-08-28 05:03:55 +00:00
|
|
|
let storage = this.storage();
|
|
|
|
// empty storage
|
2021-12-17 03:44:29 +00:00
|
|
|
[TUTORIAL_STATE, COMPONENT_STATE, RESUME_URL, RESUME_ROUTE].forEach((key) => storage.removeItem(key));
|
2018-08-28 05:03:55 +00:00
|
|
|
// reset wizard state
|
|
|
|
this.setProperties(DEFAULTS);
|
|
|
|
// restart machines from blank state
|
|
|
|
this.initializeMachines();
|
|
|
|
// progress machine to 'active.select'
|
|
|
|
this.transitionTutorialMachine('idle', 'AUTH');
|
|
|
|
},
|
|
|
|
|
2018-10-18 19:19:50 +00:00
|
|
|
saveFeatureHistory(state) {
|
|
|
|
if (
|
|
|
|
this.getCompletedFeatures().length === 0 &&
|
|
|
|
this.featureMachineHistory === null &&
|
|
|
|
(state === 'idle' || state === 'wrap')
|
|
|
|
) {
|
|
|
|
let newHistory = [state];
|
|
|
|
this.set('featureMachineHistory', newHistory);
|
|
|
|
} else {
|
|
|
|
if (this.featureMachineHistory) {
|
|
|
|
if (!this.featureMachineHistory.includes(state)) {
|
|
|
|
let newHistory = this.featureMachineHistory.addObject(state);
|
|
|
|
this.set('featureMachineHistory', newHistory);
|
|
|
|
} else {
|
|
|
|
//we're repeating steps
|
|
|
|
let stepIndex = this.featureMachineHistory.indexOf(state);
|
|
|
|
let newHistory = this.featureMachineHistory.splice(0, stepIndex + 1);
|
|
|
|
this.set('featureMachineHistory', newHistory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.featureMachineHistory) {
|
|
|
|
this.saveExtState(FEATURE_STATE_HISTORY, this.featureMachineHistory);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-08-28 05:03:55 +00:00
|
|
|
saveState(stateType, state) {
|
|
|
|
if (state.value) {
|
|
|
|
state = state.value;
|
|
|
|
}
|
|
|
|
let stateKey = '';
|
2018-09-25 16:28:26 +00:00
|
|
|
while (typeOf(state) === 'object') {
|
2018-08-28 05:03:55 +00:00
|
|
|
let newState = Object.keys(state);
|
|
|
|
stateKey += newState + '.';
|
|
|
|
state = state[newState];
|
|
|
|
}
|
|
|
|
stateKey += state;
|
|
|
|
this.set(stateType, stateKey);
|
2018-10-18 19:19:50 +00:00
|
|
|
if (stateType === 'featureState') {
|
|
|
|
//only track progress if we are on the first step of the first feature
|
|
|
|
this.saveFeatureHistory(state);
|
|
|
|
}
|
2018-08-28 05:03:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
transitionTutorialMachine(currentState, event, extendedState) {
|
|
|
|
if (extendedState) {
|
|
|
|
this.set('componentState', extendedState);
|
2018-10-18 19:19:50 +00:00
|
|
|
this.saveExtState(COMPONENT_STATE, extendedState);
|
2018-08-28 05:03:55 +00:00
|
|
|
}
|
|
|
|
let { actions, value } = TutorialMachine.transition(currentState, event);
|
|
|
|
this.saveState('currentState', value);
|
2018-10-18 19:19:50 +00:00
|
|
|
this.saveExtState(TUTORIAL_STATE, this.currentState);
|
2018-08-28 05:03:55 +00:00
|
|
|
this.executeActions(actions, event, 'tutorial');
|
|
|
|
},
|
|
|
|
|
|
|
|
transitionFeatureMachine(currentState, event, extendedState) {
|
2018-10-18 19:19:50 +00:00
|
|
|
if (!FeatureMachine || !this.currentState.includes('active')) {
|
2018-08-28 05:03:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (extendedState) {
|
|
|
|
this.set('componentState', extendedState);
|
2018-10-18 19:19:50 +00:00
|
|
|
this.saveExtState(COMPONENT_STATE, extendedState);
|
2018-08-28 05:03:55 +00:00
|
|
|
}
|
|
|
|
|
Ember-cli upgrade from ~3.8 to ~3.20 (#9972)
* Update ember-cli to ~3.20
* Remove bad optional-feature
* Remove ember-fetch dep
* re-install ember-fetch
* update model fragments pr
* update ember model fragments correct package name
* update ember composable helpers to solve array helper error
* update ember-concurrency
* add back engine dependencies, automatically removed during ember-cli-upgrade
* make author-form-options component js file otherwise error
* for now comment out withTestWaiter
* add eslint-node and fix if not with unless in templates
* fix linting for tab index of false is now -1 and add type button to all buttons without types
* fix href errors for linting, likely have to come back and fix
* using eslint fix flag to fix all this.gets
* ember modules codemode removed files that had module twice, will fix in next commit
* finish codemode ember-data-codemod needed to rename const model
* more this.get removal codemode did not work
* cont. removal of this.get
* stop mixin rules until figure out how to reconfig them all
* smaller eslint ignores
* get codemode
* testing app small fixes to bring it back after all the changes
* small changes to eslint
* test removal of getProperties
* fix issue with baseKey because value could be unknown needed to add a question mark in nested get
* smaller linting fixes
* get nested fixes
* small linting error fixes
* small linting changes
* working through more small linting changes
* another round of linting modifications
* liniting fixes
* ember module codemod
* quinit dom codemod
* angle bracket codemod
* discovered that components must have js files
* ran all codemods this is all that's left
* small changes to fix get needs two object, should not have been using get.
* fix issue with one input in form field
* fun times with set and onChange from oninput
* fix issue with model not being passed through on secret-edit-display
* fix issue with yarn run test not working, revert without npm run all
* linting and small fix when loading without a selectAuthBackend
* fix failing test with ui-wizard issue
* fix test failure due to model not being asked for correctly with new changes, probably run into this more.
* fix issue with component helper and at props specific to wizard
* rename log to clilog due to conflict with new eslint rule
* small changes for test failures
* component helper at fixes
* Revert to old component style something with new one broke this and can't figure it out for now
* small fishy smelling test fixes will revisit
* small test changes
* more small test changes, appears upgrade treats spaces differently
* comment out code and test that no longer seems relevant but confirm
* clean run on component test though still some potential timing issues on ui-console test
* fixing one auth test issue and timing issue on enable-test
* small mods
* fix this conditional check from upgrade
* linting fixes after master merge
* package updates using yarn upgrade-interactive
* update libraries that did not effect any of the test failures.
* update ember truth helpers library
* settling tests
* Fix ui-panel control group output
* fix features selection test failures
* Fix auth tests (x-vault-token)
* fix shared test
* fix issue with data null on backend
* Revert "Fix auth tests (x-vault-token)"
This reverts commit 89cb174b2f1998efa56d9604d14131415ae65d6f.
* Fix auth tests (x-vault-token) without updating this.set
* Update redirect-to tests
* fix wrapped token test
* skip some flaky test
* fix issue with href and a tags vs buttons
* fix linting
* updates to get tests running (#10409)
* yarn isntall
* increasing resource_class
* whoops
* trying large
* back to xlarge
* Fix param issue on transform item routes
* test fixes
* settle on policies (old) test
* fix browserstack test warning and skips of test confirmed worked
* Fix redirect-to test
* skips
* fix transformation test and skip some kmip
* Skip tests
* Add meep marker to remaining failing tests
* Skip test with failing component
* rever skip on secret-create test
* Skip piece of test that fails due to navigation-input
* fix settings test where can and skip in others after confirming
* fix circle ci test failures
* ssh role settle
* Fix navigate-input and add settled to test
* Remove extra import
* secret cubbyhole and alicloud
* Add settled to gcpkms test
* settles on redirect to test
* Bump browserstack test resource to large
* Update browserstack resource size to xlarge
* update todos
* add back in withTestWaiter
* try and fix credentials conditional action added comment instead
* Update volatile computed properies to get functions
* this step was never reached and we never defined secretType anywhere so I removed
* add settled to policy old test
* Fix navigate-input on policies and leases
* replace ssh test with no var hoping that helps and add settled to other failing tests, unskip console tests
* kmip, transit, role test remove a skip and add in settled
* fix hover copy button, had to remove some testing functionality
* Remove private router service
* remove skip on control ssh and ui panel, fix search select by restructuring how to read the error
* final bit of working through skipped test
* Replace clearNonGlobalModels by linking directly to namespace with href-to
* Remove unused var
* Fix role-ssh id bug by updating form-field-from-model to form-field-group-loop
* Fix transit create id would not update
* Update option toggle selector for ssh-role
* Fix ssh selector
* cleanup pt1
* small clean up
* cleanup part2
* Fix computed on pricing-metrics-form
* small cleanup based on chelseas comments.
Co-authored-by: Chelsea Shaw <chelshaw.dev@gmail.com>
Co-authored-by: Sarah Thompson <sthompson@hashicorp.com>
2020-12-03 23:00:22 +00:00
|
|
|
let { actions, value } = FeatureMachine.transition(currentState, event, this.componentState);
|
2018-08-28 05:03:55 +00:00
|
|
|
this.saveState('featureState', value);
|
2018-10-18 19:19:50 +00:00
|
|
|
this.saveExtState(FEATURE_STATE, value);
|
2018-08-28 05:03:55 +00:00
|
|
|
this.executeActions(actions, event, 'feature');
|
|
|
|
// if all features were completed, the FeatureMachine gets nulled
|
|
|
|
// out and won't exist here as there is no next step
|
|
|
|
if (FeatureMachine) {
|
|
|
|
let next;
|
2018-10-18 19:19:50 +00:00
|
|
|
if (this.currentMachine === 'secrets' && value === 'display') {
|
|
|
|
next = FeatureMachine.transition(value, 'REPEAT', this.componentState);
|
2018-08-28 05:03:55 +00:00
|
|
|
} else {
|
2018-10-18 19:19:50 +00:00
|
|
|
next = FeatureMachine.transition(value, 'CONTINUE', this.componentState);
|
2018-08-28 05:03:55 +00:00
|
|
|
}
|
|
|
|
this.saveState('nextStep', next.value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
saveExtState(key, value) {
|
|
|
|
this.storage().setItem(key, value);
|
|
|
|
},
|
|
|
|
|
|
|
|
getExtState(key) {
|
|
|
|
return this.storage().getItem(key);
|
|
|
|
},
|
|
|
|
|
|
|
|
storageHasKey(key) {
|
|
|
|
return Boolean(this.getExtState(key));
|
|
|
|
},
|
|
|
|
|
|
|
|
executeActions(actions, event, machineType) {
|
|
|
|
let transitionURL;
|
|
|
|
let expectedRouteName;
|
2018-10-18 19:19:50 +00:00
|
|
|
let router = this.router;
|
2018-08-28 05:03:55 +00:00
|
|
|
|
|
|
|
for (let action of actions) {
|
|
|
|
let type = action;
|
|
|
|
if (action.type) {
|
|
|
|
type = action.type;
|
|
|
|
}
|
|
|
|
switch (type) {
|
|
|
|
case 'render':
|
|
|
|
this.set(`${action.level}Component`, action.component);
|
|
|
|
break;
|
|
|
|
case 'routeTransition':
|
|
|
|
expectedRouteName = action.params[0];
|
|
|
|
transitionURL = router.urlFor(...action.params).replace(/^\/ui/, '');
|
2018-09-25 16:28:26 +00:00
|
|
|
next(() => {
|
2018-08-28 05:03:55 +00:00
|
|
|
router.transitionTo(...action.params);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'saveFeatures':
|
|
|
|
this.saveFeatures(event.features);
|
|
|
|
break;
|
|
|
|
case 'completeFeature':
|
|
|
|
this.completeFeature();
|
|
|
|
break;
|
|
|
|
case 'handleDismissed':
|
|
|
|
this.handleDismissed();
|
|
|
|
break;
|
|
|
|
case 'handlePaused':
|
|
|
|
this.handlePaused();
|
|
|
|
return;
|
|
|
|
case 'handleResume':
|
|
|
|
this.handleResume();
|
|
|
|
break;
|
|
|
|
case 'showTutorialWhenAuthenticated':
|
|
|
|
this.set('showWhenUnauthenticated', false);
|
|
|
|
break;
|
|
|
|
case 'showTutorialAlways':
|
|
|
|
this.set('showWhenUnauthenticated', true);
|
|
|
|
break;
|
2018-10-18 19:19:50 +00:00
|
|
|
case 'clearFeatureData':
|
|
|
|
this.clearFeatureData();
|
|
|
|
break;
|
2018-08-28 05:03:55 +00:00
|
|
|
case 'continueFeature':
|
2018-10-18 19:19:50 +00:00
|
|
|
this.transitionFeatureMachine(this.featureState, 'CONTINUE', this.componentState);
|
2018-08-28 05:03:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (machineType === 'tutorial') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// if we're transitioning in the actions, we want that url,
|
|
|
|
// else we want the URL we land on in didTransition in the
|
|
|
|
// application route - we'll notify the application route to
|
|
|
|
// update the route
|
|
|
|
if (transitionURL) {
|
|
|
|
this.set('expectedURL', transitionURL);
|
|
|
|
this.set('expectedRouteName', expectedRouteName);
|
|
|
|
this.set('setURLAfterTransition', false);
|
|
|
|
} else {
|
|
|
|
this.set('setURLAfterTransition', true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handlePaused() {
|
2018-10-18 19:19:50 +00:00
|
|
|
let expected = this.expectedURL;
|
2018-08-28 05:03:55 +00:00
|
|
|
if (expected) {
|
2018-10-18 19:19:50 +00:00
|
|
|
this.saveExtState(RESUME_URL, this.expectedURL);
|
|
|
|
this.saveExtState(RESUME_ROUTE, this.expectedRouteName);
|
2018-08-28 05:03:55 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
handleResume() {
|
2018-10-18 19:19:50 +00:00
|
|
|
let resumeURL = this.storage().getItem(RESUME_URL);
|
2018-08-28 05:03:55 +00:00
|
|
|
if (!resumeURL) {
|
|
|
|
return;
|
|
|
|
}
|
Ember-cli upgrade from ~3.8 to ~3.20 (#9972)
* Update ember-cli to ~3.20
* Remove bad optional-feature
* Remove ember-fetch dep
* re-install ember-fetch
* update model fragments pr
* update ember model fragments correct package name
* update ember composable helpers to solve array helper error
* update ember-concurrency
* add back engine dependencies, automatically removed during ember-cli-upgrade
* make author-form-options component js file otherwise error
* for now comment out withTestWaiter
* add eslint-node and fix if not with unless in templates
* fix linting for tab index of false is now -1 and add type button to all buttons without types
* fix href errors for linting, likely have to come back and fix
* using eslint fix flag to fix all this.gets
* ember modules codemode removed files that had module twice, will fix in next commit
* finish codemode ember-data-codemod needed to rename const model
* more this.get removal codemode did not work
* cont. removal of this.get
* stop mixin rules until figure out how to reconfig them all
* smaller eslint ignores
* get codemode
* testing app small fixes to bring it back after all the changes
* small changes to eslint
* test removal of getProperties
* fix issue with baseKey because value could be unknown needed to add a question mark in nested get
* smaller linting fixes
* get nested fixes
* small linting error fixes
* small linting changes
* working through more small linting changes
* another round of linting modifications
* liniting fixes
* ember module codemod
* quinit dom codemod
* angle bracket codemod
* discovered that components must have js files
* ran all codemods this is all that's left
* small changes to fix get needs two object, should not have been using get.
* fix issue with one input in form field
* fun times with set and onChange from oninput
* fix issue with model not being passed through on secret-edit-display
* fix issue with yarn run test not working, revert without npm run all
* linting and small fix when loading without a selectAuthBackend
* fix failing test with ui-wizard issue
* fix test failure due to model not being asked for correctly with new changes, probably run into this more.
* fix issue with component helper and at props specific to wizard
* rename log to clilog due to conflict with new eslint rule
* small changes for test failures
* component helper at fixes
* Revert to old component style something with new one broke this and can't figure it out for now
* small fishy smelling test fixes will revisit
* small test changes
* more small test changes, appears upgrade treats spaces differently
* comment out code and test that no longer seems relevant but confirm
* clean run on component test though still some potential timing issues on ui-console test
* fixing one auth test issue and timing issue on enable-test
* small mods
* fix this conditional check from upgrade
* linting fixes after master merge
* package updates using yarn upgrade-interactive
* update libraries that did not effect any of the test failures.
* update ember truth helpers library
* settling tests
* Fix ui-panel control group output
* fix features selection test failures
* Fix auth tests (x-vault-token)
* fix shared test
* fix issue with data null on backend
* Revert "Fix auth tests (x-vault-token)"
This reverts commit 89cb174b2f1998efa56d9604d14131415ae65d6f.
* Fix auth tests (x-vault-token) without updating this.set
* Update redirect-to tests
* fix wrapped token test
* skip some flaky test
* fix issue with href and a tags vs buttons
* fix linting
* updates to get tests running (#10409)
* yarn isntall
* increasing resource_class
* whoops
* trying large
* back to xlarge
* Fix param issue on transform item routes
* test fixes
* settle on policies (old) test
* fix browserstack test warning and skips of test confirmed worked
* Fix redirect-to test
* skips
* fix transformation test and skip some kmip
* Skip tests
* Add meep marker to remaining failing tests
* Skip test with failing component
* rever skip on secret-create test
* Skip piece of test that fails due to navigation-input
* fix settings test where can and skip in others after confirming
* fix circle ci test failures
* ssh role settle
* Fix navigate-input and add settled to test
* Remove extra import
* secret cubbyhole and alicloud
* Add settled to gcpkms test
* settles on redirect to test
* Bump browserstack test resource to large
* Update browserstack resource size to xlarge
* update todos
* add back in withTestWaiter
* try and fix credentials conditional action added comment instead
* Update volatile computed properies to get functions
* this step was never reached and we never defined secretType anywhere so I removed
* add settled to policy old test
* Fix navigate-input on policies and leases
* replace ssh test with no var hoping that helps and add settled to other failing tests, unskip console tests
* kmip, transit, role test remove a skip and add in settled
* fix hover copy button, had to remove some testing functionality
* Remove private router service
* remove skip on control ssh and ui panel, fix search select by restructuring how to read the error
* final bit of working through skipped test
* Replace clearNonGlobalModels by linking directly to namespace with href-to
* Remove unused var
* Fix role-ssh id bug by updating form-field-from-model to form-field-group-loop
* Fix transit create id would not update
* Update option toggle selector for ssh-role
* Fix ssh selector
* cleanup pt1
* small clean up
* cleanup part2
* Fix computed on pricing-metrics-form
* small cleanup based on chelseas comments.
Co-authored-by: Chelsea Shaw <chelshaw.dev@gmail.com>
Co-authored-by: Sarah Thompson <sthompson@hashicorp.com>
2020-12-03 23:00:22 +00:00
|
|
|
this.router
|
2018-10-18 19:19:50 +00:00
|
|
|
.transitionTo(resumeURL)
|
|
|
|
.followRedirects()
|
|
|
|
.then(() => {
|
|
|
|
this.set('expectedRouteName', this.storage().getItem(RESUME_ROUTE));
|
|
|
|
this.set('expectedURL', resumeURL);
|
|
|
|
this.initializeMachines();
|
|
|
|
this.storage().removeItem(RESUME_URL);
|
|
|
|
});
|
2018-08-28 05:03:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
handleDismissed() {
|
2018-10-18 19:19:50 +00:00
|
|
|
this.storage().removeItem(FEATURE_STATE);
|
|
|
|
this.storage().removeItem(FEATURE_LIST);
|
|
|
|
this.storage().removeItem(FEATURE_STATE_HISTORY);
|
|
|
|
this.storage().removeItem(COMPONENT_STATE);
|
2018-08-28 05:03:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
saveFeatures(features) {
|
|
|
|
this.set('featureList', features);
|
2018-10-18 19:19:50 +00:00
|
|
|
this.saveExtState(FEATURE_LIST, this.featureList);
|
2018-08-28 05:03:55 +00:00
|
|
|
this.buildFeatureMachine();
|
|
|
|
},
|
|
|
|
|
|
|
|
buildFeatureMachine() {
|
2018-10-18 19:19:50 +00:00
|
|
|
if (this.featureList === null) {
|
2018-08-28 05:03:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.startFeature();
|
2021-12-17 03:44:29 +00:00
|
|
|
let nextFeature = this.featureList.length > 1 ? capitalize(this.featureList.objectAt(1)) : 'Finish';
|
2018-08-28 05:03:55 +00:00
|
|
|
this.set('nextFeature', nextFeature);
|
|
|
|
let next;
|
2018-10-18 19:19:50 +00:00
|
|
|
if (this.currentMachine === 'secrets' && this.featureState === 'display') {
|
|
|
|
next = FeatureMachine.transition(this.featureState, 'REPEAT', this.componentState);
|
2018-08-28 05:03:55 +00:00
|
|
|
} else {
|
2018-10-18 19:19:50 +00:00
|
|
|
next = FeatureMachine.transition(this.featureState, 'CONTINUE', this.componentState);
|
2018-08-28 05:03:55 +00:00
|
|
|
}
|
|
|
|
this.saveState('nextStep', next.value);
|
2018-10-18 19:19:50 +00:00
|
|
|
let stateNodes = FeatureMachine.getStateNodes(this.featureState);
|
2021-12-17 03:44:29 +00:00
|
|
|
this.executeActions(
|
|
|
|
stateNodes.reduce((acc, node) => acc.concat(node.onEntry), []),
|
|
|
|
null,
|
|
|
|
'feature'
|
|
|
|
);
|
2018-08-28 05:03:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
startFeature() {
|
2018-10-18 19:19:50 +00:00
|
|
|
const FeatureMachineConfig = MACHINES[this.featureList.objectAt(0)];
|
2018-08-28 05:03:55 +00:00
|
|
|
FeatureMachine = Machine(FeatureMachineConfig);
|
2018-10-18 19:19:50 +00:00
|
|
|
this.set('currentMachine', this.featureList.objectAt(0));
|
|
|
|
if (this.storageHasKey(FEATURE_STATE)) {
|
|
|
|
this.saveState('featureState', this.getExtState(FEATURE_STATE));
|
|
|
|
} else {
|
|
|
|
this.saveState('featureState', FeatureMachine.initialState);
|
|
|
|
}
|
|
|
|
this.saveExtState(FEATURE_STATE, this.featureState);
|
|
|
|
},
|
|
|
|
|
|
|
|
getCompletedFeatures() {
|
|
|
|
if (this.storageHasKey(COMPLETED_FEATURES)) {
|
|
|
|
return this.getExtState(COMPLETED_FEATURES).toArray();
|
|
|
|
}
|
|
|
|
return [];
|
2018-08-28 05:03:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
completeFeature() {
|
2018-10-18 19:19:50 +00:00
|
|
|
let features = this.featureList;
|
2018-08-28 05:03:55 +00:00
|
|
|
let done = features.shift();
|
2018-10-18 19:19:50 +00:00
|
|
|
if (!this.getExtState(COMPLETED_FEATURES)) {
|
2018-08-28 05:03:55 +00:00
|
|
|
let completed = [];
|
|
|
|
completed.push(done);
|
2018-10-18 19:19:50 +00:00
|
|
|
this.saveExtState(COMPLETED_FEATURES, completed);
|
2018-08-28 05:03:55 +00:00
|
|
|
} else {
|
2021-12-17 03:44:29 +00:00
|
|
|
this.saveExtState(COMPLETED_FEATURES, this.getExtState(COMPLETED_FEATURES).toArray().addObject(done));
|
2018-08-28 05:03:55 +00:00
|
|
|
}
|
|
|
|
|
2018-10-18 19:19:50 +00:00
|
|
|
this.saveExtState(FEATURE_LIST, features.length ? features : null);
|
|
|
|
this.storage().removeItem(FEATURE_STATE);
|
|
|
|
if (this.featureMachineHistory) {
|
|
|
|
this.set('featureMachineHistory', []);
|
|
|
|
this.saveExtState(FEATURE_STATE_HISTORY, []);
|
|
|
|
}
|
2018-08-28 05:03:55 +00:00
|
|
|
if (features.length > 0) {
|
|
|
|
this.buildFeatureMachine();
|
|
|
|
} else {
|
2018-10-18 19:19:50 +00:00
|
|
|
this.storage().removeItem(FEATURE_LIST);
|
2018-08-28 05:03:55 +00:00
|
|
|
FeatureMachine = null;
|
2018-10-18 19:19:50 +00:00
|
|
|
this.transitionTutorialMachine(this.currentState, 'DONE');
|
2018-08-28 05:03:55 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
storage() {
|
|
|
|
return getStorage();
|
|
|
|
},
|
|
|
|
});
|