Skip to content

Commit c3029ab

Browse files
LonelyPrincessdanielcaldas
authored andcommitted
Global viewGenerator included in default config object (#131)
* fix: Add `viewGenerator` to default config When installing the library in a project, the `viewGenerator` function defined in the config object by the user did have no effect. The reason for this was that properties not included in the default config object (graph.config.js) were been ignored when building the graph and rendering it in the browser. In order to solve this issue, a `viewGenerator` property is now included in the default config object, with an initial value of `null`. * fix: Don't show function or null properties in sandbox The current sandbox example created a form that allowed all of the available config properties to be customized in real time. The `viewGenerator` property, though, cannot be customized with a form. Since its value must be a function, the user cannot set it via a form field. Also, the fact that it's initialized to null made some of the sandbox examples to throw an error because the form schema generator doesn't support neither null or undefined values. Functions are not allowed either, and in this case an error would appear on screen by saying that this type of data is not supported. The current change filters the config elements so that neither null, undefined or function values are included in the config form. * test: Update expected value for `viewGenerator`
1 parent 387d516 commit c3029ab

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

sandbox/utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ function generateFormSchema(o, rootSpreadProp, accum = {}) {
3232
for (let k of Object.keys(o)) {
3333
const kk = rootSpreadProp ? `${rootSpreadProp}.${k}` : k;
3434

35-
typeof o[k] === 'object' ? generateFormSchema(o[kk], kk, accum) : (accum[kk] = formMap(kk, o[k]));
35+
if (o[k] !== undefined && o[k] !== null && typeof o[k] !== 'function') {
36+
typeof o[k] === 'object' ? generateFormSchema(o[kk], kk, accum) : (accum[kk] = formMap(kk, o[k]));
37+
}
3638
}
3739

3840
return accum;

src/components/graph/graph.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
* - 'wye'
114114
*
115115
* **[note]** react-d3-graph will map this values to [d3 symbols](https://github.com/d3/d3-shape#symbols)
116-
* @param {Function} [node.viewGenerator=undefined] - 🔍🔍🔍 function that receives a node and returns a JSX view.
116+
* @param {Function} [node.viewGenerator=null] - 🔍🔍🔍 function that receives a node and returns a JSX view.
117117
* <br/>
118118
* @param {Object} link link object is explained in the next section. ⬇️
119119
* <h2 id="config-link"><a href="#config-link">#</a> Link level configurations</h2>
@@ -194,7 +194,8 @@ export default {
194194
strokeColor: 'none',
195195
strokeWidth: 1.5,
196196
svg: '',
197-
symbolType: 'circle'
197+
symbolType: 'circle',
198+
viewGenerator: null
198199
},
199200
link: {
200201
color: '#d3d3d3',

test/component/graph/graph.helper.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('Graph Helper', () => {
124124
strokeWidth: 2,
125125
svg: 'file.svg',
126126
type: 'circle',
127-
viewGenerator: undefined,
127+
viewGenerator: null,
128128
overrideGlobalViewGenerator: undefined
129129
});
130130
});
@@ -170,7 +170,7 @@ describe('Graph Helper', () => {
170170
strokeWidth: 1.5,
171171
svg: 'file.svg',
172172
type: 'circle',
173-
viewGenerator: undefined,
173+
viewGenerator: null,
174174
overrideGlobalViewGenerator: undefined
175175
});
176176
});
@@ -215,7 +215,7 @@ describe('Graph Helper', () => {
215215
strokeWidth: 1.5,
216216
svg: 'file.svg',
217217
type: 'circle',
218-
viewGenerator: undefined,
218+
viewGenerator: null,
219219
overrideGlobalViewGenerator: undefined
220220
});
221221
});

0 commit comments

Comments
 (0)