Skip to content

Commit ef9e083

Browse files
committed
Change tab visibility to services
1 parent c007ed9 commit ef9e083

File tree

7 files changed

+134
-110
lines changed

7 files changed

+134
-110
lines changed

client/directives/environment/modals/modalEditServer/editServerModalController.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ function EditServerModalController(
1616
findLinkedServerVariables,
1717
helpCards,
1818
instance,
19+
isTabNameValid,
1920
keypather,
2021
loading,
2122
loadingPromises,
2223
ModalService,
2324
OpenItems,
2425
tab,
26+
TAB_VISIBILITY,
2527
updateDockerfileFromState,
2628
close
2729
) {
@@ -38,7 +40,6 @@ function EditServerModalController(
3840
'getUpdatePromise': parentController.getUpdatePromise.bind(SMC),
3941
'insertHostName': parentController.insertHostName.bind(SMC),
4042
'isDirty': parentController.isDirty.bind(SMC),
41-
'_isTabVisible': parentController.isTabVisible.bind(SMC),
4243
'openDockerfile': parentController.openDockerfile.bind(SMC),
4344
'populateStateFromData': parentController.populateStateFromData.bind(SMC),
4445
'rebuildAndOrRedeploy': parentController.rebuildAndOrRedeploy.bind(SMC),
@@ -50,8 +51,7 @@ function EditServerModalController(
5051
'switchBetweenAdvancedAndMirroring': parentController.switchBetweenAdvancedAndMirroring.bind(SMC),
5152
'switchToMirrorMode': parentController.switchToMirrorMode.bind(SMC),
5253
'switchToAdvancedMode': parentController.switchToAdvancedMode.bind(SMC),
53-
'updateInstanceAndReset': parentController.updateInstanceAndReset.bind(SMC),
54-
'TAB_VISIBILITY': parentController.TAB_VISIBILITY
54+
'updateInstanceAndReset': parentController.updateInstanceAndReset.bind(SMC)
5555
});
5656

5757
SMC.instance = instance;
@@ -160,14 +160,14 @@ function EditServerModalController(
160160
*/
161161
SMC.isTabVisible = function (tabName) {
162162
// First, check if tab exists and tab FF is turned on (if applicable)
163-
if (!SMC._isTabVisible(tabName)) {
163+
if (!isTabNameValid(tabName)) {
164164
return false;
165165
}
166166
var currentStatuses = [];
167167
var currentContextVersion = keypather.get(SMC, 'instance.contextVersion');
168168

169169
if (!currentContextVersion.getMainAppCodeVersion()) {
170-
return !!SMC.TAB_VISIBILITY[tabName].nonRepo;
170+
return !!TAB_VISIBILITY[tabName].nonRepo;
171171
}
172172
if (
173173
SMC.state.advanced ||
@@ -176,9 +176,9 @@ function EditServerModalController(
176176
keypather.get(currentContextVersion, 'attrs.advanced')
177177
)
178178
) {
179-
return !!SMC.TAB_VISIBILITY[tabName].advanced;
179+
return !!TAB_VISIBILITY[tabName].advanced;
180180
}
181-
return !!SMC.TAB_VISIBILITY[tabName].basic;
181+
return !!TAB_VISIBILITY[tabName].basic;
182182
};
183183

184184
SMC.needsToBeDirtySaved = function () {

client/directives/environment/modals/modalSetupServer/setupMirrorServerModalController.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@ function SetupMirrorServerModalController(
88
$controller,
99
$q,
1010
$rootScope,
11+
cardInfoTypes,
1112
createAndBuildNewContainer,
1213
createBuildFromContextVersionId,
1314
errs,
1415
eventTracking,
1516
fetchUser,
1617
helpCards,
18+
isTabNameValid,
1719
keypather,
1820
loading,
1921
loadingPromises,
2022
ModalService,
2123
promisify,
22-
cardInfoTypes,
2324
OpenItems,
25+
TAB_VISIBILITY,
2426
updateDockerfileFromState,
2527
close,
2628
repo,
@@ -42,7 +44,6 @@ function SetupMirrorServerModalController(
4244
'getUpdatePromise': parentController.getUpdatePromise.bind(SMC),
4345
'insertHostName': parentController.insertHostName.bind(SMC),
4446
'isDirty': parentController.isDirty.bind(SMC),
45-
'_isTabVisible': parentController.isTabVisible.bind(SMC),
4647
'openDockerfile': parentController.openDockerfile.bind(SMC),
4748
'populateStateFromData': parentController.populateStateFromData.bind(SMC),
4849
'rebuildAndOrRedeploy': parentController.rebuildAndOrRedeploy.bind(SMC),
@@ -54,7 +55,6 @@ function SetupMirrorServerModalController(
5455
'switchToMirrorMode': parentController.switchToMirrorMode.bind(SMC),
5556
'switchToAdvancedMode': parentController.switchToAdvancedMode.bind(SMC),
5657
'updateInstanceAndReset': parentController.updateInstanceAndReset.bind(SMC),
57-
'TAB_VISIBILITY': parentController.TAB_VISIBILITY
5858
});
5959

6060
var mainRepoContainerFile = new cardInfoTypes.MainRepository();
@@ -214,13 +214,13 @@ function SetupMirrorServerModalController(
214214
*/
215215
SMC.isTabVisible = function (tabName) {
216216
// First, check if tab exists and tab FF is turned on (if applicable)
217-
if (!SMC._isTabVisible(tabName)) {
217+
if (!isTabNameValid(tabName)) {
218218
return false;
219219
}
220220
if (SMC.state.advanced === 'isMirroringDockerfile') {
221-
return !!SMC.TAB_VISIBILITY[tabName].mirror;
221+
return !!TAB_VISIBILITY[tabName].mirror;
222222
}
223-
return !!SMC.TAB_VISIBILITY[tabName].advanced;
223+
return !!TAB_VISIBILITY[tabName].advanced;
224224
};
225225

226226
SMC.isPrimaryButtonDisabled = function (serverFormInvalid) {

client/directives/environment/modals/modalSetupServer/setupServerModalController.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ function SetupServerModalController(
2626
fetchUser,
2727
hasKeypaths,
2828
helpCards,
29+
isTabNameValid,
2930
keypather,
3031
loading,
3132
loadingPromises,
3233
ModalService,
3334
OpenItems,
3435
promisify,
3536
updateDockerfileFromState,
37+
TAB_VISIBILITY,
3638
close,
3739
repo,
3840
build,
@@ -53,7 +55,6 @@ function SetupServerModalController(
5355
'getUpdatePromise': parentController.getUpdatePromise.bind(SMC),
5456
'insertHostName': parentController.insertHostName.bind(SMC),
5557
'isDirty': parentController.isDirty.bind(SMC),
56-
'_isTabVisible': parentController.isTabVisible.bind(SMC),
5758
'openDockerfile': parentController.openDockerfile.bind(SMC),
5859
'populateStateFromData': parentController.populateStateFromData.bind(SMC),
5960
'rebuildAndOrRedeploy': parentController.rebuildAndOrRedeploy.bind(SMC),
@@ -65,8 +66,7 @@ function SetupServerModalController(
6566
'switchBetweenAdvancedAndMirroring': parentController.switchBetweenAdvancedAndMirroring.bind(SMC),
6667
'switchToMirrorMode': parentController.switchToMirrorMode.bind(SMC),
6768
'switchToAdvancedMode': parentController.switchToAdvancedMode.bind(SMC),
68-
'updateInstanceAndReset': parentController.updateInstanceAndReset.bind(SMC),
69-
'TAB_VISIBILITY': parentController.TAB_VISIBILITY
69+
'updateInstanceAndReset': parentController.updateInstanceAndReset.bind(SMC)
7070
});
7171

7272
var mainRepoContainerFile = new cardInfoTypes.MainRepository();
@@ -376,16 +376,16 @@ function SetupServerModalController(
376376
*/
377377
SMC.isTabVisible = function (tabName) {
378378
// First, check if tab exists and tab FF is turned on (if applicable)
379-
if (!SMC._isTabVisible(tabName)) {
379+
if (!isTabNameValid(tabName)) {
380380
return false;
381381
}
382382
if (SMC.state.advanced) {
383383
if (SMC.state.advanced === 'isMirroringDockerfile') {
384-
return !!SMC.TAB_VISIBILITY[tabName].mirror;
384+
return !!TAB_VISIBILITY[tabName].mirror;
385385
}
386-
return !!SMC.TAB_VISIBILITY[tabName].advanced;
386+
return !!TAB_VISIBILITY[tabName].advanced;
387387
}
388-
return SMC.state.step >= SMC.TAB_VISIBILITY[tabName].step;
388+
return SMC.state.step >= TAB_VISIBILITY[tabName].step;
389389
};
390390

391391
SMC.isPrimaryButtonDisabled = function (serverFormInvalid) {

client/directives/environment/modals/serverModalController.js

-73
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,6 @@
33
require('app')
44
.controller('ServerModalController', ServerModalController);
55

6-
var TAB_VISIBILITY = {
7-
repository: {
8-
advanced: true,
9-
basic: true,
10-
mirror: true,
11-
step: 1
12-
},
13-
commands: {
14-
basic: true,
15-
step: 2
16-
},
17-
ports: {
18-
basic: true,
19-
step: 3
20-
},
21-
whitelist: {
22-
advanced: true,
23-
basic: true,
24-
mirror: true,
25-
featureFlagName: 'whitelist',
26-
nonRepo: true,
27-
step: 3
28-
},
29-
env: {
30-
advanced: true,
31-
basic: true,
32-
mirror: true,
33-
nonRepo: true,
34-
step: 3
35-
},
36-
backup: {
37-
featureFlagName: 'backup',
38-
nonRepo: true,
39-
step: 3
40-
},
41-
files: {
42-
basic: true,
43-
step: 3
44-
},
45-
translation: {
46-
advanced: true,
47-
basic: true,
48-
step: 3
49-
},
50-
buildfiles: {
51-
basic: true,
52-
advanced: true,
53-
mirror: true,
54-
nonRepo: true,
55-
step: 3
56-
},
57-
logs: {
58-
advanced: true,
59-
basic: true,
60-
nonRepo: true,
61-
mirror: true,
62-
step: 4
63-
}
64-
};
65-
666
function ServerModalController(
677
$filter,
688
$q,
@@ -82,8 +22,6 @@ function ServerModalController(
8222
promisify,
8323
updateDockerfileFromState
8424
) {
85-
this.TAB_VISIBILITY = TAB_VISIBILITY;
86-
8725
this.requiresRedeploy = function () {
8826
var SMC = this;
8927
return !!SMC.instance && !angular.equals(
@@ -508,17 +446,6 @@ function ServerModalController(
508446
return SMC.state.advanced === 'isMirroringDockerfile';
509447
};
510448

511-
this.isTabVisible = function (tabName) {
512-
var SMC = this;
513-
if (!SMC.TAB_VISIBILITY[tabName]) {
514-
return false;
515-
}
516-
if (SMC.TAB_VISIBILITY[tabName].featureFlagName && !$rootScope.featureFlags[SMC.TAB_VISIBILITY[tabName].featureFlagName]) {
517-
return false;
518-
}
519-
return true;
520-
};
521-
522449
this.getDisplayName = function () {
523450
var SMC = this;
524451
if (SMC.instance) {
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
'use strict';
2+
3+
require('app')
4+
.factory('isTabNameValid', isTabNameValid)
5+
.value('TAB_VISIBILITY', {
6+
repository: {
7+
advanced: true,
8+
basic: true,
9+
mirror: true,
10+
step: 1
11+
},
12+
commands: {
13+
basic: true,
14+
step: 2
15+
},
16+
ports: {
17+
basic: true,
18+
step: 3
19+
},
20+
whitelist: {
21+
advanced: true,
22+
basic: true,
23+
mirror: true,
24+
featureFlagName: 'whitelist',
25+
nonRepo: true,
26+
step: 3
27+
},
28+
env: {
29+
advanced: true,
30+
basic: true,
31+
mirror: true,
32+
nonRepo: true,
33+
step: 3
34+
},
35+
backup: {
36+
featureFlagName: 'backup',
37+
nonRepo: true,
38+
step: 3
39+
},
40+
files: {
41+
basic: true,
42+
step: 3
43+
},
44+
translation: {
45+
advanced: true,
46+
basic: true,
47+
step: 3
48+
},
49+
buildfiles: {
50+
basic: true,
51+
advanced: true,
52+
mirror: true,
53+
nonRepo: true,
54+
step: 3
55+
},
56+
logs: {
57+
advanced: true,
58+
basic: true,
59+
nonRepo: true,
60+
mirror: true,
61+
step: 4
62+
}
63+
});
64+
65+
function isTabNameValid (
66+
$rootScope,
67+
TAB_VISIBILITY
68+
) {
69+
return function (tabName) {
70+
if (!TAB_VISIBILITY[tabName]) {
71+
return false;
72+
}
73+
if (TAB_VISIBILITY[tabName].featureFlagName && !$rootScope.featureFlags[TAB_VISIBILITY[tabName].featureFlagName]) {
74+
return false;
75+
}
76+
return true;
77+
};
78+
}
79+
80+

serviceTabVisibility.unit.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
describe('serviceTabVisibility'.bold.underline.blue, function () {
4+
describe('isTabNameValid', function () {
5+
var isTabVisible;
6+
var $rootScope;
7+
var keypather;
8+
9+
beforeEach(function () {
10+
angular.mock.module('app');
11+
angular.mock.inject(function (
12+
_$rootScope_,
13+
_keypather_,
14+
_isTabVisible_
15+
) {
16+
$rootScope = _$rootScope_;
17+
keypather = _keypather_;
18+
isTabVisible = _isTabVisible_;
19+
});
20+
});
21+
22+
it('should return false for an undefined tab', function () {
23+
expect(isTabVisible('thingthatdoesntexist')).to.equal(false);
24+
expect(isTabVisible('thiasdfng')).to.equal(false);
25+
});
26+
27+
it('should return false for a feature flag that is disabled', function () {
28+
keypather.set($rootScope, 'featureFlags.whitelist', true);
29+
expect(isTabVisible('whitelist')).to.equal(true);
30+
keypather.set($rootScope, 'featureFlags.whitelist', false);
31+
expect(isTabVisible('whitelist')).to.equal(false);
32+
});
33+
});
34+
});

0 commit comments

Comments
 (0)