MCPcopy Create free account
hub / github.com/MigoXLab/coderio / applyPropsAndStateToProtocol

Function applyPropsAndStateToProtocol

src/nodes/process/structure/utils.ts:356–404  ·  view source on GitHub ↗
(
    parsed: ParsedDataListResponse,
    node: Protocol,
    compName: string,
    group: Protocol[],
    isList: boolean
)

Source from the content-addressed store, hash-verified

354 * @param isList - Whether the component is a list
355 */
356export function applyPropsAndStateToProtocol(
357 parsed: ParsedDataListResponse,
358 node: Protocol,
359 compName: string,
360 group: Protocol[],
361 isList: boolean
362): void {
363 if (parsed && parsed.state && Array.isArray(parsed.state)) {
364 if (isList) {
365 if (!node.data.states) {
366 node.data.states = [];
367 }
368
369 node.data.states.push({
370 state: parsed.state,
371 componentName: compName,
372 componentPath: group[0]?.data.componentPath || '',
373 });
374
375 const originalChildren: Protocol[] = node.children || [];
376 const newChildren: Protocol[] = [];
377 const processedComponentNames = new Set<string>();
378
379 for (const child of originalChildren) {
380 const childName = child.data.componentName;
381 if (childName === compName) {
382 if (!processedComponentNames.has(childName)) {
383 child.data.name = childName;
384 child.id = childName;
385 const cleanKebabName = toKebabCase(childName);
386 child.data.kebabName = cleanKebabName;
387 delete child.data.path;
388
389 if (parsed.props && Array.isArray(parsed.props)) {
390 child.data.props = parsed.props;
391 }
392
393 newChildren.push(child);
394 processedComponentNames.add(childName);
395 }
396 } else {
397 newChildren.push(child);
398 }
399 }
400
401 node.children = newChildren;
402 }
403 }
404}
405
406/**
407 * Extracts component properties and states from repeated component instances

Callers 1

populateComponentPropsFunction · 0.70

Calls 2

toKebabCaseFunction · 0.90
pushMethod · 0.80

Tested by

no test coverage detected