Skip to content

Commit 9fa8f49

Browse files
committed
start applying customConfig's visibility rules
1 parent 64de034 commit 9fa8f49

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

dev/App.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ class App extends Component {
183183
// makeDefaultTrace={() => ({type: 'scattergl', mode: 'markers'})}
184184
// fontOptions={[{label:'Arial', value: 'arial'}]}
185185
// chartHelp={chartHelp}
186+
customConfig={{
187+
visibility_rules: {
188+
blacklist: [
189+
{type: 'attrName', regex_match: 'color'},
190+
{type: 'attrName', regex_match: 'font'},
191+
],
192+
whitelist: [{type: 'attrName', regex_match: 'colorscale'}],
193+
},
194+
}}
186195
>
187196
<DefaultEditor
188197
// menuPanelOrder={[

src/lib/unpackPlotProps.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import isNumeric from 'fast-isnumeric';
33
import {MULTI_VALUED, MULTI_VALUED_PLACEHOLDER} from './constants';
44

55
export default function unpackPlotProps(props, context) {
6-
const {container, getValObject, defaultContainer, updateContainer} = context;
6+
const {container, getValObject, defaultContainer, updateContainer, customConfig} = context;
77

88
if (!props.attr) {
99
return {};
@@ -29,9 +29,47 @@ export default function unpackPlotProps(props, context) {
2929
}
3030

3131
let isVisible = false;
32+
// Base visibility rules
3233
if (props.show || (fullValue !== void 0 && fullValue !== null)) {
3334
isVisible = true;
3435
}
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+
}
3573

3674
let defaultValue = props.defaultValue;
3775
if (defaultValue === void 0 && defaultContainer) {

0 commit comments

Comments
 (0)