File tree 1 file changed +18
-2
lines changed
src/react-chayns-modeswitch/component
1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ export default class ModeSwitch extends Component {
64
64
constructor ( props ) {
65
65
super ( props ) ;
66
66
67
+ this . showModeSwitch = this . showModeSwitch . bind ( this ) ;
67
68
this . toggleModeSwitch = this . toggleModeSwitch . bind ( this ) ;
68
69
this . switchMode = this . switchMode . bind ( this ) ;
69
70
this . setMode = this . setMode . bind ( this ) ;
@@ -205,10 +206,25 @@ export default class ModeSwitch extends Component {
205
206
this . setState ( { open : ! open } ) ;
206
207
}
207
208
208
- render ( ) {
209
+ showModeSwitch ( ) {
209
210
const { show } = this . props ;
211
+ const { modes } = this . state ;
212
+
213
+ let customModes = modes . length ;
214
+ if ( modes . find ( mode => mode . uacIds && mode . uacIds . indexOf ( 1 ) >= 0 ) ) {
215
+ customModes -= 1 ;
216
+ }
217
+ if ( modes . find ( mode => ! mode . uacIds || ( mode . uacIds && mode . uacIds . indexOf ( 0 ) >= 0 ) ) ) {
218
+ customModes -= 1 ;
219
+ }
220
+
221
+ return ( show || ( show === null && ( ! ModeSwitch . adminSwitchSupport || modes . length > 2 || customModes ) ) ) && chayns . env . user . isAuthenticated ;
222
+ }
223
+
224
+ render ( ) {
210
225
const { modes, open, activeModeId } = this . state ;
211
- if ( ( show || ( show === null && ( ! ModeSwitch . adminSwitchSupport || modes . length > 2 ) ) ) && chayns . env . user . isAuthenticated ) {
226
+
227
+ if ( this . showModeSwitch ( ) ) {
212
228
return (
213
229
< TappPortal >
214
230
< div
You can’t perform that action at this time.
0 commit comments