(
parsed: ParsedDataListResponse,
node: Protocol,
compName: string,
group: Protocol[],
isList: boolean
)
| 354 | * @param isList - Whether the component is a list |
| 355 | */ |
| 356 | export 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 |
no test coverage detected