Skip to content

Commit aa5632a

Browse files
committed
add hooks for unseal and setting component state on the service
1 parent 35895bc commit aa5632a

File tree

5 files changed

+37
-47
lines changed

5 files changed

+37
-47
lines changed

ui/app/components/shamir-flow.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,25 @@ const DEFAULTS = {
2121
export default Component.extend(DEFAULTS, {
2222
tagName: '',
2323
store: inject.service(),
24-
wizard: inject.service(),
2524
formText: null,
2625
fetchOnInit: false,
2726
buttonText: 'Submit',
2827
thresholdPath: 'required',
2928
generateAction: false,
3029

3130
init() {
31+
this._super(...arguments);
3232
if (this.get('fetchOnInit')) {
3333
this.attemptProgress();
3434
}
35-
if (this.get('action') === 'unseal') {
36-
this.get('wizard').transitionTutorialMachine(this.get('wizard.currentState'), 'NOOP', {
37-
threshold: this.get('threshold'),
38-
progress: this.get('progress'),
39-
});
40-
}
41-
return this._super(...arguments);
4235
},
4336

37+
didInsertElement() {
38+
this._super(...arguments);
39+
this.onUpdate(this.getProperties(Object.keys(DEFAULTS)));
40+
},
41+
42+
onUpdate() {},
4443
onShamirSuccess() {},
4544
// can be overridden w/an attr
4645
isComplete(data) {
@@ -62,17 +61,23 @@ export default Component.extend(DEFAULTS, {
6261
hasProgress: computed.gt('progress', 0),
6362

6463
actionSuccess(resp) {
65-
const { isComplete, onShamirSuccess, thresholdPath } = this.getProperties(
64+
let { onActionSuccess, isComplete, onShamirSuccess, thresholdPath } = this.getProperties(
65+
'onActionSuccess',
6666
'isComplete',
6767
'onShamirSuccess',
6868
'thresholdPath'
6969
);
70+
let threshold = get(resp, thresholdPath);
71+
let props = {
72+
...resp,
73+
threshold,
74+
};
7075
this.stopLoading();
71-
this.set('threshold', get(resp, thresholdPath));
72-
this.setProperties(resp);
73-
if (isComplete(resp)) {
76+
this.setProperties(props);
77+
onUpdate(props);
78+
if (isComplete(props)) {
7479
this.reset();
75-
onShamirSuccess(resp);
80+
onShamirSuccess(props);
7681
}
7782
},
7883

ui/app/controllers/vault/cluster/unseal.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ export default Ember.Controller.extend({
55

66
actions: {
77
transitionToCluster(resp) {
8-
debugger;
98
return this.get('model').reload().then(() => {
109
this.get('wizard').transitionTutorialMachine(this.get('wizard.currentState'), 'CONTINUE', resp);
1110
return this.transitionToRoute('vault.cluster', this.get('model.name'));
1211
});
1312
},
13+
14+
setUnsealState(resp) {
15+
this.get('wizard').set('componentState', resp);
16+
},
17+
1418
isUnsealed(data) {
1519
return data.sealed === false;
1620
},
Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1 @@
1-
import ClusterRouteBase from './cluster-route-base';
2-
import Ember from 'ember';
3-
4-
const { inject } = Ember;
5-
6-
export default ClusterRouteBase.extend({
7-
wizard: inject.service(),
8-
9-
beforeModel() {
10-
this._super(...arguments);
11-
debugger;
12-
if (this.get('wizard.currentState') === 'active.init.save') {
13-
this.get('wizard').transitionTutorialMachine(this.get('wizard.currentState'), 'CONTINUE');
14-
}
15-
},
16-
afterModel() {
17-
this._super(...arguments);
18-
debugger;
19-
},
20-
});
1+
export { default } from './cluster-route-base';

ui/app/services/wizard.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ export default Service.extend({
3030
if (!this.storageHasKey(TUTORIAL_STATE)) {
3131
this.saveState('currentState', TutorialMachine.initialState);
3232
this.saveExtState(TUTORIAL_STATE, this.get('currentState'));
33-
} else {
34-
this.saveState('currentState', this.getExtState(TUTORIAL_STATE));
35-
if (this.storageHasKey(FEATURE_LIST)) {
36-
this.set('featureList', this.getExtState(FEATURE_LIST));
37-
if (this.storageHasKey(FEATURE_STATE)) {
38-
this.saveState('featureState', this.getExtState(FEATURE_STATE));
39-
} else {
40-
if (FeatureMachine != null) {
41-
this.saveState('featureState', FeatureMachine.initialState);
42-
this.saveExtState(FEATURE_STATE, this.get('featureState'));
43-
}
33+
return;
34+
}
35+
this.saveState('currentState', this.getExtState(TUTORIAL_STATE));
36+
if (this.storageHasKey(FEATURE_LIST)) {
37+
this.set('featureList', this.getExtState(FEATURE_LIST));
38+
if (this.storageHasKey(FEATURE_STATE)) {
39+
this.saveState('featureState', this.getExtState(FEATURE_STATE));
40+
} else {
41+
if (FeatureMachine != null) {
42+
this.saveState('featureState', FeatureMachine.initialState);
43+
this.saveExtState(FEATURE_STATE, this.get('featureState'));
4444
}
45-
this.buildFeatureMachine();
4645
}
46+
this.buildFeatureMachine();
4747
}
4848
},
4949

@@ -62,7 +62,6 @@ export default Service.extend({
6262
},
6363

6464
transitionTutorialMachine(currentState, event, extendedState) {
65-
debugger;
6665
if (extendedState) {
6766
this.set('componentState', extendedState);
6867
}

ui/app/templates/vault/cluster/unseal.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</MessageInPage>
1111
<ShamirFlow
1212
@action="unseal"
13+
@onUpdate={{action 'setUnsealState'}}
1314
@onShamirSuccess={{action 'transitionToCluster'}}
1415
@buttonText="Unseal"
1516
@thresholdPath="t"

0 commit comments

Comments
 (0)