Skip to content

Commit 8651490

Browse files
committed
fix(graph): handle schema-v2 array consumed_by shape in hook→consumer edges
The graph template was written for legacy consumed_by string shape ('PluginName Class::method'). Schema v2 stores it as an array of {plugin, where, kind} objects per the wp-plugin-onboard skill spec. Calling .split() on an array threw TypeError and aborted graph build, leaving the canvas empty. Normalize both shapes into a uniform consumer list before edge building. Strings still work; arrays render one edge per object, labelling the consumer node with plugin + kind.
1 parent a1006a1 commit 8651490

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

audit/graph.html

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -424,18 +424,32 @@ <h2>Stats</h2>
424424
// === EDGES (intra-plugin inferred relationships) ===
425425

426426
// hook → consumer (already in manifest)
427+
// consumed_by may be a string (legacy) or an array of {plugin, where, kind}
428+
// objects (schema v2). Normalize both into a uniform consumer list.
427429
(m.hooks_fired || []).forEach(h => {
428430
if (!h.consumed_by) return;
429-
// consumer might be a Pro feature class — check existence first
430-
const consumerId = `feature:${h.consumed_by.split(' ')[0].split('(')[0].trim()}`;
431-
if (seen.has(consumerId)) {
432-
addEdge(`hook:${h.name}`, consumerId, 'consumed_by', 2);
433-
} else {
434-
// fallback — create a generic consumer node
435-
const fallback = `consumer:${h.consumed_by}`;
436-
addNode(fallback, h.consumed_by, 'feature', { size:16, big:true });
437-
addEdge(`hook:${h.name}`, fallback, 'consumed_by', 2);
438-
}
431+
if (Array.isArray(h.consumed_by) && h.consumed_by.length === 0) return;
432+
const consumers = Array.isArray(h.consumed_by)
433+
? h.consumed_by.map(c => ({
434+
key: (c.where || c.plugin || '').split(' ')[0].split('(')[0].trim() || (c.plugin || ''),
435+
label: c.plugin ? (c.kind ? `${c.plugin} (${c.kind})` : c.plugin) : (c.where || ''),
436+
}))
437+
: [{
438+
key: String(h.consumed_by).split(' ')[0].split('(')[0].trim(),
439+
label: String(h.consumed_by),
440+
}];
441+
consumers.forEach(c => {
442+
if (!c.key) return;
443+
const consumerId = `feature:${c.key}`;
444+
if (seen.has(consumerId)) {
445+
addEdge(`hook:${h.name}`, consumerId, 'consumed_by', 2);
446+
} else {
447+
// fallback — create a generic consumer node
448+
const fallback = `consumer:${c.key}`;
449+
addNode(fallback, c.label, 'feature', { size:16, big:true });
450+
addEdge(`hook:${h.name}`, fallback, 'consumed_by', 2);
451+
}
452+
});
439453
});
440454

441455
// REST endpoint → table (route name contains table name)

0 commit comments

Comments
 (0)