081db3a240
* 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>
353 lines
11 KiB
JavaScript
353 lines
11 KiB
JavaScript
import { next } from '@ember/runloop';
|
|
import { typeOf } from '@ember/utils';
|
|
import Service, { inject as service } from '@ember/service';
|
|
import { Machine } from 'xstate';
|
|
|
|
import getStorage from 'vault/lib/token-storage';
|
|
import { STORAGE_KEYS, DEFAULTS, MACHINES } from 'vault/helpers/wizard-constants';
|
|
const {
|
|
TUTORIAL_STATE,
|
|
COMPONENT_STATE,
|
|
FEATURE_STATE,
|
|
FEATURE_LIST,
|
|
FEATURE_STATE_HISTORY,
|
|
COMPLETED_FEATURES,
|
|
RESUME_URL,
|
|
RESUME_ROUTE,
|
|
} = STORAGE_KEYS;
|
|
const TutorialMachine = Machine(MACHINES.tutorial);
|
|
let FeatureMachine = null;
|
|
|
|
export default Service.extend(DEFAULTS, {
|
|
router: service(),
|
|
showWhenUnauthenticated: false,
|
|
featureMachineHistory: null,
|
|
init() {
|
|
this._super(...arguments);
|
|
this.initializeMachines();
|
|
},
|
|
|
|
initializeMachines() {
|
|
if (!this.storageHasKey(TUTORIAL_STATE)) {
|
|
let state = TutorialMachine.initialState;
|
|
this.saveState('currentState', state.value);
|
|
this.saveExtState(TUTORIAL_STATE, state.value);
|
|
}
|
|
this.saveState('currentState', this.getExtState(TUTORIAL_STATE));
|
|
if (this.storageHasKey(COMPONENT_STATE)) {
|
|
this.set('componentState', this.getExtState(COMPONENT_STATE));
|
|
}
|
|
let stateNodes = TutorialMachine.getStateNodes(this.currentState);
|
|
this.executeActions(stateNodes.reduce((acc, node) => acc.concat(node.onEntry), []), null, 'tutorial');
|
|
|
|
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));
|
|
}
|
|
this.saveState(
|
|
'featureState',
|
|
this.getExtState(FEATURE_STATE) || (FeatureMachine ? FeatureMachine.initialState : null)
|
|
);
|
|
this.saveExtState(FEATURE_STATE, this.featureState);
|
|
this.buildFeatureMachine();
|
|
}
|
|
},
|
|
|
|
clearFeatureData() {
|
|
let storage = this.storage();
|
|
// empty storage
|
|
[FEATURE_LIST, FEATURE_STATE, FEATURE_STATE_HISTORY, COMPLETED_FEATURES].forEach(key =>
|
|
storage.removeItem(key)
|
|
);
|
|
|
|
this.set('currentMachine', null);
|
|
this.set('featureMachineHistory', null);
|
|
this.set('featureState', null);
|
|
this.set('featureList', null);
|
|
},
|
|
|
|
restartGuide() {
|
|
this.clearFeatureData();
|
|
let storage = this.storage();
|
|
// empty storage
|
|
[TUTORIAL_STATE, COMPONENT_STATE, RESUME_URL, RESUME_ROUTE].forEach(key => storage.removeItem(key));
|
|
// reset wizard state
|
|
this.setProperties(DEFAULTS);
|
|
// restart machines from blank state
|
|
this.initializeMachines();
|
|
// progress machine to 'active.select'
|
|
this.transitionTutorialMachine('idle', 'AUTH');
|
|
},
|
|
|
|
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);
|
|
}
|
|
},
|
|
|
|
saveState(stateType, state) {
|
|
if (state.value) {
|
|
state = state.value;
|
|
}
|
|
let stateKey = '';
|
|
while (typeOf(state) === 'object') {
|
|
let newState = Object.keys(state);
|
|
stateKey += newState + '.';
|
|
state = state[newState];
|
|
}
|
|
stateKey += state;
|
|
this.set(stateType, stateKey);
|
|
if (stateType === 'featureState') {
|
|
//only track progress if we are on the first step of the first feature
|
|
this.saveFeatureHistory(state);
|
|
}
|
|
},
|
|
|
|
transitionTutorialMachine(currentState, event, extendedState) {
|
|
if (extendedState) {
|
|
this.set('componentState', extendedState);
|
|
this.saveExtState(COMPONENT_STATE, extendedState);
|
|
}
|
|
let { actions, value } = TutorialMachine.transition(currentState, event);
|
|
this.saveState('currentState', value);
|
|
this.saveExtState(TUTORIAL_STATE, this.currentState);
|
|
this.executeActions(actions, event, 'tutorial');
|
|
},
|
|
|
|
transitionFeatureMachine(currentState, event, extendedState) {
|
|
if (!FeatureMachine || !this.currentState.includes('active')) {
|
|
return;
|
|
}
|
|
if (extendedState) {
|
|
this.set('componentState', extendedState);
|
|
this.saveExtState(COMPONENT_STATE, extendedState);
|
|
}
|
|
|
|
let { actions, value } = FeatureMachine.transition(currentState, event, this.componentState);
|
|
this.saveState('featureState', value);
|
|
this.saveExtState(FEATURE_STATE, value);
|
|
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;
|
|
if (this.currentMachine === 'secrets' && value === 'display') {
|
|
next = FeatureMachine.transition(value, 'REPEAT', this.componentState);
|
|
} else {
|
|
next = FeatureMachine.transition(value, 'CONTINUE', this.componentState);
|
|
}
|
|
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;
|
|
let router = this.router;
|
|
|
|
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/, '');
|
|
next(() => {
|
|
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;
|
|
case 'clearFeatureData':
|
|
this.clearFeatureData();
|
|
break;
|
|
case 'continueFeature':
|
|
this.transitionFeatureMachine(this.featureState, 'CONTINUE', this.componentState);
|
|
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() {
|
|
let expected = this.expectedURL;
|
|
if (expected) {
|
|
this.saveExtState(RESUME_URL, this.expectedURL);
|
|
this.saveExtState(RESUME_ROUTE, this.expectedRouteName);
|
|
}
|
|
},
|
|
|
|
handleResume() {
|
|
let resumeURL = this.storage().getItem(RESUME_URL);
|
|
if (!resumeURL) {
|
|
return;
|
|
}
|
|
this.router
|
|
.transitionTo(resumeURL)
|
|
.followRedirects()
|
|
.then(() => {
|
|
this.set('expectedRouteName', this.storage().getItem(RESUME_ROUTE));
|
|
this.set('expectedURL', resumeURL);
|
|
this.initializeMachines();
|
|
this.storage().removeItem(RESUME_URL);
|
|
});
|
|
},
|
|
|
|
handleDismissed() {
|
|
this.storage().removeItem(FEATURE_STATE);
|
|
this.storage().removeItem(FEATURE_LIST);
|
|
this.storage().removeItem(FEATURE_STATE_HISTORY);
|
|
this.storage().removeItem(COMPONENT_STATE);
|
|
},
|
|
|
|
saveFeatures(features) {
|
|
this.set('featureList', features);
|
|
this.saveExtState(FEATURE_LIST, this.featureList);
|
|
this.buildFeatureMachine();
|
|
},
|
|
|
|
buildFeatureMachine() {
|
|
if (this.featureList === null) {
|
|
return;
|
|
}
|
|
this.startFeature();
|
|
let nextFeature = this.featureList.length > 1 ? this.featureList.objectAt(1).capitalize() : 'Finish';
|
|
this.set('nextFeature', nextFeature);
|
|
let next;
|
|
if (this.currentMachine === 'secrets' && this.featureState === 'display') {
|
|
next = FeatureMachine.transition(this.featureState, 'REPEAT', this.componentState);
|
|
} else {
|
|
next = FeatureMachine.transition(this.featureState, 'CONTINUE', this.componentState);
|
|
}
|
|
this.saveState('nextStep', next.value);
|
|
let stateNodes = FeatureMachine.getStateNodes(this.featureState);
|
|
this.executeActions(stateNodes.reduce((acc, node) => acc.concat(node.onEntry), []), null, 'feature');
|
|
},
|
|
|
|
startFeature() {
|
|
const FeatureMachineConfig = MACHINES[this.featureList.objectAt(0)];
|
|
FeatureMachine = Machine(FeatureMachineConfig);
|
|
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 [];
|
|
},
|
|
|
|
completeFeature() {
|
|
let features = this.featureList;
|
|
let done = features.shift();
|
|
if (!this.getExtState(COMPLETED_FEATURES)) {
|
|
let completed = [];
|
|
completed.push(done);
|
|
this.saveExtState(COMPLETED_FEATURES, completed);
|
|
} else {
|
|
this.saveExtState(
|
|
COMPLETED_FEATURES,
|
|
this.getExtState(COMPLETED_FEATURES)
|
|
.toArray()
|
|
.addObject(done)
|
|
);
|
|
}
|
|
|
|
this.saveExtState(FEATURE_LIST, features.length ? features : null);
|
|
this.storage().removeItem(FEATURE_STATE);
|
|
if (this.featureMachineHistory) {
|
|
this.set('featureMachineHistory', []);
|
|
this.saveExtState(FEATURE_STATE_HISTORY, []);
|
|
}
|
|
if (features.length > 0) {
|
|
this.buildFeatureMachine();
|
|
} else {
|
|
this.storage().removeItem(FEATURE_LIST);
|
|
FeatureMachine = null;
|
|
this.transitionTutorialMachine(this.currentState, 'DONE');
|
|
}
|
|
},
|
|
|
|
storage() {
|
|
return getStorage();
|
|
},
|
|
});
|