@@ -3,7 +3,7 @@ import isNumeric from 'fast-isnumeric';
3
3
import { MULTI_VALUED , MULTI_VALUED_PLACEHOLDER } from './constants' ;
4
4
5
5
export default function unpackPlotProps ( props , context ) {
6
- const { container, getValObject, defaultContainer, updateContainer} = context ;
6
+ const { container, getValObject, defaultContainer, updateContainer, customConfig } = context ;
7
7
8
8
if ( ! props . attr ) {
9
9
return { } ;
@@ -29,9 +29,47 @@ export default function unpackPlotProps(props, context) {
29
29
}
30
30
31
31
let isVisible = false ;
32
+ // Base visibility rules
32
33
if ( props . show || ( fullValue !== void 0 && fullValue !== null ) ) {
33
34
isVisible = true ;
34
35
}
36
+ // We can override base visibility rules with a customConfig
37
+ if (
38
+ customConfig &&
39
+ customConfig === Object ( customConfig ) &&
40
+ Object . keys ( customConfig ) . length &&
41
+ customConfig . visibility_rules
42
+ ) {
43
+ // Look to see if there was an order to blacklisting or whitelisting specified
44
+ const order =
45
+ customConfig . visibility_rules . order &&
46
+ Array . isArray ( customConfig . visibility_rules . order ) &&
47
+ customConfig . visibility_rules . order . length
48
+ ? customConfig . visibility_rules . order
49
+ : [ 'blacklist' , 'whitelist' ] ;
50
+
51
+ order . forEach ( o => {
52
+ if ( customConfig . visibility_rules [ o ] ) {
53
+ customConfig . visibility_rules [ o ] . forEach ( r => {
54
+ if ( r . type && r . regex_match ) {
55
+ const regex = RegExp ( r . regex_match ) ;
56
+ if ( o === 'blacklist' && r . type === 'attrName' && regex . test ( props . attr ) ) {
57
+ isVisible = false ;
58
+ }
59
+ if ( o === 'whitelist' && r . type === 'attrName' && regex . test ( props . attr ) ) {
60
+ isVisible = true ;
61
+ }
62
+ } else {
63
+ throw new Error (
64
+ `sorry, you must include the type and regex_match in each of your blacklisting and whitelisting customConfig rules`
65
+ ) ;
66
+ }
67
+ } ) ;
68
+ } else {
69
+ throw new Error ( `sorry, you have an invalid key of ${ o } in your customConfig prop` ) ;
70
+ }
71
+ } ) ;
72
+ }
35
73
36
74
let defaultValue = props . defaultValue ;
37
75
if ( defaultValue === void 0 && defaultContainer ) {
0 commit comments