@@ -4,44 +4,49 @@ import nestedProperty from 'plotly.js/src/lib/nested_property';
4
4
import isNumeric from 'fast-isnumeric' ;
5
5
import { MULTI_VALUED , MULTI_VALUED_PLACEHOLDER } from './constants' ;
6
6
7
- export function computeVisibility ( props , fullValue , customConfig ) {
8
- let isVisible = false ;
7
+ const hasFullValue = fullValue => fullValue !== void 0 && fullValue !== null ;
9
8
10
- const hasFullValue = ( ) => fullValue !== void 0 && fullValue !== null ;
11
-
12
- const isValidCustomConfigObject = customConfig => {
13
- if ( customConfig . visibility_rules ) {
14
- const logRuleError = ( ) => {
15
- console . error (
16
- 'invalid customConfig: all customConfig visibility rules must include type and regex_match keys.'
17
- ) ;
18
- } ;
19
-
20
- if (
21
- ( customConfig . visibility_rules . blacklist &&
22
- customConfig . visibility_rules . blacklist . some ( r => ! r . type || ! r . regex_match ) ) ||
23
- ( customConfig . visibility_rules . whitelist &&
24
- customConfig . visibility_rules . whitelist . some ( r => ! r . type || ! r . regex_match ) )
25
- ) {
26
- logRuleError ( ) ;
27
- return false ;
28
- }
9
+ export function isValidCustomConfigObject ( customConfig ) {
10
+ if (
11
+ customConfig &&
12
+ customConfig === Object ( customConfig ) &&
13
+ Object . keys ( customConfig ) . length &&
14
+ customConfig . visibility_rules
15
+ ) {
16
+ const logRuleError = ( ) => {
17
+ console . error (
18
+ 'invalid customConfig: all customConfig visibility rules must include type and regex_match keys.'
19
+ ) ;
20
+ } ;
29
21
30
- if (
31
- customConfig . visibility_rules . order &&
32
- Array . isArray ( customConfig . visibility_rules . order ) &&
33
- customConfig . visibility_rules . order . some ( o => ! [ 'blacklist' , 'whitelist' ] . includes ( o ) )
34
- ) {
35
- console . error (
36
- "invalid customConfig: only 2 values are accepted in the visibility_rules.order array: 'blacklist' and 'whitelist'"
37
- ) ;
38
- return false ;
39
- }
22
+ if (
23
+ ( customConfig . visibility_rules . blacklist &&
24
+ customConfig . visibility_rules . blacklist . some ( r => ! r . type || ! r . regex_match ) ) ||
25
+ ( customConfig . visibility_rules . whitelist &&
26
+ customConfig . visibility_rules . whitelist . some ( r => ! r . type || ! r . regex_match ) )
27
+ ) {
28
+ logRuleError ( ) ;
29
+ return false ;
30
+ }
40
31
41
- return true ;
32
+ if (
33
+ customConfig . visibility_rules . order &&
34
+ Array . isArray ( customConfig . visibility_rules . order ) &&
35
+ customConfig . visibility_rules . order . some ( o => ! [ 'blacklist' , 'whitelist' ] . includes ( o ) )
36
+ ) {
37
+ console . error (
38
+ "invalid customConfig: only 2 values are accepted in the visibility_rules.order array: 'blacklist' and 'whitelist'"
39
+ ) ;
40
+ return false ;
42
41
}
43
- return false ;
44
- } ;
42
+
43
+ return true ;
44
+ }
45
+ return false ;
46
+ }
47
+
48
+ export function applyCustomConfigVisibility ( props , fullValue , customConfig ) {
49
+ let isVisible = false ;
45
50
46
51
if (
47
52
customConfig &&
@@ -68,34 +73,30 @@ export function computeVisibility(props, fullValue, customConfig) {
68
73
69
74
if ( order [ 0 ] === 'blacklist' ) {
70
75
const shouldBlacklist = matches ( 'blacklist' ) && ! matches ( 'whitelist' ) ;
71
- if ( ! shouldBlacklist && hasFullValue ( ) ) {
76
+ if ( ! shouldBlacklist && hasFullValue ( fullValue ) ) {
72
77
isVisible = true ;
73
78
}
74
79
}
75
80
76
81
if ( order [ 0 ] === 'whitelist' ) {
77
82
const shouldWhitelist = matches ( 'whitelist' ) && ! matches ( 'blacklist' ) ;
78
- if ( shouldWhitelist && hasFullValue ( ) ) {
83
+ if ( shouldWhitelist && hasFullValue ( fullValue ) ) {
79
84
isVisible = true ;
80
85
}
81
86
}
82
87
} else {
83
88
if ( customConfig . visibility_rules . blacklist ) {
84
- if ( ! matches ( 'blacklist' ) && hasFullValue ( ) ) {
89
+ if ( ! matches ( 'blacklist' ) && hasFullValue ( fullValue ) ) {
85
90
isVisible = true ;
86
91
}
87
92
}
88
93
89
94
if ( customConfig . visibility_rules . whitelist ) {
90
- if ( matches ( 'whitelist' ) && hasFullValue ( ) ) {
95
+ if ( matches ( 'whitelist' ) && hasFullValue ( fullValue ) ) {
91
96
isVisible = true ;
92
97
}
93
98
}
94
99
}
95
- } else {
96
- if ( props . show || hasFullValue ( ) ) {
97
- isVisible = true ;
98
- }
99
100
}
100
101
101
102
return isVisible ;
@@ -127,7 +128,9 @@ export default function unpackPlotProps(props, context) {
127
128
multiValued = true ;
128
129
}
129
130
130
- const isVisible = computeVisibility ( props , fullValue , customConfig ) ;
131
+ const isVisible = isValidCustomConfigObject ( customConfig )
132
+ ? applyCustomConfigVisibility ( props , fullValue , customConfig )
133
+ : Boolean ( props . show || hasFullValue ( fullValue ) ) ;
131
134
132
135
let defaultValue = props . defaultValue ;
133
136
if ( defaultValue === void 0 && defaultContainer ) {
0 commit comments